Ejemplo n.º 1
0
def update_app_features(app_id, feature_name):
    application = appstate.get_app_by_id(app_id)
    if application is None:
        return util.ensure_document_found(None)
    if feature_name != FEATURE_NAME["INTERFERENCE"] and feature_name != FEATURE_NAME["BOTTLENECK"] and feature_name != \
            FEATURE_NAME["EFFICIENCY"]:
        return util.error_response(f"{feature_name} is not valid feature name", 400)
    if "management_features" not in application:
        return util.error_response(f"management features do not exist in application {app_id}", 400)

    new_feature = request.get_json()
    if "name" not in new_feature:
        return util.error_response(f"name field is not exist in update feature", 400)
    new_feature_name = new_feature["name"]
    if new_feature_name != feature_name:
        return util.error_response(f"Input json does not have the correct feature name", 400)

    for idx, feature in enumerate(application['management_features']):
        if feature["name"] == feature_name:
            break
        else:
            idx = -1
    if idx == -1:
        application['management_features'].append(new_feature)
    else:
        application['management_features'][idx] = new_feature
    return util.update_and_return_doc(app_id, application)
Ejemplo n.º 2
0
def get_app_all_features(app_id):
    application = appstate.get_app_by_id(app_id)
    if application is None:
        return util.ensure_document_found(None)
    if "management_features" not in application:
        return util.error_response(f"management_features are not found", 400)
    return util.ensure_document_found(application['management_features'])
Ejemplo n.º 3
0
def update_app_state(app_id):
    app = appstate.get_app_by_id(app_id)
    if app is None:
        return util.ensure_document_found(None)

    state_json = request.get_json()
    state = state_json["state"]
    if state != APP_STATE["REGISTERED"] and state != APP_STATE["UNREGISTERED"] and state != APP_STATE["ACTIVE"]:
        return util.error_response(f"{state} is not valid state", 400)

    previous_state = app["state"]
    app["state"] = state

    updated_doc = appstate.update_and_get_app(app_id, app)
    if not updated_doc:
        return util.error_response(f"Could not update app {app_id}.", 404)

    # NOTE: Currently the UI is only calling this generic update API to update SLO and k8s objects.
    # Therefore we have to intercept here to start the diagnosis flow, since we need app SLO
    # to start it.
    # TODO: We should only try to start the diagnosis flow once, and also it's not gurantee we
    # have all the information we need already....
    if "slo" in updated_doc:
        if updated_doc["state"] == APP_STATE["ACTIVE"]:
            Analyzer().diagnosis.run_new_app(app_id, updated_doc)
        elif previous_state == APP_STATE["ACTIVE"] and updated_doc["state"] != APP_STATE["ACTIVE"]:
            Analyzer().diagnosis.stop_app(app_id)

    result = jsonify(data=updated_doc)
    result.status_code = 200
    return result
Ejemplo n.º 4
0
def get_app_slo(app_id):
    application = appstate.get_app_by_id(app_id)
    if application is None:
        return util.ensure_document_found(None)
    if "slo" not in application:
        return util.error_response(f"SLO is not found", 400)
    return util.ensure_document_found(application['slo'])
Ejemplo n.º 5
0
def add_app_features(app_id):
    application = appstate.get_app_by_id(app_id)
    if application is None:
        return util.ensure_document_found(None)
    if "management_features" in application:
        return util.error_response(f"management features already exist in application {app_id}", 400)

    features = request.get_json()
    return util.update_and_return_doc(app_id, {"management_features": features})
Ejemplo n.º 6
0
def add_app_slo(app_id):
    application = appstate.get_app_by_id(app_id)
    if application is None:
        return util.ensure_document_found(None)
    if "slo" in application:
        return util.error_response(f"SLO already set", 400)

    slo = request.get_json()
    return util.update_and_return_doc(app_id, {"slo": slo})
Ejemplo n.º 7
0
def update_app_slo(app_id):
    application = appstate.get_app_by_id(app_id)
    if application is None:
        return util.ensure_document_found(None)
    if "slo" not in application:
        return util.error_response(f"SLO is not added in application: {app_id}", 400)

    application['slo'] = request.get_json()
    return util.update_and_return_doc(app_id, application)
Ejemplo n.º 8
0
def delete_app(app_id):
    # Method to keep app in internal system but with unregistered state.

    # Check for existence
    app = appstate.get_app_by_id(app_id)
    if not app:
        return util.error_response(f"Tried to delete app {app_id} but app not found.", 404)
    result = appstate.update_app(app_id, {"state": APP_STATE["UNREGISTERED"]})
    if result.modified_count > 0:
        return jsonify(status=200, deleted_id=app_id)
    return util.error_response(f"Could not delete app {app_id}.", 404)
Ejemplo n.º 9
0
def get_pod_names(app_id):
    app = appstate.get_app_by_id(app_id)
    if app is None:
        return util.ensure_document_found(None)
    pod_names = []
    for microservice in app["microservices"]:
        service_id = microservice["service_id"]
        microservice_doc = k8sservicestate.get_service(service_id)
        if microservice_doc is None:
            return util.error_response("Microservice with id %s not found" %
                                       service_id, 400)
        pod_names += microservice_doc["pods"]
    return jsonify(pod_names)
Ejemplo n.º 10
0
def interference_scores(app_id, service_name):
    application = appstate.get_app_by_id(app_id)
    if application is None:
        return util.ensure_document_found(None)

    cursor = metricdb[profiling_collection].find(
        {"appName": application["name"], "serviceInTest": service_name}
    ).sort("_id", DESCENDING).limit(1)
    try:
        profiling = next(cursor)
        data = util.get_radar_dataframe(profiling)
        del profiling["testResult"]
        return jsonify(data)
    except StopIteration:
        return util.ensure_document_found(None)
Ejemplo n.º 11
0
def service_profiling(app_id, service_name):
    application = appstate.get_app_by_id(app_id)
    if app is None:
        return util.ensure_document_found(None)

    cursor = metricdb[profiling_collection].find(
        {"appName": application["name"], "serviceInTest": service_name},
        {"appName": 0, "_id": 0},
    ).sort("_id", DESCENDING).limit(1)
    try:
        profiling = next(cursor)
        data = util.get_profiling_dataframe(profiling)
        del profiling["testResult"]
        profiling["results"] = data
        return jsonify(profiling)
    except StopIteration:
        return util.ensure_document_found(None)
Ejemplo n.º 12
0
def app_calibration(app_id):
    application = appstate.get_app_by_id(app_id)
    if app is None:
        return util.ensure_document_found(None)

    cursor = metricdb[calibration_collection].find(
        {"appName": application["name"]},
        {"appName": 0, "_id": 0},
    ).sort("_id", DESCENDING).limit(1)
    try:
        calibration = next(cursor)
        data = util.get_calibration_dataframe(calibration)
        del calibration["testResult"]
        calibration["results"] = data
        return jsonify(calibration)
    except StopIteration:
        return util.ensure_document_found(None)
Ejemplo n.º 13
0
def get_app_one_feature(app_id, feature_name):
    application = appstate.get_app_by_id(app_id)
    if application is None:
        return util.ensure_document_found(None)
    if feature_name != FEATURE_NAME["INTERFERENCE"] and feature_name != FEATURE_NAME["BOTTLENECK"] and feature_name != \
            FEATURE_NAME["EFFICIENCY"]:
        return util.error_response(f"{feature_name} is not valid feature name", 400)
    if "management_features" not in application:
        return util.error_response(f"management_features is not exist", 400)

    for idx, feature in enumerate(application['management_features']):
        if feature["name"] == feature_name:
            break
        else:
            idx = -1
    if idx == -1:
        return util.error_response(f'{feature_name} is not found', 400)
    else:
        return util.ensure_document_found(feature)
Ejemplo n.º 14
0
def get_app_state(app_id):
    app = appstate.get_app_by_id(app_id)
    if app is None:
        return util.ensure_document_found(None)
    return util.ensure_document_found({"state": app["state"]})
Ejemplo n.º 15
0
def get_app_info_by_id(app_id):
    application = appstate.get_app_by_id(app_id)
    return util.ensure_document_found(application)