From a74666e819f2a84bfa71597b240f76952e6d5ec0 Mon Sep 17 00:00:00 2001 From: Alvaro Vega Date: Fri, 23 Dec 2016 10:02:00 +0100 Subject: [PATCH 01/20] add view scheme for metrics --- src/orchestrator/api/views.py | 67 +++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/src/orchestrator/api/views.py b/src/orchestrator/api/views.py index 1e63e498..2e01e4cc 100644 --- a/src/orchestrator/api/views.py +++ b/src/orchestrator/api/views.py @@ -2709,3 +2709,70 @@ def put(self, request): status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) + +class OrchMetrics_RESTView(APIView, IoTConf): + """ + { Read, Update } Orchestrator Common Metrics + """ + + def __init__(self): + IoTConf.__init__(self) + + def get(self, request): + + HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) + CORRELATOR_ID = self.getCorrelatorIdHeader(request) + reset = request.GET.get('reset', None) + + try: + # TO DO + result = {} + + + # Metrics + # incomingTransactions: number of requests consumed by the component. + # incomingTransactionRequestSize: total size (bytes) in requests associated to incoming transactions (“in” from the point of view of the component). + # incomingTransactionResponseSize: total size (bytes) in responses associated to incoming transactions (“out” from the point of view of the component). + # incomingTransacionError: number of incoming transactions resulting in error. + # serviceTime: average time to serve a transaction. + # outgoingTransactions: number of requests sent by the component. + # outgoingTransactionRequestSize: total size (bytes) in requests associated to outgoing transactions (“out” from the point of view of the component). + # outgoingTransactionResponseSize: total size (bytes) in responses associated to outgoing transactions (“in” from the point of view of the component). + # outgoingTransacionError: number of outgoing transactions resulting in error. + + + + + return Response(result, status=status.HTTP_200_OK, + headers={"Fiware-Correlator": CORRELATOR_ID}) + + except ParseError as error: + body = { + "error": "%s" % error.detail + } + return Response( + json.dumps(body), + status=status.HTTP_400_BAD_REQUEST, + headers={"Fiware-Correlator": CORRELATOR_ID} + ) + + def delete(self, request): + HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) + CORRELATOR_ID = self.getCorrelatorIdHeader(request) + + try: + # TO DO + result = {} + + return Response(result, status=status.HTTP_204_OK, + headers={"Fiware-Correlator": CORRELATOR_ID}) + + except ParseError as error: + body = { + "error": "%s" % error.detail + } + return Response( + json.dumps(body), + status=status.HTTP_400_BAD_REQUEST, + headers={"Fiware-Correlator": CORRELATOR_ID} + ) From c78c017e849d2a86522b08642487f6487cfb6248 Mon Sep 17 00:00:00 2001 From: Alvaro Vega Date: Fri, 23 Dec 2016 10:29:02 +0100 Subject: [PATCH 02/20] add new view to django router --- src/orchestrator/api/urls.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/orchestrator/api/urls.py b/src/orchestrator/api/urls.py index d8e61737..00443fec 100644 --- a/src/orchestrator/api/urls.py +++ b/src/orchestrator/api/urls.py @@ -42,7 +42,8 @@ SubServiceIoTAService_RESTView, IOTModuleActivation_RESTView, OrchVersion_RESTView, - OrchLogLevel_RESTView + OrchLogLevel_RESTView, + OrchMetrics_RESTView ) @@ -69,4 +70,5 @@ url(r'^service/(?P\w+)/trust[/]?$', Trust_RESTView.as_view(), name='new_trust_rest_view'), url(r'^version[/]?$', OrchVersion_RESTView.as_view(), name='orch_version_rest_view'), url(r'^admin/log?$', OrchLogLevel_RESTView.as_view(), name='orch_loglevel_rest_view'), + url(r'^admin/metrics?$', OrchMetrics_RESTView.as_view(), name='orch_metrics_rest_view'), ) From e2ce823366b31b0cd9bd90b43ce0e87012cdcee2 Mon Sep 17 00:00:00 2001 From: Alvaro Vega Date: Tue, 10 Jan 2017 10:35:21 +0100 Subject: [PATCH 03/20] retrieve service_name for metrics accounting --- src/orchestrator/api/views.py | 672 ++++++++++++------ .../commands/changeUserPassword.py | 2 +- .../commands/changeUserPasswordByHimself.py | 2 +- src/orchestrator/commands/createNewService.py | 2 +- .../commands/createNewServiceGroup.py | 6 +- .../commands/createNewServiceRole.py | 2 +- .../commands/createNewServiceUser.py | 2 +- .../commands/createNewSubService.py | 2 +- src/orchestrator/commands/createTrustToken.py | 2 +- src/orchestrator/commands/editService.py | 2 +- src/orchestrator/commands/editSubService.py | 2 +- .../commands/listAllRoleAssignments.py | 2 +- .../commands/listGroupRoleAssignments.py | 2 +- .../commands/listRoleAssignments.py | 2 +- .../commands/listSubServiceRoleAssignments.py | 2 +- .../commands/listUserRoleAssignments.py | 2 +- .../commands/printServiceGroups.py | 2 +- .../commands/printServiceIotModules.py | 2 +- .../commands/printServiceRolePolicies.py | 2 +- .../commands/printServiceRoles.py | 2 +- .../commands/printServiceUsers.py | 2 +- src/orchestrator/commands/printServices.py | 2 +- src/orchestrator/commands/printSubServices.py | 2 +- .../commands/registerSubServiceDevice.py | 2 +- .../commands/registerSubServiceEntity.py | 2 +- src/orchestrator/commands/removeService.py | 2 +- .../commands/removeServiceGroup.py | 2 +- .../commands/removeServiceRole.py | 2 +- .../commands/removeServiceRolePolicy.py | 2 +- .../commands/removeServiceUser.py | 2 +- src/orchestrator/commands/removeSubService.py | 2 +- src/orchestrator/core/flow/Domains.py | 23 +- src/orchestrator/core/flow/Groups.py | 123 +++- src/orchestrator/core/flow/Projects.py | 43 +- src/orchestrator/core/flow/Roles.py | 52 +- src/orchestrator/core/flow/Users.py | 23 +- src/orchestrator/core/flow/base.py | 2 +- .../core/flow/createNewService.py | 2 +- .../core/flow/createNewServiceRole.py | 3 +- .../core/flow/createNewServiceUser.py | 2 +- .../core/flow/createNewSubService.py | 2 +- .../core/flow/createTrustToken.py | 2 +- src/orchestrator/core/flow/removeUser.py | 11 +- src/orchestrator/core/flow/updateUser.py | 19 +- 44 files changed, 721 insertions(+), 322 deletions(-) diff --git a/src/orchestrator/api/views.py b/src/orchestrator/api/views.py index 2e01e4cc..685ca1c0 100644 --- a/src/orchestrator/api/views.py +++ b/src/orchestrator/api/views.py @@ -23,6 +23,7 @@ # import logging import json +import time from rest_framework.views import APIView from rest_framework.response import Response @@ -85,6 +86,14 @@ class Stats(object): num_get_userlist = 0 num_post_userlist = 0 + num_delete_group = 0 + num_put_group = 0 + num_get_group = 0 + num_post_group = 0 + + num_get_grouplist = 0 + num_post_grouplist = 0 + num_delete_role = 0 num_post_role = 0 num_get_role = 0 @@ -115,6 +124,36 @@ class Stats(object): num_api_errors = 0 num_flow_errors = 0 + service = {} + sum = {} + + def collectMetrics(self, service_start, service_name, request, response): + + # Metrics: + # incomingTransactions + # incomingTransactionRequestSize + # incomingTransactionResponseSize + # incomingTransacionError + # serviceTime + # outgoingTransactions + # outgoingTransactionRequestSize + # outgoingTransactionResponseSize + # outgoingTransacionError + + if not service_name in self.service: + self.service[service_name] = { + "incomingTransactions": 0, + "incomingTransactionRequestSize": 0, + "incomingTransactionResponseSize": 0, + "incomingTransacionError": 0, + "serviceTime": 0 + } + self.service[service_name]["incomingTransactions"] += 1 + self.service[service_name]["incomingTransactionRequestSize"] += len(json.dumps(request.data)) + self.service[service_name]["incomingTransactionResponseSize"] += len(json.dumps(response.data)) + self.service[service_name]["serviceTime"] += service_start - time.time() + + #Stats.sum[service] = { } class IoTConf(Stats): @@ -231,6 +270,8 @@ def __init__(self): def get(self, request, service_id=None): self.schema_name = "ServiceList" + service_start = time.time() + response = service_name = None HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) try: @@ -242,7 +283,7 @@ def get(self, request, service_id=None): CORRELATOR_ID = self.getCorrelatorId(flow, CORRELATOR_ID) if not service_id: # Get all domains - result = flow.domains( + result, service_name = flow.domains( request.DATA.get("DOMAIN_NAME", None), request.DATA.get("SERVICE_ADMIN_USER", None), request.DATA.get("SERVICE_ADMIN_PASSWORD", None), @@ -250,7 +291,7 @@ def get(self, request, service_id=None): HTTP_X_AUTH_TOKEN)) else: # Get detail of one domains - result = flow.get_domain( + result, service_name = flow.get_domain( request.DATA.get("DOMAIN_ID", service_id), request.DATA.get("DOMAIN_NAME", None), request.DATA.get("SERVICE_ADMIN_USER", None), @@ -259,24 +300,30 @@ def get(self, request, service_id=None): HTTP_X_AUTH_TOKEN)) if 'error' not in result: Stats.num_get_service += 1 - return Response(result, status=status.HTTP_200_OK, - headers={"Fiware-Correlator": CORRELATOR_ID}) + response = Response(result, status=status.HTTP_200_OK, + headers={"Fiware-Correlator": CORRELATOR_ID}) else: Stats.num_flow_errors += 1 - return Response(result['error'], - status=self.getStatusFromCode(result['code']), - headers={"Fiware-Correlator": CORRELATOR_ID}) + response = Response(result['error'], + status=self.getStatusFromCode(result['code']), + headers={"Fiware-Correlator": CORRELATOR_ID}) + except ParseError as error: Stats.num_api_errors += 1 - return Response( + response = Response( 'Input validation error - {0} {1}'.format(error.message, error.detail), status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) + self.collectMetrics(service_start, service_name, request, response) + return response + def put(self, request, service_id=None): + service_start = time.time() + response = service_name = None self.schema_name = "ServiceList" HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) @@ -287,7 +334,7 @@ def put(self, request, service_id=None): self.KEYSTONE_PORT, CORRELATOR_ID=CORRELATOR_ID) CORRELATOR_ID = self.getCorrelatorId(flow, CORRELATOR_ID) - result = flow.update_domain( + result, service_name = flow.update_domain( request.DATA.get("SERVICE_ID", service_id), request.DATA.get("SERVICE_NAME", None), request.DATA.get("SERVICE_ADMIN_USER", None), @@ -296,23 +343,27 @@ def put(self, request, service_id=None): request.DATA.get("NEW_SERVICE_DESCRIPTION", None)) if 'error' not in result: Stats.num_put_service += 1 - return Response(result, status=status.HTTP_200_OK, + response = Response(result, status=status.HTTP_200_OK, headers={"Fiware-Correlator": CORRELATOR_ID}) else: Stats.num_flow_errors += 1 - return Response(result['error'], + response = Response(result['error'], status=self.getStatusFromCode(result['code']), headers={"Fiware-Correlator": CORRELATOR_ID}) except ParseError as error: Stats.num_api_errors += 1 - return Response( + response = Response( 'Input validation error - {0} {1}'.format(error.message, error.detail), status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) + self.collectMetrics(service_start, service_name, request, response) + return response def delete(self, request, service_id=None): + service_start = time.time() + response = service_name = None self.schema_name = "ServiceList" HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) @@ -338,7 +389,7 @@ def delete(self, request, service_id=None): self.PERSEO_PORT, CORRELATOR_ID=CORRELATOR_ID) CORRELATOR_ID = self.getCorrelatorId(flow, CORRELATOR_ID) - result = flow.delete_domain( + result, service_name = flow.delete_domain( request.DATA.get("SERVICE_ID", service_id), request.DATA.get("SERVICE_NAME", None), request.DATA.get("SERVICE_ADMIN_USER", None), @@ -346,22 +397,23 @@ def delete(self, request, service_id=None): request.DATA.get("SERVICE_ADMIN_TOKEN", HTTP_X_AUTH_TOKEN)) if 'error' not in result: Stats.num_delete_service += 1 - return Response(result, status=status.HTTP_204_NO_CONTENT, + response = Response(result, status=status.HTTP_204_NO_CONTENT, headers={"Fiware-Correlator": CORRELATOR_ID}) else: Stats.num_flow_errors += 1 - return Response(result['error'], + response = Response(result['error'], status=self.getStatusFromCode(result['code']), headers={"Fiware-Correlator": CORRELATOR_ID}) except ParseError as error: Stats.num_api_errors += 1 - return Response( + response = Response( 'Input validation error - {0} {1}'.format(error.message, error.detail), status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) - + self.collectMetrics(service_start, service_name, request, response) + return response class ServiceCreate_RESTView(ServiceList_RESTView): """ @@ -375,6 +427,8 @@ def __init__(self): ServiceList_RESTView.__init__(self) def post(self, request, *args, **kw): + service_start = time.time() + response = service_name = None HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) try: @@ -387,7 +441,7 @@ def post(self, request, *args, **kw): self.KEYPASS_PORT, CORRELATOR_ID=CORRELATOR_ID) CORRELATOR_ID = self.getCorrelatorId(flow, CORRELATOR_ID) - result = flow.createNewService( + result, service_name = flow.createNewService( request.DATA.get("DOMAIN_NAME", None), request.DATA.get("DOMAIN_ADMIN_USER", None), request.DATA.get("DOMAIN_ADMIN_PASSWORD", None), @@ -398,24 +452,25 @@ def post(self, request, *args, **kw): request.DATA.get("NEW_SERVICE_ADMIN_USER"), request.DATA.get("NEW_SERVICE_ADMIN_PASSWORD"), request.DATA.get("NEW_SERVICE_ADMIN_EMAIL", None)) - if 'token' in result: Stats.num_post_service += 1 - return Response(result, status=status.HTTP_201_CREATED, + response = Response(result, status=status.HTTP_201_CREATED, headers={"Fiware-Correlator": CORRELATOR_ID}) else: Stats.num_flow_errors += 1 - return Response(result['error'], + response = Response(result['error'], status=self.getStatusFromCode(result['code']), headers={"Fiware-Correlator": CORRELATOR_ID}) except ParseError as error: Stats.num_api_errors += 1 - return Response( + response = Response( 'Input validation error - {0} {1}'.format(error.message, error.detail), status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) + self.collectMetrics(service_start, service_name, request, response) + return response class SubServiceList_RESTView(APIView, IoTConf): @@ -430,8 +485,9 @@ def __init__(self): IoTConf.__init__(self) def get(self, request, service_id=None, subservice_id=None): - self.schema_name = "SubServiceList" + service_start = time.time() + response = service_name = None HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) try: @@ -443,7 +499,7 @@ def get(self, request, service_id=None, subservice_id=None): CORRELATOR_ID = self.getCorrelatorId(flow, CORRELATOR_ID) if service_id: if not subservice_id: - result = flow.projects( + result, service_name = flow.projects( service_id, request.DATA.get("SERVICE_NAME", None), request.DATA.get("SERVICE_ADMIN_USER", None), @@ -452,8 +508,9 @@ def get(self, request, service_id=None, subservice_id=None): HTTP_X_AUTH_TOKEN)) else: # Get detail of subservice - result = flow.get_project( + result, service_name = flow.get_project( request.DATA.get("SERVICE_ID", service_id), + request.DATA.get("SERVICE_NAME", None), request.DATA.get("SUBSERVICE_ID", subservice_id), request.DATA.get("SERVICE_ADMIN_USER", None), request.DATA.get("SERVICE_ADMIN_PASSWORD", None), @@ -466,26 +523,29 @@ def get(self, request, service_id=None, subservice_id=None): if 'error' not in result: Stats.num_get_subservice += 1 - return Response(result, status=status.HTTP_200_OK, + response = Response(result, status=status.HTTP_200_OK, headers={"Fiware-Correlator": CORRELATOR_ID}) else: Stats.num_flow_errors += 1 - return Response(result['error'], + response = Response(result['error'], status=self.getStatusFromCode(result['code']), headers={"Fiware-Correlator": CORRELATOR_ID}) except ParseError as error: Stats.num_api_errors += 1 - return Response( + response = Response( 'Input validation error - {0} {1}'.format(error.message, error.detail), status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) + self.collectMetrics(service_start, service_name, request, response) + return response def put(self, request, service_id=None, subservice_id=None): - self.schema_name = "SubServiceList" + service_start = time.time() + response = service_name = None HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) try: @@ -497,7 +557,7 @@ def put(self, request, service_id=None, subservice_id=None): CORRELATOR_ID = self.getCorrelatorId(flow, CORRELATOR_ID) if service_id: if subservice_id: - result = flow.update_project( + result, service_name = flow.update_project( request.DATA.get("SERVICE_ID", service_id), request.DATA.get("SERVICE_NAME", None), request.DATA.get("SUBSERVICE_ID", subservice_id), @@ -513,25 +573,29 @@ def put(self, request, service_id=None, subservice_id=None): if 'error' not in result: Stats.num_put_subservice += 1 - return Response(result, status=status.HTTP_200_OK, + response = Response(result, status=status.HTTP_200_OK, headers={"Fiware-Correlator": CORRELATOR_ID}) else: Stats.num_flow_errors += 1 - return Response(result['error'], + response = Response(result['error'], status=self.getStatusFromCode(result['code']), headers={"Fiware-Correlator": CORRELATOR_ID}) except ParseError as error: Stats.num_api_errors += 1 - return Response( + response = Response( 'Input validation error - {0} {1}'.format(error.message, error.detail), status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) + self.collectMetrics(service_start, service_name, request, response) + return response def delete(self, request, service_id=None, subservice_id=None): self.schema_name = "SubServiceList" + service_start = time.time() + response = service_name = None HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) try: @@ -557,7 +621,7 @@ def delete(self, request, service_id=None, subservice_id=None): CORRELATOR_ID=CORRELATOR_ID) CORRELATOR_ID = self.getCorrelatorId(flow, CORRELATOR_ID) if service_id: - result = flow.delete_project( + result, service_name = flow.delete_project( request.DATA.get("SERVICE_ID", service_id), request.DATA.get("SERVICE_NAME", None), request.DATA.get("SUBSERVICE_ID", subservice_id), @@ -572,21 +636,23 @@ def delete(self, request, service_id=None, subservice_id=None): if 'error' not in result: Stats.num_delete_subservice += 1 - return Response(result, status=status.HTTP_204_NO_CONTENT, + response = Response(result, status=status.HTTP_204_NO_CONTENT, headers={"Fiware-Correlator": CORRELATOR_ID}) else: Stats.num_flow_errors += 1 - return Response(result['error'], + response = Response(result['error'], status=self.getStatusFromCode(result['code']), headers={"Fiware-Correlator": CORRELATOR_ID}) except ParseError as error: Stats.num_api_errors += 1 - return Response( + response = Response( 'Input validation error - {0} {1}'.format(error.message, error.detail), status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) + self.collectMetrics(service_start, service_name, request, response) + return response class SubServiceCreate_RESTView(SubServiceList_RESTView): @@ -599,6 +665,8 @@ def __init__(self): SubServiceList_RESTView.__init__(self) def post(self, request, service_id): + service_start = time.time() + response = service_name = None HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) try: @@ -618,7 +686,7 @@ def post(self, request, service_id): CORRELATOR_ID=CORRELATOR_ID) CORRELATOR_ID = self.getCorrelatorId(flow, CORRELATOR_ID) - result = flow.createNewSubService( + result, service_name = flow.createNewSubService( request.DATA.get("SERVICE_NAME", None), request.DATA.get("SERVICE_ID", service_id), request.DATA.get("SERVICE_ADMIN_USER", None), @@ -723,23 +791,24 @@ def post(self, request, service_id): if 'id' in result and ('error' not in result): Stats.num_post_subservice += 1 - return Response(result, status=status.HTTP_201_CREATED, + response = Response(result, status=status.HTTP_201_CREATED, headers={"Fiware-Correlator": CORRELATOR_ID}) else: Stats.num_flow_errors += 1 - return Response(result['error'], + response = Response(result['error'], status=self.getStatusFromCode(result['code']), headers={"Fiware-Correlator": CORRELATOR_ID}) except ParseError as error: Stats.num_api_errors += 1 - return Response( + response = Response( 'Input validation error - {0} {1}'.format(error.message, error.detail), status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) - + self.collectMetrics(service_start, service_name, request, response) + return response class User_RESTView(APIView, IoTConf): """ @@ -753,6 +822,8 @@ def __init__(self): IoTConf.__init__(self) def delete(self, request, service_id, user_id): + service_start = time.time() + response = service_name = None HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) try: @@ -762,7 +833,7 @@ def delete(self, request, service_id, user_id): self.KEYSTONE_PORT, CORRELATOR_ID=CORRELATOR_ID) CORRELATOR_ID = self.getCorrelatorId(flow, CORRELATOR_ID) - result = flow.removeUser( + result, service_name = flow.removeUser( request.DATA.get("SERVICE_NAME", None), request.DATA.get("SERVICE_ID", service_id), request.DATA.get("SERVICE_ADMIN_USER", None), @@ -772,23 +843,27 @@ def delete(self, request, service_id, user_id): request.DATA.get("USER_ID", user_id)) if 'error' not in result: Stats.num_delete_user += 1 - return Response(result, status=status.HTTP_204_NO_CONTENT, + response = Response(result, status=status.HTTP_204_NO_CONTENT, headers={"Fiware-Correlator": CORRELATOR_ID}) else: Stats.num_flow_errors += 1 - return Response(result['error'], + response = Response(result['error'], status=self.getStatusFromCode(result['code']), headers={"Fiware-Correlator": CORRELATOR_ID}) except ParseError as error: Stats.num_api_errors += 1 - return Response( + response = Response( 'Input validation error - {0} {1}'.format(error.message, error.detail), status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) + self.collectMetrics(service_start, service_name, request, response) + return response def put(self, request, service_id, user_id): + service_start = time.time() + response = service_name = None HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) try: @@ -798,33 +873,37 @@ def put(self, request, service_id, user_id): self.KEYSTONE_PORT, CORRELATOR_ID=CORRELATOR_ID) CORRELATOR_ID = self.getCorrelatorId(flow, CORRELATOR_ID) - result = flow.updateUser( - request.DATA.get("SERVICE_NAME"), + result, service_name = flow.updateUser( + request.DATA.get("SERVICE_NAME", None), request.DATA.get("SERVICE_ID", service_id), request.DATA.get("SERVICE_ADMIN_USER", None), request.DATA.get("SERVICE_ADMIN_PASSWORD", None), request.DATA.get("SERVICE_ADMIN_TOKEN", HTTP_X_AUTH_TOKEN), - request.DATA.get("USER_NAME"), + request.DATA.get("USER_NAME", None), request.DATA.get("USER_ID", user_id), request.DATA.get("USER_DATA_VALUE")) if 'error' not in result: Stats.num_put_user += 1 - return Response(result, status=status.HTTP_200_OK, + response = Response(result, status=status.HTTP_200_OK, headers={"Fiware-Correlator": CORRELATOR_ID}) else: Stats.num_flow_errors += 1 - return Response(result['error'], + response = Response(result['error'], status=self.getStatusFromCode(result['code']), headers={"Fiware-Correlator": CORRELATOR_ID}) except ParseError as error: Stats.num_api_errors += 1 - return Response( + response = Response( 'Input validation error - {0}'.format(error.message), status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) + self.collectMetrics(service_start, service_name, request, response) + return response def get(self, request, service_id, user_id): + service_start = time.time() + response = service_name = None HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) try: @@ -834,7 +913,9 @@ def get(self, request, service_id, user_id): self.KEYSTONE_PORT, CORRELATOR_ID=CORRELATOR_ID) CORRELATOR_ID = self.getCorrelatorId(flow, CORRELATOR_ID) - result = flow.user(request.DATA.get("SERVICE_ID", service_id), + result, service_name = flow.user( + request.DATA.get("SERVICE_ID", service_id), + request.DATA.get("SERVICE_NAME", None), request.DATA.get("USER_ID", user_id), request.DATA.get("SERVICE_ADMIN_USER", None), request.DATA.get("SERVICE_ADMIN_PASSWORD", None), @@ -842,23 +923,27 @@ def get(self, request, service_id, user_id): HTTP_X_AUTH_TOKEN)) if 'error' not in result: Stats.num_get_user += 1 - return Response(result, status=status.HTTP_200_OK, + response = Response(result, status=status.HTTP_200_OK, headers={"Fiware-Correlator": CORRELATOR_ID}) else: Stats.num_flow_errors += 1 - return Response(result['error'], + response = Response(result['error'], status=self.getStatusFromCode(result['code']), headers={"Fiware-Correlator": CORRELATOR_ID}) except ParseError as error: Stats.num_api_errors += 1 - return Response( + response = Response( 'Input validation error - {0} {1}'.format(error.message, error.detail), status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) + self.collectMetrics(service_start, service_name, request, response) + return response def post(self, request, service_id, user_id): + service_start = time.time() + response = service_name = None HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) try: @@ -868,7 +953,7 @@ def post(self, request, service_id, user_id): self.KEYSTONE_PORT, CORRELATOR_ID=CORRELATOR_ID) CORRELATOR_ID = self.getCorrelatorId(flow, CORRELATOR_ID) - result = flow.changeUserPassword( + result, service_name = flow.changeUserPassword( request.DATA.get("SERVICE_NAME", None), request.DATA.get("SERVICE_ID", service_id), request.DATA.get("USER_ID", user_id), @@ -880,21 +965,23 @@ def post(self, request, service_id, user_id): ) if 'error' not in result: Stats.num_post_user += 1 - return Response(result, status=status.HTTP_200_OK, + response = Response(result, status=status.HTTP_200_OK, headers={"Fiware-Correlator": CORRELATOR_ID}) else: Stats.num_flow_errors += 1 - return Response(result['error'], + response = Response(result['error'], status=self.getStatusFromCode(result['code']), headers={"Fiware-Correlator": CORRELATOR_ID}) except ParseError as error: Stats.num_api_errors += 1 - return Response( + response = Response( 'Input validation error - {0} {1}'.format(error.message, error.detail), status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) + self.collectMetrics(service_start, service_name, request, response) + return response class UserList_RESTView(APIView, IoTConf): @@ -909,6 +996,8 @@ def __init__(self): IoTConf.__init__(self) def get(self, request, service_id): + service_start = time.time() + response = service_name = None HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) index = request.GET.get('index', None) @@ -921,7 +1010,7 @@ def get(self, request, service_id): self.KEYSTONE_PORT, CORRELATOR_ID=CORRELATOR_ID) CORRELATOR_ID = self.getCorrelatorId(flow, CORRELATOR_ID) - result = flow.users( + result, service_name = flow.users( request.DATA.get("SERVICE_NAME", None), request.DATA.get("SERVICE_ID", service_id), request.DATA.get("SERVICE_ADMIN_USER", None), @@ -932,23 +1021,27 @@ def get(self, request, service_id): if 'error' not in result: Stats.num_get_userlist += 1 - return Response(result, status=status.HTTP_200_OK, + response = Response(result, status=status.HTTP_200_OK, headers={"Fiware-Correlator": CORRELATOR_ID}) else: Stats.num_flow_errors += 1 - return Response(result['error'], + response = Response(result['error'], status=self.getStatusFromCode(result['code']), headers={"Fiware-Correlator": CORRELATOR_ID}) except ParseError as error: Stats.num_api_errors += 1 - return Response( + response = Response( 'Input validation error - {0} {1}'.format(error.message, error.detail), status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) + self.collectMetrics(service_start, service_name, request, response) + return response def post(self, request, service_id): + service_start = time.time() + response = service_name = None HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) try: @@ -958,7 +1051,7 @@ def post(self, request, service_id): self.KEYSTONE_PORT, CORRELATOR_ID=CORRELATOR_ID) CORRELATOR_ID = self.getCorrelatorId(flow, CORRELATOR_ID) - result = flow.createNewServiceUser( + result, service_name = flow.createNewServiceUser( request.DATA.get("SERVICE_NAME", None), request.DATA.get("SERVICE_ID", service_id), request.DATA.get("SERVICE_ADMIN_USER", None), @@ -971,21 +1064,23 @@ def post(self, request, service_id): request.DATA.get("NEW_SERVICE_USER_DESCRIPTION", None)) if 'id' in result: Stats.num_post_userlist += 1 - return Response(result, status=status.HTTP_201_CREATED, + response = Response(result, status=status.HTTP_201_CREATED, headers={"Fiware-Correlator": CORRELATOR_ID}) else: Stats.num_flow_errors += 1 - return Response(result['error'], + response = Response(result['error'], status=self.getStatusFromCode(result['code']), headers={"Fiware-Correlator": CORRELATOR_ID}) except ParseError as error: Stats.num_api_errors += 1 - return Response( + response = Response( 'Input validation error - {0} {1}'.format(error.message, error.detail), status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) + self.collectMetrics(service_start, service_name, request, response) + return response class Group_RESTView(APIView, IoTConf): @@ -1000,6 +1095,8 @@ def __init__(self): IoTConf.__init__(self) def delete(self, request, service_id, group_id): + service_start = time.time() + response = service_name = None HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) try: @@ -1009,7 +1106,7 @@ def delete(self, request, service_id, group_id): self.KEYSTONE_PORT, CORRELATOR_ID=CORRELATOR_ID) CORRELATOR_ID = self.getCorrelatorId(flow, CORRELATOR_ID) - result = flow.removeGroup( + result, service_name = flow.removeGroup( request.DATA.get("SERVICE_NAME", None), request.DATA.get("SERVICE_ID", service_id), request.DATA.get("SERVICE_ADMIN_USER", None), @@ -1018,24 +1115,28 @@ def delete(self, request, service_id, group_id): request.DATA.get("GROUP_NAME", None), request.DATA.get("GROUP_ID", group_id)) if 'error' not in result: - Stats.num_delete_user += 1 - return Response(result, status=status.HTTP_204_NO_CONTENT, + Stats.num_delete_group += 1 + response = Response(result, status=status.HTTP_204_NO_CONTENT, headers={"Fiware-Correlator": CORRELATOR_ID}) else: Stats.num_flow_errors += 1 - return Response(result['error'], + response = Response(result['error'], status=self.getStatusFromCode(result['code']), headers={"Fiware-Correlator": CORRELATOR_ID}) except ParseError as error: Stats.num_api_errors += 1 - return Response( + response = Response( 'Input validation error - {0} {1}'.format(error.message, error.detail), status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) + self.collectMetrics(service_start, service_name, request, response) + return response def put(self, request, service_id, group_id): + service_start = time.time() + response = service_name = None HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) try: @@ -1045,32 +1146,36 @@ def put(self, request, service_id, group_id): self.KEYSTONE_PORT, CORRELATOR_ID=CORRELATOR_ID) CORRELATOR_ID = self.getCorrelatorId(flow, CORRELATOR_ID) - result = flow.updateGroup( - request.DATA.get("SERVICE_NAME"), + result, service_name = flow.updateGroup( + request.DATA.get("SERVICE_NAME", None), request.DATA.get("SERVICE_ID", service_id), request.DATA.get("SERVICE_ADMIN_USER", None), request.DATA.get("SERVICE_ADMIN_PASSWORD", None), request.DATA.get("SERVICE_ADMIN_TOKEN", HTTP_X_AUTH_TOKEN), - request.DATA.get("GROUP_NAME"), + request.DATA.get("GROUP_NAME", None), request.DATA.get("GROUP_ID", group_id)) if 'error' not in result: - Stats.num_put_user += 1 - return Response(result, status=status.HTTP_200_OK, + Stats.num_put_group += 1 + response = Response(result, status=status.HTTP_200_OK, headers={"Fiware-Correlator": CORRELATOR_ID}) else: Stats.num_flow_errors += 1 - return Response(result['error'], + response = Response(result['error'], status=self.getStatusFromCode(result['code']), headers={"Fiware-Correlator": CORRELATOR_ID}) except ParseError as error: Stats.num_api_errors += 1 - return Response( + response = Response( 'Input validation error - {0}'.format(error.message), status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) + self.collectMetrics(service_start, service_name, request, response) + return response def get(self, request, service_id, group_id): + service_start = time.time() + response = service_name = None HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) try: @@ -1080,29 +1185,33 @@ def get(self, request, service_id, group_id): self.KEYSTONE_PORT, CORRELATOR_ID=CORRELATOR_ID) CORRELATOR_ID = self.getCorrelatorId(flow, CORRELATOR_ID) - result = flow.group(request.DATA.get("SERVICE_ID", service_id), + result, service_name = flow.group( + request.DATA.get("SERVICE_ID", service_id), + request.DATA.get("SERVICE_NAME", None), request.DATA.get("GROUP_ID", group_id), request.DATA.get("SERVICE_ADMIN_USER", None), request.DATA.get("SERVICE_ADMIN_PASSWORD", None), request.DATA.get("SERVICE_ADMIN_TOKEN", HTTP_X_AUTH_TOKEN)) if 'error' not in result: - Stats.num_get_user += 1 - return Response(result, status=status.HTTP_200_OK, + Stats.num_get_group += 1 + response = Response(result, status=status.HTTP_200_OK, headers={"Fiware-Correlator": CORRELATOR_ID}) else: Stats.num_flow_errors += 1 - return Response(result['error'], + response = Response(result['error'], status=self.getStatusFromCode(result['code']), headers={"Fiware-Correlator": CORRELATOR_ID}) except ParseError as error: Stats.num_api_errors += 1 - return Response( + response = Response( 'Input validation error - {0} {1}'.format(error.message, error.detail), status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) + self.collectMetrics(service_start, service_name, request, response) + return response class GroupList_RESTView(APIView, IoTConf): @@ -1117,6 +1226,8 @@ def __init__(self): IoTConf.__init__(self) def get(self, request, service_id): + service_start = time.time() + response = service_name = None HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) index = request.GET.get('index', None) @@ -1129,7 +1240,7 @@ def get(self, request, service_id): self.KEYSTONE_PORT, CORRELATOR_ID=CORRELATOR_ID) CORRELATOR_ID = self.getCorrelatorId(flow, CORRELATOR_ID) - result = flow.users( + result, service_name = flow.groups( request.DATA.get("SERVICE_NAME", None), request.DATA.get("SERVICE_ID", service_id), request.DATA.get("SERVICE_ADMIN_USER", None), @@ -1139,34 +1250,38 @@ def get(self, request, service_id): request.DATA.get("COUNT", count)) if 'error' not in result: - Stats.num_get_userlist += 1 - return Response(result, status=status.HTTP_200_OK, + Stats.num_get_grouplist += 1 + response = Response(result, status=status.HTTP_200_OK, headers={"Fiware-Correlator": CORRELATOR_ID}) else: Stats.num_flow_errors += 1 - return Response(result['error'], + response = Response(result['error'], status=self.getStatusFromCode(result['code']), headers={"Fiware-Correlator": CORRELATOR_ID}) except ParseError as error: Stats.num_api_errors += 1 - return Response( + response = Response( 'Input validation error - {0} {1}'.format(error.message, error.detail), status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) + self.collectMetrics(service_start, service_name, request, response) + return response def post(self, request, service_id): + service_start = time.time() + response = service_name = None HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) try: request.DATA # json validation - flow = CreateNewServiceUser(self.KEYSTONE_PROTOCOL, - self.KEYSTONE_HOST, - self.KEYSTONE_PORT, - CORRELATOR_ID=CORRELATOR_ID) + flow = Groups(self.KEYSTONE_PROTOCOL, + self.KEYSTONE_HOST, + self.KEYSTONE_PORT, + CORRELATOR_ID=CORRELATOR_ID) CORRELATOR_ID = self.getCorrelatorId(flow, CORRELATOR_ID) - result = flow.createNewServiceUser( + result, service_name = flow.createNewServiceGroup( request.DATA.get("SERVICE_NAME", None), request.DATA.get("SERVICE_ID", service_id), request.DATA.get("SERVICE_ADMIN_USER", None), @@ -1176,22 +1291,24 @@ def post(self, request, service_id): request.DATA.get("NEW_SERVICE_GROUP_NAME", None), request.DATA.get("NEW_SERVICE_GROUP_DESCRIPTION", None)) if 'id' in result: - Stats.num_post_userlist += 1 - return Response(result, status=status.HTTP_201_CREATED, + Stats.num_post_grouplist += 1 + response = Response(result, status=status.HTTP_201_CREATED, headers={"Fiware-Correlator": CORRELATOR_ID}) else: Stats.num_flow_errors += 1 - return Response(result['error'], + response = Response(result['error'], status=self.getStatusFromCode(result['code']), headers={"Fiware-Correlator": CORRELATOR_ID}) except ParseError as error: Stats.num_api_errors += 1 - return Response( + response = Response( 'Input validation error - {0} {1}'.format(error.message, error.detail), status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) + self.collectMetrics(service_start, service_name, request, response) + return response class Role_RESTView(APIView, IoTConf): @@ -1206,6 +1323,8 @@ def __init__(self): IoTConf.__init__(self) def get(self, request, service_id, role_id): + service_start = time.time() + response = service_name = None HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) try: @@ -1219,7 +1338,7 @@ def get(self, request, service_id, role_id): self.KEYPASS_PORT, CORRELATOR_ID=CORRELATOR_ID) CORRELATOR_ID = self.getCorrelatorId(flow, CORRELATOR_ID) - result = flow.getDomainRolePolicies( + result, service_name = flow.getDomainRolePolicies( request.DATA.get("SERVICE_ID", service_id), request.DATA.get("SERVICE_NAME", None), request.DATA.get("SERVICE_ADMIN_USER", None), @@ -1230,24 +1349,29 @@ def get(self, request, service_id, role_id): if 'error' not in result: Stats.num_get_role_policies += 1 - return Response(result, status=status.HTTP_200_OK, + response = Response(result, status=status.HTTP_200_OK, headers={"Fiware-Correlator": CORRELATOR_ID}) else: Stats.num_flow_errors += 1 - return Response(result['error'], + response = Response(result['error'], status=self.getStatusFromCode(result['code']), headers={"Fiware-Correlator": CORRELATOR_ID}) except ParseError as error: Stats.num_api_errors += 1 - return Response( + response = Response( 'Input validation error - {0} {1}'.format(error.message, error.detail), status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) + self.collectMetrics(service_start, service_name, request, response) + return response + def post(self, request, service_id, role_id): + service_start = time.time() + response = service_name = None HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) try: @@ -1262,7 +1386,7 @@ def post(self, request, service_id, role_id): CORRELATOR_ID=CORRELATOR_ID) CORRELATOR_ID = self.getCorrelatorId(flow, CORRELATOR_ID) - result = flow.setPolicyRole( + result, service_name = flow.setPolicyRole( request.DATA.get("SERVICE_NAME", None), request.DATA.get("SERVICE_ID", service_id), request.DATA.get("SERVICE_ADMIN_USER", None), @@ -1275,24 +1399,28 @@ def post(self, request, service_id, role_id): if 'error' not in result: Stats.num_post_role_policies += 1 - return Response(result, status=status.HTTP_201_CREATED, + response = Response(result, status=status.HTTP_201_CREATED, headers={"Fiware-Correlator": CORRELATOR_ID}) else: Stats.num_flow_errors += 1 - return Response(result['error'], + response = Response(result['error'], status=self.getStatusFromCode(result['code']), headers={"Fiware-Correlator": CORRELATOR_ID}) except ParseError as error: Stats.num_api_errors += 1 - return Response( + response = Response( 'Input validation error - {0} {1}'.format(error.message, error.detail), status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) + self.collectMetrics(service_start, service_name, request, response) + return response def delete(self, request, service_id, role_id): + service_start = time.time() + response = service_name = None HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) try: @@ -1306,7 +1434,7 @@ def delete(self, request, service_id, role_id): CORRELATOR_ID=CORRELATOR_ID) CORRELATOR_ID = self.getCorrelatorId(flow, CORRELATOR_ID) - result = flow.removeRole( + result, service_name = flow.removeRole( request.DATA.get("SERVICE_NAME", None), request.DATA.get("SERVICE_ID", service_id), request.DATA.get("SERVICE_ADMIN_USER", None), @@ -1317,21 +1445,23 @@ def delete(self, request, service_id, role_id): if 'error' not in result: Stats.num_delete_role += 1 - return Response(result, status=status.HTTP_204_NO_CONTENT, + response = Response(result, status=status.HTTP_204_NO_CONTENT, headers={"Fiware-Correlator": CORRELATOR_ID}) else: Stats.num_flow_errors += 1 - return Response(result['error'], + response = Response(result['error'], status=self.getStatusFromCode(result['code']), headers={"Fiware-Correlator": CORRELATOR_ID}) except ParseError as error: Stats.num_api_errors += 1 - return Response( + response = Response( 'Input validation error - {0} {1}'.format(error.message, error.detail), status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) + self.collectMetrics(service_start, service_name, request, response) + return response class RolePolicy_RESTView(APIView, IoTConf): @@ -1347,6 +1477,8 @@ def __init__(self): def get(self, request, service_id, role_id, policy_id): + service_start = time.time() + response = service_name = None HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) try: @@ -1360,7 +1492,7 @@ def get(self, request, service_id, role_id, policy_id): CORRELATOR_ID=CORRELATOR_ID) CORRELATOR_ID = self.getCorrelatorId(flow, CORRELATOR_ID) - result = flow.getPolicyFromRole( + result, service_name = flow.getPolicyFromRole( request.DATA.get("SERVICE_NAME", None), request.DATA.get("SERVICE_ID", service_id), request.DATA.get("SERVICE_ADMIN_USER", None), @@ -1372,23 +1504,27 @@ def get(self, request, service_id, role_id, policy_id): if 'error' not in result: Stats.num_get_policy_from_role += 1 - return Response(result, status=status.HTTP_200_OK, + response = Response(result, status=status.HTTP_200_OK, headers={"Fiware-Correlator": CORRELATOR_ID}) else: Stats.num_flow_errors += 1 - return Response(result['error'], + response = Response(result['error'], status=self.getStatusFromCode(result['code']), headers={"Fiware-Correlator": CORRELATOR_ID}) except ParseError as error: Stats.num_api_errors += 1 - return Response( + response = Response( 'Input validation error - {0} {1}'.format(error.message, error.detail), status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) + self.collectMetrics(service_start, service_name, request, response) + return response def delete(self, request, service_id, role_id, policy_id): + service_start = time.time() + response = service_name = None HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) try: @@ -1402,7 +1538,7 @@ def delete(self, request, service_id, role_id, policy_id): CORRELATOR_ID=CORRELATOR_ID) CORRELATOR_ID = self.getCorrelatorId(flow, CORRELATOR_ID) - result = flow.removePolicyFromRole( + result, service_name = flow.removePolicyFromRole( request.DATA.get("SERVICE_NAME", None), request.DATA.get("SERVICE_ID", service_id), request.DATA.get("SERVICE_ADMIN_USER", None), @@ -1414,21 +1550,23 @@ def delete(self, request, service_id, role_id, policy_id): if 'error' not in result: Stats.num_delete_policy_from_role += 1 - return Response(result, status=status.HTTP_204_NO_CONTENT, + response = Response(result, status=status.HTTP_204_NO_CONTENT, headers={"Fiware-Correlator": CORRELATOR_ID}) else: Stats.num_flow_errors += 1 - return Response(result['error'], + response = Response(result['error'], status=self.getStatusFromCode(result['code']), headers={"Fiware-Correlator": CORRELATOR_ID}) except ParseError as error: Stats.num_api_errors += 1 - return Response( + response = Response( 'Input validation error - {0} {1}'.format(error.message, error.detail), status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) + self.collectMetrics(service_start, service_name, request, response) + return response class RoleList_RESTView(APIView, IoTConf): @@ -1443,6 +1581,8 @@ def __init__(self): IoTConf.__init__(self) def post(self, request, service_id): + service_start = time.time() + response = service_name = None self.schema_name = "RoleList" HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) @@ -1453,7 +1593,7 @@ def post(self, request, service_id): self.KEYSTONE_PORT, CORRELATOR_ID=CORRELATOR_ID) CORRELATOR_ID = self.getCorrelatorId(flow, CORRELATOR_ID) - result = flow.createNewServiceRole( + result, service_name = flow.createNewServiceRole( request.DATA.get("SERVICE_ID", service_id), request.DATA.get("SERVICE_NAME", None), request.DATA.get("SERVICE_ADMIN_USER", None), @@ -1463,24 +1603,28 @@ def post(self, request, service_id): request.DATA.get("XACML_POLICY", None)) if 'error' not in result: Stats.num_post_role += 1 - return Response(result, status=status.HTTP_201_CREATED, + response = Response(result, status=status.HTTP_201_CREATED, headers={"Fiware-Correlator": CORRELATOR_ID}) else: Stats.num_flow_errors += 1 - return Response(result['error'], + response = Response(result['error'], status=self.getStatusFromCode(result['code']), headers={"Fiware-Correlator": CORRELATOR_ID}) except ParseError as error: Stats.num_api_errors += 1 - return Response( + response = Response( 'Input validation error - {0} {1}'.format(error.message, error.detail), status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} - ) + ) + self.collectMetrics(service_start, service_name, request, response) + return response def get(self, request, service_id=None): + service_start = time.time() + response = service_name = None self.schema_name = "RoleAssignmentList" # Like that scheme! HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) @@ -1493,7 +1637,7 @@ def get(self, request, service_id=None): self.KEYSTONE_PORT, CORRELATOR_ID=CORRELATOR_ID) CORRELATOR_ID = self.getCorrelatorId(flow, CORRELATOR_ID) - result = flow.roles( + result, service_name = flow.roles( request.DATA.get("SERVICE_NAME", None), request.DATA.get("SERVICE_ID", service_id), request.DATA.get("SERVICE_ADMIN_USER", None), @@ -1504,21 +1648,23 @@ def get(self, request, service_id=None): if 'error' not in result: Stats.num_get_role += 1 - return Response(result, status=status.HTTP_200_OK, + response = Response(result, status=status.HTTP_200_OK, headers={"Fiware-Correlator": CORRELATOR_ID}) else: Stats.num_flow_errors += 1 - return Response(result['error'], + response = Response(result['error'], status=self.getStatusFromCode(result['code']), headers={"Fiware-Correlator": CORRELATOR_ID}) except ParseError as error: Stats.num_api_errors += 1 - return Response( + response = Response( 'Input validation error - {0} {1}'.format(error.message, error.detail), status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) + self.collectMetrics(service_start, service_name, request, response) + return response class AssignRoleUser_RESTView(APIView, IoTConf): @@ -1530,6 +1676,8 @@ def __init__(self): IoTConf.__init__(self) def get(self, request, service_id): + service_start = time.time() + response = service_name = None self.schema_name = "RoleAssignmentList" user_id = request.GET.get('user_id', None) subservice_id = request.GET.get('subservice_id', None) @@ -1544,7 +1692,7 @@ def get(self, request, service_id): self.KEYSTONE_PORT, CORRELATOR_ID=CORRELATOR_ID) CORRELATOR_ID = self.getCorrelatorId(flow, CORRELATOR_ID) - result = flow.roles_assignments( + result, service_name = flow.roles_assignments( request.DATA.get("SERVICE_ID", service_id), request.DATA.get("SERVICE_NAME",None), request.DATA.get("SUBSERVICE_ID", subservice_id), @@ -1560,23 +1708,27 @@ def get(self, request, service_id): if 'error' not in result: Stats.num_get_roleassignment += 1 - return Response(result, status=status.HTTP_200_OK, + response = Response(result, status=status.HTTP_200_OK, headers={"Fiware-Correlator": CORRELATOR_ID}) else: Stats.num_flow_errors += 1 - return Response(result['error'], + response = Response(result['error'], status=self.getStatusFromCode(result['code']), headers={"Fiware-Correlator": CORRELATOR_ID}) except ParseError as error: Stats.num_api_errors += 1 - return Response( + response = Response( 'Input validation error - {0} {1}'.format(error.message, error.detail), status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) + self.collectMetrics(service_start, service_name, request, response) + return response def post(self, request, service_id): + service_start = time.time() + response = service_name = None self.schema_name = "AssignRole" HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) @@ -1595,7 +1747,7 @@ def post(self, request, service_id): if not (request.DATA.get("SUBSERVICE_NAME", None) or request.DATA.get("SUBSERVICE_ID", subservice_id)): if inherit: - result = flow.assignInheritRoleServiceUser( + result, service_name = flow.assignInheritRoleServiceUser( request.DATA.get("SERVICE_NAME", None), request.DATA.get("SERVICE_ID", service_id), request.DATA.get("SERVICE_ADMIN_USER", None), @@ -1607,7 +1759,7 @@ def post(self, request, service_id): request.DATA.get("SERVICE_USER_NAME", None), request.DATA.get("SERVICE_USER_ID", user_id)) else: - result = flow.assignRoleServiceUser( + result, service_name = flow.assignRoleServiceUser( request.DATA.get("SERVICE_NAME", None), request.DATA.get("SERVICE_ID", service_id), request.DATA.get("SERVICE_ADMIN_USER", None), @@ -1619,7 +1771,7 @@ def post(self, request, service_id): request.DATA.get("SERVICE_USER_NAME", None), request.DATA.get("SERVICE_USER_ID", user_id)) else: - result = flow.assignRoleSubServiceUser( + result, service_name = flow.assignRoleSubServiceUser( request.DATA.get("SERVICE_NAME", None), request.DATA.get("SERVICE_ID", service_id), request.DATA.get("SUBSERVICE_NAME", None), @@ -1633,23 +1785,27 @@ def post(self, request, service_id): request.DATA.get("SERVICE_USER_ID", user_id)) if 'error' not in result: Stats.num_post_roleassignment += 1 - return Response(result, status=status.HTTP_204_NO_CONTENT, + response = Response(result, status=status.HTTP_204_NO_CONTENT, headers={"Fiware-Correlator": CORRELATOR_ID}) else: Stats.num_flow_errors += 1 - return Response(result['error'], + response = Response(result['error'], status=self.getStatusFromCode(result['code']), headers={"Fiware-Correlator": CORRELATOR_ID}) except ParseError as error: Stats.num_api_errors += 1 - return Response( + response = Response( 'Input validation error - {0} {1}'.format(error.message, error.detail), status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) + self.collectMetrics(service_start, service_name, request, response) + return response def delete(self, request, service_id): + service_start = time.time() + response = service_name = None self.schema_name = "AssignRole" HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) @@ -1669,7 +1825,7 @@ def delete(self, request, service_id): if not (request.DATA.get("SUBSERVICE_NAME", None) or request.DATA.get("SUBSERVICE_ID", subservice_id)): if inherit: - result = flow.revokeInheritRoleServiceUser( + result, service_name = flow.revokeInheritRoleServiceUser( request.DATA.get("SERVICE_NAME", None), request.DATA.get("SERVICE_ID", service_id), request.DATA.get("SERVICE_ADMIN_USER", None), @@ -1681,7 +1837,7 @@ def delete(self, request, service_id): request.DATA.get("SERVICE_USER_NAME", None), request.DATA.get("SERVICE_USER_ID", user_id)) else: - result = flow.revokeRoleServiceUser( + result, service_name = flow.revokeRoleServiceUser( request.DATA.get("SERVICE_NAME", None), request.DATA.get("SERVICE_ID", service_id), request.DATA.get("SERVICE_ADMIN_USER", None), @@ -1693,7 +1849,7 @@ def delete(self, request, service_id): request.DATA.get("SERVICE_USER_NAME", None), request.DATA.get("SERVICE_USER_ID", user_id)) else: - result = flow.revokeRoleSubServiceUser( + result, service_name = flow.revokeRoleSubServiceUser( request.DATA.get("SERVICE_NAME"), request.DATA.get("SERVICE_ID", service_id), request.DATA.get("SUBSERVICE_NAME"), @@ -1707,21 +1863,23 @@ def delete(self, request, service_id): request.DATA.get("SERVICE_USER_ID", user_id)) if 'error' not in result: Stats.num_delete_roleassignment += 1 - return Response(result, status=status.HTTP_204_NO_CONTENT, + response = Response(result, status=status.HTTP_204_NO_CONTENT, headers={"Fiware-Correlator": CORRELATOR_ID}) else: Stats.num_flow_errors += 1 - return Response(result['error'], + response = Response(result['error'], status=self.getStatusFromCode(result['code']), headers={"Fiware-Correlator": CORRELATOR_ID}) except ParseError as error: Stats.num_api_errors += 1 - return Response( + response = Response( 'Input validation error - {0} {1}'.format(error.message, error.detail), status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) + self.collectMetrics(service_start, service_name, request, response) + return response class AssignRoleGroup_RESTView(APIView, IoTConf): @@ -1733,6 +1891,8 @@ def __init__(self): IoTConf.__init__(self) def get(self, request, service_id): + service_start = time.time() + response = service_name = None self.schema_name = "RoleAssignmentList" group_id = request.GET.get('group_id', None) subservice_id = request.GET.get('subservice_id', None) @@ -1747,7 +1907,7 @@ def get(self, request, service_id): self.KEYSTONE_PORT, CORRELATOR_ID=CORRELATOR_ID) CORRELATOR_ID = self.getCorrelatorId(flow, CORRELATOR_ID) - result = flow.roles_assignments_groups( + result, service_Name = flow.roles_assignments_groups( request.DATA.get("SERVICE_ID", service_id), request.DATA.get("SERVICE_NAME",None), request.DATA.get("SUBSERVICE_ID", subservice_id), @@ -1763,23 +1923,27 @@ def get(self, request, service_id): if 'error' not in result: Stats.num_get_roleassignment += 1 - return Response(result, status=status.HTTP_200_OK, + response = Response(result, status=status.HTTP_200_OK, headers={"Fiware-Correlator": CORRELATOR_ID}) else: Stats.num_flow_errors += 1 - return Response(result['error'], + response = Response(result['error'], status=self.getStatusFromCode(result['code']), headers={"Fiware-Correlator": CORRELATOR_ID}) except ParseError as error: Stats.num_api_errors += 1 - return Response( + response = Response( 'Input validation error - {0} {1}'.format(error.message, error.detail), status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) + self.collectMetrics(service_start, service_name, request, response) + return response def post(self, request, service_id): + service_start = time.time() + response = service_name = None self.schema_name = "AssignRole" HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) @@ -1798,7 +1962,7 @@ def post(self, request, service_id): if not (request.DATA.get("SUBSERVICE_NAME", None) or request.DATA.get("SUBSERVICE_ID", subservice_id)): if inherit: - result = flow.assignInheritRoleServiceGroup( + result, service_name = flow.assignInheritRoleServiceGroup( request.DATA.get("SERVICE_NAME", None), request.DATA.get("SERVICE_ID", service_id), request.DATA.get("SERVICE_ADMIN_USER", None), @@ -1810,7 +1974,7 @@ def post(self, request, service_id): request.DATA.get("SERVICE_GROUP_NAME", None), request.DATA.get("SERVICE_GROUP_ID", group_id)) else: - result = flow.assignRoleServiceGroup( + result, service_name = flow.assignRoleServiceGroup( request.DATA.get("SERVICE_NAME", None), request.DATA.get("SERVICE_ID", service_id), request.DATA.get("SERVICE_ADMIN_USER", None), @@ -1822,7 +1986,7 @@ def post(self, request, service_id): request.DATA.get("SERVICE_GROUP_NAME", None), request.DATA.get("SERVICE_GROUP_ID", group_id)) else: - result = flow.assignRoleSubServiceGroup( + result, service_name = flow.assignRoleSubServiceGroup( request.DATA.get("SERVICE_NAME", None), request.DATA.get("SERVICE_ID", service_id), request.DATA.get("SUBSERVICE_NAME", None), @@ -1836,23 +2000,27 @@ def post(self, request, service_id): request.DATA.get("SERVICE_GROUP_ID", group_id)) if 'error' not in result: Stats.num_post_roleassignment += 1 - return Response(result, status=status.HTTP_204_NO_CONTENT, + response = Response(result, status=status.HTTP_204_NO_CONTENT, headers={"Fiware-Correlator": CORRELATOR_ID}) else: Stats.num_flow_errors += 1 - return Response(result['error'], + response = Response(result['error'], status=self.getStatusFromCode(result['code']), headers={"Fiware-Correlator": CORRELATOR_ID}) except ParseError as error: Stats.num_api_errors += 1 - return Response( + response = Response( 'Input validation error - {0} {1}'.format(error.message, error.detail), status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) + self.collectMetrics(service_start, service_name, request, response) + return response def delete(self, request, service_id): + service_start = time.time() + response = service_name = None self.schema_name = "AssignRole" HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) @@ -1872,7 +2040,7 @@ def delete(self, request, service_id): if not (request.DATA.get("SUBSERVICE_NAME", None) or request.DATA.get("SUBSERVICE_ID", subservice_id)): if inherit: - result = flow.revokeInheritRoleServiceUser( + result, service_name = flow.revokeInheritRoleServiceGroup( request.DATA.get("SERVICE_NAME", None), request.DATA.get("SERVICE_ID", service_id), request.DATA.get("SERVICE_ADMIN_USER", None), @@ -1884,7 +2052,7 @@ def delete(self, request, service_id): request.DATA.get("SERVICE_GROUP_NAME", None), request.DATA.get("SERVICE_GROUP_ID", group_id)) else: - result = flow.revokeRoleServiceGroup( + result, service_name = flow.revokeRoleServiceGroup( request.DATA.get("SERVICE_NAME", None), request.DATA.get("SERVICE_ID", service_id), request.DATA.get("SERVICE_ADMIN_USER", None), @@ -1896,7 +2064,7 @@ def delete(self, request, service_id): request.DATA.get("SERVICE_GROUP_NAME", None), request.DATA.get("SERVICE_GROUP_ID", group_id)) else: - result = flow.revokeRoleSubServiceGroup( + result, service_name = flow.revokeRoleSubServiceGroup( request.DATA.get("SERVICE_NAME"), request.DATA.get("SERVICE_ID", service_id), request.DATA.get("SUBSERVICE_NAME"), @@ -1910,21 +2078,23 @@ def delete(self, request, service_id): request.DATA.get("SERVICE_GROUP_ID", group_id)) if 'error' not in result: Stats.num_delete_roleassignment += 1 - return Response(result, status=status.HTTP_204_NO_CONTENT, + response = Response(result, status=status.HTTP_204_NO_CONTENT, headers={"Fiware-Correlator": CORRELATOR_ID}) else: Stats.num_flow_errors += 1 - return Response(result['error'], + response = Response(result['error'], status=self.getStatusFromCode(result['code']), headers={"Fiware-Correlator": CORRELATOR_ID}) except ParseError as error: Stats.num_api_errors += 1 - return Response( + response = Response( 'Input validation error - {0} {1}'.format(error.message, error.detail), status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) + self.collectMetrics(service_start, service_name, request, response) + return response class Trust_RESTView(APIView, IoTConf): @@ -1939,6 +2109,8 @@ def __init__(self): IoTConf.__init__(self) def post(self, request, service_id): + service_start = time.time() + response = service_name = None HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) try: @@ -1948,7 +2120,7 @@ def post(self, request, service_id): self.KEYSTONE_PORT, CORRELATOR_ID=CORRELATOR_ID) CORRELATOR_ID = self.getCorrelatorId(flow, CORRELATOR_ID) - result = flow.createTrustToken( + result, service_name = flow.createTrustToken( request.DATA.get("SERVICE_NAME", None), request.DATA.get("SERVICE_ID", service_id), request.DATA.get("SUBSERVICE_NAME", None), @@ -1965,22 +2137,24 @@ def post(self, request, service_id): ) if 'error' not in result: Stats.num_post_trust += 1 - return Response(result, status=status.HTTP_201_CREATED, + response = Response(result, status=status.HTTP_201_CREATED, headers={"Fiware-Correlator": CORRELATOR_ID}) else: Stats.num_flow_errors += 1 - return Response(result['error'], + response = Response(result['error'], status=self.getStatusFromCode(result['code']), headers={"Fiware-Correlator": CORRELATOR_ID}) except ParseError as error: Stats.num_api_errors += 1 - return Response( + response = Response( 'Input validation error - {0} {1}'.format(error.message, error.detail), status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) + self.collectMetrics(service_start, service_name, request, response) + return response class SubServiceIoTADevice_RESTView(APIView, IoTConf): @@ -1995,6 +2169,8 @@ def __init__(self): IoTConf.__init__(self) def post(self, request, service_id, subservice_id): + service_start = time.time() + response = service_name = None HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) try: @@ -2016,7 +2192,7 @@ def post(self, request, service_id, subservice_id): self.CA_PORT, CORRELATOR_ID=CORRELATOR_ID) CORRELATOR_ID = self.getCorrelatorId(flow, CORRELATOR_ID) - result = flow.register_device( + result, service_name = flow.register_device( request.DATA.get("SERVICE_NAME", None), request.DATA.get("SERVICE_ID", service_id), request.DATA.get("SUBSERVICE_NAME", None), @@ -2026,7 +2202,8 @@ def post(self, request, service_id, subservice_id): request.DATA.get("SERVICE_USER_TOKEN", HTTP_X_AUTH_TOKEN), request.DATA.get("DEVICE_ID", None), request.DATA.get("ENTITY_TYPE", None), - request.DATA.get("ENTITY_NAME", request.DATA.get("DEVICE_ID", None)), + request.DATA.get("ENTITY_NAME", + request.DATA.get("DEVICE_ID", None)), request.DATA.get("PROTOCOL", None), request.DATA.get("ATT_ICCID", None), request.DATA.get("ATT_IMEI", None), @@ -2037,24 +2214,28 @@ def post(self, request, service_id, subservice_id): ) if 'error' not in result: Stats.num_post_device += 1 - return Response(result, status=status.HTTP_201_CREATED, + response = Response(result, status=status.HTTP_201_CREATED, headers={"Fiware-Correlator": CORRELATOR_ID}) else: Stats.num_flow_errors += 1 - return Response(result['error'], + response = Response(result['error'], status=self.getStatusFromCode(result['code']), headers={"Fiware-Correlator": CORRELATOR_ID}) except ParseError as error: Stats.num_api_errors += 1 - return Response( + response = Response( 'Input validation error - {0} {1}'.format(error.message, error.detail), status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) + self.collectMetrics(service_start, service_name, request, response) + return response def delete(self, request, service_id, subservice_id): + service_start = time.time() + response = service_name = None HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) try: @@ -2079,7 +2260,7 @@ def delete(self, request, service_id, subservice_id): self.PERSEO_PORT, CORRELATOR_ID=CORRELATOR_ID) CORRELATOR_ID = self.getCorrelatorId(flow, CORRELATOR_ID) - result = flow.unregister_device( + result, service_name = flow.unregister_device( request.DATA.get("SERVICE_NAME", None), request.DATA.get("SERVICE_ID", service_id), request.DATA.get("SUBSERVICE_NAME", None), @@ -2091,22 +2272,24 @@ def delete(self, request, service_id, subservice_id): ) if 'error' not in result: Stats.num_delete_device += 1 - return Response(result, status=status.HTTP_204_NO_CONTENT, + response = Response(result, status=status.HTTP_204_NO_CONTENT, headers={"Fiware-Correlator": CORRELATOR_ID}) else: Stats.num_flow_errors += 1 - return Response(result['error'], + response = Response(result['error'], status=self.getStatusFromCode(result['code']), headers={"Fiware-Correlator": CORRELATOR_ID}) except ParseError as error: Stats.num_api_errors += 1 - return Response( + response = Response( 'Input validation error - {0} {1}'.format(error.message, error.detail), status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) + self.collectMetrics(service_start, service_name, request, response) + return response class SubServiceIoTADevices_RESTView(APIView, IoTConf): @@ -2121,6 +2304,8 @@ def __init__(self): IoTConf.__init__(self) def post(self, request, service_id, subservice_id): + service_start = time.time() + response = service_name = None HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) try: @@ -2145,7 +2330,7 @@ def post(self, request, service_id, subservice_id): self.PERSEO_PORT, CORRELATOR_ID=CORRELATOR_ID) CORRELATOR_ID = self.getCorrelatorId(flow, CORRELATOR_ID) - result = flow.register_devices( + result, service_name = flow.register_devices( request.DATA.get("SERVICE_NAME", None), request.DATA.get("SERVICE_ID", service_id), request.DATA.get("SUBSERVICE_NAME", None), @@ -2157,22 +2342,24 @@ def post(self, request, service_id, subservice_id): ) if 'error' not in result: Stats.num_post_devices += 1 - return Response(result, status=status.HTTP_201_CREATED, + response = Response(result, status=status.HTTP_201_CREATED, headers={"Fiware-Correlator": CORRELATOR_ID}) else: Stats.num_flow_errors += 1 - return Response(result['error'], + response = Response(result['error'], status=self.getStatusFromCode(result['code']), headers={"Fiware-Correlator": CORRELATOR_ID}) except ParseError as error: Stats.num_api_errors += 1 - return Response( + response = Response( 'Input validation error - {0} {1}'.format(error.message, error.detail), status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) + self.collectMetrics(service_start, service_name, request, response) + return response class SubServiceIoTAService_RESTView(APIView, IoTConf): @@ -2187,6 +2374,8 @@ def __init__(self): IoTConf.__init__(self) def post(self, request, service_id, subservice_id): + service_start = time.time() + response = service_name = None HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) try: @@ -2211,7 +2400,7 @@ def post(self, request, service_id, subservice_id): self.PERSEO_PORT, CORRELATOR_ID=CORRELATOR_ID) CORRELATOR_ID = self.getCorrelatorId(flow, CORRELATOR_ID) - result = flow.register_service( + result, service_name = flow.register_service( request.DATA.get("SERVICE_NAME", None), request.DATA.get("SERVICE_ID", service_id), request.DATA.get("SUBSERVICE_NAME", None), @@ -2233,22 +2422,24 @@ def post(self, request, service_id, subservice_id): ) if 'error' not in result: Stats.num_post_entity_service += 1 - return Response(result, status=status.HTTP_201_CREATED, + response = Response(result, status=status.HTTP_201_CREATED, headers={"Fiware-Correlator": CORRELATOR_ID}) else: Stats.num_flow_errors += 1 - return Response(result['error'], + response = Response(result['error'], status=self.getStatusFromCode(result['code']), headers={"Fiware-Correlator": CORRELATOR_ID}) except ParseError as error: Stats.num_api_errors += 1 - return Response( + response = Response( 'Input validation error - {0} {1}'.format(error.message, error.detail), status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) + self.collectMetrics(service_start, service_name, request, response) + return response class IOTModuleActivation_RESTView(APIView, IoTConf): @@ -2263,6 +2454,8 @@ def __init__(self): IoTConf.__init__(self) def get(self, request, service_id, subservice_id=None): + service_start = time.time() + response = service_name = None HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) try: @@ -2288,7 +2481,7 @@ def get(self, request, service_id, subservice_id=None): self.PERSEO_PORT, CORRELATOR_ID=CORRELATOR_ID) CORRELATOR_ID = self.getCorrelatorId(flow, CORRELATOR_ID) - modules = flow.list_activated_modules( + modules, service_name = flow.list_activated_modules( request.DATA.get("SERVICE_NAME", None), request.DATA.get("SERVICE_ID", service_id), request.DATA.get("SERVICE_USER_NAME", None), @@ -2316,7 +2509,7 @@ def get(self, request, service_id, subservice_id=None): self.PERSEO_PORT, CORRELATOR_ID=CORRELATOR_ID) CORRELATOR_ID = self.getCorrelatorId(flow, CORRELATOR_ID) - modules = flow.list_activated_modules( + modules, service_name = flow.list_activated_modules( request.DATA.get("SERVICE_NAME", None), request.DATA.get("SERVICE_ID", service_id), request.DATA.get("SUBSERVICE_NAME", None), @@ -2329,25 +2522,29 @@ def get(self, request, service_id, subservice_id=None): if 'error' not in modules: result['actived_modules'] = modules Stats.num_get_module_activation += 1 - return Response(result, status=status.HTTP_200_OK, + response = Response(result, status=status.HTTP_200_OK, headers={"Fiware-Correlator": CORRELATOR_ID}) else: result = modules Stats.num_flow_errors += 1 - return Response(result['error'], + response = Response(result['error'], status=self.getStatusFromCode(result['code']), headers={"Fiware-Correlator": CORRELATOR_ID}) except ParseError as error: Stats.num_api_errors += 1 - return Response( + response = Response( 'Input validation error - {0} {1}'.format(error.message, error.detail), status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) + self.collectMetrics(service_start, service_name, request, response) + return response def post(self, request, service_id, subservice_id=None, iot_module=None): + service_start = time.time() + response = service_name = None HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) try: @@ -2373,7 +2570,7 @@ def post(self, request, service_id, subservice_id=None, iot_module=None): self.PERSEO_PORT, CORRELATOR_ID=CORRELATOR_ID) CORRELATOR_ID = self.getCorrelatorId(flow, CORRELATOR_ID) - sub = flow.activate_module( + sub, service_name = flow.activate_module( request.DATA.get("SERVICE_NAME", None), request.DATA.get("SERVICE_ID", service_id), request.DATA.get("SERVICE_USER_NAME", None), @@ -2402,7 +2599,7 @@ def post(self, request, service_id, subservice_id=None, iot_module=None): self.PERSEO_PORT, CORRELATOR_ID=CORRELATOR_ID) CORRELATOR_ID = self.getCorrelatorId(flow, CORRELATOR_ID) - sub = flow.activate_module( + sub, service_name = flow.activate_module( request.DATA.get("SERVICE_NAME", None), request.DATA.get("SERVICE_ID", service_id), request.DATA.get("SUBSERVICE_NAME", None), @@ -2416,25 +2613,29 @@ def post(self, request, service_id, subservice_id=None, iot_module=None): result['subscriptionid'] = sub if 'error' not in result: Stats.num_post_module_activation += 1 - return Response(result, status=status.HTTP_201_CREATED, + response = Response(result, status=status.HTTP_201_CREATED, headers={"Fiware-Correlator": CORRELATOR_ID}) else: Stats.num_flow_errors += 1 - return Response(result['error'], + response = Response(result['error'], status=self.getStatusFromCode(result['code']), headers={"Fiware-Correlator": CORRELATOR_ID}) except ParseError as error: Stats.num_api_errors += 1 - return Response( + response = Response( 'Input validation error - {0} {1}'.format(error.message, error.detail), status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) + self.collectMetrics(service_start, service_name, request, response) + return response def delete(self, request, service_id, subservice_id=None, iot_module=None): + service_start = time.time() + response = service_name = None HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) try: @@ -2460,7 +2661,7 @@ def delete(self, request, service_id, subservice_id=None, iot_module=None): self.PERSEO_PORT, CORRELATOR_ID=CORRELATOR_ID) CORRELATOR_ID = self.getCorrelatorId(flow, CORRELATOR_ID) - flow.deactivate_module( + result, service_name = flow.deactivate_module( request.DATA.get("SERVICE_NAME", None), request.DATA.get("SERVICE_ID", service_id), request.DATA.get("SERVICE_USER_NAME", None), @@ -2489,7 +2690,7 @@ def delete(self, request, service_id, subservice_id=None, iot_module=None): self.PERSEO_PORT, CORRELATOR_ID=CORRELATOR_ID) CORRELATOR_ID = self.getCorrelatorId(flow, CORRELATOR_ID) - flow.deactivate_module( + result, service_name = flow.deactivate_module( request.DATA.get("SERVICE_NAME", None), request.DATA.get("SERVICE_ID", service_id), request.DATA.get("SUBSERVICE_NAME", None), @@ -2499,26 +2700,27 @@ def delete(self, request, service_id, subservice_id=None, iot_module=None): request.DATA.get("SERVICE_USER_TOKEN", HTTP_X_AUTH_TOKEN), request.DATA.get("IOTMODULE", iot_module), ) - result = {} if 'error' not in result: Stats.num_delete_module_activation += 1 - return Response(result, status=status.HTTP_204_NO_CONTENT, + response = Response(result, status=status.HTTP_204_NO_CONTENT, headers={"Fiware-Correlator": CORRELATOR_ID}) else: Stats.num_flow_errors += 1 - return Response(result['error'], + response = Response(result['error'], status=self.getStatusFromCode(result['code']), headers={"Fiware-Correlator": CORRELATOR_ID}) except ParseError as error: Stats.num_api_errors += 1 - return Response( + response = Response( 'Input validation error - {0} {1}'.format(error.message, error.detail), status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) + self.collectMetrics(service_start, service_name, request, response) + return response class OrchVersion_RESTView(APIView, IoTConf): @@ -2530,7 +2732,8 @@ def __init__(self): IoTConf.__init__(self) def get(self, request): - + service_start = time.time() + response = service_name = None #HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) try: # Extract version and stats data @@ -2595,17 +2798,19 @@ def get(self, request): result, indent=3)) if 'error' not in result: - return Response(result, status=status.HTTP_200_OK) + response = Response(result, status=status.HTTP_200_OK) else: - return Response(result['error'], + response = Response(result['error'], status=self.getStatusFromCode(result['code'])) except ParseError as error: - return Response( + response = Response( 'Input validation error - {0} {1}'.format(error.message, error.detail), status=status.HTTP_400_BAD_REQUEST ) + self.collectMetrics(service_start, service_name, request, response) + return response class OrchLogLevel_RESTView(APIView, IoTConf): @@ -2617,7 +2822,8 @@ def __init__(self): IoTConf.__init__(self) def get(self, request): - + service_start = time.time() + response = service_name = None CORRELATOR_ID = self.getCorrelatorIdHeader(request) try: @@ -2626,21 +2832,24 @@ def get(self, request): logging.getLevelName( logging.getLogger('orchestrator_api').getEffectiveLevel()) } - return Response(result, status=status.HTTP_200_OK, + response = Response(result, status=status.HTTP_200_OK, headers={"Fiware-Correlator": CORRELATOR_ID}) except ParseError as error: body = { "error": "%s" % error.detail } - return Response( + response = Response( json.dumps(body), status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) + self.collectMetrics(service_start, service_name, request, response) + return response def put(self, request): - + service_start = time.time() + response = service_name = None HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) logLevel = request.GET.get('level', None) @@ -2652,7 +2861,7 @@ def put(self, request): self.KEYSTONE_PORT, CORRELATOR_ID=CORRELATOR_ID) CORRELATOR_ID = self.getCorrelatorId(flow, CORRELATOR_ID) - result = flow.domains( + result, service_name = flow.domains( "admin_domain", request.DATA.get("SERVICE_ADMIN_USER", None), request.DATA.get("SERVICE_ADMIN_PASSWORD", None), @@ -2696,7 +2905,7 @@ def put(self, request): logLevel, indent=3)) Stats.num_update_loglevel += 1 - return Response(result, status=status.HTTP_200_OK, + response = Response(result, status=status.HTTP_200_OK, headers={"Fiware-Correlator": CORRELATOR_ID}) @@ -2704,11 +2913,13 @@ def put(self, request): body = { "error": "%s" % error.detail } - return Response( + response = Response( json.dumps(body), status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) + self.collectMetrics(service_start, service_name, request, response) + return response class OrchMetrics_RESTView(APIView, IoTConf): """ @@ -2719,60 +2930,57 @@ def __init__(self): IoTConf.__init__(self) def get(self, request): - + service_start = time.time() + response = service_name = None HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) reset = request.GET.get('reset', None) try: # TO DO - result = {} - - - # Metrics - # incomingTransactions: number of requests consumed by the component. - # incomingTransactionRequestSize: total size (bytes) in requests associated to incoming transactions (“in” from the point of view of the component). - # incomingTransactionResponseSize: total size (bytes) in responses associated to incoming transactions (“out” from the point of view of the component). - # incomingTransacionError: number of incoming transactions resulting in error. - # serviceTime: average time to serve a transaction. - # outgoingTransactions: number of requests sent by the component. - # outgoingTransactionRequestSize: total size (bytes) in requests associated to outgoing transactions (“out” from the point of view of the component). - # outgoingTransactionResponseSize: total size (bytes) in responses associated to outgoing transactions (“in” from the point of view of the component). - # outgoingTransacionError: number of outgoing transactions resulting in error. - - + result = { + "service" : self.service, + "sum" : self.sum + } - - return Response(result, status=status.HTTP_200_OK, + response = Response(result, status=status.HTTP_200_OK, headers={"Fiware-Correlator": CORRELATOR_ID}) except ParseError as error: body = { "error": "%s" % error.detail } - return Response( + response = Response( json.dumps(body), status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) + self.collectMetrics(service_start, service_name, request, response) + return response def delete(self, request): + service_start = time.time() + response = service_name = None HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) try: - # TO DO - result = {} - - return Response(result, status=status.HTTP_204_OK, + result = { + "service" : self.service, + "sum" : self.sum + } + # TODO: reset stats + response = Response(result, status=status.HTTP_204_OK, headers={"Fiware-Correlator": CORRELATOR_ID}) except ParseError as error: body = { "error": "%s" % error.detail } - return Response( + response = Response( json.dumps(body), status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) + self.collectMetrics(service_start, service_name, request, response) + return response diff --git a/src/orchestrator/commands/changeUserPassword.py b/src/orchestrator/commands/changeUserPassword.py index d852769f..2e909262 100755 --- a/src/orchestrator/commands/changeUserPassword.py +++ b/src/orchestrator/commands/changeUserPassword.py @@ -99,7 +99,7 @@ def main(): USER_DATA_VALUE = {"password": NEW_USER_PASSWORD} - res = flow.updateUser( + res, service_name = flow.updateUser( SERVICE_NAME, None, SERVICE_ADMIN_USER, diff --git a/src/orchestrator/commands/changeUserPasswordByHimself.py b/src/orchestrator/commands/changeUserPasswordByHimself.py index a2a9bfb8..c82a16bf 100755 --- a/src/orchestrator/commands/changeUserPasswordByHimself.py +++ b/src/orchestrator/commands/changeUserPasswordByHimself.py @@ -93,7 +93,7 @@ def main(): KEYSTONE_HOST, KEYSTONE_PORT) - res = flow.changeUserPassword( + res, service_name = flow.changeUserPassword( SERVICE_NAME, None, None, diff --git a/src/orchestrator/commands/createNewService.py b/src/orchestrator/commands/createNewService.py index 82166bc2..fd28e0ed 100755 --- a/src/orchestrator/commands/createNewService.py +++ b/src/orchestrator/commands/createNewService.py @@ -122,7 +122,7 @@ def main(): KEYPASS_HOST, KEYPASS_PORT) - res = flow.createNewService( + res, service_name = flow.createNewService( DOMAIN_NAME, DOMAIN_ADMIN_USER, DOMAIN_ADMIN_PASSWORD, diff --git a/src/orchestrator/commands/createNewServiceGroup.py b/src/orchestrator/commands/createNewServiceGroup.py index b33bb811..839d543f 100644 --- a/src/orchestrator/commands/createNewServiceGroup.py +++ b/src/orchestrator/commands/createNewServiceGroup.py @@ -33,7 +33,7 @@ sys.path.append("/var/env-orchestrator/lib/python2.6/site-packages/iotp-orchestrator") from settings.common import LOGGING -from orchestrator.core.flow.createNewServiceGroup import CreateNewServiceGroup +from orchestrator.core.flow import Groups from orchestrator.api import schemas try: logging.config.dictConfig(LOGGING) @@ -90,11 +90,11 @@ def main(): }, schemas.json["GroupList"]) - flow = CreateNewServiceGroup(KEYSTONE_PROTOCOL, + flow = Groups(KEYSTONE_PROTOCOL, KEYSTONE_HOST, KEYSTONE_PORT) - res = flow.createNewServiceGroup( + res, service_name = flow.createNewServiceGroup( SERVICE_NAME, None, SERVICE_ADMIN_USER, diff --git a/src/orchestrator/commands/createNewServiceRole.py b/src/orchestrator/commands/createNewServiceRole.py index 576a7230..85a93bff 100755 --- a/src/orchestrator/commands/createNewServiceRole.py +++ b/src/orchestrator/commands/createNewServiceRole.py @@ -105,7 +105,7 @@ def main(): KEYPASS_HOST, KEYPASS_PORT) - res = flow.createNewServiceRole( + res, service_name = flow.createNewServiceRole( None, SERVICE_NAME, SERVICE_ADMIN_USER, diff --git a/src/orchestrator/commands/createNewServiceUser.py b/src/orchestrator/commands/createNewServiceUser.py index c27b2f5e..ad0a2487 100755 --- a/src/orchestrator/commands/createNewServiceUser.py +++ b/src/orchestrator/commands/createNewServiceUser.py @@ -97,7 +97,7 @@ def main(): KEYSTONE_HOST, KEYSTONE_PORT) - res = flow.createNewServiceUser( + res, service_name = flow.createNewServiceUser( SERVICE_NAME, None, SERVICE_ADMIN_USER, diff --git a/src/orchestrator/commands/createNewSubService.py b/src/orchestrator/commands/createNewSubService.py index 8ad61dba..3ad089f5 100755 --- a/src/orchestrator/commands/createNewSubService.py +++ b/src/orchestrator/commands/createNewSubService.py @@ -97,7 +97,7 @@ def main(): KEYSTONE_HOST, KEYSTONE_PORT) - res = flow.createNewSubService( + res, service_name = flow.createNewSubService( SERVICE_NAME, None, SERVICE_ADMIN_USER, diff --git a/src/orchestrator/commands/createTrustToken.py b/src/orchestrator/commands/createTrustToken.py index 4e259485..35c10e3d 100755 --- a/src/orchestrator/commands/createTrustToken.py +++ b/src/orchestrator/commands/createTrustToken.py @@ -105,7 +105,7 @@ def main(): KEYSTONE_HOST, KEYSTONE_PORT) - res = flow.createTrustToken( + res, service_name = flow.createTrustToken( SERVICE_NAME, None, SUBSERVICE_NAME, diff --git a/src/orchestrator/commands/editService.py b/src/orchestrator/commands/editService.py index d84e102a..0335430e 100755 --- a/src/orchestrator/commands/editService.py +++ b/src/orchestrator/commands/editService.py @@ -83,7 +83,7 @@ def main(): KEYSTONE_HOST, KEYSTONE_PORT) - domain_detail = flow.update_domain( + domain_detail, service_name = flow.update_domain( None, SERVICE_NAME, DOMAIN_ADMIN_USER, diff --git a/src/orchestrator/commands/editSubService.py b/src/orchestrator/commands/editSubService.py index d6c8bbc9..4c4dd638 100755 --- a/src/orchestrator/commands/editSubService.py +++ b/src/orchestrator/commands/editSubService.py @@ -85,7 +85,7 @@ def main(): KEYSTONE_HOST, KEYSTONE_PORT) - project_detail = flow.update_project( + project_detail, service_name = flow.update_project( None, SERVICE_NAME, None, diff --git a/src/orchestrator/commands/listAllRoleAssignments.py b/src/orchestrator/commands/listAllRoleAssignments.py index c08b0f15..1f13b58f 100755 --- a/src/orchestrator/commands/listAllRoleAssignments.py +++ b/src/orchestrator/commands/listAllRoleAssignments.py @@ -91,7 +91,7 @@ def main(): KEYSTONE_HOST, KEYSTONE_PORT) - roles = flow.roles_assignments( + roles, service_name = flow.roles_assignments( None, SERVICE_NAME, None, diff --git a/src/orchestrator/commands/listGroupRoleAssignments.py b/src/orchestrator/commands/listGroupRoleAssignments.py index 4ed5cee5..4ead0c85 100644 --- a/src/orchestrator/commands/listGroupRoleAssignments.py +++ b/src/orchestrator/commands/listGroupRoleAssignments.py @@ -91,7 +91,7 @@ def main(): KEYSTONE_HOST, KEYSTONE_PORT) - roles = flow.roles_assignments_groups( + roles, service_name = flow.roles_assignments_groups( None, SERVICE_NAME, None, diff --git a/src/orchestrator/commands/listRoleAssignments.py b/src/orchestrator/commands/listRoleAssignments.py index fa6fd355..0bcd145a 100755 --- a/src/orchestrator/commands/listRoleAssignments.py +++ b/src/orchestrator/commands/listRoleAssignments.py @@ -91,7 +91,7 @@ def main(): KEYSTONE_HOST, KEYSTONE_PORT) - roles = flow.roles_assignments( + roles, service_name = flow.roles_assignments( None, SERVICE_NAME, None, diff --git a/src/orchestrator/commands/listSubServiceRoleAssignments.py b/src/orchestrator/commands/listSubServiceRoleAssignments.py index 61db612e..c194cfbf 100755 --- a/src/orchestrator/commands/listSubServiceRoleAssignments.py +++ b/src/orchestrator/commands/listSubServiceRoleAssignments.py @@ -87,7 +87,7 @@ def main(): #USER_NAME=sys.argv[7] EFFECTIVE = sys.argv[8] in ["True", "true", "TRUE"] - flow = Roles(KEYSTONE_PROTOCOL, + flow, service_name = Roles(KEYSTONE_PROTOCOL, KEYSTONE_HOST, KEYSTONE_PORT) diff --git a/src/orchestrator/commands/listUserRoleAssignments.py b/src/orchestrator/commands/listUserRoleAssignments.py index 36fa4c74..7446aee5 100755 --- a/src/orchestrator/commands/listUserRoleAssignments.py +++ b/src/orchestrator/commands/listUserRoleAssignments.py @@ -91,7 +91,7 @@ def main(): KEYSTONE_HOST, KEYSTONE_PORT) - roles = flow.roles_assignments( + roles, service_name = flow.roles_assignments( None, SERVICE_NAME, None, diff --git a/src/orchestrator/commands/printServiceGroups.py b/src/orchestrator/commands/printServiceGroups.py index d479f54d..b03ca861 100644 --- a/src/orchestrator/commands/printServiceGroups.py +++ b/src/orchestrator/commands/printServiceGroups.py @@ -80,7 +80,7 @@ def main(): KEYSTONE_HOST, KEYSTONE_PORT) - groups = flow.groups(SERVICE_NAME, + groups, service_name = flow.groups(SERVICE_NAME, None, SERVICE_ADMIN_USER, SERVICE_ADMIN_PASSWORD, diff --git a/src/orchestrator/commands/printServiceIotModules.py b/src/orchestrator/commands/printServiceIotModules.py index 10f0e455..31648bbc 100755 --- a/src/orchestrator/commands/printServiceIotModules.py +++ b/src/orchestrator/commands/printServiceIotModules.py @@ -100,7 +100,7 @@ def main(): ORION_HOST, ORION_PORT) - roles = flow.list_activated_modules(SERVICE_NAME, + roles, service_name = flow.list_activated_modules(SERVICE_NAME, None, SUBSERVICE_NAME, None, diff --git a/src/orchestrator/commands/printServiceRolePolicies.py b/src/orchestrator/commands/printServiceRolePolicies.py index c21ccb0c..134fb4d2 100755 --- a/src/orchestrator/commands/printServiceRolePolicies.py +++ b/src/orchestrator/commands/printServiceRolePolicies.py @@ -96,7 +96,7 @@ def main(): KEYPASS_HOST, KEYPASS_PORT) - policies = flow.getDomainRolePolicies(None, + policies, service_name = flow.getDomainRolePolicies(None, SERVICE_NAME, SERVICE_ADMIN_USER, SERVICE_ADMIN_PASSWORD, diff --git a/src/orchestrator/commands/printServiceRoles.py b/src/orchestrator/commands/printServiceRoles.py index f4175476..05d20e3f 100755 --- a/src/orchestrator/commands/printServiceRoles.py +++ b/src/orchestrator/commands/printServiceRoles.py @@ -79,7 +79,7 @@ def main(): KEYSTONE_HOST, KEYSTONE_PORT) - roles = flow.roles(SERVICE_NAME, + roles, service_name = flow.roles(SERVICE_NAME, None, SERVICE_ADMIN_USER, SERVICE_ADMIN_PASSWORD, diff --git a/src/orchestrator/commands/printServiceUsers.py b/src/orchestrator/commands/printServiceUsers.py index 4eb21453..34e9c262 100755 --- a/src/orchestrator/commands/printServiceUsers.py +++ b/src/orchestrator/commands/printServiceUsers.py @@ -80,7 +80,7 @@ def main(): KEYSTONE_HOST, KEYSTONE_PORT) - users = flow.users(SERVICE_NAME, + users, service_name = flow.users(SERVICE_NAME, None, SERVICE_ADMIN_USER, SERVICE_ADMIN_PASSWORD, diff --git a/src/orchestrator/commands/printServices.py b/src/orchestrator/commands/printServices.py index 75bc36de..64e6bf98 100755 --- a/src/orchestrator/commands/printServices.py +++ b/src/orchestrator/commands/printServices.py @@ -79,7 +79,7 @@ def main(): KEYSTONE_HOST, KEYSTONE_PORT) - domain_detail = flow.domains(DOMAIN_NAME, + domain_detail, service_name = flow.domains(DOMAIN_NAME, DOMAIN_ADMIN_USER, DOMAIN_ADMIN_PASSWORD, None) diff --git a/src/orchestrator/commands/printSubServices.py b/src/orchestrator/commands/printSubServices.py index 17d50925..0062510a 100755 --- a/src/orchestrator/commands/printSubServices.py +++ b/src/orchestrator/commands/printSubServices.py @@ -80,7 +80,7 @@ def main(): KEYSTONE_HOST, KEYSTONE_PORT) - subservices = flow.projects(None, + subservices, service_name = flow.projects(None, SERVICE_NAME, SERVICE_ADMIN_USER, SERVICE_ADMIN_PASSWORD, diff --git a/src/orchestrator/commands/registerSubServiceDevice.py b/src/orchestrator/commands/registerSubServiceDevice.py index 8d8ff3e9..c93e693c 100644 --- a/src/orchestrator/commands/registerSubServiceDevice.py +++ b/src/orchestrator/commands/registerSubServiceDevice.py @@ -158,7 +158,7 @@ def main(): ORION_HOST, ORION_PORT) - res = flow.register_device( + res, service_name = flow.register_device( SERVICE_NAME, None, SUBSERVICE_NAME, diff --git a/src/orchestrator/commands/registerSubServiceEntity.py b/src/orchestrator/commands/registerSubServiceEntity.py index 1159f114..f27f2cda 100644 --- a/src/orchestrator/commands/registerSubServiceEntity.py +++ b/src/orchestrator/commands/registerSubServiceEntity.py @@ -158,7 +158,7 @@ def main(): ORION_HOST, ORION_PORT) - res = flow.register_service( + res, service_name = flow.register_service( SERVICE_NAME, None, SUBSERVICE_NAME, diff --git a/src/orchestrator/commands/removeService.py b/src/orchestrator/commands/removeService.py index 4534c432..afb47355 100755 --- a/src/orchestrator/commands/removeService.py +++ b/src/orchestrator/commands/removeService.py @@ -92,7 +92,7 @@ def main(): KEYPASS_HOST, KEYPASS_PORT) - domain_detail = flow.delete_domain(None, + domain_detail, service_name = flow.delete_domain(None, SERVICE_NAME, DOMAIN_ADMIN_USER, DOMAIN_ADMIN_PASSWORD, diff --git a/src/orchestrator/commands/removeServiceGroup.py b/src/orchestrator/commands/removeServiceGroup.py index 6b9994d3..ada833ac 100644 --- a/src/orchestrator/commands/removeServiceGroup.py +++ b/src/orchestrator/commands/removeServiceGroup.py @@ -83,7 +83,7 @@ def main(): KEYSTONE_HOST, KEYSTONE_PORT) - group_detail = flow.removeUser(SERVICE_NAME, + group_detail, service_name = flow.removeUser(SERVICE_NAME, None, SERVICE_ADMIN_USER, SERVICE_ADMIN_PASSWORD, diff --git a/src/orchestrator/commands/removeServiceRole.py b/src/orchestrator/commands/removeServiceRole.py index 3de6c986..b5c6fd21 100755 --- a/src/orchestrator/commands/removeServiceRole.py +++ b/src/orchestrator/commands/removeServiceRole.py @@ -83,7 +83,7 @@ def main(): KEYSTONE_HOST, KEYSTONE_PORT) - role_detail = flow.removeRole(SERVICE_NAME, + role_detail, service_name = flow.removeRole(SERVICE_NAME, None, SERVICE_ADMIN_USER, SERVICE_ADMIN_PASSWORD, diff --git a/src/orchestrator/commands/removeServiceRolePolicy.py b/src/orchestrator/commands/removeServiceRolePolicy.py index 31d4e3af..7714a112 100644 --- a/src/orchestrator/commands/removeServiceRolePolicy.py +++ b/src/orchestrator/commands/removeServiceRolePolicy.py @@ -100,7 +100,7 @@ def main(): KEYPASS_HOST, KEYPASS_PORT) - role_detail = flow.removePolicyFromRole( + role_detail, service_name = flow.removePolicyFromRole( SERVICE_NAME, None, SERVICE_ADMIN_USER, diff --git a/src/orchestrator/commands/removeServiceUser.py b/src/orchestrator/commands/removeServiceUser.py index d446a12e..ba931b85 100755 --- a/src/orchestrator/commands/removeServiceUser.py +++ b/src/orchestrator/commands/removeServiceUser.py @@ -83,7 +83,7 @@ def main(): KEYSTONE_HOST, KEYSTONE_PORT) - user_detail = flow.removeUser(SERVICE_NAME, + user_detail, service_name = flow.removeUser(SERVICE_NAME, None, SERVICE_ADMIN_USER, SERVICE_ADMIN_PASSWORD, diff --git a/src/orchestrator/commands/removeSubService.py b/src/orchestrator/commands/removeSubService.py index dc3f04b6..f0785ab0 100755 --- a/src/orchestrator/commands/removeSubService.py +++ b/src/orchestrator/commands/removeSubService.py @@ -83,7 +83,7 @@ def main(): KEYSTONE_HOST, KEYSTONE_PORT) - project_detail = flow.delete_project(None, + project_detail, service_name = flow.delete_project(None, SERVICE_NAME, None, SUBSERVICE_NAME, diff --git a/src/orchestrator/core/flow/Domains.py b/src/orchestrator/core/flow/Domains.py index fc1dfcba..555b42a3 100644 --- a/src/orchestrator/core/flow/Domains.py +++ b/src/orchestrator/core/flow/Domains.py @@ -81,7 +81,7 @@ def domains(self, } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) - return DOMAINS + return DOMAINS, None def get_domain(self, DOMAIN_ID, @@ -143,7 +143,7 @@ def get_domain(self, } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) - return DOMAIN + return DOMAIN, DOMAIN_NAME def update_domain(self, DOMAIN_ID, @@ -210,7 +210,7 @@ def update_domain(self, "DOMAIN": DOMAIN } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) - return DOMAIN + return DOMAIN, DOMAIN_NAME def delete_domain(self, DOMAIN_ID, @@ -351,7 +351,7 @@ def delete_domain(self, } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) - return DOMAIN + return DOMAIN, DOMAIN_NAME def getDomainRolePolicies(self, @@ -408,6 +408,13 @@ def getDomainRolePolicies(self, self.logger.debug("SERVICE_ADMIN_TOKEN=%s" % SERVICE_ADMIN_TOKEN) + # Ensure SERVICE_NAME + SERVICE_NAME = self.ensure_service_name(SERVICE_ADMIN_TOKEN, + SERVICE_ID, + SERVICE_NAME) + self.logger.addFilter(ContextFilterService(SERVICE_NAME)) + self.logger.debug("SERVICE_NAME=%s" % SERVICE_NAME) + # Get Role ID if not ROLE_ID and ROLE_NAME: if ROLE_NAME == "Admin": @@ -458,7 +465,7 @@ def getDomainRolePolicies(self, } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) - return policies + return policies, SERVICE_NAME def activate_module(self, DOMAIN_NAME, @@ -571,7 +578,7 @@ def activate_module(self, "subscriptionid": subscriptionid } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) - return subscriptionid + return subscriptionid, DOMAIN_NAME def deactivate_module(self, DOMAIN_NAME, @@ -665,7 +672,7 @@ def deactivate_module(self, } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) - return subscriptionid + return subscriptionid, DOMAIN_NAME def list_activated_modules(self, @@ -742,4 +749,4 @@ def list_activated_modules(self, } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) - return modules + return modules, DOMAIN_NAME diff --git a/src/orchestrator/core/flow/Groups.py b/src/orchestrator/core/flow/Groups.py index e08f29e1..c46a708d 100644 --- a/src/orchestrator/core/flow/Groups.py +++ b/src/orchestrator/core/flow/Groups.py @@ -24,7 +24,7 @@ import json from orchestrator.core.flow.base import FlowBase - +from orchestrator.common.util import ContextFilterService class Groups(FlowBase): @@ -79,6 +79,13 @@ def groups(self, SERVICE_ADMIN_PASSWORD) self.logger.debug("SERVICE_ADMIN_TOKEN=%s" % SERVICE_ADMIN_TOKEN) + # Ensure SERVICE_NAME + SERVICE_NAME = self.ensure_service_name(SERVICE_ADMIN_TOKEN, + SERVICE_ID, + SERVICE_NAME) + self.logger.addFilter(ContextFilterService(SERVICE_NAME)) + self.logger.debug("SERVICE_NAME=%s" % SERVICE_NAME) + SERVICE_GROUPS = self.idm.getDomainGroups(SERVICE_ADMIN_TOKEN, SERVICE_ID, START_INDEX, @@ -95,11 +102,12 @@ def groups(self, "SERVICE_GROUPS": SERVICE_GROUPS, } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) - return SERVICE_GROUPS + return SERVICE_GROUPS, SERVICE_NAME def group(self, SERVICE_ID, + SERVICE_NAME, GROUP_ID, SERVICE_ADMIN_USER, SERVICE_ADMIN_PASSWORD, @@ -111,6 +119,7 @@ def group(self, Params: - SERVICE_ID: Service ID + - SERVICE_NAME: Service NAME - GROUP_ID: Group ID - SERVICE_ADMIN_USER: Service admin username - SERVICE_ADMIN_PASSWORD: Service admin password @@ -119,6 +128,7 @@ def group(self, ''' data_log = { "SERVICE_ID": "%s" % SERVICE_ID, + "SERVICE_NAME": "%s" % SERVICE_NAME, "GROUP_ID": "%s" % GROUP_ID, "SERVICE_ADMIN_USER": "%s" % SERVICE_ADMIN_USER, "SERVICE_ADMIN_PASSWORD": "%s" % SERVICE_ADMIN_PASSWORD, @@ -136,6 +146,13 @@ def group(self, SERVICE_ADMIN_PASSWORD) self.logger.debug("SERVICE_ADMIN_TOKEN=%s" % SERVICE_ADMIN_TOKEN) + # Ensure SERVICE_NAME + SERVICE_NAME = self.ensure_service_name(SERVICE_ADMIN_TOKEN, + SERVICE_ID, + SERVICE_NAME) + self.logger.addFilter(ContextFilterService(SERVICE_NAME)) + self.logger.debug("SERVICE_NAME=%s" % SERVICE_NAME) + DETAIL_GROUP = self.idm.detailUser(SERVICE_ADMIN_TOKEN, GROUP_ID) self.logger.debug("DETAIL_GROUP=%s" % json.dumps(DETAIL_GROUP, indent=3)) @@ -148,7 +165,7 @@ def group(self, "DETAIL_GROUP": DETAIL_GROUP, } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) - return DETAIL_GROUP + return DETAIL_GROUP, SERVICE_NAME def updateGroup(self, @@ -202,6 +219,13 @@ def updateGroup(self, SERVICE_ADMIN_PASSWORD) self.logger.debug("SERVICE_ADMIN_TOKEN=%s" % SERVICE_ADMIN_TOKEN) + # Ensure SERVICE_NAME + SERVICE_NAME = self.ensure_service_name(SERVICE_ADMIN_TOKEN, + SERVICE_ID, + SERVICE_NAME) + self.logger.addFilter(ContextFilterService(SERVICE_NAME)) + self.logger.debug("SERVICE_NAME=%s" % SERVICE_NAME) + # # 2. Get group ID # @@ -226,7 +250,7 @@ def updateGroup(self, } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) - return {"id": GROUP_ID} + return {"id": GROUP_ID}, SERVICE_NAME def removeGroup(self, @@ -280,6 +304,13 @@ def removeGroup(self, SERVICE_ADMIN_PASSWORD) self.logger.debug("SERVICE_ADMIN_TOKEN=%s" % SERVICE_ADMIN_TOKEN) + # Ensure SERVICE_NAME + SERVICE_NAME = self.ensure_service_name(SERVICE_ADMIN_TOKEN, + SERVICE_ID, + SERVICE_NAME) + self.logger.addFilter(ContextFilterService(SERVICE_NAME)) + self.logger.debug("SERVICE_NAME=%s" % SERVICE_NAME) + # # 2. Get group ID # @@ -304,4 +335,86 @@ def removeGroup(self, } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) - return {} + return {}, SERVICE_NAME + + def createNewServiceGroup(self, + SERVICE_NAME, + SERVICE_ID, + SERVICE_ADMIN_USER, + SERVICE_ADMIN_PASSWORD, + SERVICE_ADMIN_TOKEN, + NEW_SERVICE_GROUP_NAME, + NEW_SERVICE_GROUP_DESCRIPTION): + '''Creates a new group Service (aka domain group keystone). + + In case of HTTP error, return HTTP error + + Params: + - SERVICE_NAME: Service name + - SERVICE_ID: Service Id + - SERVICE_ADMIN_USER: Service admin username + - SERVICE_ADMIN_PASSWORD: Service admin password + - SERVICE_ADMIN_TOKEN: Service admin token + - NEW_SERVICE_GROUP_NAME: New group name (required) + - NEW_SERVICE_GROUP_DESCRIPTION: New group description (optional) + Return: + - id: New group Id + ''' + data_log = { + "SERVICE_NAME": "%s" % SERVICE_NAME, + "SERVICE_ID": "%s" % SERVICE_ID, + "SERVICE_ADMIN_USER": "%s" % SERVICE_ADMIN_USER, + "SERVICE_ADMIN_PASSWORD": "%s" % SERVICE_ADMIN_PASSWORD, + "SERVICE_ADMIN_TOKEN": self.get_extended_token(SERVICE_ADMIN_TOKEN), + "NEW_SERVICE_GROUP_NAME": "%s" % NEW_SERVICE_GROUP_NAME, + "NEW_SERVICE_GROUP_DESCRIPTION": "%s" % NEW_SERVICE_GROUP_DESCRIPTION + } + self.logger.debug("FLOW createNewServiceGroup invoked with: %s" % json.dumps( + data_log, + indent=3) + ) + try: + if not SERVICE_ADMIN_TOKEN: + SERVICE_ADMIN_TOKEN = self.idm.getToken(SERVICE_NAME, + SERVICE_ADMIN_USER, + SERVICE_ADMIN_PASSWORD) + self.logger.debug("SERVICE_ADMIN_TOKEN=%s" % SERVICE_ADMIN_TOKEN) + + # + # 1. Get service (aka domain) + # + if not SERVICE_ID: + SERVICE_ID = self.idm.getDomainId(SERVICE_ADMIN_TOKEN, + SERVICE_NAME) + + self.logger.debug("ID of your service %s:%s" % (SERVICE_NAME, + SERVICE_ID)) + + # Ensure SERVICE_NAME + SERVICE_NAME = self.ensure_service_name(SERVICE_ADMIN_TOKEN, + SERVICE_ID, + SERVICE_NAME) + self.logger.addFilter(ContextFilterService(SERVICE_NAME)) + self.logger.debug("SERVICE_NAME=%s" % SERVICE_NAME) + + # + # 2. Create group + # + ID_GROUP = self.idm.createGroupDomain(SERVICE_ADMIN_TOKEN, + SERVICE_ID, + SERVICE_NAME, + NEW_SERVICE_GROUP_NAME, + NEW_SERVICE_GROUP_DESCRIPTION) + self.logger.debug("ID of group %s: %s" % (NEW_SERVICE_GROUP_NAME, ID_GROUP)) + + except Exception, ex: + self.logger.error(ex) + return self.composeErrorCode(ex) + + data_log = { + "SERVICE_ID": "%s" % SERVICE_ID, + "ID_GROUP": "%s" % ID_GROUP, + } + self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) + + return {"id": ID_GROUP}, SERVICE_NAME diff --git a/src/orchestrator/core/flow/Projects.py b/src/orchestrator/core/flow/Projects.py index 0bb57be9..a1aed571 100644 --- a/src/orchestrator/core/flow/Projects.py +++ b/src/orchestrator/core/flow/Projects.py @@ -77,6 +77,12 @@ def projects(self, ADMIN_PASSWORD) self.logger.debug("ADMIN_TOKEN=%s" % ADMIN_TOKEN) + # Ensure DOMAIN_NAME and PROJECT_NAME + DOMAIN_NAME = self.ensure_service_name(ADMIN_TOKEN, + DOMAIN_ID, + DOMAIN_NAME) + self.logger.addFilter(ContextFilterService(DOMAIN_NAME)) + PROJECTS = self.idm.getDomainProjects(ADMIN_TOKEN, DOMAIN_ID) @@ -91,10 +97,11 @@ def projects(self, } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) - return PROJECTS + return PROJECTS, DOMAIN_NAME def get_project(self, DOMAIN_ID, + DOMAIN_NAME, PROJECT_ID, ADMIN_USER, ADMIN_PASSWORD, @@ -106,6 +113,7 @@ def get_project(self, Params: - DOMAIN_ID: id of domain + - DOMAIN_NAME: name of domain - PROJECT_ID: id of project - SERVICE_ADMIN_USER: Service admin username - SERVICE_ADMIN_PASSWORD: Service admin password @@ -115,6 +123,7 @@ def get_project(self, ''' data_log = { "DOMAIN_ID": "%s" % DOMAIN_ID, + "DOMAIN_NAME": "%s" % DOMAIN_NAME, "PROJECT_ID": "%s" % PROJECT_ID, "ADMIN_USER": "%s" % ADMIN_USER, "ADMIN_PASSWORD": "%s" % ADMIN_PASSWORD, @@ -131,6 +140,12 @@ def get_project(self, ADMIN_PASSWORD) self.logger.debug("ADMIN_TOKEN=%s" % ADMIN_TOKEN) + # Ensure DOMAIN_NAME and PROJECT_NAME + DOMAIN_NAME = self.ensure_service_name(ADMIN_TOKEN, + DOMAIN_ID, + DOMAIN_NAME) + self.logger.addFilter(ContextFilterService(DOMAIN_NAME)) + PROJECT = self.idm.getProject(ADMIN_TOKEN, PROJECT_ID) # PROJECTS = self.idm.getDomainProjects(ADMIN_TOKEN, @@ -149,7 +164,7 @@ def get_project(self, "PROJECT": PROJECT } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) - return PROJECT + return PROJECT, DOMAIN_NAME def update_project(self, DOMAIN_ID, @@ -205,6 +220,12 @@ def update_project(self, ADMIN_PASSWORD) self.logger.debug("ADMIN_TOKEN=%s" % ADMIN_TOKEN) + # Ensure DOMAIN_NAME and PROJECT_NAME + DOMAIN_NAME = self.ensure_service_name(ADMIN_TOKEN, + DOMAIN_ID, + DOMAIN_NAME) + self.logger.addFilter(ContextFilterService(DOMAIN_NAME)) + if not PROJECT_ID: PROJECT_ID = self.idm.getProjectId(ADMIN_TOKEN, DOMAIN_NAME, @@ -225,7 +246,7 @@ def update_project(self, "PROJECT": PROJECT } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) - return PROJECT + return PROJECT, DOMAIN_NAME def delete_project(self, DOMAIN_ID, @@ -346,7 +367,7 @@ def delete_project(self, } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) - return PROJECT + return PROJECT, DOMAIN_NAME def register_service(self, @@ -755,7 +776,7 @@ def register_service(self, "subscriptionid_sth": subscriptionid_sth, "subscriptionid_perseo": subscriptionid_perseo } - return result + return result, DOMAIN_NAME def register_device(self, @@ -1085,7 +1106,7 @@ def register_device(self, } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) - return DEVICE_ID + return DEVICE_ID, DOMAIN_NAME def register_devices(self, @@ -1215,7 +1236,7 @@ def register_devices(self, "devices": DEVICES_ID } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) - return DEVICES_ID + return DEVICES_ID, DOMAIN_NAME def unregister_device(self, DOMAIN_NAME, @@ -1310,7 +1331,7 @@ def unregister_device(self, } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) - return {} + return {}, DOMAIN_NAME def activate_module(self, @@ -1451,7 +1472,7 @@ def activate_module(self, "subscriptionid": subscriptionid } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) - return subscriptionid + return subscriptionid, DOMAIN_NAME def deactivate_module(self, DOMAIN_NAME, @@ -1565,7 +1586,7 @@ def deactivate_module(self, } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) - return subscriptionid + return subscriptionid, DOMAIN_NAME def list_activated_modules(self, @@ -1664,4 +1685,4 @@ def list_activated_modules(self, } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) - return modules + return modules, DOMAIN_NAME diff --git a/src/orchestrator/core/flow/Roles.py b/src/orchestrator/core/flow/Roles.py index 4b9e3eeb..b73247d4 100644 --- a/src/orchestrator/core/flow/Roles.py +++ b/src/orchestrator/core/flow/Roles.py @@ -85,6 +85,13 @@ def roles(self, ADMIN_PASSWORD) self.logger.debug("ADMIN_TOKEN=%s" % ADMIN_TOKEN) + # Ensure DOMAIN_NAME + DOMAIN_NAME = self.ensure_service_name(ADMIN_TOKEN, + DOMAIN_ID, + DOMAIN_NAME) + self.logger.addFilter(ContextFilterService(DOMAIN_NAME)) + self.logger.debug("DOMAIN_NAME=%s" % DOMAIN_NAME) + DOMAIN_ROLES = self.idm.getDomainRoles(ADMIN_TOKEN, DOMAIN_ID, START_INDEX, @@ -104,7 +111,7 @@ def roles(self, } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) - return ROLES + return ROLES, DOMAIN_NAME def roles_assignments(self, DOMAIN_ID, @@ -289,7 +296,7 @@ def roles_assignments(self, "role_assignments": role_assignments_expanded, } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) - return {"role_assignments": role_assignments_expanded} + return {"role_assignments": role_assignments_expanded}, DOMAIN_NAME def assignRoleServiceUser(self, SERVICE_NAME, @@ -418,7 +425,7 @@ def assignRoleServiceUser(self, "ROLE_ID": "%s" % ROLE_ID } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) - return {} + return {}, SERVICE_NAME def assignRoleSubServiceUser(self, SERVICE_NAME, @@ -488,6 +495,8 @@ def assignRoleSubServiceUser(self, SERVICE_NAME = self.idm.getDomainNameFromToken(SERVICE_ADMIN_TOKEN, SERVICE_ID) self.logger.addFilter(ContextFilterService(SERVICE_NAME)) + self.logger.debug("SERVICE_NAME=%s" % SERVICE_NAME) + # # 1. Get service (aka domain) # @@ -548,7 +557,7 @@ def assignRoleSubServiceUser(self, "ROLE_ID": "%s" % ROLE_ID } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) - return {} + return {}, SERVICE_NAME def assignInheritRoleServiceUser(self, SERVICE_NAME, @@ -654,7 +663,7 @@ def assignInheritRoleServiceUser(self, "INHERIT_ROLE_ID": "%s" % INHERIT_ROLE_ID } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) - return {} + return {}, SERVICE_NAME def revokeRoleServiceUser(self, SERVICE_NAME, @@ -763,7 +772,7 @@ def revokeRoleServiceUser(self, "ROLE_ID": "%s" % ROLE_ID } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) - return {} + return {}, SERVICE_NAME def revokeRoleSubServiceUser(self, SERVICE_NAME, @@ -887,7 +896,7 @@ def revokeRoleSubServiceUser(self, "ROLE_ID": "%s" % ROLE_ID } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) - return {} + return {}, SERVICE_NAME def revokeInheritRoleServiceUser(self, SERVICE_NAME, @@ -992,7 +1001,7 @@ def revokeInheritRoleServiceUser(self, "INHERIT_ROLE_ID": "%s" % INHERIT_ROLE_ID } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) - return {} + return {}, SERVICE_NAME def roles_assignments_groups(self, @@ -1176,7 +1185,7 @@ def roles_assignments_groups(self, "role_assignments": role_assignments_expanded, } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) - return {"role_assignments": role_assignments_expanded} + return {"role_assignments": role_assignments_expanded}, DOMAIN_NAME def assignRoleServiceGroup(self, @@ -1306,7 +1315,7 @@ def assignRoleServiceGroup(self, "ROLE_ID": "%s" % ROLE_ID } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) - return {} + return {}, SERVICE_NAME def assignRoleSubServiceGroup(self, @@ -1377,6 +1386,8 @@ def assignRoleSubServiceGroup(self, SERVICE_NAME = self.idm.getDomainNameFromToken(SERVICE_ADMIN_TOKEN, SERVICE_ID) self.logger.addFilter(ContextFilterService(SERVICE_NAME)) + self.logger.debug("SERVICE_NAME=%s" % SERVICE_NAME) + # # 1. Get service (aka domain) # @@ -1437,7 +1448,7 @@ def assignRoleSubServiceGroup(self, "ROLE_ID": "%s" % ROLE_ID } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) - return {} + return {}, SERVICE_NAME def assignInheritRoleServiceGroup(self, @@ -1544,7 +1555,7 @@ def assignInheritRoleServiceGroup(self, "INHERIT_ROLE_ID": "%s" % INHERIT_ROLE_ID } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) - return {} + return {}, SERVICE_NAME def revokeRoleServiceGroup(self, @@ -1654,7 +1665,7 @@ def revokeRoleServiceGroup(self, "ROLE_ID": "%s" % ROLE_ID } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) - return {} + return {}, SERVICE_NAME def revokeRoleSubServiceGroup(self, @@ -1779,7 +1790,7 @@ def revokeRoleSubServiceGroup(self, "ROLE_ID": "%s" % ROLE_ID } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) - return {} + return {}, SERVICE_NAME def revokeInheritRoleServiceGroup(self, SERVICE_NAME, @@ -1884,7 +1895,7 @@ def revokeInheritRoleServiceGroup(self, "INHERIT_ROLE_ID": "%s" % INHERIT_ROLE_ID } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) - return {} + return {}, SERVICE_NAME def removeRole(self, @@ -1968,7 +1979,7 @@ def removeRole(self, } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) - return {} + return {}, SERVICE_NAME def setPolicyRole(self, SERVICE_NAME, @@ -2073,7 +2084,7 @@ def setPolicyRole(self, self.logger.error(ex) return self.composeErrorCode(ex) - return {} + return {}, SERVICE_NAME def removePolicyFromRole(self, @@ -2134,6 +2145,7 @@ def removePolicyFromRole(self, SERVICE_ID, SERVICE_NAME) self.logger.addFilter(ContextFilterService(SERVICE_NAME)) + self.logger.debug("SERVICE_NAME=%s" % SERVICE_NAME) # # 2. Get Role ID @@ -2180,7 +2192,7 @@ def removePolicyFromRole(self, self.logger.error(ex) return self.composeErrorCode(ex) - return {} + return {}, SERVICE_NAME def getPolicyFromRole(self, @@ -2235,10 +2247,12 @@ def getPolicyFromRole(self, SERVICE_ADMIN_PASSWORD) self.logger.debug("SERVICE_ADMIN_TOKEN=%s" % SERVICE_ADMIN_TOKEN) + # Ensure SERVICE_NAME SERVICE_NAME = self.ensure_service_name(SERVICE_ADMIN_TOKEN, SERVICE_ID, SERVICE_NAME) self.logger.addFilter(ContextFilterService(SERVICE_NAME)) + self.logger.debug("SERVICE_NAME=%s" % SERVICE_NAME) # # 2. Get Role ID @@ -2285,4 +2299,4 @@ def getPolicyFromRole(self, self.logger.error(ex) return self.composeErrorCode(ex) - return {} + return {}, SERVICE_NAME diff --git a/src/orchestrator/core/flow/Users.py b/src/orchestrator/core/flow/Users.py index 82717ccd..2817d03e 100644 --- a/src/orchestrator/core/flow/Users.py +++ b/src/orchestrator/core/flow/Users.py @@ -24,7 +24,7 @@ import json from orchestrator.core.flow.base import FlowBase - +from orchestrator.common.util import ContextFilterService class Users(FlowBase): @@ -79,6 +79,13 @@ def users(self, SERVICE_ADMIN_PASSWORD) self.logger.debug("SERVICE_ADMIN_TOKEN=%s" % SERVICE_ADMIN_TOKEN) + # Ensure SERVICE_NAME + SERVICE_NAME = self.ensure_service_name(SERVICE_ADMIN_TOKEN, + SERVICE_ID, + SERVICE_NAME) + self.logger.addFilter(ContextFilterService(SERVICE_NAME)) + self.logger.debug("SERVICE_NAME=%s" % SERVICE_NAME) + # SERVICE_ROLES = self.idm.getDomainRoles(SERVICE_ADMIN_TOKEN, # SERVICE_ID) @@ -108,11 +115,12 @@ def users(self, "SERVICE_USERS": SERVICE_USERS, } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) - return SERVICE_USERS + return SERVICE_USERS, SERVICE_NAME def user(self, SERVICE_ID, + SERVICE_NAME, USER_ID, SERVICE_ADMIN_USER, SERVICE_ADMIN_PASSWORD, @@ -124,6 +132,7 @@ def user(self, Params: - SERVICE_ID: Service ID + - SERVICE_NAME: Service NAME - USER_ID: User ID - SERVICE_ADMIN_USER: Service admin username - SERVICE_ADMIN_PASSWORD: Service admin password @@ -132,6 +141,7 @@ def user(self, ''' data_log = { "SERVICE_ID": "%s" % SERVICE_ID, + "SERVICE_NAME": "%s" % SERVICE_NAME, "USER_ID": "%s" % USER_ID, "SERVICE_ADMIN_USER": "%s" % SERVICE_ADMIN_USER, "SERVICE_ADMIN_PASSWORD": "%s" % SERVICE_ADMIN_PASSWORD, @@ -149,6 +159,13 @@ def user(self, SERVICE_ADMIN_PASSWORD) self.logger.debug("SERVICE_ADMIN_TOKEN=%s" % SERVICE_ADMIN_TOKEN) + # Ensure SERVICE_NAME + SERVICE_NAME = self.ensure_service_name(SERVICE_ADMIN_TOKEN, + SERVICE_ID, + SERVICE_NAME) + self.logger.addFilter(ContextFilterService(SERVICE_NAME)) + self.logger.debug("SERVICE_NAME=%s" % SERVICE_NAME) + DETAIL_USER = self.idm.detailUser(SERVICE_ADMIN_TOKEN, USER_ID) self.logger.debug("DETAIL_USER=%s" % json.dumps(DETAIL_USER, indent=3)) @@ -161,4 +178,4 @@ def user(self, "DETAIL_USER": DETAIL_USER, } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) - return DETAIL_USER + return DETAIL_USER, SERVICE_NAME diff --git a/src/orchestrator/core/flow/base.py b/src/orchestrator/core/flow/base.py index 888ced9c..290e2d34 100644 --- a/src/orchestrator/core/flow/base.py +++ b/src/orchestrator/core/flow/base.py @@ -142,7 +142,7 @@ def composeErrorCode(self, ex): if res['code'] == 400 and len(ex.message) > 1 and \ ex.message[1].startswith('SPASSWORD'): res['error'] = ex.message[1] - return res + return res, None def get_endpoint_iot_module(self, iot_module): diff --git a/src/orchestrator/core/flow/createNewService.py b/src/orchestrator/core/flow/createNewService.py index f022b5c6..10057dde 100644 --- a/src/orchestrator/core/flow/createNewService.py +++ b/src/orchestrator/core/flow/createNewService.py @@ -339,4 +339,4 @@ def createNewService(self, return { "token": NEW_SERVICE_ADMIN_TOKEN, "id": ID_DOM1, - } + }, DOMAIN_NAME diff --git a/src/orchestrator/core/flow/createNewServiceRole.py b/src/orchestrator/core/flow/createNewServiceRole.py index 828f8913..1029463c 100644 --- a/src/orchestrator/core/flow/createNewServiceRole.py +++ b/src/orchestrator/core/flow/createNewServiceRole.py @@ -88,7 +88,6 @@ def createNewServiceRole(self, SERVICE_ID, SERVICE_NAME) self.logger.addFilter(ContextFilterService(SERVICE_NAME)) - self.logger.debug("SERVICE_NAME=%s" % SERVICE_NAME) # @@ -138,4 +137,4 @@ def createNewServiceRole(self, } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) - return {"id": ID_ROLE} + return {"id": ID_ROLE}, SERVICE_NAME diff --git a/src/orchestrator/core/flow/createNewServiceUser.py b/src/orchestrator/core/flow/createNewServiceUser.py index 190788d3..7360cbb2 100644 --- a/src/orchestrator/core/flow/createNewServiceUser.py +++ b/src/orchestrator/core/flow/createNewServiceUser.py @@ -117,4 +117,4 @@ def createNewServiceUser(self, } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) - return {"id": ID_USER} + return {"id": ID_USER}, SERVICE_NAME diff --git a/src/orchestrator/core/flow/createNewSubService.py b/src/orchestrator/core/flow/createNewSubService.py index a8980078..7fc53bcc 100644 --- a/src/orchestrator/core/flow/createNewSubService.py +++ b/src/orchestrator/core/flow/createNewSubService.py @@ -163,4 +163,4 @@ def createNewSubService(self, } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) - return {"id": ID_PRO1} + return {"id": ID_PRO1}, SERVICE_NAME diff --git a/src/orchestrator/core/flow/createTrustToken.py b/src/orchestrator/core/flow/createTrustToken.py index be2a62d3..5bb2953b 100644 --- a/src/orchestrator/core/flow/createTrustToken.py +++ b/src/orchestrator/core/flow/createTrustToken.py @@ -187,7 +187,7 @@ def createTrustToken(self, } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) - return {"id": ID_TRUST} + return {"id": ID_TRUST}, SERVICE_NAME diff --git a/src/orchestrator/core/flow/removeUser.py b/src/orchestrator/core/flow/removeUser.py index d852b0f0..faddfcc7 100644 --- a/src/orchestrator/core/flow/removeUser.py +++ b/src/orchestrator/core/flow/removeUser.py @@ -24,7 +24,7 @@ import json from orchestrator.core.flow.base import FlowBase - +from orchestrator.common.util import ContextFilterService class RemoveUser(FlowBase): @@ -79,6 +79,13 @@ def removeUser(self, SERVICE_ADMIN_PASSWORD) self.logger.debug("SERVICE_ADMIN_TOKEN=%s" % SERVICE_ADMIN_TOKEN) + # Ensure SERVICE_NAME + SERVICE_NAME = self.ensure_service_name(SERVICE_ADMIN_TOKEN, + SERVICE_ID, + SERVICE_NAME) + self.logger.addFilter(ContextFilterService(SERVICE_NAME)) + self.logger.debug("SERVICE_NAME=%s" % SERVICE_NAME) + # # 2. Get user ID # @@ -106,4 +113,4 @@ def removeUser(self, } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) - return {} + return {}, SERVICE_NAME diff --git a/src/orchestrator/core/flow/updateUser.py b/src/orchestrator/core/flow/updateUser.py index bd4d966b..72b790fb 100644 --- a/src/orchestrator/core/flow/updateUser.py +++ b/src/orchestrator/core/flow/updateUser.py @@ -24,7 +24,7 @@ import json from orchestrator.core.flow.base import FlowBase - +from orchestrator.common.util import ContextFilterService class UpdateUser(FlowBase): @@ -82,6 +82,13 @@ def updateUser(self, SERVICE_ADMIN_PASSWORD) self.logger.debug("SERVICE_ADMIN_TOKEN=%s" % SERVICE_ADMIN_TOKEN) + # Ensure SERVICE_NAME + SERVICE_NAME = self.ensure_service_name(SERVICE_ADMIN_TOKEN, + SERVICE_ID, + SERVICE_NAME) + self.logger.addFilter(ContextFilterService(SERVICE_NAME)) + self.logger.debug("SERVICE_NAME=%s" % SERVICE_NAME) + # # 2. Get user ID # @@ -107,7 +114,7 @@ def updateUser(self, } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) - return {"id": USER_ID} + return {"id": USER_ID}, SERVICE_NAME def changeUserPassword(self, @@ -164,6 +171,12 @@ def changeUserPassword(self, SCOPED=False) self.logger.debug("SERVICE_USER_TOKEN=%s" % SERVICE_USER_TOKEN) + # Ensure SERVICE_NAME + SERVICE_NAME = self.ensure_service_name(SERVICE_USER_TOKEN, + SERVICE_ID, + SERVICE_NAME) + self.logger.addFilter(ContextFilterService(SERVICE_NAME)) + self.logger.debug("SERVICE_NAME=%s" % SERVICE_NAME) # # 2. Get user ID # @@ -189,4 +202,4 @@ def changeUserPassword(self, } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) - return {"id": USER_ID} + return {"id": USER_ID}, SERVICE_NAME From 8e5eb24d6d2871a6ce98b2591f541bdccfa7c912 Mon Sep 17 00:00:00 2001 From: Alvaro Vega Date: Tue, 10 Jan 2017 12:28:06 +0100 Subject: [PATCH 04/20] use subservice_name in metrics collector --- src/orchestrator/api/views.py | 240 ++++++++++++++++++---------------- 1 file changed, 130 insertions(+), 110 deletions(-) diff --git a/src/orchestrator/api/views.py b/src/orchestrator/api/views.py index 685ca1c0..70322829 100644 --- a/src/orchestrator/api/views.py +++ b/src/orchestrator/api/views.py @@ -127,33 +127,53 @@ class Stats(object): service = {} sum = {} - def collectMetrics(self, service_start, service_name, request, response): - - # Metrics: - # incomingTransactions - # incomingTransactionRequestSize - # incomingTransactionResponseSize - # incomingTransacionError - # serviceTime - # outgoingTransactions - # outgoingTransactionRequestSize - # outgoingTransactionResponseSize - # outgoingTransacionError - - if not service_name in self.service: + # Metrics: + # incomingTransactions + # incomingTransactionRequestSize + # incomingTransactionResponseSize + # incomingTransacionError + # serviceTime + + def collectMetrics(self, service_start, service_name, subservice_name, + request, response): + + service_stop = time.time() + + if service_name and not service_name in self.service: self.service[service_name] = { + "sum": { + "incomingTransactions": 0, + "incomingTransactionRequestSize": 0, + "incomingTransactionResponseSize": 0, + "incomingTransacionError": 0, + "serviceTime": 0, + }, + "subservs": {} + } + + if (service_name and subservice_name and + not subservice_name in self.service[service_name]["subservs"]): + self.service[service_name]["subservs"][subservice_name] = { "incomingTransactions": 0, "incomingTransactionRequestSize": 0, "incomingTransactionResponseSize": 0, "incomingTransacionError": 0, "serviceTime": 0 } - self.service[service_name]["incomingTransactions"] += 1 - self.service[service_name]["incomingTransactionRequestSize"] += len(json.dumps(request.data)) - self.service[service_name]["incomingTransactionResponseSize"] += len(json.dumps(response.data)) - self.service[service_name]["serviceTime"] += service_start - time.time() - #Stats.sum[service] = { } + if service_name: + if subservice_name: + self.service[service_name]["subservs"][subservice_name]["incomingTransactions"] += 1 + self.service[service_name]["subservs"][subservice_name]["incomingTransactionRequestSize"] += len(json.dumps(request.data)) + self.service[service_name]["subservs"][subservice_name]["incomingTransactionResponseSize"] += len(json.dumps(response.data)) + self.service[service_name]["subservs"][subservice_name]["serviceTime"] += (service_stop - service_start) + + + self.service[service_name]["sum"]["incomingTransactions"] += 1 + self.service[service_name]["sum"]["incomingTransactionRequestSize"] += len(json.dumps(request.data)) + self.service[service_name]["sum"]["incomingTransactionResponseSize"] += len(json.dumps(response.data)) + self.service[service_name]["sum"]["serviceTime"] += (service_stop - service_start) + class IoTConf(Stats): @@ -271,7 +291,7 @@ def __init__(self): def get(self, request, service_id=None): self.schema_name = "ServiceList" service_start = time.time() - response = service_name = None + response = service_name = subservice_name = None HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) try: @@ -317,13 +337,13 @@ def get(self, request, service_id=None): status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) - self.collectMetrics(service_start, service_name, request, response) + self.collectMetrics(service_start, service_name, subservice_name, request, response) return response def put(self, request, service_id=None): service_start = time.time() - response = service_name = None + response = service_name = subservice_name = None self.schema_name = "ServiceList" HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) @@ -358,12 +378,12 @@ def put(self, request, service_id=None): status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) - self.collectMetrics(service_start, service_name, request, response) + self.collectMetrics(service_start, service_name, subservice_name, request, response) return response def delete(self, request, service_id=None): service_start = time.time() - response = service_name = None + response = service_name = subservice_name = None self.schema_name = "ServiceList" HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) @@ -412,7 +432,7 @@ def delete(self, request, service_id=None): status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) - self.collectMetrics(service_start, service_name, request, response) + self.collectMetrics(service_start, service_name, subservice_name, request, response) return response class ServiceCreate_RESTView(ServiceList_RESTView): @@ -428,7 +448,7 @@ def __init__(self): def post(self, request, *args, **kw): service_start = time.time() - response = service_name = None + response = service_name = subservice_name = None HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) try: @@ -469,7 +489,7 @@ def post(self, request, *args, **kw): status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) - self.collectMetrics(service_start, service_name, request, response) + self.collectMetrics(service_start, service_name, subservice_name, request, response) return response @@ -487,7 +507,7 @@ def __init__(self): def get(self, request, service_id=None, subservice_id=None): self.schema_name = "SubServiceList" service_start = time.time() - response = service_name = None + response = service_name = subservice_name = None HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) try: @@ -539,13 +559,13 @@ def get(self, request, service_id=None, subservice_id=None): status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) - self.collectMetrics(service_start, service_name, request, response) + self.collectMetrics(service_start, service_name, subservice_name, request, response) return response def put(self, request, service_id=None, subservice_id=None): self.schema_name = "SubServiceList" service_start = time.time() - response = service_name = None + response = service_name = subservice_name = None HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) try: @@ -589,13 +609,13 @@ def put(self, request, service_id=None, subservice_id=None): status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) - self.collectMetrics(service_start, service_name, request, response) + self.collectMetrics(service_start, service_name, subservice_name, request, response) return response def delete(self, request, service_id=None, subservice_id=None): self.schema_name = "SubServiceList" service_start = time.time() - response = service_name = None + response = service_name = subservice_name = None HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) try: @@ -651,7 +671,7 @@ def delete(self, request, service_id=None, subservice_id=None): status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) - self.collectMetrics(service_start, service_name, request, response) + self.collectMetrics(service_start, service_name, subservice_name, request, response) return response @@ -666,7 +686,7 @@ def __init__(self): def post(self, request, service_id): service_start = time.time() - response = service_name = None + response = service_name = subservice_name = None HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) try: @@ -807,7 +827,7 @@ def post(self, request, service_id): status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) - self.collectMetrics(service_start, service_name, request, response) + self.collectMetrics(service_start, service_name, subservice_name, request, response) return response class User_RESTView(APIView, IoTConf): @@ -823,7 +843,7 @@ def __init__(self): def delete(self, request, service_id, user_id): service_start = time.time() - response = service_name = None + response = service_name = subservice_name = None HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) try: @@ -858,12 +878,12 @@ def delete(self, request, service_id, user_id): status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) - self.collectMetrics(service_start, service_name, request, response) + self.collectMetrics(service_start, service_name, subservice_name, request, response) return response def put(self, request, service_id, user_id): service_start = time.time() - response = service_name = None + response = service_name = subservice_name = None HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) try: @@ -898,12 +918,12 @@ def put(self, request, service_id, user_id): status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) - self.collectMetrics(service_start, service_name, request, response) + self.collectMetrics(service_start, service_name, subservice_name, request, response) return response def get(self, request, service_id, user_id): service_start = time.time() - response = service_name = None + response = service_name = subservice_name = None HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) try: @@ -938,12 +958,12 @@ def get(self, request, service_id, user_id): status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) - self.collectMetrics(service_start, service_name, request, response) + self.collectMetrics(service_start, service_name, subservice_name, request, response) return response def post(self, request, service_id, user_id): service_start = time.time() - response = service_name = None + response = service_name = subservice_name = None HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) try: @@ -980,7 +1000,7 @@ def post(self, request, service_id, user_id): status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) - self.collectMetrics(service_start, service_name, request, response) + self.collectMetrics(service_start, service_name, subservice_name, request, response) return response @@ -997,7 +1017,7 @@ def __init__(self): def get(self, request, service_id): service_start = time.time() - response = service_name = None + response = service_name = subservice_name = None HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) index = request.GET.get('index', None) @@ -1036,12 +1056,12 @@ def get(self, request, service_id): status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) - self.collectMetrics(service_start, service_name, request, response) + self.collectMetrics(service_start, service_name, subservice_name, request, response) return response def post(self, request, service_id): service_start = time.time() - response = service_name = None + response = service_name = subservice_name = None HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) try: @@ -1079,7 +1099,7 @@ def post(self, request, service_id): status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) - self.collectMetrics(service_start, service_name, request, response) + self.collectMetrics(service_start, service_name, subservice_name, request, response) return response @@ -1096,7 +1116,7 @@ def __init__(self): def delete(self, request, service_id, group_id): service_start = time.time() - response = service_name = None + response = service_name = subservice_name = None HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) try: @@ -1131,12 +1151,12 @@ def delete(self, request, service_id, group_id): status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) - self.collectMetrics(service_start, service_name, request, response) + self.collectMetrics(service_start, service_name, subservice_name, request, response) return response def put(self, request, service_id, group_id): service_start = time.time() - response = service_name = None + response = service_name = subservice_name = None HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) try: @@ -1170,12 +1190,12 @@ def put(self, request, service_id, group_id): status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) - self.collectMetrics(service_start, service_name, request, response) + self.collectMetrics(service_start, service_name, subservice_name, request, response) return response def get(self, request, service_id, group_id): service_start = time.time() - response = service_name = None + response = service_name = subservice_name = None HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) try: @@ -1210,7 +1230,7 @@ def get(self, request, service_id, group_id): status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) - self.collectMetrics(service_start, service_name, request, response) + self.collectMetrics(service_start, service_name, subservice_name, request, response) return response @@ -1227,7 +1247,7 @@ def __init__(self): def get(self, request, service_id): service_start = time.time() - response = service_name = None + response = service_name = subservice_name = None HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) index = request.GET.get('index', None) @@ -1266,12 +1286,12 @@ def get(self, request, service_id): status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) - self.collectMetrics(service_start, service_name, request, response) + self.collectMetrics(service_start, service_name, subservice_name, request, response) return response def post(self, request, service_id): service_start = time.time() - response = service_name = None + response = service_name = subservice_name = None HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) try: @@ -1307,7 +1327,7 @@ def post(self, request, service_id): status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) - self.collectMetrics(service_start, service_name, request, response) + self.collectMetrics(service_start, service_name, subservice_name, request, response) return response @@ -1324,7 +1344,7 @@ def __init__(self): def get(self, request, service_id, role_id): service_start = time.time() - response = service_name = None + response = service_name = subservice_name = None HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) try: @@ -1365,13 +1385,13 @@ def get(self, request, service_id, role_id): status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) - self.collectMetrics(service_start, service_name, request, response) + self.collectMetrics(service_start, service_name, subservice_name, request, response) return response def post(self, request, service_id, role_id): service_start = time.time() - response = service_name = None + response = service_name = subservice_name = None HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) try: @@ -1415,12 +1435,12 @@ def post(self, request, service_id, role_id): status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) - self.collectMetrics(service_start, service_name, request, response) + self.collectMetrics(service_start, service_name, subservice_name, request, response) return response def delete(self, request, service_id, role_id): service_start = time.time() - response = service_name = None + response = service_name = subservice_name = None HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) try: @@ -1460,7 +1480,7 @@ def delete(self, request, service_id, role_id): status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) - self.collectMetrics(service_start, service_name, request, response) + self.collectMetrics(service_start, service_name, subservice_name, request, response) return response @@ -1478,7 +1498,7 @@ def __init__(self): def get(self, request, service_id, role_id, policy_id): service_start = time.time() - response = service_name = None + response = service_name = subservice_name = None HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) try: @@ -1519,12 +1539,12 @@ def get(self, request, service_id, role_id, policy_id): status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) - self.collectMetrics(service_start, service_name, request, response) + self.collectMetrics(service_start, service_name, subservice_name, request, response) return response def delete(self, request, service_id, role_id, policy_id): service_start = time.time() - response = service_name = None + response = service_name = subservice_name = None HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) try: @@ -1565,7 +1585,7 @@ def delete(self, request, service_id, role_id, policy_id): status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) - self.collectMetrics(service_start, service_name, request, response) + self.collectMetrics(service_start, service_name, subservice_name, request, response) return response @@ -1582,7 +1602,7 @@ def __init__(self): def post(self, request, service_id): service_start = time.time() - response = service_name = None + response = service_name = subservice_name = None self.schema_name = "RoleList" HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) @@ -1619,12 +1639,12 @@ def post(self, request, service_id): status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) - self.collectMetrics(service_start, service_name, request, response) + self.collectMetrics(service_start, service_name, subservice_name, request, response) return response def get(self, request, service_id=None): service_start = time.time() - response = service_name = None + response = service_name = subservice_name = None self.schema_name = "RoleAssignmentList" # Like that scheme! HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) @@ -1663,7 +1683,7 @@ def get(self, request, service_id=None): status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) - self.collectMetrics(service_start, service_name, request, response) + self.collectMetrics(service_start, service_name, subservice_name, request, response) return response @@ -1677,7 +1697,7 @@ def __init__(self): def get(self, request, service_id): service_start = time.time() - response = service_name = None + response = service_name = subservice_name = None self.schema_name = "RoleAssignmentList" user_id = request.GET.get('user_id', None) subservice_id = request.GET.get('subservice_id', None) @@ -1723,12 +1743,12 @@ def get(self, request, service_id): status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) - self.collectMetrics(service_start, service_name, request, response) + self.collectMetrics(service_start, service_name, subservice_name, request, response) return response def post(self, request, service_id): service_start = time.time() - response = service_name = None + response = service_name = subservice_name = None self.schema_name = "AssignRole" HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) @@ -1800,12 +1820,12 @@ def post(self, request, service_id): status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) - self.collectMetrics(service_start, service_name, request, response) + self.collectMetrics(service_start, service_name, subservice_name, request, response) return response def delete(self, request, service_id): service_start = time.time() - response = service_name = None + response = service_name = subservice_name = None self.schema_name = "AssignRole" HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) @@ -1878,7 +1898,7 @@ def delete(self, request, service_id): status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) - self.collectMetrics(service_start, service_name, request, response) + self.collectMetrics(service_start, service_name, subservice_name, request, response) return response @@ -1892,7 +1912,7 @@ def __init__(self): def get(self, request, service_id): service_start = time.time() - response = service_name = None + response = service_name = subservice_name = None self.schema_name = "RoleAssignmentList" group_id = request.GET.get('group_id', None) subservice_id = request.GET.get('subservice_id', None) @@ -1938,12 +1958,12 @@ def get(self, request, service_id): status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) - self.collectMetrics(service_start, service_name, request, response) + self.collectMetrics(service_start, service_name, subservice_name, request, response) return response def post(self, request, service_id): service_start = time.time() - response = service_name = None + response = service_name = subservice_name = None self.schema_name = "AssignRole" HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) @@ -2015,12 +2035,12 @@ def post(self, request, service_id): status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) - self.collectMetrics(service_start, service_name, request, response) + self.collectMetrics(service_start, service_name, subservice_name, request, response) return response def delete(self, request, service_id): service_start = time.time() - response = service_name = None + response = service_name = subservice_name = None self.schema_name = "AssignRole" HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) @@ -2093,7 +2113,7 @@ def delete(self, request, service_id): status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) - self.collectMetrics(service_start, service_name, request, response) + self.collectMetrics(service_start, service_name, subservice_name, request, response) return response @@ -2110,7 +2130,7 @@ def __init__(self): def post(self, request, service_id): service_start = time.time() - response = service_name = None + response = service_name = subservice_name = None HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) try: @@ -2153,7 +2173,7 @@ def post(self, request, service_id): status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) - self.collectMetrics(service_start, service_name, request, response) + self.collectMetrics(service_start, service_name, subservice_name, request, response) return response @@ -2170,7 +2190,7 @@ def __init__(self): def post(self, request, service_id, subservice_id): service_start = time.time() - response = service_name = None + response = service_name = subservice_name = None HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) try: @@ -2230,12 +2250,12 @@ def post(self, request, service_id, subservice_id): status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) - self.collectMetrics(service_start, service_name, request, response) + self.collectMetrics(service_start, service_name, subservice_name, request, response) return response def delete(self, request, service_id, subservice_id): service_start = time.time() - response = service_name = None + response = service_name = subservice_name = None HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) try: @@ -2288,7 +2308,7 @@ def delete(self, request, service_id, subservice_id): status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) - self.collectMetrics(service_start, service_name, request, response) + self.collectMetrics(service_start, service_name, subservice_name, request, response) return response @@ -2305,7 +2325,7 @@ def __init__(self): def post(self, request, service_id, subservice_id): service_start = time.time() - response = service_name = None + response = service_name = subservice_name = None HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) try: @@ -2358,7 +2378,7 @@ def post(self, request, service_id, subservice_id): status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) - self.collectMetrics(service_start, service_name, request, response) + self.collectMetrics(service_start, service_name, subservice_name, request, response) return response @@ -2375,7 +2395,7 @@ def __init__(self): def post(self, request, service_id, subservice_id): service_start = time.time() - response = service_name = None + response = service_name = subservice_name = None HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) try: @@ -2438,7 +2458,7 @@ def post(self, request, service_id, subservice_id): status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) - self.collectMetrics(service_start, service_name, request, response) + self.collectMetrics(service_start, service_name, subservice_name, request, response) return response @@ -2455,7 +2475,7 @@ def __init__(self): def get(self, request, service_id, subservice_id=None): service_start = time.time() - response = service_name = None + response = service_name = subservice_name = None HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) try: @@ -2539,12 +2559,12 @@ def get(self, request, service_id, subservice_id=None): status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) - self.collectMetrics(service_start, service_name, request, response) + self.collectMetrics(service_start, service_name, subservice_name, request, response) return response def post(self, request, service_id, subservice_id=None, iot_module=None): service_start = time.time() - response = service_name = None + response = service_name = subservice_name = None HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) try: @@ -2629,13 +2649,13 @@ def post(self, request, service_id, subservice_id=None, iot_module=None): status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) - self.collectMetrics(service_start, service_name, request, response) + self.collectMetrics(service_start, service_name, subservice_name, request, response) return response def delete(self, request, service_id, subservice_id=None, iot_module=None): service_start = time.time() - response = service_name = None + response = service_name = subservice_name = None HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) try: @@ -2719,7 +2739,7 @@ def delete(self, request, service_id, subservice_id=None, iot_module=None): status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) - self.collectMetrics(service_start, service_name, request, response) + self.collectMetrics(service_start, service_name, subservice_name, request, response) return response @@ -2733,7 +2753,7 @@ def __init__(self): def get(self, request): service_start = time.time() - response = service_name = None + response = service_name = subservice_name = None #HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) try: # Extract version and stats data @@ -2809,7 +2829,7 @@ def get(self, request): error.detail), status=status.HTTP_400_BAD_REQUEST ) - self.collectMetrics(service_start, service_name, request, response) + self.collectMetrics(service_start, service_name, subservice_name, request, response) return response @@ -2823,7 +2843,7 @@ def __init__(self): def get(self, request): service_start = time.time() - response = service_name = None + response = service_name = subservice_name = None CORRELATOR_ID = self.getCorrelatorIdHeader(request) try: @@ -2844,12 +2864,12 @@ def get(self, request): status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) - self.collectMetrics(service_start, service_name, request, response) + self.collectMetrics(service_start, service_name, subservice_name, request, response) return response def put(self, request): service_start = time.time() - response = service_name = None + response = service_name = subservice_name = None HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) logLevel = request.GET.get('level', None) @@ -2918,7 +2938,7 @@ def put(self, request): status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) - self.collectMetrics(service_start, service_name, request, response) + self.collectMetrics(service_start, service_name, subservice_name, request, response) return response class OrchMetrics_RESTView(APIView, IoTConf): @@ -2931,10 +2951,10 @@ def __init__(self): def get(self, request): service_start = time.time() - response = service_name = None + response = service_name = subservice_name = None HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) - reset = request.GET.get('reset', None) + reset = request.GET.get('reset1', None) try: # TO DO @@ -2955,12 +2975,12 @@ def get(self, request): status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) - self.collectMetrics(service_start, service_name, request, response) + self.collectMetrics(service_start, service_name, subservice_name, request, response) return response def delete(self, request): service_start = time.time() - response = service_name = None + response = service_name = subservice_name = None HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) @@ -2982,5 +3002,5 @@ def delete(self, request): status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) - self.collectMetrics(service_start, service_name, request, response) + self.collectMetrics(service_start, service_name, subservice_name, request, response) return response From 3648717c6a7f0578a18e9e88a5a83c06f730f8cc Mon Sep 17 00:00:00 2001 From: Alvaro Vega Date: Wed, 11 Jan 2017 09:08:05 +0100 Subject: [PATCH 05/20] add subservice to metrics collector --- src/orchestrator/api/views.py | 108 +++++++++--------- .../commands/changeUserPassword.py | 2 +- .../commands/changeUserPasswordByHimself.py | 2 +- src/orchestrator/commands/createNewService.py | 2 +- .../commands/createNewServiceGroup.py | 2 +- .../commands/createNewServiceRole.py | 2 +- .../commands/createNewServiceUser.py | 2 +- .../commands/createNewSubService.py | 2 +- src/orchestrator/commands/createTrustToken.py | 2 +- src/orchestrator/commands/editService.py | 2 +- src/orchestrator/commands/editSubService.py | 2 +- .../commands/listAllRoleAssignments.py | 2 +- .../commands/listGroupRoleAssignments.py | 2 +- .../commands/listRoleAssignments.py | 2 +- .../commands/listSubServiceRoleAssignments.py | 4 +- .../commands/listUserRoleAssignments.py | 2 +- .../commands/printServiceGroups.py | 3 +- .../commands/printServiceIotModules.py | 3 +- .../commands/printServiceRolePolicies.py | 3 +- .../commands/printServiceRoles.py | 3 +- .../commands/printServiceUsers.py | 3 +- src/orchestrator/commands/printServices.py | 3 +- src/orchestrator/commands/printSubServices.py | 3 +- .../commands/registerSubServiceDevice.py | 2 +- .../commands/registerSubServiceEntity.py | 2 +- src/orchestrator/commands/removeService.py | 3 +- .../commands/removeServiceGroup.py | 3 +- .../commands/removeServiceRole.py | 3 +- .../commands/removeServiceRolePolicy.py | 2 +- .../commands/removeServiceUser.py | 3 +- src/orchestrator/commands/removeSubService.py | 3 +- src/orchestrator/core/flow/Domains.py | 16 +-- src/orchestrator/core/flow/Groups.py | 10 +- src/orchestrator/core/flow/Projects.py | 33 ++++-- src/orchestrator/core/flow/Roles.py | 34 +++--- src/orchestrator/core/flow/Users.py | 4 +- src/orchestrator/core/flow/base.py | 2 +- .../core/flow/createNewService.py | 2 +- .../core/flow/createNewServiceRole.py | 2 +- .../core/flow/createNewServiceUser.py | 2 +- .../core/flow/createNewSubService.py | 2 +- .../core/flow/createTrustToken.py | 2 +- src/orchestrator/core/flow/removeUser.py | 2 +- src/orchestrator/core/flow/updateUser.py | 4 +- 44 files changed, 160 insertions(+), 137 deletions(-) diff --git a/src/orchestrator/api/views.py b/src/orchestrator/api/views.py index 70322829..084a72e8 100644 --- a/src/orchestrator/api/views.py +++ b/src/orchestrator/api/views.py @@ -303,7 +303,7 @@ def get(self, request, service_id=None): CORRELATOR_ID = self.getCorrelatorId(flow, CORRELATOR_ID) if not service_id: # Get all domains - result, service_name = flow.domains( + result, service_name, subservice_name = flow.domains( request.DATA.get("DOMAIN_NAME", None), request.DATA.get("SERVICE_ADMIN_USER", None), request.DATA.get("SERVICE_ADMIN_PASSWORD", None), @@ -311,7 +311,7 @@ def get(self, request, service_id=None): HTTP_X_AUTH_TOKEN)) else: # Get detail of one domains - result, service_name = flow.get_domain( + result, service_name, subservice_name = flow.get_domain( request.DATA.get("DOMAIN_ID", service_id), request.DATA.get("DOMAIN_NAME", None), request.DATA.get("SERVICE_ADMIN_USER", None), @@ -354,7 +354,7 @@ def put(self, request, service_id=None): self.KEYSTONE_PORT, CORRELATOR_ID=CORRELATOR_ID) CORRELATOR_ID = self.getCorrelatorId(flow, CORRELATOR_ID) - result, service_name = flow.update_domain( + result, service_name, subservice_name = flow.update_domain( request.DATA.get("SERVICE_ID", service_id), request.DATA.get("SERVICE_NAME", None), request.DATA.get("SERVICE_ADMIN_USER", None), @@ -409,7 +409,7 @@ def delete(self, request, service_id=None): self.PERSEO_PORT, CORRELATOR_ID=CORRELATOR_ID) CORRELATOR_ID = self.getCorrelatorId(flow, CORRELATOR_ID) - result, service_name = flow.delete_domain( + result, service_name, subservice_name = flow.delete_domain( request.DATA.get("SERVICE_ID", service_id), request.DATA.get("SERVICE_NAME", None), request.DATA.get("SERVICE_ADMIN_USER", None), @@ -461,7 +461,7 @@ def post(self, request, *args, **kw): self.KEYPASS_PORT, CORRELATOR_ID=CORRELATOR_ID) CORRELATOR_ID = self.getCorrelatorId(flow, CORRELATOR_ID) - result, service_name = flow.createNewService( + result, service_name, subservice_name = flow.createNewService( request.DATA.get("DOMAIN_NAME", None), request.DATA.get("DOMAIN_ADMIN_USER", None), request.DATA.get("DOMAIN_ADMIN_PASSWORD", None), @@ -519,7 +519,7 @@ def get(self, request, service_id=None, subservice_id=None): CORRELATOR_ID = self.getCorrelatorId(flow, CORRELATOR_ID) if service_id: if not subservice_id: - result, service_name = flow.projects( + result, service_name, subservice_name = flow.projects( service_id, request.DATA.get("SERVICE_NAME", None), request.DATA.get("SERVICE_ADMIN_USER", None), @@ -528,7 +528,7 @@ def get(self, request, service_id=None, subservice_id=None): HTTP_X_AUTH_TOKEN)) else: # Get detail of subservice - result, service_name = flow.get_project( + result, service_name, subservice_name = flow.get_project( request.DATA.get("SERVICE_ID", service_id), request.DATA.get("SERVICE_NAME", None), request.DATA.get("SUBSERVICE_ID", subservice_id), @@ -577,7 +577,7 @@ def put(self, request, service_id=None, subservice_id=None): CORRELATOR_ID = self.getCorrelatorId(flow, CORRELATOR_ID) if service_id: if subservice_id: - result, service_name = flow.update_project( + result, service_name, subservice_name = flow.update_project( request.DATA.get("SERVICE_ID", service_id), request.DATA.get("SERVICE_NAME", None), request.DATA.get("SUBSERVICE_ID", subservice_id), @@ -641,7 +641,7 @@ def delete(self, request, service_id=None, subservice_id=None): CORRELATOR_ID=CORRELATOR_ID) CORRELATOR_ID = self.getCorrelatorId(flow, CORRELATOR_ID) if service_id: - result, service_name = flow.delete_project( + result, service_name, subservice_name = flow.delete_project( request.DATA.get("SERVICE_ID", service_id), request.DATA.get("SERVICE_NAME", None), request.DATA.get("SUBSERVICE_ID", subservice_id), @@ -706,7 +706,7 @@ def post(self, request, service_id): CORRELATOR_ID=CORRELATOR_ID) CORRELATOR_ID = self.getCorrelatorId(flow, CORRELATOR_ID) - result, service_name = flow.createNewSubService( + result, service_name, subservice_name = flow.createNewSubService( request.DATA.get("SERVICE_NAME", None), request.DATA.get("SERVICE_ID", service_id), request.DATA.get("SERVICE_ADMIN_USER", None), @@ -853,7 +853,7 @@ def delete(self, request, service_id, user_id): self.KEYSTONE_PORT, CORRELATOR_ID=CORRELATOR_ID) CORRELATOR_ID = self.getCorrelatorId(flow, CORRELATOR_ID) - result, service_name = flow.removeUser( + result, service_name, subservice_name = flow.removeUser( request.DATA.get("SERVICE_NAME", None), request.DATA.get("SERVICE_ID", service_id), request.DATA.get("SERVICE_ADMIN_USER", None), @@ -893,7 +893,7 @@ def put(self, request, service_id, user_id): self.KEYSTONE_PORT, CORRELATOR_ID=CORRELATOR_ID) CORRELATOR_ID = self.getCorrelatorId(flow, CORRELATOR_ID) - result, service_name = flow.updateUser( + result, service_name, subservice_name = flow.updateUser( request.DATA.get("SERVICE_NAME", None), request.DATA.get("SERVICE_ID", service_id), request.DATA.get("SERVICE_ADMIN_USER", None), @@ -933,7 +933,7 @@ def get(self, request, service_id, user_id): self.KEYSTONE_PORT, CORRELATOR_ID=CORRELATOR_ID) CORRELATOR_ID = self.getCorrelatorId(flow, CORRELATOR_ID) - result, service_name = flow.user( + result, service_name, subservice_name = flow.user( request.DATA.get("SERVICE_ID", service_id), request.DATA.get("SERVICE_NAME", None), request.DATA.get("USER_ID", user_id), @@ -973,7 +973,7 @@ def post(self, request, service_id, user_id): self.KEYSTONE_PORT, CORRELATOR_ID=CORRELATOR_ID) CORRELATOR_ID = self.getCorrelatorId(flow, CORRELATOR_ID) - result, service_name = flow.changeUserPassword( + result, service_name, subservice_name = flow.changeUserPassword( request.DATA.get("SERVICE_NAME", None), request.DATA.get("SERVICE_ID", service_id), request.DATA.get("USER_ID", user_id), @@ -1030,7 +1030,7 @@ def get(self, request, service_id): self.KEYSTONE_PORT, CORRELATOR_ID=CORRELATOR_ID) CORRELATOR_ID = self.getCorrelatorId(flow, CORRELATOR_ID) - result, service_name = flow.users( + result, service_name, subservice_name = flow.users( request.DATA.get("SERVICE_NAME", None), request.DATA.get("SERVICE_ID", service_id), request.DATA.get("SERVICE_ADMIN_USER", None), @@ -1071,7 +1071,7 @@ def post(self, request, service_id): self.KEYSTONE_PORT, CORRELATOR_ID=CORRELATOR_ID) CORRELATOR_ID = self.getCorrelatorId(flow, CORRELATOR_ID) - result, service_name = flow.createNewServiceUser( + result, service_name, subservice_name = flow.createNewServiceUser( request.DATA.get("SERVICE_NAME", None), request.DATA.get("SERVICE_ID", service_id), request.DATA.get("SERVICE_ADMIN_USER", None), @@ -1126,7 +1126,7 @@ def delete(self, request, service_id, group_id): self.KEYSTONE_PORT, CORRELATOR_ID=CORRELATOR_ID) CORRELATOR_ID = self.getCorrelatorId(flow, CORRELATOR_ID) - result, service_name = flow.removeGroup( + result, service_name, subservice_name = flow.removeGroup( request.DATA.get("SERVICE_NAME", None), request.DATA.get("SERVICE_ID", service_id), request.DATA.get("SERVICE_ADMIN_USER", None), @@ -1166,7 +1166,7 @@ def put(self, request, service_id, group_id): self.KEYSTONE_PORT, CORRELATOR_ID=CORRELATOR_ID) CORRELATOR_ID = self.getCorrelatorId(flow, CORRELATOR_ID) - result, service_name = flow.updateGroup( + result, service_name, subservice_name = flow.updateGroup( request.DATA.get("SERVICE_NAME", None), request.DATA.get("SERVICE_ID", service_id), request.DATA.get("SERVICE_ADMIN_USER", None), @@ -1205,7 +1205,7 @@ def get(self, request, service_id, group_id): self.KEYSTONE_PORT, CORRELATOR_ID=CORRELATOR_ID) CORRELATOR_ID = self.getCorrelatorId(flow, CORRELATOR_ID) - result, service_name = flow.group( + result, service_name, subservice_name = flow.group( request.DATA.get("SERVICE_ID", service_id), request.DATA.get("SERVICE_NAME", None), request.DATA.get("GROUP_ID", group_id), @@ -1260,7 +1260,7 @@ def get(self, request, service_id): self.KEYSTONE_PORT, CORRELATOR_ID=CORRELATOR_ID) CORRELATOR_ID = self.getCorrelatorId(flow, CORRELATOR_ID) - result, service_name = flow.groups( + result, service_name, subservice_name = flow.groups( request.DATA.get("SERVICE_NAME", None), request.DATA.get("SERVICE_ID", service_id), request.DATA.get("SERVICE_ADMIN_USER", None), @@ -1301,7 +1301,7 @@ def post(self, request, service_id): self.KEYSTONE_PORT, CORRELATOR_ID=CORRELATOR_ID) CORRELATOR_ID = self.getCorrelatorId(flow, CORRELATOR_ID) - result, service_name = flow.createNewServiceGroup( + result, service_name, subservice_name = flow.createNewServiceGroup( request.DATA.get("SERVICE_NAME", None), request.DATA.get("SERVICE_ID", service_id), request.DATA.get("SERVICE_ADMIN_USER", None), @@ -1358,7 +1358,7 @@ def get(self, request, service_id, role_id): self.KEYPASS_PORT, CORRELATOR_ID=CORRELATOR_ID) CORRELATOR_ID = self.getCorrelatorId(flow, CORRELATOR_ID) - result, service_name = flow.getDomainRolePolicies( + result, service_name, subservice_name = flow.getDomainRolePolicies( request.DATA.get("SERVICE_ID", service_id), request.DATA.get("SERVICE_NAME", None), request.DATA.get("SERVICE_ADMIN_USER", None), @@ -1406,7 +1406,7 @@ def post(self, request, service_id, role_id): CORRELATOR_ID=CORRELATOR_ID) CORRELATOR_ID = self.getCorrelatorId(flow, CORRELATOR_ID) - result, service_name = flow.setPolicyRole( + result, service_name, subservice_name = flow.setPolicyRole( request.DATA.get("SERVICE_NAME", None), request.DATA.get("SERVICE_ID", service_id), request.DATA.get("SERVICE_ADMIN_USER", None), @@ -1454,7 +1454,7 @@ def delete(self, request, service_id, role_id): CORRELATOR_ID=CORRELATOR_ID) CORRELATOR_ID = self.getCorrelatorId(flow, CORRELATOR_ID) - result, service_name = flow.removeRole( + result, service_name, subservice_name = flow.removeRole( request.DATA.get("SERVICE_NAME", None), request.DATA.get("SERVICE_ID", service_id), request.DATA.get("SERVICE_ADMIN_USER", None), @@ -1512,7 +1512,7 @@ def get(self, request, service_id, role_id, policy_id): CORRELATOR_ID=CORRELATOR_ID) CORRELATOR_ID = self.getCorrelatorId(flow, CORRELATOR_ID) - result, service_name = flow.getPolicyFromRole( + result, service_name, subservice_name = flow.getPolicyFromRole( request.DATA.get("SERVICE_NAME", None), request.DATA.get("SERVICE_ID", service_id), request.DATA.get("SERVICE_ADMIN_USER", None), @@ -1558,7 +1558,7 @@ def delete(self, request, service_id, role_id, policy_id): CORRELATOR_ID=CORRELATOR_ID) CORRELATOR_ID = self.getCorrelatorId(flow, CORRELATOR_ID) - result, service_name = flow.removePolicyFromRole( + result, service_name, subservice_name = flow.removePolicyFromRole( request.DATA.get("SERVICE_NAME", None), request.DATA.get("SERVICE_ID", service_id), request.DATA.get("SERVICE_ADMIN_USER", None), @@ -1613,7 +1613,7 @@ def post(self, request, service_id): self.KEYSTONE_PORT, CORRELATOR_ID=CORRELATOR_ID) CORRELATOR_ID = self.getCorrelatorId(flow, CORRELATOR_ID) - result, service_name = flow.createNewServiceRole( + result, service_name, subservice_name = flow.createNewServiceRole( request.DATA.get("SERVICE_ID", service_id), request.DATA.get("SERVICE_NAME", None), request.DATA.get("SERVICE_ADMIN_USER", None), @@ -1657,7 +1657,7 @@ def get(self, request, service_id=None): self.KEYSTONE_PORT, CORRELATOR_ID=CORRELATOR_ID) CORRELATOR_ID = self.getCorrelatorId(flow, CORRELATOR_ID) - result, service_name = flow.roles( + result, service_name, subservice_name = flow.roles( request.DATA.get("SERVICE_NAME", None), request.DATA.get("SERVICE_ID", service_id), request.DATA.get("SERVICE_ADMIN_USER", None), @@ -1712,7 +1712,7 @@ def get(self, request, service_id): self.KEYSTONE_PORT, CORRELATOR_ID=CORRELATOR_ID) CORRELATOR_ID = self.getCorrelatorId(flow, CORRELATOR_ID) - result, service_name = flow.roles_assignments( + result, service_name, subservice_name = flow.roles_assignments( request.DATA.get("SERVICE_ID", service_id), request.DATA.get("SERVICE_NAME",None), request.DATA.get("SUBSERVICE_ID", subservice_id), @@ -1767,7 +1767,7 @@ def post(self, request, service_id): if not (request.DATA.get("SUBSERVICE_NAME", None) or request.DATA.get("SUBSERVICE_ID", subservice_id)): if inherit: - result, service_name = flow.assignInheritRoleServiceUser( + result, service_name, subservice_name = flow.assignInheritRoleServiceUser( request.DATA.get("SERVICE_NAME", None), request.DATA.get("SERVICE_ID", service_id), request.DATA.get("SERVICE_ADMIN_USER", None), @@ -1779,7 +1779,7 @@ def post(self, request, service_id): request.DATA.get("SERVICE_USER_NAME", None), request.DATA.get("SERVICE_USER_ID", user_id)) else: - result, service_name = flow.assignRoleServiceUser( + result, service_name, subservice_name = flow.assignRoleServiceUser( request.DATA.get("SERVICE_NAME", None), request.DATA.get("SERVICE_ID", service_id), request.DATA.get("SERVICE_ADMIN_USER", None), @@ -1791,7 +1791,7 @@ def post(self, request, service_id): request.DATA.get("SERVICE_USER_NAME", None), request.DATA.get("SERVICE_USER_ID", user_id)) else: - result, service_name = flow.assignRoleSubServiceUser( + result, service_name, subservice_name = flow.assignRoleSubServiceUser( request.DATA.get("SERVICE_NAME", None), request.DATA.get("SERVICE_ID", service_id), request.DATA.get("SUBSERVICE_NAME", None), @@ -1845,7 +1845,7 @@ def delete(self, request, service_id): if not (request.DATA.get("SUBSERVICE_NAME", None) or request.DATA.get("SUBSERVICE_ID", subservice_id)): if inherit: - result, service_name = flow.revokeInheritRoleServiceUser( + result, service_name, subservice_name = flow.revokeInheritRoleServiceUser( request.DATA.get("SERVICE_NAME", None), request.DATA.get("SERVICE_ID", service_id), request.DATA.get("SERVICE_ADMIN_USER", None), @@ -1857,7 +1857,7 @@ def delete(self, request, service_id): request.DATA.get("SERVICE_USER_NAME", None), request.DATA.get("SERVICE_USER_ID", user_id)) else: - result, service_name = flow.revokeRoleServiceUser( + result, service_name, subservice_name = flow.revokeRoleServiceUser( request.DATA.get("SERVICE_NAME", None), request.DATA.get("SERVICE_ID", service_id), request.DATA.get("SERVICE_ADMIN_USER", None), @@ -1869,7 +1869,7 @@ def delete(self, request, service_id): request.DATA.get("SERVICE_USER_NAME", None), request.DATA.get("SERVICE_USER_ID", user_id)) else: - result, service_name = flow.revokeRoleSubServiceUser( + result, service_name, subservice_name = flow.revokeRoleSubServiceUser( request.DATA.get("SERVICE_NAME"), request.DATA.get("SERVICE_ID", service_id), request.DATA.get("SUBSERVICE_NAME"), @@ -1927,7 +1927,7 @@ def get(self, request, service_id): self.KEYSTONE_PORT, CORRELATOR_ID=CORRELATOR_ID) CORRELATOR_ID = self.getCorrelatorId(flow, CORRELATOR_ID) - result, service_Name = flow.roles_assignments_groups( + result, service_name, subservice_name = flow.roles_assignments_groups( request.DATA.get("SERVICE_ID", service_id), request.DATA.get("SERVICE_NAME",None), request.DATA.get("SUBSERVICE_ID", subservice_id), @@ -1982,7 +1982,7 @@ def post(self, request, service_id): if not (request.DATA.get("SUBSERVICE_NAME", None) or request.DATA.get("SUBSERVICE_ID", subservice_id)): if inherit: - result, service_name = flow.assignInheritRoleServiceGroup( + result, service_name, subservice_name = flow.assignInheritRoleServiceGroup( request.DATA.get("SERVICE_NAME", None), request.DATA.get("SERVICE_ID", service_id), request.DATA.get("SERVICE_ADMIN_USER", None), @@ -1994,7 +1994,7 @@ def post(self, request, service_id): request.DATA.get("SERVICE_GROUP_NAME", None), request.DATA.get("SERVICE_GROUP_ID", group_id)) else: - result, service_name = flow.assignRoleServiceGroup( + result, service_name, subservice_name = flow.assignRoleServiceGroup( request.DATA.get("SERVICE_NAME", None), request.DATA.get("SERVICE_ID", service_id), request.DATA.get("SERVICE_ADMIN_USER", None), @@ -2006,7 +2006,7 @@ def post(self, request, service_id): request.DATA.get("SERVICE_GROUP_NAME", None), request.DATA.get("SERVICE_GROUP_ID", group_id)) else: - result, service_name = flow.assignRoleSubServiceGroup( + result, service_name, subservice_name = flow.assignRoleSubServiceGroup( request.DATA.get("SERVICE_NAME", None), request.DATA.get("SERVICE_ID", service_id), request.DATA.get("SUBSERVICE_NAME", None), @@ -2060,7 +2060,7 @@ def delete(self, request, service_id): if not (request.DATA.get("SUBSERVICE_NAME", None) or request.DATA.get("SUBSERVICE_ID", subservice_id)): if inherit: - result, service_name = flow.revokeInheritRoleServiceGroup( + result, service_name, subservice_name = flow.revokeInheritRoleServiceGroup( request.DATA.get("SERVICE_NAME", None), request.DATA.get("SERVICE_ID", service_id), request.DATA.get("SERVICE_ADMIN_USER", None), @@ -2072,7 +2072,7 @@ def delete(self, request, service_id): request.DATA.get("SERVICE_GROUP_NAME", None), request.DATA.get("SERVICE_GROUP_ID", group_id)) else: - result, service_name = flow.revokeRoleServiceGroup( + result, service_name, subservice_name = flow.revokeRoleServiceGroup( request.DATA.get("SERVICE_NAME", None), request.DATA.get("SERVICE_ID", service_id), request.DATA.get("SERVICE_ADMIN_USER", None), @@ -2084,7 +2084,7 @@ def delete(self, request, service_id): request.DATA.get("SERVICE_GROUP_NAME", None), request.DATA.get("SERVICE_GROUP_ID", group_id)) else: - result, service_name = flow.revokeRoleSubServiceGroup( + result, service_name, subservice_name = flow.revokeRoleSubServiceGroup( request.DATA.get("SERVICE_NAME"), request.DATA.get("SERVICE_ID", service_id), request.DATA.get("SUBSERVICE_NAME"), @@ -2140,7 +2140,7 @@ def post(self, request, service_id): self.KEYSTONE_PORT, CORRELATOR_ID=CORRELATOR_ID) CORRELATOR_ID = self.getCorrelatorId(flow, CORRELATOR_ID) - result, service_name = flow.createTrustToken( + result, service_name, subservice_name = flow.createTrustToken( request.DATA.get("SERVICE_NAME", None), request.DATA.get("SERVICE_ID", service_id), request.DATA.get("SUBSERVICE_NAME", None), @@ -2212,7 +2212,7 @@ def post(self, request, service_id, subservice_id): self.CA_PORT, CORRELATOR_ID=CORRELATOR_ID) CORRELATOR_ID = self.getCorrelatorId(flow, CORRELATOR_ID) - result, service_name = flow.register_device( + result, service_name, subservice_name = flow.register_device( request.DATA.get("SERVICE_NAME", None), request.DATA.get("SERVICE_ID", service_id), request.DATA.get("SUBSERVICE_NAME", None), @@ -2280,7 +2280,7 @@ def delete(self, request, service_id, subservice_id): self.PERSEO_PORT, CORRELATOR_ID=CORRELATOR_ID) CORRELATOR_ID = self.getCorrelatorId(flow, CORRELATOR_ID) - result, service_name = flow.unregister_device( + result, service_name, subservice_name = flow.unregister_device( request.DATA.get("SERVICE_NAME", None), request.DATA.get("SERVICE_ID", service_id), request.DATA.get("SUBSERVICE_NAME", None), @@ -2350,7 +2350,7 @@ def post(self, request, service_id, subservice_id): self.PERSEO_PORT, CORRELATOR_ID=CORRELATOR_ID) CORRELATOR_ID = self.getCorrelatorId(flow, CORRELATOR_ID) - result, service_name = flow.register_devices( + result, service_name, subservice_name = flow.register_devices( request.DATA.get("SERVICE_NAME", None), request.DATA.get("SERVICE_ID", service_id), request.DATA.get("SUBSERVICE_NAME", None), @@ -2420,7 +2420,7 @@ def post(self, request, service_id, subservice_id): self.PERSEO_PORT, CORRELATOR_ID=CORRELATOR_ID) CORRELATOR_ID = self.getCorrelatorId(flow, CORRELATOR_ID) - result, service_name = flow.register_service( + result, service_name, subservice_name = flow.register_service( request.DATA.get("SERVICE_NAME", None), request.DATA.get("SERVICE_ID", service_id), request.DATA.get("SUBSERVICE_NAME", None), @@ -2501,7 +2501,7 @@ def get(self, request, service_id, subservice_id=None): self.PERSEO_PORT, CORRELATOR_ID=CORRELATOR_ID) CORRELATOR_ID = self.getCorrelatorId(flow, CORRELATOR_ID) - modules, service_name = flow.list_activated_modules( + modules, service_name, subservice_name = flow.list_activated_modules( request.DATA.get("SERVICE_NAME", None), request.DATA.get("SERVICE_ID", service_id), request.DATA.get("SERVICE_USER_NAME", None), @@ -2529,7 +2529,7 @@ def get(self, request, service_id, subservice_id=None): self.PERSEO_PORT, CORRELATOR_ID=CORRELATOR_ID) CORRELATOR_ID = self.getCorrelatorId(flow, CORRELATOR_ID) - modules, service_name = flow.list_activated_modules( + modules, service_name, subservice_name = flow.list_activated_modules( request.DATA.get("SERVICE_NAME", None), request.DATA.get("SERVICE_ID", service_id), request.DATA.get("SUBSERVICE_NAME", None), @@ -2590,7 +2590,7 @@ def post(self, request, service_id, subservice_id=None, iot_module=None): self.PERSEO_PORT, CORRELATOR_ID=CORRELATOR_ID) CORRELATOR_ID = self.getCorrelatorId(flow, CORRELATOR_ID) - sub, service_name = flow.activate_module( + sub, service_name, subservice_name = flow.activate_module( request.DATA.get("SERVICE_NAME", None), request.DATA.get("SERVICE_ID", service_id), request.DATA.get("SERVICE_USER_NAME", None), @@ -2619,7 +2619,7 @@ def post(self, request, service_id, subservice_id=None, iot_module=None): self.PERSEO_PORT, CORRELATOR_ID=CORRELATOR_ID) CORRELATOR_ID = self.getCorrelatorId(flow, CORRELATOR_ID) - sub, service_name = flow.activate_module( + sub, service_name, subservice_name = flow.activate_module( request.DATA.get("SERVICE_NAME", None), request.DATA.get("SERVICE_ID", service_id), request.DATA.get("SUBSERVICE_NAME", None), @@ -2681,7 +2681,7 @@ def delete(self, request, service_id, subservice_id=None, iot_module=None): self.PERSEO_PORT, CORRELATOR_ID=CORRELATOR_ID) CORRELATOR_ID = self.getCorrelatorId(flow, CORRELATOR_ID) - result, service_name = flow.deactivate_module( + result, service_name, subservice_name = flow.deactivate_module( request.DATA.get("SERVICE_NAME", None), request.DATA.get("SERVICE_ID", service_id), request.DATA.get("SERVICE_USER_NAME", None), @@ -2710,7 +2710,7 @@ def delete(self, request, service_id, subservice_id=None, iot_module=None): self.PERSEO_PORT, CORRELATOR_ID=CORRELATOR_ID) CORRELATOR_ID = self.getCorrelatorId(flow, CORRELATOR_ID) - result, service_name = flow.deactivate_module( + result, service_name, subservice_name = flow.deactivate_module( request.DATA.get("SERVICE_NAME", None), request.DATA.get("SERVICE_ID", service_id), request.DATA.get("SUBSERVICE_NAME", None), @@ -2881,7 +2881,7 @@ def put(self, request): self.KEYSTONE_PORT, CORRELATOR_ID=CORRELATOR_ID) CORRELATOR_ID = self.getCorrelatorId(flow, CORRELATOR_ID) - result, service_name = flow.domains( + result, service_name, subservice_name = flow.domains( "admin_domain", request.DATA.get("SERVICE_ADMIN_USER", None), request.DATA.get("SERVICE_ADMIN_PASSWORD", None), diff --git a/src/orchestrator/commands/changeUserPassword.py b/src/orchestrator/commands/changeUserPassword.py index 2e909262..83e49326 100755 --- a/src/orchestrator/commands/changeUserPassword.py +++ b/src/orchestrator/commands/changeUserPassword.py @@ -99,7 +99,7 @@ def main(): USER_DATA_VALUE = {"password": NEW_USER_PASSWORD} - res, service_name = flow.updateUser( + res, service_name, subservice_name = flow.updateUser( SERVICE_NAME, None, SERVICE_ADMIN_USER, diff --git a/src/orchestrator/commands/changeUserPasswordByHimself.py b/src/orchestrator/commands/changeUserPasswordByHimself.py index c82a16bf..17fd780a 100755 --- a/src/orchestrator/commands/changeUserPasswordByHimself.py +++ b/src/orchestrator/commands/changeUserPasswordByHimself.py @@ -93,7 +93,7 @@ def main(): KEYSTONE_HOST, KEYSTONE_PORT) - res, service_name = flow.changeUserPassword( + res, service_name, subservice_name = flow.changeUserPassword( SERVICE_NAME, None, None, diff --git a/src/orchestrator/commands/createNewService.py b/src/orchestrator/commands/createNewService.py index fd28e0ed..d4138802 100755 --- a/src/orchestrator/commands/createNewService.py +++ b/src/orchestrator/commands/createNewService.py @@ -122,7 +122,7 @@ def main(): KEYPASS_HOST, KEYPASS_PORT) - res, service_name = flow.createNewService( + res, service_name, subservice_name = flow.createNewService( DOMAIN_NAME, DOMAIN_ADMIN_USER, DOMAIN_ADMIN_PASSWORD, diff --git a/src/orchestrator/commands/createNewServiceGroup.py b/src/orchestrator/commands/createNewServiceGroup.py index 839d543f..96c73eff 100644 --- a/src/orchestrator/commands/createNewServiceGroup.py +++ b/src/orchestrator/commands/createNewServiceGroup.py @@ -94,7 +94,7 @@ def main(): KEYSTONE_HOST, KEYSTONE_PORT) - res, service_name = flow.createNewServiceGroup( + res, service_name, subservice_name = flow.createNewServiceGroup( SERVICE_NAME, None, SERVICE_ADMIN_USER, diff --git a/src/orchestrator/commands/createNewServiceRole.py b/src/orchestrator/commands/createNewServiceRole.py index 85a93bff..9e4dc67f 100755 --- a/src/orchestrator/commands/createNewServiceRole.py +++ b/src/orchestrator/commands/createNewServiceRole.py @@ -105,7 +105,7 @@ def main(): KEYPASS_HOST, KEYPASS_PORT) - res, service_name = flow.createNewServiceRole( + res, service_name, subservice_name = flow.createNewServiceRole( None, SERVICE_NAME, SERVICE_ADMIN_USER, diff --git a/src/orchestrator/commands/createNewServiceUser.py b/src/orchestrator/commands/createNewServiceUser.py index ad0a2487..828eaedb 100755 --- a/src/orchestrator/commands/createNewServiceUser.py +++ b/src/orchestrator/commands/createNewServiceUser.py @@ -97,7 +97,7 @@ def main(): KEYSTONE_HOST, KEYSTONE_PORT) - res, service_name = flow.createNewServiceUser( + res, service_name, subservice_name = flow.createNewServiceUser( SERVICE_NAME, None, SERVICE_ADMIN_USER, diff --git a/src/orchestrator/commands/createNewSubService.py b/src/orchestrator/commands/createNewSubService.py index 3ad089f5..77355002 100755 --- a/src/orchestrator/commands/createNewSubService.py +++ b/src/orchestrator/commands/createNewSubService.py @@ -97,7 +97,7 @@ def main(): KEYSTONE_HOST, KEYSTONE_PORT) - res, service_name = flow.createNewSubService( + res, service_name, subservice_name = flow.createNewSubService( SERVICE_NAME, None, SERVICE_ADMIN_USER, diff --git a/src/orchestrator/commands/createTrustToken.py b/src/orchestrator/commands/createTrustToken.py index 35c10e3d..629a33f1 100755 --- a/src/orchestrator/commands/createTrustToken.py +++ b/src/orchestrator/commands/createTrustToken.py @@ -105,7 +105,7 @@ def main(): KEYSTONE_HOST, KEYSTONE_PORT) - res, service_name = flow.createTrustToken( + res, service_name, subservice_name = flow.createTrustToken( SERVICE_NAME, None, SUBSERVICE_NAME, diff --git a/src/orchestrator/commands/editService.py b/src/orchestrator/commands/editService.py index 0335430e..b0b9e0c7 100755 --- a/src/orchestrator/commands/editService.py +++ b/src/orchestrator/commands/editService.py @@ -83,7 +83,7 @@ def main(): KEYSTONE_HOST, KEYSTONE_PORT) - domain_detail, service_name = flow.update_domain( + domain_detail, service_name, subservice_name = flow.update_domain( None, SERVICE_NAME, DOMAIN_ADMIN_USER, diff --git a/src/orchestrator/commands/editSubService.py b/src/orchestrator/commands/editSubService.py index 4c4dd638..38c2cbc7 100755 --- a/src/orchestrator/commands/editSubService.py +++ b/src/orchestrator/commands/editSubService.py @@ -85,7 +85,7 @@ def main(): KEYSTONE_HOST, KEYSTONE_PORT) - project_detail, service_name = flow.update_project( + project_detail, service_name, subservice_name = flow.update_project( None, SERVICE_NAME, None, diff --git a/src/orchestrator/commands/listAllRoleAssignments.py b/src/orchestrator/commands/listAllRoleAssignments.py index 1f13b58f..7eeed409 100755 --- a/src/orchestrator/commands/listAllRoleAssignments.py +++ b/src/orchestrator/commands/listAllRoleAssignments.py @@ -91,7 +91,7 @@ def main(): KEYSTONE_HOST, KEYSTONE_PORT) - roles, service_name = flow.roles_assignments( + roles, service_name, subservice_name = flow.roles_assignments( None, SERVICE_NAME, None, diff --git a/src/orchestrator/commands/listGroupRoleAssignments.py b/src/orchestrator/commands/listGroupRoleAssignments.py index 4ead0c85..b279bec8 100644 --- a/src/orchestrator/commands/listGroupRoleAssignments.py +++ b/src/orchestrator/commands/listGroupRoleAssignments.py @@ -91,7 +91,7 @@ def main(): KEYSTONE_HOST, KEYSTONE_PORT) - roles, service_name = flow.roles_assignments_groups( + roles, service_name, subservice_name = flow.roles_assignments_groups( None, SERVICE_NAME, None, diff --git a/src/orchestrator/commands/listRoleAssignments.py b/src/orchestrator/commands/listRoleAssignments.py index 0bcd145a..594c55ee 100755 --- a/src/orchestrator/commands/listRoleAssignments.py +++ b/src/orchestrator/commands/listRoleAssignments.py @@ -91,7 +91,7 @@ def main(): KEYSTONE_HOST, KEYSTONE_PORT) - roles, service_name = flow.roles_assignments( + roles, service_name, subservice_name = flow.roles_assignments( None, SERVICE_NAME, None, diff --git a/src/orchestrator/commands/listSubServiceRoleAssignments.py b/src/orchestrator/commands/listSubServiceRoleAssignments.py index c194cfbf..996f8f73 100755 --- a/src/orchestrator/commands/listSubServiceRoleAssignments.py +++ b/src/orchestrator/commands/listSubServiceRoleAssignments.py @@ -87,11 +87,11 @@ def main(): #USER_NAME=sys.argv[7] EFFECTIVE = sys.argv[8] in ["True", "true", "TRUE"] - flow, service_name = Roles(KEYSTONE_PROTOCOL, + flow = Roles(KEYSTONE_PROTOCOL, KEYSTONE_HOST, KEYSTONE_PORT) - roles = flow.roles_assignments( + roles, service_name, subservice_name = flow.roles_assignments( None, SERVICE_NAME, None, diff --git a/src/orchestrator/commands/listUserRoleAssignments.py b/src/orchestrator/commands/listUserRoleAssignments.py index 7446aee5..2574c36b 100755 --- a/src/orchestrator/commands/listUserRoleAssignments.py +++ b/src/orchestrator/commands/listUserRoleAssignments.py @@ -91,7 +91,7 @@ def main(): KEYSTONE_HOST, KEYSTONE_PORT) - roles, service_name = flow.roles_assignments( + roles, service_name, subservice_name = flow.roles_assignments( None, SERVICE_NAME, None, diff --git a/src/orchestrator/commands/printServiceGroups.py b/src/orchestrator/commands/printServiceGroups.py index b03ca861..695f8ef1 100644 --- a/src/orchestrator/commands/printServiceGroups.py +++ b/src/orchestrator/commands/printServiceGroups.py @@ -80,7 +80,8 @@ def main(): KEYSTONE_HOST, KEYSTONE_PORT) - groups, service_name = flow.groups(SERVICE_NAME, + groups, service_name, subservice_name = flow.groups( + SERVICE_NAME, None, SERVICE_ADMIN_USER, SERVICE_ADMIN_PASSWORD, diff --git a/src/orchestrator/commands/printServiceIotModules.py b/src/orchestrator/commands/printServiceIotModules.py index 31648bbc..eacbce8a 100755 --- a/src/orchestrator/commands/printServiceIotModules.py +++ b/src/orchestrator/commands/printServiceIotModules.py @@ -100,7 +100,8 @@ def main(): ORION_HOST, ORION_PORT) - roles, service_name = flow.list_activated_modules(SERVICE_NAME, + roles, service_name, subservice_name = flow.list_activated_modules( + SERVICE_NAME, None, SUBSERVICE_NAME, None, diff --git a/src/orchestrator/commands/printServiceRolePolicies.py b/src/orchestrator/commands/printServiceRolePolicies.py index 134fb4d2..25fe5c14 100755 --- a/src/orchestrator/commands/printServiceRolePolicies.py +++ b/src/orchestrator/commands/printServiceRolePolicies.py @@ -96,7 +96,8 @@ def main(): KEYPASS_HOST, KEYPASS_PORT) - policies, service_name = flow.getDomainRolePolicies(None, + policies, service_name, subservice_name = flow.getDomainRolePolicies( + None, SERVICE_NAME, SERVICE_ADMIN_USER, SERVICE_ADMIN_PASSWORD, diff --git a/src/orchestrator/commands/printServiceRoles.py b/src/orchestrator/commands/printServiceRoles.py index 05d20e3f..0275f663 100755 --- a/src/orchestrator/commands/printServiceRoles.py +++ b/src/orchestrator/commands/printServiceRoles.py @@ -79,7 +79,8 @@ def main(): KEYSTONE_HOST, KEYSTONE_PORT) - roles, service_name = flow.roles(SERVICE_NAME, + roles, service_name, subservice_name = flow.roles( + SERVICE_NAME, None, SERVICE_ADMIN_USER, SERVICE_ADMIN_PASSWORD, diff --git a/src/orchestrator/commands/printServiceUsers.py b/src/orchestrator/commands/printServiceUsers.py index 34e9c262..b1ff7275 100755 --- a/src/orchestrator/commands/printServiceUsers.py +++ b/src/orchestrator/commands/printServiceUsers.py @@ -80,7 +80,8 @@ def main(): KEYSTONE_HOST, KEYSTONE_PORT) - users, service_name = flow.users(SERVICE_NAME, + users, service_name, subservice_name = flow.users( + SERVICE_NAME, None, SERVICE_ADMIN_USER, SERVICE_ADMIN_PASSWORD, diff --git a/src/orchestrator/commands/printServices.py b/src/orchestrator/commands/printServices.py index 64e6bf98..afc7b5ee 100755 --- a/src/orchestrator/commands/printServices.py +++ b/src/orchestrator/commands/printServices.py @@ -79,7 +79,8 @@ def main(): KEYSTONE_HOST, KEYSTONE_PORT) - domain_detail, service_name = flow.domains(DOMAIN_NAME, + domain_detail, service_name, subservice_name = flow.domains( + DOMAIN_NAME, DOMAIN_ADMIN_USER, DOMAIN_ADMIN_PASSWORD, None) diff --git a/src/orchestrator/commands/printSubServices.py b/src/orchestrator/commands/printSubServices.py index 0062510a..4343d4d1 100755 --- a/src/orchestrator/commands/printSubServices.py +++ b/src/orchestrator/commands/printSubServices.py @@ -80,7 +80,8 @@ def main(): KEYSTONE_HOST, KEYSTONE_PORT) - subservices, service_name = flow.projects(None, + subservices, service_name, subservice_name = flow.projects( + None, SERVICE_NAME, SERVICE_ADMIN_USER, SERVICE_ADMIN_PASSWORD, diff --git a/src/orchestrator/commands/registerSubServiceDevice.py b/src/orchestrator/commands/registerSubServiceDevice.py index c93e693c..f74cdd07 100644 --- a/src/orchestrator/commands/registerSubServiceDevice.py +++ b/src/orchestrator/commands/registerSubServiceDevice.py @@ -158,7 +158,7 @@ def main(): ORION_HOST, ORION_PORT) - res, service_name = flow.register_device( + res, service_name, subservice_name = flow.register_device( SERVICE_NAME, None, SUBSERVICE_NAME, diff --git a/src/orchestrator/commands/registerSubServiceEntity.py b/src/orchestrator/commands/registerSubServiceEntity.py index f27f2cda..737cb2d6 100644 --- a/src/orchestrator/commands/registerSubServiceEntity.py +++ b/src/orchestrator/commands/registerSubServiceEntity.py @@ -158,7 +158,7 @@ def main(): ORION_HOST, ORION_PORT) - res, service_name = flow.register_service( + res, service_name, subservice_name = flow.register_service( SERVICE_NAME, None, SUBSERVICE_NAME, diff --git a/src/orchestrator/commands/removeService.py b/src/orchestrator/commands/removeService.py index afb47355..872ab1af 100755 --- a/src/orchestrator/commands/removeService.py +++ b/src/orchestrator/commands/removeService.py @@ -92,7 +92,8 @@ def main(): KEYPASS_HOST, KEYPASS_PORT) - domain_detail, service_name = flow.delete_domain(None, + domain_detail, service_name, subservice_name = flow.delete_domain( + None, SERVICE_NAME, DOMAIN_ADMIN_USER, DOMAIN_ADMIN_PASSWORD, diff --git a/src/orchestrator/commands/removeServiceGroup.py b/src/orchestrator/commands/removeServiceGroup.py index ada833ac..bd9944a8 100644 --- a/src/orchestrator/commands/removeServiceGroup.py +++ b/src/orchestrator/commands/removeServiceGroup.py @@ -83,7 +83,8 @@ def main(): KEYSTONE_HOST, KEYSTONE_PORT) - group_detail, service_name = flow.removeUser(SERVICE_NAME, + group_detail, service_name, subservice_name = flow.removeUser( + SERVICE_NAME, None, SERVICE_ADMIN_USER, SERVICE_ADMIN_PASSWORD, diff --git a/src/orchestrator/commands/removeServiceRole.py b/src/orchestrator/commands/removeServiceRole.py index b5c6fd21..c279a918 100755 --- a/src/orchestrator/commands/removeServiceRole.py +++ b/src/orchestrator/commands/removeServiceRole.py @@ -83,7 +83,8 @@ def main(): KEYSTONE_HOST, KEYSTONE_PORT) - role_detail, service_name = flow.removeRole(SERVICE_NAME, + role_detail, service_name, subservice_name = flow.removeRole( + SERVICE_NAME, None, SERVICE_ADMIN_USER, SERVICE_ADMIN_PASSWORD, diff --git a/src/orchestrator/commands/removeServiceRolePolicy.py b/src/orchestrator/commands/removeServiceRolePolicy.py index 7714a112..1638ed4c 100644 --- a/src/orchestrator/commands/removeServiceRolePolicy.py +++ b/src/orchestrator/commands/removeServiceRolePolicy.py @@ -100,7 +100,7 @@ def main(): KEYPASS_HOST, KEYPASS_PORT) - role_detail, service_name = flow.removePolicyFromRole( + role_detail, service_name, subservice_name = flow.removePolicyFromRole( SERVICE_NAME, None, SERVICE_ADMIN_USER, diff --git a/src/orchestrator/commands/removeServiceUser.py b/src/orchestrator/commands/removeServiceUser.py index ba931b85..151f06ba 100755 --- a/src/orchestrator/commands/removeServiceUser.py +++ b/src/orchestrator/commands/removeServiceUser.py @@ -83,7 +83,8 @@ def main(): KEYSTONE_HOST, KEYSTONE_PORT) - user_detail, service_name = flow.removeUser(SERVICE_NAME, + user_detail, service_name, subservice_name = flow.removeUser( + SERVICE_NAME, None, SERVICE_ADMIN_USER, SERVICE_ADMIN_PASSWORD, diff --git a/src/orchestrator/commands/removeSubService.py b/src/orchestrator/commands/removeSubService.py index f0785ab0..bbb0b63e 100755 --- a/src/orchestrator/commands/removeSubService.py +++ b/src/orchestrator/commands/removeSubService.py @@ -83,7 +83,8 @@ def main(): KEYSTONE_HOST, KEYSTONE_PORT) - project_detail, service_name = flow.delete_project(None, + project_detail, service_name, subservice_name = flow.delete_project( + None, SERVICE_NAME, None, SUBSERVICE_NAME, diff --git a/src/orchestrator/core/flow/Domains.py b/src/orchestrator/core/flow/Domains.py index 555b42a3..db438a5b 100644 --- a/src/orchestrator/core/flow/Domains.py +++ b/src/orchestrator/core/flow/Domains.py @@ -81,7 +81,7 @@ def domains(self, } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) - return DOMAINS, None + return DOMAINS, None, None def get_domain(self, DOMAIN_ID, @@ -143,7 +143,7 @@ def get_domain(self, } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) - return DOMAIN, DOMAIN_NAME + return DOMAIN, DOMAIN_NAME, None def update_domain(self, DOMAIN_ID, @@ -210,7 +210,7 @@ def update_domain(self, "DOMAIN": DOMAIN } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) - return DOMAIN, DOMAIN_NAME + return DOMAIN, DOMAIN_NAME, None def delete_domain(self, DOMAIN_ID, @@ -351,7 +351,7 @@ def delete_domain(self, } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) - return DOMAIN, DOMAIN_NAME + return DOMAIN, DOMAIN_NAME, None def getDomainRolePolicies(self, @@ -465,7 +465,7 @@ def getDomainRolePolicies(self, } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) - return policies, SERVICE_NAME + return policies, SERVICE_NAME, None def activate_module(self, DOMAIN_NAME, @@ -578,7 +578,7 @@ def activate_module(self, "subscriptionid": subscriptionid } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) - return subscriptionid, DOMAIN_NAME + return subscriptionid, DOMAIN_NAME, None def deactivate_module(self, DOMAIN_NAME, @@ -672,7 +672,7 @@ def deactivate_module(self, } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) - return subscriptionid, DOMAIN_NAME + return subscriptionid, DOMAIN_NAME, None def list_activated_modules(self, @@ -749,4 +749,4 @@ def list_activated_modules(self, } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) - return modules, DOMAIN_NAME + return modules, DOMAIN_NAME, None diff --git a/src/orchestrator/core/flow/Groups.py b/src/orchestrator/core/flow/Groups.py index c46a708d..f0ce3bad 100644 --- a/src/orchestrator/core/flow/Groups.py +++ b/src/orchestrator/core/flow/Groups.py @@ -102,7 +102,7 @@ def groups(self, "SERVICE_GROUPS": SERVICE_GROUPS, } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) - return SERVICE_GROUPS, SERVICE_NAME + return SERVICE_GROUPS, SERVICE_NAME, None def group(self, @@ -165,7 +165,7 @@ def group(self, "DETAIL_GROUP": DETAIL_GROUP, } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) - return DETAIL_GROUP, SERVICE_NAME + return DETAIL_GROUP, SERVICE_NAME, None def updateGroup(self, @@ -250,7 +250,7 @@ def updateGroup(self, } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) - return {"id": GROUP_ID}, SERVICE_NAME + return {"id": GROUP_ID}, SERVICE_NAME, None def removeGroup(self, @@ -335,7 +335,7 @@ def removeGroup(self, } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) - return {}, SERVICE_NAME + return {}, SERVICE_NAME, None def createNewServiceGroup(self, SERVICE_NAME, @@ -417,4 +417,4 @@ def createNewServiceGroup(self, } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) - return {"id": ID_GROUP}, SERVICE_NAME + return {"id": ID_GROUP}, SERVICE_NAME, None diff --git a/src/orchestrator/core/flow/Projects.py b/src/orchestrator/core/flow/Projects.py index a1aed571..c6341810 100644 --- a/src/orchestrator/core/flow/Projects.py +++ b/src/orchestrator/core/flow/Projects.py @@ -97,7 +97,7 @@ def projects(self, } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) - return PROJECTS, DOMAIN_NAME + return PROJECTS, DOMAIN_NAME, None def get_project(self, DOMAIN_ID, @@ -148,6 +148,12 @@ def get_project(self, PROJECT = self.idm.getProject(ADMIN_TOKEN, PROJECT_ID) + + PROJECT_NAME = self.ensure_subservice_name(ADMIN_TOKEN, + DOMAIN_ID, + PROJECT_ID, + None) + self.logger.addFilter(ContextFilterSubService(PROJECT_NAME)) # PROJECTS = self.idm.getDomainProjects(ADMIN_TOKEN, # DOMAIN_ID) # for project in PROJECTS: @@ -164,7 +170,7 @@ def get_project(self, "PROJECT": PROJECT } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) - return PROJECT, DOMAIN_NAME + return PROJECT, DOMAIN_NAME, PROJECT_NAME def update_project(self, DOMAIN_ID, @@ -230,6 +236,11 @@ def update_project(self, PROJECT_ID = self.idm.getProjectId(ADMIN_TOKEN, DOMAIN_NAME, PROJECT_NAME) + PROJECT_NAME = self.ensure_subservice_name(ADMIN_TOKEN, + DOMAIN_ID, + PROJECT_ID, + PROJECT_NAME) + self.logger.addFilter(ContextFilterSubService(PROJECT_NAME)) PROJECT = self.idm.updateProject(ADMIN_TOKEN, DOMAIN_ID, @@ -246,7 +257,7 @@ def update_project(self, "PROJECT": PROJECT } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) - return PROJECT, DOMAIN_NAME + return PROJECT, DOMAIN_NAME, PROJECT_NAME def delete_project(self, DOMAIN_ID, @@ -367,7 +378,7 @@ def delete_project(self, } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) - return PROJECT, DOMAIN_NAME + return PROJECT, DOMAIN_NAME, PROJECT_NAME def register_service(self, @@ -776,7 +787,7 @@ def register_service(self, "subscriptionid_sth": subscriptionid_sth, "subscriptionid_perseo": subscriptionid_perseo } - return result, DOMAIN_NAME + return result, DOMAIN_NAME, PROJECT_NAME def register_device(self, @@ -1106,7 +1117,7 @@ def register_device(self, } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) - return DEVICE_ID, DOMAIN_NAME + return DEVICE_ID, DOMAIN_NAME, PROJECT_NAME def register_devices(self, @@ -1236,7 +1247,7 @@ def register_devices(self, "devices": DEVICES_ID } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) - return DEVICES_ID, DOMAIN_NAME + return DEVICES_ID, DOMAIN_NAME, PROJECT_NAME def unregister_device(self, DOMAIN_NAME, @@ -1331,7 +1342,7 @@ def unregister_device(self, } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) - return {}, DOMAIN_NAME + return {}, DOMAIN_NAME, PROJECT_NAME def activate_module(self, @@ -1472,7 +1483,7 @@ def activate_module(self, "subscriptionid": subscriptionid } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) - return subscriptionid, DOMAIN_NAME + return subscriptionid, DOMAIN_NAME, PROJECT_NAME def deactivate_module(self, DOMAIN_NAME, @@ -1586,7 +1597,7 @@ def deactivate_module(self, } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) - return subscriptionid, DOMAIN_NAME + return subscriptionid, DOMAIN_NAME, PROJECT_NAME def list_activated_modules(self, @@ -1685,4 +1696,4 @@ def list_activated_modules(self, } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) - return modules, DOMAIN_NAME + return modules, DOMAIN_NAME, PROJECT_NAME diff --git a/src/orchestrator/core/flow/Roles.py b/src/orchestrator/core/flow/Roles.py index b73247d4..712c52c6 100644 --- a/src/orchestrator/core/flow/Roles.py +++ b/src/orchestrator/core/flow/Roles.py @@ -111,7 +111,7 @@ def roles(self, } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) - return ROLES, DOMAIN_NAME + return ROLES, DOMAIN_NAME, None def roles_assignments(self, DOMAIN_ID, @@ -296,7 +296,7 @@ def roles_assignments(self, "role_assignments": role_assignments_expanded, } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) - return {"role_assignments": role_assignments_expanded}, DOMAIN_NAME + return {"role_assignments": role_assignments_expanded}, DOMAIN_NAME, PROJECT_NAME def assignRoleServiceUser(self, SERVICE_NAME, @@ -425,7 +425,7 @@ def assignRoleServiceUser(self, "ROLE_ID": "%s" % ROLE_ID } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) - return {}, SERVICE_NAME + return {}, SERVICE_NAME, None def assignRoleSubServiceUser(self, SERVICE_NAME, @@ -557,7 +557,7 @@ def assignRoleSubServiceUser(self, "ROLE_ID": "%s" % ROLE_ID } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) - return {}, SERVICE_NAME + return {}, SERVICE_NAME, SUBSERVICE_NAME def assignInheritRoleServiceUser(self, SERVICE_NAME, @@ -896,7 +896,7 @@ def revokeRoleSubServiceUser(self, "ROLE_ID": "%s" % ROLE_ID } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) - return {}, SERVICE_NAME + return {}, SERVICE_NAME, SUBSERVICE_NAME def revokeInheritRoleServiceUser(self, SERVICE_NAME, @@ -1001,7 +1001,7 @@ def revokeInheritRoleServiceUser(self, "INHERIT_ROLE_ID": "%s" % INHERIT_ROLE_ID } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) - return {}, SERVICE_NAME + return {}, SERVICE_NAME, None def roles_assignments_groups(self, @@ -1185,7 +1185,7 @@ def roles_assignments_groups(self, "role_assignments": role_assignments_expanded, } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) - return {"role_assignments": role_assignments_expanded}, DOMAIN_NAME + return {"role_assignments": role_assignments_expanded}, DOMAIN_NAME, PROJECT_NAME def assignRoleServiceGroup(self, @@ -1315,7 +1315,7 @@ def assignRoleServiceGroup(self, "ROLE_ID": "%s" % ROLE_ID } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) - return {}, SERVICE_NAME + return {}, SERVICE_NAME, None def assignRoleSubServiceGroup(self, @@ -1448,7 +1448,7 @@ def assignRoleSubServiceGroup(self, "ROLE_ID": "%s" % ROLE_ID } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) - return {}, SERVICE_NAME + return {}, SERVICE_NAME, SUBSERVICE_NAME def assignInheritRoleServiceGroup(self, @@ -1555,7 +1555,7 @@ def assignInheritRoleServiceGroup(self, "INHERIT_ROLE_ID": "%s" % INHERIT_ROLE_ID } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) - return {}, SERVICE_NAME + return {}, SERVICE_NAME, None def revokeRoleServiceGroup(self, @@ -1665,7 +1665,7 @@ def revokeRoleServiceGroup(self, "ROLE_ID": "%s" % ROLE_ID } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) - return {}, SERVICE_NAME + return {}, SERVICE_NAME, None def revokeRoleSubServiceGroup(self, @@ -1790,7 +1790,7 @@ def revokeRoleSubServiceGroup(self, "ROLE_ID": "%s" % ROLE_ID } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) - return {}, SERVICE_NAME + return {}, SERVICE_NAME, SUBSERVICE_NAME def revokeInheritRoleServiceGroup(self, SERVICE_NAME, @@ -1895,7 +1895,7 @@ def revokeInheritRoleServiceGroup(self, "INHERIT_ROLE_ID": "%s" % INHERIT_ROLE_ID } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) - return {}, SERVICE_NAME + return {}, SERVICE_NAME, None def removeRole(self, @@ -1979,7 +1979,7 @@ def removeRole(self, } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) - return {}, SERVICE_NAME + return {}, SERVICE_NAME, None def setPolicyRole(self, SERVICE_NAME, @@ -2084,7 +2084,7 @@ def setPolicyRole(self, self.logger.error(ex) return self.composeErrorCode(ex) - return {}, SERVICE_NAME + return {}, SERVICE_NAME, None def removePolicyFromRole(self, @@ -2192,7 +2192,7 @@ def removePolicyFromRole(self, self.logger.error(ex) return self.composeErrorCode(ex) - return {}, SERVICE_NAME + return {}, SERVICE_NAME, None def getPolicyFromRole(self, @@ -2299,4 +2299,4 @@ def getPolicyFromRole(self, self.logger.error(ex) return self.composeErrorCode(ex) - return {}, SERVICE_NAME + return {}, SERVICE_NAME, None diff --git a/src/orchestrator/core/flow/Users.py b/src/orchestrator/core/flow/Users.py index 2817d03e..62961d67 100644 --- a/src/orchestrator/core/flow/Users.py +++ b/src/orchestrator/core/flow/Users.py @@ -115,7 +115,7 @@ def users(self, "SERVICE_USERS": SERVICE_USERS, } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) - return SERVICE_USERS, SERVICE_NAME + return SERVICE_USERS, SERVICE_NAME, None def user(self, @@ -178,4 +178,4 @@ def user(self, "DETAIL_USER": DETAIL_USER, } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) - return DETAIL_USER, SERVICE_NAME + return DETAIL_USER, SERVICE_NAME, None diff --git a/src/orchestrator/core/flow/base.py b/src/orchestrator/core/flow/base.py index 290e2d34..9cf6670d 100644 --- a/src/orchestrator/core/flow/base.py +++ b/src/orchestrator/core/flow/base.py @@ -142,7 +142,7 @@ def composeErrorCode(self, ex): if res['code'] == 400 and len(ex.message) > 1 and \ ex.message[1].startswith('SPASSWORD'): res['error'] = ex.message[1] - return res, None + return res, None, None def get_endpoint_iot_module(self, iot_module): diff --git a/src/orchestrator/core/flow/createNewService.py b/src/orchestrator/core/flow/createNewService.py index 10057dde..d8151587 100644 --- a/src/orchestrator/core/flow/createNewService.py +++ b/src/orchestrator/core/flow/createNewService.py @@ -339,4 +339,4 @@ def createNewService(self, return { "token": NEW_SERVICE_ADMIN_TOKEN, "id": ID_DOM1, - }, DOMAIN_NAME + }, DOMAIN_NAME, None diff --git a/src/orchestrator/core/flow/createNewServiceRole.py b/src/orchestrator/core/flow/createNewServiceRole.py index 1029463c..118762a1 100644 --- a/src/orchestrator/core/flow/createNewServiceRole.py +++ b/src/orchestrator/core/flow/createNewServiceRole.py @@ -137,4 +137,4 @@ def createNewServiceRole(self, } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) - return {"id": ID_ROLE}, SERVICE_NAME + return {"id": ID_ROLE}, SERVICE_NAME, None diff --git a/src/orchestrator/core/flow/createNewServiceUser.py b/src/orchestrator/core/flow/createNewServiceUser.py index 7360cbb2..0c93e9c9 100644 --- a/src/orchestrator/core/flow/createNewServiceUser.py +++ b/src/orchestrator/core/flow/createNewServiceUser.py @@ -117,4 +117,4 @@ def createNewServiceUser(self, } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) - return {"id": ID_USER}, SERVICE_NAME + return {"id": ID_USER}, SERVICE_NAME, None diff --git a/src/orchestrator/core/flow/createNewSubService.py b/src/orchestrator/core/flow/createNewSubService.py index 7fc53bcc..63859a99 100644 --- a/src/orchestrator/core/flow/createNewSubService.py +++ b/src/orchestrator/core/flow/createNewSubService.py @@ -163,4 +163,4 @@ def createNewSubService(self, } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) - return {"id": ID_PRO1}, SERVICE_NAME + return {"id": ID_PRO1}, SERVICE_NAME, NEW_SUBSERVICE_NAME diff --git a/src/orchestrator/core/flow/createTrustToken.py b/src/orchestrator/core/flow/createTrustToken.py index 5bb2953b..f9eae104 100644 --- a/src/orchestrator/core/flow/createTrustToken.py +++ b/src/orchestrator/core/flow/createTrustToken.py @@ -187,7 +187,7 @@ def createTrustToken(self, } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) - return {"id": ID_TRUST}, SERVICE_NAME + return {"id": ID_TRUST}, SERVICE_NAME, SUBSERVICE_NAME diff --git a/src/orchestrator/core/flow/removeUser.py b/src/orchestrator/core/flow/removeUser.py index faddfcc7..ca987f05 100644 --- a/src/orchestrator/core/flow/removeUser.py +++ b/src/orchestrator/core/flow/removeUser.py @@ -113,4 +113,4 @@ def removeUser(self, } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) - return {}, SERVICE_NAME + return {}, SERVICE_NAME, None diff --git a/src/orchestrator/core/flow/updateUser.py b/src/orchestrator/core/flow/updateUser.py index 72b790fb..d1cc051a 100644 --- a/src/orchestrator/core/flow/updateUser.py +++ b/src/orchestrator/core/flow/updateUser.py @@ -114,7 +114,7 @@ def updateUser(self, } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) - return {"id": USER_ID}, SERVICE_NAME + return {"id": USER_ID}, SERVICE_NAME, None def changeUserPassword(self, @@ -202,4 +202,4 @@ def changeUserPassword(self, } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) - return {"id": USER_ID}, SERVICE_NAME + return {"id": USER_ID}, SERVICE_NAME, None From 1bfc3cb597f1ac8bb6872333777e6a13467081f9 Mon Sep 17 00:00:00 2001 From: Alvaro Vega Date: Wed, 11 Jan 2017 09:18:45 +0100 Subject: [PATCH 06/20] add missed return --- src/orchestrator/core/flow/Roles.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/orchestrator/core/flow/Roles.py b/src/orchestrator/core/flow/Roles.py index 712c52c6..3928bca5 100644 --- a/src/orchestrator/core/flow/Roles.py +++ b/src/orchestrator/core/flow/Roles.py @@ -663,7 +663,7 @@ def assignInheritRoleServiceUser(self, "INHERIT_ROLE_ID": "%s" % INHERIT_ROLE_ID } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) - return {}, SERVICE_NAME + return {}, SERVICE_NAME, None def revokeRoleServiceUser(self, SERVICE_NAME, @@ -772,7 +772,7 @@ def revokeRoleServiceUser(self, "ROLE_ID": "%s" % ROLE_ID } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) - return {}, SERVICE_NAME + return {}, SERVICE_NAME, None def revokeRoleSubServiceUser(self, SERVICE_NAME, From 01f2d9a1f7335be0d7cb4a987f1beee965c44ec9 Mon Sep 17 00:00:00 2001 From: Alvaro Vega Date: Wed, 11 Jan 2017 14:56:30 +0100 Subject: [PATCH 07/20] add outgoing metrics --- src/orchestrator/api/views.py | 241 +++++++++++------- src/orchestrator/common/util.py | 32 ++- src/orchestrator/core/flow/Domains.py | 30 +++ src/orchestrator/core/flow/Groups.py | 17 ++ src/orchestrator/core/flow/Projects.py | 43 +++- src/orchestrator/core/flow/Roles.py | 71 ++++++ src/orchestrator/core/flow/Users.py | 8 + src/orchestrator/core/flow/base.py | 24 +- .../core/flow/createNewService.py | 3 + .../core/flow/createNewServiceRole.py | 3 + .../core/flow/createNewServiceUser.py | 3 + .../core/flow/createNewSubService.py | 3 + .../core/flow/createTrustToken.py | 3 + src/orchestrator/core/flow/removeUser.py | 3 + src/orchestrator/core/flow/updateUser.py | 6 + 15 files changed, 391 insertions(+), 99 deletions(-) diff --git a/src/orchestrator/api/views.py b/src/orchestrator/api/views.py index 084a72e8..4f998152 100644 --- a/src/orchestrator/api/views.py +++ b/src/orchestrator/api/views.py @@ -125,7 +125,17 @@ class Stats(object): num_flow_errors = 0 service = {} - sum = {} + sum = { + "incomingTransactions": 0, + "incomingTransactionRequestSize": 0, + "incomingTransactionResponseSize": 0, + "incomingTransacionError": 0, + "serviceTime": 0, + "outgoingTransactions": 0, + "outgoingTransactionRequestSize": 0, + "outgoingTransactionResponseSize": 0, + "outgoingTransacionError": 0, + } # Metrics: # incomingTransactions @@ -135,9 +145,21 @@ class Stats(object): # serviceTime def collectMetrics(self, service_start, service_name, subservice_name, - request, response): + request, response, flow): service_stop = time.time() + if flow: + flow_metrics = flow.getFlowMetrics() + else: + flow_metrics = { + "serviceTime": 0, + "outgoingTransactions": 0, + "outgoingTransactionRequestSize": 0, + "outgoingTransactionResponseSize": 0, + "outgoingTransacionError": 0, + } + + # TODO: integrate flow (outgoing) metrics into results) if service_name and not service_name in self.service: self.service[service_name] = { @@ -147,6 +169,10 @@ def collectMetrics(self, service_start, service_name, subservice_name, "incomingTransactionResponseSize": 0, "incomingTransacionError": 0, "serviceTime": 0, + "outgoingTransactions": 0, + "outgoingTransactionRequestSize": 0, + "outgoingTransactionResponseSize": 0, + "ouggoingTransacionError": 0, }, "subservs": {} } @@ -158,22 +184,47 @@ def collectMetrics(self, service_start, service_name, subservice_name, "incomingTransactionRequestSize": 0, "incomingTransactionResponseSize": 0, "incomingTransacionError": 0, - "serviceTime": 0 + "serviceTime": 0, + "outgoingTransactions": 0, + "outgoingTransactionRequestSize": 0, + "outgoingTransactionResponseSize": 0, + "ouggoingTransacionError": 0, } if service_name: if subservice_name: + # Service and Subservice self.service[service_name]["subservs"][subservice_name]["incomingTransactions"] += 1 self.service[service_name]["subservs"][subservice_name]["incomingTransactionRequestSize"] += len(json.dumps(request.data)) self.service[service_name]["subservs"][subservice_name]["incomingTransactionResponseSize"] += len(json.dumps(response.data)) self.service[service_name]["subservs"][subservice_name]["serviceTime"] += (service_stop - service_start) + self.service[service_name]["subservs"][subservice_name]["outgoingTransactions"] += flow_metrics["outgoingTransactions"] + self.service[service_name]["subservs"][subservice_name]["outgoingTransactionRequestSize"] += flow_metrics["outgoingTransactionRequestSize"] + self.service[service_name]["subservs"][subservice_name]["outgoingTransactionResponseSize"] += flow_metrics["outgoingTransactionResponseSize"] + self.service[service_name]["subservs"][subservice_name]["serviceTime"] += flow_metrics["serviceTime"] + + + # Service self.service[service_name]["sum"]["incomingTransactions"] += 1 self.service[service_name]["sum"]["incomingTransactionRequestSize"] += len(json.dumps(request.data)) self.service[service_name]["sum"]["incomingTransactionResponseSize"] += len(json.dumps(response.data)) self.service[service_name]["sum"]["serviceTime"] += (service_stop - service_start) - + self.service[service_name]["sum"]["outgoingTransactions"] += flow_metrics["outgoingTransactions"] + self.service[service_name]["sum"]["outgoingTransactionRequestSize"] += flow_metrics["outgoingTransactionRequestSize"] + self.service[service_name]["sum"]["outgoingTransactionResponseSize"] += flow_metrics["outgoingTransactionResponseSize"] + self.service[service_name]["sum"]["serviceTime"] += flow_metrics["serviceTime"] + + # Sum + self.sum["incomingTransactions"] += 1 + self.sum["incomingTransactionRequestSize"] += len(json.dumps(request.data)) + self.sum["incomingTransactionResponseSize"] += len(json.dumps(response.data)) + self.sum["serviceTime"] += (service_stop - service_start) + self.sum["outgoingTransactions"] += flow_metrics["outgoingTransactions"] + self.sum["outgoingTransactionRequestSize"] += flow_metrics["outgoingTransactionRequestSize"] + self.sum["outgoingTransactionResponseSize"] += flow_metrics["outgoingTransactionResponseSize"] + self.sum["serviceTime"] += flow_metrics["serviceTime"] class IoTConf(Stats): @@ -291,7 +342,7 @@ def __init__(self): def get(self, request, service_id=None): self.schema_name = "ServiceList" service_start = time.time() - response = service_name = subservice_name = None + response = service_name = subservice_name = flow = None HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) try: @@ -337,13 +388,13 @@ def get(self, request, service_id=None): status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) - self.collectMetrics(service_start, service_name, subservice_name, request, response) + self.collectMetrics(service_start, service_name, subservice_name, request, response, flow) return response def put(self, request, service_id=None): service_start = time.time() - response = service_name = subservice_name = None + response = service_name = subservice_name = flow = None self.schema_name = "ServiceList" HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) @@ -378,12 +429,12 @@ def put(self, request, service_id=None): status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) - self.collectMetrics(service_start, service_name, subservice_name, request, response) + self.collectMetrics(service_start, service_name, subservice_name, request, response, flow) return response def delete(self, request, service_id=None): service_start = time.time() - response = service_name = subservice_name = None + response = service_name = subservice_name = flow = None self.schema_name = "ServiceList" HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) @@ -432,7 +483,7 @@ def delete(self, request, service_id=None): status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) - self.collectMetrics(service_start, service_name, subservice_name, request, response) + self.collectMetrics(service_start, service_name, subservice_name, request, response, flow) return response class ServiceCreate_RESTView(ServiceList_RESTView): @@ -448,7 +499,7 @@ def __init__(self): def post(self, request, *args, **kw): service_start = time.time() - response = service_name = subservice_name = None + response = service_name = subservice_name = flow = None HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) try: @@ -489,7 +540,7 @@ def post(self, request, *args, **kw): status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) - self.collectMetrics(service_start, service_name, subservice_name, request, response) + self.collectMetrics(service_start, service_name, subservice_name, request, response, flow) return response @@ -507,7 +558,7 @@ def __init__(self): def get(self, request, service_id=None, subservice_id=None): self.schema_name = "SubServiceList" service_start = time.time() - response = service_name = subservice_name = None + response = service_name = subservice_name = flow = None HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) try: @@ -559,13 +610,13 @@ def get(self, request, service_id=None, subservice_id=None): status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) - self.collectMetrics(service_start, service_name, subservice_name, request, response) + self.collectMetrics(service_start, service_name, subservice_name, request, response, flow) return response def put(self, request, service_id=None, subservice_id=None): self.schema_name = "SubServiceList" service_start = time.time() - response = service_name = subservice_name = None + response = service_name = subservice_name = flow = None HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) try: @@ -609,13 +660,13 @@ def put(self, request, service_id=None, subservice_id=None): status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) - self.collectMetrics(service_start, service_name, subservice_name, request, response) + self.collectMetrics(service_start, service_name, subservice_name, request, response, flow) return response def delete(self, request, service_id=None, subservice_id=None): self.schema_name = "SubServiceList" service_start = time.time() - response = service_name = subservice_name = None + response = service_name = subservice_name = flow = None HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) try: @@ -671,7 +722,7 @@ def delete(self, request, service_id=None, subservice_id=None): status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) - self.collectMetrics(service_start, service_name, subservice_name, request, response) + self.collectMetrics(service_start, service_name, subservice_name, request, response, flow) return response @@ -686,7 +737,7 @@ def __init__(self): def post(self, request, service_id): service_start = time.time() - response = service_name = subservice_name = None + response = service_name = subservice_name = flow = None HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) try: @@ -827,7 +878,7 @@ def post(self, request, service_id): status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) - self.collectMetrics(service_start, service_name, subservice_name, request, response) + self.collectMetrics(service_start, service_name, subservice_name, request, response, flow) return response class User_RESTView(APIView, IoTConf): @@ -843,7 +894,7 @@ def __init__(self): def delete(self, request, service_id, user_id): service_start = time.time() - response = service_name = subservice_name = None + response = service_name = subservice_name = flow = None HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) try: @@ -878,12 +929,12 @@ def delete(self, request, service_id, user_id): status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) - self.collectMetrics(service_start, service_name, subservice_name, request, response) + self.collectMetrics(service_start, service_name, subservice_name, request, response, flow) return response def put(self, request, service_id, user_id): service_start = time.time() - response = service_name = subservice_name = None + response = service_name = subservice_name = flow = None HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) try: @@ -918,12 +969,12 @@ def put(self, request, service_id, user_id): status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) - self.collectMetrics(service_start, service_name, subservice_name, request, response) + self.collectMetrics(service_start, service_name, subservice_name, request, response, flow) return response def get(self, request, service_id, user_id): service_start = time.time() - response = service_name = subservice_name = None + response = service_name = subservice_name = flow = None HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) try: @@ -958,12 +1009,12 @@ def get(self, request, service_id, user_id): status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) - self.collectMetrics(service_start, service_name, subservice_name, request, response) + self.collectMetrics(service_start, service_name, subservice_name, request, response, flow) return response def post(self, request, service_id, user_id): service_start = time.time() - response = service_name = subservice_name = None + response = service_name = subservice_name = flow = None HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) try: @@ -1000,7 +1051,7 @@ def post(self, request, service_id, user_id): status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) - self.collectMetrics(service_start, service_name, subservice_name, request, response) + self.collectMetrics(service_start, service_name, subservice_name, request, response, flow) return response @@ -1017,7 +1068,7 @@ def __init__(self): def get(self, request, service_id): service_start = time.time() - response = service_name = subservice_name = None + response = service_name = subservice_name = flow = None HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) index = request.GET.get('index', None) @@ -1056,12 +1107,12 @@ def get(self, request, service_id): status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) - self.collectMetrics(service_start, service_name, subservice_name, request, response) + self.collectMetrics(service_start, service_name, subservice_name, request, response, flow) return response def post(self, request, service_id): service_start = time.time() - response = service_name = subservice_name = None + response = service_name = subservice_name = flow = None HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) try: @@ -1099,7 +1150,7 @@ def post(self, request, service_id): status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) - self.collectMetrics(service_start, service_name, subservice_name, request, response) + self.collectMetrics(service_start, service_name, subservice_name, request, response, flow) return response @@ -1116,7 +1167,7 @@ def __init__(self): def delete(self, request, service_id, group_id): service_start = time.time() - response = service_name = subservice_name = None + response = service_name = subservice_name = flow = None HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) try: @@ -1151,12 +1202,12 @@ def delete(self, request, service_id, group_id): status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) - self.collectMetrics(service_start, service_name, subservice_name, request, response) + self.collectMetrics(service_start, service_name, subservice_name, request, response, flow) return response def put(self, request, service_id, group_id): service_start = time.time() - response = service_name = subservice_name = None + response = service_name = subservice_name = flow = None HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) try: @@ -1190,12 +1241,12 @@ def put(self, request, service_id, group_id): status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) - self.collectMetrics(service_start, service_name, subservice_name, request, response) + self.collectMetrics(service_start, service_name, subservice_name, request, response, flow) return response def get(self, request, service_id, group_id): service_start = time.time() - response = service_name = subservice_name = None + response = service_name = subservice_name = flow = None HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) try: @@ -1230,7 +1281,7 @@ def get(self, request, service_id, group_id): status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) - self.collectMetrics(service_start, service_name, subservice_name, request, response) + self.collectMetrics(service_start, service_name, subservice_name, request, response, flow) return response @@ -1247,7 +1298,7 @@ def __init__(self): def get(self, request, service_id): service_start = time.time() - response = service_name = subservice_name = None + response = service_name = subservice_name = flow = None HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) index = request.GET.get('index', None) @@ -1286,12 +1337,12 @@ def get(self, request, service_id): status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) - self.collectMetrics(service_start, service_name, subservice_name, request, response) + self.collectMetrics(service_start, service_name, subservice_name, request, response, flow) return response def post(self, request, service_id): service_start = time.time() - response = service_name = subservice_name = None + response = service_name = subservice_name = flow = None HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) try: @@ -1327,7 +1378,7 @@ def post(self, request, service_id): status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) - self.collectMetrics(service_start, service_name, subservice_name, request, response) + self.collectMetrics(service_start, service_name, subservice_name, request, response, flow) return response @@ -1344,7 +1395,7 @@ def __init__(self): def get(self, request, service_id, role_id): service_start = time.time() - response = service_name = subservice_name = None + response = service_name = subservice_name = flow = None HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) try: @@ -1385,13 +1436,13 @@ def get(self, request, service_id, role_id): status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) - self.collectMetrics(service_start, service_name, subservice_name, request, response) + self.collectMetrics(service_start, service_name, subservice_name, request, response, flow) return response def post(self, request, service_id, role_id): service_start = time.time() - response = service_name = subservice_name = None + response = service_name = subservice_name = flow = None HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) try: @@ -1435,12 +1486,12 @@ def post(self, request, service_id, role_id): status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) - self.collectMetrics(service_start, service_name, subservice_name, request, response) + self.collectMetrics(service_start, service_name, subservice_name, request, response, flow) return response def delete(self, request, service_id, role_id): service_start = time.time() - response = service_name = subservice_name = None + response = service_name = subservice_name = flow = None HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) try: @@ -1480,7 +1531,7 @@ def delete(self, request, service_id, role_id): status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) - self.collectMetrics(service_start, service_name, subservice_name, request, response) + self.collectMetrics(service_start, service_name, subservice_name, request, response, flow) return response @@ -1498,7 +1549,7 @@ def __init__(self): def get(self, request, service_id, role_id, policy_id): service_start = time.time() - response = service_name = subservice_name = None + response = service_name = subservice_name = flow = None HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) try: @@ -1539,12 +1590,12 @@ def get(self, request, service_id, role_id, policy_id): status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) - self.collectMetrics(service_start, service_name, subservice_name, request, response) + self.collectMetrics(service_start, service_name, subservice_name, request, response, flow) return response def delete(self, request, service_id, role_id, policy_id): service_start = time.time() - response = service_name = subservice_name = None + response = service_name = subservice_name = flow = None HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) try: @@ -1585,7 +1636,7 @@ def delete(self, request, service_id, role_id, policy_id): status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) - self.collectMetrics(service_start, service_name, subservice_name, request, response) + self.collectMetrics(service_start, service_name, subservice_name, request, response, flow) return response @@ -1602,7 +1653,7 @@ def __init__(self): def post(self, request, service_id): service_start = time.time() - response = service_name = subservice_name = None + response = service_name = subservice_name = flow = None self.schema_name = "RoleList" HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) @@ -1638,13 +1689,13 @@ def post(self, request, service_id): error.detail), status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} - ) - self.collectMetrics(service_start, service_name, subservice_name, request, response) + ) + self.collectMetrics(service_start, service_name, subservice_name, request, response, flow) return response def get(self, request, service_id=None): service_start = time.time() - response = service_name = subservice_name = None + response = service_name = subservice_name = flow = None self.schema_name = "RoleAssignmentList" # Like that scheme! HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) @@ -1683,7 +1734,7 @@ def get(self, request, service_id=None): status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) - self.collectMetrics(service_start, service_name, subservice_name, request, response) + self.collectMetrics(service_start, service_name, subservice_name, request, response, flow) return response @@ -1697,7 +1748,7 @@ def __init__(self): def get(self, request, service_id): service_start = time.time() - response = service_name = subservice_name = None + response = service_name = subservice_name = flow = None self.schema_name = "RoleAssignmentList" user_id = request.GET.get('user_id', None) subservice_id = request.GET.get('subservice_id', None) @@ -1743,12 +1794,12 @@ def get(self, request, service_id): status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) - self.collectMetrics(service_start, service_name, subservice_name, request, response) + self.collectMetrics(service_start, service_name, subservice_name, request, response, flow) return response def post(self, request, service_id): service_start = time.time() - response = service_name = subservice_name = None + response = service_name = subservice_name = flow = None self.schema_name = "AssignRole" HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) @@ -1820,12 +1871,12 @@ def post(self, request, service_id): status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) - self.collectMetrics(service_start, service_name, subservice_name, request, response) + self.collectMetrics(service_start, service_name, subservice_name, request, response, flow) return response def delete(self, request, service_id): service_start = time.time() - response = service_name = subservice_name = None + response = service_name = subservice_name = flow = None self.schema_name = "AssignRole" HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) @@ -1898,7 +1949,7 @@ def delete(self, request, service_id): status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) - self.collectMetrics(service_start, service_name, subservice_name, request, response) + self.collectMetrics(service_start, service_name, subservice_name, request, response, flow) return response @@ -1912,7 +1963,7 @@ def __init__(self): def get(self, request, service_id): service_start = time.time() - response = service_name = subservice_name = None + response = service_name = subservice_name = flow = None self.schema_name = "RoleAssignmentList" group_id = request.GET.get('group_id', None) subservice_id = request.GET.get('subservice_id', None) @@ -1958,12 +2009,12 @@ def get(self, request, service_id): status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) - self.collectMetrics(service_start, service_name, subservice_name, request, response) + self.collectMetrics(service_start, service_name, subservice_name, request, response, flow) return response def post(self, request, service_id): service_start = time.time() - response = service_name = subservice_name = None + response = service_name = subservice_name = flow = None self.schema_name = "AssignRole" HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) @@ -2035,12 +2086,12 @@ def post(self, request, service_id): status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) - self.collectMetrics(service_start, service_name, subservice_name, request, response) + self.collectMetrics(service_start, service_name, subservice_name, request, response, flow) return response def delete(self, request, service_id): service_start = time.time() - response = service_name = subservice_name = None + response = service_name = subservice_name = flow = None self.schema_name = "AssignRole" HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) @@ -2113,7 +2164,7 @@ def delete(self, request, service_id): status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) - self.collectMetrics(service_start, service_name, subservice_name, request, response) + self.collectMetrics(service_start, service_name, subservice_name, request, response, flow) return response @@ -2130,7 +2181,7 @@ def __init__(self): def post(self, request, service_id): service_start = time.time() - response = service_name = subservice_name = None + response = service_name = subservice_name = flow = None HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) try: @@ -2173,7 +2224,7 @@ def post(self, request, service_id): status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) - self.collectMetrics(service_start, service_name, subservice_name, request, response) + self.collectMetrics(service_start, service_name, subservice_name, request, response, flow) return response @@ -2190,7 +2241,7 @@ def __init__(self): def post(self, request, service_id, subservice_id): service_start = time.time() - response = service_name = subservice_name = None + response = service_name = subservice_name = flow = None HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) try: @@ -2250,12 +2301,12 @@ def post(self, request, service_id, subservice_id): status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) - self.collectMetrics(service_start, service_name, subservice_name, request, response) + self.collectMetrics(service_start, service_name, subservice_name, request, response, flow) return response def delete(self, request, service_id, subservice_id): service_start = time.time() - response = service_name = subservice_name = None + response = service_name = subservice_name = flow = None HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) try: @@ -2308,7 +2359,7 @@ def delete(self, request, service_id, subservice_id): status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) - self.collectMetrics(service_start, service_name, subservice_name, request, response) + self.collectMetrics(service_start, service_name, subservice_name, request, response, flow) return response @@ -2325,7 +2376,7 @@ def __init__(self): def post(self, request, service_id, subservice_id): service_start = time.time() - response = service_name = subservice_name = None + response = service_name = subservice_name = flow = None HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) try: @@ -2378,7 +2429,7 @@ def post(self, request, service_id, subservice_id): status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) - self.collectMetrics(service_start, service_name, subservice_name, request, response) + self.collectMetrics(service_start, service_name, subservice_name, request, response, flow) return response @@ -2395,7 +2446,7 @@ def __init__(self): def post(self, request, service_id, subservice_id): service_start = time.time() - response = service_name = subservice_name = None + response = service_name = subservice_name = flow = None HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) try: @@ -2458,7 +2509,7 @@ def post(self, request, service_id, subservice_id): status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) - self.collectMetrics(service_start, service_name, subservice_name, request, response) + self.collectMetrics(service_start, service_name, subservice_name, request, response, flow) return response @@ -2475,7 +2526,7 @@ def __init__(self): def get(self, request, service_id, subservice_id=None): service_start = time.time() - response = service_name = subservice_name = None + response = service_name = subservice_name = flow = None HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) try: @@ -2559,12 +2610,12 @@ def get(self, request, service_id, subservice_id=None): status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) - self.collectMetrics(service_start, service_name, subservice_name, request, response) + self.collectMetrics(service_start, service_name, subservice_name, request, response, flow) return response def post(self, request, service_id, subservice_id=None, iot_module=None): service_start = time.time() - response = service_name = subservice_name = None + response = service_name = subservice_name = flow = None HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) try: @@ -2649,13 +2700,13 @@ def post(self, request, service_id, subservice_id=None, iot_module=None): status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) - self.collectMetrics(service_start, service_name, subservice_name, request, response) + self.collectMetrics(service_start, service_name, subservice_name, request, response, flow) return response def delete(self, request, service_id, subservice_id=None, iot_module=None): service_start = time.time() - response = service_name = subservice_name = None + response = service_name = subservice_name = flow = None HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) try: @@ -2739,7 +2790,7 @@ def delete(self, request, service_id, subservice_id=None, iot_module=None): status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) - self.collectMetrics(service_start, service_name, subservice_name, request, response) + self.collectMetrics(service_start, service_name, subservice_name, request, response, flow) return response @@ -2753,7 +2804,7 @@ def __init__(self): def get(self, request): service_start = time.time() - response = service_name = subservice_name = None + response = service_name = subservice_name = flow = None #HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) try: # Extract version and stats data @@ -2829,7 +2880,7 @@ def get(self, request): error.detail), status=status.HTTP_400_BAD_REQUEST ) - self.collectMetrics(service_start, service_name, subservice_name, request, response) + self.collectMetrics(service_start, service_name, subservice_name, request, response, flow) return response @@ -2843,7 +2894,7 @@ def __init__(self): def get(self, request): service_start = time.time() - response = service_name = subservice_name = None + response = service_name = subservice_name = flow = None CORRELATOR_ID = self.getCorrelatorIdHeader(request) try: @@ -2864,12 +2915,12 @@ def get(self, request): status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) - self.collectMetrics(service_start, service_name, subservice_name, request, response) + self.collectMetrics(service_start, service_name, subservice_name, request, response, flow) return response def put(self, request): service_start = time.time() - response = service_name = subservice_name = None + response = service_name = subservice_name = flow = None HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) logLevel = request.GET.get('level', None) @@ -2938,7 +2989,7 @@ def put(self, request): status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) - self.collectMetrics(service_start, service_name, subservice_name, request, response) + self.collectMetrics(service_start, service_name, subservice_name, request, response, flow) return response class OrchMetrics_RESTView(APIView, IoTConf): @@ -2951,7 +3002,7 @@ def __init__(self): def get(self, request): service_start = time.time() - response = service_name = subservice_name = None + response = service_name = subservice_name = flow = None HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) reset = request.GET.get('reset1', None) @@ -2975,12 +3026,12 @@ def get(self, request): status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) - self.collectMetrics(service_start, service_name, subservice_name, request, response) + self.collectMetrics(service_start, service_name, subservice_name, request, response, flow) return response def delete(self, request): service_start = time.time() - response = service_name = subservice_name = None + response = service_name = subservice_name = flow = None HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) @@ -3002,5 +3053,5 @@ def delete(self, request): status=status.HTTP_400_BAD_REQUEST, headers={"Fiware-Correlator": CORRELATOR_ID} ) - self.collectMetrics(service_start, service_name, subservice_name, request, response) + self.collectMetrics(service_start, service_name, subservice_name, request, response, flow) return response diff --git a/src/orchestrator/common/util.py b/src/orchestrator/common/util.py index c8b2d3ce..aa08b4f0 100644 --- a/src/orchestrator/common/util.py +++ b/src/orchestrator/common/util.py @@ -28,6 +28,7 @@ import StringIO import requests import logging +import time class RestOperations(object): ''' @@ -61,6 +62,16 @@ def __init__(self, else: self.CORRELATOR_ID = None + self.service = {} + self.sum = { + "serviceTime": 0, + "outgoingTransactions": 0, + "outgoingTransactionRequestSize": 0, + "outgoingTransactionResponseSize": 0, + "outgoingTransacionError": 0, + } + + def rest_request(self, url, method, user=None, password=None, data=None, json_data=True, relative_url=True, @@ -71,6 +82,7 @@ def rest_request(self, url, method, user=None, password=None, In case of HTTP error, the exception is returned normally instead of raised and, if JSON error data is present in the response, .msg will contain the error detail.''' + service_start = time.time() user = user or None password = password or None @@ -149,10 +161,12 @@ def rest_request(self, url, method, user=None, password=None, except Exception, e: print e except urllib2.URLError, e: + data = None res = e res.code = 500 res.msg = self.ENDPOINT_NAME + " endpoint ERROR: " + res.args[0][1] + self.collectOutgoingMetrics(service_start, request.data, data) return res @@ -168,6 +182,7 @@ def rest_request2(self, url, method, user=None, password=None, Without SSL security ''' + service_start = time.time() user = user or None password = password or None auth = None @@ -234,9 +249,22 @@ def rest_request2(self, url, method, user=None, password=None, except Exception, e: print e + self.collectOutgoingMetrics(service_start, rdata, res) return res + def collectOutgoingMetrics(self, service_start, data_request, data_response): + + service_stop = time.time() + self.sum["outgoingTransactions"] += 1 + self.sum["outgoingTransactionRequestSize"] += len(json.dumps(data_request)) + self.sum["outgoingTransactionResponseSize"] += len(json.dumps(data_response)) + self.sum["serviceTime"] += (service_stop - service_start) + + def getOutgoingMetrics(self): + return self.sum + + class CSVOperations(object): ''' @@ -298,13 +326,13 @@ def __init__(self, subservice): def filter(self, record): record.subservice = self.subservice - return True + return True class ContextFilterCorrelatorId(logging.Filter): """ This is a filter which injects contextual information into the log. - """ + """ def __init__(self, CORRELATOR_ID): self.CORRELATOR_ID = CORRELATOR_ID diff --git a/src/orchestrator/core/flow/Domains.py b/src/orchestrator/core/flow/Domains.py index db438a5b..27b62a5e 100644 --- a/src/orchestrator/core/flow/Domains.py +++ b/src/orchestrator/core/flow/Domains.py @@ -81,6 +81,10 @@ def domains(self, } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) + + # Consolidate opetions metrics into flow metrics + self.collectComponentMetrics() + return DOMAINS, None, None def get_domain(self, @@ -143,6 +147,10 @@ def get_domain(self, } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) + + # Consolidate opetions metrics into flow metrics + self.collectComponentMetrics() + return DOMAIN, DOMAIN_NAME, None def update_domain(self, @@ -210,6 +218,10 @@ def update_domain(self, "DOMAIN": DOMAIN } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) + + # Consolidate opetions metrics into flow metrics + self.collectComponentMetrics() + return DOMAIN, DOMAIN_NAME, None def delete_domain(self, @@ -351,6 +363,10 @@ def delete_domain(self, } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) + + # Consolidate opetions metrics into flow metrics + self.collectComponentMetrics() + return DOMAIN, DOMAIN_NAME, None @@ -465,6 +481,10 @@ def getDomainRolePolicies(self, } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) + + # Consolidate opetions metrics into flow metrics + self.collectComponentMetrics() + return policies, SERVICE_NAME, None def activate_module(self, @@ -578,6 +598,10 @@ def activate_module(self, "subscriptionid": subscriptionid } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) + + # Consolidate opetions metrics into flow metrics + self.collectComponentMetrics() + return subscriptionid, DOMAIN_NAME, None def deactivate_module(self, @@ -672,6 +696,9 @@ def deactivate_module(self, } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) + # Consolidate opetions metrics into flow metrics + self.collectComponentMetrics() + return subscriptionid, DOMAIN_NAME, None @@ -749,4 +776,7 @@ def list_activated_modules(self, } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) + # Consolidate opetions metrics into flow metrics + self.collectComponentMetrics() + return modules, DOMAIN_NAME, None diff --git a/src/orchestrator/core/flow/Groups.py b/src/orchestrator/core/flow/Groups.py index f0ce3bad..b370f61c 100644 --- a/src/orchestrator/core/flow/Groups.py +++ b/src/orchestrator/core/flow/Groups.py @@ -102,6 +102,10 @@ def groups(self, "SERVICE_GROUPS": SERVICE_GROUPS, } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) + + # Consolidate opetions metrics into flow metrics + self.collectComponentMetrics() + return SERVICE_GROUPS, SERVICE_NAME, None @@ -165,6 +169,10 @@ def group(self, "DETAIL_GROUP": DETAIL_GROUP, } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) + + # Consolidate opetions metrics into flow metrics + self.collectComponentMetrics() + return DETAIL_GROUP, SERVICE_NAME, None @@ -250,6 +258,9 @@ def updateGroup(self, } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) + # Consolidate opetions metrics into flow metrics + self.collectComponentMetrics() + return {"id": GROUP_ID}, SERVICE_NAME, None @@ -335,6 +346,9 @@ def removeGroup(self, } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) + # Consolidate opetions metrics into flow metrics + self.collectComponentMetrics() + return {}, SERVICE_NAME, None def createNewServiceGroup(self, @@ -417,4 +431,7 @@ def createNewServiceGroup(self, } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) + # Consolidate opetions metrics into flow metrics + self.collectComponentMetrics() + return {"id": ID_GROUP}, SERVICE_NAME, None diff --git a/src/orchestrator/core/flow/Projects.py b/src/orchestrator/core/flow/Projects.py index c6341810..4665f072 100644 --- a/src/orchestrator/core/flow/Projects.py +++ b/src/orchestrator/core/flow/Projects.py @@ -97,6 +97,9 @@ def projects(self, } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) + # Consolidate opetions metrics into flow metrics + self.collectComponentMetrics() + return PROJECTS, DOMAIN_NAME, None def get_project(self, @@ -170,6 +173,10 @@ def get_project(self, "PROJECT": PROJECT } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) + + # Consolidate opetions metrics into flow metrics + self.collectComponentMetrics() + return PROJECT, DOMAIN_NAME, PROJECT_NAME def update_project(self, @@ -240,7 +247,7 @@ def update_project(self, DOMAIN_ID, PROJECT_ID, PROJECT_NAME) - self.logger.addFilter(ContextFilterSubService(PROJECT_NAME)) + self.logger.addFilter(ContextFilterSubService(PROJECT_NAME)) PROJECT = self.idm.updateProject(ADMIN_TOKEN, DOMAIN_ID, @@ -257,6 +264,10 @@ def update_project(self, "PROJECT": PROJECT } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) + + # Consolidate opetions metrics into flow metrics + self.collectComponentMetrics() + return PROJECT, DOMAIN_NAME, PROJECT_NAME def delete_project(self, @@ -378,6 +389,10 @@ def delete_project(self, } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) + + # Consolidate opetions metrics into flow metrics + self.collectComponentMetrics() + return PROJECT, DOMAIN_NAME, PROJECT_NAME @@ -787,6 +802,10 @@ def register_service(self, "subscriptionid_sth": subscriptionid_sth, "subscriptionid_perseo": subscriptionid_perseo } + + # Consolidate opetions metrics into flow metrics + self.collectComponentMetrics() + return result, DOMAIN_NAME, PROJECT_NAME @@ -1117,6 +1136,10 @@ def register_device(self, } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) + + # Consolidate opetions metrics into flow metrics + self.collectComponentMetrics() + return DEVICE_ID, DOMAIN_NAME, PROJECT_NAME @@ -1247,6 +1270,10 @@ def register_devices(self, "devices": DEVICES_ID } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) + + # Consolidate opetions metrics into flow metrics + self.collectComponentMetrics() + return DEVICES_ID, DOMAIN_NAME, PROJECT_NAME def unregister_device(self, @@ -1342,6 +1369,10 @@ def unregister_device(self, } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) + + # Consolidate opetions metrics into flow metrics + self.collectComponentMetrics() + return {}, DOMAIN_NAME, PROJECT_NAME @@ -1483,6 +1514,10 @@ def activate_module(self, "subscriptionid": subscriptionid } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) + + # Consolidate opetions metrics into flow metrics + self.collectComponentMetrics() + return subscriptionid, DOMAIN_NAME, PROJECT_NAME def deactivate_module(self, @@ -1597,6 +1632,9 @@ def deactivate_module(self, } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) + # Consolidate opetions metrics into flow metrics + self.collectComponentMetrics() + return subscriptionid, DOMAIN_NAME, PROJECT_NAME @@ -1696,4 +1734,7 @@ def list_activated_modules(self, } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) + # Consolidate opetions metrics into flow metrics + self.collectComponentMetrics() + return modules, DOMAIN_NAME, PROJECT_NAME diff --git a/src/orchestrator/core/flow/Roles.py b/src/orchestrator/core/flow/Roles.py index 3928bca5..6a8d03aa 100644 --- a/src/orchestrator/core/flow/Roles.py +++ b/src/orchestrator/core/flow/Roles.py @@ -111,6 +111,9 @@ def roles(self, } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) + # Consolidate opetions metrics into flow metrics + self.collectComponentMetrics() + return ROLES, DOMAIN_NAME, None def roles_assignments(self, @@ -296,6 +299,10 @@ def roles_assignments(self, "role_assignments": role_assignments_expanded, } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) + + # Consolidate opetions metrics into flow metrics + self.collectComponentMetrics() + return {"role_assignments": role_assignments_expanded}, DOMAIN_NAME, PROJECT_NAME def assignRoleServiceUser(self, @@ -425,6 +432,10 @@ def assignRoleServiceUser(self, "ROLE_ID": "%s" % ROLE_ID } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) + + # Consolidate opetions metrics into flow metrics + self.collectComponentMetrics() + return {}, SERVICE_NAME, None def assignRoleSubServiceUser(self, @@ -557,6 +568,10 @@ def assignRoleSubServiceUser(self, "ROLE_ID": "%s" % ROLE_ID } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) + + # Consolidate opetions metrics into flow metrics + self.collectComponentMetrics() + return {}, SERVICE_NAME, SUBSERVICE_NAME def assignInheritRoleServiceUser(self, @@ -663,6 +678,10 @@ def assignInheritRoleServiceUser(self, "INHERIT_ROLE_ID": "%s" % INHERIT_ROLE_ID } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) + + # Consolidate opetions metrics into flow metrics + self.collectComponentMetrics() + return {}, SERVICE_NAME, None def revokeRoleServiceUser(self, @@ -772,6 +791,10 @@ def revokeRoleServiceUser(self, "ROLE_ID": "%s" % ROLE_ID } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) + + # Consolidate opetions metrics into flow metrics + self.collectComponentMetrics() + return {}, SERVICE_NAME, None def revokeRoleSubServiceUser(self, @@ -896,6 +919,10 @@ def revokeRoleSubServiceUser(self, "ROLE_ID": "%s" % ROLE_ID } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) + + # Consolidate opetions metrics into flow metrics + self.collectComponentMetrics() + return {}, SERVICE_NAME, SUBSERVICE_NAME def revokeInheritRoleServiceUser(self, @@ -1001,6 +1028,10 @@ def revokeInheritRoleServiceUser(self, "INHERIT_ROLE_ID": "%s" % INHERIT_ROLE_ID } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) + + # Consolidate opetions metrics into flow metrics + self.collectComponentMetrics() + return {}, SERVICE_NAME, None @@ -1185,6 +1216,10 @@ def roles_assignments_groups(self, "role_assignments": role_assignments_expanded, } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) + + # Consolidate opetions metrics into flow metrics + self.collectComponentMetrics() + return {"role_assignments": role_assignments_expanded}, DOMAIN_NAME, PROJECT_NAME @@ -1315,6 +1350,10 @@ def assignRoleServiceGroup(self, "ROLE_ID": "%s" % ROLE_ID } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) + + # Consolidate opetions metrics into flow metrics + self.collectComponentMetrics() + return {}, SERVICE_NAME, None @@ -1448,6 +1487,10 @@ def assignRoleSubServiceGroup(self, "ROLE_ID": "%s" % ROLE_ID } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) + + # Consolidate opetions metrics into flow metrics + self.collectComponentMetrics() + return {}, SERVICE_NAME, SUBSERVICE_NAME @@ -1555,6 +1598,10 @@ def assignInheritRoleServiceGroup(self, "INHERIT_ROLE_ID": "%s" % INHERIT_ROLE_ID } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) + + # Consolidate opetions metrics into flow metrics + self.collectComponentMetrics() + return {}, SERVICE_NAME, None @@ -1665,6 +1712,10 @@ def revokeRoleServiceGroup(self, "ROLE_ID": "%s" % ROLE_ID } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) + + # Consolidate opetions metrics into flow metrics + self.collectComponentMetrics() + return {}, SERVICE_NAME, None @@ -1790,6 +1841,10 @@ def revokeRoleSubServiceGroup(self, "ROLE_ID": "%s" % ROLE_ID } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) + + # Consolidate opetions metrics into flow metrics + self.collectComponentMetrics() + return {}, SERVICE_NAME, SUBSERVICE_NAME def revokeInheritRoleServiceGroup(self, @@ -1895,6 +1950,10 @@ def revokeInheritRoleServiceGroup(self, "INHERIT_ROLE_ID": "%s" % INHERIT_ROLE_ID } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) + + # Consolidate opetions metrics into flow metrics + self.collectComponentMetrics() + return {}, SERVICE_NAME, None @@ -1979,6 +2038,9 @@ def removeRole(self, } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) + # Consolidate opetions metrics into flow metrics + self.collectComponentMetrics() + return {}, SERVICE_NAME, None def setPolicyRole(self, @@ -2084,6 +2146,9 @@ def setPolicyRole(self, self.logger.error(ex) return self.composeErrorCode(ex) + # Consolidate opetions metrics into flow metrics + self.collectComponentMetrics() + return {}, SERVICE_NAME, None @@ -2192,6 +2257,9 @@ def removePolicyFromRole(self, self.logger.error(ex) return self.composeErrorCode(ex) + # Consolidate opetions metrics into flow metrics + self.collectComponentMetrics() + return {}, SERVICE_NAME, None @@ -2299,4 +2367,7 @@ def getPolicyFromRole(self, self.logger.error(ex) return self.composeErrorCode(ex) + # Consolidate opetions metrics into flow metrics + self.collectComponentMetrics() + return {}, SERVICE_NAME, None diff --git a/src/orchestrator/core/flow/Users.py b/src/orchestrator/core/flow/Users.py index 62961d67..b55ca52f 100644 --- a/src/orchestrator/core/flow/Users.py +++ b/src/orchestrator/core/flow/Users.py @@ -115,6 +115,10 @@ def users(self, "SERVICE_USERS": SERVICE_USERS, } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) + + # Consolidate opetions metrics into flow metrics + self.collectComponentMetrics() + return SERVICE_USERS, SERVICE_NAME, None @@ -178,4 +182,8 @@ def user(self, "DETAIL_USER": DETAIL_USER, } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) + + # Consolidate opetions metrics into flow metrics + self.collectComponentMetrics() + return DETAIL_USER, SERVICE_NAME, None diff --git a/src/orchestrator/core/flow/base.py b/src/orchestrator/core/flow/base.py index 9cf6670d..e0c26a7d 100644 --- a/src/orchestrator/core/flow/base.py +++ b/src/orchestrator/core/flow/base.py @@ -59,7 +59,7 @@ def __init__(self, CA_PORT="9999", PERSEO_PROTOCOL="http", PERSEO_HOST="localhost", - PERSEO_PORT="9090", + PERSEO_PORT="9090", TRANSACTION_ID=None, CORRELATOR_ID=None): @@ -120,6 +120,14 @@ def __init__(self, self.endpoints['CA'] = \ CA_PROTOCOL + "://"+CA_HOST+":"+CA_PORT+""+"/v1/notifyGeolocation" + self.sum = { + "serviceTime": 0, + "outgoingTransactions": 0, + "outgoingTransactionRequestSize": 0, + "outgoingTransactionResponseSize": 0, + "outgoingTransacionError": 0, + } + def composeErrorCode(self, ex): ''' @@ -236,3 +244,17 @@ def get_extended_token(self, USER_TOKEN): "error": ex.message } return token_extended + + def collectComponentMetrics(self): + # self.idm + # self.ac + # self.iota + # self.cb + # self.perseo + sum = self.idm.IdMRestOperations.getOutgoingMetrics() + # TO DO: join all component results + + self.sum = sum + + def getFlowMetrics(self): + return self.sum diff --git a/src/orchestrator/core/flow/createNewService.py b/src/orchestrator/core/flow/createNewService.py index d8151587..3351231a 100644 --- a/src/orchestrator/core/flow/createNewService.py +++ b/src/orchestrator/core/flow/createNewService.py @@ -336,6 +336,9 @@ def createNewService(self, } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) + # Consolidate opetions metrics into flow metrics + self.collectComponentMetrics() + return { "token": NEW_SERVICE_ADMIN_TOKEN, "id": ID_DOM1, diff --git a/src/orchestrator/core/flow/createNewServiceRole.py b/src/orchestrator/core/flow/createNewServiceRole.py index 118762a1..ff257802 100644 --- a/src/orchestrator/core/flow/createNewServiceRole.py +++ b/src/orchestrator/core/flow/createNewServiceRole.py @@ -137,4 +137,7 @@ def createNewServiceRole(self, } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) + # Consolidate opetions metrics into flow metrics + self.collectComponentMetrics() + return {"id": ID_ROLE}, SERVICE_NAME, None diff --git a/src/orchestrator/core/flow/createNewServiceUser.py b/src/orchestrator/core/flow/createNewServiceUser.py index 0c93e9c9..966c0f93 100644 --- a/src/orchestrator/core/flow/createNewServiceUser.py +++ b/src/orchestrator/core/flow/createNewServiceUser.py @@ -117,4 +117,7 @@ def createNewServiceUser(self, } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) + # Consolidate opetions metrics into flow metrics + self.collectComponentMetrics() + return {"id": ID_USER}, SERVICE_NAME, None diff --git a/src/orchestrator/core/flow/createNewSubService.py b/src/orchestrator/core/flow/createNewSubService.py index 63859a99..f09b68fb 100644 --- a/src/orchestrator/core/flow/createNewSubService.py +++ b/src/orchestrator/core/flow/createNewSubService.py @@ -163,4 +163,7 @@ def createNewSubService(self, } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) + # Consolidate opetions metrics into flow metrics + self.collectComponentMetrics() + return {"id": ID_PRO1}, SERVICE_NAME, NEW_SUBSERVICE_NAME diff --git a/src/orchestrator/core/flow/createTrustToken.py b/src/orchestrator/core/flow/createTrustToken.py index f9eae104..695ec1ff 100644 --- a/src/orchestrator/core/flow/createTrustToken.py +++ b/src/orchestrator/core/flow/createTrustToken.py @@ -187,6 +187,9 @@ def createTrustToken(self, } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) + # Consolidate opetions metrics into flow metrics + self.collectComponentMetrics() + return {"id": ID_TRUST}, SERVICE_NAME, SUBSERVICE_NAME diff --git a/src/orchestrator/core/flow/removeUser.py b/src/orchestrator/core/flow/removeUser.py index ca987f05..0e42d43c 100644 --- a/src/orchestrator/core/flow/removeUser.py +++ b/src/orchestrator/core/flow/removeUser.py @@ -113,4 +113,7 @@ def removeUser(self, } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) + # Consolidate opetions metrics into flow metrics + self.collectComponentMetrics() + return {}, SERVICE_NAME, None diff --git a/src/orchestrator/core/flow/updateUser.py b/src/orchestrator/core/flow/updateUser.py index d1cc051a..cf99bad9 100644 --- a/src/orchestrator/core/flow/updateUser.py +++ b/src/orchestrator/core/flow/updateUser.py @@ -114,6 +114,9 @@ def updateUser(self, } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) + # Consolidate opetions metrics into flow metrics + self.collectComponentMetrics() + return {"id": USER_ID}, SERVICE_NAME, None @@ -202,4 +205,7 @@ def changeUserPassword(self, } self.logger.info("Summary report : %s" % json.dumps(data_log, indent=3)) + # Consolidate opetions metrics into flow metrics + self.collectComponentMetrics() + return {"id": USER_ID}, SERVICE_NAME, None From 70e8f832da7dbcec28b6ae95266ef0350b75f509 Mon Sep 17 00:00:00 2001 From: Alvaro Vega Date: Wed, 11 Jan 2017 15:15:55 +0100 Subject: [PATCH 08/20] combine all components outgoing results --- src/orchestrator/core/flow/base.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/orchestrator/core/flow/base.py b/src/orchestrator/core/flow/base.py index e0c26a7d..e7b810d7 100644 --- a/src/orchestrator/core/flow/base.py +++ b/src/orchestrator/core/flow/base.py @@ -246,15 +246,13 @@ def get_extended_token(self, USER_TOKEN): return token_extended def collectComponentMetrics(self): - # self.idm - # self.ac - # self.iota - # self.cb - # self.perseo - sum = self.idm.IdMRestOperations.getOutgoingMetrics() - # TO DO: join all component results - - self.sum = sum + all = [] + all.append(self.idm.IdMRestOperations.getOutgoingMetrics()) + all.append(self.ac.AccessControlRestOperations.getOutgoingMetrics()) + all.append(self.iota.IoTACppRestOperations.getOutgoingMetrics()) + all.append(self.cb.CBRestOperations.getOutgoingMetrics()) + all.append(self.perseo.PerseoRestOperations.getOutgoingMetrics()) + self.sum = reduce(lambda x, y: dict((k, v + y[k]) for k, v in x.iteritems()), all) def getFlowMetrics(self): return self.sum From 44bc0844645cf1305f63d6412175f6e883bf31cc Mon Sep 17 00:00:00 2001 From: Alvaro Vega Date: Wed, 11 Jan 2017 15:27:00 +0100 Subject: [PATCH 09/20] add try catch block in method related with collection metrics procedure --- src/orchestrator/common/util.py | 14 ++++++++------ src/orchestrator/core/flow/base.py | 15 +++++++++------ 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/orchestrator/common/util.py b/src/orchestrator/common/util.py index aa08b4f0..3de09b42 100644 --- a/src/orchestrator/common/util.py +++ b/src/orchestrator/common/util.py @@ -254,12 +254,14 @@ def rest_request2(self, url, method, user=None, password=None, def collectOutgoingMetrics(self, service_start, data_request, data_response): - - service_stop = time.time() - self.sum["outgoingTransactions"] += 1 - self.sum["outgoingTransactionRequestSize"] += len(json.dumps(data_request)) - self.sum["outgoingTransactionResponseSize"] += len(json.dumps(data_response)) - self.sum["serviceTime"] += (service_stop - service_start) + try: + service_stop = time.time() + self.sum["outgoingTransactions"] += 1 + self.sum["outgoingTransactionRequestSize"] += len(json.dumps(data_request)) + self.sum["outgoingTransactionResponseSize"] += len(json.dumps(data_response)) + self.sum["serviceTime"] += (service_stop - service_start) + except Exception, ex: + self.logger.error("ERROR collecting outgoing metrics %s", ex) def getOutgoingMetrics(self): return self.sum diff --git a/src/orchestrator/core/flow/base.py b/src/orchestrator/core/flow/base.py index e7b810d7..723ce39f 100644 --- a/src/orchestrator/core/flow/base.py +++ b/src/orchestrator/core/flow/base.py @@ -247,12 +247,15 @@ def get_extended_token(self, USER_TOKEN): def collectComponentMetrics(self): all = [] - all.append(self.idm.IdMRestOperations.getOutgoingMetrics()) - all.append(self.ac.AccessControlRestOperations.getOutgoingMetrics()) - all.append(self.iota.IoTACppRestOperations.getOutgoingMetrics()) - all.append(self.cb.CBRestOperations.getOutgoingMetrics()) - all.append(self.perseo.PerseoRestOperations.getOutgoingMetrics()) - self.sum = reduce(lambda x, y: dict((k, v + y[k]) for k, v in x.iteritems()), all) + try: + all.append(self.idm.IdMRestOperations.getOutgoingMetrics()) + all.append(self.ac.AccessControlRestOperations.getOutgoingMetrics()) + all.append(self.iota.IoTACppRestOperations.getOutgoingMetrics()) + all.append(self.cb.CBRestOperations.getOutgoingMetrics()) + all.append(self.perseo.PerseoRestOperations.getOutgoingMetrics()) + self.sum = reduce(lambda x, y: dict((k, v + y[k]) for k, v in x.iteritems()), all) + except Exception, ex: + self.logger.error("ERROR collecting component metrics %s", ex) def getFlowMetrics(self): return self.sum From 21c0577d4b67c7dd6daa26aa1332e9b468714440 Mon Sep 17 00:00:00 2001 From: Alvaro Vega Date: Wed, 11 Jan 2017 15:48:54 +0100 Subject: [PATCH 10/20] add reset metrics --- src/orchestrator/api/views.py | 36 +++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/src/orchestrator/api/views.py b/src/orchestrator/api/views.py index 4f998152..01f09450 100644 --- a/src/orchestrator/api/views.py +++ b/src/orchestrator/api/views.py @@ -137,13 +137,6 @@ class Stats(object): "outgoingTransacionError": 0, } - # Metrics: - # incomingTransactions - # incomingTransactionRequestSize - # incomingTransactionResponseSize - # incomingTransacionError - # serviceTime - def collectMetrics(self, service_start, service_name, subservice_name, request, response, flow): @@ -159,8 +152,6 @@ def collectMetrics(self, service_start, service_name, subservice_name, "outgoingTransacionError": 0, } - # TODO: integrate flow (outgoing) metrics into results) - if service_name and not service_name in self.service: self.service[service_name] = { "sum": { @@ -227,6 +218,22 @@ def collectMetrics(self, service_start, service_name, subservice_name, self.sum["serviceTime"] += flow_metrics["serviceTime"] + def resetMetrics(self): + self.service = {} + self.sum = { + "incomingTransactions": 0, + "incomingTransactionRequestSize": 0, + "incomingTransactionResponseSize": 0, + "incomingTransacionError": 0, + "serviceTime": 0, + "outgoingTransactions": 0, + "outgoingTransactionRequestSize": 0, + "outgoingTransactionResponseSize": 0, + "outgoingTransacionError": 0, + } + + + class IoTConf(Stats): throttle_classes = (AnonRateThrottle,) @@ -3005,14 +3012,15 @@ def get(self, request): response = service_name = subservice_name = flow = None HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) - reset = request.GET.get('reset1', None) + reset = request.GET.get('reset', None) try: - # TO DO result = { - "service" : self.service, - "sum" : self.sum + "service": self.service, + "sum": self.sum } + if reset: + self.resetMetrics() response = Response(result, status=status.HTTP_200_OK, headers={"Fiware-Correlator": CORRELATOR_ID}) @@ -3040,7 +3048,7 @@ def delete(self, request): "service" : self.service, "sum" : self.sum } - # TODO: reset stats + self.resetMetrics() response = Response(result, status=status.HTTP_204_OK, headers={"Fiware-Correlator": CORRELATOR_ID}) From 1ce36eaab0fc682a628325bf05d52d143bb94fe4 Mon Sep 17 00:00:00 2001 From: Alvaro Vega Date: Wed, 11 Jan 2017 17:10:36 +0100 Subject: [PATCH 11/20] collect incoming errors --- src/orchestrator/api/views.py | 43 +++++++++++++++++++++--------- src/orchestrator/common/util.py | 4 ++- src/orchestrator/core/flow/base.py | 2 +- 3 files changed, 35 insertions(+), 14 deletions(-) diff --git a/src/orchestrator/api/views.py b/src/orchestrator/api/views.py index 01f09450..f8cfbfc2 100644 --- a/src/orchestrator/api/views.py +++ b/src/orchestrator/api/views.py @@ -129,18 +129,19 @@ class Stats(object): "incomingTransactions": 0, "incomingTransactionRequestSize": 0, "incomingTransactionResponseSize": 0, - "incomingTransacionError": 0, + "incomingTransactionErrors": 0, "serviceTime": 0, "outgoingTransactions": 0, "outgoingTransactionRequestSize": 0, "outgoingTransactionResponseSize": 0, - "outgoingTransacionError": 0, + "outgoingTransactionErrors": 0, } def collectMetrics(self, service_start, service_name, subservice_name, request, response, flow): service_stop = time.time() + transactionError = False if flow: flow_metrics = flow.getFlowMetrics() else: @@ -149,7 +150,7 @@ def collectMetrics(self, service_start, service_name, subservice_name, "outgoingTransactions": 0, "outgoingTransactionRequestSize": 0, "outgoingTransactionResponseSize": 0, - "outgoingTransacionError": 0, + "outgoingTransactionErrors": 0, } if service_name and not service_name in self.service: @@ -158,12 +159,12 @@ def collectMetrics(self, service_start, service_name, subservice_name, "incomingTransactions": 0, "incomingTransactionRequestSize": 0, "incomingTransactionResponseSize": 0, - "incomingTransacionError": 0, + "incomingTransactionErrors": 0, "serviceTime": 0, "outgoingTransactions": 0, "outgoingTransactionRequestSize": 0, "outgoingTransactionResponseSize": 0, - "ouggoingTransacionError": 0, + "outgoingTransactionErrors": 0, }, "subservs": {} } @@ -174,18 +175,27 @@ def collectMetrics(self, service_start, service_name, subservice_name, "incomingTransactions": 0, "incomingTransactionRequestSize": 0, "incomingTransactionResponseSize": 0, - "incomingTransacionError": 0, + "incomingTransactionErrors": 0, "serviceTime": 0, "outgoingTransactions": 0, "outgoingTransactionRequestSize": 0, "outgoingTransactionResponseSize": 0, - "ouggoingTransacionError": 0, + "outgoingTransactionErrors": 0, } + # TODO: + # Analize "response"" to know if is a Response about an error or not + if response.status_code not in ["200", "201", "204"]: + # API error + transactionError = True + if service_name: if subservice_name: # Service and Subservice - self.service[service_name]["subservs"][subservice_name]["incomingTransactions"] += 1 + if not transactionError: + self.service[service_name]["subservs"][subservice_name]["incomingTransactions"] += 1 + else: + self.service[service_name]["subservs"][subservice_name]["incomingTransactionErrors"] += 1 self.service[service_name]["subservs"][subservice_name]["incomingTransactionRequestSize"] += len(json.dumps(request.data)) self.service[service_name]["subservs"][subservice_name]["incomingTransactionResponseSize"] += len(json.dumps(response.data)) self.service[service_name]["subservs"][subservice_name]["serviceTime"] += (service_stop - service_start) @@ -193,28 +203,37 @@ def collectMetrics(self, service_start, service_name, subservice_name, self.service[service_name]["subservs"][subservice_name]["outgoingTransactions"] += flow_metrics["outgoingTransactions"] self.service[service_name]["subservs"][subservice_name]["outgoingTransactionRequestSize"] += flow_metrics["outgoingTransactionRequestSize"] self.service[service_name]["subservs"][subservice_name]["outgoingTransactionResponseSize"] += flow_metrics["outgoingTransactionResponseSize"] + self.service[service_name]["subservs"][subservice_name]["outgoingTransactionErrors"] += flow_metrics["outgoingTransactionErrors"] self.service[service_name]["subservs"][subservice_name]["serviceTime"] += flow_metrics["serviceTime"] # Service - self.service[service_name]["sum"]["incomingTransactions"] += 1 + if not transactionError: + self.service[service_name]["sum"]["incomingTransactions"] += 1 + else: + self.service[service_name]["sum"]["incomingTransactionErrors"] += 1 self.service[service_name]["sum"]["incomingTransactionRequestSize"] += len(json.dumps(request.data)) self.service[service_name]["sum"]["incomingTransactionResponseSize"] += len(json.dumps(response.data)) self.service[service_name]["sum"]["serviceTime"] += (service_stop - service_start) self.service[service_name]["sum"]["outgoingTransactions"] += flow_metrics["outgoingTransactions"] self.service[service_name]["sum"]["outgoingTransactionRequestSize"] += flow_metrics["outgoingTransactionRequestSize"] self.service[service_name]["sum"]["outgoingTransactionResponseSize"] += flow_metrics["outgoingTransactionResponseSize"] + self.service[service_name]["sum"]["outgoingTransactionErrors"] += flow_metrics["outgoingTransactionErrors"] self.service[service_name]["sum"]["serviceTime"] += flow_metrics["serviceTime"] # Sum - self.sum["incomingTransactions"] += 1 + if not transactionError: + self.sum["incomingTransactions"] += 1 + else: + self.sum["incomingTransactionErrors"] += 1 self.sum["incomingTransactionRequestSize"] += len(json.dumps(request.data)) self.sum["incomingTransactionResponseSize"] += len(json.dumps(response.data)) self.sum["serviceTime"] += (service_stop - service_start) self.sum["outgoingTransactions"] += flow_metrics["outgoingTransactions"] self.sum["outgoingTransactionRequestSize"] += flow_metrics["outgoingTransactionRequestSize"] self.sum["outgoingTransactionResponseSize"] += flow_metrics["outgoingTransactionResponseSize"] + self.sum["outgoingTransactionErrors"] += flow_metrics["outgoingTransactionErrors"] self.sum["serviceTime"] += flow_metrics["serviceTime"] @@ -224,12 +243,12 @@ def resetMetrics(self): "incomingTransactions": 0, "incomingTransactionRequestSize": 0, "incomingTransactionResponseSize": 0, - "incomingTransacionError": 0, + "incomingTransactionErrors": 0, "serviceTime": 0, "outgoingTransactions": 0, "outgoingTransactionRequestSize": 0, "outgoingTransactionResponseSize": 0, - "outgoingTransacionError": 0, + "outgoingTransactionErrors": 0, } diff --git a/src/orchestrator/common/util.py b/src/orchestrator/common/util.py index 3de09b42..de96409d 100644 --- a/src/orchestrator/common/util.py +++ b/src/orchestrator/common/util.py @@ -68,7 +68,7 @@ def __init__(self, "outgoingTransactions": 0, "outgoingTransactionRequestSize": 0, "outgoingTransactionResponseSize": 0, - "outgoingTransacionError": 0, + "outgoingTransactionErrors": 0, } @@ -256,7 +256,9 @@ def rest_request2(self, url, method, user=None, password=None, def collectOutgoingMetrics(self, service_start, data_request, data_response): try: service_stop = time.time() + # TODO: check if data_response is an error or not self.sum["outgoingTransactions"] += 1 + self.sum["outgoingTransactionErrors"] += 0 self.sum["outgoingTransactionRequestSize"] += len(json.dumps(data_request)) self.sum["outgoingTransactionResponseSize"] += len(json.dumps(data_response)) self.sum["serviceTime"] += (service_stop - service_start) diff --git a/src/orchestrator/core/flow/base.py b/src/orchestrator/core/flow/base.py index 723ce39f..a555fa08 100644 --- a/src/orchestrator/core/flow/base.py +++ b/src/orchestrator/core/flow/base.py @@ -125,7 +125,7 @@ def __init__(self, "outgoingTransactions": 0, "outgoingTransactionRequestSize": 0, "outgoingTransactionResponseSize": 0, - "outgoingTransacionError": 0, + "outgoingTransactionErrors": 0, } From e22ae63c6a33d68de5f34058ddd6564c06b83389 Mon Sep 17 00:00:00 2001 From: Alvaro Vega Date: Thu, 12 Jan 2017 08:54:30 +0100 Subject: [PATCH 12/20] fix error status check --- src/orchestrator/api/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/orchestrator/api/views.py b/src/orchestrator/api/views.py index f8cfbfc2..4273649d 100644 --- a/src/orchestrator/api/views.py +++ b/src/orchestrator/api/views.py @@ -185,7 +185,7 @@ def collectMetrics(self, service_start, service_name, subservice_name, # TODO: # Analize "response"" to know if is a Response about an error or not - if response.status_code not in ["200", "201", "204"]: + if response.status_code not in [200, 201, 204]: # API error transactionError = True From fa8146d3f50cc4da8d4b538cf63b15b67384bd23 Mon Sep 17 00:00:00 2001 From: Alvaro Vega Date: Thu, 12 Jan 2017 09:10:59 +0100 Subject: [PATCH 13/20] fix reset metrics argument --- src/orchestrator/api/views.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/orchestrator/api/views.py b/src/orchestrator/api/views.py index 4273649d..e8f6c158 100644 --- a/src/orchestrator/api/views.py +++ b/src/orchestrator/api/views.py @@ -3029,9 +3029,8 @@ def __init__(self): def get(self, request): service_start = time.time() response = service_name = subservice_name = flow = None - HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) - reset = request.GET.get('reset', None) + reset = request.GET.get('reset', False) == "true" try: result = { @@ -3059,7 +3058,6 @@ def get(self, request): def delete(self, request): service_start = time.time() response = service_name = subservice_name = flow = None - HTTP_X_AUTH_TOKEN = self.getXAuthToken(request) CORRELATOR_ID = self.getCorrelatorIdHeader(request) try: From 85622e98393305c3b5cf4e4de840262f8d0f8d08 Mon Sep 17 00:00:00 2001 From: Alvaro Vega Date: Thu, 12 Jan 2017 10:23:24 +0100 Subject: [PATCH 14/20] add check for outgoing errors --- src/orchestrator/common/util.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/orchestrator/common/util.py b/src/orchestrator/common/util.py index de96409d..9fe3ca7f 100644 --- a/src/orchestrator/common/util.py +++ b/src/orchestrator/common/util.py @@ -30,6 +30,7 @@ import logging import time + class RestOperations(object): ''' IoT IdM (keystone + keypass) @@ -62,6 +63,10 @@ def __init__(self, else: self.CORRELATOR_ID = None + self.logger = logging.getLogger('orchestrator_core') + self.logger.addFilter(ContextFilterCorrelatorId(self.CORRELATOR_ID)) + self.logger.addFilter(ContextFilterTransactionId(self.TRANSACTION_ID)) + self.service = {} self.sum = { "serviceTime": 0, @@ -166,7 +171,7 @@ def rest_request(self, url, method, user=None, password=None, res.code = 500 res.msg = self.ENDPOINT_NAME + " endpoint ERROR: " + res.args[0][1] - self.collectOutgoingMetrics(service_start, request.data, data) + self.collectOutgoingMetrics(service_start, request.data, res) return res @@ -253,12 +258,17 @@ def rest_request2(self, url, method, user=None, password=None, return res - def collectOutgoingMetrics(self, service_start, data_request, data_response): + def collectOutgoingMetrics(self, service_start, data_request, response): try: service_stop = time.time() - # TODO: check if data_response is an error or not - self.sum["outgoingTransactions"] += 1 - self.sum["outgoingTransactionErrors"] += 0 + transactionError = False + if response.code not in [200, 201, 204]: + transactionError = True + data_response = response.msg + if transactionError: + self.sum["outgoingTransactions"] += 1 + else: + self.sum["outgoingTransactionErrors"] += 1 self.sum["outgoingTransactionRequestSize"] += len(json.dumps(data_request)) self.sum["outgoingTransactionResponseSize"] += len(json.dumps(data_response)) self.sum["serviceTime"] += (service_stop - service_start) From 507d851efe2fcb45f14b9249ccde450f46e86a70 Mon Sep 17 00:00:00 2001 From: Alvaro Vega Date: Thu, 12 Jan 2017 11:30:22 +0100 Subject: [PATCH 15/20] update apirary doc --- apiary.apib | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/apiary.apib b/apiary.apib index 9d6a4ac7..087b8af5 100644 --- a/apiary.apib +++ b/apiary.apib @@ -977,3 +977,55 @@ In the cases where "serviceId" is part of URL "SERVICE_NAME" field at body can b { "level": "DEBUG" } + +## Metrics [/v1.0/admin/metrics] + +### Get current metrics [GET] ++ Parameters + + reset (optional, `string`) ... ["true", "false"] ++ Response 200 (application/json) + + Body + { + "service": { + "service1": { + "subservs": { + "subserv1": {}, + "subserv2": {} + }, + "sum": {} + }, + "service2": { + "subservs": { + "subserv1": {}, + "subserv2": {} + }, + "sum": {} + } + }, + "sum": {} + } + + +### Reset current metrics [DELETE] ++ Parameters ++ Response 204 (application/json) + + Body + { + "service": { + "service1": { + "subservs": { + "subserv1": {}, + "subserv2": {} + }, + "sum": {} + }, + "service2": { + "subservs": { + "subserv1": {}, + "subserv2": {} + }, + "sum": {} + } + }, + "sum": {} + } From f3d3a262978f8e8d7a1326fe3a5ada551288244d Mon Sep 17 00:00:00 2001 From: Alvaro Vega Date: Thu, 12 Jan 2017 12:03:50 +0100 Subject: [PATCH 16/20] add test about metrics API --- README.md | 2 +- src/tests/api/test_api.py | 47 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3d9b15db..4c849084 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ A tipical scenario for IoT Platform can be [scenario_test](https://pdihub.hi.ine - Assign/unassign roles to users in a service - Create/List Trust Tokens - Activate / deactivate IoT Modules -- Retrieve statistics about API usage +- Retrieve statistics and metrics about API usage Orchestrator is based mainly on: - Python diff --git a/src/tests/api/test_api.py b/src/tests/api/test_api.py index 42ccb861..f43d3175 100644 --- a/src/tests/api/test_api.py +++ b/src/tests/api/test_api.py @@ -3259,7 +3259,49 @@ def test_change_log_level_bad(self): assert res.code == 400, (res.code, res.msg, res.raw_json) +class Test_Metrics_RestView(object): + def __init__(self): + self.suffix = str(uuid.uuid4())[:8] + self.TestRestOps = TestRestOperations(PROTOCOL=ORC_PROTOCOL, + HOST=ORC_HOST, + PORT=ORC_PORT) + + def test_get_metrics_ok(self): + res = self.TestRestOps.rest_request(method="GET", + url="/v1.0/admin/metrics", + json_data=True, + auth_token=None, + data=None) + assert res.code == 200, (res.code, res.msg, res.raw_json) + response = res.read() + json_body_response = json.loads(response) + assert "service" in json_body_response + assert "sum" in json_body_response + + def test_get_and_reset_metrics_ok(self): + res = self.TestRestOps.rest_request(method="GET", + url="/v1.0/admin/metrics?reset=true", + json_data=True, + auth_token=None, + data=None) + assert res.code == 200, (res.code, res.msg, res.raw_json) + response = res.read() + json_body_response = json.loads(response) + assert "service" in json_body_response + assert "sum" in json_body_response + + def test_reset_metrics_ok(self): + res = self.TestRestOps.rest_request(method="DELETE", + url="/v1.0/admin/metrics", + json_data=True, + auth_token=None, + data=None) + assert res.code == 204, (res.code, res.msg, res.raw_json) + response = res.read() + json_body_response = json.loads(response) + assert "service" in json_body_response + assert "sum" in json_body_response if __name__ == '__main__': @@ -3401,3 +3443,8 @@ def test_change_log_level_bad(self): test_LogLevel = Test_LogLevel_RestView() test_LogLevel.test_change_log_level_ok() test_LogLevel.test_change_log_level_bad() + + test_Metrics = Test_Metrics_RestView() + test_Metrics.test_get_metrics_ok() + test_Metrics.test_get_and_reset_metrics_ok() + test_Metrics.test_reset_metrics_ok() From e62cbc6652a55cf6731d52ddd7be348f3833b79e Mon Sep 17 00:00:00 2001 From: Alvaro Vega Date: Thu, 12 Jan 2017 12:38:34 +0100 Subject: [PATCH 17/20] update ChangeLog --- ChangeLog | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index c562012f..cae56db8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3,7 +3,8 @@ CHANGES 1.5.0 -FEATURE: Support keystone groups in a Service, including role assignments +FEATURE: Metrics API [#58] +FEATURE: Support keystone groups in a Service, including role assignments [#56] 1.4.2 From c98d0e415a0f127560e7502e3028b913bfb2b48e Mon Sep 17 00:00:00 2001 From: Alvaro Vega Date: Wed, 18 Jan 2017 07:40:00 +0100 Subject: [PATCH 18/20] add time per call in serviceTIme metric --- src/orchestrator/api/views.py | 75 +++++++++++++++++++++--------- src/orchestrator/common/util.py | 3 +- src/orchestrator/core/flow/base.py | 1 + 3 files changed, 57 insertions(+), 22 deletions(-) diff --git a/src/orchestrator/api/views.py b/src/orchestrator/api/views.py index e8f6c158..7e176a29 100644 --- a/src/orchestrator/api/views.py +++ b/src/orchestrator/api/views.py @@ -131,6 +131,7 @@ class Stats(object): "incomingTransactionResponseSize": 0, "incomingTransactionErrors": 0, "serviceTime": 0, + "serviceTimeTotal": 0, "outgoingTransactions": 0, "outgoingTransactionRequestSize": 0, "outgoingTransactionResponseSize": 0, @@ -146,12 +147,13 @@ def collectMetrics(self, service_start, service_name, subservice_name, flow_metrics = flow.getFlowMetrics() else: flow_metrics = { - "serviceTime": 0, - "outgoingTransactions": 0, - "outgoingTransactionRequestSize": 0, - "outgoingTransactionResponseSize": 0, - "outgoingTransactionErrors": 0, - } + "serviceTime": 0, + "serviceTimeTotal": 0, + "outgoingTransactions": 0, + "outgoingTransactionRequestSize": 0, + "outgoingTransactionResponseSize": 0, + "outgoingTransactionErrors": 0, + } if service_name and not service_name in self.service: self.service[service_name] = { @@ -161,6 +163,7 @@ def collectMetrics(self, service_start, service_name, subservice_name, "incomingTransactionResponseSize": 0, "incomingTransactionErrors": 0, "serviceTime": 0, + "serviceTimeTotal": 0, "outgoingTransactions": 0, "outgoingTransactionRequestSize": 0, "outgoingTransactionResponseSize": 0, @@ -177,13 +180,13 @@ def collectMetrics(self, service_start, service_name, subservice_name, "incomingTransactionResponseSize": 0, "incomingTransactionErrors": 0, "serviceTime": 0, + "serviceTimeTotal": 0, "outgoingTransactions": 0, "outgoingTransactionRequestSize": 0, "outgoingTransactionResponseSize": 0, "outgoingTransactionErrors": 0, } - # TODO: # Analize "response"" to know if is a Response about an error or not if response.status_code not in [200, 201, 204]: # API error @@ -198,13 +201,13 @@ def collectMetrics(self, service_start, service_name, subservice_name, self.service[service_name]["subservs"][subservice_name]["incomingTransactionErrors"] += 1 self.service[service_name]["subservs"][subservice_name]["incomingTransactionRequestSize"] += len(json.dumps(request.data)) self.service[service_name]["subservs"][subservice_name]["incomingTransactionResponseSize"] += len(json.dumps(response.data)) - self.service[service_name]["subservs"][subservice_name]["serviceTime"] += (service_stop - service_start) + self.service[service_name]["subservs"][subservice_name]["serviceTimeTotal"] += (service_stop - service_start) self.service[service_name]["subservs"][subservice_name]["outgoingTransactions"] += flow_metrics["outgoingTransactions"] self.service[service_name]["subservs"][subservice_name]["outgoingTransactionRequestSize"] += flow_metrics["outgoingTransactionRequestSize"] self.service[service_name]["subservs"][subservice_name]["outgoingTransactionResponseSize"] += flow_metrics["outgoingTransactionResponseSize"] self.service[service_name]["subservs"][subservice_name]["outgoingTransactionErrors"] += flow_metrics["outgoingTransactionErrors"] - self.service[service_name]["subservs"][subservice_name]["serviceTime"] += flow_metrics["serviceTime"] + self.service[service_name]["subservs"][subservice_name]["serviceTimeTotal"] += flow_metrics["serviceTimeTotal"] @@ -215,12 +218,12 @@ def collectMetrics(self, service_start, service_name, subservice_name, self.service[service_name]["sum"]["incomingTransactionErrors"] += 1 self.service[service_name]["sum"]["incomingTransactionRequestSize"] += len(json.dumps(request.data)) self.service[service_name]["sum"]["incomingTransactionResponseSize"] += len(json.dumps(response.data)) - self.service[service_name]["sum"]["serviceTime"] += (service_stop - service_start) + self.service[service_name]["sum"]["serviceTimeTotal"] += (service_stop - service_start) self.service[service_name]["sum"]["outgoingTransactions"] += flow_metrics["outgoingTransactions"] self.service[service_name]["sum"]["outgoingTransactionRequestSize"] += flow_metrics["outgoingTransactionRequestSize"] self.service[service_name]["sum"]["outgoingTransactionResponseSize"] += flow_metrics["outgoingTransactionResponseSize"] self.service[service_name]["sum"]["outgoingTransactionErrors"] += flow_metrics["outgoingTransactionErrors"] - self.service[service_name]["sum"]["serviceTime"] += flow_metrics["serviceTime"] + self.service[service_name]["sum"]["serviceTimeTotal"] += flow_metrics["serviceTimeTotal"] # Sum if not transactionError: @@ -229,12 +232,12 @@ def collectMetrics(self, service_start, service_name, subservice_name, self.sum["incomingTransactionErrors"] += 1 self.sum["incomingTransactionRequestSize"] += len(json.dumps(request.data)) self.sum["incomingTransactionResponseSize"] += len(json.dumps(response.data)) - self.sum["serviceTime"] += (service_stop - service_start) + self.sum["serviceTimeTotal"] += (service_stop - service_start) self.sum["outgoingTransactions"] += flow_metrics["outgoingTransactions"] self.sum["outgoingTransactionRequestSize"] += flow_metrics["outgoingTransactionRequestSize"] self.sum["outgoingTransactionResponseSize"] += flow_metrics["outgoingTransactionResponseSize"] self.sum["outgoingTransactionErrors"] += flow_metrics["outgoingTransactionErrors"] - self.sum["serviceTime"] += flow_metrics["serviceTime"] + self.sum["serviceTimeTotal"] += flow_metrics["serviceTimeTotal"] def resetMetrics(self): @@ -245,6 +248,7 @@ def resetMetrics(self): "incomingTransactionResponseSize": 0, "incomingTransactionErrors": 0, "serviceTime": 0, + "serviceTimeTotal": 0, "outgoingTransactions": 0, "outgoingTransactionRequestSize": 0, "outgoingTransactionResponseSize": 0, @@ -252,6 +256,40 @@ def resetMetrics(self): } + def composeMetrics(self): + + result = { + "service": self.service, + "sum": self.sum + } + + for serv in result["service"]: + if result["service"][serv]["sum"]["serviceTimeTotal"] > 0: + result["service"][serv]["sum"]["serviceTime"] = result["service"][serv]["sum"]["serviceTimeTotal"] / ( + result["service"][serv]["sum"]["incomingTransactions"] + + result["service"][serv]["sum"]["incomingTransactionErrors"] + + result["service"][serv]["sum"]["outgoingTransactions"] + + result["service"][serv]["sum"]["outgoingTransactionErrors"] + ) + + for subserv in result["service"][serv]["subservs"]: + if result["service"][serv]["subservs"][subserv]["serviceTimeTotal"] > 0: + result["service"][serv]["subservs"][subserv]["serviceTime"] = result["service"][serv]["subservs"][subserv]["serviceTimeTotal"] / ( + result["service"][serv]["subservs"][subserv]["incomingTransactions"] + + result["service"][serv]["subservs"][subserv]["incomingTransactionErrors"] + + result["service"][serv]["subservs"][subserv]["outgoingTransactions"] + + result["service"][serv]["subservs"][subserv]["outgoingTransactionErrors"] + ) + + if result["sum"]["serviceTimeTotal"] > 0: + result["sum"]["serviceTime"] = result["sum"]["serviceTimeTotal"] / ( + result["sum"]["incomingTransactions"] + + result["sum"]["incomingTransactionErrors"] + + result["sum"]["outgoingTransactions"] + + result["sum"]["outgoingTransactionErrors"] + ) + return result + class IoTConf(Stats): throttle_classes = (AnonRateThrottle,) @@ -3033,10 +3071,8 @@ def get(self, request): reset = request.GET.get('reset', False) == "true" try: - result = { - "service": self.service, - "sum": self.sum - } + result = self.composeMetrics() + if reset: self.resetMetrics() @@ -3061,10 +3097,7 @@ def delete(self, request): CORRELATOR_ID = self.getCorrelatorIdHeader(request) try: - result = { - "service" : self.service, - "sum" : self.sum - } + result = self.composeMetrics() self.resetMetrics() response = Response(result, status=status.HTTP_204_OK, headers={"Fiware-Correlator": CORRELATOR_ID}) diff --git a/src/orchestrator/common/util.py b/src/orchestrator/common/util.py index 9fe3ca7f..7f63d8b9 100644 --- a/src/orchestrator/common/util.py +++ b/src/orchestrator/common/util.py @@ -70,6 +70,7 @@ def __init__(self, self.service = {} self.sum = { "serviceTime": 0, + "serviceTimeTotal": 0, "outgoingTransactions": 0, "outgoingTransactionRequestSize": 0, "outgoingTransactionResponseSize": 0, @@ -271,7 +272,7 @@ def collectOutgoingMetrics(self, service_start, data_request, response): self.sum["outgoingTransactionErrors"] += 1 self.sum["outgoingTransactionRequestSize"] += len(json.dumps(data_request)) self.sum["outgoingTransactionResponseSize"] += len(json.dumps(data_response)) - self.sum["serviceTime"] += (service_stop - service_start) + self.sum["serviceTimeTotal"] += (service_stop - service_start) except Exception, ex: self.logger.error("ERROR collecting outgoing metrics %s", ex) diff --git a/src/orchestrator/core/flow/base.py b/src/orchestrator/core/flow/base.py index a555fa08..20bf858d 100644 --- a/src/orchestrator/core/flow/base.py +++ b/src/orchestrator/core/flow/base.py @@ -122,6 +122,7 @@ def __init__(self, self.sum = { "serviceTime": 0, + "serviceTimeTotal": 0, "outgoingTransactions": 0, "outgoingTransactionRequestSize": 0, "outgoingTransactionResponseSize": 0, From 3067dc02df3c1736f90a0ed7b9e66de07b685286 Mon Sep 17 00:00:00 2001 From: Alvaro Vega Date: Mon, 23 Jan 2017 14:27:06 +0100 Subject: [PATCH 19/20] add json examples about metrics --- apiary.apib | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/apiary.apib b/apiary.apib index 087b8af5..ff451e1b 100644 --- a/apiary.apib +++ b/apiary.apib @@ -980,7 +980,15 @@ In the cases where "serviceId" is part of URL "SERVICE_NAME" field at body can b ## Metrics [/v1.0/admin/metrics] +The following metrics are collected by the component: ++ incomingTransactions: number of requests consumed by the component. ++ incomingTransactionRequestSize: total size (bytes) in requests associated to incoming transactions ++ incomingTransactionResponseSize: total size (bytes) in responses associated to incoming transactions ++ incomingTransacionError: number of incoming transactions resulting in error. ++ serviceTime: average time to serve a transaction. + ### Get current metrics [GET] + + Parameters + reset (optional, `string`) ... ["true", "false"] + Response 200 (application/json) @@ -1002,7 +1010,17 @@ In the cases where "serviceId" is part of URL "SERVICE_NAME" field at body can b "sum": {} } }, - "sum": {} + "sum": { + "incomingTransactions": 25, + "incomingTransactionRequestSize": 3456, + "incomingTransactionResponseSize": 435, + "incomingTransacionError": 2, + "serviceTime": 0.48, + "outgoingTransactions": 46, + "outgoingTransactionRequestSize": 323361, + "outgoingTransactionResponseSize": 2343, + "outgoingTransacionError": 10 + } } @@ -1027,5 +1045,15 @@ In the cases where "serviceId" is part of URL "SERVICE_NAME" field at body can b "sum": {} } }, - "sum": {} + "sum": { + "incomingTransactions": 25, + "incomingTransactionRequestSize": 3456, + "incomingTransactionResponseSize": 435, + "incomingTransacionError": 2, + "serviceTime": 0.48, + "outgoingTransactions": 46, + "outgoingTransactionRequestSize": 323361, + "outgoingTransactionResponseSize": 2343, + "outgoingTransacionError": 10 + } } From add27e2682349675eea253d08b1eccd36425a71b Mon Sep 17 00:00:00 2001 From: Alvaro Vega Date: Mon, 23 Jan 2017 16:35:17 +0100 Subject: [PATCH 20/20] add header size to metrics --- src/orchestrator/common/util.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/orchestrator/common/util.py b/src/orchestrator/common/util.py index 7f63d8b9..33b40309 100644 --- a/src/orchestrator/common/util.py +++ b/src/orchestrator/common/util.py @@ -172,7 +172,7 @@ def rest_request(self, url, method, user=None, password=None, res.code = 500 res.msg = self.ENDPOINT_NAME + " endpoint ERROR: " + res.args[0][1] - self.collectOutgoingMetrics(service_start, request.data, res) + self.collectOutgoingMetrics(service_start, request.data, request.headers, res) return res @@ -255,11 +255,11 @@ def rest_request2(self, url, method, user=None, password=None, except Exception, e: print e - self.collectOutgoingMetrics(service_start, rdata, res) + self.collectOutgoingMetrics(service_start, rdata, headers, res) return res - def collectOutgoingMetrics(self, service_start, data_request, response): + def collectOutgoingMetrics(self, service_start, data_request, headers_request, response): try: service_stop = time.time() transactionError = False @@ -270,8 +270,8 @@ def collectOutgoingMetrics(self, service_start, data_request, response): self.sum["outgoingTransactions"] += 1 else: self.sum["outgoingTransactionErrors"] += 1 - self.sum["outgoingTransactionRequestSize"] += len(json.dumps(data_request)) - self.sum["outgoingTransactionResponseSize"] += len(json.dumps(data_response)) + self.sum["outgoingTransactionRequestSize"] += len(json.dumps(data_request)) + len(str(headers_request)) + self.sum["outgoingTransactionResponseSize"] += len(json.dumps(data_response)) + len(str(response.headers.headers)) self.sum["serviceTimeTotal"] += (service_stop - service_start) except Exception, ex: self.logger.error("ERROR collecting outgoing metrics %s", ex)