diff --git a/demo-workflows/requirements.txt b/demo-workflows/requirements.txt index 28d2925..d335861 100644 --- a/demo-workflows/requirements.txt +++ b/demo-workflows/requirements.txt @@ -3,5 +3,5 @@ marshmallow-dataclass==8.5.3 jinja2==3.0.3 python_graphql_client==0.4.3 influxdb_client==1.26.0 -frinx-conductor-client==1.0.5 -frinx-conductor-workers==1.0.5 +frinx-conductor-client==1.0.5 +frinx-conductor-workers==1.0.6 diff --git a/demo-workflows/workers/importDevices.py b/demo-workflows/workers/importDevices.py index 9d01a6c..8f0eb45 100755 --- a/demo-workflows/workers/importDevices.py +++ b/demo-workflows/workers/importDevices.py @@ -4,10 +4,9 @@ from sys import argv from python_graphql_client import GraphqlClient import os -from frinx_conductor_workers.frinx_rest import x_tenant_id +from frinx_conductor_workers.frinx_rest import x_tenant_id, inventory_url_base # graphql client settings -inventory_url = "http://inventory:8000/graphql" inventory_headers = { "Accept-Encoding": "gzip, deflate, br", "Content-Type": "application/json", @@ -17,7 +16,7 @@ "DNT": "1" } -client = GraphqlClient(endpoint=inventory_url, headers=inventory_headers) +client = GraphqlClient(endpoint=inventory_url_base, headers=inventory_headers) def execute(body, variables): diff --git a/demo-workflows/workers/influx_db.py b/demo-workflows/workers/influx_db.py index 2347efb..cbb5605 100644 --- a/demo-workflows/workers/influx_db.py +++ b/demo-workflows/workers/influx_db.py @@ -3,8 +3,8 @@ from influxdb_client import InfluxDBClient, BucketsApi from influxdb_client.client.write_api import SYNCHRONOUS +from frinx_conductor_workers.frinx_rest import influxdb_url_base -influxdb_url="http://influxdb:8086" # You can generate an API token from the "API Tokens Tab" in the UI token = os.getenv("DOCKER_INFLUXDB_INIT_ADMIN_TOKEN","eyJrIjoiN09MSVpVZjlVRG1xNHlLNXpVbmZJOXFLWU1GOXFxNEIiLCJuIjoic3Nzc3MiLCJpZCI6MX0") org = os.getenv("DOCKER_INFLUXDB_INIT_ORG","frinx-machine") @@ -15,19 +15,19 @@ def create_bucket_if_not_exist(task): bucket_name = task['inputData']['bucket'] if bucket_name is '': - return {'status': 'FAILED', 'output': {'url': influxdb_url, 'response_code': 500, 'response_body': "Failed"}, 'logs': []} + return {'status': 'FAILED', 'output': {'url': influxdb_url_base, 'response_code': 500, 'response_body': "Failed"}, 'logs': []} - with InfluxDBClient(url=influxdb_url, token=token, org=org) as client: + with InfluxDBClient(url=influxdb_url_base, token=token, org=org) as client: bucket_api=client.buckets_api() bucket = bucket_api.find_bucket_by_name(bucket_name) if bucket != None: print(bucket.name) - return {'status': 'COMPLETED', 'output': {'url': influxdb_url, 'response_code': 200, 'bucket_name': bucket.name, 'response_body': "Bucket with name " + bucket.name + " exist before"}, 'logs': []} + return {'status': 'COMPLETED', 'output': {'url': influxdb_url_base, 'response_code': 200, 'bucket_name': bucket.name, 'response_body': "Bucket with name " + bucket.name + " exist before"}, 'logs': []} else: bucket = bucket_api.create_bucket(bucket_name=bucket_name, org=org) print(bucket.name) - return {'status': 'COMPLETED', 'output': {'url': influxdb_url, 'response_code': 200, 'bucket_name': bucket.name, 'response_body': "Created new bucket with name " + bucket.name}, 'logs': []} + return {'status': 'COMPLETED', 'output': {'url': influxdb_url_base, 'response_code': 200, 'bucket_name': bucket.name, 'response_body': "Created new bucket with name " + bucket.name}, 'logs': []} except: return {'status': 'FAILED', 'output': {'url': "influxdb", 'response_code': 500, 'response_body': "Creating of bucket was unsucessful"}, 'logs': []} @@ -40,7 +40,7 @@ def store_ops_data(task): fields = task['inputData']['fields'] bucket = task['inputData']['bucket'] - with InfluxDBClient(url=influxdb_url, token=token, org=org) as client: + with InfluxDBClient(url=influxdb_url_base, token=token, org=org) as client: write_api = client.write_api(write_options=SYNCHRONOUS) diff --git a/demo-workflows/workers/inventory_worker.py b/demo-workflows/workers/inventory_worker.py index 892c91a..d895666 100644 --- a/demo-workflows/workers/inventory_worker.py +++ b/demo-workflows/workers/inventory_worker.py @@ -2,10 +2,9 @@ import copy import math import json -from frinx_conductor_workers.frinx_rest import x_tenant_id +from frinx_conductor_workers.frinx_rest import x_tenant_id, inventory_url_base # graphql client settings -inventory_url = "http://inventory:8000/graphql" inventory_headers = { "Accept-Encoding": "gzip, deflate, br", "Content-Type": "application/json", @@ -16,7 +15,7 @@ "Keep-Alive": "timeout=5" } -client = GraphqlClient(endpoint=inventory_url, headers=inventory_headers) +client = GraphqlClient(endpoint=inventory_url_base, headers=inventory_headers) def execute(body, variables): @@ -233,16 +232,16 @@ def installed_device(task): if response.get('errors'): body['message'] = response['errors'][0]['message'] - return {'status': 'FAILED', 'output': {'url': inventory_url, 'response_code': 404, 'response_body': body}, + return {'status': 'FAILED', 'output': {'url': inventory_url_base, 'response_code': 404, 'response_body': body}, 'logs': []} if response.get('data'): body['name'] = response['data']['devices']['edges'] - return {'status': 'COMPLETED', 'output': {'url': inventory_url, 'response_code': 200, 'response_body': body}, + return {'status': 'COMPLETED', 'output': {'url': inventory_url_base, 'response_code': 200, 'response_body': body}, 'logs': []} - return {'status': 'FAILED', 'output': {'url': inventory_url, 'response_code': 404, 'response_body': {'Workflow failed'}}, + return {'status': 'FAILED', 'output': {'url': inventory_url_base, 'response_code': 404, 'response_body': {'Workflow failed'}}, 'logs': []} @@ -254,7 +253,7 @@ def install_uninstall_device(task): if device_id is None: body = {"message": device_status} - return {'status': 'FAILED', 'output': {'url': inventory_url, 'response_code': 404, 'response_body': body}, + return {'status': 'FAILED', 'output': {'url': inventory_url_base, 'response_code': 404, 'response_body': body}, 'logs': []} variables = { @@ -284,13 +283,13 @@ def install_uninstall_device(task): body['message'] = response['errors'][0]['message'] if 'already been installed' not in body['message']: - return {'status': 'FAILED', 'output': {'url': inventory_url, 'response_code': 404, 'response_body': body}, + return {'status': 'FAILED', 'output': {'url': inventory_url_base, 'response_code': 404, 'response_body': body}, 'logs': []} if response.get('data'): body['name'] = response['data'][task_type]['device']['name'] - return {'status': 'COMPLETED', 'output': {'url': inventory_url, 'response_code': 200, 'response_body': body}, + return {'status': 'COMPLETED', 'output': {'url': inventory_url_base, 'response_code': 200, 'response_body': body}, 'logs': []} @@ -308,7 +307,7 @@ def install_uninstall_in_batch(task): body = {} if response.get('errors'): body['message'] = response['errors'][0]['message'] - return {'status': 'FAILED', 'output': {'url': inventory_url, 'response_code': 404, 'response_body': body}, + return {'status': 'FAILED', 'output': {'url': inventory_url_base, 'response_code': 404, 'response_body': body}, 'logs': []} if str(task['taskType']).find('uninstall') == -1: @@ -349,7 +348,7 @@ def install_uninstall_in_batch(task): device_status.update({device_id['node']['name']: per_device_params}) - return {'status': 'COMPLETED', 'output': {'url': inventory_url, 'response_code': 200, 'response_body': device_status}, + return {'status': 'COMPLETED', 'output': {'url': inventory_url_base, 'response_code': 200, 'response_body': device_status}, 'logs': []} @@ -369,7 +368,7 @@ def get_device_pages_ids(task): print(response) if response.get('errors'): body = {'message': response['errors'][0]['message']} - return {'status': 'FAILED', 'output': {'url': inventory_url, 'response_code': 404, 'response_body': body}, + return {'status': 'FAILED', 'output': {'url': inventory_url_base, 'response_code': 404, 'response_body': body}, 'logs': []} if response.get('data'): @@ -397,7 +396,7 @@ def get_device_pages_ids(task): print(e) break - return {'status': 'COMPLETED', 'output': {'url': inventory_url, 'response_code': 200, + return {'status': 'COMPLETED', 'output': {'url': inventory_url_base, 'response_code': 200, 'page_ids': page_loop, 'page_size': len(page_loop), "page_ids_count": len(page_ids)}, @@ -429,7 +428,7 @@ def page_device_dynamic_fork_tasks(task): taskReferenceName_id += 1 return {'status': 'COMPLETED', - 'output': {'url': inventory_url, 'dynamic_tasks_i': dynamic_tasks_i, 'dynamic_tasks': dynamic_tasks}, + 'output': {'url': inventory_url_base, 'dynamic_tasks_i': dynamic_tasks_i, 'dynamic_tasks': dynamic_tasks}, 'logs': []} def all_devices_fork_tasks(task): @@ -459,7 +458,7 @@ def all_devices_fork_tasks(task): dynamic_tasks_i.update({device_id: per_device_params}) return {'status': 'COMPLETED', - 'output': {'url': inventory_url, 'dynamic_tasks_i': dynamic_tasks_i, 'dynamic_tasks': dynamic_tasks}, + 'output': {'url': inventory_url_base, 'dynamic_tasks_i': dynamic_tasks_i, 'dynamic_tasks': dynamic_tasks}, 'logs': []} @@ -487,7 +486,7 @@ def add_cli_device(task): if response.get('errors'): body['message'] = response['errors'][0]['message'] - return {'status': 'FAILED', 'output': {'url': inventory_url, 'response_code': 404, 'response_body': body}, + return {'status': 'FAILED', 'output': {'url': inventory_url_base, 'response_code': 404, 'response_body': body}, 'logs': []} body = { @@ -496,7 +495,7 @@ def add_cli_device(task): "isInstalled": response['data']['addDevice']['device']['isInstalled'] } - return {'status': 'COMPLETED', 'output': {'url': inventory_url, 'response_code': 200, 'response_body': body}, + return {'status': 'COMPLETED', 'output': {'url': inventory_url_base, 'response_code': 200, 'response_body': body}, 'logs': []} @@ -531,7 +530,7 @@ def add_netconf_device(task): if response.get('errors'): body['message'] = response['errors'][0]['message'] - return {'status': 'FAILED', 'output': {'url': inventory_url, 'response_code': 404, 'response_body': body}, + return {'status': 'FAILED', 'output': {'url': inventory_url_base, 'response_code': 404, 'response_body': body}, 'logs': []} body = { @@ -540,7 +539,7 @@ def add_netconf_device(task): "isInstalled": response['data']['addDevice']['device']['isInstalled'] } - return {'status': 'COMPLETED', 'output': {'url': inventory_url, 'response_code': 200, 'response_body': body}, + return {'status': 'COMPLETED', 'output': {'url': inventory_url_base, 'response_code': 200, 'response_body': body}, 'logs': []}