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
24 import org.camunda.bpm.engine.delegate.BpmnError
25 import org.camunda.bpm.engine.delegate.DelegateExecution
26 import org.onap.aai.domain.yang.ServiceInstance
27 import org.onap.aaiclient.client.aai.AAIResourcesClient
28 import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri
29 import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory
30 import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder
31 import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types
32 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
33 import org.onap.so.bpmn.common.scripts.ExceptionUtil
34 import org.onap.so.bpmn.common.scripts.RequestDBUtil
35 import org.onap.so.bpmn.core.json.JsonUtils
36 import org.onap.so.db.request.beans.ResourceOperationStatus
37 import org.slf4j.Logger
38 import org.slf4j.LoggerFactory
40 import static org.apache.commons.lang3.StringUtils.isBlank
41 import static org.apache.commons.lang3.StringUtils.isEmpty
43 class DoCloudLeasedLineDelete extends AbstractServiceTaskProcessor {
44 String Prefix = "DCLL_"
46 ExceptionUtil exceptionUtil = new ExceptionUtil()
47 JsonUtils jsonUtil = new JsonUtils()
48 RequestDBUtil requestDBUtil = new RequestDBUtil()
49 ServiceIntentUtils serviceIntentUtils = new ServiceIntentUtils()
50 private static final Logger logger = LoggerFactory.getLogger(DoCloudLeasedLineDelete.class)
53 void preProcessRequest(DelegateExecution execution) {
54 logger.debug("Start preProcessRequest")
56 execution.setVariable("startTime", System.currentTimeMillis())
57 String msg = serviceIntentUtils.getExecutionInputParams(execution)
58 logger.debug("Deallocate CLL input parameters: " + msg)
60 execution.setVariable("prefix", Prefix)
62 serviceIntentUtils.setSdncCallbackUrl(execution, true)
63 logger.debug("SDNC Callback URL: " + execution.getVariable("sdncCallbackUrl"))
65 String cllId = execution.getVariable("serviceInstanceID")
66 execution.setVariable("cllId", cllId)
68 String cllName = execution.getVariable("servicename")
69 execution.setVariable("cllName", cllName)
71 String modelInvariantUuid = execution.getVariable("modelInvariantUuid")
72 String modelUuid = execution.getVariable("modelUuid")
73 if (isEmpty(modelUuid)) {
74 modelUuid = serviceIntentUtils.getModelUuidFromServiceInstance(execution.getVariable("serviceInstanceID"))
76 def isDebugLogEnabled = true
77 execution.setVariable("isDebugLogEnabled", isDebugLogEnabled)
78 String serviceModelInfo = """{
79 "modelInvariantUuid":"${modelInvariantUuid}",
80 "modelUuid":"${modelUuid}",
83 execution.setVariable("serviceModelInfo", serviceModelInfo)
85 String additionalPropJsonStr = execution.getVariable("serviceIntentParams")
86 if (isBlank(additionalPropJsonStr) ||
87 isBlank(serviceIntentUtils.setExecVarFromJsonIfExists(execution,
88 additionalPropJsonStr,
89 "enableSdnc", "enableSdnc"))) {
90 serviceIntentUtils.setEnableSdncConfig(execution)
93 logger.debug("Finish preProcessRequest")
96 void preprocessSdncDeleteCllRequest(DelegateExecution execution) {
97 def method = getClass().getSimpleName() + '.preprocessSdncDeallocateCllRequest(' +
98 'execution=' + execution.getId() + ')'
99 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
100 logger.trace('Entered ' + method)
103 String serviceInstanceId = execution.getVariable("serviceInstanceID")
105 String sdncRequest = serviceIntentUtils.buildSDNCRequest(execution, serviceInstanceId, "delete")
107 execution.setVariable("CLL_SDNCRequest", sdncRequest)
108 logger.debug("Outgoing SDNCRequest is: \n" + sdncRequest)
110 } catch (Exception e) {
111 logger.debug("Exception Occurred Processing preprocessSdncDeallocateCllRequest. Exception is:\n" + e)
112 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occurred during preProcessSDNCActivateRequest Method:\n" + e.getMessage())
114 logger.trace("COMPLETED preprocessSdncDeallocateCllRequest Process")
118 void validateSDNCResponse(DelegateExecution execution, String response, String method) {
119 serviceIntentUtils.validateSDNCResponse(execution, response, method)
122 void deleteServiceInstance(DelegateExecution execution) {
124 AAIResourcesClient client = getAAIClient()
125 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(execution.getVariable("globalSubscriberId")).serviceSubscription(execution.getVariable("subscriptionServiceType")).serviceInstance(execution.getVariable("serviceInstanceID")))
127 } catch (BpmnError e) {
129 } catch (Exception ex) {
130 String msg = "Exception in DoDeallocateCll.deleteServiceInstance. " + ex.getMessage()
132 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
136 public void updateAAIOrchStatus(DelegateExecution execution) {
137 logger.debug("Start updateAAIOrchStatus")
138 String cllId = execution.getVariable("cllId")
139 String orchStatus = execution.getVariable("orchestrationStatus")
142 ServiceInstance si = new ServiceInstance()
143 si.setOrchestrationStatus(orchStatus)
144 AAIResourcesClient client = getAAIClient()
145 AAIResourceUri uri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(cllId))
146 client.update(uri, si)
147 } catch (BpmnError e) {
149 } catch (Exception ex) {
150 String msg = "Exception in CreateSliceService.updateAAIOrchStatus " + ex.getMessage()
152 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
155 logger.debug("Finish updateAAIOrchStatus")
158 void prepareUpdateJobStatus(DelegateExecution execution,
161 String statusDescription) {
162 String cllId = execution.getVariable("cllId")
163 String modelUuid = execution.getVariable("modelUuid")
164 String jobId = execution.getVariable("jobId")
165 String nsiId = execution.getVariable("nsiId")
167 ResourceOperationStatus roStatus = serviceIntentUtils.buildRoStatus(modelUuid, cllId,
168 jobId, nsiId, "DELETE", status, progress, statusDescription)
170 logger.debug("prepareUpdateJobStatus: roStatus={}", roStatus)
171 requestDBUtil.prepareUpdateResourceOperationStatus(execution, roStatus)