Skip to content

Commit

Permalink
add proper error message when analytics engine is not started
Browse files Browse the repository at this point in the history
  • Loading branch information
ck-c8y committed Mar 19, 2024
1 parent 7902a1d commit 8e606d5
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 11 deletions.
41 changes: 31 additions & 10 deletions analytics-service/flask_wrapper.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import requests
from flask import Flask, request, send_file, make_response, jsonify
from flask import Flask, request, Response, send_file, make_response, jsonify
import logging

# from github import Github
Expand Down Expand Up @@ -72,11 +72,15 @@ def get_content(repository):
return response
except Exception as e:
logger.error(f"Exception when retrieving content extension!", exc_info=True)
return f"Bad request: {str(e)}", 400
resp = Response(
json.dumps({"message": f"Bad request: {str(e)}"}), mimetype="application/json"
)
resp.status_code = 400
return resp


@app.route("/extension", methods=["POST"])
def create_extension_zip ():
def create_extension_zip():
# sample url
# "https://api.github.com/repos/SoftwareAG/apama-analytics-builder-block-sdk/contents/samples/blocks/CreateEvent.mon?ref=rel/10.18.0.x"

Expand Down Expand Up @@ -159,7 +163,11 @@ def create_extension_zip ():

except Exception as e:
logger.error(f"Exception when creating extension!", exc_info=True)
return f"Bad request: {str(e)}", 400
resp = Response(
json.dumps({"message": f"Bad request: {str(e)}"}), mimetype="application/json"
)
resp.status_code = 400
return resp


# return the details for the extension
Expand Down Expand Up @@ -214,9 +222,19 @@ def get_extension_metadata():
@app.route("/cep/id", methods=["GET"])
def get_cep_operationobject_id():
result = agent.get_cep_operationobject_id(request_headers=request.headers)
if (result == None):
return f"Not found", 400
return jsonify(result)
if result == None:
resp = Response(
json.dumps({"message": "Not found"}), mimetype="application/json"
)
resp.status_code = 400
return resp

resp = Response(
json.dumps({"message": "Not found"}), mimetype="application/json"
)
resp.status_code = 400
return resp
# return jsonify(result)


# return status of cep ctrl microservice
Expand All @@ -226,12 +244,15 @@ def get_cep_operationobject_id():
@app.route("/cep/status", methods=["GET"])
def get_cep_ctrl_status():
result = agent.get_cep_ctrl_status(request_headers=request.headers)
if (result == None):
return f"Not found", 400
if result == None:
resp = Response(
json.dumps({"message": "Not found"}), mimetype="application/json"
)
resp.status_code = 400
return resp
return jsonify(result)



# this endpoint was only exposed for test purposes
# @app.route("/cep/restart", methods=["PUT"])
# def restart():
Expand Down
2 changes: 1 addition & 1 deletion analytics-ui/src/shared/analytics.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export const REPO_SAMPLES_BLOCKSDK = `${GITHUB_BASE}/repos/${REPO_SAMPLES_OWNER}
export const REPO_SAMPLES_CONTRIB_BLOCK = `${GITHUB_BASE}/repos/${REPO_SAMPLES_OWNER}/analytics-builder-blocks-contrib/contents/blocks`;
export const REPO_SAMPLES_CONTRIB_CUMULOCITY = `${GITHUB_BASE}/repos/${REPO_SAMPLES_OWNER}/analytics-builder-blocks-contrib/contents/cumulocity-blocks`;
export const REPO_SAMPLES_CONTRIB_SIMULATION = `${GITHUB_BASE}/repos/${REPO_SAMPLES_OWNER}/analytics-builder-blocks-contrib/contents/simulation-blocks`;
export const REPO_SAMPLES_ANALYTICS_MANAGEMENT = `${GITHUB_BASE}/repos/${REPO_SAMPLES_OWNER}//cumulocity-analytics-management/contents/repository/blocks`;
export const REPO_SAMPLES_ANALYTICS_MANAGEMENT = `${GITHUB_BASE}/repos/${REPO_SAMPLES_OWNER}/cumulocity-analytics-management/contents/repository/blocks`;
export const REPO_SAMPLES = [
{
id: uuidCustom(),
Expand Down
3 changes: 3 additions & 0 deletions analytics-ui/src/shared/analytics.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,9 @@ export class AnalyticsService {

async subscribeMonitoringChannel(): Promise<object> {
const cepOperationObjectId = await this.getCEP_OperationObjectId();
if (!cepOperationObjectId) {
this.alertService.warning('Analytics Engine is currently not started. Try again later ...');
}
const { data } = await this.inventoryService.detail(cepOperationObjectId);
this.cepOperationObject$.next(data);
console.log(
Expand Down

0 comments on commit 8e606d5

Please sign in to comment.