From 06fb1d8bc8727d476c0998ff19f90a07f14edade Mon Sep 17 00:00:00 2001 From: hyu2010 Date: Tue, 20 Jul 2021 15:34:03 -0400 Subject: [PATCH] SO changes for Service Intent This update contains the SO changes for the CCVPN extension to support Intent Based Networking (REQ-719). The SO is responsible for providing the Service Intent orchestration, as well as providing the Service Intent APIs which are consumed by the IBN use-case. The changes on the SO are technology-agnostic and are relatively simple. i.e., Technology specific network configurations are carried out by the SDNC. Issue-ID: SO-3714 Signed-off-by: hyu2010 Change-Id: Iec9d2fc80adc79faaeeaf811bd0d02c9d7611d61 Signed-off-by: hyu2010 --- .../db/migration/V1.1__Initial_Recipe_Setup.sql | 8 + .../scripts/CreateServiceIntentInstance.groovy | 153 +++++ .../scripts/DeleteServiceIntentInstance.groovy | 127 ++++ .../scripts/DoCloudLeasedLineCreate.groovy | 391 ++++++++++++ .../scripts/DoCloudLeasedLineDelete.groovy | 174 ++++++ .../scripts/DoCloudLeasedLineModify.groovy | 502 ++++++++++++++++ .../scripts/ModifyServiceIntentInstance.groovy | 128 ++++ .../scripts/ServiceIntentUtils.groovy | 669 +++++++++++++++++++++ .../process/CreateServiceIntentInstance.bpmn | 175 ++++++ .../process/DeleteServiceIntentInstance.bpmn | 161 +++++ .../process/ModifyServiceIntentInstance.bpmn | 173 ++++++ .../subprocess/DoCloudLeasedLineCreate.bpmn | 321 ++++++++++ .../subprocess/DoCloudLeasedLineDelete.bpmn | 235 ++++++++ .../subprocess/DoCloudLeasedLineModify.bpmn | 252 ++++++++ .../so/apihandlerinfra/JerseyConfiguration.java | 1 + .../apihandlerinfra/ServiceIntentApiHandler.java | 431 +++++++++++++ .../ServiceIntentCommonRequest.java | 83 +++ .../ServiceIntentCreationRequest.java | 82 +++ .../ServiceIntentDeletionRequest.java | 48 ++ .../ServiceIntentModificationRequest.java | 60 ++ .../ServiceIntentApiHandlerTest.java | 156 +++++ .../ServiceIntentTest/create-cll-payload.json | 29 + .../ServiceIntentTest/delete-cll-payload.json | 9 + .../ServiceIntentTest/modify-cll-payload.json | 29 + 24 files changed, 4397 insertions(+) create mode 100644 bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/CreateServiceIntentInstance.groovy create mode 100644 bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DeleteServiceIntentInstance.groovy create mode 100644 bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCloudLeasedLineCreate.groovy create mode 100644 bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCloudLeasedLineDelete.groovy create mode 100644 bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCloudLeasedLineModify.groovy create mode 100644 bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/ModifyServiceIntentInstance.groovy create mode 100644 bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/ServiceIntentUtils.groovy create mode 100644 bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/CreateServiceIntentInstance.bpmn create mode 100644 bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/DeleteServiceIntentInstance.bpmn create mode 100644 bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/ModifyServiceIntentInstance.bpmn create mode 100644 bpmn/so-bpmn-infrastructure-flows/src/main/resources/subprocess/DoCloudLeasedLineCreate.bpmn create mode 100644 bpmn/so-bpmn-infrastructure-flows/src/main/resources/subprocess/DoCloudLeasedLineDelete.bpmn create mode 100644 bpmn/so-bpmn-infrastructure-flows/src/main/resources/subprocess/DoCloudLeasedLineModify.bpmn create mode 100644 mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ServiceIntentApiHandler.java create mode 100644 mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/serviceintentinstancebeans/ServiceIntentCommonRequest.java create mode 100644 mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/serviceintentinstancebeans/ServiceIntentCreationRequest.java create mode 100644 mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/serviceintentinstancebeans/ServiceIntentDeletionRequest.java create mode 100644 mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/serviceintentinstancebeans/ServiceIntentModificationRequest.java create mode 100644 mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/ServiceIntentApiHandlerTest.java create mode 100644 mso-api-handlers/mso-api-handler-infra/src/test/resources/ServiceIntentTest/create-cll-payload.json create mode 100644 mso-api-handlers/mso-api-handler-infra/src/test/resources/ServiceIntentTest/delete-cll-payload.json create mode 100644 mso-api-handlers/mso-api-handler-infra/src/test/resources/ServiceIntentTest/modify-cll-payload.json diff --git a/adapters/mso-catalog-db-adapter/src/main/resources/db/migration/V1.1__Initial_Recipe_Setup.sql b/adapters/mso-catalog-db-adapter/src/main/resources/db/migration/V1.1__Initial_Recipe_Setup.sql index c5a3701a82..c613f26c30 100644 --- a/adapters/mso-catalog-db-adapter/src/main/resources/db/migration/V1.1__Initial_Recipe_Setup.sql +++ b/adapters/mso-catalog-db-adapter/src/main/resources/db/migration/V1.1__Initial_Recipe_Setup.sql @@ -55,6 +55,14 @@ INSERT INTO `service_recipe` (`id`, `ACTION`, `VERSION_STR`, `DESCRIPTION`, `ORC INSERT INTO `service_recipe` (`id`, `ACTION`, `VERSION_STR`, `DESCRIPTION`, `ORCHESTRATION_URI`, `SERVICE_PARAM_XSD`, `RECIPE_TIMEOUT`, `SERVICE_TIMEOUT_INTERIM`, `CREATION_TIMESTAMP`, `SERVICE_MODEL_UUID`) VALUES (20,'activateInstance','1','Custom recipe to activate/deactivate 3gpp service-instance if no custom BPMN flow is found','/mso/async/services/ActivateSliceSubnet',NULL,180,NULL,'2020-08-18 18:40:03','3d30a774-e149-11ea-87d0-0242ac130003'); INSERT INTO `service_recipe` (`id`, `ACTION`, `VERSION_STR`, `DESCRIPTION`, `ORCHESTRATION_URI`, `SERVICE_PARAM_XSD`, `RECIPE_TIMEOUT`, `SERVICE_TIMEOUT_INTERIM`, `CREATION_TIMESTAMP`, `SERVICE_MODEL_UUID`) VALUES (21,'deactivateInstance','1','Custom recipe to activate/deactivate 3gpp service-instance if no custom BPMN flow is found','/mso/async/services/ActivateSliceSubnet',NULL,180,NULL,'2020-08-18 18:40:03','3d30a774-e149-11ea-87d0-0242ac130003'); +-- Recipe for Service Intent + +INSERT INTO `service` (`MODEL_UUID`, `MODEL_NAME`, `MODEL_INVARIANT_UUID`, `MODEL_VERSION`, `DESCRIPTION`, `CREATION_TIMESTAMP`, `TOSCA_CSAR_ARTIFACT_UUID`) VALUES ('6790ab0e-034f-11eb-adc1-0242ac120002','COMMON_SI_DEFAULT','6790ab0e-034f-11eb-adc1-0242ac120002','1.0','Default service for Service Intent','2021-08-18 17:40:03',NULL); + +INSERT INTO `service_recipe` (`id`, `ACTION`, `VERSION_STR`, `DESCRIPTION`, `ORCHESTRATION_URI`, `SERVICE_PARAM_XSD`, `RECIPE_TIMEOUT`, `SERVICE_TIMEOUT_INTERIM`, `CREATION_TIMESTAMP`, `SERVICE_MODEL_UUID`) VALUES (22,'createInstance','1','Custom recipe to create Service Intent instance if no custom BPMN flow is found','/mso/async/services/CreateServiceIntentInstance',NULL,180,NULL,'2021-08-18 17:40:03','6790ab0e-034f-11eb-adc1-0242ac120002'); +INSERT INTO `service_recipe` (`id`, `ACTION`, `VERSION_STR`, `DESCRIPTION`, `ORCHESTRATION_URI`, `SERVICE_PARAM_XSD`, `RECIPE_TIMEOUT`, `SERVICE_TIMEOUT_INTERIM`, `CREATION_TIMESTAMP`, `SERVICE_MODEL_UUID`) VALUES (23,'deleteInstance','1','Custom recipe to delete Service Intent instance if no custom BPMN flow is found','/mso/async/services/DeleteServiceIntentInstance',NULL,180,NULL,'2021-08-18 18:40:03','6790ab0e-034f-11eb-adc1-0242ac120002'); +INSERT INTO `service_recipe` (`id`, `ACTION`, `VERSION_STR`, `DESCRIPTION`, `ORCHESTRATION_URI`, `SERVICE_PARAM_XSD`, `RECIPE_TIMEOUT`, `SERVICE_TIMEOUT_INTERIM`, `CREATION_TIMESTAMP`, `SERVICE_MODEL_UUID`) VALUES (24,'updateInstance','1','Custom recipe to modify Service Intent instance if no custom BPMN flow is found','/mso/async/services/ModifyServiceIntentInstance',NULL,180,NULL,'2021-08-18 18:40:03','6790ab0e-034f-11eb-adc1-0242ac120002'); + -- Recipe for E2E service update (R2 just support adding/deleting network service) INSERT INTO `service_recipe` (`id`, `ACTION`, `VERSION_STR`, `DESCRIPTION`, `ORCHESTRATION_URI`, `SERVICE_PARAM_XSD`, `RECIPE_TIMEOUT`, `SERVICE_TIMEOUT_INTERIM`, `CREATION_TIMESTAMP`, `SERVICE_MODEL_UUID`) VALUES (15,'updateInstance','1','Custom recipe to update E2E service-instance if no custom BPMN flow is found','/mso/async/services/UpdateCustomE2EServiceInstance',NULL,180,NULL,'2018-03-05 10:52:03','dfcd7471-16c7-444e-8268-d4c50d90593a'); INSERT INTO `service_recipe` (`id`, `ACTION`, `VERSION_STR`, `DESCRIPTION`, `ORCHESTRATION_URI`, `SERVICE_PARAM_XSD`, `RECIPE_TIMEOUT`, `SERVICE_TIMEOUT_INTERIM`, `CREATION_TIMESTAMP`, `SERVICE_MODEL_UUID`) VALUES (16,'scaleInstance','1','Custom recipe to scale E2E service-instance if no custom BPMN flow is found','/mso/async/services/ScaleCustomE2EServiceInstance',NULL,180,NULL,'2018-05-15 18:52:03','dfcd7471-16c7-444e-8268-d4c50d90593a'); diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/CreateServiceIntentInstance.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/CreateServiceIntentInstance.groovy new file mode 100644 index 0000000000..303b685a38 --- /dev/null +++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/CreateServiceIntentInstance.groovy @@ -0,0 +1,153 @@ +/* + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + # Copyright (c) 2020, Wipro Limited. + # + # Licensed under the Apache License, Version 2.0 (the "License") + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.bpmn.infrastructure.scripts + +import org.camunda.bpm.engine.delegate.BpmnError +import org.camunda.bpm.engine.delegate.DelegateExecution +import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor +import org.onap.so.bpmn.common.scripts.ExceptionUtil +import org.onap.so.bpmn.common.scripts.RequestDBUtil +import org.onap.so.bpmn.core.json.JsonUtils +import org.onap.so.db.request.beans.ResourceOperationStatus +import org.slf4j.Logger +import org.slf4j.LoggerFactory + +import static org.apache.commons.lang3.StringUtils.isBlank + +class CreateServiceIntentInstance extends AbstractServiceTaskProcessor { + + String Prefix = "CreateSiInstance_" + ExceptionUtil exceptionUtil = new ExceptionUtil() + RequestDBUtil requestDBUtil = new RequestDBUtil() + JsonUtils jsonUtil = new JsonUtils() + ServiceIntentUtils serviceIntentUtils = new ServiceIntentUtils() + private static final Logger logger = LoggerFactory.getLogger(CreateServiceIntentInstance.class) + + @Override + void preProcessRequest(DelegateExecution execution) { + logger.debug(Prefix + "preProcessRequest Start") + execution.setVariable("prefix", Prefix) + execution.setVariable("startTime", System.currentTimeMillis()) + def msg + try { + // get request input + String subnetInstanceReq = execution.getVariable("bpmnRequest") + logger.debug(subnetInstanceReq) + + serviceIntentUtils.setCommonExecutionVars(execution) + + //modelInfo + String modelInvariantUuid = jsonUtil.getJsonValue(subnetInstanceReq, "modelInvariantUuid") + if (isBlank(modelInvariantUuid)) { + msg = "Input modelInvariantUuid is null" + logger.debug(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg) + } else { + execution.setVariable("modelInvariantUuid", modelInvariantUuid) + } + + logger.debug("modelInvariantUuid: " + modelInvariantUuid) + + String modelUuid = jsonUtil.getJsonValue(subnetInstanceReq, "modelUuid") + if (isBlank(modelUuid)) { + msg = "Input modelUuid is null" + logger.debug(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg) + } else { + execution.setVariable("modelUuid", modelUuid) + } + + logger.debug("modelUuid: " + modelUuid) + + String additionalPropJsonStr = execution.getVariable("serviceIntentParams") + String siId = jsonUtil.getJsonValue(additionalPropJsonStr, "serviceInstanceID") //for debug + if (isBlank(siId)) { + siId = UUID.randomUUID().toString() + } + + logger.debug("serviceInstanceID: " + modelUuid) + execution.setVariable("serviceInstanceID", siId) + + String sST = jsonUtil.getJsonValue(subnetInstanceReq, "sst") + execution.setVariable("sst", sST) + + String jobId = UUID.randomUUID().toString() + execution.setVariable("jobId", jobId) + + } catch (BpmnError e) { + throw e + } catch (Exception ex) { + msg = "Exception in CreateServiceIntentInstance.preProcessRequest " + ex.getMessage() + logger.debug(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) + } + logger.debug(Prefix + "preProcessRequest Exit") + } + + + /** + * create operation status in request db + * + * Init the Operation Status + */ + def prepareInitOperationStatus = { DelegateExecution execution -> + logger.debug(Prefix + "prepareInitOperationStatus Start") + + String modelUuid = execution.getVariable("modelUuid") + String jobId = execution.getVariable("jobId") + String nsiId = execution.getVariable("serviceInstanceID") + logger.debug("Generated new job for Service Instance serviceId:" + modelUuid + " jobId:" + jobId) + + ResourceOperationStatus initStatus = new ResourceOperationStatus() + initStatus.setServiceId(nsiId) // set nsiId to this field + initStatus.setOperationId(jobId) // set jobId to this field + initStatus.setResourceTemplateUUID(modelUuid) // set modelUuid to this field + initStatus.setOperType("Create") + //initStatus.setResourceInstanceID() // set nssiId to this field + requestDBUtil.prepareInitResourceOperationStatus(execution, initStatus) + + logger.debug(Prefix + "prepareInitOperationStatus Exit") + } + + + /** + * return sync response + */ + def sendSyncResponse = { DelegateExecution execution -> + logger.debug(Prefix + "sendSyncResponse Start") + try { + String jobId = execution.getVariable("jobId") + String allocateSyncResponse = """{"jobId": "${jobId}","status": "processing"}""" + .trim().replaceAll(" ", "").trim().replaceAll(" ", "") + + logger.debug("sendSyncResponse to APIH:" + "\n" + allocateSyncResponse) + sendWorkflowResponse(execution, 202, allocateSyncResponse) + + execution.setVariable("sentSyncResponse", true) + } catch (Exception ex) { + String msg = "Exception in sendSyncResponse:" + ex.getMessage() + logger.debug(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) + } + logger.debug(Prefix + "sendSyncResponse Exit") + } + +} diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DeleteServiceIntentInstance.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DeleteServiceIntentInstance.groovy new file mode 100644 index 0000000000..59cf5ee7fe --- /dev/null +++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DeleteServiceIntentInstance.groovy @@ -0,0 +1,127 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + # Copyright (c) 2020, Wipro Limited. + # + # Licensed under the Apache License, Version 2.0 (the "License") + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.bpmn.infrastructure.scripts + +import org.camunda.bpm.engine.delegate.BpmnError +import org.camunda.bpm.engine.delegate.DelegateExecution +import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor +import org.onap.so.bpmn.common.scripts.ExceptionUtil +import org.onap.so.bpmn.common.scripts.RequestDBUtil +import org.onap.so.bpmn.core.json.JsonUtils +import org.onap.so.db.request.beans.ResourceOperationStatus +import org.slf4j.Logger +import org.slf4j.LoggerFactory + +import static org.apache.commons.lang3.StringUtils.isBlank + +class DeleteServiceIntentInstance extends AbstractServiceTaskProcessor { + String Prefix = "DCLL_" + ExceptionUtil exceptionUtil = new ExceptionUtil() + JsonUtils jsonUtil = new JsonUtils() + RequestDBUtil requestDBUtil = new RequestDBUtil() + ServiceIntentUtils serviceIntentUtils = new ServiceIntentUtils() + + private static final Logger logger = LoggerFactory.getLogger(DeleteServiceIntentInstance.class) + + @Override + void preProcessRequest(DelegateExecution execution) { + logger.debug(Prefix + "preProcessRequest Start") + execution.setVariable("prefix", Prefix) + execution.setVariable("startTime", System.currentTimeMillis()) + def msg + try { + // get request input + String subnetInstanceReq = execution.getVariable("bpmnRequest") + logger.debug(subnetInstanceReq) + + serviceIntentUtils.setCommonExecutionVars(execution) + + String serviceInstanceID = jsonUtil.getJsonValue(subnetInstanceReq, "serviceInstanceID") + if (isBlank(serviceInstanceID)) { + msg = "Input serviceInstanceID is null" + logger.debug(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg) + } else { + execution.setVariable("serviceInstanceID", serviceInstanceID) + } + + String jobId = UUID.randomUUID().toString() + execution.setVariable("jobId", jobId) + + } catch (BpmnError e) { + throw e + } catch (Exception ex) { + msg = "Exception in DeAllocateSliceSubnet.preProcessRequest " + ex.getMessage() + logger.debug(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) + } + logger.debug(Prefix + "preProcessRequest Exit") + } + + + /** + * create operation status in request db + * + * Init the Operation Status + */ + def prepareInitOperationStatus = { DelegateExecution execution -> + logger.debug(Prefix + "prepareInitOperationStatus Start") + + String siId = execution.getVariable("serviceInstanceID") + String jobId = execution.getVariable("jobId") + String nsiId = siId + String modelUuid = serviceIntentUtils.getModelUuidFromServiceInstance(siId) + logger.debug("Generated new job for Service Instance serviceId:" + nsiId + " jobId:" + jobId) + + ResourceOperationStatus initStatus = new ResourceOperationStatus() + initStatus.setServiceId(nsiId) + initStatus.setOperationId(jobId) + initStatus.setResourceTemplateUUID(modelUuid) + initStatus.setOperType("Delete") + requestDBUtil.prepareInitResourceOperationStatus(execution, initStatus) + + logger.debug(Prefix + "prepareInitOperationStatus Exit") + } + + + /** + * return sync response + */ + def sendSyncResponse = { DelegateExecution execution -> + logger.debug(Prefix + "sendSyncResponse Start") + try { + String jobId = execution.getVariable("jobId") + String deAllocateSyncResponse = """{"jobId": "${jobId}","status": "processing"}""".trim().replaceAll(" ", "") + + logger.debug("sendSyncResponse to APIH:" + "\n" + deAllocateSyncResponse) + sendWorkflowResponse(execution, 202, deAllocateSyncResponse) + + execution.setVariable("sentSyncResponse", true) + } catch (Exception ex) { + String msg = "Exception in sendSyncResponse:" + ex.getMessage() + logger.debug(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) + } + logger.debug(Prefix + "sendSyncResponse Exit") + } + +} + diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCloudLeasedLineCreate.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCloudLeasedLineCreate.groovy new file mode 100644 index 0000000000..2e0f3cfd66 --- /dev/null +++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCloudLeasedLineCreate.groovy @@ -0,0 +1,391 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2020 Huawei Technologies Co., Ltd. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.bpmn.infrastructure.scripts + +import org.camunda.bpm.engine.delegate.BpmnError +import org.camunda.bpm.engine.delegate.DelegateExecution +import org.onap.aai.domain.yang.NetworkPolicy +import org.onap.aai.domain.yang.ServiceInstance +import org.onap.aaiclient.client.aai.AAIResourcesClient +import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri +import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory +import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder +import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor +import org.onap.so.bpmn.common.scripts.ExceptionUtil +import org.onap.so.bpmn.common.scripts.RequestDBUtil +import org.onap.so.bpmn.core.json.JsonUtils +import org.onap.so.db.request.beans.ResourceOperationStatus +import org.slf4j.Logger +import org.slf4j.LoggerFactory +import org.springframework.web.util.UriUtils + +import static org.apache.commons.lang3.StringUtils.isBlank + +class DoCloudLeasedLineCreate extends AbstractServiceTaskProcessor { + + private static final Logger logger = LoggerFactory.getLogger(DoCloudLeasedLineCreate.class); + JsonUtils jsonUtil = new JsonUtils() + RequestDBUtil requestDBUtil = new RequestDBUtil() + ServiceIntentUtils serviceIntentUtils = new ServiceIntentUtils() + ExceptionUtil exceptionUtil = new ExceptionUtil() + String Prefix = "CLLC_" + + + void preProcessRequest(DelegateExecution execution) { + logger.debug("Start preProcessRequest") + execution.setVariable("prefix", Prefix) + String msg = "" + + try { + execution.setVariable("startTime", System.currentTimeMillis()) + + msg = serviceIntentUtils.getExecutionInputParams(execution) + logger.debug("Create CLL input parameters: " + msg) + + serviceIntentUtils.setSdncCallbackUrl(execution, true) + logger.debug("SDNC Callback URL: " + execution.getVariable("sdncCallbackUrl")) + + String additionalPropJsonStr = execution.getVariable("serviceIntentParams") + + String cllId = jsonUtil.getJsonValue(additionalPropJsonStr, "serviceInstanceID") //for debug + if (isBlank(cllId)) { + cllId = UUID.randomUUID().toString() + } + + String operationId = UUID.randomUUID().toString() + execution.setVariable("operationId", operationId) + + logger.debug("Generate new CLL ID:" + cllId) + cllId = UriUtils.encode(cllId, "UTF-8") + execution.setVariable("cllId", cllId) + + String cllName = execution.getVariable("servicename") + execution.setVariable("cllName", cllName) + + String sst = execution.getVariable("sst") + execution.setVariable("sst", sst) + + String transportNetworks = jsonUtil.getJsonValue(additionalPropJsonStr, "transportNetworks") + if (isBlank(transportNetworks)) { + msg = "ERROR: preProcessRequest: Input transportNetworks is null" + logger.error(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg) + } else { + execution.setVariable("transportNetworks", transportNetworks) + } + logger.debug("transportNetworks: " + transportNetworks) + + if (isBlank(serviceIntentUtils.setExecVarFromJsonIfExists(execution, additionalPropJsonStr, + "enableSdnc", "enableSdnc"))) { + serviceIntentUtils.setEnableSdncConfig(execution) + } + } catch (BpmnError e) { + throw e + } catch (Exception ex) { + msg = "Exception in preProcessRequest " + ex.getMessage() + logger.debug(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) + } + logger.debug("Finish preProcessRequest") + } + + void updateAAIOrchStatus(DelegateExecution execution) { + logger.debug("Start updateAAIOrchStatus") + String cllId = execution.getVariable("cllId") + String orchStatus = execution.getVariable("orchestrationStatus") + + try { + ServiceInstance si = new ServiceInstance() + si.setOrchestrationStatus(orchStatus) + AAIResourcesClient client = new AAIResourcesClient() + AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.Types.SERVICE_INSTANCE.getFragment(cllId)) + client.update(uri, si) + } catch (BpmnError e) { + throw e + } catch (Exception ex) { + String msg = "Exception in CreateSliceService.updateAAIOrchStatus " + ex.getMessage() + logger.info(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) + } + + logger.debug("Finish updateAAIOrchStatus") + } + + void prepareUpdateJobStatus(DelegateExecution execution, + String status, + String progress, + String statusDescription) { + String cllId = execution.getVariable("cllId") + String modelUuid = execution.getVariable("modelUuid") + String jobId = execution.getVariable("jobId") + String nsiId = cllId + String operType = "CREATE" + + ResourceOperationStatus roStatus = serviceIntentUtils.buildRoStatus(modelUuid, cllId, + jobId, nsiId, operType, status, progress, statusDescription) + + logger.debug("prepareUpdateJobStatus: roStatus={}", roStatus) + requestDBUtil.prepareUpdateResourceOperationStatus(execution, roStatus) + } + + + void createServiceInstance(DelegateExecution execution) { + + String serviceRole = "cll" + String serviceType = execution.getVariable("serviceType") + String cllId = execution.getVariable("cllId") + try { + org.onap.aai.domain.yang.ServiceInstance ss = new org.onap.aai.domain.yang.ServiceInstance() + ss.setServiceInstanceId(cllId) + String cllName = execution.getVariable("cllName") + if (isBlank(cllName)) { + logger.error("ERROR: createServiceInstance: cllName is null") + cllName = cllId + } + ss.setServiceInstanceName(cllName) + ss.setServiceType(serviceType) + String serviceStatus = "created" + ss.setOrchestrationStatus(serviceStatus) + String modelInvariantUuid = execution.getVariable("modelInvariantUuid") + String modelUuid = execution.getVariable("modelUuid") + ss.setModelInvariantId(modelInvariantUuid) + ss.setModelVersionId(modelUuid) + ss.setEnvironmentContext("cll") + ss.setServiceRole(serviceRole) + + AAIResourcesClient client = getAAIClient() + AAIResourceUri uri = + AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business() + .customer(execution.getVariable("globalSubscriberId")) + .serviceSubscription(execution.getVariable("subscriptionServiceType")) + .serviceInstance(cllId)) + client.create(uri, ss) + } catch (BpmnError e) { + throw e + } catch (Exception ex) { + String msg = "Exception in DoCloudLeasedLineCreate.createServiceInstance: " + ex.getMessage() + logger.error(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) + } + } + + + void createAllottedResource(DelegateExecution execution) { + String cllId = execution.getVariable('cllId') + + try { + List networkStrList = jsonUtil.StringArrayToList(execution.getVariable("transportNetworks")) + + for (String networkStr : networkStrList) { + String networkId = jsonUtil.getJsonValue(networkStr, "id") + String allottedResourceId = isBlank(networkId) ? UUID.randomUUID().toString() : networkId + + AAIResourceUri allottedResourceUri = + AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business() + .customer(execution.getVariable("globalSubscriberId")) + .serviceSubscription(execution.getVariable("subscriptionServiceType")) + .serviceInstance(execution.getVariable("cllId")) + .allottedResource(allottedResourceId)) + execution.setVariable("allottedResourceUri", allottedResourceUri) + String modelInvariantId = execution.getVariable("modelInvariantUuid") + String modelVersionId = execution.getVariable("modelUuid") + + String slaStr = jsonUtil.getJsonValue(networkStr, "sla") + if (slaStr == null || slaStr.isEmpty()) { + String msg = "ERROR: createNetworkPolicy: SLA is null" + logger.error(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) + } + + org.onap.aai.domain.yang.AllottedResource resource = new org.onap.aai.domain.yang.AllottedResource() + resource.setId(allottedResourceId) + resource.setType("TsciNetwork") + resource.setAllottedResourceName("network_" + allottedResourceId) + getAAIClient().create(allottedResourceUri, resource) + + createNetworkPolicyForAllocatedResource(execution, cllId, allottedResourceId, slaStr) + + String linkArrayStr = jsonUtil.getJsonValue(networkStr, "connectionLinks") + createLogicalLinksForAllocatedResource(execution, linkArrayStr, cllId, allottedResourceId) + } + } catch (BpmnError e) { + throw e + } catch (Exception ex) { + String msg = "Exception in DoCloudLeasedLineCreate.createAllottedResource: " + ex.getMessage() + logger.error(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) + } + } + + void createNetworkPolicy(DelegateExecution execution, String cllId, String networkPolicyId, String slaStr) { + try { + + + NetworkPolicy networkPolicy = new NetworkPolicy(); + networkPolicy.setNetworkPolicyId(networkPolicyId) + networkPolicy.setName("TSCi policy") + networkPolicy.setType("SLA") + networkPolicy.setNetworkPolicyFqdn(cllId) + + String latencyStr = jsonUtil.getJsonValue(slaStr, "latency") + if (latencyStr != null && !latencyStr.isEmpty()) { + networkPolicy.setLatency(Integer.parseInt(latencyStr)) + } + + String bwStr = jsonUtil.getJsonValue(slaStr, "maxBandwidth") + if (bwStr != null && !bwStr.isEmpty()) { + networkPolicy.setMaxBandwidth(Integer.parseInt(bwStr)) + } else { + logger.debug("ERROR: createNetworkPolicy: maxBandwidth is null") + } + + //networkPolicy.setReliability(new Object()) + + AAIResourceUri networkPolicyUri = + AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().networkPolicy(networkPolicyId)) + getAAIClient().create(networkPolicyUri, networkPolicy) + + } catch (BpmnError e) { + throw e + } catch (Exception ex) { + String msg = "Exception in DoCreateSliceServiceInstance.instantiateSliceService. " + ex.getMessage() + logger.error(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) + } + } + + void createNetworkPolicyForAllocatedResource(DelegateExecution execution, + String cllId, + String allottedResourceId, String slaStr) { + try { + AAIResourceUri allottedResourceUri = + AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business() + .customer(execution.getVariable("globalSubscriberId")) + .serviceSubscription(execution.getVariable("subscriptionServiceType")) + .serviceInstance(cllId) + .allottedResource(allottedResourceId)) + + if (!getAAIClient().exists(allottedResourceUri)) { + logger.info("ERROR: createLogicalLinksForAllocatedResource: allottedResource not exist: uri={}", + allottedResourceUri) + return + } + + String networkPolicyId = UUID.randomUUID().toString() + createNetworkPolicy(execution, cllId, networkPolicyId, slaStr) + + serviceIntentUtils.attachNetworkPolicyToAllottedResource(execution, serviceIntentUtils.AAI_VERSION, + allottedResourceUri, + networkPolicyId); + + } catch (BpmnError e) { + throw e + } catch (Exception ex) { + String msg = "Exception in DoCreateSliceServiceInstance.instantiateSliceService. " + ex.getMessage() + logger.error(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) + } + } + + void createLogicalLinksForAllocatedResource(DelegateExecution execution, + String linkArrayStr, String cllId, + String allottedResourceId) { + try { + AAIResourceUri allottedResourceUri = + AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business() + .customer(execution.getVariable("globalSubscriberId")) + .serviceSubscription(execution.getVariable("subscriptionServiceType")) + .serviceInstance(cllId) + .allottedResource(allottedResourceId)) + + if (!getAAIClient().exists(allottedResourceUri)) { + logger.info("ERROR: createLogicalLinksForAllocatedResource: allottedResource not exist: uri={}", + allottedResourceUri) + return + } + + List linkStrList = jsonUtil.StringArrayToList(linkArrayStr) + + for (String linkStr : linkStrList) { + String linkId = jsonUtil.getJsonValue(linkStr, "name") + if (isBlank(linkId)) { + linkId = "cll-" + UUID.randomUUID().toString() + } + logger.debug("createLogicalLinksForAllocatedResource: linkId=" + linkId) + + String epA = jsonUtil.getJsonValue(linkStr, "transportEndpointA") + String epB = jsonUtil.getJsonValue(linkStr, "transportEndpointB") + String modelInvariantId = execution.getVariable("modelInvariantUuid") + String modelVersionId = execution.getVariable("modelUuid") + + org.onap.aai.domain.yang.LogicalLink resource = new org.onap.aai.domain.yang.LogicalLink() + resource.setLinkId(linkId) + resource.setLinkName(epA) + resource.setLinkName2(epB) + resource.setLinkType("TsciConnectionLink") + resource.setInMaint(false) + + //epA is link-name + AAIResourceUri logicalLinkUri = + AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().logicalLink(epA)) + getAAIClient().create(logicalLinkUri, resource) + + serviceIntentUtils.attachLogicalLinkToAllottedResource(execution, serviceIntentUtils.AAI_VERSION, + allottedResourceUri, epA); + } + } catch (BpmnError e) { + throw e + } catch (Exception ex) { + String msg = "Exception in DoCloudLeasedLineCreate.createLogicalLinksForAllocatedResource: " + ex.getMessage() + logger.error(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) + } + } + + void preprocessSdncCreateCllRequest(DelegateExecution execution) { + def method = getClass().getSimpleName() + '.preProcessSDNCActivateRequest(' + + 'execution=' + execution.getId() + + ')' + def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled') + logger.trace('Entered ' + method) + + logger.trace("STARTED preProcessSDNCActivateRequest Process") + try { + String serviceInstanceId = execution.getVariable("cllId") + + String createSDNCRequest = serviceIntentUtils.buildSDNCRequest(execution, serviceInstanceId, "create") + + execution.setVariable("CLL_SDNCRequest", createSDNCRequest) + logger.debug("Outgoing SDNCRequest is: \n" + createSDNCRequest) + + } catch (Exception e) { + logger.debug("Exception Occured Processing preProcessSDNCActivateRequest. Exception is:\n" + e) + exceptionUtil.buildAndThrowWorkflowException(execution, 1002, + "Error Occured during preProcessSDNCActivateRequest Method:\n" + e.getMessage()) + } + logger.trace("COMPLETED preProcessSDNCActivateRequest Process") + } + + + void validateSDNCResponse(DelegateExecution execution, String response, String method) { + serviceIntentUtils.validateSDNCResponse(execution, response, method) + } +} diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCloudLeasedLineDelete.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCloudLeasedLineDelete.groovy new file mode 100644 index 0000000000..b7f206cedc --- /dev/null +++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCloudLeasedLineDelete.groovy @@ -0,0 +1,174 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2020 Huawei Technologies Co., Ltd. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.bpmn.infrastructure.scripts + + +import org.camunda.bpm.engine.delegate.BpmnError +import org.camunda.bpm.engine.delegate.DelegateExecution +import org.onap.aai.domain.yang.ServiceInstance +import org.onap.aaiclient.client.aai.AAIResourcesClient +import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri +import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory +import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder +import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types +import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor +import org.onap.so.bpmn.common.scripts.ExceptionUtil +import org.onap.so.bpmn.common.scripts.RequestDBUtil +import org.onap.so.bpmn.core.json.JsonUtils +import org.onap.so.db.request.beans.ResourceOperationStatus +import org.slf4j.Logger +import org.slf4j.LoggerFactory + +import static org.apache.commons.lang3.StringUtils.isBlank +import static org.apache.commons.lang3.StringUtils.isEmpty + +class DoCloudLeasedLineDelete extends AbstractServiceTaskProcessor { + String Prefix = "DCLL_" + + ExceptionUtil exceptionUtil = new ExceptionUtil() + JsonUtils jsonUtil = new JsonUtils() + RequestDBUtil requestDBUtil = new RequestDBUtil() + ServiceIntentUtils serviceIntentUtils = new ServiceIntentUtils() + private static final Logger logger = LoggerFactory.getLogger(DoCloudLeasedLineDelete.class) + + + void preProcessRequest(DelegateExecution execution) { + logger.debug("Start preProcessRequest") + + execution.setVariable("startTime", System.currentTimeMillis()) + String msg = serviceIntentUtils.getExecutionInputParams(execution) + logger.debug("Deallocate CLL input parameters: " + msg) + + execution.setVariable("prefix", Prefix) + + serviceIntentUtils.setSdncCallbackUrl(execution, true) + logger.debug("SDNC Callback URL: " + execution.getVariable("sdncCallbackUrl")) + + String cllId = execution.getVariable("serviceInstanceID") + execution.setVariable("cllId", cllId) + + String cllName = execution.getVariable("servicename") + execution.setVariable("cllName", cllName) + + String modelInvariantUuid = execution.getVariable("modelInvariantUuid") + String modelUuid = execution.getVariable("modelUuid") + if (isEmpty(modelUuid)) { + modelUuid = serviceIntentUtils.getModelUuidFromServiceInstance(execution.getVariable("serviceInstanceID")) + } + def isDebugLogEnabled = true + execution.setVariable("isDebugLogEnabled", isDebugLogEnabled) + String serviceModelInfo = """{ + "modelInvariantUuid":"${modelInvariantUuid}", + "modelUuid":"${modelUuid}", + "modelVersion":"" + }""" + execution.setVariable("serviceModelInfo", serviceModelInfo) + + String additionalPropJsonStr = execution.getVariable("serviceIntentParams") + if (isBlank(additionalPropJsonStr) || + isBlank(serviceIntentUtils.setExecVarFromJsonIfExists(execution, + additionalPropJsonStr, + "enableSdnc", "enableSdnc"))) { + serviceIntentUtils.setEnableSdncConfig(execution) + } + + logger.debug("Finish preProcessRequest") + } + + void preprocessSdncDeleteCllRequest(DelegateExecution execution) { + def method = getClass().getSimpleName() + '.preprocessSdncDeallocateCllRequest(' + + 'execution=' + execution.getId() + ')' + def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled') + logger.trace('Entered ' + method) + + try { + String serviceInstanceId = execution.getVariable("serviceInstanceID") + + String sdncRequest = serviceIntentUtils.buildSDNCRequest(execution, serviceInstanceId, "delete") + + execution.setVariable("CLL_SDNCRequest", sdncRequest) + logger.debug("Outgoing SDNCRequest is: \n" + sdncRequest) + + } catch (Exception e) { + logger.debug("Exception Occurred Processing preprocessSdncDeallocateCllRequest. Exception is:\n" + e) + exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occurred during preProcessSDNCActivateRequest Method:\n" + e.getMessage()) + } + logger.trace("COMPLETED preprocessSdncDeallocateCllRequest Process") + } + + + void validateSDNCResponse(DelegateExecution execution, String response, String method) { + serviceIntentUtils.validateSDNCResponse(execution, response, method) + } + + void deleteServiceInstance(DelegateExecution execution) { + try { + AAIResourcesClient client = getAAIClient() + AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(execution.getVariable("globalSubscriberId")).serviceSubscription(execution.getVariable("subscriptionServiceType")).serviceInstance(execution.getVariable("serviceInstanceID"))) + client.delete(uri) + } catch (BpmnError e) { + throw e + } catch (Exception ex) { + String msg = "Exception in DoDeallocateCll.deleteServiceInstance. " + ex.getMessage() + logger.info(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) + } + } + + public void updateAAIOrchStatus(DelegateExecution execution) { + logger.debug("Start updateAAIOrchStatus") + String cllId = execution.getVariable("cllId") + String orchStatus = execution.getVariable("orchestrationStatus") + + try { + ServiceInstance si = new ServiceInstance() + si.setOrchestrationStatus(orchStatus) + AAIResourcesClient client = getAAIClient() + AAIResourceUri uri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(cllId)) + client.update(uri, si) + } catch (BpmnError e) { + throw e + } catch (Exception ex) { + String msg = "Exception in CreateSliceService.updateAAIOrchStatus " + ex.getMessage() + logger.info(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) + } + + logger.debug("Finish updateAAIOrchStatus") + } + + void prepareUpdateJobStatus(DelegateExecution execution, + String status, + String progress, + String statusDescription) { + String cllId = execution.getVariable("cllId") + String modelUuid = execution.getVariable("modelUuid") + String jobId = execution.getVariable("jobId") + String nsiId = execution.getVariable("nsiId") + + ResourceOperationStatus roStatus = serviceIntentUtils.buildRoStatus(modelUuid, cllId, + jobId, nsiId, "DELETE", status, progress, statusDescription) + + logger.debug("prepareUpdateJobStatus: roStatus={}", roStatus) + requestDBUtil.prepareUpdateResourceOperationStatus(execution, roStatus) + } +} + diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCloudLeasedLineModify.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCloudLeasedLineModify.groovy new file mode 100644 index 0000000000..5c9877840d --- /dev/null +++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCloudLeasedLineModify.groovy @@ -0,0 +1,502 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2020 Huawei Technologies Co., Ltd. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.bpmn.infrastructure.scripts + +import org.camunda.bpm.engine.delegate.BpmnError +import org.camunda.bpm.engine.delegate.DelegateExecution +import org.onap.aai.domain.yang.AllottedResource +import org.onap.aai.domain.yang.AllottedResources +import org.onap.aai.domain.yang.NetworkPolicy +import org.onap.aai.domain.yang.ServiceInstance +import org.onap.aaiclient.client.aai.AAIResourcesClient +import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri +import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory +import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder +import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types +import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor +import org.onap.so.bpmn.common.scripts.ExceptionUtil +import org.onap.so.bpmn.common.scripts.RequestDBUtil +import org.onap.so.bpmn.core.json.JsonUtils +import org.onap.so.db.request.beans.ResourceOperationStatus +import org.slf4j.Logger +import org.slf4j.LoggerFactory + +import static org.apache.commons.lang3.StringUtils.isBlank +import static org.apache.commons.lang3.StringUtils.isEmpty +import static org.apache.commons.lang3.StringUtils.isNotBlank + +public class DoCloudLeasedLineModify extends AbstractServiceTaskProcessor { + String Prefix = "MCLL_" + + ExceptionUtil exceptionUtil = new ExceptionUtil() + JsonUtils jsonUtil = new JsonUtils() + RequestDBUtil requestDBUtil = new RequestDBUtil() + ServiceIntentUtils serviceIntentUtils = new ServiceIntentUtils() + private static final Logger logger = LoggerFactory.getLogger(DoCloudLeasedLineModify.class) + + + void preProcessRequest(DelegateExecution execution) { + logger.debug("Start preProcessRequest") + execution.setVariable("prefix", Prefix) + String msg = "" + + try { + execution.setVariable("startTime", System.currentTimeMillis()) + msg = serviceIntentUtils.getExecutionInputParams(execution) + logger.debug("Modify CLL input parameters: " + msg) + + execution.setVariable("prefix", Prefix) + + serviceIntentUtils.setSdncCallbackUrl(execution, true) + logger.debug("SDNC Callback URL: " + execution.getVariable("sdncCallbackUrl")) + + String additionalPropJsonStr = execution.getVariable("serviceIntentParams") + if (isBlank(additionalPropJsonStr)) { + msg = "ERROR: preProcessRequest: additionalPropJsonStr is null" + logger.error(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg) + } + + String cllId = execution.getVariable("serviceInstanceID") + if (isBlank(cllId)) { + msg = "ERROR: cllId is null" + logger.debug(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg) + } + execution.setVariable("cllId", cllId) + + String cllName = execution.getVariable("servicename") + execution.setVariable("cllName", cllName) + + String operationId = UUID.randomUUID().toString() + execution.setVariable("operationId", operationId) + + String modelInvariantUuid = execution.getVariable("modelInvariantUuid") + String modelUuid = execution.getVariable("modelUuid") + if (isEmpty(modelUuid)) { + modelUuid = serviceIntentUtils.getModelUuidFromServiceInstance(execution.getVariable("serviceInstanceID")) + } + + def isDebugLogEnabled = true + execution.setVariable("isDebugLogEnabled", isDebugLogEnabled) + String serviceModelInfo = """{ + "modelInvariantUuid":"${modelInvariantUuid}", + "modelUuid":"${modelUuid}", + "modelVersion":"" + }""" + execution.setVariable("serviceModelInfo", serviceModelInfo) + + + serviceIntentUtils.setExecVarFromJsonStr(execution, additionalPropJsonStr, + "transportNetworks", "transportNetworks", true) + logger.debug("transportNetworks: " + execution.getVariable("transportNetworks")) + + if (isBlank(serviceIntentUtils.setExecVarFromJsonIfExists(execution, additionalPropJsonStr, + "enableSdnc", "enableSdnc"))) { + serviceIntentUtils.setEnableSdncConfig(execution) + } + } catch (BpmnError e) { + throw e + } catch (Exception ex) { + msg = "Exception in preProcessRequest " + ex.getMessage() + logger.debug(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) + } + logger.debug("Finish preProcessRequest") + } + + + void deleteServiceInstance(DelegateExecution execution) { + try { + AAIResourcesClient client = getAAIClient() + AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(execution.getVariable("globalSubscriberId")).serviceSubscription(execution.getVariable("subscriptionServiceType")).serviceInstance(execution.getVariable("serviceInstanceID"))) + client.delete(uri) + } catch (BpmnError e) { + throw e + } catch (Exception ex) { + String msg = "Exception in DoDeallocateTnNssi.deleteServiceInstance. " + ex.getMessage() + logger.info(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) + } + } + + + void getExistingServiceInstance(DelegateExecution execution) { + String serviceInstanceId = execution.getVariable("cllId") + + AAIResourcesClient resourceClient = getAAIClient() + AAIResourceUri ssServiceuri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(serviceInstanceId)) + + try { + Optional ssOpt = resourceClient.get(ServiceInstance.class, ssServiceuri) + if (ssOpt.isPresent()) { + ServiceInstance ss = ssOpt.get() + AllottedResources ars = serviceIntentUtils.getAllottedResourcesFromAai(execution, serviceInstanceId, true) + if (ars != null) { + List arList = ars.getAllottedResource() + List arIdList = new ArrayList<>() + Map policyMap = new HashMap<>() + Map> logicalLinksMap = new HashMap<>() + for (AllottedResource ar : arList) { + String arId = ar.getId() + arIdList.add(arId) + String policyId = serviceIntentUtils.getPolicyIdFromAr(execution, serviceInstanceId, arId, true) + policyMap.put(arId, policyId) + List logicalLinkList = serviceIntentUtils.getLogicalLinkNamesFromAr(execution, + serviceInstanceId, arId, true) + logicalLinksMap.put(arId, logicalLinkList) + } + execution.setVariable("arIdList", arIdList) + execution.setVariable("arPolicyMap", policyMap) + execution.setVariable("arLogicalLinkMap", logicalLinksMap) + } else { + logger.error("ERROR: getExistingServiceInstance: getAllottedResources() returned null. ss=" + ss + .toString()) + } + } else { + exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Service instance was not found in aai to " + + "associate allotted resource for service :" + serviceInstanceId) + } + } catch (BpmnError e) { + throw e; + } catch (Exception ex) { + String msg = "Exception in getExistingServiceInstance. " + ex.getMessage() + logger.debug(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) + } + } + + void updateServiceInstanceInAAI(DelegateExecution execution) { + getExistingServiceInstance(execution) + updateTsciNetworks(execution) + } + + void updateServiceInstance(DelegateExecution execution) { + String cllId = execution.getVariable("cllId") + try { + ServiceInstance ss = new ServiceInstance() + //ss.setServiceInstanceId(cllId) + String serviceStatus = "modified" + ss.setOrchestrationStatus(serviceStatus) + ss.setEnvironmentContext("tn") + AAIResourcesClient client = getAAIClient() + AAIResourceUri uri = AAIUriFactory.createResourceUri( + AAIFluentTypeBuilder.business() + .customer(execution.getVariable("globalSubscriberId")) + .serviceSubscription(execution.getVariable("subscriptionServiceType")) + .serviceInstance(cllId)) + client.update(uri, ss) + } catch (BpmnError e) { + throw e + } catch (Exception ex) { + String msg = "Exception in DoModifyCllInstance.updateServiceInstance. " + ex.getMessage() + logger.info(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) + } + } + + + String getValidArId(DelegateExecution execution, String arIdStr) { + List arIdList = execution.getVariable("arIdList") + /* + * If arId is not specified by the caller, then we assume the caller + * wants to modify the first network (i.e., allotted resource) in the TSCi tree. + */ + String arId = isBlank(arIdStr) ? arIdList.get(0) : arIdStr + + return arId + } + + void updateLogicalLinksInAr(DelegateExecution execution, String arId, String linkArrayJsonStr) { + try { + String serviceInstanceId = execution.getVariable('cllId') + + /* + * Each TSCi connection-link in linkArrayJsonStr is considered as an "ADD" new + * link to allotted-resource. So, if the link already exists under AR, then do + * nothing. Otherwise, create logical-link. + */ + List linkStrList = jsonUtil.StringArrayToList(linkArrayJsonStr) + for (String linkStr : linkStrList) { + if (logicalLinkExists(execution, arId, linkStr)) { + continue + } + + createLogicalLinkForAllocatedResource(execution, linkStr, serviceInstanceId, arId) + } + } catch (BpmnError e) { + throw e + } catch (Exception ex) { + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, + "Exception in updateLogicalLinksInAr" + ex.getMessage()) + } + } + + void updateLogicalLinksInNetwork(DelegateExecution execution, String networkJsonStr) { + try { + String arId = getValidArId(execution, jsonUtil.getJsonValue(networkJsonStr, "id")) + String linkArrayStr = jsonUtil.getJsonValue(networkJsonStr, "connectionLinks") + updateLogicalLinksInAr(execution, arId, linkArrayStr) + } catch (BpmnError e) { + throw e + } catch (Exception ex) { + String msg = String.format("ERROR: updateLogicalLinksInNetwork: exception: %s", ex.getMessage()) + logger.error(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg); + } + } + + void updateTsciNetworks(DelegateExecution execution) { + try { + List networkStrList = jsonUtil.StringArrayToList(execution.getVariable("transportNetworks")) + for (String networkStr : networkStrList) { + updateLogicalLinksInNetwork(execution, networkStr) + updateNetworkPolicy(execution, networkStr) + } + + } catch (BpmnError e) { + throw e + } catch (Exception ex) { + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, + "Exception in updateTsciNetworks" + ex.getMessage()) + } + } + + int getMaxBwFromNetworkJsonStr(DelegateExecution execution, String networkJsonStr) { + int maxBw = 0 + try { + if (isBlank(networkJsonStr)) { + String msg = "ERROR: getMaxBw: networkJsonStr is null" + logger.error(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) + } + String slaStr = jsonUtil.getJsonValue(networkJsonStr, "sla") + if (isBlank(slaStr)) { + String msg = "ERROR: getMaxBw: slaStr is null" + logger.error(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) + } + + String bwStr = jsonUtil.getJsonValue(slaStr, "maxBandwidth") + if (isNotBlank(bwStr)) { + maxBw = Integer.parseInt(bwStr) + } else { + logger.error("ERROR: getMaxBw: maxBandwidth is null") + } + } catch (BpmnError e) { + throw e + } catch (Exception ex) { + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, + "Exception in getMaxBw" + ex.getMessage()) + } + + return maxBw + } + + void updatePolicyMaxBandwidthInAAI(DelegateExecution execution, String policyId, int maxBw) { + try { + NetworkPolicy networkPolicy = new NetworkPolicy() + networkPolicy.setMaxBandwidth(maxBw) + AAIResourceUri networkPolicyUri = + AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().networkPolicy(policyId)) + getAAIClient().update(networkPolicyUri, networkPolicy) + } catch (BpmnError e) { + throw e + } catch (Exception ex) { + String msg = "Exception in DoModifyCllInstance.updatePolicyMaxBandwidthInAAI. " + ex.getMessage() + logger.info(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) + } + } + + void updateNetworkPolicy(DelegateExecution execution, String networkJsonStr) { + try { + int maxBw = getMaxBwFromNetworkJsonStr(execution, networkJsonStr) + + String arId = getValidArId(execution, jsonUtil.getJsonValue(networkJsonStr, "id")) + Map policyMap = execution.getVariable("arPolicyMap") + String policyId = policyMap.get(arId) + if (isBlank(policyId)) { + String msg = String.format("ERROR: updateNetworkPolicy: policyId not found. arId=%s", arId) + logger.error(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) + } + + updatePolicyMaxBandwidthInAAI(execution, policyId, maxBw) + + } catch (BpmnError e) { + throw e + } catch (Exception ex) { + String msg = String.format("ERROR: updateNetworkPolicy: exception: %s", ex.getMessage()) + logger.error(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg); + } + } + + + void createLogicalLinkForAllocatedResource(DelegateExecution execution, + String linkJsonStr, String cllId, + String allottedResourceId) { + try { + AAIResourceUri allottedResourceUri = serviceIntentUtils.buildAllottedResourceUri(execution, + cllId, allottedResourceId) + + if (!getAAIClient().exists(allottedResourceUri)) { + logger.info("ERROR: createLogicalLinksForAllocatedResource: allottedResource not exist: uri={}", + allottedResourceUri) + return + } + + String linkId = jsonUtil.getJsonValue(linkJsonStr, "id") + if (isBlank(linkId)) { + linkId = "cll-" + UUID.randomUUID().toString() + } + logger.debug("createLogicalLinkForAllocatedResource: linkId=" + linkId) + + String epA = jsonUtil.getJsonValue(linkJsonStr, "transportEndpointA") + String epB = jsonUtil.getJsonValue(linkJsonStr, "transportEndpointB") + String modelInvariantId = execution.getVariable("modelInvariantUuid") + String modelVersionId = execution.getVariable("modelUuid") + + org.onap.aai.domain.yang.LogicalLink resource = new org.onap.aai.domain.yang.LogicalLink() + resource.setLinkId(linkId) + resource.setLinkName(epA) + resource.setLinkName2(epB) + resource.setLinkType("TsciConnectionLink") + resource.setInMaint(false) + + //epA is link-name + AAIResourceUri logicalLinkUri = + AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().logicalLink(epA)) + getAAIClient().create(logicalLinkUri, resource) + + serviceIntentUtils.attachLogicalLinkToAllottedResource(execution, serviceIntentUtils.AAI_VERSION, + allottedResourceUri, epA); + } catch (BpmnError e) { + throw e + } catch (Exception ex) { + String msg = "Exception in DoModifyCllInstance.createLogicalLinksForAllocatedResource: " + ex.getMessage() + logger.error(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) + } + } + + + void preprocessSdncModifyCllRequest(DelegateExecution execution) { + def method = getClass().getSimpleName() + '.preprocessSdncModifyCllRequest(' + + 'execution=' + execution.getId() + ')' + def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled') + logger.trace('Entered ' + method) + + try { + String serviceInstanceId = execution.getVariable("cllId") + + String sdncRequest = serviceIntentUtils.buildSDNCRequest(execution, serviceInstanceId, "update") + + execution.setVariable("CLL_SDNCRequest", sdncRequest) + logger.debug("Outgoing SDNCRequest is: \n" + sdncRequest) + + } catch (BpmnError e) { + throw e + } catch (Exception e) { + logger.debug("Exception Occurred Processing preprocessSdncModifyCllRequest. Exception is:\n" + e) + exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occurred during preProcessSDNCActivateRequest Method:\n" + e.getMessage()) + } + logger.trace("COMPLETED preprocessSdncModifyCllRequest Process") + } + + + void validateSDNCResponse(DelegateExecution execution, String response, String method) { + serviceIntentUtils.validateSDNCResponse(execution, response, method) + } + + + void updateAAIOrchStatus(DelegateExecution execution) { + logger.debug("Start updateAAIOrchStatus") + String cllId = execution.getVariable("cllId") + String orchStatus = execution.getVariable("orchestrationStatus") + + try { + ServiceInstance si = new ServiceInstance() + si.setOrchestrationStatus(orchStatus) + AAIResourcesClient client = getAAIClient() + AAIResourceUri uri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(cllId)) + client.update(uri, si) + } catch (BpmnError e) { + throw e + } catch (Exception ex) { + String msg = "Exception in CreateSliceService.updateAAIOrchStatus " + ex.getMessage() + logger.info(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) + } + + logger.debug("Finish updateAAIOrchStatus") + } + + void prepareUpdateJobStatus(DelegateExecution execution, + String status, + String progress, + String statusDescription) { + String cllId = execution.getVariable("cllId") + String modelUuid = execution.getVariable("modelUuid") + String jobId = execution.getVariable("jobId") + String nsiId = cllId + String operType = "MODIFY" + + ResourceOperationStatus roStatus = serviceIntentUtils.buildRoStatus(modelUuid, cllId, + jobId, nsiId, operType, status, progress, statusDescription) + + logger.debug("prepareUpdateJobStatus: roStatus={}", roStatus) + requestDBUtil.prepareUpdateResourceOperationStatus(execution, roStatus) + } + + boolean logicalLinkExists(DelegateExecution execution, String arIdStr, String linkJsonStr) { + if (isBlank(arIdStr)) { + logger.error("ERROR: logicalLinkExists: arIdStr is empty") + return false + } + if (isBlank(linkJsonStr)) { + logger.error("ERROR: logicalLinkExists: linkJsonStr is empty") + return false + } + + Map> logicalLinksMap = execution.getVariable("arLogicalLinkMap") + if (logicalLinksMap == null) { + logger.error("ERROR: logicalLinkExists: logicalLinksMap is null") + return false + } + + List logicalLinkNameList = logicalLinksMap.get(arIdStr) + if (logicalLinksMap == null) { + logger.error("ERROR: logicalLinkExists: logicalLinkNameList is null. arIdStr=" + arIdStr) + return false + } + + String linkName = jsonUtil.getJsonValue(linkJsonStr, "transportEndpointA") + if (isBlank(linkName)) { + logger.error("ERROR: logicalLinkExists: epA is empty") + return false + } + + return logicalLinkNameList.contains(linkName) + } +} + diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/ModifyServiceIntentInstance.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/ModifyServiceIntentInstance.groovy new file mode 100644 index 0000000000..df817ed90b --- /dev/null +++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/ModifyServiceIntentInstance.groovy @@ -0,0 +1,128 @@ +/* + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + # Copyright (c) 2020, Wipro Limited. + # + # Licensed under the Apache License, Version 2.0 (the "License") + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.bpmn.infrastructure.scripts + +import org.camunda.bpm.engine.delegate.BpmnError +import org.camunda.bpm.engine.delegate.DelegateExecution +import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor +import org.onap.so.bpmn.common.scripts.ExceptionUtil +import org.onap.so.bpmn.common.scripts.RequestDBUtil +import org.onap.so.bpmn.core.json.JsonUtils +import org.onap.so.db.request.beans.ResourceOperationStatus +import org.slf4j.Logger +import org.slf4j.LoggerFactory + +import static org.apache.commons.lang3.StringUtils.isBlank + +class ModifyServiceIntentInstance extends AbstractServiceTaskProcessor { + String Prefix="MCLL_" + ExceptionUtil exceptionUtil = new ExceptionUtil() + JsonUtils jsonUtil = new JsonUtils() + RequestDBUtil requestDBUtil = new RequestDBUtil() + ServiceIntentUtils serviceIntentUtils = new ServiceIntentUtils() + + private static final Logger logger = LoggerFactory.getLogger(ModifyServiceIntentInstance.class) + + @Override + void preProcessRequest(DelegateExecution execution) { + logger.debug(Prefix + "preProcessRequest Start") + execution.setVariable("prefix", Prefix) + execution.setVariable("startTime", System.currentTimeMillis()) + def msg + try { + // get request input + String subnetInstanceReq = execution.getVariable("bpmnRequest") + logger.debug(subnetInstanceReq) + + serviceIntentUtils.setCommonExecutionVars(execution) + + String serviceInstanceID = jsonUtil.getJsonValue(subnetInstanceReq, "serviceInstanceID") + if (isBlank(serviceInstanceID)) { + msg = "Input serviceInstanceID is null" + logger.debug(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg) + } else + { + execution.setVariable("serviceInstanceID", serviceInstanceID) + } + + String jobId = UUID.randomUUID().toString() + execution.setVariable("jobId", jobId) + + } catch(BpmnError e) { + throw e + } catch(Exception ex) { + msg = "Exception in ModifyServiceIntentInstance.preProcessRequest " + ex.getMessage() + logger.debug(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) + } + logger.debug(Prefix + "preProcessRequest Exit") + } + + + /** + * create operation status in request db + * + * Init the Operation Status + */ + def prepareInitOperationStatus = { DelegateExecution execution -> + logger.debug(Prefix + "prepareInitOperationStatus Start") + + String siId = execution.getVariable("serviceInstanceID") + String jobId = execution.getVariable("jobId") + String nsiId = siId + String modelUuid = serviceIntentUtils.getModelUuidFromServiceInstance(siId) + logger.debug("Generated new job for Service Instance serviceId:" + nsiId + "jobId:" + jobId) + + ResourceOperationStatus initStatus = new ResourceOperationStatus() + initStatus.setServiceId(nsiId) + initStatus.setOperationId(jobId) + initStatus.setResourceTemplateUUID(modelUuid) + initStatus.setOperType("Modify") + requestDBUtil.prepareInitResourceOperationStatus(execution, initStatus) + + logger.debug(Prefix + "prepareInitOperationStatus Exit") + } + + + + /** + * return sync response + */ + def sendSyncResponse = { DelegateExecution execution -> + logger.debug(Prefix + "sendSyncResponse Start") + try { + String jobId = execution.getVariable("jobId") + String modifySyncResponse = """{"jobId": "${jobId}","status": "processing"}""" + .trim().replaceAll(" ", "") + logger.debug("sendSyncResponse to APIH:" + "\n" + modifySyncResponse) + sendWorkflowResponse(execution, 202, modifySyncResponse) + + execution.setVariable("sentSyncResponse", true) + } catch (Exception ex) { + String msg = "Exception in sendSyncResponse:" + ex.getMessage() + logger.debug(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) + } + logger.debug(Prefix + "sendSyncResponse Exit") + } + +} diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/ServiceIntentUtils.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/ServiceIntentUtils.groovy new file mode 100644 index 0000000000..f60bfa1c47 --- /dev/null +++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/ServiceIntentUtils.groovy @@ -0,0 +1,669 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2020 Huawei Technologies Co., Ltd. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.bpmn.infrastructure.scripts + +import org.camunda.bpm.engine.delegate.BpmnError +import org.camunda.bpm.engine.delegate.DelegateExecution +import org.onap.aai.domain.yang.AllottedResources +import org.onap.aai.domain.yang.LogicalLink +import org.onap.aai.domain.yang.NetworkPolicy +import org.onap.aai.domain.yang.Relationship +import org.onap.aai.domain.yang.ServiceInstance +import org.onap.aaiclient.client.aai.AAIResourcesClient +import org.onap.aaiclient.client.aai.AAIVersion +import org.onap.aaiclient.client.aai.entities.AAIResultWrapper +import org.onap.aaiclient.client.aai.entities.Relationships +import org.onap.aaiclient.client.aai.entities.uri.AAIPluralResourceUri +import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri +import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory +import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder +import org.onap.so.bpmn.common.scripts.ExceptionUtil +import org.onap.so.bpmn.common.scripts.MsoUtils +import org.onap.so.bpmn.common.scripts.SDNCAdapterUtils +import org.onap.so.bpmn.core.RollbackData +import org.onap.so.bpmn.core.UrnPropertiesReader +import org.onap.so.bpmn.core.WorkflowException +import org.onap.so.bpmn.core.json.JsonUtils +import org.onap.so.db.request.beans.ResourceOperationStatus +import org.slf4j.Logger +import org.slf4j.LoggerFactory + +import static org.apache.commons.lang3.StringUtils.isBlank +import static org.apache.commons.lang3.StringUtils.isNotBlank + +class ServiceIntentUtils { + static final String AAI_VERSION = AAIVersion.LATEST + private static final Logger logger = LoggerFactory.getLogger(ServiceIntentUtils.class); + + + ExceptionUtil exceptionUtil = new ExceptionUtil() + JsonUtils jsonUtil = new JsonUtils() + MsoUtils msoUtils = new MsoUtils() + SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils() + + ServiceIntentUtils() { + } + + + void setCommonExecutionVars(DelegateExecution execution) { + setCommonExecutionVars(execution, true) + } + + void setCommonExecutionVars(DelegateExecution execution, boolean exceptionOnErr) { + def msg + try { + // get request input + String bpmnRequestStr = execution.getVariable("bpmnRequest") + logger.debug("Input Request: " + bpmnRequestStr) + + String requestId = execution.getVariable("mso-request-id") + execution.setVariable("msoRequestId", requestId) + logger.debug("requestId: " + requestId) + + //subscriberInfo + String globalSubscriberId = jsonUtil.getJsonValue(bpmnRequestStr, "globalSubscriberId") + if (isBlank(globalSubscriberId) && exceptionOnErr) { + msg = "Input globalSubscriberId' is null" + exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg) + } else { + execution.setVariable("globalSubscriberId", globalSubscriberId) + } + + String serviceType = jsonUtil.getJsonValue(bpmnRequestStr, "serviceType") + if (isBlank(serviceType) && exceptionOnErr) { + msg = "Input serviceType is null" + logger.debug(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg) + } else { + execution.setVariable("serviceType", serviceType) + } + + String servicename = jsonUtil.getJsonValue(bpmnRequestStr, "name") + if (isNotBlank(servicename)) { + execution.setVariable("servicename", servicename) + } else { + logger.debug("erviceIntentUtils.setCommonExecutionVars: servicename is NOT set") + } + + //requestParameters, subscriptionServiceType is 5G + String subscriptionServiceType = jsonUtil.getJsonValue(bpmnRequestStr, "subscriptionServiceType") + if (isBlank(subscriptionServiceType)) { + msg = "Input subscriptionServiceType is null" + logger.debug(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg) + } else { + execution.setVariable("subscriptionServiceType", subscriptionServiceType) + } + + String jobId = UUID.randomUUID().toString() + execution.setVariable("jobId", jobId) + + String sliceParams = jsonUtil.getJsonValue(bpmnRequestStr, "additionalProperties") + execution.setVariable("serviceIntentParams", sliceParams) + + } catch (BpmnError e) { + throw e + } catch (Exception ex) { + msg = "Exception in ServiceIntentUtils.setCommonExecutionVars: " + ex.getMessage() + logger.debug(msg) + if (exceptionOnErr) { + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) + } + } + } + + void setSdncCallbackUrl(DelegateExecution execution, boolean exceptionOnErr) { + setSdncCallbackUrl(execution, "sdncCallbackUrl", exceptionOnErr) + } + + void setSdncCallbackUrl(DelegateExecution execution, String variableName, boolean exceptionOnErr) { + String sdncCallbackUrl = UrnPropertiesReader.getVariable('mso.workflow.sdncadapter.callback', execution) + + if (isBlank(sdncCallbackUrl) && exceptionOnErr) { + String msg = "mso.workflow.sdncadapter.callback is null" + logger.debug(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg) + } else { + execution.setVariable(variableName, sdncCallbackUrl) + } + } + + String buildSDNCRequest(DelegateExecution execution, String svcInstId, String svcAction) { + String reqAction + switch (svcAction) { + case "create": + reqAction = "CreateCloudLeasedLineInstance" + break + case "delete": + reqAction = "DeleteCloudLeasedLineInstance" + break + case "activate": + reqAction = "ActivateCloudLeasedLineInstance" + break + case "deactivate": + reqAction = "DeactivateCloudLeasedLineInstance" + break + case "update": + reqAction = "ModifyCloudLeasedLineInstance" + break + default: + reqAction = svcAction + } + + buildSDNCRequest(execution, svcInstId, svcAction, reqAction) + } + + String buildSDNCRequest(DelegateExecution execution, String svcInstId, String svcAction, String reqAction) { + + String uuid = execution.getVariable('testReqId') // for junits + if (uuid == null) { + uuid = execution.getVariable("msoRequestId") + "-" + System.currentTimeMillis() + } + + def callbackURL = execution.getVariable("sdncCallbackUrl") + def requestId = execution.getVariable("msoRequestId") + def serviceId = execution.getVariable("sliceServiceInstanceId") + def subServiceType = execution.getVariable("subscriptionServiceType") + def vnfType = execution.getVariable("serviceType") + def vnfName = execution.getVariable("sliceServiceInstanceName") + def tenantId = execution.getVariable("sliceServiceInstanceId") + def source = execution.getVariable("sliceServiceInstanceId") + def vnfId = execution.getVariable("sliceServiceInstanceId") + def cloudSiteId = execution.getVariable("sliceServiceInstanceId") + def serviceModelInfo = execution.getVariable("serviceModelInfo") + def vnfModelInfo = execution.getVariable("serviceModelInfo") + def globalSubscriberId = execution.getVariable("globalSubscriberId") + + String vnfNameString = """${MsoUtils.xmlEscape(vnfName)}""" + String serviceEcompModelInformation = sdncAdapterUtils.modelInfoToEcompModelInformation(serviceModelInfo) + String vnfEcompModelInformation = sdncAdapterUtils.modelInfoToEcompModelInformation(vnfModelInfo) + + String sdncVNFParamsXml = "" + + if (execution.getVariable("vnfParamsExistFlag") == true) { + sdncVNFParamsXml = buildSDNCParamsXml(execution) + } else { + sdncVNFParamsXml = buildDefaultVnfInputParams(vnfId) + } + + String sdncRequest = + """ + + ${MsoUtils.xmlEscape(uuid)} + ${MsoUtils.xmlEscape(svcInstId)} + ${MsoUtils.xmlEscape(svcAction)} + vnf-topology-operation + ${MsoUtils.xmlEscape(callbackURL)} + generic-resource + + + + ${MsoUtils.xmlEscape(requestId)} + ${MsoUtils.xmlEscape(reqAction)} + ${MsoUtils.xmlEscape(source)} + + + + + + ${MsoUtils.xmlEscape(serviceId)} + ${MsoUtils.xmlEscape(subServiceType)} + ${serviceEcompModelInformation} + ${MsoUtils.xmlEscape(svcInstId)} + ${MsoUtils.xmlEscape(globalSubscriberId)} + + + ${MsoUtils.xmlEscape(vnfId)} + ${MsoUtils.xmlEscape(vnfType)} + ${vnfEcompModelInformation} + + + ${vnfNameString} + ${MsoUtils.xmlEscape(tenantId)} + ${MsoUtils.xmlEscape(cloudSiteId)} + ${sdncVNFParamsXml} + + + """ + + logger.debug("sdncRequest: " + sdncRequest) + return sdncRequest + } + + + String buildDefaultVnfInputParams(String vnfName) { + String res = + """ + + ${MsoUtils.xmlEscape(vnfName)} + + """ + + return res + } + + String buildSDNCParamsXml(DelegateExecution execution) { + String params = "" + StringBuilder sb = new StringBuilder() + Map paramsMap = execution.getVariable("TNNSSMF_vnfParamsMap") + + for (Map.Entry entry : paramsMap.entrySet()) { + String paramsXml + String key = entry.getKey(); + String value = entry.getValue() + paramsXml = """<${key}>$value""" + params = sb.append(paramsXml) + } + return params + } + + void validateSDNCResponse(DelegateExecution execution, String response, String method) { + validateSDNCResponse(execution, response, method, true) + } + + void validateSDNCResponse(DelegateExecution execution, String response, String method, boolean exceptionOnErr) { + logger.debug("STARTED ValidateSDNCResponse Process") + + String msg + + String prefix = execution.getVariable("prefix") + if (isBlank(prefix)) { + if (exceptionOnErr) { + msg = "validateSDNCResponse: prefix is null" + logger.error(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg) + } + return + } + + WorkflowException workflowException = execution.getVariable("WorkflowException") + boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator") + + logger.debug("ServiceIntentUtils.validateSDNCResponse: SDNCResponse: " + response) + logger.debug("ServiceIntentUtils.validateSDNCResponse: workflowException: " + workflowException) + + sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator) + + String sdncResponse = response + if (execution.getVariable(prefix + 'sdncResponseSuccess') == true) { + logger.debug("Received a Good Response from SDNC Adapter for " + method + " SDNC Call. Response is: \n" + sdncResponse) + RollbackData rollbackData = execution.getVariable("rollbackData") + if (rollbackData == null) { + rollbackData = new RollbackData() + } + + if (method.equals("allocate")) { + rollbackData.put("VNFMODULE", "rollbackSDNCRequestAllocate", "true") + } else if (method.equals("deallocate")) { + rollbackData.put("VNFMODULE", "rollbackSDNCRequestDeallocate", "true") + } else if (method.equals("activate")) { + rollbackData.put("VNFMODULE", "rollbackSDNCRequestActivate", "true") + } else if (method.equals("deactivate")) { + rollbackData.put("VNFMODULE", "rollbackSDNCRequestDeactivate", "true") + } else if (method.equals("modify")) { + rollbackData.put("VNFMODULE", "rollbackSDNCRequestModify", "true") + } + execution.setVariable("rollbackData", rollbackData) + } else { + if (exceptionOnErr) { + msg = "ServiceIntentUtils.validateSDNCResponse: bad Response from SDNC Adapter for " + method + " SDNC Call." + logger.error(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg) + } + } + + logger.debug("COMPLETED ValidateSDNCResponse Process") + } + + String getExecutionInputParams(DelegateExecution execution) { + String res = "\n msoRequestId=" + execution.getVariable("msoRequestId") + + "\n modelInvariantUuid=" + execution.getVariable("modelInvariantUuid") + + "\n modelUuid=" + execution.getVariable("modelUuid") + + "\n serviceInstanceID=" + execution.getVariable("serviceInstanceID") + + "\n operationType=" + execution.getVariable("operationType") + + "\n globalSubscriberId=" + execution.getVariable("globalSubscriberId") + + "\n dummyServiceId=" + execution.getVariable("dummyServiceId") + + "\n nsiId=" + execution.getVariable("nsiId") + + "\n serviceType=" + execution.getVariable("serviceType") + + "\n subscriptionServiceType=" + execution.getVariable("subscriptionServiceType") + + "\n jobId=" + execution.getVariable("jobId") + + "\n serviceIntentParams=" + execution.getVariable("serviceIntentParams") + + "\n servicename=" + execution.getVariable("servicename") + + return res + } + + String getFirstSnssaiFromSliceProfile(String sliceProfileStr) { + String snssaiListStr = jsonUtil.getJsonValue(sliceProfileStr, "snssaiList") + String snssai = jsonUtil.StringArrayToList(snssaiListStr).get(0) + + return snssai + } + + String getFirstPlmnIdFromSliceProfile(String sliceProfileStr) { + String plmnListStr = jsonUtil.getJsonValue(sliceProfileStr, "plmnIdList") + String res = jsonUtil.StringArrayToList(plmnListStr).get(0) + + return res + } + + void createRelationShipInAAI(DelegateExecution execution, AAIResourceUri uri, Relationship relationship) { + logger.debug("createRelationShipInAAI Start") + String msg + AAIResourcesClient client = new AAIResourcesClient() + try { + if (!client.exists(uri)) { + logger.info("ERROR: createRelationShipInAAI: not exist: uri={}", uri) + return + } + AAIResourceUri from = ((AAIResourceUri) (uri.clone())).relationshipAPI() + client.create(from, relationship) + + } catch (BpmnError e) { + throw e + } catch (Exception ex) { + msg = "Exception in createRelationShipInAAI. " + ex.getMessage() + logger.info(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) + } + logger.debug("createRelationShipInAAI Exit") + } + + void attachLogicalLinkToAllottedResource(DelegateExecution execution, String aaiVersion, AAIResourceUri arUri, + String logicalLinkId) { + + String toLink = "aai/${aaiVersion}/network/logical-links/logical-link/${logicalLinkId}" + + Relationship relationship = new Relationship() + relationship.setRelatedLink(toLink) + relationship.setRelatedTo("logical-link") + relationship.setRelationshipLabel("org.onap.relationships.inventory.ComposedOf") + + createRelationShipInAAI(execution, arUri, relationship) + } + + void attachNetworkPolicyToAllottedResource(DelegateExecution execution, String aaiVersion, + AAIResourceUri aaiResourceUri, String networkPolicyId) { + + String toLink = "aai/${aaiVersion}/network/network-policies/network-policy/${networkPolicyId}" + + Relationship relationship = new Relationship() + relationship.setRelatedLink(toLink) + relationship.setRelatedTo("network-policy") + relationship.setRelationshipLabel("org.onap.relationships.inventory.Uses") + + createRelationShipInAAI(execution, aaiResourceUri, relationship) + + } + + ResourceOperationStatus buildRoStatus(String nsstId, + String nssiId, + String jobId, + String nsiId, + String action, + String status, + String progress, + String statusDescription) { + ResourceOperationStatus roStatus = new ResourceOperationStatus() + roStatus.setResourceTemplateUUID(nsstId) + roStatus.setResourceInstanceID(nssiId) + roStatus.setServiceId(nsiId) + roStatus.setOperationId(jobId) + roStatus.setOperType(action) + roStatus.setProgress(progress) + roStatus.setStatus(status) + roStatus.setStatusDescription(statusDescription) + + return roStatus + } + + + void setEnableSdncConfig(DelegateExecution execution) { + String enableSdnc = UrnPropertiesReader.getVariable( + "mso.workflow.TnNssmf.enableSDNCNetworkConfig") + if (isBlank(enableSdnc)) { + logger.debug("mso.workflow.TnNssmf.enableSDNCNetworkConfig is undefined, so use default value (true)") + enableSdnc = "true" + } + + logger.debug("setEnableSdncConfig: enableSdnc=" + enableSdnc) + + execution.setVariable("enableSdnc", enableSdnc) + } + + String setExecVarFromJsonIfExists(DelegateExecution execution, + String jsonStr, String jsonKey, String varName) { + return setExecVarFromJsonStr(execution, jsonStr, jsonKey, varName, false) + } + + String setExecVarFromJsonStr(DelegateExecution execution, + String jsonStr, String jsonKey, String varName, + boolean exceptionOnErr) { + String msg = "" + String valueStr = jsonUtil.getJsonValue(jsonStr, jsonKey) + if (isBlank(valueStr)) { + if (exceptionOnErr) { + msg = "cannot find " + jsonKey + " in " + jsonStr + logger.debug(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg) + } + } else { + execution.setVariable(varName, valueStr) + } + + return valueStr + } + + ServiceInstance getServiceInstanceFromAai(String serviceInstanceId) { + if (isBlank(serviceInstanceId)) { + logger.error("ERROR: getServiceInstanceFromAai: serviceInstanceId is blank") + return null + } + + ServiceInstance nssi = null + AAIResourcesClient client = new AAIResourcesClient() + AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.Types.SERVICE_INSTANCE + .getFragment(serviceInstanceId)) + Optional nssiOpt = client.get(ServiceInstance.class, uri) + + if (nssiOpt.isPresent()) { + nssi = nssiOpt.get() + return nssi + } else { + String msg = String.format("ERROR: getServiceInstanceFromAai: NSSI %s not found in AAI", serviceInstanceId) + logger.error(msg) + } + + return nssi; + } + + String getModelUuidFromServiceInstance(String serviceInstanceId) { + ServiceInstance si = getServiceInstanceFromAai(serviceInstanceId) + if (si == null) { + String msg = String.format("ERROR: getModelUuidFromServiceInstance: getServiceInstanceFromAai() failed. " + + "serviceInstanceId=%s", serviceInstanceId) + logger.error(msg) + return null + } + + return si.getModelVersionId() + } + + AAIResourceUri buildNetworkPolicyUri(String networkPolicyId) { + AAIResourceUri networkPolicyUri = + AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().networkPolicy(networkPolicyId)) + + return networkPolicyUri + } + + AAIResourceUri buildAllottedResourceUri(DelegateExecution execution, String serviceInstanceId, + String allottedResourceId) { + + AAIResourceUri allottedResourceUri = + AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business() + .customer(execution.getVariable("globalSubscriberId")) + .serviceSubscription(execution.getVariable("subscriptionServiceType")) + .serviceInstance(serviceInstanceId) + .allottedResource(allottedResourceId)) + + return allottedResourceUri + } + + AAIPluralResourceUri buildAllottedResourcesUri(DelegateExecution execution, String serviceInstanceId) { + + AAIPluralResourceUri arsUri = + AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business() + .customer(execution.getVariable("globalSubscriberId")) + .serviceSubscription(execution.getVariable("subscriptionServiceType")) + .serviceInstance(serviceInstanceId) + .allottedResources()) + + return arsUri + } + + AllottedResources getAllottedResourcesFromAai(DelegateExecution execution, String serviceInstanceId, boolean exceptionOnErr) { + AllottedResources res + try { + AAIResourcesClient client = new AAIResourcesClient() + + AAIPluralResourceUri arsUri = buildAllottedResourcesUri(execution, serviceInstanceId) + + //AAIResultWrapper wrapperAllotted = client.get(arsUri, NotFoundException.class) + //Optional allAllotted = wrapperAllotted.asBean(AllottedResources.class) + //AllottedResources allottedResources = allAllotted.get() + + Optional arsOpt = client.get(AllottedResources.class, arsUri) + if (arsOpt.isPresent()) { + res = arsOpt.get() + return res + } else { + String msg = String.format("ERROR: getAllottedResourcesFromAai: ars not found. nssiId=%s", serviceInstanceId) + logger.error(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg) + } + } catch (BpmnError e) { + if (exceptionOnErr) { + throw e; + } + } catch (Exception ex) { + if (exceptionOnErr) { + String msg = String.format("ERROR: getAllottedResourcesFromAai: %s", ex.getMessage()) + logger.error(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg) + } + } + + return res + } + + String getPolicyIdFromAr(DelegateExecution execution, String serviceInstanceId, + String arId, boolean exceptionOnErr) { + String res + try { + AAIResourcesClient client = new AAIResourcesClient() + + AAIResourceUri arUri = buildAllottedResourceUri(execution, serviceInstanceId, arId) + List policyUriList = getRelationshipUriListInAai(execution, arUri, + AAIFluentTypeBuilder.Types.NETWORK_POLICY, exceptionOnErr) + for (AAIResourceUri policyUri : policyUriList) { + Optional policyOpt = client.get(NetworkPolicy.class, policyUri) + if (policyOpt.isPresent()) { + NetworkPolicy policy = policyOpt.get() + return policy.getNetworkPolicyId() + } else { + String msg = String.format("ERROR: getPolicyIdFromAr: arUri=%s", policyUri) + logger.error(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg) + } + } + } catch (BpmnError e) { + if (exceptionOnErr) { + throw e; + } + } catch (Exception ex) { + if (exceptionOnErr) { + String msg = String.format("ERROR: getPolicyIdFromAr: %s", ex.getMessage()) + logger.error(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg) + } + } + + return res + } + + + List getRelationshipUriListInAai(DelegateExecution execution, + AAIResourceUri uri, + Object info, + boolean exceptionOnErr) { + AAIResourcesClient client = new AAIResourcesClient() + AAIResultWrapper wrapper = client.get(uri); + Optional relationships = wrapper.getRelationships() + if (relationships.isPresent()) { + return relationships.get().getRelatedUris(info) + } else { + if (exceptionOnErr) { + String msg = "ERROR: getRelationshipUriListInAai: No relationship found" + logger.error(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg) + } + } + + return null + } + + List getLogicalLinkNamesFromAr(DelegateExecution execution, String serviceInstanceId, + String arId, boolean exceptionOnErr) { + List res = new ArrayList<>() + try { + AAIResourcesClient client = new AAIResourcesClient() + + AAIResourceUri arUri = buildAllottedResourceUri(execution, serviceInstanceId, arId) + List logicalLinkUriList = getRelationshipUriListInAai(execution, arUri, + AAIFluentTypeBuilder.Types.LOGICAL_LINK, exceptionOnErr) + for (AAIResourceUri logicalLinkUri : logicalLinkUriList) { + Optional logicalLinkOpt = client.get(LogicalLink.class, logicalLinkUri) + if (logicalLinkOpt.isPresent()) { + LogicalLink logicalLink = logicalLinkOpt.get() + res.add(logicalLink.getLinkName()) + } else { + String msg = String.format("ERROR: getLogicalLinkNamesFromAr: logicalLinkUri=%s", logicalLinkUri) + logger.error(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg) + } + } + } catch (BpmnError e) { + if (exceptionOnErr) { + throw e; + } + } catch (Exception ex) { + if (exceptionOnErr) { + String msg = String.format("ERROR: getLogicalLinkNamesFromAr: %s", ex.getMessage()) + logger.error(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg) + } + } + + return res + } +} \ No newline at end of file diff --git a/bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/CreateServiceIntentInstance.bpmn b/bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/CreateServiceIntentInstance.bpmn new file mode 100644 index 0000000000..7e8290d728 --- /dev/null +++ b/bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/CreateServiceIntentInstance.bpmn @@ -0,0 +1,175 @@ + + + + + Flow_0cmaj9d + + + Flow_0cmaj9d + Flow_0ou7wr9 + import org.onap.so.bpmn.infrastructure.scripts.* +def nss = new CreateServiceIntentInstance() +nss.preProcessRequest(execution) + + + Flow_0ayd6dj + Flow_0m5n6md + import org.onap.so.bpmn.infrastructure.scripts.* +def nss = new CreateServiceIntentInstance() +nss.sendSyncResponse(execution) + + + Flow_0m5n6md + Flow_1fij4ds + Flow_0g7721r + Flow_1kk0exp + + + Flow_189zwjw + Flow_1fij4ds + Flow_1kk0exp + + + + + + ${dbAdapterEndpoint} + + + application/soap+xml + Basic YnBlbDpwYXNzd29yZDEk + + + ${initResourceOperationStatus} + POST + ${statusCode} + ${response} + + http-connector + + + Flow_18cgkru + Flow_0ayd6dj + + + + + + #{execution.getVariable("serviceType") != "CLL"} + + + #{execution.getVariable("serviceType") == "CLL"} + + + #{execution.getVariable("networkType") == "AN"} + + + Flow_0ou7wr9 + Flow_18cgkru + import org.onap.so.bpmn.infrastructure.scripts.* +def nss = new CreateServiceIntentInstance() +nss.prepareInitOperationStatus(execution) + + + + + + + + + + + + + + + + + + + Flow_0g7721r + Flow_189zwjw + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/DeleteServiceIntentInstance.bpmn b/bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/DeleteServiceIntentInstance.bpmn new file mode 100644 index 0000000000..384f9657d3 --- /dev/null +++ b/bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/DeleteServiceIntentInstance.bpmn @@ -0,0 +1,161 @@ + + + + + Flow_143ck2k + + + + Flow_143ck2k + Flow_0pttfuf + import org.onap.so.bpmn.infrastructure.scripts.* +def nss = new DeleteServiceIntentInstance() +nss.preProcessRequest(execution) + + + Flow_1c1j5i1 + Flow_1kljyhj + import org.onap.so.bpmn.infrastructure.scripts.* +def nss = new DeleteServiceIntentInstance() +nss.sendSyncResponse(execution) + + + + + + ${dbAdapterEndpoint} + + + application/soap+xml + Basic YnBlbDpwYXNzd29yZDEk + + + ${initResourceOperationStatus} + POST + ${statusCode} + ${response} + + http-connector + + + Flow_04jsg9s + Flow_1c1j5i1 + + + + + Flow_0pttfuf + Flow_04jsg9s + import org.onap.so.bpmn.infrastructure.scripts.* +def nss = new DeleteServiceIntentInstance() +nss.prepareInitOperationStatus(execution) + + + + Flow_1kljyhj + Flow_0zwyxxc + Flow_0roz1jy + + + + + + + + + + + + + + Flow_0zwyxxc + Flow_1l74oic + + + Flow_1l74oic + Flow_0roz1jy + + + #{execution.getVariable("serviceType") == "CLL"} + + + #{execution.getVariable("serviceType") != "CLL"} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/ModifyServiceIntentInstance.bpmn b/bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/ModifyServiceIntentInstance.bpmn new file mode 100644 index 0000000000..e042c1a552 --- /dev/null +++ b/bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/ModifyServiceIntentInstance.bpmn @@ -0,0 +1,173 @@ + + + + + Flow_1t0w8dn + + + Flow_1t0w8dn + Flow_0fzchbl + import org.onap.so.bpmn.infrastructure.scripts.* +def nss = new ModifyServiceIntentInstance() +nss.preProcessRequest(execution) + + + Flow_1q030ul + Flow_0ps6iyc + import org.onap.so.bpmn.infrastructure.scripts.* +def nss = new ModifyServiceIntentInstance() +nss.sendSyncResponse(execution) + + + Flow_0ps6iyc + Flow_15luvlg + Flow_0usuozn + Flow_1dfyoe6 + + + Flow_1b2k523 + Flow_1dfyoe6 + Flow_15luvlg + + + + + + ${dbAdapterEndpoint} + + + application/soap+xml + Basic YnBlbDpwYXNzd29yZDEk + + + ${initResourceOperationStatus} + POST + ${statusCode} + ${response} + + http-connector + + + Flow_1grhlet + Flow_1q030ul + + + + + + + #{execution.getVariable("networkType") == "TN"} + + + #{execution.getVariable("serviceType") == "CLL"} + + + Flow_0fzchbl + Flow_1grhlet + import org.onap.so.bpmn.infrastructure.scripts.* +def nss = new ModifyServiceIntentInstance() +nss.prepareInitOperationStatus(execution) + + + + + + + + + + + + + + + Flow_0usuozn + Flow_1b2k523 + + + + #{execution.getVariable("serviceType") != "CLL"} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/bpmn/so-bpmn-infrastructure-flows/src/main/resources/subprocess/DoCloudLeasedLineCreate.bpmn b/bpmn/so-bpmn-infrastructure-flows/src/main/resources/subprocess/DoCloudLeasedLineCreate.bpmn new file mode 100644 index 0000000000..96ebce2297 --- /dev/null +++ b/bpmn/so-bpmn-infrastructure-flows/src/main/resources/subprocess/DoCloudLeasedLineCreate.bpmn @@ -0,0 +1,321 @@ + + + + + SequenceFlow_03s744c + + + SequenceFlow_03s744c + SequenceFlow_07e12rt + import org.onap.so.bpmn.infrastructure.scripts.* +def css= new DoCloudLeasedLineCreate() +css.preProcessRequest(execution) + + + + SequenceFlow_1w67v6s + + + + SequenceFlow_08mlzwz + + + SequenceFlow_1w67v6s + SequenceFlow_08mlzwz + import org.onap.so.bpmn.common.scripts.* +ExceptionUtil ex = new ExceptionUtil() +ex.processJavaException(execution) + + + + + + Flow_06rrcwf + + + SequenceFlow_07e12rt + SequenceFlow_0t094g7 + import org.onap.so.bpmn.infrastructure.scripts.* +def runScript = new DoCloudLeasedLineCreate() +runScript.prepareUpdateJobStatus(execution,"INPROGRESS","10","Create Cloud Leased Line started") + + + SequenceFlow_0kixzdj + SequenceFlow_1qv8qw1 + import org.onap.so.bpmn.infrastructure.scripts.* +def runScript = new DoCloudLeasedLineCreate() +runScript.prepareUpdateJobStatus(execution,"FINISHED","100","Created CLL successfully") + + + + + + + + Flow_1865m9a + Flow_15mdc4q + SequenceFlow_0kixzdj + import org.onap.so.bpmn.infrastructure.scripts.* +execution.setVariable("orchestrationStatus", "created") +def runScript = new DoCloudLeasedLineCreate() +runScript.updateAAIOrchStatus(execution) + + + + + + + ${dbAdapterEndpoint} + + + application/soap+xml + Basic YnBlbDpwYXNzd29yZDEk + + + ${updateResourceOperationStatus} + POST + ${statusCode} + ${response} + + http-connector + + + SequenceFlow_0t094g7 + Flow_1k88aak + + + + + + + ${dbAdapterEndpoint} + + + application/soap+xml + Basic YnBlbDpwYXNzd29yZDEk + + + ${updateResourceOperationStatus} + POST + ${statusCode} + ${response} + + http-connector + + + SequenceFlow_1qv8qw1 + Flow_06rrcwf + + + + Flow_1k88aak + Flow_0xqfi6l + import org.onap.so.bpmn.infrastructure.scripts.* +def dcsi = new DoCloudLeasedLineCreate() +dcsi.createServiceInstance(execution) + + + Flow_0xqfi6l + Flow_1wzmy62 + import org.onap.so.bpmn.infrastructure.scripts.* +def dcsi = new DoCloudLeasedLineCreate() +dcsi.createAllottedResource(execution) + + + Flow_1wzmy62 + Flow_08u0q5g + Flow_15mdc4q + + + Flow_08u0q5g + Flow_1xqkjy9 + import org.onap.so.bpmn.infrastructure.scripts.* +def dcsi = new DoCloudLeasedLineCreate() +dcsi.preprocessSdncCreateCllRequest(execution) + + + + + + + + + + + + Flow_1xqkjy9 + Flow_0vvbiux + + + Flow_0vvbiux + Flow_1865m9a + import org.onap.so.bpmn.infrastructure.scripts.* + +String response = execution.getVariable("CLL_SDNCAdapterResponse") + +def dcsi = new DoCloudLeasedLineCreate() +dcsi.validateSDNCResponse(execution, response, "allocate") + + + + + + + #{(execution.getVariable("enableSdnc" ) == true)} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/bpmn/so-bpmn-infrastructure-flows/src/main/resources/subprocess/DoCloudLeasedLineDelete.bpmn b/bpmn/so-bpmn-infrastructure-flows/src/main/resources/subprocess/DoCloudLeasedLineDelete.bpmn new file mode 100644 index 0000000000..4f84317945 --- /dev/null +++ b/bpmn/so-bpmn-infrastructure-flows/src/main/resources/subprocess/DoCloudLeasedLineDelete.bpmn @@ -0,0 +1,235 @@ + + + + + SequenceFlow_03s744c + + + + SequenceFlow_1w67v6s + + + + SequenceFlow_08mlzwz + + + SequenceFlow_1w67v6s + SequenceFlow_08mlzwz + import org.onap.so.bpmn.common.scripts.* +ExceptionUtil ex = new ExceptionUtil() +ex.processJavaException(execution) + + + + + + Flow_0ca4l8d + + + SequenceFlow_1jygjln + SequenceFlow_1qv8qw1 + import org.onap.so.bpmn.infrastructure.scripts.* +def runScript = new DoCloudLeasedLineDelete() +runScript.prepareUpdateJobStatus(execution,"FINISHED","100","Deleted CLL successfully") + + + + + Flow_0sj0mtu + Flow_0cpctye + import org.onap.so.bpmn.infrastructure.scripts.* +def runScript = new DoCloudLeasedLineDelete() +runScript.preprocessSdncDeleteCllRequest(execution) + + + + + + + + + + + + + Flow_0cpctye + Flow_0fuabjs + + + + Flow_0fuabjs + SequenceFlow_1jdb2oq + import org.onap.so.bpmn.infrastructure.scripts.* + +String response = execution.getVariable("CLL_SDNCAdapterResponse") + +def runScript = new DoCloudLeasedLineDelete() +runScript.validateSDNCResponse(execution, response, "deallocate") + + + SequenceFlow_1jdb2oq + Flow_0dirb5b + SequenceFlow_1jygjln + import org.onap.so.bpmn.infrastructure.scripts.* +def runScript = new DoCloudLeasedLineDelete() +runScript.deleteServiceInstance(execution) + + + + SequenceFlow_03s744c + SequenceFlow_07e12rt + import org.onap.so.bpmn.infrastructure.scripts.* +def runScript = new DoCloudLeasedLineDelete() +runScript.preProcessRequest(execution) + + + + + + + + ${dbAdapterEndpoint} + + + application/soap+xml + Basic YnBlbDpwYXNzd29yZDEk + + + ${updateResourceOperationStatus} + POST + ${statusCode} + ${response} + + http-connector + + + SequenceFlow_1qv8qw1 + Flow_0ca4l8d + + + + SequenceFlow_07e12rt + Flow_0sj0mtu + Flow_0dirb5b + + + #{(execution.getVariable("enableSdnc" ) == true)} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/bpmn/so-bpmn-infrastructure-flows/src/main/resources/subprocess/DoCloudLeasedLineModify.bpmn b/bpmn/so-bpmn-infrastructure-flows/src/main/resources/subprocess/DoCloudLeasedLineModify.bpmn new file mode 100644 index 0000000000..1c2ce98f09 --- /dev/null +++ b/bpmn/so-bpmn-infrastructure-flows/src/main/resources/subprocess/DoCloudLeasedLineModify.bpmn @@ -0,0 +1,252 @@ + + + + + SequenceFlow_03s744c + + + + SequenceFlow_1w67v6s + + + + SequenceFlow_08mlzwz + + + SequenceFlow_1w67v6s + SequenceFlow_08mlzwz + import org.onap.so.bpmn.common.scripts.* +ExceptionUtil ex = new ExceptionUtil() +ex.processJavaException(execution) + + + + + + Flow_1akxvak + + + SequenceFlow_0kixzdj + SequenceFlow_1qv8qw1 + import org.onap.so.bpmn.infrastructure.scripts.* +def runScript = new DoCloudLeasedLineModify() +runScript.prepareUpdateJobStatus(execution,"FINISHED","100","Modified CLL successfully") + + + + + Flow_0h5rwlh + Flow_0b3rxne + SequenceFlow_0kixzdj + import org.onap.so.bpmn.infrastructure.scripts.* +execution.setVariable("orchestrationStatus", "modified") +def runScript = new DoCloudLeasedLineModify() +runScript.updateAAIOrchStatus(execution) + + + + SequenceFlow_07e12rt + SequenceFlow_1jdb2oq + import org.onap.so.bpmn.infrastructure.scripts.* + +def runScript = new DoCloudLeasedLineModify() +runScript.updateServiceInstanceInAAI(execution) + + + + SequenceFlow_03s744c + SequenceFlow_07e12rt + import org.onap.so.bpmn.infrastructure.scripts.* +def runScript = new DoCloudLeasedLineModify() +runScript.preProcessRequest(execution) + + + + Flow_0cm9i4m + Flow_1dvo5ih + import org.onap.so.bpmn.infrastructure.scripts.* +def runScript = new DoCloudLeasedLineModify() +runScript.preprocessSdncModifyCllRequest(execution) + + + + + + + + + + + + + Flow_1dvo5ih + Flow_139j3yd + + + + Flow_139j3yd + Flow_0h5rwlh + import org.onap.so.bpmn.infrastructure.scripts.* + +String response = execution.getVariable("CLL_SDNCAdapterResponse") + +def runScript = new DoCloudLeasedLineModify() +runScript.validateSDNCResponse(execution, response, "modify") + + + + + + + ${dbAdapterEndpoint} + + + application/soap+xml + Basic YnBlbDpwYXNzd29yZDEk + + + ${updateResourceOperationStatus} + POST + ${statusCode} + ${response} + + http-connector + + + SequenceFlow_1qv8qw1 + Flow_1akxvak + + + + SequenceFlow_1jdb2oq + Flow_0cm9i4m + Flow_0b3rxne + + + #{(execution.getVariable("enableSdnc" ) == true)} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/JerseyConfiguration.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/JerseyConfiguration.java index d69c395f96..031e9eee2a 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/JerseyConfiguration.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/JerseyConfiguration.java @@ -65,6 +65,7 @@ public class JerseyConfiguration extends ResourceConfig { register(NodeHealthcheckHandler.class); register(ServiceInstances.class); register(Onap3gppServiceInstances.class); + register(ServiceIntentApiHandler.class); register(TasksHandler.class); register(CloudOrchestration.class); register(CloudResourcesOrchestration.class); diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ServiceIntentApiHandler.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ServiceIntentApiHandler.java new file mode 100644 index 0000000000..be63c5fb9a --- /dev/null +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ServiceIntentApiHandler.java @@ -0,0 +1,431 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2021 Huawei Technologies. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.apihandlerinfra; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import io.swagger.v3.oas.annotations.OpenAPIDefinition; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.info.Info; +import io.swagger.v3.oas.annotations.media.ArraySchema; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import org.apache.http.HttpStatus; +import org.onap.logging.filter.base.ErrorCode; +import org.onap.so.apihandler.camundabeans.CamundaResponse; +import org.onap.so.apihandler.common.CamundaClient; +import org.onap.so.apihandler.common.ErrorNumbers; +import org.onap.so.apihandler.common.RequestClientParameter; +import org.onap.so.apihandler.common.ResponseBuilder; +import org.onap.so.apihandler.common.ResponseHandler; +import org.onap.so.apihandlerinfra.exceptions.ApiException; +import org.onap.so.apihandlerinfra.exceptions.BPMNFailureException; +import org.onap.so.apihandlerinfra.exceptions.RequestDbFailureException; +import org.onap.so.apihandlerinfra.exceptions.ValidateException; +import org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo; +import org.onap.so.apihandlerinfra.serviceintentinstancebeans.ServiceIntentCommonRequest; +import org.onap.so.apihandlerinfra.serviceintentinstancebeans.ServiceIntentCreationRequest; +import org.onap.so.apihandlerinfra.serviceintentinstancebeans.ServiceIntentDeletionRequest; +import org.onap.so.apihandlerinfra.serviceintentinstancebeans.ServiceIntentModificationRequest; +import org.onap.so.constants.Status; +import org.onap.so.db.catalog.beans.Service; +import org.onap.so.db.catalog.beans.ServiceRecipe; +import org.onap.so.db.catalog.client.CatalogDbClient; +import org.onap.so.db.request.beans.InfraActiveRequests; +import org.onap.so.db.request.client.RequestsDbClient; +import org.onap.so.logger.LogConstants; +import org.onap.so.logger.LoggingAnchor; +import org.onap.so.logger.MessageEnum; +import org.onap.so.serviceinstancebeans.ModelType; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.slf4j.MDC; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Component; +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.container.ContainerRequestContext; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import java.sql.Timestamp; +import java.util.HashMap; +import java.util.function.Function; + +/** + * This class serves as the entry point for Service Intent APIs. Unlike User Intent, which describes Intent using + * natural languages, Service Intent describes Intent through technology-agnostic and model-driven APIs. The Service + * Intent APIs have the following format: {service-Intent-Root}/{operation}, where {operation} may be "create", + * "delete", "modify", etc. And the parameters of the Intent service instance are specified in the payloads of the APIs. + *

+ * For scalability, these APIs are designed to be generic, and thus support all the service Intent use-cases. i.e., The + * actual intent use-case/application, e.g., Cloud Leased Line, is differentiated by the "serviceType" parameter in the + * payload, rather than by specific APIs. Thus, this class does not need to grow when we add new Intent use-cases or + * applications. + *

+ */ +@Component +@Path("/onap/so/infra/serviceIntent") +@OpenAPIDefinition(info = @Info(title = "/onap/so/infra/serviceIntent", + description = "API Requests for Intent services and " + "applications")) +public class ServiceIntentApiHandler { + + private static final Logger logger = LoggerFactory.getLogger(ServiceIntentApiHandler.class); + + private static final String MSO_PROP_APIHANDLER_INFRA = "MSO_PROP_APIHANDLER_INFRA"; + + private static final String END_OF_THE_TRANSACTION = "End of the transaction, the final response is: "; + + private static final String SAVE_TO_DB = "save instance to db"; + + private static final String URI_PREFIX = "/serviceIntent/"; + + @Autowired + private MsoRequest msoRequest; + + @Autowired + private CatalogDbClient catalogDbClient; + + @Autowired + private RequestsDbClient requestsDbClient; + + @Autowired + private RequestHandlerUtils requestHandlerUtils; + + @Autowired + private ResponseBuilder builder; + + @Autowired + private CamundaClient camundaClient; + + @Autowired + private ResponseHandler responseHandler; + + // @Value("${serviceIntent.config.file}") + // private String serviceIntentConfigFile; + + /** + * POST Requests for create Service Intent Instance on a version provided + * + * @throws ApiException + */ + + @POST + @Path("/{version:[vV][1]}/create") + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + @Operation(description = "Create a SI Instance on a version provided", responses = @ApiResponse( + content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class))))) + public Response createServiceIntentInstance(ServiceIntentCreationRequest request, + @PathParam("version") String version, @Context ContainerRequestContext requestContext) throws ApiException { + String requestId = requestHandlerUtils.getRequestId(requestContext); + return processServiceIntentRequest(request, Action.createInstance, version, requestId, null, + requestHandlerUtils.getRequestUri(requestContext, URI_PREFIX)); + } + + /** + * PUT Requests for Service Intent Modification on a version provided + * + * @throws ApiException + */ + + @PUT + @Path("/{version:[vV][1]}/modify") + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + @Operation(description = "Modify a SI Instance on a version provided", responses = @ApiResponse( + content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class))))) + public Response modifyServiceIntentInstance(ServiceIntentModificationRequest request, + @PathParam("version") String version, @Context ContainerRequestContext requestContext) throws ApiException { + String requestId = requestHandlerUtils.getRequestId(requestContext); + HashMap instanceIdMap = new HashMap<>(); + instanceIdMap.put("serviceInstanceId", request.getServiceInstanceID()); + return processServiceIntentRequest(request, Action.updateInstance, version, requestId, instanceIdMap, + requestHandlerUtils.getRequestUri(requestContext, URI_PREFIX)); + } + + /** + * DELETE Requests for Service Intent Instance on a specified version + * + * @throws ApiException + */ + + @DELETE + @Path("/{version:[vV][1]}/delete") + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + @Operation(description = "Terminate/Delete a SI Service Instance on a version provided", responses = @ApiResponse( + content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class))))) + public Response deleteServiceIntentInstance(ServiceIntentDeletionRequest request, + @PathParam("version") String version, @Context ContainerRequestContext requestContext) throws ApiException { + String requestId = requestHandlerUtils.getRequestId(requestContext); + HashMap instanceIdMap = new HashMap<>(); + instanceIdMap.put("serviceInstanceId", request.getServiceInstanceID()); + return processServiceIntentRequest(request, Action.deleteInstance, version, requestId, instanceIdMap, + requestHandlerUtils.getRequestUri(requestContext, URI_PREFIX)); + } + + /** + * Process Service Intent request and send request to corresponding workflow + * + * @param request + * @param action + * @param version + * @return + * @throws ApiException + */ + private Response processServiceIntentRequest(ServiceIntentCommonRequest request, Action action, String version, + String requestId, HashMap instanceIdMap, String requestUri) throws ApiException { + String defaultServiceModelName = "COMMON_SI_DEFAULT"; + String requestScope = ModelType.service.name(); + String apiVersion = version.substring(1); + String serviceRequestJson = toString.apply(request); + + String instanceName = null; + String modelUuid = null; + String serviceInstanceId = null; + + try { + if (action == Action.createInstance) { + instanceName = ((ServiceIntentCreationRequest) request).getName(); + modelUuid = ((ServiceIntentCreationRequest) request).getModelUuid(); + } else if (action == Action.updateInstance) { + instanceName = ((ServiceIntentModificationRequest) request).getName(); + serviceInstanceId = ((ServiceIntentModificationRequest) request).getServiceInstanceID(); + } else if (action == Action.deleteInstance) { + serviceInstanceId = ((ServiceIntentDeletionRequest) request).getServiceInstanceID(); + } + } catch (Exception e) { + logger.error("ERROR: processCllServiceRequest: Exception: ", e); + Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_INTERNAL_SERVER_ERROR, + MsoException.ServiceException, "processCllServiceRequest error", ErrorNumbers.SVC_BAD_PARAMETER, + null, version); + return response; + } + + if (serviceRequestJson != null) { + InfraActiveRequests currentActiveReq = createRequestObject(request, action, requestId, Status.IN_PROGRESS, + requestScope, serviceRequestJson); + + requestHandlerUtils.checkForDuplicateRequests(action, instanceIdMap, requestScope, currentActiveReq, + instanceName); + try { + requestsDbClient.save(currentActiveReq); + } catch (Exception e) { + logger.error("Exception occurred", e); + ErrorLoggerInfo errorLoggerInfo = + new ErrorLoggerInfo.Builder(MessageEnum.APIH_DB_ACCESS_EXC, ErrorCode.DataError) + .errorSource(Constants.MSO_PROP_APIHANDLER_INFRA).build(); + throw new RequestDbFailureException.Builder(SAVE_TO_DB, e.toString(), + HttpStatus.SC_INTERNAL_SERVER_ERROR, ErrorNumbers.SVC_DETAILED_SERVICE_ERROR).cause(e) + .errorInfo(errorLoggerInfo).build(); + } + + RecipeLookupResult recipeLookupResult; + try { + recipeLookupResult = getServiceInstanceOrchestrationURI(modelUuid, action, defaultServiceModelName); + } catch (Exception e) { + logger.error(LoggingAnchor.FOUR, MessageEnum.APIH_DB_ACCESS_EXC.toString(), MSO_PROP_APIHANDLER_INFRA, + ErrorCode.AvailabilityError.getValue(), "Exception while communicate with Catalog DB", e); + Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_NOT_FOUND, + MsoException.ServiceException, "No " + "communication to catalog DB " + e.getMessage(), + ErrorNumbers.SVC_NO_SERVER_RESOURCES, null, version); + logger.debug(END_OF_THE_TRANSACTION + response.getEntity()); + return response; + } + + if (recipeLookupResult == null) { + logger.error(LoggingAnchor.FOUR, MessageEnum.APIH_DB_ATTRIBUTE_NOT_FOUND.toString(), + MSO_PROP_APIHANDLER_INFRA, ErrorCode.DataError.getValue(), "No recipe found in DB"); + Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_NOT_FOUND, + MsoException.ServiceException, "Recipe does " + "not exist in catalog DB", + ErrorNumbers.SVC_GENERAL_SERVICE_ERROR, null, version); + logger.debug(END_OF_THE_TRANSACTION + response.getEntity()); + return response; + } + + String serviceInstanceType = request.getSubscriptionServiceType(); + RequestClientParameter parameter; + try { + parameter = new RequestClientParameter.Builder().setRequestId(requestId).setBaseVfModule(false) + .setRecipeTimeout(recipeLookupResult.getRecipeTimeout()).setRequestAction(action.name()) + .setServiceInstanceId(serviceInstanceId).setServiceType(serviceInstanceType) + .setRequestDetails(serviceRequestJson).setApiVersion(version).setALaCarte(false) + .setRecipeParamXsd(recipeLookupResult.getRecipeParamXsd()).setApiVersion(apiVersion).build(); + } catch (Exception e) { + logger.error("Exception occurred", e); + ErrorLoggerInfo errorLoggerInfo = + new ErrorLoggerInfo.Builder(MessageEnum.APIH_BPEL_RESPONSE_ERROR, ErrorCode.SchemaError) + .errorSource(Constants.MSO_PROP_APIHANDLER_INFRA).build(); + throw new ValidateException.Builder("Unable to generate RequestClientParameter object" + e.getMessage(), + HttpStatus.SC_INTERNAL_SERVER_ERROR, ErrorNumbers.SVC_BAD_PARAMETER).errorInfo(errorLoggerInfo) + .build(); + } + return postBPELRequest(currentActiveReq, parameter, recipeLookupResult.getOrchestrationURI(), requestScope); + } else { + Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_INTERNAL_SERVER_ERROR, + MsoException.ServiceException, "JsonProcessingException occurred - " + "serviceRequestJson is null", + ErrorNumbers.SVC_BAD_PARAMETER, null, version); + return response; + } + } + + /** + * Getting recipes from catalogDb + * + * @param serviceModelUUID the service model version uuid + * @param action the action for the service + * @param defaultServiceModelName default service name + * @return the service recipe result + */ + private RecipeLookupResult getServiceInstanceOrchestrationURI(String serviceModelUUID, Action action, + String defaultServiceModelName) { + + RecipeLookupResult recipeLookupResult = getServiceURI(serviceModelUUID, action, defaultServiceModelName); + + if (recipeLookupResult != null) { + logger.debug("Orchestration URI is: " + recipeLookupResult.getOrchestrationURI() + ", recipe Timeout is: " + + Integer.toString(recipeLookupResult.getRecipeTimeout())); + } else { + logger.debug("No matching recipe record found"); + } + return recipeLookupResult; + } + + /** + * Getting recipes from catalogDb If Service recipe is not set, use default recipe, if set , use special recipe. + * + * @param serviceModelUUID the service version uuid + * @param action the action of the service. + * @param defaultServiceModelName default service name + * @return the service recipe result. + */ + private RecipeLookupResult getServiceURI(String serviceModelUUID, Action action, String defaultServiceModelName) { + + Service defaultServiceRecord = + catalogDbClient.getFirstByModelNameOrderByModelVersionDesc(defaultServiceModelName); + // set recipe as default generic recipe + ServiceRecipe recipe = + catalogDbClient.getFirstByServiceModelUUIDAndAction(defaultServiceRecord.getModelUUID(), action.name()); + // check the service special recipe + if (null != serviceModelUUID && !serviceModelUUID.isEmpty()) { + ServiceRecipe serviceSpecialRecipe = + catalogDbClient.getFirstByServiceModelUUIDAndAction(serviceModelUUID, action.name()); + if (null != serviceSpecialRecipe) { + // set service special recipe. + recipe = serviceSpecialRecipe; + } + } + + if (recipe == null) { + return null; + } + return new RecipeLookupResult(recipe.getOrchestrationUri(), recipe.getRecipeTimeout(), recipe.getParamXsd()); + + } + + Function toString = serviceRequest -> { + ObjectMapper mapper = new ObjectMapper(); + String requestAsString = null; + try { + requestAsString = mapper.writeValueAsString(serviceRequest); + } catch (JsonProcessingException e) { + logger.debug("Exception while converting service request object to String {}", e); + } + return requestAsString; + }; + + private InfraActiveRequests createRequestObject(ServiceIntentCommonRequest request, Action action, String requestId, + Status status, String requestScope, String requestJson) { + InfraActiveRequests aq = new InfraActiveRequests(); + try { + String serviceInstanceName = null; + String serviceInstanceId = null; + String serviceType = request.getServiceType(); + if (action.name().equals("createInstance")) { + serviceInstanceName = ((ServiceIntentCreationRequest) request).getName(); + aq.setServiceInstanceName(serviceInstanceName); + } else if (action.name().equals("updateInstance")) { + serviceInstanceName = ((ServiceIntentModificationRequest) request).getName(); + serviceInstanceId = ((ServiceIntentModificationRequest) request).getServiceInstanceID(); + aq.setServiceInstanceName(serviceInstanceName); + aq.setServiceInstanceId(serviceInstanceId); + } else if (action.name().equals("deleteInstance")) { + serviceInstanceId = ((ServiceIntentDeletionRequest) request).getServiceInstanceID(); + aq.setServiceInstanceId(serviceInstanceId); + } + + aq.setRequestId(requestId); + aq.setRequestAction(action.toString()); + aq.setRequestUrl(MDC.get(LogConstants.HTTP_URL)); + Timestamp startTimeStamp = new Timestamp(System.currentTimeMillis()); + aq.setStartTime(startTimeStamp); + aq.setRequestScope(requestScope); + aq.setRequestBody(requestJson); + aq.setRequestStatus(status.toString()); + aq.setLastModifiedBy(Constants.MODIFIED_BY_APIHANDLER); + aq.setServiceType(serviceType); + } catch (Exception e) { + logger.error("Exception when creation record request", e); + + if (!status.equals(Status.FAILED)) { + throw e; + } + } + return aq; + } + + private Response postBPELRequest(InfraActiveRequests currentActiveReq, RequestClientParameter parameter, + String orchestrationURI, String requestScope) throws ApiException { + ResponseEntity response = + requestHandlerUtils.postRequest(currentActiveReq, parameter, orchestrationURI); + logger.debug("BPEL response : " + response); + int bpelStatus = responseHandler.setStatus(response.getStatusCodeValue()); + String jsonResponse; + try { + responseHandler.acceptedResponse(response); + CamundaResponse camundaResponse = responseHandler.getCamundaResponse(response); + String responseBody = camundaResponse.getResponse(); + if ("Success".equalsIgnoreCase(camundaResponse.getMessage())) { + jsonResponse = responseBody; + } else { + BPMNFailureException bpmnException = + new BPMNFailureException.Builder(String.valueOf(bpelStatus) + responseBody, bpelStatus, + ErrorNumbers.SVC_DETAILED_SERVICE_ERROR).build(); + requestHandlerUtils.updateStatus(currentActiveReq, Status.FAILED, bpmnException.getMessage()); + throw bpmnException; + } + } catch (ApiException e) { + requestHandlerUtils.updateStatus(currentActiveReq, Status.FAILED, e.getMessage()); + throw e; + } + return builder.buildResponse(HttpStatus.SC_ACCEPTED, parameter.getRequestId(), jsonResponse, + parameter.getApiVersion()); + } +} diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/serviceintentinstancebeans/ServiceIntentCommonRequest.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/serviceintentinstancebeans/ServiceIntentCommonRequest.java new file mode 100644 index 0000000000..f27f88c428 --- /dev/null +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/serviceintentinstancebeans/ServiceIntentCommonRequest.java @@ -0,0 +1,83 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2020 Huawei Technologies. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.apihandlerinfra.serviceintentinstancebeans; + +import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.HashMap; +import java.util.Map; + +/** + * Model class for common parameter of Service Intent request + */ +public class ServiceIntentCommonRequest { + + @JsonProperty("globalSubscriberId") + private String globalSubscriberId; + + @JsonProperty("subscriptionServiceType") + private String subscriptionServiceType; + + @JsonProperty("additionalProperties") + private Map additionalProperties = new HashMap<>(); + + @JsonProperty("serviceType") + private String serviceType; + + public String getGlobalSubscriberId() { + return globalSubscriberId; + } + + public void setGlobalSubscriberId(String globalSubscriberId) { + this.globalSubscriberId = globalSubscriberId; + } + + public String getSubscriptionServiceType() { + return subscriptionServiceType; + } + + public void setSubscriptionServiceType(String subscriptionServiceType) { + this.subscriptionServiceType = subscriptionServiceType; + } + + public Map getAdditionalProperties() { + return additionalProperties; + } + + public void setAdditionalProperties(Map additionalProperties) { + this.additionalProperties = additionalProperties; + } + + public String getServiceType() { + return serviceType; + } + + public void setServiceType(String serviceType) { + this.serviceType = serviceType; + } + + @Override + public String toString() { + return "ServiceIntentCommonRequest [globalSubscriberId=" + globalSubscriberId + ", subscriptionServiceType=" + + subscriptionServiceType + ", serviceType=" + serviceType + ", additionalProperties=" + + additionalProperties + "]"; + } + +} diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/serviceintentinstancebeans/ServiceIntentCreationRequest.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/serviceintentinstancebeans/ServiceIntentCreationRequest.java new file mode 100644 index 0000000000..bc711a00dc --- /dev/null +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/serviceintentinstancebeans/ServiceIntentCreationRequest.java @@ -0,0 +1,82 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2020 Huawei Technologies. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.apihandlerinfra.serviceintentinstancebeans; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Model class for Service Intent Creation request + */ +public class ServiceIntentCreationRequest extends ServiceIntentCommonRequest { + + @JsonProperty("name") + private String name; + + @JsonProperty("modelInvariantUuid") + private String modelInvariantUuid; + + @JsonProperty("modelUuid") + private String modelUuid; + + @JsonProperty("sst") + private String sST; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getModelInvariantUuid() { + return modelInvariantUuid; + } + + public void setModelInvariantUuid(String modelInvariantUuid) { + this.modelInvariantUuid = modelInvariantUuid; + } + + public String getModelUuid() { + return modelUuid; + } + + public void setModelUuid(String modelUuid) { + this.modelUuid = modelUuid; + } + + public String getsST() { + return sST; + } + + public void setsST(String sST) { + this.sST = sST; + } + + @Override + public String toString() { + return "ServiceIntentCreationRequest [name=" + name + ", modelInvariantUuid=" + modelInvariantUuid + + ", modelUuid=" + modelUuid + ", globalSubscriberId=" + getGlobalSubscriberId() + + ", subscriptionServiceType=" + getSubscriptionServiceType() + ", serviceType=" + getServiceType() + + ", additionalProperties=" + getAdditionalProperties() + "]"; + } + +} diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/serviceintentinstancebeans/ServiceIntentDeletionRequest.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/serviceintentinstancebeans/ServiceIntentDeletionRequest.java new file mode 100644 index 0000000000..c463c7bae4 --- /dev/null +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/serviceintentinstancebeans/ServiceIntentDeletionRequest.java @@ -0,0 +1,48 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2020 Huawei Technologies. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.apihandlerinfra.serviceintentinstancebeans; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Model class for service intent instance terminate request + */ +public class ServiceIntentDeletionRequest extends ServiceIntentCommonRequest { + + @JsonProperty("serviceInstanceID") + private String serviceInstanceID; + + public String getServiceInstanceID() { + return serviceInstanceID; + } + + public void setServiceInstanceID(String serviceInstanceID) { + this.serviceInstanceID = serviceInstanceID; + } + + @Override + public String toString() { + return "ServiceIntentDeletionRequest [serviceInstanceID=" + getServiceInstanceID() + ", globalSubscriberId=" + + getGlobalSubscriberId() + ", subscriptionServiceType=" + getSubscriptionServiceType() + + ", serviceType=" + getServiceType() + ", additionalProperties=" + getAdditionalProperties() + "]"; + } + +} diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/serviceintentinstancebeans/ServiceIntentModificationRequest.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/serviceintentinstancebeans/ServiceIntentModificationRequest.java new file mode 100644 index 0000000000..17d6dc84ab --- /dev/null +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/serviceintentinstancebeans/ServiceIntentModificationRequest.java @@ -0,0 +1,60 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2021 Huawei Technologies. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.apihandlerinfra.serviceintentinstancebeans; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Model class for Service Intent Update request + */ +public class ServiceIntentModificationRequest extends ServiceIntentCommonRequest { + + @JsonProperty("name") + private String name; + + @JsonProperty("serviceInstanceID") + private String serviceInstanceID; + + public String getServiceInstanceID() { + return serviceInstanceID; + } + + public void setServiceInstanceID(String serviceInstanceID) { + this.serviceInstanceID = serviceInstanceID; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + @Override + public String toString() { + return "ServiceIntentModificationRequest [name=" + name + ", serviceInstanceID=" + getServiceInstanceID() + + ", globalSubscriberId=" + getGlobalSubscriberId() + ", subscriptionServiceType=" + + getSubscriptionServiceType() + ", serviceType=" + getServiceType() + ", additionalProperties=" + + getAdditionalProperties() + "]"; + } + +} diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/ServiceIntentApiHandlerTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/ServiceIntentApiHandlerTest.java new file mode 100644 index 0000000000..059c2bc057 --- /dev/null +++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/ServiceIntentApiHandlerTest.java @@ -0,0 +1,156 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.apihandlerinfra; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.apache.http.HttpStatus; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; +import org.onap.logging.ref.slf4j.ONAPLogConstants; +import org.onap.so.db.catalog.beans.Service; +import org.onap.so.db.catalog.beans.ServiceRecipe; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.ResponseEntity; +import org.springframework.web.util.UriComponentsBuilder; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; +import static com.github.tomakehurst.wiremock.client.WireMock.get; +import static com.github.tomakehurst.wiremock.client.WireMock.post; +import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching; +import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; +import static org.junit.Assert.assertEquals; +import static org.onap.logging.filter.base.Constants.HttpHeaders.ONAP_PARTNER_NAME; +import static org.onap.logging.filter.base.Constants.HttpHeaders.ONAP_REQUEST_ID; +import static org.onap.logging.filter.base.Constants.HttpHeaders.TRANSACTION_ID; +import static org.onap.so.logger.HttpHeadersConstants.REQUESTOR_ID; + +public class ServiceIntentApiHandlerTest extends BaseTest { + + private static final String ROOT_URI = "/onap/so/infra/serviceIntent/"; + + private static final ObjectMapper MAPPER = new ObjectMapper(); + + @Autowired + private Onap3gppServiceInstances objUnderTest; + + @Before + public void init() throws JsonProcessingException { + + Service defaultService = new Service(); + defaultService.setModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a"); + ServiceRecipe serviceRecipe = new ServiceRecipe(); + serviceRecipe.setServiceModelUUID(defaultService.getModelUUID()); + serviceRecipe.setRecipeTimeout(180); + serviceRecipe.setOrchestrationUri("/mso/async/services/commonServiceIntentTest"); + + wireMockServer.stubFor(get(urlPathEqualTo("/service/search/findFirstByModelNameOrderByModelVersionDesc")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(MAPPER.writeValueAsString(defaultService)).withStatus(HttpStatus.SC_OK))); + + wireMockServer.stubFor(get(urlPathEqualTo("/serviceRecipe/search/findFirstByServiceModelUUIDAndAction")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(MAPPER.writeValueAsString(serviceRecipe)).withStatus(HttpStatus.SC_OK))); + wireMockServer.stubFor(post(urlMatching(".*/infraActiveRequests/")).willReturn(aResponse() + .withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).withStatus(HttpStatus.SC_OK))); + Mockito.doReturn(null).when(requestsDbClient).getInfraActiveRequestbyRequestId(Mockito.any()); + } + + public String inputStream(String JsonInput) throws IOException { + JsonInput = "src/test/resources/ServiceIntentTest" + JsonInput; + return new String(Files.readAllBytes(Paths.get(JsonInput))); + } + + public ResponseEntity sendRequest(String requestJson, String uriPath, HttpMethod reqMethod) { + HttpHeaders headers = new HttpHeaders(); + headers.set("Accept", MediaType.APPLICATION_JSON); + headers.set("Content-Type", MediaType.APPLICATION_JSON); + headers.set(ONAPLogConstants.Headers.PARTNER_NAME, "test_name"); + headers.set(TRANSACTION_ID, "32807a28-1a14-4b88-b7b3-2950918aa76d"); + headers.set(ONAP_REQUEST_ID, "32807a28-1a14-4b88-b7b3-2950918aa76d"); + headers.set(ONAPLogConstants.MDCs.REQUEST_ID, "32807a28-1a14-4b88-b7b3-2950918aa76d"); + headers.set(ONAP_PARTNER_NAME, "VID"); + headers.set(REQUESTOR_ID, "xxxxxx"); + UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(createURLWithPort(uriPath)); + HttpEntity request = new HttpEntity<>(requestJson, headers); + + return restTemplate.exchange(builder.toUriString(), reqMethod, request, String.class); + } + + @Test + public void createServiceInstanceTest() throws IOException { + String uri = ROOT_URI + "v1/create"; + wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/commonServiceIntentTest")) + .willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBodyFile("Camunda/BPMN_response.json").withStatus(HttpStatus.SC_ACCEPTED))); + + String expectedResponse = + "{\"jobId\":\"db245365e79c47ed88fcd60caa8f6549\",\"status\":\"\",\"statusDescription\":{}}"; + ResponseEntity response = sendRequest(inputStream("/create-cll-payload.json"), uri, HttpMethod.POST); + + assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value()); + String actualResponse = response.getBody(); + assertEquals(expectedResponse, actualResponse); + } + + @Test + public void updateServiceInstanceTest() throws IOException { + String uri = ROOT_URI + "v1/modify"; + wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/commonServiceIntentTest")) + .willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBodyFile("Camunda/BPMN_response.json").withStatus(HttpStatus.SC_ACCEPTED))); + + String expectedResponse = + "{\"jobId\":\"db245365e79c47ed88fcd60caa8f6549\",\"status\":\"\",\"statusDescription\":{}}"; + ResponseEntity response = sendRequest(inputStream("/modify-cll-payload.json"), uri, HttpMethod.PUT); + + assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value()); + String actualResponse = response.getBody(); + assertEquals(expectedResponse, actualResponse); + } + + @Test + public void deleteServiceInstanceTest() throws IOException { + String uri = ROOT_URI + "v1/delete"; + wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/commonServiceIntentTest")) + .willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBodyFile("Camunda/BPMN_response.json").withStatus(HttpStatus.SC_ACCEPTED))); + String expectedResponse = + "{\"jobId\":\"db245365e79c47ed88fcd60caa8f6549\",\"status\":\"\",\"statusDescription\":{}}"; + ResponseEntity response = sendRequest(inputStream("/delete-cll-payload.json"), uri, HttpMethod.DELETE); + + assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value()); + String actualResponse = response.getBody(); + assertEquals(expectedResponse, actualResponse); + } + + +} + + diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/resources/ServiceIntentTest/create-cll-payload.json b/mso-api-handlers/mso-api-handler-infra/src/test/resources/ServiceIntentTest/create-cll-payload.json new file mode 100644 index 0000000000..6018392abd --- /dev/null +++ b/mso-api-handlers/mso-api-handler-infra/src/test/resources/ServiceIntentTest/create-cll-payload.json @@ -0,0 +1,29 @@ +{ + "name": "cloud-leased-line-101", + "modelInvariantUuid": "6790ab0e-034f-11eb-adc1-0242ac120002", + "modelUuid": "6790ab0e-034f-11eb-adc1-0242ac120002", + "globalSubscriberId": "IBNCustomer", + "subscriptionServiceType": "IBN", + "serviceType": "CLL", + "additionalProperties": { + "enableSdnc": "false", + "serviceInstanceID": "cll-101", + "transportNetworks": [ + { + "id": "cll-101-network-001", + "sla": { + "latency": 2, + "maxBandwidth": 3000 + }, + "connectionLinks": [ + { + "name": "cll-link-1", + "transportEndpointA": "tranportEp_UNI_ID_311_1", + "transportEndpointB": "tranportEp_ROOT_ID_512_1" + } + ] + } + ] + } +} + diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/resources/ServiceIntentTest/delete-cll-payload.json b/mso-api-handlers/mso-api-handler-infra/src/test/resources/ServiceIntentTest/delete-cll-payload.json new file mode 100644 index 0000000000..f21f4e3cea --- /dev/null +++ b/mso-api-handlers/mso-api-handler-infra/src/test/resources/ServiceIntentTest/delete-cll-payload.json @@ -0,0 +1,9 @@ +{ + "serviceInstanceID": "cll-101", + "globalSubscriberId": "IBNCustomer", + "subscriptionServiceType": "IBN", + "serviceType": "CLL", + "additionalProperties": { + "enableSdnc": "false" + } +} diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/resources/ServiceIntentTest/modify-cll-payload.json b/mso-api-handlers/mso-api-handler-infra/src/test/resources/ServiceIntentTest/modify-cll-payload.json new file mode 100644 index 0000000000..3611adaf3b --- /dev/null +++ b/mso-api-handlers/mso-api-handler-infra/src/test/resources/ServiceIntentTest/modify-cll-payload.json @@ -0,0 +1,29 @@ +{ + "serviceInstanceID": "cll-101", + "name": "cloud-leased-line-101", + "modelInvariantUuid": "6790ab0e-034f-11eb-adc1-0242ac120002", + "modelUuid": "6790ab0e-034f-11eb-adc1-0242ac120002", + "globalSubscriberId": "IBNCustomer", + "subscriptionServiceType": "IBN", + "serviceType": "CLL", + "additionalProperties": { + "enableSdnc": "false", + "transportNetworks": [ + { + "id": "cll-101-network-001", + "sla": { + "latency": 2, + "maxBandwidth": 8000 + }, + "connectionLinks": [ + { + "name": "cll-link-1", + "transportEndpointA": "tranportEp_UNI_ID_311_1", + "transportEndpointB": "tranportEp_ROOT_ID_512_1" + } + ] + } + ] + } +} + -- 2.16.6