diff --git a/analytics-service/c8y_agent.py b/analytics-service/c8y_agent.py index fead484..55a6885 100644 --- a/analytics-service/c8y_agent.py +++ b/analytics-service/c8y_agent.py @@ -1,14 +1,28 @@ import logging +import requests from dotenv import load_dotenv from c8y_api.app import MultiTenantCumulocityApp from c8y_api.model import Binary import json +# These two lines enable debugging at httplib level (requests->urllib3->http.client) +# You will see the REQUEST, including HEADERS and DATA, and RESPONSE with HEADERS but without DATA. +# The only thing missing will be the response.body which is not logged. +# import http.client as http_client + +# http_client.HTTPConnection.debuglevel = 1 +# # You must initialize logging, otherwise you'll not see debug output. +# logging.basicConfig() +# logging.getLogger().setLevel(logging.DEBUG) +# requests_log = logging.getLogger("requests.packages.urllib3") +# requests_log.setLevel(logging.DEBUG) +# requests_log.propagate = True + class C8YAgent: def __init__(self): self._logger = logging.getLogger("C8YAgent") - self._logger.setLevel(logging.INFO) + self._logger.setLevel(logging.DEBUG) load_dotenv() # c8y self.c8yapp = MultiTenantCumulocityApp() @@ -25,21 +39,12 @@ def upload_extension(self, extension_name, ext_file, request_headers): return b.id def restart_cep(self,request_headers): - result = {} try: - self._logger.info(f"Restarted CEP!") - # self.c8yapp.get_tenant_instance(headers=request_headers).put(resource="/service/cep/restart", json="") - # self.c8yapp.bootstrap_instance.put(resource="/service/cep/restart", json="") - self.c8yapp.bootstrap_instance.put(resource="/service/cep/restart", json={}) + self._logger.info(f"Restarting CEP ...") + self.c8yapp.get_tenant_instance(headers=request_headers).put(resource="/service/cep/restart", json={}) except Exception as e: self._logger.error(f"Ignoring exceptiom!", exc_info=True) - # try: - # self._logger.info(f"Restarted CEP Format 2") - # result = self.c8y_client.put(resource="/service/cep/restart", json={}) - # except: - # self._logger.info(f"Restarted CEP Format 3") - # result = self.c8y_client.put( - # resource="/service/cep/restart", json=json.dumps({}) - # ) + # for keys,values in request_headers.items(): + # self._logger.info(f"Headers: {keys} {values}") self._logger.info(f"Restarted CEP!") diff --git a/analytics-service/cumulocity.json b/analytics-service/cumulocity.json index 916db8f..4661fea 100644 --- a/analytics-service/cumulocity.json +++ b/analytics-service/cumulocity.json @@ -10,7 +10,8 @@ "ROLE_OPTION_MANAGEMENT_ADMIN", "ROLE_INVENTORY_ADMIN", "ROLE_INVENTORY_READ", - "ROLE_INVENTORY_CREATE" + "ROLE_INVENTORY_CREATE", + "ROLE_CEP_MANAGEMENT_ADMIN" ], "roles": [] } diff --git a/analytics-service/flask_wrapper.py b/analytics-service/flask_wrapper.py index 3b29cb2..e3209a3 100644 --- a/analytics-service/flask_wrapper.py +++ b/analytics-service/flask_wrapper.py @@ -31,6 +31,12 @@ def health(): return '{"status":"UP"}' +# this endpoint was only exposed for test purposes +# @app.route("/service/cep/restart", methods=["PUT"]) +# def restart(): +# agent.restart_cep(request_headers=request.headers) +# return f"OK", 200 + # download the content from github # params: # url url of monitor to download @@ -90,19 +96,9 @@ def create_extension(): logger.info(f"... in temp dir: {work_temp_dir}") # step 1: download all monitors for monitor in monitors: - # organization, repository_name, file_path, file_name = extract_path( - # monitor - # ) - # logger.info( - # f"File ( path / file_name ) : ({file_path} / {file_name} )" - # ) - - # get repository - # repo = gh.get_repo(f"{organization}/{repository_name}") # get the contents of the file try: - # file_content = repo.get_contents(file_path).decoded_content file_name = extract_raw_path(monitor) monitor_code = requests.get(monitor, allow_redirects=True) diff --git a/analytics-ui/package-lock.json b/analytics-ui/package-lock.json index 5ae28dd..b4d7fcf 100644 --- a/analytics-ui/package-lock.json +++ b/analytics-ui/package-lock.json @@ -1,12 +1,12 @@ { "name": "analytics-extension", - "version": "2.1.6", + "version": "2.1.8", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "analytics-extension", - "version": "2.1.6", + "version": "2.1.8", "hasInstallScript": true, "license": "ISC", "dependencies": { diff --git a/analytics-ui/package.json b/analytics-ui/package.json index ae93767..3db4550 100644 --- a/analytics-ui/package.json +++ b/analytics-ui/package.json @@ -1,6 +1,6 @@ { "name": "analytics-extension", - "version": "2.1.7", + "version": "2.1.8", "description": "Extends the standard Cumulocity administration web application with a dialog to add Analytics Builder extensions.", "repository": { "type": "git", diff --git a/analytics-ui/src/analytics/manage/extension-details.component.html b/analytics-ui/src/analytics/manage/extension-details.component.html index bd80800..27b9420 100644 --- a/analytics-ui/src/analytics/manage/extension-details.component.html +++ b/analytics-ui/src/analytics/manage/extension-details.component.html @@ -37,16 +37,16 @@
Block Name | +Block Name | +Block Category | Block Description | -Block Category | |
---|---|---|---|---|---|
{{ block.id }} | -{{ block.description }} | -{{ block.category }} | +{{ block.id }} | +{{ block.category }} | +{{ block.description }} |