From a3ca071c4c24b7d837de33fa4fe06b58dfc0083d Mon Sep 17 00:00:00 2001
From: Krish Moodbidri <krish94@uab.edu>
Date: Fri, 16 May 2025 16:09:19 -0500
Subject: [PATCH 1/5] Update README with improvements and corrections

- Fixed JSON code block syntax and structure in Data Flow section
- Added hyperlinks to CentOS setup steps for RabbitMQ configuration
- Added vhost config
---
 README.md | 186 +++++++++++++++++++++++++++++++++++++++++++-----------
 1 file changed, 149 insertions(+), 37 deletions(-)

diff --git a/README.md b/README.md
index 2672aae..0be06ff 100644
--- a/README.md
+++ b/README.md
@@ -1,53 +1,165 @@
-# rabbitmq_agents
 
-This repo keeps different rabbitmq agents that help in account creation on OHPC system.
+# RabbitMQ User Registration Agents 
 
-It has 2 branches ```develop``` and ```production``` , that houses agents based on where they are launched
+---
 
-## Using RCRMQ class
+## Overview
+This project automates user registration workflows at UAB using **RabbitMQ** to route tasks between systems like the web interface, CLI tools, databases, and email services. It ensures tasks like assigning user IDs, validating data, and sending notifications happen in sequence without manual intervention.  
 
-- First, rename `rabbit_config.py.example` to `rabbit_config.py`
+---
 
-- Modify config file, at least the `Password` needs to be your own passwod
+## Key Components 
+### 1. **The `RegUsr` Exchange** 
+- **Type**: Topic exchange (routes messages using `routing_key` patterns).  
+- **Purpose**: Acts as the central hub for all registration-related messages.  
 
-- In your code:
+### 2. **Core Scripts** 
+- **`self_reg_app` (Web UI)**: Starts the process by sending a `request<queuename>` message with user data.  
+- **`create_account.py` (CLI)**: Triggers backend tasks (e.g., UID/GID assignment, email subscriptions).  
 
+### 3. **Queues & Their Jobs** 
+| Queue Name               | What It Does                                                                 |  
+|--------------------------|-----------------------------------------------------------------------------|  
+| `get next uid gid`        | Reserves a unique UID/GID for the user (uses SQLite to track IDs).          |  
+| `subscribe mail list`     | Adds the user’s email to mailing lists (e.g., department announcements).    |  
+| `git commit`              | Logs configuration changes to Git (e.g., new user added).                   |  
+| `notify user`             | Sends emails/SMS to users (e.g., "Your account is ready").                  |  
+| `task_manager`            | Coordinates tasks like retrying failed steps or updating logs.              |  
+
+### 4. **Data Flow** 
+1. A user submits details via the **Web UI** (`self_reg_app`).  
+2. A `request<queuename>` message is sent to `RegUsr` with fields:  
+   ```json  
+   { "username", "queuename", "email", "fullname", "reason" }  
+
+3.  The system:
+    
+    -   Assigns UID/GID via SQLite (`get next uid gid`  queue).
+        
+    -   Validates data with a  `verify<queuename>`  message.
+        
+    -   Sends a  `completed<queuename>`  message with success/failure status.
+        
+    -   Notifies the user and logs the event.
+        
+
+----------
+
+## Setup & Usage
+
+### Prerequisites
+
+-   macOS
+    
+-   Homebrew
+    
+-   Python 3.x
+
+### Install and Setup RabbitMQ
+
+```bash
+brew update
+brew install rabbitmq
 ```
-# import the class
-from rc_rmq import RCRMQ
+For CentOS, refer to:
 
-# instantiate an instance
-rc_rmq = RCRMQ({'exchange': 'RegUsr'})
+-   [RabbitMQ Role Configuration](https://github.com/jprorama/CRI_XCBC/blob/dev/roles/ohpc_rabbitmq/tasks/main.yaml)
+    
+-   [VHost Configuration](https://github.com/jprorama/CRI_XCBC/blob/dev/roles/ohpc_add_rabbitmq_agents/tasks/main.yaml)
 
-# publish a message to message queue
-rc_rmq.publish_msg({
-  'routing_key': 'your_key',
-  'msg': {
-    'type': 'warning',
-    'content': 'this is warning'
-  }
-})
+### Add RabbitMQ to Your PATH
 
-# to consume message from a queue
-# you have to first define callback function
-# with parameters: channel, method, properties, body
-def callback_function(ch, method, properties, body):
-  msg = json.loads(body)
-  print("get msg: {}".format(msg['username')
+```
+echo 'export PATH="/usr/local/sbin:$PATH"' >> ~/.zshrc
+source ~/.zshrc  # Reload your shell to apply changes
+```
+### install centos steps 
+https://github.com/jprorama/CRI_XCBC/blob/dev/roles/ohpc_rabbitmq/tasks/main.yaml
+and the 2 vhosts
+https://github.com/jprorama/CRI_XCBC/blob/dev/roles/ohpc_add_rabbitmq_agents/tasks/main.yaml
 
-  # this will stop the consumer
-  rc_rmq.stop_consumer()
+### Start RabbitMQ
+```
+brew services start rabbitmq
+```
 
-# start consume messagre from queue with callback function
-rc_rmq.start_consume({
-  'queue': 'queue_name',
-  'routing_key: 'your_key',
-  'cb': callback_function
-})
+### Check RabbitMQ Status
+```
+rabbitmqctl status
+```
+### Create Config File
+```
+echo '[{rabbit, [{loopback_users, []}]}].' | sudo tee /etc/rabbitmq/rabbitmq.config
+sudo chown rabbitmq:rabbitmq /etc/rabbitmq/rabbitmq.config
+sudo chmod 644 /etc/rabbitmq/rabbitmq.config
+```
+###  Restart Service
+```
+sudo systemctl restart rabbitmq-server
+```
+
+### Access the Management UI
+
+-   **URL**:  [http://localhost:15672](http://localhost:15672/)
+    
+-   **Credentials**:
+    
+    -   Username:  `guest`
+        
+    -   Password:  `guest`
 
-# don't forget to close connection
-rc_rmq.disconnect()
+### Add Vhost in **rabbit_config.py**
+
+```
+RABBITMQ = {
+    'HOST': 'localhost',
+    'PORT': 5672,
+    'VHOST': 'adduser',
+    'USER': 'reggie',
+    'PASSWORD': 'reggie'
+}
 ```
 
-### Account creation flowchart
-![Account creation flowchart](./account-creation-flow.png)
\ No newline at end of file
+### Add Celery Vhost 
+
+```
+rabbitmqctl add_vhost adduser
+rabbitmqctl add_user reggie reggie
+rabbitmqctl set_permissions -p adduser reggie ".*" ".*" ".*"
+```
+
+### WIP Configuration Steps
+
+1.  **Bind Queues to  `RegUsr`  Exchange**:  
+    Use these routing keys:
+    
+    -   `request<queuename>`
+        
+    -   `completed<queuename>`
+        
+    -   `verify<queuename>`  
+        _(Replace  `<queuename>`  with your queue’s name, e.g.,  `request_user_reg`)_
+        
+2.  **Deploy Agents**:
+    
+    -   Run the Web UI (`self_reg_app`) for user submissions.
+        
+    -   Execute  `create_account.py`  to process tasks (e.g., UID assignment).
+        
+3.  **Monitor Queues**:  
+    Use RabbitMQ’s management UI or CLI tools to check:
+    
+    -   `task_manager`  for workflow progress.
+        
+    -   `notify user`  for delivery status of emails/SMS.
+        
+
+----------
+
+## Error Handling
+
+-   Failures (e.g., duplicate email) are reported in the  `completed<queuename>`  message’s  `errmsg`  field.
+    
+-   The  `user reg event logger`  tracks all registration attempts. Check logs at  `/var/log/user_reg.log`.
+    
+
-- 
GitLab


From d45dc138dc70638106da4593b81a82203dbc461b Mon Sep 17 00:00:00 2001
From: Krish Moodbidri <krish94@uab.edu>
Date: Mon, 5 May 2025 09:29:01 -0500
Subject: [PATCH 2/5] added initial instructions to setup and configure
 rabbitmq on a standalone vm (alma9) on openstack

---
 README.md | 193 +++++++++++++++++++++++++++++++++---------------------
 1 file changed, 118 insertions(+), 75 deletions(-)

diff --git a/README.md b/README.md
index 0be06ff..5110881 100644
--- a/README.md
+++ b/README.md
@@ -49,112 +49,155 @@ This project automates user registration workflows at UAB using **RabbitMQ** to
 
 ### Prerequisites
 
--   macOS
-    
--   Homebrew
-    
--   Python 3.x
+* Launch an alma9 instance on openstack, ssh into it and run the following commands
+
+*Before proceeding, set these environment variables:*
+```
+export RABBITMQ_USER="reggie"                  # RabbitMQ admin username
+export RABBITMQ_PASSWORD="secure_password"     # RabbitMQ admin password
+export CELERY_VHOST="adduser"                  # Celery-dedicated vhost
+export CELERY_USER="celery_user"               # Celery service username
+export CELERY_PASSWORD="celery_pass"           # Celery service password
+```
+
+### 1.1 Configure Package Repositories
 
-### Install and Setup RabbitMQ
+# Import security keys
+sudo rpm --import https://github.com/rabbitmq/signing-keys/releases/download/2.0/rabbitmq-release-signing-key.asc
+sudo rpm --import https://packagecloud.io/rabbitmq/erlang/gpgkey
+sudo rpm --import https://packagecloud.io/rabbitmq/rabbitmq-server/gpgkey
 
-```bash
-brew update
-brew install rabbitmq
+# Erlang Repository (AlmaLinux 8)
+```
+sudo tee /etc/yum.repos.d/rabbitmq_erlang.repo <<'EOL'
+[rabbitmq_erlang]
+name=RabbitMQ Erlang
+baseurl=https://packagecloud.io/rabbitmq/erlang/el/8/$basearch
+gpgcheck=1
+gpgkey=https://packagecloud.io/rabbitmq/erlang/gpgkey
+       https://github.com/rabbitmq/signing-keys/releases/download/2.0/rabbitmq-release-signing-key.asc
+enabled=1
+EOL
 ```
-For CentOS, refer to:
 
--   [RabbitMQ Role Configuration](https://github.com/jprorama/CRI_XCBC/blob/dev/roles/ohpc_rabbitmq/tasks/main.yaml)
-    
--   [VHost Configuration](https://github.com/jprorama/CRI_XCBC/blob/dev/roles/ohpc_add_rabbitmq_agents/tasks/main.yaml)
+# RabbitMQ Server Repository
+```
+sudo tee /etc/yum.repos.d/rabbitmq_server.repo <<'EOL'
+[rabbitmq_server]
+name=RabbitMQ Server
+baseurl=https://packagecloud.io/rabbitmq/rabbitmq-server/el/8/$basearch
+gpgcheck=1
+gpgkey=https://packagecloud.io/rabbitmq/rabbitmq-server/gpgkey
+enabled=1
+EOL
+```
 
-### Add RabbitMQ to Your PATH
+### 1.2 Install Packages
 
 ```
-echo 'export PATH="/usr/local/sbin:$PATH"' >> ~/.zshrc
-source ~/.zshrc  # Reload your shell to apply changes
+sudo yum install -y socat logrotate
+sudo yum install -y erlang-25.3.2 rabbitmq-server-3.12.6
+sudo systemctl enable --now rabbitmq-server
 ```
-### install centos steps 
-https://github.com/jprorama/CRI_XCBC/blob/dev/roles/ohpc_rabbitmq/tasks/main.yaml
-and the 2 vhosts
-https://github.com/jprorama/CRI_XCBC/blob/dev/roles/ohpc_add_rabbitmq_agents/tasks/main.yaml
 
-### Start RabbitMQ
+
+
+## 2. RabbitMQ Configuration
+### 2.1 Create Admin User & Permissions
+
 ```
-brew services start rabbitmq
+sudo rabbitmqctl add_user $RABBITMQ_USER $RABBITMQ_PASSWORD
+sudo rabbitmqctl set_user_tags $RABBITMQ_USER administrator
+sudo rabbitmqctl set_permissions -p / $RABBITMQ_USER ".*" ".*" ".*"
 ```
 
-### Check RabbitMQ Status
+
+### 2.2 Configure Celery Environment
+
 ```
-rabbitmqctl status
+sudo rabbitmqctl add_vhost $CELERY_VHOST
+sudo rabbitmqctl add_user $CELERY_USER $CELERY_PASSWORD
+sudo rabbitmqctl set_permissions -p $CELERY_VHOST $CELERY_USER ".*" ".*" ".*"
 ```
-### Create Config File
+
+## 3. Agent Service Setup
+
+### 3.1 Deploy Agent Codebase
+
 ```
-echo '[{rabbit, [{loopback_users, []}]}].' | sudo tee /etc/rabbitmq/rabbitmq.config
-sudo chown rabbitmq:rabbitmq /etc/rabbitmq/rabbitmq.config
-sudo chmod 644 /etc/rabbitmq/rabbitmq.config
+AGENT_DIR="/cm/shared/rabbitmq_agents"
+sudo git clone https://gitlab.rc.uab.edu/rc/rabbitmq_agents.git $AGENT_DIR
+cd $AGENT_DIR
+sudo git checkout main  # Or specific commit/tag
 ```
-###  Restart Service
+
+### 3.2 Configure Python Environment
+
 ```
-sudo systemctl restart rabbitmq-server
+sudo python3 -m venv $AGENT_DIR/venv
+sudo $AGENT_DIR/venv/bin/pip install -r $AGENT_DIR/requirements.txt
 ```
 
-### Access the Management UI
+### 3.3 Create Agent Configuration
 
--   **URL**:  [http://localhost:15672](http://localhost:15672/)
-    
--   **Credentials**:
-    
-    -   Username:  `guest`
-        
-    -   Password:  `guest`
+Create  `$AGENT_DIR/rabbit_config.py`  with:
+
+```
+# rabbit_config.py
+host = 'localhost'           # Or your cluster host
+port = 5672
+vhost = '$CELERY_VHOST'      # Use actual vhost name
+user = '$CELERY_USER'        # Celery username
+password = '$CELERY_PASSWORD'
+```
 
-### Add Vhost in **rabbit_config.py**
+### 3.4 Systemd Service Setup
 
 ```
-RABBITMQ = {
-    'HOST': 'localhost',
-    'PORT': 5672,
-    'VHOST': 'adduser',
-    'USER': 'reggie',
-    'PASSWORD': 'reggie'
-}
+sudo tee /etc/systemd/system/ood_account_agent.service <<'EOL'
+[Unit]
+Description=User Account Agent
+After=rabbitmq-server.service
+
+[Service]
+Type=simple
+User=root
+WorkingDirectory=/cm/shared/rabbitmq_agents
+ExecStart=/cm/shared/rabbitmq_agents/venv/bin/python agent_main.py
+Restart=on-failure
+Environment="PYTHONUNBUFFERED=1"
+
+[Install]
+WantedBy=multi-user.target
+EOL
+
+sudo systemctl daemon-reload
+sudo systemctl enable --now ood_account_agent
 ```
 
-### Add Celery Vhost 
+## 4. Network Configuration
+### Disable Firewall (Testing Only)
 
 ```
-rabbitmqctl add_vhost adduser
-rabbitmqctl add_user reggie reggie
-rabbitmqctl set_permissions -p adduser reggie ".*" ".*" ".*"
+sudo systemctl stop firewalld
+sudo systemctl disable firewalld
 ```
 
-### WIP Configuration Steps
+## 5. Validation & Testing
+
+```
+# Verify Services 
+systemctl is-active rabbitmq-server ood_account_agent 
+
+# Check RabbitMQ Users  
+sudo rabbitmqctl list_users 
+
+# Inspect Agent Logs 
+journalctl -u ood_account_agent -f  --since  "5m ago"
+
+```
 
-1.  **Bind Queues to  `RegUsr`  Exchange**:  
-    Use these routing keys:
-    
-    -   `request<queuename>`
-        
-    -   `completed<queuename>`
-        
-    -   `verify<queuename>`  
-        _(Replace  `<queuename>`  with your queue’s name, e.g.,  `request_user_reg`)_
-        
-2.  **Deploy Agents**:
-    
-    -   Run the Web UI (`self_reg_app`) for user submissions.
-        
-    -   Execute  `create_account.py`  to process tasks (e.g., UID assignment).
-        
-3.  **Monitor Queues**:  
-    Use RabbitMQ’s management UI or CLI tools to check:
-    
-    -   `task_manager`  for workflow progress.
-        
-    -   `notify user`  for delivery status of emails/SMS.
-        
 
-----------
 
 ## Error Handling
 
-- 
GitLab


From 81b594bc9d7c6e8cbb638fc0525099d30cbb7d15 Mon Sep 17 00:00:00 2001
From: Krish Moodbidri <krish94@uab.edu>
Date: Mon, 5 May 2025 09:31:22 -0500
Subject: [PATCH 3/5] fixed code block in import security keys section

---
 README.md | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/README.md b/README.md
index 5110881..bbe1bb3 100644
--- a/README.md
+++ b/README.md
@@ -63,9 +63,11 @@ export CELERY_PASSWORD="celery_pass"           # Celery service password
 ### 1.1 Configure Package Repositories
 
 # Import security keys
+```
 sudo rpm --import https://github.com/rabbitmq/signing-keys/releases/download/2.0/rabbitmq-release-signing-key.asc
 sudo rpm --import https://packagecloud.io/rabbitmq/erlang/gpgkey
 sudo rpm --import https://packagecloud.io/rabbitmq/rabbitmq-server/gpgkey
+```
 
 # Erlang Repository (AlmaLinux 8)
 ```
-- 
GitLab


From 50649fec8d4e220563bf6051e34dd2b884a53671 Mon Sep 17 00:00:00 2001
From: Krish Moodbidri <krish94@uab.edu>
Date: Mon, 12 May 2025 14:18:41 -0500
Subject: [PATCH 4/5] Add systemd service files for ohpc_account_agent,
 ood_account_agent, and slurm_agent

---
 README.md | 60 +++++++++++++++++++++++++++++++++++++++++++++++--------
 1 file changed, 52 insertions(+), 8 deletions(-)

diff --git a/README.md b/README.md
index bbe1bb3..c686406 100644
--- a/README.md
+++ b/README.md
@@ -153,29 +153,73 @@ user = '$CELERY_USER'        # Celery username
 password = '$CELERY_PASSWORD'
 ```
 
-### 3.4 Systemd Service Setup
+### 3.4 Systemd Service Setup for All Agents
+OHPC Account Agent:
 
 ```
-sudo tee /etc/systemd/system/ood_account_agent.service <<'EOL'
+ssudo tee /etc/systemd/system/ohpc_account_agent.service <<EOL
 [Unit]
-Description=User Account Agent
 After=rabbitmq-server.service
 
 [Service]
 Type=simple
+StartLimitInterval=0
+Restart=on-failure
 User=root
-WorkingDirectory=/cm/shared/rabbitmq_agents
-ExecStart=/cm/shared/rabbitmq_agents/venv/bin/python agent_main.py
+WorkingDirectory=/cm/shared/rabbitmq_agents/dev_rmq_agents
+Environment="PYTHONPATH=/cm/shared/rabbitmq_agents/"
+Environment="PATH=/cm/shared/rabbitmq_agents/dev_rmq_agents/venv/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin"
+ExecStart=/cm/shared/rabbitmq_agents/venv/bin/python -u ohpc_account_create.py
+
+[Install]
+WantedBy=multi-user.target
+EOL
+```
+
+OOD Account Agent:
+
+```
+sudo tee /etc/systemd/system/ood_account_agent.service <<EOL
+[Unit]
+After=rabbitmq-server.service
+
+[Service]
+Type=simple
+StartLimitInterval=0
 Restart=on-failure
-Environment="PYTHONUNBUFFERED=1"
+User=root
+WorkingDirectory=/cm/shared/rabbitmq_agents/dev_rmq_agents
+Environment="PYTHONPATH=/cm/shared/rabbitmq_agents/"
+Environment="PATH=/cm/shared/rabbitmq_agents/dev_rmq_agents/venv/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin"
+ExecStart=/cm/shared/rabbitmq_agents/venv/bin/python -u ood_account_create.py
 
 [Install]
 WantedBy=multi-user.target
 EOL
+```
+
+Slurm Agent:
 
-sudo systemctl daemon-reload
-sudo systemctl enable --now ood_account_agent
 ```
+sudo tee /etc/systemd/system/slurm_agent.service <<EOL
+[Unit]
+After=rabbitmq-server.service
+
+[Service]
+Type=simple
+StartLimitInterval=0
+Restart=on-failure
+User=root
+WorkingDirectory=/cm/shared/rabbitmq_agents/dev_rmq_agents
+Environment="PYTHONPATH=/cm/shared/rabbitmq_agents/"
+Environment="PATH=/cm/shared/rabbitmq_agents/dev_rmq_agents/venv/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin"
+ExecStart=/cm/shared/rabbitmq_agents/venv/bin/python -u slurm_agent.py
+
+[Install]
+WantedBy=multi-user.target
+EOL
+```
+
 
 ## 4. Network Configuration
 ### Disable Firewall (Testing Only)
-- 
GitLab


From c6b96aa51c183431399938d51c3ed339b56e2414 Mon Sep 17 00:00:00 2001
From: Krish Moodbidri <krish94@uab.edu>
Date: Mon, 12 May 2025 15:04:49 -0500
Subject: [PATCH 5/5] fixed typo

---
 README.md | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/README.md b/README.md
index c686406..6f36fd9 100644
--- a/README.md
+++ b/README.md
@@ -157,7 +157,7 @@ password = '$CELERY_PASSWORD'
 OHPC Account Agent:
 
 ```
-ssudo tee /etc/systemd/system/ohpc_account_agent.service <<EOL
+sudo tee /etc/systemd/system/ohpc_account_agent.service <<EOL
 [Unit]
 After=rabbitmq-server.service
 
-- 
GitLab