2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Modifications Copyright (c) 2019 Samsung
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=========================================================
23 package org.onap.so.bpmn.infrastructure.scripts
25 import groovy.json.JsonOutput
26 import groovy.json.JsonSlurper
27 import org.camunda.bpm.engine.delegate.BpmnError
28 import org.camunda.bpm.engine.delegate.DelegateExecution
29 import org.onap.so.bpmn.common.scripts.ExceptionUtil
30 import org.onap.so.bpmn.common.scripts.MsoUtils
31 import org.onap.so.bpmn.core.UrnPropertiesReader
32 import org.onap.so.client.aai.AAIValidatorImpl
33 import org.onap.so.client.appc.ApplicationControllerClient
34 import org.slf4j.Logger
35 import org.slf4j.LoggerFactory
37 public class UpdateVfModuleInfraV2 {
38 private static final Logger logger = LoggerFactory.getLogger(UpdateVfModuleInfraV2.class)
40 ExceptionUtil exceptionUtil = new ExceptionUtil()
42 boolean preProcessRequestCheck = true;
43 boolean sendSynchResponseCheck = true;
44 boolean checkPserverFlagCheck = true;
45 boolean vfFlagCheckSetCheck = true;
46 boolean lockAppCCheck = true;
47 boolean healthDiagnosticSDNOCheck = true;
48 boolean healthCheckAppCCheck = true;
49 boolean stopVfModuleControllerCheck = true;
50 boolean healthCheckControllerCheck = true;
51 boolean doUpdateVfModulePrepCheck = true;
52 boolean completionHandlerPrepCheck = true;
53 boolean startVfModuleControllerCheck = true;
54 boolean vFFlagUnsetCheck = true;
55 boolean unlockAppCCheck = true;
56 boolean postUpgradeHealthCheckControllerCheck = true;
60 public void initProcessVariables(DelegateExecution execution) {
61 execution.setVariable('prefix', 'UPDVfModI_')
62 execution.setVariable('UPDVfModI_Request', null)
63 execution.setVariable('UPDVfModI_requestInfo', null)
64 execution.setVariable('UPDVfModI_requestId', null)
65 execution.setVariable('UPDVfModI_source', null)
66 execution.setVariable('UPDVfModI_vnfInputs', null)
67 execution.setVariable('UPDVfModI_vnfId', null)
68 execution.setVariable('UPDVFModI_moduleUuid', null)
69 execution.setVariable('UPDVfModI_vfModuleId', null)
70 execution.setVariable('UPDVfModI_tenantId', null)
71 execution.setVariable('UPDVfModI_volumeGroupId', null)
72 execution.setVariable('UPDVfModI_vnfParams', null)
73 execution.setVariable('UPDVfModI_updateInfraRequest', null)
74 execution.setVariable('UpdateVfModuleSuccessIndicator', false)
78 * Check for missing elements in the received request.
80 * @param execution The flow's execution instance.
82 public void preProcessRequest(DelegateExecution execution) {
83 logger.debug("*****************************PreProcessRequest**************************")
85 def method = getClass().getSimpleName() + '.preProcessRequest(' +
86 'execution=' + execution.getId() +
89 //logger.trace('Entered ' + method)
91 initProcessVariables(execution)
93 def prefix = "UPDVfModI_"
95 def incomingRequest = execution.getVariable('bpmnRequest')
97 //logger.debug("Incoming Infra Request: " + incomingRequest)
99 def jsonSlurper = new JsonSlurper()
100 def jsonOutput = new JsonOutput()
101 Map reqMap = jsonSlurper.parseText(incomingRequest)
102 //logger.debug(" Request is in JSON format.")
104 def serviceInstanceId = execution.getVariable('serviceInstanceId')
105 def vnfId = execution.getVariable('vnfId')
106 def moduleUuid = execution.getVariable('moduleUuid')
107 execution.setVariable(prefix + 'moduleUuid',moduleUuid)
108 execution.setVariable(prefix + 'serviceInstanceId', serviceInstanceId)
109 execution.setVariable(prefix+'vnfId', vnfId)
110 execution.setVariable("isVidRequest", "true")
113 def asdcServiceModelVersion = ''
114 def serviceModelInfo = null
115 def vnfModelInfo = null
117 def relatedInstanceList = reqMap.requestDetails?.relatedInstanceList
119 if (relatedInstanceList != null) {
120 relatedInstanceList.each {
121 if (it.relatedInstance.modelInfo?.modelType == 'service') {
122 asdcServiceModelVersion = it.relatedInstance.modelInfo?.modelVersion
123 serviceModelInfo = jsonOutput.toJson(it.relatedInstance.modelInfo)
125 if (it.relatedInstance.modelInfo.modelType == 'vnf') {
126 vnfName = it.relatedInstance.instanceName ?: ''
127 vnfModelInfo = jsonOutput.toJson(it.relatedInstance.modelInfo)
132 execution.setVariable(prefix + 'vnfName', vnfName)
133 execution.setVariable(prefix + 'asdcServiceModelVersion', asdcServiceModelVersion)
134 execution.setVariable(prefix + 'serviceModelInfo', serviceModelInfo)
135 execution.setVariable(prefix + 'vnfModelInfo', vnfModelInfo)
137 def vnfType = execution.getVariable('vnfType')
138 execution.setVariable(prefix + 'vnfType', vnfType)
139 def vfModuleId = execution.getVariable('vfModuleId')
140 execution.setVariable(prefix + 'vfModuleId', vfModuleId)
141 def volumeGroupId = execution.getVariable('volumeGroupId')
142 execution.setVariable(prefix + 'volumeGroupId', volumeGroupId)
143 def userParams = reqMap.requestDetails?.requestParameters?.userParams
145 Map<String, String> userParamsMap = [:]
146 if (userParams != null) {
147 userParams.each { userParam ->
148 userParamsMap.put(userParam.name, userParam.value.toString())
152 //logger.debug('Processed user params: ' + userParamsMap)
154 execution.setVariable(prefix + 'vfModuleInputParams', userParamsMap)
156 def isBaseVfModule = "false"
157 if (execution.getVariable('isBaseVfModule') == true) {
158 isBaseVfModule = "true"
161 execution.setVariable(prefix + 'isBaseVfModule', isBaseVfModule)
163 def requestId = execution.getVariable("mso-request-id")
164 execution.setVariable(prefix + 'requestId', requestId)
166 def vfModuleModelInfo = jsonOutput.toJson(reqMap.requestDetails?.modelInfo)
167 execution.setVariable(prefix + 'vfModuleModelInfo', vfModuleModelInfo)
169 def suppressRollback = reqMap.requestDetails?.requestInfo?.suppressRollback
172 def backoutOnFailure = ""
173 if(suppressRollback != null){
174 if ( suppressRollback == true) {
175 backoutOnFailure = "false"
176 } else if ( suppressRollback == false) {
177 backoutOnFailure = "true"
181 execution.setVariable('disableRollback', suppressRollback)
183 def vfModuleName = reqMap.requestDetails?.requestInfo?.instanceName ?: null
184 execution.setVariable(prefix + 'vfModuleName', vfModuleName)
186 def serviceId = reqMap.requestDetails?.requestParameters?.serviceId ?: ''
187 execution.setVariable(prefix + 'serviceId', serviceId)
189 def usePreload = reqMap.requestDetails?.requestParameters?.usePreload
190 execution.setVariable(prefix + 'usePreload', usePreload)
192 def cloudConfiguration = reqMap.requestDetails?.cloudConfiguration
193 def lcpCloudRegionId = cloudConfiguration.lcpCloudRegionId
194 execution.setVariable(prefix + 'lcpCloudRegionId', lcpCloudRegionId)
196 def cloudOwner = cloudConfiguration.cloudOwner
197 execution.setVariable(prefix + 'cloudOwner', cloudOwner)
199 def tenantId = cloudConfiguration.tenantId
200 execution.setVariable(prefix + 'tenantId', tenantId)
202 def globalSubscriberId = reqMap.requestDetails?.subscriberInfo?.globalSubscriberId ?: ''
203 execution.setVariable(prefix + 'globalSubscriberId', globalSubscriberId)
205 execution.setVariable(prefix + 'sdncVersion', '1702')
207 execution.setVariable("UpdateVfModuleInfraSuccessIndicator", false)
212 def source = reqMap.requestDetails?.requestInfo?.source
213 execution.setVariable(prefix + "source", source)
215 //For Completion Handler & Fallout Handler
217 """<request-info xmlns="http://org.onap/so/infra/vnf-request/v1">
218 <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
219 <action>UPDATE</action>
220 <source>${MsoUtils.xmlEscape(source)}</source>
223 execution.setVariable(prefix + "requestInfo", requestInfo)
227 //logger.debug('RequestInfo: ' + execution.getVariable(prefix + "requestInfo"))
229 //logger.trace('Exited ' + method)
232 catch(groovy.json.JsonException je) {
233 //logger.debug(" Request is not in JSON format.")
234 exceptionUtil.buildAndThrowWorkflowException(execution, 5000, "Invalid request format")
237 String restFaultMessage = e.getMessage()
238 //logger.error("{} {} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), " Exception Encountered - " + "\n" + restFaultMessage, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
239 exceptionUtil.buildAndThrowWorkflowException(execution, 5000, restFaultMessage)
244 * Prepare and send the synchronous response for this flow.
246 * @param execution The flow's execution instance.
248 public void sendSynchResponse(DelegateExecution execution) {
249 logger.debug("*****************************SendSynchResponse**************************")
251 def method = getClass().getSimpleName() + '.sendSynchResponse(' +
252 'execution=' + execution.getId() +
255 //logger.trace('Entered ' + method)
259 def requestInfo = execution.getVariable('UPDVfModI_requestInfo')
260 def requestId = execution.getVariable('UPDVfModI_requestId')
261 def source = execution.getVariable('UPDVfModI_source')
263 def progress = getNodeTextForce(requestInfo, 'progress')
264 if (progress.isEmpty()) {
267 def startTime = getNodeTextForce(requestInfo, 'start-time')
268 if (startTime.isEmpty()) {
269 startTime = System.currentTimeMillis()
271 // RESTResponse (for API Handler (APIH) Reply Task)
272 def vfModuleId = execution.getVariable("vfModuleId")
273 String synchResponse = """{"requestReferences":{"instanceId":"${vfModuleId}","requestId":"${requestId}"}}""".trim()
274 sendWorkflowResponse(execution, 200, synchResponse)
275 //logger.trace('Exited ' + method)
276 } catch (BpmnError e) {
278 } catch (Exception e) {
279 //logger.error("{} {} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), 'Caught exception in ' + method, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
280 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in sendResponse(): ' + e.getMessage())
284 //check to see if the Pserver Flag is locked
285 public void checkPserverFlag(DelegateExecution execution) {
287 logger.debug("*****************************CheckingPserverFlag*************************")
288 String vnfId = (String)execution.getVariable('vnfId')
289 AAIValidatorImpl aaiVI = new AAIValidatorImpl()
290 boolean flag = aaiVI.isPhysicalServerLocked(vnfId)
293 //check to see if the VFFlag is locked
294 public void vfFlagCheck(DelegateExecution execution) {
296 logger.debug("*****************************VfFlagCheck*************************")
297 String vnfId = (String)execution.getVariable('vnfId')
298 AAIValidatorImpl aaiVI = new AAIValidatorImpl()
299 boolean flag = aaiVI.isVNFLocked(vnfId)
303 public void vfFlagSet(DelegateExecution execution) {
305 logger.debug("*****************************VfFlagSet*************************")
306 String vnfId = (String)execution.getVariable('vnfId')
307 String uuid = (String)execution.getVariable('moduleUuid')
308 AAIValidatorImpl aaiVI = new AAIValidatorImpl()
309 aaiVI.updateVnfToLocked(vnfId,uuid);
314 public void lockAppC(DelegateExecution execution) {
316 logger.debug("*****************************lockAppC*************************")
318 ApplicationControllerClient aCC = new ApplicationControllerClient(getLCMProperties())
319 def status = aCC.runCommand("Lock",vfModuleId)
324 public void healthCheckAppC(DelegateExecution execution) {
326 logger.debug("*****************************healthCheckAppC*************************")
328 ApplicationControllerClient aCC = new ApplicationControllerClient(getLCMProperties())
329 def status = aCC.runCommand("HealthCheck",vfModuleId)
332 //SDNO health diagnostic
333 public void healthDiagnosticSDNO(DelegateExecution execution) {
335 logger.debug("*****************************healthDiagnosticSDNO is currently ignored*************************")
336 //SDNOValidatorImpl.healthDiagnostic("","");
339 //stop VF module controller
340 public void stopVfModuleController(DelegateExecution execution) {
342 logger.debug("*****************************stopVfModuleController*************************")
344 ApplicationControllerClient aCC = new ApplicationControllerClient(getLCMProperties())
345 def status = aCC.runCommand("Stop",vfModuleId)
350 public void doUpdateVfModulePrep(DelegateExecution execution) {
352 logger.debug("*****************************doUpdateVfModulePrep*************************")
353 def method = getClass().getSimpleName() + '.prepDoUpdateVfModule(' +
354 'execution=' + execution.getId() +
357 //logger.trace('Entered ' + method)
361 //logger.trace('Exited ' + method)
362 } catch (BpmnError e) {
364 } catch (Exception e) {
365 //logger.error("{} {} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), 'Caught exception in ' + method, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
366 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in prepDoUpdateVfModule(): ' + e.getMessage())
372 public void completionHandlerPrep(DelegateExecution execution,String resultVar) {
374 logger.debug("*****************************completionHandlerPrep*************************")
375 def method = getClass().getSimpleName() + '.completionHandlerPrep(' +
376 'execution=' + execution.getId() +
377 ', resultVar=' + resultVar +
380 //logger.trace('Entered ' + method)
383 def requestInfo = getVariable(execution, 'UPDVfModI_requestInfo')
386 <sdncadapterworkflow:MsoCompletionRequest xmlns:sdncadapterworkflow="http://org.onap/so/workflow/schema/v1"
387 xmlns:reqtype="http://org.onap/so/request/types/v1">
389 <sdncadapterworkflow:mso-bpel-name>MSO_ACTIVATE_BPEL</sdncadapterworkflow:mso-bpel-name>
390 </sdncadapterworkflow:MsoCompletionRequest>
393 content = utils.formatXml(content)
394 //logger.debug(resultVar + ' = ' + System.lineSeparator() + content)
395 execution.setVariable(resultVar, content)
397 //logger.trace('Exited ' + method)
398 } catch (BpmnError e) {
400 } catch (Exception e) {
401 //logger.error("{} {} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), 'Caught exception in ' + method, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError.getValue(), "Exception is:\n" + e);
402 exceptionUtil.buildAndThrowWorkflowException(execution, 2000, 'Internal Error')
408 public void healthCheckController(DelegateExecution execution) {
410 logger.debug("*****************************healthCheckController*************************")
412 ApplicationControllerClient aCC = new ApplicationControllerClient(getLCMProperties())
413 def status = aCC.runCommand("HealthCheck",vfModuleId)
417 public void startVfModuleController(DelegateExecution execution) {
419 logger.debug("*****************************startVfModuleController*************************")
421 ApplicationControllerClient aCC = new ApplicationControllerClient(getLCMProperties())
422 def status = aCC.runCommand("Start",vfModuleId)
426 public void vFFlagUnset(DelegateExecution execution) {
428 logger.debug("*****************************vFFlagUnset*************************")
429 String vnfId = (String)execution.getVariable('vnfId')
430 String uuid = (String)execution.getVariable('moduleUuid')
431 AAIValidatorImpl aaiVI = new AAIValidatorImpl()
432 aaiVI.updateVnfToUnLocked(vnfId,uuid);
437 public void unlockAppC(DelegateExecution execution) {
439 logger.debug("*****************************unlockAppC*************************")
441 ApplicationControllerClient aCC = new ApplicationControllerClient(getLCMProperties())
442 def status = aCC.runCommand("Unlock",vfModuleId)
446 public void postUpgradeHealthCheckController(DelegateExecution execution) {
448 logger.debug("*****************************postUpgradeHealthCheckController*************************")
450 ApplicationControllerClient aCC = new ApplicationControllerClient(getLCMProperties())
451 def status = aCC.runCommand("HealthCheck",vfModuleId)
455 Properties getLCMProperties() {
456 Properties properties = new Properties()
458 properties.put("topic.read", UrnPropertiesReader.getVariable("appc.client.topic.read.name"))
459 properties.put("topic.read.timeout", UrnPropertiesReader.getVariable("appc.client.topic.read.timeout"))
460 properties.put("client.response.timeout", UrnPropertiesReader.getVariable("appc.client.response.timeout"))
461 properties.put("topic.write", UrnPropertiesReader.getVariable("appc.client.topic.write"))
462 properties.put("poolMembers", UrnPropertiesReader.getVariable("appc.client.poolMembers"))
463 properties.put("client.key", UrnPropertiesReader.getVariable("appc.client.key"))
464 properties.put("client.secret", UrnPropertiesReader.getVariable("appc.client.secret"))
465 properties.put("client.name", "MSO")
466 properties.put("service", UrnPropertiesReader.getVariable("appc.client.service"))