From 2771d9cf7af721ab447add53e69f22e1c57cd007 Mon Sep 17 00:00:00 2001 From: zm330 Date: Wed, 26 Feb 2020 18:37:32 +0800 Subject: Add DeallocateNSSI Sub-process Issue-ID: SO-2368 Signed-off-by: zm330 Change-Id: Ibf443a3d490e48d397f1f3240207b5c00b92695f --- .../onap/so/bpmn/core/domain/ServiceArtifact.java | 119 ++++++++ .../infrastructure/scripts/DoDeallocateNSSI.groovy | 309 +++++++++++++++++++++ .../resources/subprocess/DoDeallocateNSSI.bpmn | 254 +++++++++++++++++ 3 files changed, 682 insertions(+) create mode 100644 bpmn/MSOCoreBPMN/src/main/java/org/onap/so/bpmn/core/domain/ServiceArtifact.java create mode 100644 bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeallocateNSSI.groovy create mode 100644 bpmn/so-bpmn-infrastructure-flows/src/main/resources/subprocess/DoDeallocateNSSI.bpmn (limited to 'bpmn') diff --git a/bpmn/MSOCoreBPMN/src/main/java/org/onap/so/bpmn/core/domain/ServiceArtifact.java b/bpmn/MSOCoreBPMN/src/main/java/org/onap/so/bpmn/core/domain/ServiceArtifact.java new file mode 100644 index 0000000000..aefd70ff89 --- /dev/null +++ b/bpmn/MSOCoreBPMN/src/main/java/org/onap/so/bpmn/core/domain/ServiceArtifact.java @@ -0,0 +1,119 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + # Copyright (c) 2019, CMCC Technologies Co., Ltd. + # + # Licensed under the Apache License, Version 2.0 (the "License") + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.onap.so.bpmn.core.domain; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import com.fasterxml.jackson.annotation.JsonRootName; +import java.io.Serializable; + +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonPropertyOrder({"artifactUUID", "name", "version", "checksum", "type", "content", "description"}) +@JsonRootName("serviceArtifact") +public class ServiceArtifact extends JsonWrapper implements Serializable { + + private static final long serialVersionUID = 1L; + @JsonProperty("artifactUUID") + private String artifactUUID; + @JsonProperty("name") + private String name; + @JsonProperty("version") + private String version; + @JsonProperty("checksum") + private String checksum; + @JsonProperty("type") + private String type; + @JsonProperty("content") + private String content; + @JsonProperty("description") + private String description; + + @JsonProperty("artifactUUID") + public String getArtifactUUID() { + return artifactUUID; + } + + @JsonProperty("artifactUUID") + public void setArtifactUUID(String artifactUUID) { + this.artifactUUID = artifactUUID; + } + + @JsonProperty("name") + public String getName() { + return name; + } + + @JsonProperty("name") + public void setName(String name) { + this.name = name; + } + + @JsonProperty("version") + public String getVersion() { + return version; + } + + @JsonProperty("version") + public void setVersion(String version) { + this.version = version; + } + + @JsonProperty("checksum") + public String getChecksum() { + return checksum; + } + + @JsonProperty("checksum") + public void setChecksum(String checksum) { + this.checksum = checksum; + } + + @JsonProperty("type") + public String getType() { + return type; + } + + @JsonProperty("type") + public void setType(String type) { + this.type = type; + } + + @JsonProperty("content") + public String getContent() { + return content; + } + + @JsonProperty("content") + public void setContent(String content) { + this.content = content; + } + + @JsonProperty("description") + public String getDescription() { + return description; + } + + @JsonProperty("description") + public void setDescription(String description) { + this.description = description; + } + +} diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeallocateNSSI.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeallocateNSSI.groovy new file mode 100644 index 0000000000..d8897a2468 --- /dev/null +++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeallocateNSSI.groovy @@ -0,0 +1,309 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + # Copyright (c) 2019, CMCC Technologies Co., Ltd. + # + # Licensed under the Apache License, Version 2.0 (the "License") + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.onap.so.bpmn.infrastructure.scripts + +import com.fasterxml.jackson.databind.ObjectMapper +import org.camunda.bpm.engine.delegate.DelegateExecution +import org.onap.logging.filter.base.ONAPComponents +import org.onap.so.beans.nsmf.DeAllocateNssi +import org.onap.so.beans.nsmf.EsrInfo +import org.onap.so.beans.nsmf.JobStatusRequest +import org.onap.so.beans.nsmf.JobStatusResponse +import org.onap.so.beans.nsmf.NetworkType +import org.onap.so.beans.nsmf.NssiDeAllocateRequest +import org.onap.so.beans.nsmf.NssiResponse +import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor +import org.onap.so.bpmn.common.scripts.ExceptionUtil +import org.onap.so.bpmn.common.scripts.RequestDBUtil +import org.onap.so.bpmn.core.UrnPropertiesReader +import org.onap.so.bpmn.core.domain.ServiceArtifact +import org.onap.so.bpmn.core.domain.ServiceDecomposition +import org.onap.so.bpmn.core.json.JsonUtils +import org.onap.so.client.HttpClient +import org.onap.so.client.HttpClientFactory +import org.onap.so.client.aai.AAIObjectType +import org.onap.so.client.aai.AAIResourcesClient +import org.onap.so.client.aai.entities.uri.AAIResourceUri +import org.onap.so.client.aai.entities.uri.AAIUriFactory +import org.onap.so.db.request.beans.OperationStatus +import org.slf4j.Logger +import org.slf4j.LoggerFactory + +import javax.ws.rs.core.Response + + +class DoDeallocateNSSI extends AbstractServiceTaskProcessor +{ + private final String PREFIX ="DoDeallocateNSSI" + + private ExceptionUtil exceptionUtil = new ExceptionUtil() + private JsonUtils jsonUtil = new JsonUtils() + private RequestDBUtil requestDBUtil = new RequestDBUtil() + private static final Logger LOGGER = LoggerFactory.getLogger( DoDeallocateNSSI.class) + + @Override + void preProcessRequest(DelegateExecution execution) { + LOGGER.trace(" ***** ${PREFIX} Start preProcessRequest *****") + + def currentNSSI = execution.getVariable("currentNSSI") + if (!currentNSSI) { + String msg = "currentNSSI is null" + LOGGER.error(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg) + } + + LOGGER.trace("***** ${PREFIX} Exit preProcessRequest *****") + } + + /** + * + * @param execution + */ + private void prepareDecomposeService(DelegateExecution execution) + { + LOGGER.trace(" *****${PREFIX} Start prepareDecomposeService *****") + try + { + def currentNSSI = execution.getVariable("currentNSSI") + String modelInvariantUuid = currentNSSI['modelInvariantId'] + String modelVersionId = currentNSSI['modelVersionId'] + String serviceModelInfo = """{ + "modelInvariantUuid":"${modelInvariantUuid}", + "modelUuid":"${modelVersionId}", + "modelVersion":"" + }""" + execution.setVariable("serviceModelInfo", serviceModelInfo) + } + catch (any) + { + String exceptionMessage = "Bpmn error encountered in deallocate nssi. Unexpected Error from method prepareDecomposeService() - " + any.getMessage() + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage) + } + LOGGER.debug(" ***** ${PREFIX} Exit prepareDecomposeService *****") + } + + /** + * get vendor Info + * @param execution + */ + private void processDecomposition(DelegateExecution execution) { + LOGGER.debug("*****${PREFIX} start processDecomposition *****") + + try { + ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition") as ServiceDecomposition + ServiceArtifact serviceArtifact = serviceDecomposition ?.getServiceInfo()?.getServiceArtifact()?.get(0) + String content = serviceArtifact.getContent() + String vendor = jsonUtil.getJsonValue(content, "metadata.vendor") + String domainType = jsonUtil.getJsonValue(content, "metadata.domainType") + + def currentNSSI = execution.getVariable("currentNSSI") + currentNSSI['vendor'] = vendor + currentNSSI['domainType'] = domainType + LOGGER.info("processDecomposition, current vendor-domainType:" +String.join("-", vendor, domainType)) + + } catch (any) { + String exceptionMessage = "Bpmn error encountered in deallocate nssi. processDecomposition() - " + any.getMessage() + LOGGER.debug(exceptionMessage) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage) + } + LOGGER.debug("*****${PREFIX} Exit processDecomposition *****") + } + + /** + * send deallocate request to nssmf + * @param execution + */ + private void sendRequestToNSSMF(DelegateExecution execution) + { + LOGGER.debug("*****${PREFIX} start sendRequestToNSSMF *****") + def currentNSSI = execution.getVariable("currentNSSI") + String snssai= currentNSSI['snssai'] + String profileId = currentNSSI['profileId'] + String nssiId = currentNSSI['nssiServiceInstanceId'] + String nsiId = currentNSSI['nsiServiceInstanceId'] + + DeAllocateNssi deAllocateNssi = new DeAllocateNssi() + deAllocateNssi.setNsiId(nsiId) + deAllocateNssi.setNssiId(nssiId) + deAllocateNssi.setTerminateNssiOption(0) + deAllocateNssi.setSnssaiList(Arrays.asList(snssai)) + + NssiDeAllocateRequest deAllocateRequest = new NssiDeAllocateRequest() + deAllocateRequest.setDeAllocateNssi(deAllocateNssi) + deAllocateRequest.setEsrInfo(getEsrInfo(currentNSSI)) + + ObjectMapper mapper = new ObjectMapper() + String json = mapper.writeValueAsString(deAllocateRequest) + + //Prepare auth for NSSMF - Begin + String nssmfRequest = UrnPropertiesReader.getVariable("mso.adapters.nssmf.endpoint", execution) + nssmfRequest = nssmfRequest + String.format("/api/rest/provMns/v1/NSS/SliceProfiles/%s",profileId) + //nssmfRequest = nssmfRequest + String.format(NssmfAdapterUtil.NSSMI_DEALLOCATE_URL,profileId) + //send request to active NSSI TN option + URL url = new URL(nssmfRequest) + LOGGER.info("deallocate nssmfRequest:${nssmfRequest}, reqBody: ${json}") + + HttpClient httpClient = new HttpClientFactory().newJsonClient(url, ONAPComponents.EXTERNAL) + Response httpResponse = httpClient.post(json) + checkNssmfResponse(httpResponse, execution) + + NssiResponse nssmfResponse = httpResponse.readEntity(NssiResponse.class) + currentNSSI['jobId']= nssmfResponse.getJobId() ?: "" + currentNSSI['jobProgress'] = 0 + execution.setVariable("currentNSSI", currentNSSI) + + LOGGER.debug("*****${PREFIX} Exit sendRequestToNSSMF *****") + } + + /** + * send to nssmf query progress + * @param execution + */ + private void getJobStatus(DelegateExecution execution) + { + def currentNSSI = execution.getVariable("currentNSSI") + String jobId = currentNSSI['jobId'] + String nssiId = currentNSSI['nssiServiceInstanceId'] + String nsiId = currentNSSI['nsiServiceInstanceId'] + + JobStatusRequest jobStatusRequest = new JobStatusRequest() + jobStatusRequest.setNssiId(nssiId) + jobStatusRequest.setNsiId(nsiId) + jobStatusRequest.setEsrInfo(getEsrInfo(currentNSSI)) + + ObjectMapper mapper = new ObjectMapper() + String json = mapper.writeValueAsString(jobStatusRequest) + + //Prepare auth for NSSMF - Begin + String nssmfRequest = UrnPropertiesReader.getVariable("mso.adapters.nssmf.endpoint", execution) + nssmfRequest = nssmfRequest + String.format("/api/rest/provMns/v1/NSS/jobs/%s",jobId) + //send request to active NSSI TN option + URL url = new URL(nssmfRequest) + LOGGER.info("get deallocate job status, nssmfRequest:${nssmfRequest}, requestBody: ${json}") + + HttpClient httpClient = new HttpClientFactory().newJsonClient(url, ONAPComponents.EXTERNAL) + Response httpResponse = httpClient.post(json) + checkNssmfResponse(httpResponse, execution) + + JobStatusResponse jobStatusResponse = httpResponse.readEntity(JobStatusResponse.class) + def progress = jobStatusResponse?.getResponseDescriptor()?.getProgress() + if(!progress) + { + LOGGER.error("job progress is null or empty!") + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, "Received a Bad Job progress from NSSMF.") + } + int oldProgress = currentNSSI['jobProgress'] + int currentProgress = progress + + execution.setVariable("isNSSIDeAllocated", (currentProgress == 100)) + execution.setVariable("isNeedUpdateDB", (oldProgress != currentProgress)) + currentNSSI['jobProgress'] = currentProgress + + def statusDescription = jobStatusResponse?.getResponseDescriptor()?.getStatusDescription() + currentNSSI['statusDescription'] = statusDescription + + LOGGER.debug("job status result: nsiId = ${nsiId}, nssiId=${nssiId}, oldProgress=${oldProgress}, progress = ${currentProgress}" ) + } + + private void checkNssmfResponse(Response httpResponse, DelegateExecution execution) { + int responseCode = httpResponse.getStatus() + LOGGER.debug("NSSMF response code is: " + responseCode) + + if ( responseCode < 200 || responseCode > 204 || !httpResponse.hasEntity()) { + exceptionUtil.buildAndThrowWorkflowException(execution, responseCode, "Received a Bad Response from NSSMF.") + } + } + + + private EsrInfo getEsrInfo(def currentNSSI) + { + String domaintype = currentNSSI['domainType'] + String vendor = currentNSSI['vendor'] + + EsrInfo info = new EsrInfo() + info.setNetworkType(NetworkType.fromString(domaintype)) + info.setVendor(vendor) + return info + } + + /** + * handle job status + * prepare update requestdb + * @param execution + */ + private void handleJobStatus(DelegateExecution execution) + { + def currentNSSI = execution.getVariable("currentNSSI") + int currentProgress = currentNSSI["jobProgress"] + def proportion = currentNSSI['proportion'] + def statusDes = currentNSSI["statusDescription"] + int progress = (currentProgress as int) == 0 ? 0 : (currentProgress as int) / 100 * (proportion as int) + + OperationStatus operationStatus = new OperationStatus() + operationStatus.setServiceId(currentNSSI['e2eServiceInstanceId'] as String) + operationStatus.setOperationId(currentNSSI['operationId'] as String) + operationStatus.setOperation("DELETE") + operationStatus.setResult("processing") + operationStatus.setProgress(progress as String) + operationStatus.setOperationContent(statusDes as String) + requestDBUtil.prepareUpdateOperationStatus(execution, operationStatus) + LOGGER.debug("update operation, currentProgress=${currentProgress}, proportion=${proportion}, progress = ${progress}" ) + } + + private void timeDelay(DelegateExecution execution) { + try { + Thread.sleep(10000); + } catch(InterruptedException e) { + LOGGER.error("Time Delay exception" + e) + } + } + + /** + * delete slice profile from aai + * @param execution + */ + private void delSliceProfileFromAAI(DelegateExecution execution) + { + LOGGER.debug("*****${PREFIX} start delSliceProfileFromAAI *****") + def currentNSSI = execution.getVariable("currentNSSI") + String nssiServiceInstanceId = currentNSSI['nssiServiceInstanceId'] + String profileId = currentNSSI['profileId'] + String globalSubscriberId = currentNSSI["globalSubscriberId"] + String serviceType = currentNSSI["serviceType"] + + try + { + LOGGER.debug("delete nssiServiceInstanceId:${nssiServiceInstanceId}, profileId:${profileId}") + AAIResourcesClient resourceClient = new AAIResourcesClient() + AAIResourceUri resourceUri = AAIUriFactory.createResourceUri(AAIObjectType.SLICE_PROFILE, globalSubscriberId, serviceType, nssiServiceInstanceId, profileId) + if (!resourceClient.exists(resourceUri)) { + exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Service Instance was not found in aai") + } + resourceClient.delete(resourceUri) + } + catch (any) + { + String msg = "delete slice profile from aai failed! cause-"+any.getCause() + LOGGER.error(any.printStackTrace()) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) + } + LOGGER.debug("*****${PREFIX} Exist delSliceProfileFromAAI *****") + } +} diff --git a/bpmn/so-bpmn-infrastructure-flows/src/main/resources/subprocess/DoDeallocateNSSI.bpmn b/bpmn/so-bpmn-infrastructure-flows/src/main/resources/subprocess/DoDeallocateNSSI.bpmn new file mode 100644 index 0000000000..db805ecb92 --- /dev/null +++ b/bpmn/so-bpmn-infrastructure-flows/src/main/resources/subprocess/DoDeallocateNSSI.bpmn @@ -0,0 +1,254 @@ + + + + + SequenceFlow_05jfhy6 + + + + SequenceFlow_0eug5nv + SequenceFlow_0wlyy5i + import org.onap.so.bpmn.infrastructure.scripts.* +def dnssi= new DoDeallocateNSSI() +dnssi.prepareDecomposeService(execution) + + + + + + + + + + + SequenceFlow_0wlyy5i + SequenceFlow_1e451y9 + + + + SequenceFlow_1e451y9 + SequenceFlow_1e7o57n + import org.onap.so.bpmn.infrastructure.scripts.* +def dnssi= new DoDeallocateNSSI() +dnssi.processDecomposition(execution) + + + + SequenceFlow_1e7o57n + SequenceFlow_03b0822 + import org.onap.so.bpmn.infrastructure.scripts.* +def dnssi= new DoDeallocateNSSI() +dnssi.sendRequestToNSSMF(execution) + + + + SequenceFlow_03b0822 + SequenceFlow_1anlirk + SequenceFlow_1jj0p5q + import org.onap.so.bpmn.infrastructure.scripts.* +def dnssi= new DoDeallocateNSSI() +dnssi.getJobStatus(execution) + + + + SequenceFlow_1jj0p5q + SequenceFlow_0xq380j + SequenceFlow_0sfh52b + + + SequenceFlow_0xq380j + SequenceFlow_1ii5002 + import org.onap.so.bpmn.infrastructure.scripts.* +def dnssi= new DoDeallocateNSSI() +dnssi.delSliceProfileFromAAI(execution) + + + SequenceFlow_1ii5002 + + + + #{(execution.getVariable("isNSSIDeAllocated" ) == true)} + + + + SequenceFlow_05jfhy6 + SequenceFlow_0eug5nv + import org.onap.so.bpmn.infrastructure.scripts.* +def dnssi= new DoDeallocateNSSI() +dnssi.preProcessRequest(execution) + + + + SequenceFlow_1ugva41 + SequenceFlow_1u66wjs + SequenceFlow_1anlirk + import org.onap.so.bpmn.infrastructure.scripts.* +def dnssi= new DoDeallocateNSSI() +dnssi.timeDelay(execution) + + + + + + ${dbAdapterEndpoint} + + + application/soap+xml + Basic YnBlbDpwYXNzd29yZDEk + + + ${updateOperationStatus} + POST + ${statusCode} + ${response} + + http-connector + + + SequenceFlow_04vg0c2 + SequenceFlow_1ugva41 + + + SequenceFlow_0sfh52b + SequenceFlow_0r95j9m + SequenceFlow_1u66wjs + + + + #{(execution.getVariable("isNeedUpdateDB" ) == true)} + #{(execution.getVariable("isNeedUpdateDB" ) == true)} + + + + + + SequenceFlow_0r95j9m + SequenceFlow_04vg0c2 + import org.onap.so.bpmn.infrastructure.scripts.* +def dnssi= new DoDeallocateNSSI() +dnssi.handleJobStatus(execution) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -- cgit 1.2.3-korg