From e88ee9a2c2970735222eeeb155eaf4fdfb63698d Mon Sep 17 00:00:00 2001 From: subhash kumar singh Date: Wed, 11 Apr 2018 05:58:45 +0000 Subject: Implementation for SDNC resource delete Implementation for SDNC resource delete Change-Id: I7e7366cadb29ad9c4d4a3ca4f25512e6cbf2fcdb Issue-ID: SO-422 Signed-off-by: subhash kumar singh --- .../scripts/DeleteSDNCNetworkResource.groovy | 222 +++++++++++++++++++++ 1 file changed, 222 insertions(+) create mode 100644 bpmn/MSOInfrastructureBPMN/src/main/groovy/org/openecomp/mso/bpmn/infrastructure/scripts/DeleteSDNCNetworkResource.groovy (limited to 'bpmn') diff --git a/bpmn/MSOInfrastructureBPMN/src/main/groovy/org/openecomp/mso/bpmn/infrastructure/scripts/DeleteSDNCNetworkResource.groovy b/bpmn/MSOInfrastructureBPMN/src/main/groovy/org/openecomp/mso/bpmn/infrastructure/scripts/DeleteSDNCNetworkResource.groovy new file mode 100644 index 0000000000..479e091345 --- /dev/null +++ b/bpmn/MSOInfrastructureBPMN/src/main/groovy/org/openecomp/mso/bpmn/infrastructure/scripts/DeleteSDNCNetworkResource.groovy @@ -0,0 +1,222 @@ + +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. 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. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.openecomp.mso.bpmn.infrastructure.scripts + +import org.json.JSONArray +import org.openecomp.mso.bpmn.common.resource.ResourceRequestBuilder +import org.openecomp.mso.bpmn.core.domain.Resource +import org.openecomp.mso.bpmn.core.domain.ServiceDecomposition +import org.openecomp.mso.bpmn.infrastructure.properties.BPMNProperties; +import org.apache.http.HttpResponse +import org.json.JSONArray +import org.openecomp.mso.bpmn.common.recipe.BpmnRestClient +import org.openecomp.mso.bpmn.common.recipe.ResourceInput; + +import static org.apache.commons.lang3.StringUtils.*; +import groovy.xml.XmlUtil +import org.openecomp.mso.bpmn.common.scripts.CatalogDbUtils; +import groovy.json.* + +import org.openecomp.mso.bpmn.core.json.JsonUtils +import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor +import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil +import org.openecomp.mso.bpmn.common.scripts.SDNCAdapterUtils +import org.openecomp.mso.bpmn.core.WorkflowException +import org.openecomp.mso.rest.APIResponse; +import org.openecomp.mso.rest.RESTClient +import org.openecomp.mso.rest.RESTConfig + +import java.util.List; +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.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 + +import com.fasterxml.jackson.jaxrs.json.annotation.JSONP.Def; + +public class DeleteSDNCNetworkResource extends AbstractServiceTaskProcessor { + String Prefix="DDELSDNNS_" + + + public void preProcessRequest (DelegateExecution execution) { + def isDebugEnabled = execution.getVariable("isDebugLogEnabled") + utils.log("INFO"," ***** preProcessSDNCDelete *****", isDebugEnabled) + String msg = "" + + try { + serviceInstanceId = execution.getVariable("serviceInstanceId") + serviceInstanceName = execution.getVariable("serviceInstanceName") + callbackURL = execution.getVariable("sdncCallbackUrl") + requestId = execution.getVariable("msoRequestId") + serviceId = execution.getVariable("productFamilyId") + subscriptionServiceType = execution.getVariable("subscriptionServiceType") + globalSubscriberId = execution.getVariable("globalSubscriberId") //globalCustomerId + String recipeParamsFromRequest = execution.getVariable("recipeParams") + String serviceModelInfo = execution.getVariable("serviceModelInfo") + modelInvariantUuid = "" + modelVersion = "" + modelUuid = "" + modelName = "" + + if (!isBlank(serviceModelInfo)) + { + modelInvariantUuid = jsonUtil.getJsonValue(serviceModelInfo, "modelInvariantUuid") + modelVersion = jsonUtil.getJsonValue(serviceModelInfo, "modelVersion") + modelUuid = jsonUtil.getJsonValue(serviceModelInfo, "modelUuid") + modelName = jsonUtil.getJsonValue(serviceModelInfo, "modelName") + + if (modelInvariantUuid == null) { + modelInvariantUuid = "" + } + if (modelVersion == null) { + modelVersion = "" + } + if (modelUuid == null) { + modelUuid = "" + } + if (modelName == null) { + modelName = "" + } + } + if (serviceInstanceName == null) { + serviceInstanceName = "" + } + if (serviceId == null) { + serviceId = "" + } + + def siParamsXml = execution.getVariable("siParamsXml") + def serviceType = execution.getVariable("serviceType") + if (serviceType == null) + { + serviceType = "" + } + + sdncRequestId = UUID.randomUUID().toString() + + String recipeParamsFromWf = execution.getVariable("recipeParamXsd") + + String operationType = "Network" + String sdnc_svcAction = "delete" + + if(!StringUtils.isBlank(recipeParamsFromRequest)){ + //the operationType from worflow(first node) is second priority. + operationType = jsonUtil.getJsonValue(recipeParamsFromRequest, "operationType") + } + if(!StringUtils.isBlank(recipeParamsFromWf)){ + //the operationType from worflow(first node) is highest priority. + operationType = jsonUtil.getJsonValue(recipeParamsFromWf, "operationType") + } + + operationType = "delete" + operationType + "Instance" + + if(StringUtils.containsIgnoreCase(resourceInputObj.getResourceInstanceName(), "overlay")){ + //This will be resolved in R3. + sdnc_svcAction ="deactivate" + operationType = "DeActivateDCINetworkInstance" + } + if(StringUtils.containsIgnoreCase(resourceInputObj.getResourceInstanceName(), "underlay")){ + //This will be resolved in R3. + operationType ="DeleteNetworkInstance" + } + + String sdncDelete = + """ + + ${sdncRequestId} + ${serviceInstanceId} + ${sdnc_svcAction} + service-topology-operation + ${callbackURL} + ${serviceType} + + + + ${requestId} + MSO + + + + ${operationType} + + + ${serviceId} + ${subscriptionServiceType} + + ${modelInvariantUuid} + ${modelUuid} + ${modelVersion} + ${modelName} + + ${serviceInstanceId} + + ${globalSubscriberId} + + + ${serviceInstanceName} + ${siParamsXml} + + + """ + + sdncDelete = utils.formatXml(sdncDelete) + //def sdncRequestId2 = UUID.randomUUID().toString() + //String sdncDeactivate = sdncDelete.replace(">delete<", ">deactivate<").replace(">${sdncRequestId}<", ">${sdncRequestId2}<") + execution.setVariable("sdncDelete", sdncDelete) + execution.setVariable("sdncDeactivate", sdncDeactivate) + utils.log("INFO","sdncDeactivate:\n" + sdncDeactivate, isDebugEnabled) + utils.log("INFO","sdncDelete:\n" + sdncDelete, isDebugEnabled) + + } catch (BpmnError e) { + throw e; + } catch(Exception ex) { + msg = "Exception in preProcessSDNCDelete. " + ex.getMessage() + utils.log("INFO", msg, isDebugEnabled) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, "Exception Occured in preProcessSDNCDelete.\n" + ex.getMessage()) + } + utils.log("INFO"," *****Exit preProcessSDNCDelete *****", isDebugEnabled) + } + + + public void postProcessSDNCDelete(DelegateExecution execution, String response) { + + def isDebugEnabled=execution.getVariable("isDebugLogEnabled") + utils.log("INFO"," ***** postProcessSDNC " + " *****", isDebugEnabled) + String msg = "" + utils.log("INFO"," response " + response, isDebugEnabled) + utils.log("INFO"," *** Exit postProcessSDNC " + " ***", isDebugEnabled) + } + +} -- cgit 1.2.3-korg