2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2020 Huawei Technologies Co., Ltd. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License")
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.so.bpmn.infrastructure.scripts
23 import com.fasterxml.jackson.databind.ObjectMapper
24 import groovy.json.JsonSlurper
25 import org.camunda.bpm.engine.delegate.BpmnError
26 import org.camunda.bpm.engine.delegate.DelegateExecution
27 import org.onap.aai.domain.yang.ServiceInstance
28 import org.onap.aaiclient.client.aai.AAIObjectType
29 import org.onap.aaiclient.client.aai.AAIResourcesClient
30 import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri
31 import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory
32 import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder
33 import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types
34 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
35 import org.onap.so.bpmn.common.scripts.ExceptionUtil
36 import org.onap.so.bpmn.common.scripts.RequestDBUtil
37 import org.onap.so.bpmn.core.json.JsonUtils
38 import org.onap.so.db.request.beans.ResourceOperationStatus
39 import org.slf4j.Logger
40 import org.slf4j.LoggerFactory
42 class DoDeallocateTnNssi extends AbstractServiceTaskProcessor {
43 String Prefix = "TNDEALLOC_"
45 ExceptionUtil exceptionUtil = new ExceptionUtil()
46 JsonUtils jsonUtil = new JsonUtils()
47 RequestDBUtil requestDBUtil = new RequestDBUtil()
48 TnNssmfUtils tnNssmfUtils = new TnNssmfUtils()
49 JsonSlurper jsonSlurper = new JsonSlurper()
50 ObjectMapper objectMapper = new ObjectMapper()
51 private static final Logger logger = LoggerFactory.getLogger(DoDeallocateTnNssi.class)
54 void preProcessRequest(DelegateExecution execution) {
55 logger.debug("Start preProcessRequest")
57 execution.setVariable("startTime", System.currentTimeMillis())
58 String msg = tnNssmfUtils.getExecutionInputParams(execution)
59 logger.debug("Deallocate TN NSSI input parameters: " + msg)
61 execution.setVariable("prefix", Prefix)
63 tnNssmfUtils.setSdncCallbackUrl(execution, true)
64 logger.debug("SDNC Callback URL: " + execution.getVariable("sdncCallbackUrl"))
66 String sliceServiceInstanceId = execution.getVariable("serviceInstanceID")
67 execution.setVariable("sliceServiceInstanceId", sliceServiceInstanceId)
69 String sliceServiceInstanceName = execution.getVariable("servicename")
70 execution.setVariable("sliceServiceInstanceName", sliceServiceInstanceName)
73 String modelInvariantUuid = execution.getVariable("modelInvariantUuid")
74 String modelUuid = execution.getVariable("modelUuid")
75 //here modelVersion is not set, we use modelUuid to decompose the service.
76 def isDebugLogEnabled = true
77 execution.setVariable("isDebugLogEnabled", isDebugLogEnabled)
78 String serviceModelInfo = """{
79 "modelInvariantUuid":"${modelInvariantUuid}",
80 "modelUuid":"${modelUuid}",
83 execution.setVariable("serviceModelInfo", serviceModelInfo)
84 logger.debug("Finish preProcessRequest")
87 void preprocessSdncDeallocateTnNssiRequest(DelegateExecution execution) {
88 def method = getClass().getSimpleName() + '.preprocessSdncDeallocateTnNssiRequest(' +
89 'execution=' + execution.getId() + ')'
90 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
91 logger.trace('Entered ' + method)
94 String serviceInstanceId = execution.getVariable("serviceInstanceID")
96 String sdncRequest = tnNssmfUtils.buildSDNCRequest(execution, serviceInstanceId, "deallocate")
98 execution.setVariable("TNNSSMF_SDNCRequest", sdncRequest)
99 logger.debug("Outgoing SDNCRequest is: \n" + sdncRequest)
101 } catch (Exception e) {
102 logger.debug("Exception Occured Processing preprocessSdncDeallocateTnNssiRequest. Exception is:\n" + e)
103 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occured during preProcessSDNCActivateRequest Method:\n" + e.getMessage())
105 logger.trace("COMPLETED preprocessSdncDeallocateTnNssiRequest Process")
109 void validateSDNCResponse(DelegateExecution execution, String response, String method) {
110 tnNssmfUtils.validateSDNCResponse(execution, response, method)
113 void deleteServiceInstance(DelegateExecution execution) {
115 AAIResourcesClient client = getAAIClient()
116 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(execution.getVariable("globalSubscriberId")).serviceSubscription(execution.getVariable("subscriptionServiceType")).serviceInstance(execution.getVariable("serviceInstanceID")))
118 } catch (BpmnError e) {
120 } catch (Exception ex) {
121 String msg = "Exception in DoDeallocateTnNssi.deleteServiceInstance. " + ex.getMessage()
123 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
127 public void updateAAIOrchStatus(DelegateExecution execution) {
128 logger.debug("Start updateAAIOrchStatus")
129 String tnNssiId = execution.getVariable("serviceInstanceID")
130 String orchStatus = execution.getVariable("orchestrationStatus")
133 ServiceInstance si = new ServiceInstance()
134 si.setOrchestrationStatus(orchStatus)
135 AAIResourcesClient client = getAAIClient()
136 AAIResourceUri uri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(tnNssiId))
137 client.update(uri, si)
138 } catch (BpmnError e) {
140 } catch (Exception ex) {
141 String msg = "Exception in CreateSliceService.updateAAIOrchStatus " + ex.getMessage()
143 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
146 logger.debug("Finish updateAAIOrchStatus")
149 void prepareUpdateJobStatus(DelegateExecution execution,
152 String statusDescription) {
153 String serviceId = execution.getVariable("serviceInstanceID")
154 String jobId = execution.getVariable("jobId")
155 String nsiId = execution.getVariable("nsiId")
157 ResourceOperationStatus roStatus = new ResourceOperationStatus()
158 roStatus.setServiceId(serviceId)
159 roStatus.setOperationId(jobId)
160 roStatus.setResourceTemplateUUID(nsiId)
161 roStatus.setOperType("Deallocate")
162 roStatus.setProgress(progress)
163 roStatus.setStatus(status)
164 roStatus.setStatusDescription(statusDescription)
165 requestDBUtil.prepareUpdateResourceOperationStatus(execution, roStatus)