1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
|
/*-
* ============LICENSE_START=======================================================
* ONAP - SO
* ================================================================================
* Copyright (C) 2020 Huawei Technologies Co., Ltd. All rights reserved.
* ================================================================================
* 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 groovy.json.JsonSlurper
import org.camunda.bpm.engine.delegate.BpmnError
import org.camunda.bpm.engine.delegate.DelegateExecution
import org.onap.aai.domain.yang.ServiceInstance
import org.onap.aaiclient.client.aai.AAIObjectType
import org.onap.aaiclient.client.aai.AAIResourcesClient
import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri
import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory
import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder
import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types
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.json.JsonUtils
import org.onap.so.db.request.beans.ResourceOperationStatus
import org.slf4j.Logger
import org.slf4j.LoggerFactory
public class DoActivateTnNssi extends AbstractServiceTaskProcessor {
String Prefix = "TNACT_"
ExceptionUtil exceptionUtil = new ExceptionUtil()
JsonUtils jsonUtil = new JsonUtils()
RequestDBUtil requestDBUtil = new RequestDBUtil()
TnNssmfUtils tnNssmfUtils = new TnNssmfUtils()
JsonSlurper jsonSlurper = new JsonSlurper()
ObjectMapper objectMapper = new ObjectMapper()
private static final Logger logger = LoggerFactory.getLogger(DoActivateTnNssi.class)
public void preProcessRequest(DelegateExecution execution) {
logger.debug("Start preProcessRequest")
execution.setVariable("startTime", System.currentTimeMillis())
String msg = tnNssmfUtils.getExecutionInputParams(execution)
logger.debug("Activate TN NSSI input parameters: " + msg)
execution.setVariable("prefix", Prefix)
tnNssmfUtils.setSdncCallbackUrl(execution, true)
logger.debug("SDNC Callback URL: " + execution.getVariable("sdncCallbackUrl"))
String modelInvariantUuid = execution.getVariable("modelInvariantUuid")
String modelUuid = execution.getVariable("modelUuid")
//here modelVersion is not set, we use modelUuid to decompose the service.
def isDebugLogEnabled = true
execution.setVariable("isDebugLogEnabled", isDebugLogEnabled)
String serviceModelInfo = """{
"modelInvariantUuid":"${modelInvariantUuid}",
"modelUuid":"${modelUuid}",
"modelVersion":""
}"""
execution.setVariable("serviceModelInfo", serviceModelInfo)
String sliceServiceInstanceId = execution.getVariable("serviceInstanceID")
execution.setVariable("sliceServiceInstanceId", sliceServiceInstanceId)
String sliceServiceInstanceName = execution.getVariable("servicename")
execution.setVariable("sliceServiceInstanceName", sliceServiceInstanceName)
String operationType = execution.getVariable("operationType")
String actionType = operationType.equals("activateInstance") ? "activate" : "deactivate"
execution.setVariable("actionType", actionType)
logger.debug("Finish preProcessRequest")
}
void preprocessSdncActOrDeactTnNssiRequest(DelegateExecution execution) {
def method = getClass().getSimpleName() + '.preprocessSdncActivateTnNssiRequest(' +
'execution=' + execution.getId() + ')'
def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
logger.trace('Entered ' + method)
try {
String serviceInstanceId = execution.getVariable("sliceServiceInstanceId")
String actionType = execution.getVariable("actionType")
String sdncRequest = tnNssmfUtils.buildSDNCRequest(execution, serviceInstanceId, actionType)
execution.setVariable("TNNSSMF_SDNCRequest", sdncRequest)
logger.debug("Outgoing SDNCRequest is: \n" + sdncRequest)
} catch (Exception e) {
logger.debug("Exception Occured Processing preprocessSdncDeallocateTnNssiRequest. Exception is:\n" + e)
exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occured during preProcessSDNCActivateRequest Method:\n" + e.getMessage())
}
logger.trace("COMPLETED preprocessSdncActivateTnNssiRequest Process")
}
void validateSDNCResponse(DelegateExecution execution, String response) {
tnNssmfUtils.validateSDNCResponse(execution, response, method)
}
void updateAAIOrchStatus(DelegateExecution execution) {
logger.debug("Start updateAAIOrchStatus")
String tnNssiId = execution.getVariable("tnNssiId")
String orchStatus = execution.getVariable("orchestrationStatus")
try {
ServiceInstance si = new ServiceInstance()
si.setOrchestrationStatus(orchStatus)
AAIResourcesClient client = getAAIClient()
AAIResourceUri uri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(tnNssiId))
client.update(uri, si)
} catch (BpmnError e) {
throw e
} catch (Exception ex) {
String msg = "Exception in CreateSliceService.updateAAIOrchStatus " + ex.getMessage()
logger.info(msg)
exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
}
logger.debug("Finish updateAAIOrchStatus")
}
void prepareUpdateJobStatus(DelegateExecution execution,
String status,
String progress,
String statusDescription) {
String serviceId = execution.getVariable("serviceInstanceID")
String jobId = execution.getVariable("jobId")
String nsiId = execution.getVariable("nsiId")
String operType = execution.getVariable("actionType")
ResourceOperationStatus roStatus = new ResourceOperationStatus()
roStatus.setServiceId(serviceId)
roStatus.setOperationId(jobId)
roStatus.setResourceTemplateUUID(nsiId)
roStatus.setOperType(operType)
roStatus.setProgress(progress)
roStatus.setStatus(status)
roStatus.setStatusDescription(statusDescription)
requestDBUtil.prepareUpdateResourceOperationStatus(execution, roStatus)
}
}
|