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
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 //here modelVersion is not set, we use modelUuid to decompose the service.
70 def isDebugLogEnabled = true
71 execution.setVariable("isDebugLogEnabled", isDebugLogEnabled)
72 String serviceModelInfo = """{
73 "modelInvariantUuid":"${modelInvariantUuid}",
74 "modelUuid":"${modelUuid}",
77 execution.setVariable("serviceModelInfo", serviceModelInfo)
79 String sliceServiceInstanceId = execution.getVariable("serviceInstanceID")
80 execution.setVariable("sliceServiceInstanceId", sliceServiceInstanceId)
82 String sliceServiceInstanceName = execution.getVariable("servicename")
83 execution.setVariable("sliceServiceInstanceName", sliceServiceInstanceName)
85 String operationType = execution.getVariable("operationType")
86 String actionType = operationType.equals("activateInstance") ? "activate" : "deactivate"
87 execution.setVariable("actionType", actionType)
90 logger.debug("Finish preProcessRequest")
93 void preprocessSdncActOrDeactTnNssiRequest(DelegateExecution execution) {
94 def method = getClass().getSimpleName() + '.preprocessSdncActivateTnNssiRequest(' +
95 'execution=' + execution.getId() + ')'
96 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
97 logger.trace('Entered ' + method)
100 String serviceInstanceId = execution.getVariable("sliceServiceInstanceId")
101 String actionType = execution.getVariable("actionType")
103 String sdncRequest = tnNssmfUtils.buildSDNCRequest(execution, serviceInstanceId, actionType)
105 execution.setVariable("TNNSSMF_SDNCRequest", sdncRequest)
106 logger.debug("Outgoing SDNCRequest is: \n" + sdncRequest)
108 } catch (Exception e) {
109 logger.debug("Exception Occured Processing preprocessSdncDeallocateTnNssiRequest. Exception is:\n" + e)
110 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occured during preProcessSDNCActivateRequest Method:\n" + e.getMessage())
112 logger.trace("COMPLETED preprocessSdncActivateTnNssiRequest Process")
116 void validateSDNCResponse(DelegateExecution execution, String response) {
117 tnNssmfUtils.validateSDNCResponse(execution, response, method)
121 void updateAAIOrchStatus(DelegateExecution execution) {
122 logger.debug("Start updateAAIOrchStatus")
123 String tnNssiId = execution.getVariable("tnNssiId")
124 String orchStatus = execution.getVariable("orchestrationStatus")
127 ServiceInstance si = new ServiceInstance()
128 si.setOrchestrationStatus(orchStatus)
129 AAIResourcesClient client = getAAIClient()
130 AAIResourceUri uri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(tnNssiId))
131 client.update(uri, si)
132 } catch (BpmnError e) {
134 } catch (Exception ex) {
135 String msg = "Exception in CreateSliceService.updateAAIOrchStatus " + ex.getMessage()
137 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
140 logger.debug("Finish updateAAIOrchStatus")
143 void prepareUpdateJobStatus(DelegateExecution execution,
146 String statusDescription) {
147 String serviceId = execution.getVariable("serviceInstanceID")
148 String jobId = execution.getVariable("jobId")
149 String nsiId = execution.getVariable("nsiId")
150 String operType = execution.getVariable("actionType")
153 ResourceOperationStatus roStatus = new ResourceOperationStatus()
154 roStatus.setServiceId(serviceId)
155 roStatus.setOperationId(jobId)
156 roStatus.setResourceTemplateUUID(nsiId)
157 roStatus.setOperType(operType)
158 roStatus.setProgress(progress)
159 roStatus.setStatus(status)
160 roStatus.setStatusDescription(statusDescription)
161 requestDBUtil.prepareUpdateResourceOperationStatus(execution, roStatus)