diff options
author | Benjamin, Max (mb388a) <mb388a@us.att.com> | 2018-08-07 16:06:09 -0400 |
---|---|---|
committer | Benjamin, Max (mb388a) <mb388a@us.att.com> | 2018-08-07 16:09:14 -0400 |
commit | 0bb644bd5c11ce03b6dec71d26127fbd3519a9b4 (patch) | |
tree | 13c7af86a5ce8568f613e1fe95b02be462ed43a3 /bpmn/so-bpmn-infrastructure-flows/src/main/groovy | |
parent | 94450aaa3ceaf24f2de6a949c0ccc447fbc7fe06 (diff) |
Refactored references to AaiUtils
to use AAIResourceClient
updated bpmn, removed Generic AAI flows, and removed dead useless code
Did not modify E2E Delete Service Instance flow as it has changed
significantly
Issue-ID: SO-813
Change-Id: I1a6bc5353ef89e2ce4359be2654395f7ce060aba
Signed-off-by: Benjamin, Max (mb388a) <mb388a@us.att.com>
Diffstat (limited to 'bpmn/so-bpmn-infrastructure-flows/src/main/groovy')
14 files changed, 931 insertions, 1154 deletions
diff --git a/bpmn/so-bpmn-infrastructure-flows/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCompareModelofE2EServiceInstance.groovy b/bpmn/so-bpmn-infrastructure-flows/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCompareModelofE2EServiceInstance.groovy index eceba5abe3..3702862a04 100644 --- a/bpmn/so-bpmn-infrastructure-flows/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCompareModelofE2EServiceInstance.groovy +++ b/bpmn/so-bpmn-infrastructure-flows/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCompareModelofE2EServiceInstance.groovy @@ -2,14 +2,14 @@ * ============LICENSE_START======================================================= * ONAP - SO * ================================================================================ - * Copyright (C) 2018 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (C) 2018 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. @@ -20,47 +20,29 @@ package org.onap.so.bpmn.infrastructure.scripts; import static org.apache.commons.lang3.StringUtils.*; -import groovy.xml.XmlUtil -import groovy.json.* -import org.onap.so.bpmn.core.domain.ServiceDecomposition -import org.onap.so.bpmn.core.domain.ServiceInstance +import javax.ws.rs.NotFoundException + +import org.apache.commons.lang3.* +import org.camunda.bpm.engine.delegate.BpmnError +import org.camunda.bpm.engine.delegate.DelegateExecution +import org.onap.aai.domain.yang.ServiceInstance +import org.onap.so.bpmn.common.resource.ResourceRequestBuilder +import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor +import org.onap.so.bpmn.common.scripts.ExceptionUtil +import org.onap.so.bpmn.core.domain.CompareModelsResult import org.onap.so.bpmn.core.domain.ModelInfo import org.onap.so.bpmn.core.domain.Resource -import org.onap.so.bpmn.core.domain.CompareModelsResult import org.onap.so.bpmn.core.domain.ResourceModelInfo import org.onap.so.bpmn.core.json.JsonUtils -import org.onap.so.bpmn.common.scripts.AaiUtil -import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor -import org.onap.so.bpmn.common.scripts.ExceptionUtil -import org.onap.so.bpmn.common.scripts.SDNCAdapterUtils -import org.onap.so.bpmn.common.resource.ResourceRequestBuilder -import org.onap.so.bpmn.core.RollbackData -import org.onap.so.bpmn.core.WorkflowException -import org.onap.so.rest.APIResponse; -import org.onap.so.rest.RESTClient -import org.onap.so.rest.RESTConfig +import org.onap.so.client.aai.AAIObjectType +import org.onap.so.client.aai.AAIResourcesClient +import org.onap.so.client.aai.entities.AAIResultWrapper +import org.onap.so.client.aai.entities.uri.AAIResourceUri +import org.onap.so.client.aai.entities.uri.AAIUriFactory +import groovy.json.* -import java.util.List -import java.util.Map -import java.util.UUID; -import javax.xml.parsers.DocumentBuilder -import javax.xml.parsers.DocumentBuilderFactory - -import org.camunda.bpm.engine.delegate.BpmnError -import org.camunda.bpm.engine.delegate.DelegateExecution -import org.json.JSONObject; -import org.json.JSONArray; -import org.apache.commons.lang3.* -import org.apache.commons.codec.binary.Base64; -import org.springframework.web.util.UriUtils; - -import org.w3c.dom.Document -import org.w3c.dom.Element -import org.w3c.dom.Node -import org.w3c.dom.NodeList -import org.xml.sax.InputSource /** * This groovy class supports the <class>DoCompareModelofE2EServiceInstance.bpmn</class> process. * @@ -80,7 +62,7 @@ public class DoCompareModelofE2EServiceInstance extends AbstractServiceTaskProce String Prefix="DCMPMDSI_" private static final String DebugFlag = "isDebugEnabled" - + ExceptionUtil exceptionUtil = new ExceptionUtil() JsonUtils jsonUtil = new JsonUtils() @@ -94,11 +76,11 @@ public class DoCompareModelofE2EServiceInstance extends AbstractServiceTaskProce execution.setVariable("prefix", Prefix) //Inputs - + //subscriberInfo. for AAI GET String globalSubscriberId = execution.getVariable("globalSubscriberId") utils.log("INFO"," ***** globalSubscriberId *****" + globalSubscriberId, isDebugEnabled) - + String serviceType = execution.getVariable("serviceType") utils.log("INFO"," ***** serviceType *****" + serviceType, isDebugEnabled) @@ -142,85 +124,48 @@ public class DoCompareModelofE2EServiceInstance extends AbstractServiceTaskProce utils.log("INFO", "Exited " + method, isDebugEnabled) } - - public void postProcessAAIGET(DelegateExecution execution) { - def isDebugEnabled=execution.getVariable("isDebugLogEnabled") - utils.log("INFO"," ***** postProcessAAIGET ***** ", isDebugEnabled) - String msg = "" + /** + * Gets the service instance from aai + * + * @author cb645j + */ + public void getServiceInstance(DelegateExecution execution) { try { - String serviceInstanceId = execution.getVariable("serviceInstanceId") - boolean foundInAAI = execution.getVariable("GENGS_FoundIndicator") - String serviceType = "" - - if(foundInAAI){ - utils.log("INFO","Found Service-instance in AAI", isDebugEnabled) - - String siData = execution.getVariable("GENGS_service") - utils.log("INFO", "SI Data", isDebugEnabled) - if (isBlank(siData)) - { - msg = "Could not retrive ServiceInstance data from AAI, Id:" + serviceInstanceId - utils.log("INFO", msg, isDebugEnabled) - exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg) - } - else - { - utils.log("INFO", "SI Data" + siData, isDebugEnabled) - - // Get Template uuid and version - if (utils.nodeExists(siData, "model-invariant-id") && utils.nodeExists(siData, "model-version-id") ) { - utils.log("INFO", "SI Data model-invariant-id and model-version-id exist", isDebugEnabled) - - def modelInvariantId = utils.getNodeText(siData, "model-invariant-id") - def modelVersionId = utils.getNodeText(siData, "model-version-id") - - // Set Original Template info - execution.setVariable("model-invariant-id-original", modelInvariantId) - execution.setVariable("model-version-id-original", modelVersionId) - } - } - }else{ - boolean succInAAI = execution.getVariable("GENGS_SuccessIndicator") - if(!succInAAI){ - utils.log("INFO","Error getting Service-instance from AAI", + serviceInstanceId, isDebugEnabled) - WorkflowException workflowException = execution.getVariable("WorkflowException") - utils.logAudit("workflowException: " + workflowException) - if(workflowException != null){ - exceptionUtil.buildAndThrowWorkflowException(execution, workflowException.getErrorCode(), workflowException.getErrorMessage()) - } - else - { - msg = "Failure in postProcessAAIGET GENGS_SuccessIndicator:" + succInAAI - utils.log("INFO", msg, isDebugEnabled) - exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg) - } - } - - utils.log("INFO","Service-instance NOT found in AAI. Silent Success", isDebugEnabled) - } - }catch (BpmnError e) { + String serviceInstanceId = execution.getVariable('serviceInstanceId') + String globalSubscriberId = execution.getVariable('globalSubscriberId') + String serviceType = execution.getVariable('serviceType') + + AAIResourcesClient resourceClient = new AAIResourcesClient() + AAIResourceUri serviceInstanceUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, globalSubscriberId, serviceType, serviceInstanceId) + AAIResultWrapper wrapper = resourceClient.get(serviceInstanceUri, NotFoundException.class) + + ServiceInstance si = wrapper.asBean(ServiceInstance.class) + execution.setVariable("model-invariant-id-original", si.getModelInvariantId()) + execution.setVariable("model-version-id-original", si.getModelVersionId()) + + }catch(BpmnError e) { throw e; - } catch (Exception ex) { - msg = "Exception in DoDeleteE2EServiceInstance.postProcessAAIGET. " + ex.getMessage() - utils.log("INFO", msg, isDebugEnabled) + }catch(NotFoundException e) { + exceptionUtil.buildAndThrowWorkflowException(execution, 404, "Service-instance does not exist AAI") + }catch(Exception ex) { + String msg = "Internal Error in getServiceInstance: " + ex.getMessage() exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) } - msoLogger.trace("Exit postProcessAAIGET ") } public void postCompareModelVersions(DelegateExecution execution) { def isDebugEnabled=execution.getVariable("isDebugLogEnabled") - + List<Resource> addResourceList = execution.getVariable("addResourceList") List<Resource> delResourceList = execution.getVariable("delResourceList") - + CompareModelsResult cmpResult = new CompareModelsResult() List<ResourceModelInfo> addedResourceList = new ArrayList<ResourceModelInfo>() List<ResourceModelInfo> deletedResourceList = new ArrayList<ResourceModelInfo>() - - + + String serviceModelUuid = execution.getVariable("model-version-id-target") List<String> requestInputs = new ArrayList<String>() ModelInfo mi = null; @@ -233,11 +178,11 @@ public class DoCompareModelofE2EServiceInstance extends AbstractServiceTaskProce rmodel.setResourceUuid(mi.getModelUuid()) rmodel.setResourceCustomizationUuid(resourceCustomizationUuid) addedResourceList.add(rmodel) - + Map<String, Object> resourceParameters = ResourceRequestBuilder.buildResouceRequest(serviceModelUuid, resourceCustomizationUuid, null) - requestInputs.addAll(resourceParameters.keySet()) + requestInputs.addAll(resourceParameters.keySet()) } - + for(Resource rc : delResourceList) { mi = rc.getModelInfo() String resourceCustomizationUuid = mi.getModelCustomizationUuid() @@ -246,15 +191,15 @@ public class DoCompareModelofE2EServiceInstance extends AbstractServiceTaskProce rmodel.setResourceInvariantUuid(mi.getModelInvariantUuid()) rmodel.setResourceUuid(mi.getModelUuid()) rmodel.setResourceCustomizationUuid(resourceCustomizationUuid) - deletedResourceList.add(rmodel) + deletedResourceList.add(rmodel) } - + cmpResult.setAddedResourceList(addedResourceList) cmpResult.setDeletedResourceList(deletedResourceList) - cmpResult.setRequestInputs(requestInputs) + cmpResult.setRequestInputs(requestInputs) execution.setVariable("compareModelsResult", cmpResult) } - + } - + diff --git a/bpmn/so-bpmn-infrastructure-flows/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCreateE2EServiceInstance.groovy b/bpmn/so-bpmn-infrastructure-flows/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCreateE2EServiceInstance.groovy index bb48671e73..b5d196181b 100644 --- a/bpmn/so-bpmn-infrastructure-flows/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCreateE2EServiceInstance.groovy +++ b/bpmn/so-bpmn-infrastructure-flows/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCreateE2EServiceInstance.groovy @@ -3,14 +3,14 @@ * ONAP - SO * ================================================================================ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * Copyright (C) 2017 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (C) 2017 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. @@ -22,9 +22,12 @@ package org.onap.so.bpmn.infrastructure.scripts; import static org.apache.commons.lang3.StringUtils.*; +import javax.ws.rs.NotFoundException + import org.apache.commons.lang3.* import org.camunda.bpm.engine.delegate.BpmnError import org.camunda.bpm.engine.delegate.DelegateExecution +import org.onap.aai.domain.yang.ServiceInstance import org.onap.so.bpmn.common.scripts.AaiUtil import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor import org.onap.so.bpmn.common.scripts.CatalogDbUtils; @@ -35,6 +38,11 @@ import org.onap.so.bpmn.core.WorkflowException import org.onap.so.bpmn.core.domain.Resource import org.onap.so.bpmn.core.domain.ServiceDecomposition import org.onap.so.bpmn.core.json.JsonUtils +import org.onap.so.client.aai.AAIObjectType +import org.onap.so.client.aai.AAIResourcesClient +import org.onap.so.client.aai.entities.AAIResultWrapper +import org.onap.so.client.aai.entities.uri.AAIResourceUri +import org.onap.so.client.aai.entities.uri.AAIUriFactory import org.onap.so.logger.MessageEnum import org.onap.so.logger.MsoLogger import org.springframework.web.util.UriUtils; @@ -58,7 +66,7 @@ import groovy.json.* * @param - failExists - TODO * @param - serviceInputParams (should contain aic_zone for serviceTypes TRANSPORT,ATM) * @param - sdncVersion ("1610") - * @param - serviceDecomposition - Decomposition for R1710 + * @param - serviceDecomposition - Decomposition for R1710 * (if macro provides serviceDecompsition then serviceModelInfo, serviceInstanceId & serviceInstanceName will be ignored) * * Outputs: @@ -98,17 +106,17 @@ public class DoCreateE2EServiceInstance extends AbstractServiceTaskProcessor { msoLogger.info(msg) exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg) } - + if (isBlank(serviceType)) { msg = "Input serviceType is null" msoLogger.info(msg) exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg) } - + if (productFamilyId == null) { execution.setVariable("productFamilyId", "") } - + String sdncCallbackUrl = execution.getVariable('URN_mso_workflow_sdncadapter_callback') if (isBlank(sdncCallbackUrl)) { msg = "URN_mso_workflow_sdncadapter_callback is null" @@ -118,8 +126,8 @@ public class DoCreateE2EServiceInstance extends AbstractServiceTaskProcessor { execution.setVariable("sdncCallbackUrl", sdncCallbackUrl) msoLogger.info("SDNC Callback URL: " + sdncCallbackUrl) - //requestDetails.modelInfo.for AAI PUT servieInstanceData - //requestDetails.requestInfo. for AAI GET/PUT serviceInstanceData + //requestDetails.modelInfo.for AAI PUT servieInstanceData + //requestDetails.requestInfo. for AAI GET/PUT serviceInstanceData String serviceInstanceName = execution.getVariable("serviceInstanceName") String serviceInstanceId = execution.getVariable("serviceInstanceId") String uuiRequest = execution.getVariable("uuiRequest") @@ -130,7 +138,7 @@ public class DoCreateE2EServiceInstance extends AbstractServiceTaskProcessor { //aai serviceType and Role can be setted as fixed value now. String aaiServiceType = "E2E Service" String aaiServiceRole = "E2E Service" - + execution.setVariable("modelInvariantUuid", modelInvariantUuid) execution.setVariable("modelUuid", modelUuid) @@ -142,7 +150,7 @@ public class DoCreateE2EServiceInstance extends AbstractServiceTaskProcessor { } String statusLine = isBlank(oStatus) ? "" : "<orchestration-status>${MsoUtils.xmlEscape(oStatus)}</orchestration-status>" - + AaiUtil aaiUriUtil = new AaiUtil(this) String aai_uri = aaiUriUtil.getBusinessCustomerUri(execution) String namespace = aaiUriUtil.getNamespaceFromUri(aai_uri) @@ -155,7 +163,7 @@ public class DoCreateE2EServiceInstance extends AbstractServiceTaskProcessor { ${statusLine} <model-invariant-id>${MsoUtils.xmlEscape(modelInvariantUuid)}</model-invariant-id> <model-version-id>${MsoUtils.xmlEscape(modelUuid)}</model-version-id> - </service-instance>""".trim() + </service-instance>""".trim() execution.setVariable("serviceInstanceData", serviceInstanceData) msoLogger.debug(serviceInstanceData) msoLogger.info(" aai_uri " + aai_uri + " namespace:" + namespace) @@ -170,7 +178,7 @@ public class DoCreateE2EServiceInstance extends AbstractServiceTaskProcessor { } msoLogger.trace("Exit preProcessRequest ") } - + public void prepareDecomposeService(DelegateExecution execution) { try { msoLogger.trace("Inside prepareDecomposeService of create generic e2e service ") @@ -193,7 +201,7 @@ public class DoCreateE2EServiceInstance extends AbstractServiceTaskProcessor { } public void processDecomposition(DelegateExecution execution) { - msoLogger.trace("Inside processDecomposition() of create generic e2e service flow ") + msoLogger.trace("Inside processDecomposition() of create generic e2e service flow ") try { ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition") } catch (Exception ex) { @@ -202,23 +210,23 @@ public class DoCreateE2EServiceInstance extends AbstractServiceTaskProcessor { exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage) } } - + public void doServicePreOperation(DelegateExecution execution){ - //we need a service plugin platform here. + //we need a service plugin platform here. ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition") - String uuiRequest = execution.getVariable("uuiRequest") + String uuiRequest = execution.getVariable("uuiRequest") String newUuiRequest = ServicePluginFactory.getInstance().preProcessService(serviceDecomposition, uuiRequest); - execution.setVariable("uuiRequest", newUuiRequest) + execution.setVariable("uuiRequest", newUuiRequest) } - + public void doServiceHoming(DelegateExecution execution) { - //we need a service plugin platform here. + //we need a service plugin platform here. ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition") - String uuiRequest = execution.getVariable("uuiRequest") + String uuiRequest = execution.getVariable("uuiRequest") String newUuiRequest = ServicePluginFactory.getInstance().doServiceHoming(serviceDecomposition, uuiRequest); - execution.setVariable("uuiRequest", newUuiRequest) + execution.setVariable("uuiRequest", newUuiRequest) } - + public void postProcessAAIGET(DelegateExecution execution) { msoLogger.trace("postProcessAAIGET ") String msg = "" @@ -260,6 +268,7 @@ public class DoCreateE2EServiceInstance extends AbstractServiceTaskProcessor { msoLogger.trace("Exit postProcessAAIGET ") } + //TODO use create if not exist public void postProcessAAIPUT(DelegateExecution execution) { msoLogger.trace("postProcessAAIPUT ") String msg = "" @@ -296,7 +305,32 @@ public class DoCreateE2EServiceInstance extends AbstractServiceTaskProcessor { } msoLogger.trace("Exit postProcessAAIPUT ") } - + + /** + * Gets the service instance and its relationships from aai + */ + public void getServiceInstance(DelegateExecution execution) { + try { + String serviceInstanceId = execution.getVariable('serviceInstanceId') + String globalSubscriberId = execution.getVariable('globalSubscriberId') + String serviceType = execution.getVariable('subscriptionServiceType') + + AAIResourcesClient resourceClient = new AAIResourcesClient() + AAIResourceUri serviceInstanceUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, globalSubscriberId, serviceType, serviceInstanceId) + AAIResultWrapper wrapper = resourceClient.get(serviceInstanceUri, NotFoundException.class) + + ServiceInstance si = wrapper.asBean(ServiceInstance.class) + execution.setVariable("serviceInstanceName", si.getServiceInstanceName()) + + }catch(BpmnError e) { + throw e; + }catch(Exception ex) { + String msg = "Internal Error in getServiceInstance: " + ex.getMessage() + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) + } + } + + public void postProcessAAIGET2(DelegateExecution execution) { msoLogger.trace("postProcessAAIGET2 ") String msg = "" @@ -342,7 +376,7 @@ public class DoCreateE2EServiceInstance extends AbstractServiceTaskProcessor { public void preProcessRollback (DelegateExecution execution) { msoLogger.trace("preProcessRollback ") try { - + Object workflowException = execution.getVariable("WorkflowException"); if (workflowException instanceof WorkflowException) { @@ -397,10 +431,10 @@ public class DoCreateE2EServiceInstance extends AbstractServiceTaskProcessor { execution.setVariable("operationType", operationType) ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition") List<Resource> resourceList = serviceDecomposition.getServiceResources() - + for(Resource resource : resourceList){ resourceTemplateUUIDs = resourceTemplateUUIDs + resource.getModelInfo().getModelCustomizationUuid() + ":" - } + } def dbAdapterEndpoint = "http://mso.mso.testlab.openecomp.org:8080/dbadapters/RequestsDbAdapter" execution.setVariable("CVFMI_dbAdapterEndpoint", dbAdapterEndpoint) @@ -429,23 +463,23 @@ public class DoCreateE2EServiceInstance extends AbstractServiceTaskProcessor { msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception Occured Processing preInitResourcesOperStatus.", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, e); execution.setVariable("CVFMI_ErrorResponse", "Error Occurred during preInitResourcesOperStatus Method:\n" + e.getMessage()) } - msoLogger.trace("COMPLETED preInitResourcesOperStatus Process ") + msoLogger.trace("COMPLETED preInitResourcesOperStatus Process ") } // prepare input param for using DoCreateResources.bpmn public void preProcessForAddResource(DelegateExecution execution) { msoLogger.trace("STARTED preProcessForAddResource Process ") - + ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition") List<Resource> addResourceList = serviceDecomposition.getServiceResources() execution.setVariable("addResourceList", addResourceList) - + msoLogger.trace("COMPLETED preProcessForAddResource Process ") } public void postProcessForAddResource(DelegateExecution execution) { // do nothing now - + } } diff --git a/bpmn/so-bpmn-infrastructure-flows/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCreateNetworkInstance.groovy b/bpmn/so-bpmn-infrastructure-flows/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCreateNetworkInstance.groovy index 4bbaef8ecb..a376e581fe 100644 --- a/bpmn/so-bpmn-infrastructure-flows/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCreateNetworkInstance.groovy +++ b/bpmn/so-bpmn-infrastructure-flows/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCreateNetworkInstance.groovy @@ -7,9 +7,9 @@ * 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. @@ -36,6 +36,14 @@ import org.onap.so.bpmn.core.json.JsonUtils import org.onap.so.logger.MsoLogger import org.onap.so.rest.APIResponse; import org.springframework.web.util.UriUtils +import org.onap.so.client.aai.AAIResourcesClient +import org.onap.so.client.aai.AAIObjectType +import org.onap.so.client.aai.entities.AAIResultWrapper +import org.onap.so.client.aai.entities.Relationships +import org.onap.so.client.aai.entities.uri.AAIResourceUri +import org.onap.so.client.aai.entities.uri.AAIUriFactory +import org.json.JSONObject +import javax.ws.rs.NotFoundException import groovy.json.* import groovy.xml.XmlUtil @@ -47,7 +55,7 @@ import groovy.xml.XmlUtil */ public class DoCreateNetworkInstance extends AbstractServiceTaskProcessor { private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, DoCreateNetworkInstance.class); - + String Prefix="CRENWKI_" ExceptionUtil exceptionUtil = new ExceptionUtil() JsonUtils jsonUtil = new JsonUtils() @@ -56,7 +64,7 @@ public class DoCreateNetworkInstance extends AbstractServiceTaskProcessor { SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils() def className = getClass().getSimpleName() - + /** * This method is executed during the preProcessRequest task of the <class>DoCreateNetworkInstance.bpmn</class> process. * @param execution @@ -78,7 +86,7 @@ public class DoCreateNetworkInstance extends AbstractServiceTaskProcessor { execution.setVariable(Prefix + "networkOutputs", "") execution.setVariable(Prefix + "networkId","") execution.setVariable(Prefix + "networkName","") - + // AAI query Name execution.setVariable(Prefix + "queryNameAAIRequest","") execution.setVariable(Prefix + "queryNameAAIResponse", "") @@ -149,7 +157,7 @@ public class DoCreateNetworkInstance extends AbstractServiceTaskProcessor { //execution.setVariable(Prefix + "rollbackSDNCReturnCode", "") execution.setVariable(Prefix + "isSdncRollbackNeeded", false) execution.setVariable(Prefix + "sdncResponseSuccess", false) - + execution.setVariable(Prefix + "activateSDNCRequest", "") execution.setVariable(Prefix + "activateSDNCResponse", "") execution.setVariable(Prefix + "rollbackActivateSDNCRequest", "") @@ -164,7 +172,7 @@ public class DoCreateNetworkInstance extends AbstractServiceTaskProcessor { execution.setVariable(Prefix + "Success", false) execution.setVariable(Prefix + "isException", false) - + } // ************************************************** @@ -175,25 +183,25 @@ public class DoCreateNetworkInstance extends AbstractServiceTaskProcessor { * @param execution */ public void preProcessRequest (DelegateExecution execution) { - - execution.setVariable("prefix",Prefix) + + execution.setVariable("prefix",Prefix) msoLogger.trace("Inside preProcessRequest() of " + className + ".groovy") - + try { // initialize flow variables InitializeProcessVariables(execution) - + // GET Incoming request & validate 3 kinds of format. execution.setVariable("action", "CREATE") String networkRequest = execution.getVariable("bpmnRequest") if (networkRequest != null) { if (networkRequest.contains("requestDetails")) { - // JSON format request is sent, create xml + // JSON format request is sent, create xml try { def prettyJson = JsonOutput.prettyPrint(networkRequest.toString()) msoLogger.debug(" Incoming message formatted . . . : " + '\n' + prettyJson) networkRequest = vidUtils.createXmlNetworkRequestInfra(execution, networkRequest) - + } catch (Exception ex) { String dataErrorMessage = " Invalid json format Request - " + ex.getMessage() msoLogger.debug(dataErrorMessage) @@ -201,26 +209,26 @@ public class DoCreateNetworkInstance extends AbstractServiceTaskProcessor { } } else { // XML format request is sent - + } } else { // vIPR format request is sent, create xml from individual variables networkRequest = vidUtils.createXmlNetworkRequestInstance(execution) } - + networkRequest = utils.formatXml(networkRequest) execution.setVariable(Prefix + "networkRequest", networkRequest) msoLogger.debug(Prefix + "networkRequest - " + '\n' + networkRequest) - + // validate 'backout-on-failure' to override 'mso.rollback' boolean rollbackEnabled = networkUtils.isRollbackEnabled(execution, networkRequest) execution.setVariable(Prefix + "rollbackEnabled", rollbackEnabled) msoLogger.debug(Prefix + "rollbackEnabled - " + rollbackEnabled) - + String networkInputs = utils.getNodeXml(networkRequest, "network-inputs", false).replace("tag0:","").replace(":tag0","") execution.setVariable(Prefix + "networkInputs", networkInputs) msoLogger.debug(Prefix + "networkInputs - " + '\n' + networkInputs) - + // prepare messageId String messageId = execution.getVariable("testMessageId") // for testing if (messageId == null || messageId == "") { @@ -230,12 +238,12 @@ public class DoCreateNetworkInstance extends AbstractServiceTaskProcessor { msoLogger.debug(Prefix + "messageId, pre-assigned: " + messageId) } execution.setVariable(Prefix + "messageId", messageId) - + String source = utils.getNodeText(networkRequest, "source") execution.setVariable(Prefix + "source", source) msoLogger.debug(Prefix + "source - " + source) - - // validate cloud region + + // validate cloud region String lcpCloudRegionId = utils.getNodeText(networkRequest, "aic-cloud-region") if ((lcpCloudRegionId == null) || (lcpCloudRegionId == "") || (lcpCloudRegionId == "null")) { String dataErrorMessage = "Missing value/element: 'lcpCloudRegionId' or 'cloudConfiguration' or 'aic-cloud-region'." @@ -244,7 +252,7 @@ public class DoCreateNetworkInstance extends AbstractServiceTaskProcessor { } // validate service instance id - String serviceInstanceId = utils.getNodeText(networkRequest, "service-instance-id") + String serviceInstanceId = utils.getNodeText(networkRequest, "service-instance-id") if ((serviceInstanceId == null) || (serviceInstanceId == "") || (serviceInstanceId == "null")) { String dataErrorMessage = "Missing value/element: 'serviceInstanceId'." msoLogger.debug(" Invalid Request - " + dataErrorMessage) @@ -253,12 +261,12 @@ public class DoCreateNetworkInstance extends AbstractServiceTaskProcessor { // PO Authorization Info / headers Authorization= String basicAuthValuePO = UrnPropertiesReader.getVariable("mso.adapters.po.auth",execution) - + try { def encodedString = utils.getBasicAuth(basicAuthValuePO, UrnPropertiesReader.getVariable("mso.msoKey",execution)) execution.setVariable("BasicAuthHeaderValuePO",encodedString) execution.setVariable("BasicAuthHeaderValueSDNC", encodedString) - + } catch (IOException ex) { String exceptionMessage = "Exception Encountered in DoCreateNetworkInstance, PreProcessRequest() - " String dataErrorMessage = exceptionMessage + " Unable to encode PO/SDNC user/password string - " + ex.getMessage() @@ -273,11 +281,11 @@ public class DoCreateNetworkInstance extends AbstractServiceTaskProcessor { execution.setVariable("GENGS_type", "service-instance") msoLogger.debug("GENGS_type - " + "service-instance") msoLogger.debug(" Url for SDNC adapter: " + UrnPropertiesReader.getVariable("mso.adapters.sdnc.endpoint",execution)) - + String sdncVersion = execution.getVariable("sdncVersion") msoLogger.debug("sdncVersion? : " + sdncVersion) - - // build 'networkOutputs' + + // build 'networkOutputs' String networkId = utils.getNodeText(networkRequest, "network-id") if ((networkId == null) || (networkId == "null")) { networkId = "" @@ -295,25 +303,49 @@ public class DoCreateNetworkInstance extends AbstractServiceTaskProcessor { msoLogger.debug(Prefix + "networkOutputs - " + '\n' + networkOutputs) execution.setVariable(Prefix + "networkId", networkId) execution.setVariable(Prefix + "networkName", networkName) - + } catch (BpmnError e) { throw e; - + } catch (Exception ex) { sendSyncError(execution) // caught exception String exceptionMessage = "Exception Encountered in PreProcessRequest() of " + className + ".groovy ***** : " + ex.getMessage() msoLogger.debug(exceptionMessage) exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage) - + } } - + + /** + * Gets the service instance uri from aai + */ + public void getServiceInstance(DelegateExecution execution) { + try { + String serviceInstanceId = execution.getVariable('CRENWKI_serviceInstanceId') + + AAIResourcesClient resourceClient = new AAIResourcesClient() + AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, serviceInstanceId) + + if(!resourceClient.exists(uri)){ + exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Service instance was not found in aai") + } + + }catch(BpmnError e) { + throw e; + }catch (Exception ex){ + String msg = "Exception in getServiceInstance. " + ex.getMessage() + msoLogger.debug(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) + } + } + + public void callRESTQueryAAINetworkName (DelegateExecution execution) { - + execution.setVariable("prefix",Prefix) - + msoLogger.debug(" ***** Inside callRESTQueryAAINetworkName() of DoCreateNetworkInstance ***** " ) // get variables @@ -348,7 +380,7 @@ public class DoCreateNetworkInstance extends AbstractServiceTaskProcessor { execution.setVariable(Prefix + "orchestrationStatus", orchestrationStatus.toUpperCase()) msoLogger.debug(Prefix + "orchestrationStatus - " + orchestrationStatus.toUpperCase()) execution.setVariable("orchestrationStatus", orchestrationStatus) - + } catch (Exception ex) { // response is empty execution.setVariable(Prefix + "orchestrationStatus", orchestrationStatus) @@ -385,9 +417,9 @@ public class DoCreateNetworkInstance extends AbstractServiceTaskProcessor { } public void callRESTQueryAAICloudRegion (DelegateExecution execution) { - + execution.setVariable("prefix",Prefix) - + msoLogger.debug(" ***** Inside callRESTQueryAAICloudRegion() of DoCreateNetworkInstance ***** " ) try { @@ -434,7 +466,7 @@ public class DoCreateNetworkInstance extends AbstractServiceTaskProcessor { } public void callRESTQueryAAINetworkId(DelegateExecution execution) { - + execution.setVariable("prefix",Prefix) msoLogger.debug(" ***** Inside callRESTQueryAAINetworkId() of DoCreateNetworkInstance ***** " ) @@ -445,15 +477,15 @@ public class DoCreateNetworkInstance extends AbstractServiceTaskProcessor { String assignSDNCResponse = execution.getVariable(Prefix + "assignSDNCResponse") if (execution.getVariable("sdncVersion") != "1610") { String networkResponseInformation = "" - try { + try { networkResponseInformation = utils.getNodeXml(assignSDNCResponse, "network-response-information", false).replace("tag0:","").replace(":tag0","") networkId = utils.getNodeText(networkResponseInformation, "instance-id") } catch (Exception ex) { String dataErrorMessage = " SNDC Response network validation for 'instance-id' (network-id) failed: Empty <network-response-information>" msoLogger.debug(dataErrorMessage) exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage) - } - + } + } else { networkId = utils.getNodeText(assignSDNCResponse, "network-id") } @@ -465,11 +497,11 @@ public class DoCreateNetworkInstance extends AbstractServiceTaskProcessor { msoLogger.debug(" SNDC Response network validation for 'instance-id' (network-id)' is good: " + networkId) } - + execution.setVariable(Prefix + "networkId", networkId) String networkName = utils.getNodeText(assignSDNCResponse, "network-name") execution.setVariable(Prefix + "networkName", networkName) - + networkId = UriUtils.encode(networkId,"UTF-8") // Prepare AA&I url @@ -491,7 +523,7 @@ public class DoCreateNetworkInstance extends AbstractServiceTaskProcessor { if (returnCode=='200') { execution.setVariable(Prefix + "queryIdAAIResponse", aaiResponseAsString) msoLogger.debug(" QueryAAINetworkId Success REST Response - " + "\n" + aaiResponseAsString) - + String netId = utils.getNodeText(aaiResponseAsString, "network-id") execution.setVariable(Prefix + "networkId", netId) String netName = utils.getNodeText(aaiResponseAsString, "network-name") @@ -532,7 +564,7 @@ public class DoCreateNetworkInstance extends AbstractServiceTaskProcessor { } public void callRESTReQueryAAINetworkId(DelegateExecution execution) { - + execution.setVariable("prefix",Prefix) msoLogger.debug(" ***** Inside callRESTReQueryAAINetworkId() of DoCreateNetworkInstance ***** " ) @@ -540,7 +572,7 @@ public class DoCreateNetworkInstance extends AbstractServiceTaskProcessor { try { // get variables String networkId = execution.getVariable(Prefix + "networkId") - String netId = networkId + String netId = networkId networkId = UriUtils.encode(networkId,"UTF-8") // Prepare AA&I url @@ -606,7 +638,7 @@ public class DoCreateNetworkInstance extends AbstractServiceTaskProcessor { } public void callRESTQueryAAINetworkVpnBinding(DelegateExecution execution) { - + execution.setVariable("prefix",Prefix) msoLogger.debug(" ***** Inside callRESTQueryAAINetworkVpnBinding() of DoCreateNetworkInstance ***** " ) @@ -748,7 +780,7 @@ public class DoCreateNetworkInstance extends AbstractServiceTaskProcessor { } public void callRESTQueryAAINetworkPolicy(DelegateExecution execution) { - + execution.setVariable("prefix",Prefix) msoLogger.debug(" ***** Inside callRESTQueryAAINetworkPolicy() of DoCreateNetworkInstance ***** " ) @@ -882,7 +914,7 @@ public class DoCreateNetworkInstance extends AbstractServiceTaskProcessor { } public void callRESTQueryAAINetworkTableRef(DelegateExecution execution) { - + execution.setVariable("prefix",Prefix) msoLogger.debug(" ***** Inside callRESTQueryAAINetworkTableRef() of DoCreateNetworkInstance ***** " ) @@ -1017,7 +1049,7 @@ public class DoCreateNetworkInstance extends AbstractServiceTaskProcessor { public void callRESTUpdateContrailAAINetwork(DelegateExecution execution) { - + execution.setVariable("prefix",Prefix) msoLogger.debug(" ***** Inside callRESTUpdateContrailAAINetwork() of DoCreateNetworkInstance ***** " ) @@ -1046,7 +1078,7 @@ public class DoCreateNetworkInstance extends AbstractServiceTaskProcessor { msoLogger.debug(" 'payload' to Update Contrail - " + "\n" + payloadXml) APIResponse response = aaiUriUtil.executeAAIPutCall(execution, updateContrailAAIUrlRequest, payloadXml) - + String returnCode = response.getStatusCode() execution.setVariable(Prefix + "aaiUpdateContrailReturnCode", returnCode) msoLogger.debug(" ***** AAI Update Contrail Response Code : " + returnCode) @@ -1060,7 +1092,7 @@ public class DoCreateNetworkInstance extends AbstractServiceTaskProcessor { execution.setVariable(Prefix + "isPONR", false) } else { execution.setVariable(Prefix + "isPONR", true) - } + } msoLogger.debug(Prefix + "isPONR" + ": " + execution.getVariable(Prefix + "isPONR")) } else { if (returnCode=='404') { @@ -1096,7 +1128,7 @@ public class DoCreateNetworkInstance extends AbstractServiceTaskProcessor { } public void prepareCreateNetworkRequest (DelegateExecution execution) { - + execution.setVariable("prefix",Prefix) msoLogger.trace("Inside prepareCreateNetworkRequest() of DoCreateNetworkInstance") @@ -1106,7 +1138,7 @@ public class DoCreateNetworkInstance extends AbstractServiceTaskProcessor { // get variables String requestId = execution.getVariable("msoRequestId") if (requestId == null) { - requestId = execution.getVariable("mso-request-id") + requestId = execution.getVariable("mso-request-id") } String messageId = execution.getVariable(Prefix + "messageId") String source = execution.getVariable(Prefix + "source") @@ -1115,7 +1147,7 @@ public class DoCreateNetworkInstance extends AbstractServiceTaskProcessor { String queryIdResponse = execution.getVariable(Prefix + "queryIdAAIResponse") String cloudRegionId = execution.getVariable(Prefix + "cloudRegionPo") String backoutOnFailure = execution.getVariable(Prefix + "rollbackEnabled") - + // Prepare Network request String routeCollection = execution.getVariable(Prefix + "routeCollection") String policyCollection = execution.getVariable(Prefix + "networkCollection") @@ -1138,7 +1170,7 @@ public class DoCreateNetworkInstance extends AbstractServiceTaskProcessor { } public void prepareSDNCRequest (DelegateExecution execution) { - + execution.setVariable("prefix",Prefix) msoLogger.trace("Inside prepareSDNCRequest() of DoCreateNetworkInstance") @@ -1158,9 +1190,9 @@ public class DoCreateNetworkInstance extends AbstractServiceTaskProcessor { execution.setVariable("mso-request-id", requestId) } else { requestId = execution.getVariable("mso-request-id") - } + } execution.setVariable(Prefix + "requestId", requestId) - + // 1. prepare assign topology via SDNC Adapter SUBFLOW call String sndcTopologyCreateRequest = sdncAdapterUtils.sdncTopologyRequestV2(execution, createNetworkInput, serviceInstanceId, sdncCallback, "assign", "NetworkActivateRequest", cloudRegionId, networkId, null, null) @@ -1179,21 +1211,21 @@ public class DoCreateNetworkInstance extends AbstractServiceTaskProcessor { } public void prepareRpcSDNCRequest (DelegateExecution execution) { - + execution.setVariable("prefix",Prefix) msoLogger.trace("Inside prepareRpcSDNCRequest() of DoCreateNetworkInstance") try { // get variables - + String sdncCallback = UrnPropertiesReader.getVariable("mso.workflow.sdncadapter.callback",execution) String createNetworkInput = execution.getVariable(Prefix + "networkRequest") String cloudRegionId = execution.getVariable(Prefix + "cloudRegionSdnc") String networkId = execution.getVariable(Prefix + "networkId") String serviceInstanceId = execution.getVariable(Prefix + "serviceInstanceId") - + // 1. prepare assign topology via SDNC Adapter SUBFLOW call String sndcTopologyCreateRequest = sdncAdapterUtils.sdncTopologyRequestRsrc(execution, createNetworkInput, serviceInstanceId, sdncCallback, "assign", "CreateNetworkInstance", cloudRegionId, networkId, null) @@ -1209,11 +1241,11 @@ public class DoCreateNetworkInstance extends AbstractServiceTaskProcessor { } } - + public void prepareRpcSDNCActivateRequest (DelegateExecution execution) { - + execution.setVariable("prefix",Prefix) - + msoLogger.trace("Inside prepareRpcSDNCActivateRequest() of DoCreateNetworkInstance") try { @@ -1223,7 +1255,7 @@ public class DoCreateNetworkInstance extends AbstractServiceTaskProcessor { String cloudRegionId = execution.getVariable(Prefix + "cloudRegionSdnc") String networkId = execution.getVariable(Prefix + "networkId") String serviceInstanceId = execution.getVariable(Prefix + "serviceInstanceId") - + // 1. prepare assign topology via SDNC Adapter SUBFLOW call String sndcTopologyCreateRequest = sdncAdapterUtils.sdncTopologyRequestRsrc(execution, createNetworkInput, serviceInstanceId, sdncCallback, "activate", "CreateNetworkInstance", cloudRegionId, networkId, null) @@ -1240,7 +1272,7 @@ public class DoCreateNetworkInstance extends AbstractServiceTaskProcessor { } } - + @@ -1249,7 +1281,7 @@ public class DoCreateNetworkInstance extends AbstractServiceTaskProcessor { // ************************************************** public void validateCreateNetworkResponse (DelegateExecution execution) { - + execution.setVariable("prefix",Prefix) msoLogger.trace("Inside validateNetworkResponse() of DoCreateNetworkInstance") @@ -1321,7 +1353,7 @@ public class DoCreateNetworkInstance extends AbstractServiceTaskProcessor { } public void validateSDNCResponse (DelegateExecution execution) { - + execution.setVariable("prefix",Prefix) msoLogger.trace("Inside validateSDNCResponse() of DoCreateNetworkInstance") @@ -1329,7 +1361,7 @@ public class DoCreateNetworkInstance extends AbstractServiceTaskProcessor { String response = execution.getVariable(Prefix + "assignSDNCResponse") boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator") WorkflowException workflowException = execution.getVariable("WorkflowException") - + SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils(this) sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator) // reset variable @@ -1349,7 +1381,7 @@ public class DoCreateNetworkInstance extends AbstractServiceTaskProcessor { } public void validateRpcSDNCActivateResponse (DelegateExecution execution) { - + execution.setVariable("prefix",Prefix) msoLogger.trace("Inside validateRpcSDNCActivateResponse() of DoCreateNetworkInstance") @@ -1373,12 +1405,12 @@ public class DoCreateNetworkInstance extends AbstractServiceTaskProcessor { msoLogger.debug("Did NOT Successfully Validated Rpc SDNC Activate Response") throw new BpmnError("MSOWorkflowException") } - + } public void prepareSDNCRollbackRequest (DelegateExecution execution) { - + execution.setVariable("prefix",Prefix) msoLogger.trace("Inside prepareSDNCRollbackRequest() of DoCreateNetworkInstance") @@ -1392,7 +1424,7 @@ public class DoCreateNetworkInstance extends AbstractServiceTaskProcessor { String networkId = execution.getVariable(Prefix + "networkId") if (networkId == 'null') {networkId = ""} String serviceInstanceId = execution.getVariable(Prefix + "serviceInstanceId") - + // 2. prepare rollback topology via SDNC Adapter SUBFLOW call String sndcTopologyRollbackRequest = sdncAdapterUtils.sdncTopologyRequestV2(execution, createNetworkInput, serviceInstanceId, sdncCallback, "rollback", "NetworkActivateRequest", cloudRegionId, networkId, null, null) String sndcTopologyRollbackRequestAsString = utils.formatXml(sndcTopologyRollbackRequest) @@ -1410,7 +1442,7 @@ public class DoCreateNetworkInstance extends AbstractServiceTaskProcessor { } public void prepareRpcSDNCRollbackRequest (DelegateExecution execution) { - + execution.setVariable("prefix",Prefix) msoLogger.trace("Inside prepareRpcSDNCRollbackRequest() of DoCreateNetworkInstance") @@ -1440,15 +1472,15 @@ public class DoCreateNetworkInstance extends AbstractServiceTaskProcessor { } } - + public void prepareRpcSDNCActivateRollback(DelegateExecution execution) { - + execution.setVariable("prefix",Prefix) msoLogger.trace("Inside prepareRpcSDNCActivateRollback() of DoCreateNetworkInstance") try { - + // get variables String sdncCallback = UrnPropertiesReader.getVariable("mso.workflow.sdncadapter.callback",execution) String createNetworkInput = execution.getVariable(Prefix + "networkRequest") @@ -1473,76 +1505,76 @@ public class DoCreateNetworkInstance extends AbstractServiceTaskProcessor { } } - + public void prepareRollbackData(DelegateExecution execution) { - + execution.setVariable("prefix",Prefix) - + msoLogger.trace("Inside prepareRollbackData() of DoCreateNetworkInstance") - + try { - + Map<String, String> rollbackData = new HashMap<String, String>(); String rollbackSDNCRequest = execution.getVariable(Prefix + "rollbackSDNCRequest") - if (rollbackSDNCRequest != null) { + if (rollbackSDNCRequest != null) { if (rollbackSDNCRequest != "") { rollbackData.put("rollbackSDNCRequest", execution.getVariable(Prefix + "rollbackSDNCRequest")) } - } + } String rollbackNetworkRequest = execution.getVariable(Prefix + "rollbackNetworkRequest") if (rollbackNetworkRequest != null) { - if (rollbackNetworkRequest != "") { + if (rollbackNetworkRequest != "") { rollbackData.put("rollbackNetworkRequest", execution.getVariable(Prefix + "rollbackNetworkRequest")) - } + } } String rollbackActivateSDNCRequest = execution.getVariable(Prefix + "rollbackActivateSDNCRequest") if (rollbackActivateSDNCRequest != null) { - if (rollbackActivateSDNCRequest != "") { + if (rollbackActivateSDNCRequest != "") { rollbackData.put("rollbackActivateSDNCRequest", execution.getVariable(Prefix + "rollbackActivateSDNCRequest")) - } + } } execution.setVariable("rollbackData", rollbackData) msoLogger.debug("** rollbackData : " + rollbackData) - + execution.setVariable("WorkflowException", execution.getVariable(Prefix + "WorkflowException")) msoLogger.debug("** WorkflowException : " + execution.getVariable("WorkflowException")) - + } catch (Exception ex) { String exceptionMessage = " Bpmn error encountered in DoCreateNetworkInstance flow. prepareRollbackData() - " + ex.getMessage() msoLogger.debug(exceptionMessage) exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage) - + } - + } - + public void postProcessResponse(DelegateExecution execution) { - + execution.setVariable("prefix",Prefix) - + msoLogger.trace("Inside postProcessResponse() of DoCreateNetworkInstance") - + try { - + //Conditions: - // 1. Silent Success: execution.getVariable("CRENWKI_orchestrationStatus") == "ACTIVE" + // 1. Silent Success: execution.getVariable("CRENWKI_orchestrationStatus") == "ACTIVE" // 2. Success: execution.getVariable("WorkflowException") == null (NULL) - // 3. WorkflowException: execution.getVariable("WorkflowException") != null (NOT NULL) - + // 3. WorkflowException: execution.getVariable("WorkflowException") != null (NOT NULL) + msoLogger.debug(" ***** Is Exception Encountered (isException)? : " + execution.getVariable(Prefix + "isException")) // successful flow - if (execution.getVariable(Prefix + "isException") == false) { + if (execution.getVariable(Prefix + "isException") == false) { // set rollback data execution.setVariable("orchestrationStatus", "") execution.setVariable("networkId", execution.getVariable(Prefix + "networkId")) execution.setVariable("networkName", execution.getVariable(Prefix + "networkName")) - prepareSuccessRollbackData(execution) // populate rollbackData + prepareSuccessRollbackData(execution) // populate rollbackData execution.setVariable("WorkflowException", null) execution.setVariable(Prefix + "Success", true) msoLogger.debug(" ***** postProcessResponse(), GOOD !!!") } else { // inside sub-flow logic - execution.setVariable(Prefix + "Success", false) + execution.setVariable(Prefix + "Success", false) execution.setVariable("rollbackData", null) String exceptionMessage = " Exception encountered in MSO Bpmn. " if (execution.getVariable("workflowException") != null) { // Output of Rollback flow. @@ -1553,45 +1585,45 @@ public class DoCreateNetworkInstance extends AbstractServiceTaskProcessor { if (execution.getVariable(Prefix + "WorkflowException") != null) { WorkflowException pwfex = execution.getVariable(Prefix + "WorkflowException") exceptionMessage = pwfex.getErrorMessage() - } + } } // going to the Main flow: a-la-carte or macro msoLogger.debug(" ***** postProcessResponse(), BAD !!!") exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage) throw new BpmnError("MSOWorkflowException") } - + } catch(BpmnError b){ msoLogger.debug("Rethrowing MSOWorkflowException") throw b - + } catch (Exception ex) { String exceptionMessage = " Bpmn error encountered in DoCreateNetworkInstance flow. postProcessResponse() - " + ex.getMessage() msoLogger.debug(exceptionMessage) exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage) throw new BpmnError("MSOWorkflowException") - + } - - - + + + } - + public void prepareSuccessRollbackData(DelegateExecution execution) { - + execution.setVariable("prefix",Prefix) - + msoLogger.trace("Inside prepareSuccessRollbackData() of DoCreateNetworkInstance") - + try { - + if (execution.getVariable("sdncVersion") != '1610') { prepareRpcSDNCRollbackRequest(execution) prepareRpcSDNCActivateRollback(execution) } else { prepareSDNCRollbackRequest(execution) - } - + } + Map<String, String> rollbackData = new HashMap<String, String>(); String rollbackSDNCRequest = execution.getVariable(Prefix + "rollbackSDNCRequest") if (rollbackSDNCRequest != null) { @@ -1612,63 +1644,63 @@ public class DoCreateNetworkInstance extends AbstractServiceTaskProcessor { } } execution.setVariable("rollbackData", rollbackData) - + msoLogger.debug("** 'rollbackData' for Full Rollback : " + rollbackData) execution.setVariable("WorkflowException", null) - + } catch (Exception ex) { String exceptionMessage = " Bpmn error encountered in DoCreateNetworkInstance flow. prepareSuccessRollbackData() - " + ex.getMessage() msoLogger.debug(exceptionMessage) exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage) - + } - + } public void setExceptionFlag(DelegateExecution execution){ - + execution.setVariable("prefix",Prefix) - + msoLogger.trace("Inside setExceptionFlag() of DoCreateNetworkInstance") - + try { - + execution.setVariable(Prefix + "isException", true) - + if (execution.getVariable("SavedWorkflowException1") != null) { execution.setVariable(Prefix + "WorkflowException", execution.getVariable("SavedWorkflowException1")) } else { execution.setVariable(Prefix + "WorkflowException", execution.getVariable("WorkflowException")) } msoLogger.debug(Prefix + "WorkflowException - " +execution.getVariable(Prefix + "WorkflowException")) - + } catch(Exception ex){ String exceptionMessage = "Bpmn error encountered in DoCreateNetworkInstance flow. setExceptionFlag(): " + ex.getMessage() msoLogger.debug(exceptionMessage) exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage) - } - + } + } - - + + // ******************************* // Build Error Section // ******************************* - + public void processJavaException(DelegateExecution execution){ - + execution.setVariable("prefix",Prefix) - + try{ msoLogger.debug( "Caught a Java Exception in " + Prefix) msoLogger.debug("Started processJavaException Method") msoLogger.debug("Variables List: " + execution.getVariables()) execution.setVariable("UnexpectedError", "Caught a Java Lang Exception - " + Prefix) // Adding this line temporarily until this flows error handling gets updated exceptionUtil.buildWorkflowException(execution, 500, "Caught a Java Lang Exception") - + }catch(Exception e){ msoLogger.debug("Caught Exception during processJavaException Method: " + e) execution.setVariable("UnexpectedError", "Exception in processJavaException method - " + Prefix) // Adding this line temporarily until this flows error handling gets updated diff --git a/bpmn/so-bpmn-infrastructure-flows/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCreateServiceInstance.groovy b/bpmn/so-bpmn-infrastructure-flows/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCreateServiceInstance.groovy index 93a260a544..b44940eb20 100644 --- a/bpmn/so-bpmn-infrastructure-flows/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCreateServiceInstance.groovy +++ b/bpmn/so-bpmn-infrastructure-flows/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCreateServiceInstance.groovy @@ -7,9 +7,9 @@ * 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. @@ -62,7 +62,7 @@ import groovy.json.* * @param - failExists - TODO * @param - serviceInputParams (should contain aic_zone for serviceTypes TRANSPORT,ATM) * @param - sdncVersion ("1610") - * @param - serviceDecomposition - Decomposition for R1710 + * @param - serviceDecomposition - Decomposition for R1710 * (if macro provides serviceDecompsition then serviceModelInfo, serviceInstanceId & serviceInstanceName will be ignored) * * Outputs: @@ -71,7 +71,7 @@ import groovy.json.* * @param - WorkflowException * @param - serviceInstanceName - (GET from AAI if null in input) * - * This BB processes Macros(except TRANSPORT all sent to sdnc) and Alacartes(sdncSvcs && nonSdncSvcs) + * This BB processes Macros(except TRANSPORT all sent to sdnc) and Alacartes(sdncSvcs && nonSdncSvcs) */ public class DoCreateServiceInstance extends AbstractServiceTaskProcessor { @@ -89,7 +89,7 @@ public class DoCreateServiceInstance extends AbstractServiceTaskProcessor { try { String requestId = execution.getVariable("msoRequestId") execution.setVariable("prefix", Prefix) - + setBasicDBAuthHeader(execution, isDebugEnabled) //Inputs //requestDetails.subscriberInfo. for AAI GET & PUT & SDNC assignToplology @@ -106,17 +106,17 @@ public class DoCreateServiceInstance extends AbstractServiceTaskProcessor { msoLogger.debug(msg) exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg) } - + if (isBlank(subscriptionServiceType)) { msg = "Input subscriptionServiceType is null" msoLogger.debug(msg) exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg) } - + if (productFamilyId == null) { execution.setVariable("productFamilyId", "") } - + String sdncCallbackUrl = UrnPropertiesReader.getVariable("mso.workflow.sdncadapter.callback",execution) if (isBlank(sdncCallbackUrl)) { msg = "mso.workflow.sdncadapter.callback is null" @@ -131,19 +131,19 @@ public class DoCreateServiceInstance extends AbstractServiceTaskProcessor { String modelVersion = "" String modelUuid = "" String modelName = "" - String serviceInstanceName = "" + String serviceInstanceName = "" //Generated in parent.for AAI PUT String serviceInstanceId = "" String serviceType = "" String serviceRole = "" - + ServiceDecomposition serviceDecomp = (ServiceDecomposition) execution.getVariable("serviceDecomposition") if (serviceDecomp != null) { serviceType = serviceDecomp.getServiceType() ?: "" msoLogger.debug("serviceType:" + serviceType) serviceRole = serviceDecomp.getServiceRole() ?: "" - + ServiceInstance serviceInstance = serviceDecomp.getServiceInstance() if (serviceInstance != null) { @@ -152,7 +152,7 @@ public class DoCreateServiceInstance extends AbstractServiceTaskProcessor { execution.setVariable("serviceInstanceId", serviceInstanceId) execution.setVariable("serviceInstanceName", serviceInstanceName) } - + ModelInfo modelInfo = serviceDecomp.getModelInfo() if (modelInfo != null) { @@ -161,7 +161,7 @@ public class DoCreateServiceInstance extends AbstractServiceTaskProcessor { modelUuid = modelInfo.getModelUuid() ?: "" modelName = modelInfo.getModelName() ?: "" } - else + else { msg = "Input serviceModelInfo is null" msoLogger.debug(msg) @@ -173,21 +173,21 @@ public class DoCreateServiceInstance extends AbstractServiceTaskProcessor { //requestDetails.requestInfo. for AAI GET/PUT serviceInstanceData & SDNC assignToplology serviceInstanceName = execution.getVariable("serviceInstanceName") ?: "" serviceInstanceId = execution.getVariable("serviceInstanceId") ?: "" - + String serviceModelInfo = execution.getVariable("serviceModelInfo") if (isBlank(serviceModelInfo)) { msg = "Input serviceModelInfo is null" msoLogger.debug(msg) exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg) - } + } modelInvariantUuid = jsonUtil.getJsonValue(serviceModelInfo, "modelInvariantUuid") ?: "" modelVersion = jsonUtil.getJsonValue(serviceModelInfo, "modelVersion") ?: "" modelUuid = jsonUtil.getJsonValue(serviceModelInfo, "modelUuid") ?: "" modelName = jsonUtil.getJsonValue(serviceModelInfo, "modelName") ?: "" //modelCustomizationUuid NA for SI - + } - + execution.setVariable("serviceType", serviceType) execution.setVariable("serviceRole", serviceRole) execution.setVariable("serviceInstanceName", serviceInstanceName) @@ -196,7 +196,7 @@ public class DoCreateServiceInstance extends AbstractServiceTaskProcessor { execution.setVariable("modelVersion", modelVersion) execution.setVariable("modelUuid", modelUuid) execution.setVariable("modelName", modelName) - + //alacarte SIs are NOT sent to sdnc. exceptions are listed in config variable String svcTypes = UrnPropertiesReader.getVariable("sdnc.si.svc.types",execution) ?: "" msoLogger.debug("SDNC SI serviceTypes:" + svcTypes) @@ -208,13 +208,13 @@ public class DoCreateServiceInstance extends AbstractServiceTaskProcessor { break; } } - + //All Macros are sent to SDNC, TRANSPORT(Macro) is sent to SDNW //Alacartes are sent to SDNC if they are listed in config variable above execution.setVariable("sendToSDNC", true) if(execution.getVariable("sdncVersion").equals("1610")) //alacarte { - if(!isSdncService){ + if(!isSdncService){ execution.setVariable("sendToSDNC", false) //alacarte non-sdnc svcs must provide name (sdnc provides name for rest) if (isBlank(execution.getVariable("serviceInstanceName" ))) @@ -225,25 +225,25 @@ public class DoCreateServiceInstance extends AbstractServiceTaskProcessor { } } } - + msoLogger.debug("isSdncService: " + isSdncService) msoLogger.debug("Send To SDNC: " + execution.getVariable("sendToSDNC")) msoLogger.debug("Service Type: " + execution.getVariable("serviceType")) - + //macro may provide name and alacarte-portm may provide name execution.setVariable("checkAAI", false) if (!isBlank(execution.getVariable("serviceInstanceName" ))) { execution.setVariable("checkAAI", true) } - + if (isBlank(serviceInstanceId)){ msg = "Input serviceInstanceId is null" msoLogger.debug(msg) exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg) } - - + + StringBuilder sbParams = new StringBuilder() Map<String, String> paramsMap = execution.getVariable("serviceInputParams") if (paramsMap != null) @@ -278,16 +278,16 @@ public class DoCreateServiceInstance extends AbstractServiceTaskProcessor { String statusLine = isBlank(oStatus) ? "" : "<orchestration-status>${MsoUtils.xmlEscape(oStatus)}</orchestration-status>" String serviceTypeLine = isBlank(serviceType) ? "" : "<service-type>${MsoUtils.xmlEscape(serviceType)}</service-type>" String serviceRoleLine = isBlank(serviceRole) ? "" : "<service-role>${MsoUtils.xmlEscape(serviceRole)}</service-role>" - + //QUERY CATALOG DB AND GET WORKLOAD / ENVIRONMENT CONTEXT String environmentContext = "" String workloadContext ="" - + try{ String json = cutils.getServiceResourcesByServiceModelInvariantUuidString(execution,modelInvariantUuid ) - + msoLogger.debug("JSON IS: "+json) - + environmentContext = jsonUtil.getJsonValue(json, "serviceResources.environmentContext") ?: "" workloadContext = jsonUtil.getJsonValue(json, "serviceResources.workloadContext") ?: "" msoLogger.debug("Env Context is: "+ environmentContext) @@ -299,7 +299,7 @@ public class DoCreateServiceInstance extends AbstractServiceTaskProcessor { msoLogger.debug(msg) exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) } - + //Create AAI Payload AaiUtil aaiUriUtil = new AaiUtil(this) String aai_uri = aaiUriUtil.getBusinessCustomerUri(execution) @@ -318,7 +318,7 @@ public class DoCreateServiceInstance extends AbstractServiceTaskProcessor { execution.setVariable("serviceInstanceData", serviceInstanceData) msoLogger.debug(" 'payload' to create Service Instance in AAI - " + "\n" + serviceInstanceData) - + } catch (BpmnError e) { throw e; } catch (Exception ex){ @@ -329,7 +329,6 @@ public class DoCreateServiceInstance extends AbstractServiceTaskProcessor { msoLogger.trace("Exit preProcessRequest") } - //TODO: Will be able to replace with call to GenericGetService public void getAAICustomerById (DelegateExecution execution) { // https://{aaiEP}/aai/v8/business/customers/customer/{globalCustomerId} def isDebugEnabled = execution.getVariable("isDebugLogEnabled") @@ -400,47 +399,6 @@ public class DoCreateServiceInstance extends AbstractServiceTaskProcessor { } - public void postProcessAAIGET(DelegateExecution execution) { - def isDebugEnabled=execution.getVariable("isDebugLogEnabled") - msoLogger.trace("postProcessAAIGET") - String msg = "" - - try { - String serviceInstanceName = execution.getVariable("serviceInstanceName") - boolean succInAAI = execution.getVariable("GENGS_SuccessIndicator") - if(!succInAAI){ - msoLogger.debug("Error getting Service-instance from AAI", + serviceInstanceName) - WorkflowException workflowException = execution.getVariable("WorkflowException") - if(workflowException != null){ - exceptionUtil.buildAndThrowWorkflowException(execution, workflowException.getErrorCode(), workflowException.getErrorMessage()) - } - else - { - msg = "Failure in postProcessAAIGET GENGS_SuccessIndicator:" + succInAAI - msoLogger.debug(msg) - exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg) - } - } - else - { - boolean foundInAAI = execution.getVariable("GENGS_FoundIndicator") - if(foundInAAI){ - msoLogger.debug("Found Service-instance in AAI") - msg = "ServiceInstance already exists in AAI:" + serviceInstanceName - msoLogger.debug(msg) - exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg) - } - } - } catch (BpmnError e) { - throw e; - } catch (Exception ex) { - msg = "Exception in DoCreateServiceInstance.postProcessAAIGET. " + ex.getMessage() - msoLogger.debug(msg) - exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) - } - msoLogger.trace("Exit postProcessAAIGET") - } - public void postProcessAAIPUT(DelegateExecution execution) { def isDebugEnabled=execution.getVariable("isDebugLogEnabled") msoLogger.trace("postProcessAAIPUT") @@ -498,17 +456,17 @@ public class DoCreateServiceInstance extends AbstractServiceTaskProcessor { def modelVersion = execution.getVariable("modelVersion") def modelUuid = execution.getVariable("modelUuid") def modelName = execution.getVariable("modelName") - + def sdncRequestId = UUID.randomUUID().toString() - + def siParamsXml = execution.getVariable("siParamsXml") - + // special URL for SDNW, msoAction helps set diff url in SDNCA if("TRANSPORT".equalsIgnoreCase(execution.getVariable("serviceType"))) { msoAction = "TRANSPORT" } - + String sdncAssignRequest = """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.onap/so/request/types/v1" xmlns:sdncadapterworkflow="http://org.onap/so/workflow/schema/v1" @@ -563,7 +521,7 @@ public class DoCreateServiceInstance extends AbstractServiceTaskProcessor { rollbackData.put("SERVICEINSTANCE", "sdncDeactivate", sdncDeactivate) rollbackData.put("SERVICEINSTANCE", "sdncDelete", sdncDelete) execution.setVariable("rollbackData", rollbackData) - + msoLogger.debug("rollbackData:\n" + rollbackData.toString()) } catch (BpmnError e) { @@ -575,7 +533,7 @@ public class DoCreateServiceInstance extends AbstractServiceTaskProcessor { } msoLogger.trace("Exit preProcessSDNCAssignRequest") } - + public void postProcessSDNCAssign (DelegateExecution execution) { def isDebugEnabled=execution.getVariable("isDebugLogEnabled") msoLogger.trace("postProcessSDNCAssign") @@ -612,7 +570,7 @@ public class DoCreateServiceInstance extends AbstractServiceTaskProcessor { } msoLogger.trace("Exit postProcessSDNCAssign") } - + public void postProcessAAIGET2(DelegateExecution execution) { def isDebugEnabled=execution.getVariable("isDebugLogEnabled") msoLogger.trace("postProcessAAIGET2") @@ -660,7 +618,7 @@ public class DoCreateServiceInstance extends AbstractServiceTaskProcessor { def isDebugEnabled=execution.getVariable("isDebugLogEnabled") msoLogger.trace("preProcessRollback") try { - + Object workflowException = execution.getVariable("WorkflowException"); if (workflowException instanceof WorkflowException) { @@ -697,19 +655,19 @@ public class DoCreateServiceInstance extends AbstractServiceTaskProcessor { } msoLogger.trace("Exit postProcessRollback") } - + public void createProject(DelegateExecution execution) { def isDebugEnabled=execution.getVariable("isDebugLogEnabled") msoLogger.trace("createProject") - String bpmnRequest = execution.getVariable("requestJson") - String projectName = jsonUtil.getJsonValue(bpmnRequest, "requestDetails.project.projectName") + String bpmnRequest = execution.getVariable("requestJson") + String projectName = jsonUtil.getJsonValue(bpmnRequest, "requestDetails.project.projectName") String serviceInstance = execution.getVariable("serviceInstanceId") - + msoLogger.debug("BPMN REQUEST IS: "+ bpmnRequest) msoLogger.debug("PROJECT NAME: " + projectName) msoLogger.debug("Service Instance: " + serviceInstance) - + if(projectName == null||projectName.equals("")){ msoLogger.debug("Project Name was not found in input. Skipping task...") }else{ @@ -722,27 +680,27 @@ public class DoCreateServiceInstance extends AbstractServiceTaskProcessor { msoLogger.error(ex); exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) } - } + } msoLogger.trace("Exit createProject") } - + public void createOwningEntity(DelegateExecution execution) { def isDebugEnabled=execution.getVariable("isDebugLogEnabled") msoLogger.trace("createOwningEntity") String msg = ""; - String bpmnRequest = execution.getVariable("requestJson") - String owningEntityId = jsonUtil.getJsonValue(bpmnRequest, "requestDetails.owningEntity.owningEntityId") + String bpmnRequest = execution.getVariable("requestJson") + String owningEntityId = jsonUtil.getJsonValue(bpmnRequest, "requestDetails.owningEntity.owningEntityId") String owningEntityName = jsonUtil.getJsonValue(bpmnRequest,"requestDetails.owningEntity.owningEntityName"); String serviceInstance = execution.getVariable("serviceInstanceId") - + msoLogger.debug("owningEntity: " + owningEntityId) msoLogger.debug("OwningEntityName: "+ owningEntityName) msoLogger.debug("Service Instance: " + serviceInstance) - + try{ AAICreateResources aaiCR = new AAICreateResources() if(owningEntityId==null||owningEntityId.equals("")){ - msg = "Exception in createOwningEntity. OwningEntityId is null in input."; + msg = "Exception in createOwningEntity. OwningEntityId is null in input."; throw new IllegalStateException(); }else{ if(aaiCR.existsOwningEntity(owningEntityId)){ @@ -769,21 +727,21 @@ public class DoCreateServiceInstance extends AbstractServiceTaskProcessor { } msoLogger.trace("Exit createOwningEntity") } - + // ******************************* // Build Error Section // ******************************* public void processJavaException(DelegateExecution execution){ def isDebugEnabled=execution.getVariable("isDebugLogEnabled") - + try{ msoLogger.debug("Caught a Java Exception in DoCreateServiceInstance") msoLogger.debug("Started processJavaException Method") msoLogger.debug("Variables List: " + execution.getVariables()) execution.setVariable("UnexpectedError", "Caught a Java Lang Exception in DoCreateServiceInstance") // Adding this line temporarily until this flows error handling gets updated exceptionUtil.buildWorkflowException(execution, 500, "Caught a Java Lang Exception in DoCreateServiceInstance") - + }catch(Exception e){ msoLogger.debug("Caught Exception during processJavaException Method: " + e) execution.setVariable("UnexpectedError", "Exception in processJavaException") // Adding this line temporarily until this flows error handling gets updated diff --git a/bpmn/so-bpmn-infrastructure-flows/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCreateVfModuleVolumeV2.groovy b/bpmn/so-bpmn-infrastructure-flows/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCreateVfModuleVolumeV2.groovy index f734ffb3ff..f87f32c610 100644 --- a/bpmn/so-bpmn-infrastructure-flows/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCreateVfModuleVolumeV2.groovy +++ b/bpmn/so-bpmn-infrastructure-flows/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCreateVfModuleVolumeV2.groovy @@ -7,9 +7,9 @@ * 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. @@ -35,6 +35,14 @@ import org.onap.so.bpmn.core.json.JsonUtils; import org.onap.so.logger.MsoLogger import org.onap.so.rest.APIResponse import org.springframework.web.util.UriUtils +import org.onap.so.client.aai.AAIResourcesClient +import org.onap.so.client.aai.AAIObjectType +import org.onap.so.client.aai.entities.AAIResultWrapper +import org.onap.so.client.aai.entities.Relationships +import org.onap.so.client.aai.entities.uri.AAIResourceUri +import org.onap.so.client.aai.entities.uri.AAIUriFactory +import org.json.JSONObject +import javax.ws.rs.NotFoundException class DoCreateVfModuleVolumeV2 extends VfModuleBase { @@ -53,16 +61,16 @@ class DoCreateVfModuleVolumeV2 extends VfModuleBase { } public void preProcessRequest(DelegateExecution execution, isDebugLogEnabled) { - + execution.setVariable("prefix",prefix) execution.setVariable(prefix+'SuccessIndicator', false) execution.setVariable(prefix+'isPONR', false) displayInput(execution, isDebugLogEnabled) setRollbackData(execution, isDebugLogEnabled) - setRollbackEnabled(execution, isDebugLogEnabled) - - + setRollbackEnabled(execution, isDebugLogEnabled) + + def tenantId = execution.getVariable("tenantId") if (tenantId == null) { String cloudConfiguration = execution.getVariable("cloudConfiguration") @@ -84,17 +92,17 @@ class DoCreateVfModuleVolumeV2 extends VfModuleBase { def modelCustomizationUuid = jsonUtil.getJsonValue(vfModuleModelInfo, "modelCustomizationUuid") execution.setVariable("modelCustomizationId", modelCustomizationUuid) msoLogger.debug("modelCustomizationId: " + modelCustomizationUuid) - + //modelName def modelName = jsonUtil.getJsonValue(vfModuleModelInfo, "modelName") execution.setVariable("modelName", modelName) msoLogger.debug("modelName: " + modelName) - + // The following is used on the get Generic Service Instance call execution.setVariable('GENGS_type', 'service-instance') } - + /** * Display input variables * @param execution @@ -111,10 +119,10 @@ class DoCreateVfModuleVolumeV2 extends VfModuleBase { } msoLogger.debug('End input.') } - - + + /** - * Define and set rollbackdata object + * Define and set rollbackdata object * @param execution * @param isDebugEnabled */ @@ -127,25 +135,29 @@ class DoCreateVfModuleVolumeV2 extends VfModuleBase { rollbackData.put("DCVFMODULEVOL", "volumeGroupName", volumeGroupName) execution.setVariable("rollbackData", rollbackData) } - - + + /** - * validate getServiceInstance response - * @param execution - * @param isDebugEnabled + * Gets the service instance uri from aai */ - public void validateGetServiceInstanceCall(DelegateExecution execution, isDebugEnabled) { - def found = execution.getVariable('GENGS_FoundIndicator') - def success = execution.getVariable('GENGS_SuccessIndicator') - def serviceInstanceId = execution.getVariable('serviceInstanceId') - msoLogger.debug("getServiceInstance success: " + success) - msoLogger.debug("getServiceInstance found: " + found) - if(!found || !success) { - String errorMessage = "Service instance id not found in AAI: ${serviceInstanceId}." - msoLogger.debug(errorMessage) - (new ExceptionUtil()).buildAndThrowWorkflowException(execution, 2500, errorMessage) + public void getServiceInstance(DelegateExecution execution) { + try { + String serviceInstanceId = execution.getVariable('serviceInstanceId') + + AAIResourcesClient resourceClient = new AAIResourcesClient() + AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, serviceInstanceId) + + if(!resourceClient.exists(uri)){ + (new ExceptionUtil()).buildAndThrowWorkflowException(execution, 2500, "Service instance was not found in aai") + } + + }catch(BpmnError e) { + throw e; + }catch (Exception ex){ + String msg = "Exception in getServiceInstance. " + ex.getMessage() + msoLogger.debug(msg) + (new ExceptionUtil()).buildAndThrowWorkflowException(execution, 2500, msg) } - } /** @@ -175,7 +187,7 @@ class DoCreateVfModuleVolumeV2 extends VfModuleBase { msoLogger.debug(errorMessage) (new ExceptionUtil()).buildAndThrowWorkflowException(execution, 2500, errorMessage) } - + def poCloudRegion = aaiUtil.getAAICloudReqion(execution, queryCloudRegionRequest, "PO", cloudRegion) if ((poCloudRegion != "ERROR")) { execution.setVariable("poLcpCloudRegionId", poCloudRegion) @@ -185,7 +197,7 @@ class DoCreateVfModuleVolumeV2 extends VfModuleBase { msoLogger.debug(errorMessage) (new ExceptionUtil()).buildAndThrowWorkflowException(execution, 2500, errorMessage) } - + def rollbackData = execution.getVariable("rollbackData") rollbackData.put("DCVFMODULEVOL", "aiccloudregion", cloudRegion) } @@ -242,7 +254,7 @@ class DoCreateVfModuleVolumeV2 extends VfModuleBase { /** - * Create a WorkflowException + * Create a WorkflowException * @param execution * @param isDebugEnabled */ @@ -265,7 +277,7 @@ class DoCreateVfModuleVolumeV2 extends VfModuleBase { throw new BpmnError("MSOWorkflowException") } - + /** * Create volume group in AAI * @param execution @@ -280,7 +292,7 @@ class DoCreateVfModuleVolumeV2 extends VfModuleBase { def vnfType = execution.getVariable("vnfType") def tenantId = execution.getVariable("tenantId") def cloudRegion = execution.getVariable('lcpCloudRegionId') - + msoLogger.debug("volumeGroupId: " + volumeGroupId) def testGroupId = execution.getVariable('test-volume-group-id') @@ -316,7 +328,7 @@ class DoCreateVfModuleVolumeV2 extends VfModuleBase { execution.setVariable(prefix+"createAAIVolumeGrpNameReturnCode", returnCode) execution.setVariable(prefix+"createAAIVolumeGrpNameResponse", aaiResponseAsString) - + ExceptionUtil exceptionUtil = new ExceptionUtil() if (returnCode =='201') { @@ -333,7 +345,7 @@ class DoCreateVfModuleVolumeV2 extends VfModuleBase { } } } - + /** * Prepare VNF adapter create request XML @@ -345,7 +357,7 @@ class DoCreateVfModuleVolumeV2 extends VfModuleBase { def vnfId = utils.getNodeText(aaiGenericVnfResponse, 'vnf-id') def vnfName = utils.getNodeText(aaiGenericVnfResponse, 'vnf-name') def vnfType = utils.getNodeText(aaiGenericVnfResponse, "vnf-type") - + def requestId = execution.getVariable('msoRequestId') def serviceId = execution.getVariable('serviceInstanceId') def cloudSiteId = execution.getVariable('poLcpCloudRegionId') @@ -353,11 +365,11 @@ class DoCreateVfModuleVolumeV2 extends VfModuleBase { def volumeGroupId = execution.getVariable('volumeGroupId') def volumeGroupnName = execution.getVariable('volumeGroupName') - def vnfVersion = execution.getVariable("asdcServiceModelVersion") + def vnfVersion = execution.getVariable("asdcServiceModelVersion") def vnfModuleType = execution.getVariable("modelName") def modelCustomizationId = execution.getVariable("modelCustomizationId") - + // for testing msoLogger.debug("volumeGroupId: " + volumeGroupId) def testGroupId = execution.getVariable('test-volume-group-id') @@ -367,9 +379,9 @@ class DoCreateVfModuleVolumeV2 extends VfModuleBase { execution.setVariable("test-volume-group-name", "MSOTESTVOL101a-vSAMP12_base_vol_module-0") } msoLogger.debug("volumeGroupId to be used: " + volumeGroupId) - + // volume group parameters - + String volumeGroupParams = '' StringBuilder sbParams = new StringBuilder() Map<String, String> paramsMap = execution.getVariable("vfModuleInputParams") @@ -396,17 +408,17 @@ class DoCreateVfModuleVolumeV2 extends VfModuleBase { if(failIfExists == null) { failIfExists = 'true' } - + String messageId = UUID.randomUUID() msoLogger.debug("messageId to be used is generated: " + messageId) - + def notificationUrl = createCallbackURL(execution, "VNFAResponse", messageId) def useQualifiedHostName = UrnPropertiesReader.getVariable("mso.use.qualified.host",execution) if ('true'.equals(useQualifiedHostName)) { notificationUrl = utils.getQualifiedHostNameForCallback(notificationUrl) } msoLogger.debug("CreateVfModuleVolume - notificationUrl: "+ notificationUrl) - + // build request String vnfSubCreateWorkflowRequest = """ @@ -465,9 +477,9 @@ class DoCreateVfModuleVolumeV2 extends VfModuleBase { String vnfSubRollbackWorkflowRequestAsString = utils.formatXml(vnfSubRollbackWorkflowRequest) execution.setVariable(prefix+"rollbackVnfARequest", vnfSubRollbackWorkflowRequestAsString) } - + public String buildRollbackVolumeGroupRequestXml(volumeGroupId, cloudSiteId, tenantId, requestId, serviceId, messageId, notificationUrl) { - + def request = """ <rollbackVolumeGroupRequest> <volumeGroupRollback> @@ -485,16 +497,16 @@ class DoCreateVfModuleVolumeV2 extends VfModuleBase { <skipAAI>true</skipAAI> <notificationUrl>${MsoUtils.xmlEscape(notificationUrl)}</notificationUrl> </rollbackVolumeGroupRequest> - """ - - return request + """ + + return request } public String updateRollbackVolumeGroupRequestXml(String rollabackRequest, String heatStackId) { String newRequest = rollabackRequest.replace("{{VOLUMEGROUPSTACKID}}", heatStackId) return newRequest } - + /** * Validate VNF adapter response * @param execution @@ -513,10 +525,10 @@ class DoCreateVfModuleVolumeV2 extends VfModuleBase { rollbackData.put("DCVFMODULEVOL", "isCreateVnfRollbackNeeded", "true") } } - + /** - * Update voulume group in AAI + * Update voulume group in AAI * @TODO: Can we re-use the create method?? * @param execution * @param isDebugEnabled @@ -525,7 +537,7 @@ class DoCreateVfModuleVolumeV2 extends VfModuleBase { String requeryAAIVolGrpNameResponse = execution.getVariable(prefix+"queryAAIVolGrpNameResponse") String volumeGroupId = utils.getNodeText(requeryAAIVolGrpNameResponse, "volume-group-id") - String modelCustomizationId = execution.getVariable("modelCustomizationId") + String modelCustomizationId = execution.getVariable("modelCustomizationId") String cloudRegion = execution.getVariable("lcpCloudRegionId") AaiUtil aaiUtil = new AaiUtil(this) @@ -538,7 +550,7 @@ class DoCreateVfModuleVolumeV2 extends VfModuleBase { String createVnfAResponse = execution.getVariable(prefix+"createVnfAResponse") def heatStackID = utils.getNodeText(createVnfAResponse, "volumeGroupStackId") - + execution.setVariable(prefix+"heatStackId", heatStackID) NetworkUtils networkUtils = new NetworkUtils() diff --git a/bpmn/so-bpmn-infrastructure-flows/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCreateVnf.groovy b/bpmn/so-bpmn-infrastructure-flows/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCreateVnf.groovy index 46a502e124..7fa8b4409b 100644 --- a/bpmn/so-bpmn-infrastructure-flows/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCreateVnf.groovy +++ b/bpmn/so-bpmn-infrastructure-flows/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCreateVnf.groovy @@ -43,6 +43,7 @@ import org.onap.so.client.aai.entities.AAIResultWrapper import org.onap.so.client.aai.entities.uri.AAIResourceUri import org.onap.so.client.aai.entities.uri.AAIUriFactory; import org.springframework.web.util.UriUtils +import org.json.JSONObject /** @@ -247,6 +248,32 @@ class DoCreateVnf extends AbstractServiceTaskProcessor { msoLogger.trace("COMPLETED DoCreateVnf PreProcessRequest Process") } + /** + * Gets the service instance from aai + */ + public void getServiceInstance(DelegateExecution execution) { + try { + String serviceInstanceId = execution.getVariable('DoCVNF_serviceInstanceId') + + AAIResourcesClient resourceClient = new AAIResourcesClient() + AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, serviceInstanceId) + + if(resourceClient.exists(uri)){ + execution.setVariable("GENGS_siResourceLink", uri.build().toString()) + + }else{ + exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Service instance was not found in aai") + } + + }catch(BpmnError e) { + throw e; + }catch(Exception ex) { + String msg = "Exception in getServiceInstance. " + ex.getMessage() + msoLogger.debug(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) + } + } + private Object getVariableEnforced(DelegateExecution execution, String name){ Object enforced = execution.getVariable(name) if(!enforced){ diff --git a/bpmn/so-bpmn-infrastructure-flows/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCustomDeleteE2EServiceInstanceV2.groovy b/bpmn/so-bpmn-infrastructure-flows/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCustomDeleteE2EServiceInstanceV2.groovy index 20a7f43de7..21bf0f2c5c 100644 --- a/bpmn/so-bpmn-infrastructure-flows/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCustomDeleteE2EServiceInstanceV2.groovy +++ b/bpmn/so-bpmn-infrastructure-flows/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCustomDeleteE2EServiceInstanceV2.groovy @@ -37,7 +37,14 @@ import org.onap.so.logger.MessageEnum import org.onap.so.logger.MsoLogger import org.onap.so.rest.APIResponse; import org.springframework.web.util.UriUtils; - +import org.onap.so.client.aai.AAIResourcesClient +import org.onap.so.client.aai.AAIObjectType +import org.onap.so.client.aai.entities.AAIResultWrapper +import org.onap.so.client.aai.entities.Relationships +import org.onap.so.client.aai.entities.uri.AAIResourceUri +import org.onap.so.client.aai.entities.uri.AAIUriFactory +import org.json.JSONObject +import javax.ws.rs.NotFoundException import groovy.json.* @@ -149,63 +156,32 @@ public class DoCustomDeleteE2EServiceInstanceV2 extends AbstractServiceTaskProce msoLogger.info("Exited " + method) } - - - public void postProcessAAIGET(DelegateExecution execution) { - def method = getClass().getSimpleName() + '.postProcessAAIGET(' +'execution=' + execution.getId() +')' - msoLogger.info("Entered " + method) - - String msg = "" - + /** + * Gets the service instance and its relationships from aai + * + * @author cb645j + */ + public void getServiceInstance(DelegateExecution execution) { try { - String serviceInstanceId = execution.getVariable("serviceInstanceId") - msoLogger.info("serviceInstanceId: "+serviceInstanceId) - - boolean foundInAAI = execution.getVariable("GENGS_FoundIndicator") - msoLogger.info("foundInAAI: "+foundInAAI) - - String serviceType = "" - - - if(foundInAAI){ - msoLogger.info("Found Service-instance in AAI") + String serviceInstanceId = execution.getVariable('serviceInstanceId') + String globalSubscriberId = execution.getVariable('globalSubscriberId') + String serviceType = execution.getVariable('serviceType') - String siData = execution.getVariable("GENGS_service") - msoLogger.info("SI Data") - if (isBlank(siData)) - { - msg = "Could not retrive ServiceInstance data from AAI to delete id:" + serviceInstanceId - msoLogger.info(msg) - exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg) - } + AAIResourcesClient resourceClient = new AAIResourcesClient() + AAIResourceUri serviceInstanceUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, globalSubscriberId, serviceType, serviceInstanceId) + AAIResultWrapper wrapper = resourceClient.get(serviceInstanceUri, NotFoundException.class) + String json = wrapper.getJson() - }else{ - boolean succInAAI = execution.getVariable("GENGS_SuccessIndicator") - if(!succInAAI){ - msoLogger.info("Error getting Service-instance from AAI", + serviceInstanceId) - WorkflowException workflowException = execution.getVariable("WorkflowException") - msoLogger.debug("workflowException: " + workflowException) - if(workflowException != null){ - exceptionUtil.buildAndThrowWorkflowException(execution, workflowException.getErrorCode(), workflowException.getErrorMessage()) - } - else - { - msg = "Failure in postProcessAAIGET GENGS_SuccessIndicator:" + succInAAI - msoLogger.info(msg) - exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg) - } - } + execution.setVariable("serviceInstance", json) - msoLogger.info("Service-instance NOT found in AAI. Silent Success") - } - }catch (BpmnError e) { + }catch(BpmnError e) { throw e; - } catch (Exception ex) { - msg = "Bpmn error encountered in " + method + "--" + ex.getMessage() - msoLogger.info(msg) + }catch(NotFoundException e) { + msoLogger.info("SI not found in aai. Silent Success ") + }catch(Exception ex) { + String msg = "Internal Error in getServiceInstance: " + ex.getMessage() exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) } - msoLogger.info("Exited " + method) } private void loadResourcesProperties(DelegateExecution execution) { @@ -334,23 +310,14 @@ public class DoCustomDeleteE2EServiceInstanceV2 extends AbstractServiceTaskProce String serviceInstanceId = execution.getVariable("serviceInstanceId") - // confirm if ServiceInstance was found - if ( !execution.getVariable("GENGS_FoundIndicator") ) - { - String exceptionMessage = "Bpmn error encountered in DeleteMobileAPNCustService flow. Service Instance was not found in AAI by id: " + serviceInstanceId - exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage) - } execution.setVariable(Prefix+"resourceList", "") execution.setVariable(Prefix+"resourceCount", 0) execution.setVariable(Prefix+"nextResource", 0) execution.setVariable(Prefix+"resourceFinish", true) - // get SI extracted by GenericGetService - String serviceInstanceAaiRecord = execution.getVariable("GENGS_service"); - msoLogger.info("serviceInstanceAaiRecord: " +serviceInstanceAaiRecord) - - String aaiJsonRecord = jsonUtil.xml2json(serviceInstanceAaiRecord) + String aaiJsonRecord = execution.getVariable("serviceInstance"); + msoLogger.info("serviceInstanceAaiRecord: " +aaiJsonRecord) msoLogger.info("aaiJsonRecord: " +aaiJsonRecord) def serviceInstanceName = jsonUtil.getJsonValue(aaiJsonRecord, "service-instance.service-instance-name") diff --git a/bpmn/so-bpmn-infrastructure-flows/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeleteServiceInstance.groovy b/bpmn/so-bpmn-infrastructure-flows/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeleteServiceInstance.groovy index 198144ad34..c7e3eb437c 100644 --- a/bpmn/so-bpmn-infrastructure-flows/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeleteServiceInstance.groovy +++ b/bpmn/so-bpmn-infrastructure-flows/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeleteServiceInstance.groovy @@ -22,12 +22,10 @@ package org.onap.so.bpmn.infrastructure.scripts import static org.apache.commons.lang3.StringUtils.*; -import javax.xml.parsers.DocumentBuilder -import javax.xml.parsers.DocumentBuilderFactory - import org.apache.commons.lang3.* import org.camunda.bpm.engine.delegate.BpmnError import org.camunda.bpm.engine.delegate.DelegateExecution +import org.onap.aai.domain.yang.ServiceInstance import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor import org.onap.so.bpmn.common.scripts.ExceptionUtil import org.onap.so.bpmn.common.scripts.MsoUtils @@ -35,17 +33,13 @@ import org.onap.so.bpmn.common.scripts.SDNCAdapterUtils 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.logger.MsoLogger -import org.onap.so.client.aai.entities.uri.AAIResourceUri -import org.onap.so.client.aai.entities.uri.AAIUriFactory import org.onap.so.client.aai.AAIObjectType import org.onap.so.client.aai.AAIResourcesClient +import org.onap.so.client.aai.entities.AAIResultWrapper +import org.onap.so.client.aai.entities.uri.AAIResourceUri +import org.onap.so.client.aai.entities.uri.AAIUriFactory +import org.onap.so.logger.MsoLogger import org.springframework.web.util.UriUtils; -import org.w3c.dom.Document -import org.w3c.dom.Element -import org.w3c.dom.Node -import org.w3c.dom.NodeList -import org.xml.sax.InputSource import groovy.json.* @@ -282,170 +276,86 @@ public class DoDeleteServiceInstance extends AbstractServiceTaskProcessor { msoLogger.trace("Exit postProcessSDNC " + method + " ") } - public void postProcessAAIGET(DelegateExecution execution) { - - msoLogger.trace("postProcessAAIGET ") - String msg = "" - + /** + * Gets the service instance uri from aai + */ + public void getServiceInstance(DelegateExecution execution) { + msoLogger.trace("getServiceInstance ") try { - - String serviceInstanceId = execution.getVariable("serviceInstanceId") - boolean foundInAAI = execution.getVariable("GENGS_FoundIndicator") - String serviceType = "" - - if(foundInAAI == true){ - msoLogger.debug("Found Service-instance in AAI") - - //Extract GlobalSubscriberId - String siRelatedLink = execution.getVariable("GENGS_siResourceLink") - if (isBlank(siRelatedLink)) - { - msg = "Could not retrive ServiceInstance data from AAI to delete id:" + serviceInstanceId - msoLogger.debug(msg) - exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg) + String serviceInstanceId = execution.getVariable('serviceInstanceId') + + AAIResourcesClient resourceClient = new AAIResourcesClient() + AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, serviceInstanceId) + + if(resourceClient.exists(uri)){ + execution.setVariable("GENGS_siResourceLink", uri.build().toString()) + Map<String, String> keys = uri.getURIKeys() + String globalSubscriberId = execution.getVariable("globalSubscriberId") + if(isBlank(globalSubscriberId)){ + globalSubscriberId = keys.get("global-customer-id") + execution.setVariable("globalSubscriberId", globalSubscriberId) } - else - { - msoLogger.debug("Found Service-instance in AAI. link: " + siRelatedLink) - String globalSubscriberId = execution.getVariable("globalSubscriberId") - if(isBlank(globalSubscriberId)){ - int custStart = siRelatedLink.indexOf("customer/") - int custEnd = siRelatedLink.indexOf("/service-subscriptions") - globalSubscriberId = siRelatedLink.substring(custStart + 9, custEnd) - execution.setVariable("globalSubscriberId", globalSubscriberId) - } - - //Extract Service Type if not provided on request - String subscriptionServiceType = execution.getVariable("subscriptionServiceType") - if(isBlank(subscriptionServiceType)){ - int serviceStart = siRelatedLink.indexOf("service-subscription/") - int serviceEnd = siRelatedLink.indexOf("/service-instances/") - String serviceTypeEncoded = siRelatedLink.substring(serviceStart + 21, serviceEnd) - subscriptionServiceType = UriUtils.decode(serviceTypeEncoded, "UTF-8") - execution.setVariable("subscriptionServiceType", subscriptionServiceType) - } - if (isBlank(globalSubscriberId) || isBlank(subscriptionServiceType)) - { - msg = "Could not retrive global-customer-id & subscription-service-type from AAI to delete id:" + serviceInstanceId - msoLogger.debug(msg) - exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg) - } + //Extract Service Type if not provided on request + String subscriptionServiceType = execution.getVariable("subscriptionServiceType") + if(isBlank(subscriptionServiceType)){ + String serviceTypeEncoded = keys.get("service-type") //TODO will this produce as already decoded? + subscriptionServiceType = UriUtils.decode(serviceTypeEncoded, "UTF-8") + execution.setVariable("subscriptionServiceType", subscriptionServiceType) } - String siData = execution.getVariable("GENGS_service") - msoLogger.debug("SI Data") - if (isBlank(siData)) - { - msg = "Could not retrive ServiceInstance data from AAI to delete id:" + serviceInstanceId - msoLogger.debug(msg) - exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg) - } - else - { - msoLogger.debug("SI Data" + siData) - serviceType = utils.getNodeText(siData,"service-type") + AAIResultWrapper wrapper = resourceClient.get(uri) + List<AAIResourceUri> uriList = wrapper.getRelationships().get().getRelatedAAIUris(AAIObjectType.ALLOTTED_RESOURCE) + uriList.addAll(wrapper.getRelationships().get().getRelatedAAIUris(AAIObjectType.GENERIC_VNF)) + uriList.addAll(wrapper.getRelationships().get().getRelatedAAIUris(AAIObjectType.L3_NETWORK)) + + if(uriList.isEmpty){ + ServiceInstance si = wrapper.asBean(ServiceInstance.class) + String orchestrationStatus = si.getOrchestrationStatus() + String serviceType = si.getServiceType() execution.setVariable("serviceType", serviceType) - execution.setVariable("serviceRole", utils.getNodeText(siData,"service-role")) - String orchestrationStatus = utils.getNodeText(siData,"orchestration-status") - - //Confirm there are no related service instances (vnf/network or volume) - if (utils.nodeExists(siData, "relationship-list")) { - msoLogger.debug("SI Data relationship-list exists:") - InputSource source = new InputSource(new StringReader(siData)); - DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); - DocumentBuilder docBuilder = docFactory.newDocumentBuilder() - Document serviceXml = docBuilder.parse(source) - - NodeList nodeList = serviceXml.getElementsByTagName("relationship") - for (int x = 0; x < nodeList.getLength(); x++) { - Node node = nodeList.item(x) - if (node.getNodeType() == Node.ELEMENT_NODE) { - Element eElement = (Element) node - def e = eElement.getElementsByTagName("related-to").item(0).getTextContent() - if(e.equals("generic-vnf") || e.equals("l3-network") || e.equals("allotted-resource") ){ - msoLogger.debug("ServiceInstance still has relationship(s) to generic-vnfs, l3-networks or allotted-resources") - execution.setVariable("siInUse", true) - //there are relationship dependencies to this Service Instance - msg = " Stopped deleting Service Instance, it has dependencies. Service instance id: " + serviceInstanceId - msoLogger.debug(msg) - exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg) - }else{ - msoLogger.debug("Relationship NOT related to OpenStack") - } - } - } - } + execution.setVariable("serviceRole", si.getServiceRole()) - if ("TRANSPORT".equalsIgnoreCase(serviceType)) - { - if ("PendingDelete".equals(orchestrationStatus)) - { + if("TRANSPORT".equalsIgnoreCase(serviceType)){ + if("PendingDelete".equals(orchestrationStatus)){ execution.setVariable("skipDeactivate", true) + }else{ + exceptionUtil.buildAndThrowWorkflowException(execution, 500, "ServiceInstance of type TRANSPORT must in PendingDelete status to allow Delete. Orchestration-status: " + orchestrationStatus) } - else - { - msg = "ServiceInstance of type TRANSPORT must in PendingDelete status to allow Delete. Orchestration-status:" + orchestrationStatus - msoLogger.debug(msg) - exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg) - } - } - //alacarte SIs are NOT sent to sdnc. exceptions are listed in config variable String svcTypes = UrnPropertiesReader.getVariable("sdnc.si.svc.types",execution) ?: "" - msoLogger.debug("SDNC SI serviceTypes:" + svcTypes) List<String> svcList = Arrays.asList(svcTypes.split("\\s*,\\s*")); boolean isSdncService= false - for (String listEntry : svcList){ - if (listEntry.equalsIgnoreCase(serviceType)){ + for(String listEntry : svcList){ + if(listEntry.equalsIgnoreCase(serviceType)){ isSdncService = true break; } } - - //All Macros are sent to SDNC, TRANSPORT(Macro) is sent to SDNW - //Alacartes are sent to SDNC if they are listed in config variable above execution.setVariable("sendToSDNC", true) - if(execution.getVariable("sdncVersion").equals("1610")) //alacarte - { + if(execution.getVariable("sdncVersion").equals("1610")){ if(!isSdncService){ execution.setVariable("sendToSDNC", false) } } - msoLogger.debug("isSdncService: " + isSdncService) - msoLogger.debug("Send To SDNC: " + execution.getVariable("sendToSDNC")) - msoLogger.debug("Service Type: " + execution.getVariable("serviceType")) - + }else{ + execution.setVariable("siInUse", true) + msoLogger.debug("Stopped deleting Service Instance, it has dependencies") + exceptionUtil.buildAndThrowWorkflowException(execution, 500, "Stopped deleting Service Instance, it has dependencies") } }else{ - boolean succInAAI = execution.getVariable("GENGS_SuccessIndicator") - if(succInAAI != true){ - msoLogger.debug("Error getting Service-instance from AAI", + serviceInstanceId) - WorkflowException workflowException = execution.getVariable("WorkflowException") - msoLogger.debug("workflowException: " + workflowException) - if(workflowException != null){ - exceptionUtil.buildAndThrowWorkflowException(execution, workflowException.getErrorCode(), workflowException.getErrorMessage()) - } - else - { - msg = "Failure in postProcessAAIGET GENGS_SuccessIndicator:" + succInAAI - msoLogger.debug(msg) - exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg) - } - } - - msoLogger.debug("Service-instance NOT found in AAI. Silent Success") + exceptionUtil.buildAndThrowWorkflowException(execution, 500, "ServiceInstance not found in aai") } - } catch (BpmnError e) { + + }catch(BpmnError e) { throw e; - } catch (Exception ex) { - msg = "Exception in DoDeleteServiceInstance.postProcessAAIGET. " + ex.getMessage() + }catch (Exception ex){ + String msg = "Exception in getServiceInstance. " + ex.getMessage() msoLogger.debug(msg) exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) } - msoLogger.trace("Exit postProcessAAIGET ") } /** diff --git a/bpmn/so-bpmn-infrastructure-flows/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoUpdateE2EServiceInstance.groovy b/bpmn/so-bpmn-infrastructure-flows/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoUpdateE2EServiceInstance.groovy index 5fb6a9df9a..cb50fbbee6 100644 --- a/bpmn/so-bpmn-infrastructure-flows/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoUpdateE2EServiceInstance.groovy +++ b/bpmn/so-bpmn-infrastructure-flows/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoUpdateE2EServiceInstance.groovy @@ -2,14 +2,14 @@ * ============LICENSE_START======================================================= * ONAP - SO * ================================================================================ - * Copyright (C) 2018 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (C) 2018 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. @@ -53,7 +53,7 @@ import groovy.json.* * @param - serviceDecomposition_Original * @param - addResourceList * @param - delResourceList - * + * * Outputs: * @param - rollbackData (localRB->null) * @param - rolledBack (no localRB->null, localRB F->false, localRB S->true) @@ -63,15 +63,15 @@ public class DoUpdateE2EServiceInstance extends AbstractServiceTaskProcessor { String Prefix="DUPDSI_" private static final String DebugFlag = "isDebugEnabled" - + ExceptionUtil exceptionUtil = new ExceptionUtil() JsonUtils jsonUtil = new JsonUtils() public void preProcessRequest (DelegateExecution execution) { def isDebugEnabled = execution.getVariable("isDebugLogEnabled") utils.log("INFO"," ***** Enter DoUpdateE2EServiceInstance preProcessRequest *****", isDebugEnabled) - - String msg = "" + + String msg = "" try { execution.setVariable("prefix", Prefix) @@ -79,11 +79,11 @@ public class DoUpdateE2EServiceInstance extends AbstractServiceTaskProcessor { //for AAI GET & PUT & SDNC assignToplology String globalSubscriberId = execution.getVariable("globalSubscriberId") //globalCustomerId utils.log("INFO"," ***** globalSubscriberId *****" + globalSubscriberId, isDebugEnabled) - + //for AAI PUT & SDNC assignTopology String serviceType = execution.getVariable("serviceType") utils.log("INFO"," ***** serviceType *****" + serviceType, isDebugEnabled) - + //for SDNC assignTopology String productFamilyId = execution.getVariable("productFamilyId") //AAI productFamilyId @@ -92,14 +92,14 @@ public class DoUpdateE2EServiceInstance extends AbstractServiceTaskProcessor { utils.log("INFO", msg, isDebugEnabled) exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg) } - + if (isBlank(serviceType)) { msg = "Input serviceType is null" utils.log("INFO", msg, isDebugEnabled) exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg) } - - //Generated in parent for AAI + + //Generated in parent for AAI String serviceInstanceId = execution.getVariable("serviceInstanceId") if (isBlank(serviceInstanceId)){ msg = "Input serviceInstanceId is null" @@ -108,21 +108,21 @@ public class DoUpdateE2EServiceInstance extends AbstractServiceTaskProcessor { } String serviceInstanceName = execution.getVariable("serviceInstanceName") - + // user params String uuiRequest = execution.getVariable("uuiRequest") - + // target model Invariant uuid String modelInvariantUuid = jsonUtil.getJsonValue(uuiRequest, "service.serviceInvariantUuid") - execution.setVariable("modelInvariantUuid", modelInvariantUuid) - utils.log("INFO", "modelInvariantUuid: " + modelInvariantUuid, isDebugEnabled) - + execution.setVariable("modelInvariantUuid", modelInvariantUuid) + utils.log("INFO", "modelInvariantUuid: " + modelInvariantUuid, isDebugEnabled) + // target model uuid String modelUuid = jsonUtil.getJsonValue(uuiRequest, "service.serviceUuid") execution.setVariable("modelUuid", modelUuid) - + utils.log("INFO","modelUuid: " + modelUuid, isDebugEnabled) - + } catch (BpmnError e) { throw e; } catch (Exception ex){ @@ -130,10 +130,10 @@ public class DoUpdateE2EServiceInstance extends AbstractServiceTaskProcessor { utils.log("INFO", msg, isDebugEnabled) exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) } - utils.log("INFO", "======== COMPLETED preProcessRequest Process ======== ", isDebugEnabled) + utils.log("INFO", "======== COMPLETED preProcessRequest Process ======== ", isDebugEnabled) } - + public void preInitResourcesOperStatus(DelegateExecution execution){ def isDebugEnabled = execution.getVariable("isDebugLogEnabled") @@ -161,7 +161,7 @@ public class DoUpdateE2EServiceInstance extends AbstractServiceTaskProcessor { for(Resource resource : resourceList){ resourceTemplateUUIDs = resourceTemplateUUIDs + resource.getModelInfo().getModelCustomizationUuid() + ":" } - + def dbAdapterEndpoint = "http://mso.mso.testlab.openecomp.org:8080/dbadapters/RequestsDbAdapter" execution.setVariable("CVFMI_dbAdapterEndpoint", dbAdapterEndpoint) utils.log("INFO", "DB Adapter Endpoint is: " + dbAdapterEndpoint, isDebugEnabled) @@ -189,34 +189,34 @@ public class DoUpdateE2EServiceInstance extends AbstractServiceTaskProcessor { utils.log("ERROR", "Exception Occured Processing preInitResourcesOperStatus. Exception is:\n" + e, isDebugEnabled) execution.setVariable("CVFMI_ErrorResponse", "Error Occurred during preInitResourcesOperStatus Method:\n" + e.getMessage()) } - utils.log("INFO", "======== COMPLETED preInitResourcesOperStatus Process ======== ", isDebugEnabled) + utils.log("INFO", "======== COMPLETED preInitResourcesOperStatus Process ======== ", isDebugEnabled) } - + public void preProcessForAddResource(DelegateExecution execution) { def isDebugEnabled=execution.getVariable("isDebugLogEnabled") utils.log("INFO"," ***** preProcessForAddResource ***** ", isDebugEnabled) - + execution.setVariable("operationType", "create") - + execution.setVariable("hasResourcetoAdd", false) List<Resource> addResourceList = execution.getVariable("addResourceList") if(addResourceList != null && !addResourceList.isEmpty()) { - execution.setVariable("hasResourcetoAdd", true) + execution.setVariable("hasResourcetoAdd", true) } - + utils.log("INFO"," *** Exit preProcessForAddResource *** ", isDebugEnabled) } public void postProcessForAddResource(DelegateExecution execution) { def isDebugEnabled=execution.getVariable("isDebugLogEnabled") utils.log("INFO"," ***** postProcessForAddResource ***** ", isDebugEnabled) - + execution.setVariable("operationType", "update") utils.log("INFO"," *** Exit postProcessForAddResource *** ", isDebugEnabled) } - + public void preProcessForDeleteResource(DelegateExecution execution) { def isDebugEnabled=execution.getVariable("isDebugLogEnabled") utils.log("INFO"," ***** preProcessForDeleteResource ***** ", isDebugEnabled) @@ -232,7 +232,7 @@ public class DoUpdateE2EServiceInstance extends AbstractServiceTaskProcessor { if(hasResourcetoDelete) { def jsonSlurper = new JsonSlurper() - String serviceRelationShip = execution.getVariable("serviceRelationShip") + String serviceRelationShip = execution.getVariable("serviceRelationShip") List relationShipList = jsonSlurper.parseText(serviceRelationShip) //Set the real resource instance id to the decomosed resource list @@ -249,7 +249,7 @@ public class DoUpdateE2EServiceInstance extends AbstractServiceTaskProcessor { } } } - + execution.setVariable("deleteResourceList", delResourceList) utils.log("INFO"," *** Exit preProcessForDeleteResource *** ", isDebugEnabled) @@ -258,60 +258,13 @@ public class DoUpdateE2EServiceInstance extends AbstractServiceTaskProcessor { public void postProcessForDeleteResource(DelegateExecution execution) { def isDebugEnabled=execution.getVariable("isDebugLogEnabled") utils.log("INFO"," ***** postProcessForDeleteResource ***** ", isDebugEnabled) - + execution.setVariable("operationType", "update") utils.log("INFO"," *** Exit postProcessForDeleteResource *** ", isDebugEnabled) - } - - public void preProcessAAIGET(DelegateExecution execution) { - def isDebugEnabled=execution.getVariable("isDebugLogEnabled") - } - - public void postProcessAAIGET(DelegateExecution execution) { - def isDebugEnabled=execution.getVariable("isDebugLogEnabled") - utils.log("INFO"," ***** postProcessAAIGET ***** ", isDebugEnabled) - String msg = "" - - try { - String serviceInstanceName = execution.getVariable("serviceInstanceName") - boolean succInAAI = execution.getVariable("GENGS_SuccessIndicator") - if(!succInAAI){ - utils.log("INFO","Error getting Service-instance from AAI in postProcessAAIGET", + serviceInstanceName, isDebugEnabled) - WorkflowException workflowException = execution.getVariable("WorkflowException") - utils.logAudit("workflowException: " + workflowException) - if(workflowException != null){ - exceptionUtil.buildAndThrowWorkflowException(execution, workflowException.getErrorCode(), workflowException.getErrorMessage()) - } - else - { - msg = "Failure in postProcessAAIGET GENGS_SuccessIndicator:" + succInAAI - utils.log("INFO", msg, isDebugEnabled) - exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg) - } - } - else - { - boolean foundInAAI = execution.getVariable("GENGS_FoundIndicator") - if(foundInAAI){ - String aaiService = execution.getVariable("GENGS_service") - if (!isBlank(aaiService) && (utils.nodeExists(aaiService, "resource-version"))) { - execution.setVariable("serviceInstanceVersion", utils.getNodeText(aaiService, "resource-version")) - utils.log("INFO","Found Service-instance in AAI.serviceInstanceName:" + execution.getVariable("serviceInstanceName"), isDebugEnabled) - } - } - } - } catch (BpmnError e) { - throw e; - } catch (Exception ex) { - msg = "Exception in DoUpdateE2EServiceInstance.postProcessAAIGET " + ex.getMessage() - utils.log("INFO", msg, isDebugEnabled) - exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) - } - utils.log("INFO"," *** Exit postProcessAAIGET *** ", isDebugEnabled) - } + } - public void preProcessAAIPUT(DelegateExecution execution) { + public void preProcessAAIPUT(DelegateExecution execution) { def method = getClass().getSimpleName() + '.preProcessRequest(' +'execution=' + execution.getId() +')' def isDebugEnabled = execution.getVariable("isDebugLogEnabled") utils.log("INFO","Entered " + method, isDebugEnabled) @@ -321,7 +274,7 @@ public class DoUpdateE2EServiceInstance extends AbstractServiceTaskProcessor { String serviceInstanceVersion = execution.getVariable("serviceInstanceVersion") //execution.setVariable("GENPS_serviceResourceVersion", serviceInstanceVersion) - + //requestDetails.modelInfo.for AAI PUT servieInstanceData //requestDetails.requestInfo. for AAI GET/PUT serviceInstanceData String serviceInstanceName = execution.getVariable("serviceInstanceName") @@ -334,7 +287,7 @@ public class DoUpdateE2EServiceInstance extends AbstractServiceTaskProcessor { AaiUtil aaiUriUtil = new AaiUtil(this) - utils.log("INFO","start create aai uri: " + aaiUriUtil, isDebugEnabled) + utils.log("INFO","start create aai uri: " + aaiUriUtil, isDebugEnabled) String aai_uri = aaiUriUtil.getBusinessCustomerUri(execution) utils.log("INFO","aai_uri: " + aai_uri, isDebugEnabled) String namespace = aaiUriUtil.getNamespaceFromUri(aai_uri) @@ -349,7 +302,7 @@ public class DoUpdateE2EServiceInstance extends AbstractServiceTaskProcessor { <service-role>${MsoUtils.xmlEscape(aaiServiceRole)}</service-role> <resource-version>${MsoUtils.xmlEscape(serviceInstanceVersion)}</resource-version> <model-invariant-id>${MsoUtils.xmlEscape(modelInvariantUuid)}</model-invariant-id> - <model-version-id>${MsoUtils.xmlEscape(modelUuid)}</model-version-id> + <model-version-id>${MsoUtils.xmlEscape(modelUuid)}</model-version-id> </service-instance>""".trim() execution.setVariable("serviceInstanceData", serviceInstanceData) @@ -357,10 +310,10 @@ public class DoUpdateE2EServiceInstance extends AbstractServiceTaskProcessor { utils.logAudit(serviceInstanceData) utils.log("INFO", " aai_uri " + aai_uri + " namespace:" + namespace, isDebugEnabled) utils.log("INFO", " 'payload' to update Service Instance in AAI - " + "\n" + serviceInstanceData, isDebugEnabled) - + utils.log("INFO", "Exited " + method, isDebugEnabled) - } - + } + public void postProcessAAIPUT(DelegateExecution execution) { def isDebugEnabled=execution.getVariable("isDebugLogEnabled") utils.log("INFO"," ***** postProcessAAIPUT ***** ", isDebugEnabled) @@ -397,13 +350,13 @@ public class DoUpdateE2EServiceInstance extends AbstractServiceTaskProcessor { exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) } utils.log("INFO"," *** Exit postProcessAAIPUT *** ", isDebugEnabled) - } + } public void preProcessRollback (DelegateExecution execution) { def isDebugEnabled=execution.getVariable("isDebugLogEnabled") utils.log("INFO"," ***** preProcessRollback ***** ", isDebugEnabled) try { - + Object workflowException = execution.getVariable("WorkflowException"); if (workflowException instanceof WorkflowException) { @@ -441,11 +394,11 @@ public class DoUpdateE2EServiceInstance extends AbstractServiceTaskProcessor { utils.log("INFO"," *** Exit postProcessRollback *** ", isDebugEnabled) } - + public void postConfigRequest(execution){ //now do noting } - + } - + diff --git a/bpmn/so-bpmn-infrastructure-flows/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoUpdateE2EServiceInstanceRollback.groovy b/bpmn/so-bpmn-infrastructure-flows/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoUpdateE2EServiceInstanceRollback.groovy index a2d94baaed..b5a8c898a1 100644 --- a/bpmn/so-bpmn-infrastructure-flows/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoUpdateE2EServiceInstanceRollback.groovy +++ b/bpmn/so-bpmn-infrastructure-flows/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoUpdateE2EServiceInstanceRollback.groovy @@ -7,9 +7,9 @@ * 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. @@ -67,13 +67,13 @@ public class DoUpdateE2EServiceInstanceRollback extends AbstractServiceTaskProce execution.setVariable("rollbackAAI",false) execution.setVariable("rollbackAdded",false) execution.setVariable("rollbackDeleted",false) - + List addResourceList = execution.getVariable("addResourceList") List delResourceList = execution.getVariable("delResourceList") execution.setVariable("addResourceList_o", addResourceList) execution.setVariable("delResourceList_o", delResourceList) //exchange add and delete resource list - execution.setVariable("addResourceList", delResourceList) + execution.setVariable("addResourceList", delResourceList) execution.setVariable("delResourceList", addResourceList) try { @@ -103,14 +103,14 @@ public class DoUpdateE2EServiceInstanceRollback extends AbstractServiceTaskProce { execution.setVariable("rollbackAdded", true) } - + def rollbackDeleted = rollbackData.get("SERVICEINSTANCE", "rollbackDeleted") if ("true".equals(rollbackDeleted)) { execution.setVariable("rollbackDeleted", true) - } + } - if (execution.getVariable("rollbackAAI") != true && execution.getVariable("rollbackAdded") != true + if (execution.getVariable("rollbackAAI") != true && execution.getVariable("rollbackAdded") != true && execution.getVariable("rollbackDeleted") != true) { execution.setVariable("skipRollback", true) @@ -148,7 +148,7 @@ public class DoUpdateE2EServiceInstanceRollback extends AbstractServiceTaskProce boolean rollbackAAI = execution.getVariable("rollbackAAI") boolean rollbackAdded = execution.getVariable("rollbackAdded") boolean rollbackDeleted = execution.getVariable("rollbackDeleted") - + List addResourceList = execution.getVariable("addResourceList_o") List delResourceList = execution.getVariable("delResourceList_o") execution.setVariable("addResourceList", addResourceList) @@ -177,66 +177,21 @@ public class DoUpdateE2EServiceInstanceRollback extends AbstractServiceTaskProce msoLogger.debug(msg) } } - - + + public void preProcessForAddResource(DelegateExecution execution) { } public void postProcessForAddResource(DelegateExecution execution) { } - + public void preProcessForDeleteResource(DelegateExecution execution) { } public void postProcessForDeleteResource(DelegateExecution execution) { - } - - public void preProcessAAIGET(DelegateExecution execution) { - } - - public void postProcessAAIGET(DelegateExecution execution) { - msoLogger.trace("postProcessAAIGET ") - String msg = "" - - try { - String serviceInstanceName = execution.getVariable("serviceInstanceName") - boolean succInAAI = execution.getVariable("GENGS_SuccessIndicator") - if(!succInAAI){ - msoLogger.info("Error getting Service-instance from AAI in postProcessAAIGET", + serviceInstanceName) - WorkflowException workflowException = execution.getVariable("WorkflowException") - msoLogger.debug("workflowException: " + workflowException) - if(workflowException != null){ - exceptionUtil.buildAndThrowWorkflowException(execution, workflowException.getErrorCode(), workflowException.getErrorMessage()) - } - else - { - msg = "Failure in postProcessAAIGET GENGS_SuccessIndicator:" + succInAAI - msoLogger.info(msg) - exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg) - } - } - else - { - boolean foundInAAI = execution.getVariable("GENGS_FoundIndicator") - if(foundInAAI){ - String aaiService = execution.getVariable("GENGS_service") - if (!isBlank(aaiService) && (utils.nodeExists(aaiService, "resource-version"))) { - execution.setVariable("serviceInstanceVersion_n", utils.getNodeText(aaiService, "resource-version")) - msoLogger.info("Found Service-instance in AAI.serviceInstanceName:" + execution.getVariable("serviceInstanceName")) - } - } - } - } catch (BpmnError e) { - throw e; - } catch (Exception ex) { - msg = "Exception in DoCreateServiceInstance.postProcessAAIGET " + ex.getMessage() - msoLogger.info(msg) - exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) - } - msoLogger.trace("Exit postProcessAAIGET ") - } + } - public void preProcessAAIPUT(DelegateExecution execution) { + public void preProcessAAIPUT(DelegateExecution execution) { def method = getClass().getSimpleName() + '.preProcessRequest(' +'execution=' + execution.getId() +')' msoLogger.info("Entered " + method) String msg = "" @@ -244,7 +199,7 @@ public class DoUpdateE2EServiceInstanceRollback extends AbstractServiceTaskProce String serviceInstanceVersion = execution.getVariable("serviceInstanceVersion_n") // execution.setVariable("GENPS_serviceResourceVersion", serviceInstanceVersion) - + //requestDetails.modelInfo.for AAI PUT servieInstanceData //requestDetails.requestInfo. for AAI GET/PUT serviceInstanceData String serviceInstanceName = execution.getVariable("serviceInstanceName") @@ -255,7 +210,7 @@ public class DoUpdateE2EServiceInstanceRollback extends AbstractServiceTaskProce String modelInvariantUuid = execution.getVariable("modelInvariantUuid") String modelUuid = execution.getVariable("model-version-id-original") - //AAI PUT + //AAI PUT AaiUtil aaiUriUtil = new AaiUtil(this) utils.log("INFO","start create aai uri: " + aaiUriUtil, isDebugEnabled) String aai_uri = aaiUriUtil.getBusinessCustomerUri(execution) @@ -271,7 +226,7 @@ public class DoUpdateE2EServiceInstanceRollback extends AbstractServiceTaskProce <service-role>${MsoUtils.xmlEscape(aaiServiceRole)}</service-role> <resource-version>${MsoUtils.xmlEscape(serviceInstanceVersion)}</resource-version> <model-invariant-id>${MsoUtils.xmlEscape(modelInvariantUuid)}</model-invariant-id> - <model-version-id>${MsoUtils.xmlEscape(modelUuid)}</model-version-id> + <model-version-id>${MsoUtils.xmlEscape(modelUuid)}</model-version-id> </service-instance>""".trim() execution.setVariable("serviceInstanceData", serviceInstanceData) @@ -279,10 +234,10 @@ public class DoUpdateE2EServiceInstanceRollback extends AbstractServiceTaskProce msoLogger.debug(serviceInstanceData) msoLogger.info(" aai_uri " + aai_uri + " namespace:" + namespace) msoLogger.info(" 'payload' to update Service Instance in AAI - " + "\n" + serviceInstanceData) - + msoLogger.info("Exited " + method) - } - + } + public void postProcessAAIPUT(DelegateExecution execution) { msoLogger.trace("postProcessAAIPUT ") String msg = "" @@ -299,7 +254,7 @@ public class DoUpdateE2EServiceInstanceRollback extends AbstractServiceTaskProce } else { - + } } catch (BpmnError e) { @@ -310,7 +265,7 @@ public class DoUpdateE2EServiceInstanceRollback extends AbstractServiceTaskProce exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) } msoLogger.trace("Exit postProcessAAIPUT ") - } + } public void processRollbackException(DelegateExecution execution){ msoLogger.trace("processRollbackException ") diff --git a/bpmn/so-bpmn-infrastructure-flows/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoUpdateNetworkInstance.groovy b/bpmn/so-bpmn-infrastructure-flows/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoUpdateNetworkInstance.groovy index 7272f421fc..4f6fbf9966 100644 --- a/bpmn/so-bpmn-infrastructure-flows/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoUpdateNetworkInstance.groovy +++ b/bpmn/so-bpmn-infrastructure-flows/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoUpdateNetworkInstance.groovy @@ -7,9 +7,9 @@ * 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. @@ -37,6 +37,15 @@ import org.onap.so.logger.MsoLogger import org.onap.so.rest.APIResponse import org.springframework.web.util.UriUtils +import org.onap.so.client.aai.AAIResourcesClient +import org.onap.so.client.aai.AAIObjectType +import org.onap.so.client.aai.entities.AAIResultWrapper +import org.onap.so.client.aai.entities.Relationships +import org.onap.so.client.aai.entities.uri.AAIResourceUri +import org.onap.so.client.aai.entities.uri.AAIUriFactory +import org.json.JSONObject +import javax.ws.rs.NotFoundException + import groovy.json.* import groovy.xml.XmlUtil @@ -46,7 +55,7 @@ import groovy.xml.XmlUtil */ public class DoUpdateNetworkInstance extends AbstractServiceTaskProcessor { private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, DoUpdateNetworkInstance.class); - + String Prefix="UPDNETI_" ExceptionUtil exceptionUtil = new ExceptionUtil() JsonUtils jsonUtil = new JsonUtils() @@ -109,7 +118,7 @@ public class DoUpdateNetworkInstance extends AbstractServiceTaskProcessor { execution.setVariable(Prefix + "networkTableRefUriList", null) execution.setVariable(Prefix + "networkTableRefCount", 0) execution.setVariable(Prefix + "tableRefCollection", "") - + // AAI requery Id execution.setVariable(Prefix + "requeryIdAAIRequest","") execution.setVariable(Prefix + "requeryIdAAIResponse", "") @@ -137,9 +146,9 @@ public class DoUpdateNetworkInstance extends AbstractServiceTaskProcessor { execution.setVariable(Prefix + "isVnfBindingPresent", false) execution.setVariable(Prefix + "Success", false) execution.setVariable(Prefix + "serviceInstanceId", "") - + execution.setVariable(Prefix + "isException", false) - + } // ************************************************** @@ -158,7 +167,7 @@ public class DoUpdateNetworkInstance extends AbstractServiceTaskProcessor { try { // initialize flow variables InitializeProcessVariables(execution) - + // GET Incoming request & validate 3 kinds of format. execution.setVariable("action", "UPDATE") String networkRequest = execution.getVariable("bpmnRequest") @@ -169,7 +178,7 @@ public class DoUpdateNetworkInstance extends AbstractServiceTaskProcessor { def prettyJson = JsonOutput.prettyPrint(networkRequest.toString()) msoLogger.debug(" Incoming message formatted . . . : " + '\n' + prettyJson) networkRequest = vidUtils.createXmlNetworkRequestInfra(execution, networkRequest) - + } catch (Exception ex) { String dataErrorMessage = " Invalid json format Request - " + ex.getMessage() msoLogger.debug(dataErrorMessage) @@ -177,27 +186,27 @@ public class DoUpdateNetworkInstance extends AbstractServiceTaskProcessor { } } else { // XML format request is sent - + } } else { // vIPR format request is sent, create xml from individual variables networkRequest = vidUtils.createXmlNetworkRequestInstance(execution) } - + networkRequest = utils.formatXml(networkRequest) msoLogger.debug(networkRequest) execution.setVariable(Prefix + "networkRequest", networkRequest) msoLogger.debug(" network-request - " + '\n' + networkRequest) - + // validate 'disableRollback' (aka, 'suppressRollback') boolean rollbackEnabled = networkUtils.isRollbackEnabled(execution, networkRequest) execution.setVariable(Prefix + "rollbackEnabled", rollbackEnabled) msoLogger.debug(Prefix + "rollbackEnabled - " + rollbackEnabled) - + String networkInputs = utils.getNodeXml(networkRequest, "network-inputs", false).replace("tag0:","").replace(":tag0","") execution.setVariable(Prefix + "networkInputs", networkInputs) msoLogger.debug(Prefix + "networkInputs - " + '\n' + networkInputs) - + // prepare messageId String messageId = execution.getVariable(Prefix + "messageId") // for testing if (messageId == null || messageId == "") { @@ -207,11 +216,11 @@ public class DoUpdateNetworkInstance extends AbstractServiceTaskProcessor { msoLogger.debug(" UPDNETI_messageId, pre-assigned: " + messageId) } execution.setVariable(Prefix + "messageId", messageId) - + String source = utils.getNodeText(networkRequest, "source") execution.setVariable(Prefix + "source", source) msoLogger.debug(Prefix + "source - " + source) - + String networkId = "" if (utils.nodeExists(networkRequest, "network-id")) { networkId = utils.getNodeText(networkRequest, "network-id") @@ -221,10 +230,10 @@ public class DoUpdateNetworkInstance extends AbstractServiceTaskProcessor { String dataErrorMessage = "Variable 'network-id' value/element is missing." msoLogger.debug(" Invalid Request - " + dataErrorMessage) exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage) - + } } - + String lcpCloudRegion = "" if (utils.nodeExists(networkRequest, "aic-cloud-region")) { lcpCloudRegion = utils.getNodeText(networkRequest, "aic-cloud-region") @@ -235,7 +244,7 @@ public class DoUpdateNetworkInstance extends AbstractServiceTaskProcessor { exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage) } } - + String serviceInstanceId = "" if (utils.nodeExists(networkRequest, "service-instance-id")) { serviceInstanceId = utils.getNodeText(networkRequest, "service-instance-id") @@ -246,35 +255,33 @@ public class DoUpdateNetworkInstance extends AbstractServiceTaskProcessor { exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage) } } - + // PO Authorization Info / headers Authorization= String basicAuthValuePO = UrnPropertiesReader.getVariable("mso.adapters.po.auth",execution) - + try { def encodedString = utils.getBasicAuth(basicAuthValuePO, UrnPropertiesReader.getVariable("mso.msoKey", execution)) execution.setVariable("BasicAuthHeaderValuePO",encodedString) execution.setVariable("BasicAuthHeaderValueSDNC", encodedString) - + } catch (IOException ex) { String exceptionMessage = "Exception Encountered in DoUpdateNetworkInstance, PreProcessRequest() - " String dataErrorMessage = exceptionMessage + " Unable to encode PO/SDNC user/password string - " + ex.getMessage() msoLogger.debug(dataErrorMessage) exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage) } - + // Set variables for Generic Get Sub Flow use execution.setVariable(Prefix + "serviceInstanceId", serviceInstanceId) msoLogger.debug(Prefix + "serviceInstanceId - " + serviceInstanceId) - - execution.setVariable("GENGS_type", "service-instance") - msoLogger.debug("GENGS_type - " + "service-instance") + msoLogger.debug(" Url for SDNC adapter: " + UrnPropertiesReader.getVariable("mso.adapters.sdnc.endpoint",execution)) - + String sdncVersion = execution.getVariable("sdncVersion") msoLogger.debug("sdncVersion? : " + sdncVersion) - - // build 'networkOutputs' + + // build 'networkOutputs' networkId = utils.getNodeText(networkRequest, "network-id") if ((networkId == null) || (networkId == "null")) { networkId = "" @@ -292,7 +299,7 @@ public class DoUpdateNetworkInstance extends AbstractServiceTaskProcessor { msoLogger.debug(Prefix + "networkOutputs - " + '\n' + networkOutputs) execution.setVariable(Prefix + "networkId", networkId) execution.setVariable(Prefix + "networkName", networkName) - + } catch (BpmnError e) { throw e; @@ -307,6 +314,31 @@ public class DoUpdateNetworkInstance extends AbstractServiceTaskProcessor { } } + /** + * Gets the service instance uri from aai + * + */ + public void getServiceInstance(DelegateExecution execution) { + msoLogger.trace("getServiceInstance ") + try { + String serviceInstanceId = execution.getVariable('serviceInstanceId') + + AAIResourcesClient resourceClient = new AAIResourcesClient() + AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, serviceInstanceId) + + if(!resourceClient.exists(uri)){ + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, "Service Instance not found in aai") + } + + }catch(BpmnError e) { + throw e; + }catch (Exception ex){ + String msg = "Exception in getServiceInstance. " + ex.getMessage() + msoLogger.debug(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) + } + } + public void callRESTQueryAAICloudRegion (DelegateExecution execution) { execution.setVariable("prefix", Prefix) @@ -383,7 +415,7 @@ public class DoUpdateNetworkInstance extends AbstractServiceTaskProcessor { String returnCode = response.getStatusCode() execution.setVariable(Prefix + "aaiIdReturnCode", returnCode) msoLogger.debug(" ***** AAI Response Code : " + returnCode) - + String aaiResponseAsString = response.getResponseBodyAsString() if (returnCode=='200') { @@ -462,12 +494,12 @@ public class DoUpdateNetworkInstance extends AbstractServiceTaskProcessor { String netName = utils.getNodeText(aaiResponseAsString, "network-name") String networkOutputs = """<network-outputs> - <network-id>${MsoUtils.xmlEscape(netId)}</network-id> + <network-id>${MsoUtils.xmlEscape(netId)}</network-id> <network-name>${MsoUtils.xmlEscape(netName)}</network-name> </network-outputs>""" execution.setVariable(Prefix + "networkOutputs", networkOutputs) msoLogger.debug(" networkOutputs - " + '\n' + networkOutputs) - + } else { if (returnCode=='404') { String dataErrorMessage = "Response Error from ReQueryAAINetworkId is 404 (Not Found)." @@ -866,13 +898,13 @@ public class DoUpdateNetworkInstance extends AbstractServiceTaskProcessor { String dataErrorMessage = "Response Error from QueryAAINetworkTableRef is 404 (Not Found)." msoLogger.debug(dataErrorMessage) exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage) - + } else { if (aaiResponseAsString.contains("RESTFault")) { WorkflowException exceptionObject = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution) execution.setVariable("WorkflowException", exceptionObject) throw new BpmnError("MSOWorkflowException") - + } else { // aai all errors String dataErrorMessage = "Unexpected Response from QueryAAINetworkTableRef - " + returnCode @@ -908,7 +940,7 @@ public class DoUpdateNetworkInstance extends AbstractServiceTaskProcessor { } catch (BpmnError e) { throw e; - + } catch (Exception ex) { String exceptionMessage = "Bpmn error encountered in DoUpdateNetworkInstance flow. callRESTQueryAAINetworkTableRef() - " + ex.getMessage() msoLogger.debug(exceptionMessage) @@ -917,7 +949,7 @@ public class DoUpdateNetworkInstance extends AbstractServiceTaskProcessor { } } - + public void callRESTUpdateContrailAAINetwork(DelegateExecution execution) { execution.setVariable("prefix", Prefix) @@ -953,7 +985,7 @@ public class DoUpdateNetworkInstance extends AbstractServiceTaskProcessor { APIResponse response = aaiUriUtil.executeAAIPutCall(execution, updateContrailAAIUrlRequest, payload) String returnCode = response.getStatusCode() String aaiUpdateContrailResponseAsString = response.getResponseBodyAsString() - + execution.setVariable(Prefix + "aaiUpdateContrailReturnCode", returnCode) msoLogger.debug(" ***** AAI Update Contrail Response Code : " + returnCode) @@ -1015,7 +1047,7 @@ public class DoUpdateNetworkInstance extends AbstractServiceTaskProcessor { String queryIdResponse = execution.getVariable(Prefix + "requeryIdAAIResponse") String cloudRegionId = execution.getVariable(Prefix + "cloudRegionPo") String backoutOnFailure = execution.getVariable(Prefix + "rollbackEnabled") - + // Prepare Network request String routeCollection = execution.getVariable(Prefix + "routeCollection") String policyCollection = execution.getVariable(Prefix + "networkCollection") @@ -1057,7 +1089,7 @@ public class DoUpdateNetworkInstance extends AbstractServiceTaskProcessor { if (networkId == null) {networkId = ""} String serviceInstanceId = utils.getNodeText(updateNetworkInput, "service-instance-id") - + String queryAAIResponse = execution.getVariable(Prefix + "queryIdAAIResponse") // 1. prepare assign topology via SDNC Adapter SUBFLOW call @@ -1078,7 +1110,7 @@ public class DoUpdateNetworkInstance extends AbstractServiceTaskProcessor { } - + // ************************************************** @@ -1212,7 +1244,7 @@ public class DoUpdateNetworkInstance extends AbstractServiceTaskProcessor { execution.setVariable(Prefix + "Success", true) msoLogger.debug(" ***** postProcessResponse(), GOOD !!!") } else { - execution.setVariable(Prefix + "Success", false) + execution.setVariable(Prefix + "Success", false) execution.setVariable("rollbackData", null) String exceptionMessage = " Exception encountered in MSO Bpmn. " if (execution.getVariable("workflowException") != null) { // Output of Rollback flow. @@ -1223,18 +1255,18 @@ public class DoUpdateNetworkInstance extends AbstractServiceTaskProcessor { if (execution.getVariable(Prefix + "WorkflowException") != null) { WorkflowException pwfex = execution.getVariable(Prefix + "WorkflowException") exceptionMessage = pwfex.getErrorMessage() - } + } } // going to the Main flow: a-la-carte or macro msoLogger.debug(" ***** postProcessResponse(), BAD !!!") exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage) throw new BpmnError("MSOWorkflowException") } - + } catch(BpmnError b){ msoLogger.debug("Rethrowing MSOWorkflowException") throw b - + } catch (Exception ex) { String exceptionMessage = " Bpmn error encountered in DoUpdateNetworkInstance flow. postProcessResponse() - " + ex.getMessage() @@ -1253,7 +1285,7 @@ public class DoUpdateNetworkInstance extends AbstractServiceTaskProcessor { msoLogger.trace("Inside prepareSDNCRollbackRequest of DoUpdateNetworkInstance ") try { - // for some reason the WorkflowException object is null after the sdnc rollback call task, need to save WorkflowException. + // for some reason the WorkflowException object is null after the sdnc rollback call task, need to save WorkflowException. execution.setVariable(Prefix + "WorkflowException", execution.getVariable("WorkflowException")) // get variables String sdncCallback = UrnPropertiesReader.getVariable("mso.workflow.sdncadapter.callback",execution) @@ -1282,11 +1314,11 @@ public class DoUpdateNetworkInstance extends AbstractServiceTaskProcessor { public void prepareRollbackData(DelegateExecution execution) { execution.setVariable("prefix",Prefix) - + msoLogger.trace("Inside prepareRollbackData() of DoUpdateNetworkInstance ") - + try { - + Map<String, String> rollbackData = new HashMap<String, String>(); String rollbackSDNCRequest = execution.getVariable(Prefix + "rollbackSDNCRequest") if (rollbackSDNCRequest != null) { @@ -1302,33 +1334,33 @@ public class DoUpdateNetworkInstance extends AbstractServiceTaskProcessor { } execution.setVariable("rollbackData", rollbackData) msoLogger.debug("** rollbackData : " + rollbackData) - + execution.setVariable("WorkflowException", execution.getVariable(Prefix + "WorkflowException")) msoLogger.debug("** WorkflowException : " + execution.getVariable("WorkflowException")) - + } catch (Exception ex) { String exceptionMessage = " Bpmn error encountered in DoUpdateNetworkInstance flow. prepareRollbackData() - " + ex.getMessage() msoLogger.debug(exceptionMessage) exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage) - + } - + } - + public void prepareSuccessRollbackData(DelegateExecution execution) { execution.setVariable("prefix",Prefix) - + msoLogger.trace("Inside prepareSuccessRollbackData() of DoUpdateNetworkInstance ") - + try { - + if (execution.getVariable("sdncVersion") != '1610') { // skip: 1702 for 'changeassign' or equivalent not yet defined in SNDC, so no rollback. } else { prepareSDNCRollbackRequest(execution) } - + Map<String, String> rollbackData = new HashMap<String, String>(); String rollbackSDNCRequest = execution.getVariable(Prefix + "rollbackSDNCRequest") if (rollbackSDNCRequest != null) { @@ -1343,43 +1375,43 @@ public class DoUpdateNetworkInstance extends AbstractServiceTaskProcessor { } } execution.setVariable("rollbackData", rollbackData) - + msoLogger.debug("** 'rollbackData' for Full Rollback : " + rollbackData) execution.setVariable("WorkflowException", null) - + } catch (Exception ex) { String exceptionMessage = " Bpmn error encountered in DoUpdateNetworkInstance flow. prepareSuccessRollbackData() - " + ex.getMessage() msoLogger.debug(exceptionMessage) exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage) - + } - + } - + public void setExceptionFlag(DelegateExecution execution){ execution.setVariable("prefix",Prefix) - + msoLogger.trace("Inside setExceptionFlag() of DoUpdateNetworkInstance ") - + try { - + execution.setVariable(Prefix + "isException", true) - + if (execution.getVariable("SavedWorkflowException1") != null) { execution.setVariable(Prefix + "WorkflowException", execution.getVariable("SavedWorkflowException1")) } else { execution.setVariable(Prefix + "WorkflowException", execution.getVariable("WorkflowException")) } msoLogger.debug(Prefix + "WorkflowException - " +execution.getVariable(Prefix + "WorkflowException")) - + } catch(Exception ex){ String exceptionMessage = "Bpmn error encountered in DoUpdateNetworkInstance flow. setExceptionFlag(): " + ex.getMessage() msoLogger.debug(exceptionMessage) exceptionUtil.buildWorkflowException(execution, 7000, exceptionMessage) } - + } @@ -1396,7 +1428,7 @@ public class DoUpdateNetworkInstance extends AbstractServiceTaskProcessor { msoLogger.debug("Variables List: " + execution.getVariables()) execution.setVariable("UnexpectedError", "Caught a Java Lang Exception - " + Prefix) // Adding this line temporarily until this flows error handling gets updated exceptionUtil.buildWorkflowException(execution, 500, "Caught a Java Lang Exception") - + }catch(Exception e){ msoLogger.debug("Caught Exception during processJavaException Method: " + e) execution.setVariable("UnexpectedError", "Exception in processJavaException method") // Adding this line temporarily until this flows error handling gets updated diff --git a/bpmn/so-bpmn-infrastructure-flows/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/UpdateCustomE2EServiceInstance.groovy b/bpmn/so-bpmn-infrastructure-flows/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/UpdateCustomE2EServiceInstance.groovy index 538f882c2b..ac8e506e1f 100644 --- a/bpmn/so-bpmn-infrastructure-flows/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/UpdateCustomE2EServiceInstance.groovy +++ b/bpmn/so-bpmn-infrastructure-flows/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/UpdateCustomE2EServiceInstance.groovy @@ -2,14 +2,14 @@ * ============LICENSE_START======================================================= * ONAP - SO * ================================================================================ - * Copyright (C) 2018 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (C) 2018 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. @@ -22,17 +22,25 @@ package org.onap.so.bpmn.infrastructure.scripts; import static org.apache.commons.lang3.StringUtils.*; +import javax.ws.rs.NotFoundException + import org.apache.commons.lang3.* import org.camunda.bpm.engine.delegate.BpmnError import org.camunda.bpm.engine.delegate.DelegateExecution import org.json.JSONArray import org.json.JSONObject +import org.onap.aai.domain.yang.ServiceInstance import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor import org.onap.so.bpmn.common.scripts.ExceptionUtil import org.onap.so.bpmn.common.scripts.MsoUtils import org.onap.so.bpmn.core.WorkflowException import org.onap.so.bpmn.core.domain.Resource import org.onap.so.bpmn.core.json.JsonUtils +import org.onap.so.client.aai.AAIObjectType +import org.onap.so.client.aai.AAIResourcesClient +import org.onap.so.client.aai.entities.AAIResultWrapper +import org.onap.so.client.aai.entities.uri.AAIResourceUri +import org.onap.so.client.aai.entities.uri.AAIUriFactory import org.springframework.web.util.UriUtils import groovy.json.* @@ -68,7 +76,7 @@ public class UpdateCustomE2EServiceInstance extends AbstractServiceTaskProcessor msg = "Input serviceInstanceId' is null" exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg) } - + //subscriberInfo for aai String globalSubscriberId = jsonUtil.getJsonValue(siRequest, "requestDetails.subscriberInfo.globalSubscriberId") if (isBlank(globalSubscriberId)) { @@ -86,16 +94,16 @@ public class UpdateCustomE2EServiceInstance extends AbstractServiceTaskProcessor if (isBlank(productFamilyId)) { msg = "Input productFamilyId is null" - utils.log("INFO", msg, isDebugEnabled) + utils.log("INFO", msg, isDebugEnabled) } else { execution.setVariable("productFamilyId", productFamilyId) } - + //user params - String userParams = jsonUtil.getJsonValue(siRequest, "requestDetails.requestParameters.userParams") + String userParams = jsonUtil.getJsonValue(siRequest, "requestDetails.requestParameters.userParams") utils.log("INFO", "userParams:" + userParams, isDebugEnabled) List<String> paramList = jsonUtil.StringArrayToList(execution, userParams) - String uuiRequest = jsonUtil.getJsonValue(paramList.get(0), "UUIRequest") + String uuiRequest = jsonUtil.getJsonValue(paramList.get(0), "UUIRequest") if (isBlank(uuiRequest)) { msg = "Input uuiRequest is null" utils.log("INFO", msg, isDebugEnabled) @@ -116,34 +124,34 @@ public class UpdateCustomE2EServiceInstance extends AbstractServiceTaskProcessor } else { execution.setVariable("serviceType", serviceType) } - + // target model info String modelInvariantUuid = jsonUtil.getJsonValue(uuiRequest, "service.serviceInvariantUuid") utils.log("INFO","modelInvariantUuid: " + modelInvariantUuid, isDebugEnabled) execution.setVariable("modelInvariantUuid", modelInvariantUuid) execution.setVariable("model-invariant-id-target", modelInvariantUuid) - + String modelUuid = jsonUtil.getJsonValue(uuiRequest, "service.serviceUuid") utils.log("INFO","modelUuid: " + modelUuid, isDebugEnabled) execution.setVariable("modelUuid", modelUuid) execution.setVariable("model-version-id-target", modelUuid) - + String serviceModelName = jsonUtil.getJsonValue(uuiRequest, "service.parameters.templateName") utils.log("INFO","serviceModelName: " + serviceModelName, isDebugEnabled) if(serviceModelName == null) { serviceModelName = "" } - execution.setVariable("serviceModelName", serviceModelName) - + execution.setVariable("serviceModelName", serviceModelName) + //operationId String operationId = jsonUtil.getJsonValue(siRequest, "operationId") if (isBlank(operationId)) { operationId = UUID.randomUUID().toString() - } - execution.setVariable("operationId", operationId) + } + execution.setVariable("operationId", operationId) execution.setVariable("operationType", "update") execution.setVariable("hasResourcetoUpdate", false) - + execution.setVariable("URN_mso_adapters_openecomp_db_endpoint","http://mso.mso.testlab.openecomp.org:8080/dbadapters/RequestsDbAdapter") } catch (BpmnError e) { @@ -155,164 +163,69 @@ public class UpdateCustomE2EServiceInstance extends AbstractServiceTaskProcessor } utils.log("INFO"," ***** Exit preProcessRequest *****", isDebugEnabled) } - - - public void postProcessAAIGET(DelegateExecution execution) { - def isDebugEnabled=execution.getVariable("isDebugLogEnabled") - utils.log("INFO"," ***** postProcessAAIGET ***** ", isDebugEnabled) - String msg = "" + /** + * Gets the service instance and its relationships from aai + */ + public void getServiceInstance(DelegateExecution execution) { try { - String serviceInstanceId = execution.getVariable("serviceInstanceId") - boolean foundInAAI = execution.getVariable("GENGS_FoundIndicator") - String serviceType = "" - - if(foundInAAI){ - utils.log("INFO","Found Service-instance in AAI", isDebugEnabled) - - String siData = execution.getVariable("GENGS_service") - utils.log("INFO", "SI Data", isDebugEnabled) - if (isBlank(siData)) - { - msg = "Could not retrive ServiceInstance data from AAI, Id:" + serviceInstanceId - utils.log("INFO", msg, isDebugEnabled) - exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg) - } - - utils.log("INFO", "SI Data" + siData, isDebugEnabled) - - // serviceInstanceName - String serviceInstanceName = execution.getVariable("serviceInstanceName") - if(isBlank(serviceInstanceName) && utils.nodeExists(siData, "service-instance-name")) { - serviceInstanceName = utils.getNodeText(siData, "service-instance-name") - execution.setVariable("serviceInstanceName", serviceInstanceName) - } - - // Get Template uuid and version - if (utils.nodeExists(siData, "model-invariant-id") && utils.nodeExists(siData, "model-version-id") ) { - utils.log("INFO", "SI Data model-invariant-id and model-version-id exist:", isDebugEnabled) - - def modelInvariantId = utils.getNodeText(siData, "model-invariant-id") - def modelVersionId = utils.getNodeText(siData, "model-version-id") - - // Set Original Template info - execution.setVariable("model-invariant-id-original", modelInvariantId) - execution.setVariable("model-version-id-original", modelVersionId) - } - - //get related service instances (vnf/network or volume) for delete - if (utils.nodeExists(siData, "relationship-list")) { - utils.log("INFO", "SI Data relationship-list exists:", isDebugEnabled) - - JSONArray jArray = new JSONArray() - - XmlParser xmlParser = new XmlParser() - Node root = xmlParser.parseText(siData) - def relation_list = utils.getChildNode(root, 'relationship-list') - def relationships = utils.getIdenticalChildren(relation_list, 'relationship') - - for (def relation: relationships) { - def jObj = getRelationShipData(relation, isDebugEnabled) - jArray.put(jObj) - } - - execution.setVariable("serviceRelationShip", jArray.toString()) - } - }else{ - boolean succInAAI = execution.getVariable("GENGS_SuccessIndicator") - if(!succInAAI){ - utils.log("INFO","Error getting Service-instance from AAI", + serviceInstanceId, isDebugEnabled) - WorkflowException workflowException = execution.getVariable("WorkflowException") - utils.logAudit("workflowException: " + workflowException) - if(workflowException != null){ - exceptionUtil.buildAndThrowWorkflowException(execution, workflowException.getErrorCode(), workflowException.getErrorMessage()) - } - else - { - msg = "Failure in postProcessAAIGET GENGS_SuccessIndicator:" + succInAAI - utils.log("INFO", msg, isDebugEnabled) - exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg) - } - } - - utils.log("INFO","Service-instance NOT found in AAI. Silent Success", isDebugEnabled) - } - }catch (BpmnError e) { + String serviceInstanceId = execution.getVariable('serviceInstanceId') + String globalSubscriberId = execution.getVariable('globalSubscriberId') + String serviceType = execution.getVariable('serviceType') + + AAIResourcesClient resourceClient = new AAIResourcesClient() + AAIResourceUri serviceInstanceUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, globalSubscriberId, serviceType, serviceInstanceId) + AAIResultWrapper wrapper = resourceClient.get(serviceInstanceUri, NotFoundException.class) + + ServiceInstance si = wrapper.asBean(ServiceInstance.class) + execution.setVariable("serviceInstanceName", si.getServiceInstanceName()) + execution.setVariable("model-invariant-id-original", si.getModelInvariantId()) + execution.setVariable("model-version-id-original", si.getModelVersionId()) + + JSONObject ob = new JSONObject(wrapper.getJson()) + JSONArray ar = ob.getJSONObject("relationship-list").getJSONArray("relationship") + + execution.setVariable("serviceRelationShip", ar.toString()) + + + }catch(BpmnError e) { throw e; - } catch (Exception ex) { - msg = "Exception in DoDeleteE2EServiceInstance.postProcessAAIGET. " + ex.getMessage() - utils.log("INFO", msg, isDebugEnabled) + }catch(NotFoundException e) { + exceptionUtil.buildAndThrowWorkflowException(execution, 404, "Service-instance does not exist AAI") + }catch(Exception ex) { + String msg = "Internal Error in getServiceInstance: " + ex.getMessage() exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) } - utils.log("INFO"," *** Exit postProcessAAIGET *** ", isDebugEnabled) } - - private JSONObject getRelationShipData(node, isDebugEnabled){ - JSONObject jObj = new JSONObject() - - def relation = utils.nodeToString(node) - def rt = utils.getNodeText(relation, "related-to") - - def rl = utils.getNodeText(relation, "related-link") - utils.log("INFO", "ServiceInstance Related NS/Configuration :" + rl, isDebugEnabled) - - def rl_datas = utils.getIdenticalChildren(node, "relationship-data") - for(def rl_data : rl_datas) { - def eKey = utils.getChildNodeText(rl_data, "relationship-key") - def eValue = utils.getChildNodeText(rl_data, "relationship-value") - - if ((rt == "service-instance" && eKey.equals("service-instance.service-instance-id")) - //for overlay/underlay - || (rt == "configuration" && eKey.equals("configuration.configuration-id"))){ - jObj.put("resourceInstanceId", eValue) - } - } - - def rl_props = utils.getIdenticalChildren(node, "related-to-property") - for(def rl_prop : rl_props) { - def eKey = utils.getChildNodeText(rl_prop, "property-key") - def eValue = utils.getChildNodeText(rl_prop, "property-value") - if((rt == "service-instance" && eKey.equals("service-instance.service-instance-name")) - //for overlay/underlay - || (rt == "configuration" && eKey.equals("configuration.configuration-type"))){ - jObj.put("resourceType", eValue) - } - } - - utils.log("INFO", "Relationship related to Resource:" + jObj.toString(), isDebugEnabled) - return jObj - } - - public void preCompareModelVersions(DelegateExecution execution) { def isDebugEnabled=execution.getVariable("isDebugLogEnabled") } - public void postCompareModelVersions(DelegateExecution execution) { + public void postCompareModelVersions(DelegateExecution execution) { def isDebugEnabled=execution.getVariable("isDebugLogEnabled") utils.log("DEBUG", " ======== STARTED postCompareModelVersions Process ======== ", isDebugEnabled) - + def hasResourcetoUpdate = false def hasResourcetoAdd = false def hasResourcetoDelete = false List<Resource> addResourceList = execution.getVariable("addResourceList") List<Resource> delResourceList = execution.getVariable("delResourceList") - + if(addResourceList != null && !addResourceList.isEmpty()) { hasResourcetoAdd = true } - + if(delResourceList != null && !delResourceList.isEmpty()) { hasResourcetoDelete = true } - + hasResourcetoUpdate = hasResourcetoAdd || hasResourcetoDelete execution.setVariable("hasResourcetoUpdate", hasResourcetoUpdate) - - utils.log("DEBUG", "======== COMPLETED postCompareModelVersions Process ======== ", isDebugEnabled) + + utils.log("DEBUG", "======== COMPLETED postCompareModelVersions Process ======== ", isDebugEnabled) } - + /** * Init the service Operation Status */ @@ -367,28 +280,28 @@ public class UpdateCustomE2EServiceInstance extends AbstractServiceTaskProcessor } utils.log("DEBUG", "======== COMPLETED prepareInitServiceOperationStatus Process ======== ", isDebugEnabled) } - + /** * Update the service Operation Status */ - public void preUpdateServiceOperationStatus(DelegateExecution execution){ + public void preUpdateServiceOperationStatus(DelegateExecution execution){ def method = getClass().getSimpleName() + '.preUpdateServiceOperationStatus(' +'execution=' + execution.getId() +')' def isDebugEnabled = execution.getVariable("isDebugLogEnabled") utils.log("INFO","Entered " + method, isDebugEnabled) - + try{ String serviceId = execution.getVariable("serviceInstanceId") String operationId = execution.getVariable("operationId") String operationType = execution.getVariable("operationType") String serviceName = execution.getVariable("serviceInstanceName") - String result = execution.getVariable("operationResult") + String result = execution.getVariable("operationResult") String progress = execution.getVariable("progress") String reason = execution.getVariable("operationReason") String userId = "" utils.log("INFO", "progress: " + progress , isDebugEnabled) String operationContent = "Prepare service : " + execution.getVariable("operationStatus") - + utils.log("INFO", "Generated new operation for Service Instance serviceId:" + serviceId + " operationId:" + operationId, isDebugEnabled) serviceId = UriUtils.encode(serviceId,"UTF-8") execution.setVariable("serviceInstanceId", serviceId) @@ -421,7 +334,7 @@ public class UpdateCustomE2EServiceInstance extends AbstractServiceTaskProcessor payload = utils.formatXml(payload) execution.setVariable("CVFMI_updateServiceOperStatusRequest", payload) utils.log("INFO", "Outgoing preUpdateServiceOperationStatus: \n" + payload, isDebugEnabled) - + }catch(Exception e){ utils.log("ERROR", "Exception Occured Processing preUpdateServiceOperationStatus. Exception is:\n" + e, isDebugEnabled) @@ -429,7 +342,7 @@ public class UpdateCustomE2EServiceInstance extends AbstractServiceTaskProcessor } utils.log("INFO", "======== COMPLETED preUpdateServiceOperationStatus Process ======== ", isDebugEnabled) utils.log("INFO", "Exited " + method, isDebugEnabled) - } + } public void sendSyncResponse (DelegateExecution execution) { def isDebugEnabled=execution.getVariable("isDebugLogEnabled") @@ -438,7 +351,7 @@ public class UpdateCustomE2EServiceInstance extends AbstractServiceTaskProcessor try { String operationId = execution.getVariable("operationId") def hasResourcetoUpdate = execution.getVariable("hasResourcetoUpdate") - + String updateServiceResp = "" if(hasResourcetoUpdate) { // RESTResponse for API Handler (APIH) Reply Task @@ -447,7 +360,7 @@ public class UpdateCustomE2EServiceInstance extends AbstractServiceTaskProcessor else { updateServiceResp = """{"OperationResult":"No Resource to Add or Delete or Service Instance not found in AAI."}""" } - + utils.log("INFO", " sendSyncResponse to APIH:" + "\n" + updateServiceResp, isDebugEnabled) sendWorkflowResponse(execution, 202, updateServiceResp) execution.setVariable("sentSyncResponse", true) @@ -498,7 +411,7 @@ public class UpdateCustomE2EServiceInstance extends AbstractServiceTaskProcessor String requestId = execution.getVariable("msoRequestId") String serviceInstanceId = execution.getVariable("serviceInstanceId") String source = execution.getVariable("source") - + String msoCompletionRequest = """<aetgt:MsoCompletionRequest xmlns:aetgt="http://org.onap/so/workflow/schema/v1" xmlns:ns="http://org.onap/so/request/types/v1"> @@ -566,5 +479,5 @@ public class UpdateCustomE2EServiceInstance extends AbstractServiceTaskProcessor execution.setVariable("falloutRequest", falloutRequest) } utils.log("INFO", "*** Exit prepareFalloutRequest ***", isDebugEnabled) - } + } } diff --git a/bpmn/so-bpmn-infrastructure-flows/src/main/groovy/org/onap/so/bpmn/vcpe/scripts/DeleteVcpeResCustService.groovy b/bpmn/so-bpmn-infrastructure-flows/src/main/groovy/org/onap/so/bpmn/vcpe/scripts/DeleteVcpeResCustService.groovy index eaf3631441..85993d6c92 100644 --- a/bpmn/so-bpmn-infrastructure-flows/src/main/groovy/org/onap/so/bpmn/vcpe/scripts/DeleteVcpeResCustService.groovy +++ b/bpmn/so-bpmn-infrastructure-flows/src/main/groovy/org/onap/so/bpmn/vcpe/scripts/DeleteVcpeResCustService.groovy @@ -7,9 +7,9 @@ * 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. @@ -33,6 +33,14 @@ import org.onap.so.bpmn.core.json.JsonUtils import org.onap.so.logger.MessageEnum import org.onap.so.logger.MsoLogger import org.onap.so.rest.APIResponse +import org.onap.so.client.aai.AAIResourcesClient +import org.onap.so.client.aai.AAIObjectType +import org.onap.so.client.aai.entities.AAIResultWrapper +import org.onap.so.client.aai.entities.Relationships +import org.onap.so.client.aai.entities.uri.AAIResourceUri +import org.onap.so.client.aai.entities.uri.AAIUriFactory +import javax.ws.rs.NotFoundException +import org.json.JSONObject import static org.apache.commons.lang3.StringUtils.isBlank @@ -100,7 +108,7 @@ public class DeleteVcpeResCustService extends AbstractServiceTaskProcessor { String dataErrorMessage = " Element 'serviceInstanceId' is missing. " exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage) } - + String requestAction = execution.getVariable("requestAction") execution.setVariable("requestAction", requestAction) @@ -117,20 +125,20 @@ public class DeleteVcpeResCustService extends AbstractServiceTaskProcessor { execution.setVariable("globalSubscriberId", globalSubscriberId) execution.setVariable("globalCustomerId", globalSubscriberId) - + String suppressRollback = jsonUtil.getJsonValue(DeleteVcpeResCustServiceRequest, "requestDetails.requestInfo.suppressRollback") execution.setVariable("disableRollback", suppressRollback) msoLogger.debug("Incoming Suppress/Disable Rollback is: " + suppressRollback) - + String productFamilyId = jsonUtil.getJsonValue(DeleteVcpeResCustServiceRequest, "requestDetails.requestInfo.productFamilyId") execution.setVariable("productFamilyId", productFamilyId) msoLogger.debug("Incoming productFamilyId is: " + productFamilyId) - + // extract subscriptionServiceType String subscriptionServiceType = jsonUtil.getJsonValue(DeleteVcpeResCustServiceRequest, "requestDetails.requestParameters.subscriptionServiceType") execution.setVariable("subscriptionServiceType", subscriptionServiceType) msoLogger.debug("Incoming subscriptionServiceType is: " + subscriptionServiceType) - + // extract cloud configuration String cloudConfiguration = jsonUtil.getJsonValue(DeleteVcpeResCustServiceRequest, "requestDetails.cloudConfiguration") execution.setVariable("cloudConfiguration", cloudConfiguration) @@ -145,7 +153,7 @@ public class DeleteVcpeResCustService extends AbstractServiceTaskProcessor { String sdncVersion = "1707" execution.setVariable("sdncVersion", sdncVersion) msoLogger.debug("sdncVersion: "+ sdncVersion) - + //For Completion Handler & Fallout Handler String requestInfo = """<request-info xmlns="http://org.onap/so/infra/vnf-request/v1"> @@ -155,10 +163,7 @@ public class DeleteVcpeResCustService extends AbstractServiceTaskProcessor { </request-info>""" execution.setVariable(Prefix+"requestInfo", requestInfo) - - //Setting for Generic Sub Flows - execution.setVariable("GENGS_type", "service-instance") - + msoLogger.trace("Completed preProcessRequest DeleteVcpeResCustServiceRequest Request ") } catch (BpmnError e) { @@ -189,120 +194,87 @@ public class DeleteVcpeResCustService extends AbstractServiceTaskProcessor { } } - public void prepareServiceDelete(DelegateExecution execution) { - def isDebugEnabled=execution.getVariable(DebugFlag) - msoLogger.trace("Inside prepareServiceDelete() of DeleteVcpeResCustService ") - + /** + * Gets the service instance and its related resources from aai + * + * @author cb645j + */ + public void getServiceInstance(DelegateExecution execution) { try { - - String serviceInstanceId = execution.getVariable("serviceInstanceId") - - // confirm if ServiceInstance was found - if ( !execution.getVariable("GENGS_FoundIndicator") ) - { - String exceptionMessage = "Bpmn error encountered in DeleteVcpeResCustService flow. Service Instance was not found in AAI by id: " + serviceInstanceId - exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage) - } - - // get variable within incoming json - String DeleteVcpeResCustServiceRequest = execution.getVariable("DeleteVcpeResCustServiceRequest"); - - // get SI extracted by GenericGetService - String serviceInstanceAaiRecord = execution.getVariable("GENGS_service"); - - msoLogger.debug("serviceInstanceAaiRecord: "+serviceInstanceAaiRecord) - serviceInstanceAaiRecord = utils.removeXmlNamespaces(serviceInstanceAaiRecord) - - def (TXC_found, TXC_id) = new Tuple(false, null) - def (BRG_found, BRG_id) = new Tuple(false, null) - List relatedVnfIdList = [] - - for(Node rel: utils.getMultNodeObjects(serviceInstanceAaiRecord, "relationship")) { - def relto = utils.getChildNodeText(rel, "related-to") - def relink = utils.getChildNodeText(rel, "related-link") - msoLogger.debug("check: "+relto+" link: "+relink) - - if(isBlank(relto) || isBlank(relink)) { - - } else if(relto == "generic-vnf") { - def id = relink.substring(relink.indexOf("/generic-vnf/")+13) - if(id.endsWith("/")) { - id = id.substring(0, id.length()-1) + String serviceInstanceId = execution.getVariable('serviceInstanceId') + + AAIResourcesClient resourceClient = new AAIResourcesClient() + AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, serviceInstanceId) + + if(resourceClient.exists(uri)){ + AAIResultWrapper wrapper = resourceClient.get(uri, NotFoundException.class) + Optional<Relationships> relationships = wrapper.getRelationships() + + def (TXC_found, TXC_id) = new Tuple(false, null) + def (BRG_found, BRG_id) = new Tuple(false, null) + List relatedVnfIdList = [] + + if(relationships.isPresent()){ + + List<AAIResourceUri> vnfUris = relationships.get().getRelatedAAIUris(AAIObjectType.GENERIC_VNF) + for(AAIResourceUri u:vnfUris){ + Map<String, String> keys = u.getURIKeys() + String vnfId = keys.get("vnf-id") + relatedVnfIdList.add(vnfId) } - - relatedVnfIdList.add(id) - - } else if(relto == "allotted-resource") { - def (type, id) = getAaiAr(execution, relink) - - if(isBlank(type) || isBlank(id)) { - - } else if(type == "TunnelXConn" || type == "Tunnel XConn") { - msoLogger.debug("TunnelXConn AR found") - TXC_found = true - TXC_id = id - - } else if(type == "BRG") { - msoLogger.debug("BRG AR found") - BRG_found = true - BRG_id = id + List<AAIResourceUri> arUris = relationships.get().getRelatedAAIUris(AAIObjectType.ALLOTTED_RESOURCE) + for(AAIResourceUri u:arUris){ + String ar = resourceClient.get(u).getJson() + + def type = jsonUtil.getJsonValue(ar, "type") + def id = jsonUtil.getJsonValue(ar, "id") + + if(type == "TunnelXConn" || type == "Tunnel XConn") { + msoLogger.debug("TunnelXConn AR found") + TXC_found = true + TXC_id = id + + }else if(type == "BRG") { + msoLogger.debug("BRG AR found") + BRG_found = true + BRG_id = id + } + + execution.setVariable(Prefix+"TunnelXConn", TXC_found) + execution.setVariable("TXC_allottedResourceId", TXC_id) + msoLogger.debug("TXC_allottedResourceId: " + TXC_id) + + execution.setVariable(Prefix+"BRG", BRG_found) + execution.setVariable("BRG_allottedResourceId", BRG_id) + msoLogger.debug("BRG_allottedResourceId: " + BRG_id) + } } + + execution.setVariable(Prefix+"vnfsCount", relatedVnfIdList.size()) + if(relatedVnfIdList.size() > 0) { + execution.setVariable(Prefix+"relatedVnfIdList", relatedVnfIdList) + } + + }else{ + exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Service Instance was not found in aai") } - - execution.setVariable(Prefix+"TunnelXConn", TXC_found) - execution.setVariable("TXC_allottedResourceId", TXC_id) - msoLogger.debug("TXC_allottedResourceId: " + TXC_id) - - execution.setVariable(Prefix+"BRG", BRG_found) - execution.setVariable("BRG_allottedResourceId", BRG_id) - msoLogger.debug("BRG_allottedResourceId: " + BRG_id) - - int vnfsCount = relatedVnfIdList.size() - execution.setVariable(Prefix+"vnfsCount", vnfsCount) - msoLogger.debug(" "+Prefix+"vnfsCount : " + vnfsCount) - if(vnfsCount > 0) { - execution.setVariable(Prefix+"relatedVnfIdList", relatedVnfIdList) - } - - msoLogger.trace("Completed prepareServiceDelete() of DeleteVcpeResCustService ") - } catch (BpmnError e){ + + }catch(BpmnError e) { throw e; - } catch (Exception ex) { - sendSyncError(execution) - String exceptionMessage = "Bpmn error encountered in DeleteVcpeResCustService flow. prepareServiceDelete() - " + ex.getMessage() - msoLogger.debug(exceptionMessage) - exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage) - } - } - - private getAaiAr(DelegateExecution execution, String relink) { - def isDebugEnabled = execution.getVariable(DebugFlag) - AaiUtil aaiUtil = new AaiUtil(this) - String aaiEndpoint = UrnPropertiesReader.getVariable("aai.endpoint",execution) + relink - - msoLogger.debug("get AR info " + aaiEndpoint) - APIResponse response = aaiUtil.executeAAIGetCall(execution, aaiEndpoint) - - int responseCode = response.getStatusCode() - msoLogger.debug("get AR info responseCode:" + responseCode) - - String aaiResponse = response.getResponseBodyAsString() - msoLogger.debug("get AR info " + aaiResponse) - - if(responseCode < 200 || responseCode >= 300 || isBlank(aaiResponse)) { - return new Tuple2(null, null) + }catch(NotFoundException e) { + msoLogger.debug("Service Instance does not exist AAI") + exceptionUtil.buildAndThrowWorkflowException(execution, 404, "Service Instance was not found in aai") + }catch(Exception ex) { + String msg = "Internal Error in getServiceInstance: " + ex.getMessage() + msoLogger.debug(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) } - - def type = utils.getNodeText(aaiResponse, "type") - def id = utils.getNodeText(aaiResponse, "id") - - return new Tuple2(type, id) } - - + + // ******************************* - // + // // ******************************* public void prepareVnfAndModulesDelete (DelegateExecution execution) { def isDebugEnabled=execution.getVariable(DebugFlag) @@ -316,7 +288,7 @@ public class DeleteVcpeResCustService extends AbstractServiceTaskProcessor { if (vnfList.size() > 0 ) { vnfId = vnfList.get(vnfsDeletedCount.intValue()) } - + execution.setVariable("vnfId", vnfId) msoLogger.debug("need to delete vnfId:" + vnfId) @@ -327,7 +299,7 @@ public class DeleteVcpeResCustService extends AbstractServiceTaskProcessor { exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage) } } - + // ******************************* // Validate Vnf request Section -> increment count // ******************************* @@ -338,9 +310,9 @@ public class DeleteVcpeResCustService extends AbstractServiceTaskProcessor { try { int vnfsDeletedCount = execution.getVariable(Prefix+"vnfsDeletedCount") vnfsDeletedCount++ - + execution.setVariable(Prefix+"vnfsDeletedCount", vnfsDeletedCount) - + msoLogger.debug(" ***** Completed validateVnfDelete of DeleteVcpeResCustService ***** "+" vnf # "+vnfsDeletedCount) } catch (Exception ex) { // try error in method block @@ -349,7 +321,7 @@ public class DeleteVcpeResCustService extends AbstractServiceTaskProcessor { } } - + // ***************************************** // Prepare Completion request Section // ***************************************** diff --git a/bpmn/so-bpmn-infrastructure-flows/src/main/groovy/org/onap/so/bpmn/vcpe/scripts/DoCreateAllottedResourceBRG.groovy b/bpmn/so-bpmn-infrastructure-flows/src/main/groovy/org/onap/so/bpmn/vcpe/scripts/DoCreateAllottedResourceBRG.groovy index 8a8aa2b2ad..3c08779513 100644 --- a/bpmn/so-bpmn-infrastructure-flows/src/main/groovy/org/onap/so/bpmn/vcpe/scripts/DoCreateAllottedResourceBRG.groovy +++ b/bpmn/so-bpmn-infrastructure-flows/src/main/groovy/org/onap/so/bpmn/vcpe/scripts/DoCreateAllottedResourceBRG.groovy @@ -7,9 +7,9 @@ * 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. @@ -37,12 +37,19 @@ import static org.apache.commons.lang3.StringUtils.* import org.onap.so.logger.MessageEnum import org.onap.so.logger.MsoLogger - +import org.onap.so.client.aai.AAIResourcesClient +import org.onap.so.client.aai.AAIObjectType +import org.onap.so.client.aai.entities.AAIResultWrapper +import org.onap.so.client.aai.entities.Relationships +import org.onap.so.client.aai.entities.uri.AAIResourceUri +import org.onap.so.client.aai.entities.uri.AAIUriFactory +import org.json.JSONObject +import javax.ws.rs.NotFoundException /** * This groovy class supports the <class>DoCreateAllottedResourceBRG.bpmn</class> process. * * @author - * + * * Inputs: * @param - msoRequestId * @param - isDEbugLogEnabled @@ -57,15 +64,15 @@ import org.onap.so.logger.MsoLogger * @param - allottedResourceRole * @param - allottedResourceType * @param - brgWanMacAddress - * @param - vni - * @param - vgmuxBearerIP + * @param - vni + * @param - vgmuxBearerIP * * Outputs: * @param - rollbackData (localRB->null) * @param - rolledBack (no localRB->null, localRB F->false, localRB S->true) * @param - WorkflowException - O * @param - allottedResourceId - * @param - allottedResourceName + * @param - allottedResourceName * */ public class DoCreateAllottedResourceBRG extends AbstractServiceTaskProcessor{ @@ -155,6 +162,33 @@ public class DoCreateAllottedResourceBRG extends AbstractServiceTaskProcessor{ msoLogger.trace("end preProcessRequest") } + /** + * Gets the service instance uri from aai + */ + public void getServiceInstance(DelegateExecution execution) { + msoLogger.trace("getServiceInstance ") + try { + String serviceInstanceId = execution.getVariable('serviceInstanceId') + + AAIResourcesClient resourceClient = new AAIResourcesClient() + AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, serviceInstanceId) + + if(resourceClient.exists(uri)){ + execution.setVariable("CSI_resourceLink", uri.build().toString()) + }else{ + exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Service instance was not found in aai") + } + + }catch(BpmnError e) { + throw e; + }catch (Exception ex){ + String msg = "Exception in getServiceInstance. " + ex.getMessage() + msoLogger.debug(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) + } + msoLogger.trace("Exit getServiceInstance ") + } + public void getAaiAR (DelegateExecution execution) { @@ -193,6 +227,39 @@ public class DoCreateAllottedResourceBRG extends AbstractServiceTaskProcessor{ msoLogger.trace("end getAaiAR") } + public void getParentServiceInstance(DelegateExecution execution) { + msoLogger.trace("getParentServiceInstance ") + try { + String serviceInstanceId = execution.getVariable('parentServiceInstanceId') + + AAIResourcesClient resourceClient = new AAIResourcesClient() + AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.NODES_QUERY, "").queryParam("search-node-type", "service-instance").queryParam("filter", "service-instance-id:EQUALS:" + serviceInstanceId) + String json = resourceClient.get(uri).getJson() + + JSONObject obj = new JSONObject(json) + if(obj.has("result-data")){ + JSONObject ob = obj.getJSONArray("result-data").getJSONObject(0) + String resourceLink = ob.getString("resource-link") + + String[] split = resourceLink.split("/aai/") + String siRelatedLink = "/aai/" + split[1] + + execution.setVariable("PSI_resourceLink", resourceLink) + }else{ + exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Service instance was not found in aai") + } + + }catch(BpmnError e) { + throw e; + }catch (Exception ex){ + String msg = "Exception in getParentServiceInstance. " + ex.getMessage() + msoLogger.debug(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) + } + msoLogger.trace("Exit getParentServiceInstance ") + } + + public void createAaiAR(DelegateExecution execution) { @@ -387,9 +454,9 @@ public class DoCreateAllottedResourceBRG extends AbstractServiceTaskProcessor{ <global-customer-id>${MsoUtils.xmlEscape(globalCustomerId)}</global-customer-id> </service-information> <allotted-resource-information> - <allotted-resource-id>${MsoUtils.xmlEscape(allottedResourceId)}</allotted-resource-id> + <allotted-resource-id>${MsoUtils.xmlEscape(allottedResourceId)}</allotted-resource-id> <allotted-resource-type>brg</allotted-resource-type> - <parent-service-instance-id>${MsoUtils.xmlEscape(parentServiceInstanceId)}</parent-service-instance-id> + <parent-service-instance-id>${MsoUtils.xmlEscape(parentServiceInstanceId)}</parent-service-instance-id> <onap-model-information> <model-invariant-uuid>${MsoUtils.xmlEscape(modelInvariantId)}</model-invariant-uuid> <model-uuid>${MsoUtils.xmlEscape(modelUUId)}</model-uuid> @@ -575,7 +642,7 @@ public class DoCreateAllottedResourceBRG extends AbstractServiceTaskProcessor{ String serviceInstanceId = execution.getVariable("serviceInstanceId") String sdncRequestId = UUID.randomUUID().toString() - + //neeed the same url as used by vfmodules String SDNCGetRequest = """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.onap/so/request/types/v1" @@ -600,7 +667,7 @@ public class DoCreateAllottedResourceBRG extends AbstractServiceTaskProcessor{ } msoLogger.trace("end preProcessSDNCGet") } - + public void updateAaiAROrchStatus(DelegateExecution execution, String status){ msoLogger.trace("start updateAaiAROrchStatus") @@ -609,7 +676,7 @@ public class DoCreateAllottedResourceBRG extends AbstractServiceTaskProcessor{ String orchStatus = arUtils.updateAROrchStatus(execution, status, aaiARPath) msoLogger.trace("end updateAaiAROrchStatus") } - + public void generateOutputs(DelegateExecution execution) { @@ -619,7 +686,7 @@ public class DoCreateAllottedResourceBRG extends AbstractServiceTaskProcessor{ msoLogger.debug("resp:" + sdncGetResponse) String arData = utils.getNodeXml(sdncGetResponse, "brg-topology") arData = utils.removeXmlNamespaces(arData) - + String brga = utils.getNodeXml(arData, "brg-assignments") String ari = utils.getNodeXml(arData, "allotted-resource-identifiers") execution.setVariable("allotedResourceName", utils.getNodeText(ari, "allotted-resource-name")) @@ -630,7 +697,7 @@ public class DoCreateAllottedResourceBRG extends AbstractServiceTaskProcessor{ msoLogger.debug(msg) } msoLogger.trace("end generateOutputs") - + } public void preProcessRollback (DelegateExecution execution) { |