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.AAIResourcesClient
29 import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri
30 import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory
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 public class DoActivateTnNssi extends AbstractServiceTaskProcessor {
44 String Prefix = "TNACT_"
46 ExceptionUtil exceptionUtil = new ExceptionUtil()
47 JsonUtils jsonUtil = new JsonUtils()
48 RequestDBUtil requestDBUtil = new RequestDBUtil()
49 TnNssmfUtils tnNssmfUtils = new TnNssmfUtils()
50 JsonSlurper jsonSlurper = new JsonSlurper()
51 ObjectMapper objectMapper = new ObjectMapper()
52 private static final Logger logger = LoggerFactory.getLogger(DoActivateTnNssi.class)
55 public void preProcessRequest(DelegateExecution execution) {
56 logger.debug("Start preProcessRequest")
58 execution.setVariable("startTime", System.currentTimeMillis())
59 String msg = tnNssmfUtils.getExecutionInputParams(execution)
60 logger.debug("Activate TN NSSI input parameters: " + msg)
62 execution.setVariable("prefix", Prefix)
64 tnNssmfUtils.setSdncCallbackUrl(execution, true)
65 logger.debug("SDNC Callback URL: " + execution.getVariable("sdncCallbackUrl"))
67 String modelInvariantUuid = execution.getVariable("modelInvariantUuid")
68 String modelUuid = execution.getVariable("modelUuid")
69 if (isEmpty(modelUuid)) {
70 modelUuid = tnNssmfUtils.getModelUuidFromServiceInstance(execution.getVariable("serviceInstanceID"))
72 def isDebugLogEnabled = true
73 execution.setVariable("isDebugLogEnabled", isDebugLogEnabled)
74 String serviceModelInfo = """{
75 "modelInvariantUuid":"${modelInvariantUuid}",
76 "modelUuid":"${modelUuid}",
79 execution.setVariable("serviceModelInfo", serviceModelInfo)
81 String sliceServiceInstanceId = execution.getVariable("serviceInstanceID")
82 execution.setVariable("sliceServiceInstanceId", sliceServiceInstanceId)
84 String sliceServiceInstanceName = execution.getVariable("servicename")
85 execution.setVariable("sliceServiceInstanceName", sliceServiceInstanceName)
87 String operationType = execution.getVariable("operationType")
88 String actionType = operationType.equals("activateInstance") ? "activate" : "deactivate"
89 execution.setVariable("actionType", actionType)
91 String additionalPropJsonStr = execution.getVariable("sliceParams")
92 if (isBlank(additionalPropJsonStr) ||
93 isBlank(tnNssmfUtils.setExecVarFromJsonIfExists(execution,
94 additionalPropJsonStr,
95 "enableSdnc", "enableSdnc"))) {
96 tnNssmfUtils.setEnableSdncConfig(execution)
99 logger.debug("Finish preProcessRequest")
102 void preprocessSdncActOrDeactTnNssiRequest(DelegateExecution execution) {
103 def method = getClass().getSimpleName() + '.preprocessSdncActivateTnNssiRequest(' +
104 'execution=' + execution.getId() + ')'
105 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
106 logger.trace('Entered ' + method)
109 String serviceInstanceId = execution.getVariable("sliceServiceInstanceId")
110 String actionType = execution.getVariable("actionType")
112 String sdncRequest = tnNssmfUtils.buildSDNCRequest(execution, serviceInstanceId, actionType)
114 execution.setVariable("TNNSSMF_SDNCRequest", sdncRequest)
115 logger.debug("Outgoing SDNCRequest is: \n" + sdncRequest)
117 } catch (Exception e) {
118 logger.debug("Exception Occured Processing preprocessSdncDeallocateTnNssiRequest. Exception is:\n" + e)
119 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occured during preProcessSDNCActivateRequest Method:\n" + e.getMessage())
121 logger.trace("COMPLETED preprocessSdncActivateTnNssiRequest Process")
125 void validateSDNCResponse(DelegateExecution execution, String response) {
126 String actionType = execution.getVariable("actionType")
127 tnNssmfUtils.validateSDNCResponse(execution, response, actionType)
131 String getOrchStatusBasedOnActionType(String actionType) {
132 String res = "unknown"
133 if (actionType.equals("activate")) {
135 } else if (actionType.equals("deactivate")) {
138 logger.error("ERROR: getOrchStatusBasedOnActionType bad actionType= \n" + actionType)
144 void updateAAIOrchStatus(DelegateExecution execution) {
145 logger.debug("Start updateAAIOrchStatus")
146 String tnNssiId = execution.getVariable("sliceServiceInstanceId")
147 String orchStatus = execution.getVariable("orchestrationStatus")
150 ServiceInstance si = new ServiceInstance()
151 si.setOrchestrationStatus(orchStatus)
152 AAIResourcesClient client = getAAIClient()
153 AAIResourceUri uri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(tnNssiId))
154 client.update(uri, si)
155 } catch (BpmnError e) {
157 } catch (Exception ex) {
158 String msg = "Exception in CreateSliceService.updateAAIOrchStatus " + ex.getMessage()
160 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
163 logger.debug("Finish updateAAIOrchStatus")
166 void prepareUpdateJobStatus(DelegateExecution execution,
169 String statusDescription) {
170 String ssInstanceId = execution.getVariable("sliceServiceInstanceId")
171 String modelUuid = execution.getVariable("modelUuid")
172 String jobId = execution.getVariable("jobId")
173 String nsiId = execution.getVariable("nsiId")
174 String operType = execution.getVariable("actionType")
175 operType = operType.toUpperCase()
178 ResourceOperationStatus roStatus = tnNssmfUtils.buildRoStatus(modelUuid, ssInstanceId,
179 jobId, nsiId, operType, status, progress, statusDescription)
181 requestDBUtil.prepareUpdateResourceOperationStatus(execution, roStatus)