Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding pika authentication and sleep time to queue consumer #221

Closed
wants to merge 14 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.git/
venv*/
.tox/
16 changes: 7 additions & 9 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@ jobs:
steps:

- name: Check out sources
uses: actions/checkout@v4
uses: actions/checkout@v3

- name: Set up Python 3.9
uses: actions/setup-python@v5
uses: actions/setup-python@v4
with:
python-version: "3.9"
cache: "pip" # cache pip dependencies

- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install black==24.* isort==5.*
python -m pip install black isort

- name: Run "black --check"
run: |
Expand All @@ -39,12 +39,10 @@ jobs:
run: |
python -m isort --check --profile black .

# # Disable hadolint check until
# # https://github.com/hadolint/hadolint/issues/943 is solved.
# - name: Lint sdx-controller Dockerfile
# uses: hadolint/hadolint-action@v3.1.0
# with:
# dockerfile: Dockerfile
- name: Lint sdx-controller Dockerfile
uses: hadolint/hadolint-action@v3.1.0
with:
dockerfile: Dockerfile

- name: Lint bapm-server Dockerfile
uses: hadolint/hadolint-action@v3.1.0
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/images.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
uses: actions/checkout@v3

# Collect metadata for container image tags
# See https://github.com/docker/metadata-action
Expand Down
16 changes: 8 additions & 8 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ on:

permissions:
contents: read

jobs:
test:

Expand All @@ -28,9 +28,9 @@ jobs:
ports:
- 5672:5672
- 15672:15672

mongodb:
image: mongo:7.0.5
image: mongo:3.7
ports:
- 27017:27017
env:
Expand All @@ -46,12 +46,12 @@ jobs:
- "3.10"

steps:

- name: Check out code
uses: actions/checkout@v4

uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: 'pip' # cache pip dependencies
Expand Down Expand Up @@ -82,7 +82,7 @@ jobs:
SUB_QUEUE: 'sdx-controller-test-queue'
DB_NAME: 'sdx-controllder-test-db'
DB_CONFIG_TABLE_NAME: 'sdx-controller-test-table'
MONGODB_CONNSTRING: 'mongodb://guest:guest@localhost:27017/'
MONGODB_CONNSTRING: 'mongodb://guest:guest@localhost:27017/'
timeout-minutes: 3

- name: Send coverage data to coveralls.io
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,3 @@ dmypy.json
/*.sqlite3-wal

/db/*
/sdx_controller/_version.py
22 changes: 9 additions & 13 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
FROM python:3.9-slim-bullseye

RUN apt-get update \
&& apt-get -y upgrade \
&& apt-get install -y --no-install-recommends gcc python3-dev git \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* \
&& mkdir -p /usr/src/app
# RUN apt-get -y upgrade &&
RUN apt-get update && apt-get install -y --no-install-recommends gcc python3-dev git && apt-get clean && rm -rf /var/lib/apt/lists/*

RUN mkdir -p /usr/src/app

WORKDIR /usr/src/app

COPY requirements.txt /usr/src/app/

RUN pip3 install --no-cache-dir -r requirements.txt

WORKDIR /usr/src/app
COPY . /usr/src/app

# In order to make setuptools_scm work during container build, we
# temporarily bind-mount .git. Via
# https://github.com/pypa/setuptools_scm/issues/77#issuecomment-844927695
RUN --mount=source=.git,target=.git,type=bind \
pip install --no-cache-dir .[wsgi]

EXPOSE 8080

ENTRYPOINT ["python3"]
CMD ["-m", "uvicorn", "sdx_controller.app:asgi_app", "--host", "0.0.0.0", "--port", "8080"]
CMD ["-m", "swagger_server"]
30 changes: 7 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,37 +72,21 @@ $ sudo sh elastic-search-setup.sh

### Running with Docker Compose (recommended)

A `compose.yaml` is provided for bringing up SDX Controller and a
MongoDB instance, and a separate `compose.bapm.yml` is provided for
bringing up bapm-server and a single-node ElasticSearch instance.

To start/stop SDX Controller, from the project root directory, do:
A `docker-compose.yaml` is provided for bringing up run
sdx-controller, bapm-server, and a MongoDB instance used by
sdx-controller. From the project root directory, do:

```console
$ source .env
$ docker compose up --build
$ docker compose down
```

Navigate to http://localhost:8080/SDX-Controller/1.0.0/ui/ for testing
the API. The OpenAPI/Swagger definition should be available at
http://localhost:8080/SDX-Controller/1.0.0/openapi.json.

Similarly, to start/stop BAPM Server, do:

```
$ source .env
$ docker compose -f compose.bapm.yml up --build
$ docker compose -f compose.bapm.yml down
```
Use `docker compose down` to shut down the services.

To start/stop all the services together:

```
$ source .env
$ docker compose -f compose.yml -f compose.bapm.yml up --build
$ docker compose -f compose.yml -f compose.bapm.yml down
```

#### Building the container images

Expand Down Expand Up @@ -138,9 +122,9 @@ directory:
```console
$ python3 -m venv venv --upgrade-deps
$ source ./venv/bin/activate
$ pip3 install [--editable] .
$ pip3 install -r requirements.txt
$ source .env
$ flask --app sdx_controller.app:app run --debug
$ python3 -m swagger_server
```

### Test topology files and connection requests
Expand All @@ -165,7 +149,7 @@ with Docker:

```console
$ docker run --rm -d --name rabbitmq -p 5672:5672 -p 15672:15672 rabbitmq:latest
$ docker run --rm -d --name mongo -p 27017:27017 -e MONGO_INITDB_ROOT_USERNAME=guest -e MONGO_INITDB_ROOT_PASSWORD=guest mongo:7.0.5
$ docker run --rm -d --name mongo -p 27017:27017 -e MONGO_INITDB_ROOT_USERNAME=guest -e MONGO_INITDB_ROOT_PASSWORD=guest mongo:3.7
```

Some environment variables are expected to be set for the tests to
Expand Down
15 changes: 8 additions & 7 deletions bapm_server/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,14 @@ def start_consumer(thread_queue, es):
t1.start()

while True:
data = thread_queue.get()
if is_json(data):
resp = es.index(index="measurement-index", id=MSG_ID, document=data)
print(resp["result"])
MSG_ID += 1
else:
logger.info("Received non-JSON data. Not saving to ElasticSearch.")
if not thread_queue.empty():
data = thread_queue.get()
if is_json(data):
resp = es.index(index="measurement-index", id=MSG_ID, document=data)
print(resp["result"])
MSG_ID += 1
else:
logger.info("Received non-JSON data. Not saving to ElasticSearch.")


def main():
Expand Down
44 changes: 0 additions & 44 deletions compose.bapm.yml

This file was deleted.

38 changes: 22 additions & 16 deletions compose.yml → docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ version: '3.8'

services:

mongodb:
# See https://hub.docker.com/_/mongo/ for documentation about
# MongoDB Docker images.
image: mongo:7.0.5
# See https://hub.docker.com/_/mongo/ for documentation about
# MongoDB Docker images.
mongodb-service:
image: mongo:3.7
ports:
- ${MONGO_PORT}:${MONGO_PORT}
environment:
MONGO_INITDB_ROOT_USERNAME: ${MONGO_INITDB_ROOT_USERNAME}
MONGO_INITDB_ROOT_PASSWORD: ${MONGO_INITDB_ROOT_PASSWORD}
MONGODB_DATA_DIR: ${MONGODB_DATA_DIR}
volumes:
# See https://docs.docker.com/storage/volumes/
#
Expand All @@ -21,35 +22,40 @@ services:
- type: volume
source: mongodb
target: /data/db:Z
# healthcheck:
# test: ["CMD", "mongo", "--eval", "db.version()"]
# interval: 10s
# timeout: 5s
# retries: 3

sdx-controller:
sdx-controller-service:
image: sdx-controller
depends_on:
mongodb:
# Anther condition is `service_healthy`, and it will require
# the `healthcheck` above.
condition: service_started
- mongodb-service
tty: true
build: ./
ports:
- 8080:8080
environment:
# Use mongodb service specified above. Note that we do not use
# Use mongodb-service specified above. Note that we do not use
# the same MONGODB_CONNSTRING variable from .env here, because
# that is helpful for running unit/integration tests.
- MONGODB_CONNSTRING=mongodb://${MONGO_INITDB_ROOT_USERNAME}:${MONGO_INITDB_ROOT_PASSWORD}@mongodb:${MONGO_PORT}/
- MONGODB_CONNSTRING=mongodb://${MONGO_INITDB_ROOT_USERNAME}:${MONGO_INITDB_ROOT_PASSWORD}@${MONGO_HOST}:${MONGO_PORT}/
- SDX_HOST=${SDX_HOST}
- SDX_PORT=${SDX_PORT}
- SDX_VERSION=${SDX_VERSION}
- MQ_HOST=${MQ_HOST}
- SUB_TOPIC=${SUB_TOPIC}
- SUB_QUEUE=${SUB_QUEUE}
- DB_NAME=${DB_NAME}
- DB_CONFIG_TABLE_NAME=${DB_CONFIG_TABLE_NAME}

bapm-server-service:
image: bapm-server
tty: true
build: ./bapm_server
environment:
- ES_HOST=${ES_HOST}
- ES_PORT=${ES_PORT}
- BAPM_MQ_HOST=${BAPM_MQ_HOST}
- BAPM_EXCHANGE=${BAPM_EXCHANGE}
- BAPM_QUEUE=${BAPM_QUEUE}
- BAPM_ROUTING_KEY=${BAPM_ROUTING_KEY}

volumes:
mongodb:
1 change: 0 additions & 1 deletion env.template
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- conf -*-
# SDX Controller settings.
export SDX_HOST="localhost"
export SDX_PORT="8080"
Expand Down
52 changes: 52 additions & 0 deletions git_push.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/bin/sh
# ref: https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/
#
# Usage example: /bin/sh ./git_push.sh wing328 swagger-petstore-perl "minor update"

git_user_id=$1
git_repo_id=$2
release_note=$3

if [ "$git_user_id" = "" ]; then
git_user_id="GIT_USER_ID"
echo "[INFO] No command line input provided. Set \$git_user_id to $git_user_id"
fi

if [ "$git_repo_id" = "" ]; then
git_repo_id="GIT_REPO_ID"
echo "[INFO] No command line input provided. Set \$git_repo_id to $git_repo_id"
fi

if [ "$release_note" = "" ]; then
release_note="Minor update"
echo "[INFO] No command line input provided. Set \$release_note to $release_note"
fi

# Initialize the local directory as a Git repository
git init

# Adds the files in the local repository and stages them for commit.
git add .

# Commits the tracked changes and prepares them to be pushed to a remote repository.
git commit -m "$release_note"

# Sets the new remote
git_remote=`git remote`
if [ "$git_remote" = "" ]; then # git remote not defined

if [ "$GIT_TOKEN" = "" ]; then
echo "[INFO] \$GIT_TOKEN (environment variable) is not set. Using the git credential in your environment."
git remote add origin https://github.com/${git_user_id}/${git_repo_id}.git
else
git remote add origin https://${git_user_id}:${GIT_TOKEN}@github.com/${git_user_id}/${git_repo_id}.git
fi

fi

git pull origin master

# Pushes (Forces) the changes in the local repository up to the remote repository
echo "Git pushing to https://github.com/${git_user_id}/${git_repo_id}.git"
git push origin master 2>&1 | grep -v 'To https'

Loading
Loading