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

implement scheduler to main.py #134

Merged
merged 4 commits into from
Oct 12, 2022
Merged
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 composefiles/swarm-fm-workflows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ services:
- UNICONFIG_URL_BASE=https://uniconfig:8181/rests
- INSTANCES_TO_SIMULATE=${INSTANCES_TO_SIMULATE}
- RUN_TESTTOOLS=${RUN_TESTTOOLS}
- TOPOLOGY_DISCOVERY_BACKUP_ENABLED=${TOPOLOGY_DISCOVERY_BACKUP_ENABLED}
entrypoint: ["/set_env_secrets.sh", "python3 main.py"]
secrets:
- frinx_auth
Expand Down
14 changes: 14 additions & 0 deletions demo-workflows/workers/constants/scheduler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
UNIFLOW_SCHEDULER_URL = "http://workflow-proxy:8088/schedule"

UNIFLOW_SCHEDULER_LIST = [
{
"Arangodb_create_backup_and_delete_old_backups": {
"workflowName": "Arangodb_create_backup_and_delete_old_backups",
"workflowVersion": "1",
"workflowContext": {"delete_age": "24"},
"name": "Arangodb_create_backup_and_delete_old_backups:1",
"cronString": "0 * * * *",
"enabled": True,
}
}
]
21 changes: 21 additions & 0 deletions demo-workflows/workers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

from importDevices import import_devices
from importDevices import import_blueprints
from constants.scheduler import UNIFLOW_SCHEDULER_LIST, UNIFLOW_SCHEDULER_URL

# Suppress InsecureRequestWarning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
Expand Down Expand Up @@ -124,6 +125,22 @@ def _configure_healthcheck(file: Path = HEALTCHCHEK_FILE) -> None:
pass


def _import_schedulers() -> dict:
"""
return: result_dict ex. {'Arangodb_create_backup_and_delete_old_backups:1': {'status_code': 200}}
"""
result_dict = {}
for scheduler_data in UNIFLOW_SCHEDULER_LIST:
# Convert dict values to dict
data = list(scheduler_data.values())[0]
# URL ex. http://workflow-proxy:8088/schedule/Arangodb_create_backup_and_delete_old_backups:1
response = requests.put(f"{UNIFLOW_SCHEDULER_URL}/{data['name']}",
data=json.dumps(data), headers=conductor_headers)
result_dict[data["name"]] = {"status_code": response.status_code}

return result_dict


def main():
configure_logging()
logger = logging.getLogger(__name__)
Expand All @@ -147,6 +164,10 @@ def main():
_import_blueprints()
logger.info("All blueprints are imported")

if int(os.getenv("TOPOLOGY_DISCOVERY_BACKUP_ENABLED")):
result_dict = _import_schedulers()
logger.info(f"Scheduler import status codes: {result_dict}")

_configure_healthcheck()
logger.debug("Health check is configured")

Expand Down
2 changes: 1 addition & 1 deletion demo-workflows/workers/topology_discovery_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import requests
import json

TOPOLOGY_DISCOVERY_BASE_URL = "http://fm_topology-discovery:5000/api"
TOPOLOGY_DISCOVERY_BASE_URL = "http://topology-discovery:5000/api"
TOPOLOGY_DISCOVERY_HEADERS = {"Content-Type": "application/json"}


Expand Down
8 changes: 7 additions & 1 deletion startup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ DESCRIPTION:
-h|--help Print this help and exit
-d|--debug Enable verbose

-ci|--clean-inventory Clean device inventory
-ci|--clean-inventory Clean device inventory
-tdb|--topology-discovery-backup Create Schedule for topology discovery backup WF (every 1 hour)


SAMPLE-TOPOLOGY Parameters:
-ad|--all-devices Run CLI and netconf devices
Expand All @@ -28,6 +30,7 @@ EOF
}

export RUN_TESTTOOLS="./scripts/run_cli_devices/run_devices_docker.sh"
export TOPOLOGY_DISCOVERY_BACKUP_ENABLED="0"
INSTANCES_TO_SIMULATE=""

function argumentsCheck {
Expand Down Expand Up @@ -55,6 +58,9 @@ function argumentsCheck {
-ci|--clean-inventory)
docker exec -it "$(docker ps -qf "name=fm_inventory-postgres")" psql -U postgres -a inventory -c 'delete from device_inventory;'
echo "Device inventory has been cleaned.";;
-tdb|--topology-discovery-backup)
export TOPOLOGY_DISCOVERY_BACKUP_ENABLED="1"
echo "Run scheduler for topology discovery arangodb backup";;
*)
echo "Unknow option: ${1}"
show_help
Expand Down