2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. 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.so.bpmn.common.scripts.ExceptionUtil
27 import org.onap.so.bpmn.common.scripts.MsoUtils
28 import org.onap.so.bpmn.core.UrnPropertiesReader
29 import org.onap.so.client.aai.AAIValidatorImpl
30 import org.onap.so.client.appc.ApplicationControllerClient
31 import org.onap.so.logger.MsoLogger
33 import groovy.json.JsonOutput
34 import groovy.json.JsonSlurper
36 public class UpdateVfModuleInfraV2 {
37 private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, UpdateVfModuleInfraV2.class);
39 ExceptionUtil exceptionUtil = new ExceptionUtil()
41 boolean preProcessRequestCheck = true;
42 boolean sendSynchResponseCheck = true;
43 boolean checkPserverFlagCheck = true;
44 boolean vfFlagCheckSetCheck = true;
45 boolean lockAppCCheck = true;
46 boolean healthDiagnosticSDNOCheck = true;
47 boolean healthCheckAppCCheck = true;
48 boolean stopVfModuleControllerCheck = true;
49 boolean healthCheckControllerCheck = true;
50 boolean doUpdateVfModulePrepCheck = true;
51 boolean completionHandlerPrepCheck = true;
52 boolean startVfModuleControllerCheck = true;
53 boolean vFFlagUnsetCheck = true;
54 boolean unlockAppCCheck = true;
55 boolean postUpgradeHealthCheckControllerCheck = true;
59 public void initProcessVariables(DelegateExecution execution) {
60 execution.setVariable('prefix', 'UPDVfModI_')
61 execution.setVariable('UPDVfModI_Request', null)
62 execution.setVariable('UPDVfModI_requestInfo', null)
63 execution.setVariable('UPDVfModI_requestId', null)
64 execution.setVariable('UPDVfModI_source', null)
65 execution.setVariable('UPDVfModI_vnfInputs', null)
66 execution.setVariable('UPDVfModI_vnfId', null)
67 execution.setVariable('UPDVFModI_moduleUuid', null)
68 execution.setVariable('UPDVfModI_vfModuleId', null)
69 execution.setVariable('UPDVfModI_tenantId', null)
70 execution.setVariable('UPDVfModI_volumeGroupId', null)
71 execution.setVariable('UPDVfModI_vnfParams', null)
72 execution.setVariable('UPDVfModI_updateInfraRequest', null)
73 execution.setVariable('UpdateVfModuleSuccessIndicator', false)
77 * Check for missing elements in the received request.
79 * @param execution The flow's execution instance.
81 public void preProcessRequest(DelegateExecution execution) {
82 System.out.print("*****************************PreProcessRequest**************************")
84 def method = getClass().getSimpleName() + '.preProcessRequest(' +
85 'execution=' + execution.getId() +
88 //msoLogger.trace('Entered ' + method)
90 initProcessVariables(execution)
92 def prefix = "UPDVfModI_"
94 def incomingRequest = execution.getVariable('bpmnRequest')
96 //msoLogger.debug("Incoming Infra Request: " + incomingRequest)
98 def jsonSlurper = new JsonSlurper()
99 def jsonOutput = new JsonOutput()
100 Map reqMap = jsonSlurper.parseText(incomingRequest)
101 //msoLogger.debug(" Request is in JSON format.")
103 def serviceInstanceId = execution.getVariable('serviceInstanceId')
104 def vnfId = execution.getVariable('vnfId')
105 def moduleUuid = execution.getVariable('moduleUuid')
106 execution.setVariable(prefix + 'moduleUuid',moduleUuid)
107 execution.setVariable(prefix + 'serviceInstanceId', serviceInstanceId)
108 execution.setVariable(prefix+'vnfId', vnfId)
109 execution.setVariable("isVidRequest", "true")
112 def asdcServiceModelVersion = ''
113 def serviceModelInfo = null
114 def vnfModelInfo = null
116 def relatedInstanceList = reqMap.requestDetails?.relatedInstanceList
118 if (relatedInstanceList != null) {
119 relatedInstanceList.each {
120 if (it.relatedInstance.modelInfo?.modelType == 'service') {
121 asdcServiceModelVersion = it.relatedInstance.modelInfo?.modelVersion
122 serviceModelInfo = jsonOutput.toJson(it.relatedInstance.modelInfo)
124 if (it.relatedInstance.modelInfo.modelType == 'vnf') {
125 vnfName = it.relatedInstance.instanceName ?: ''
126 vnfModelInfo = jsonOutput.toJson(it.relatedInstance.modelInfo)
131 execution.setVariable(prefix + 'vnfName', vnfName)
132 execution.setVariable(prefix + 'asdcServiceModelVersion', asdcServiceModelVersion)
133 execution.setVariable(prefix + 'serviceModelInfo', serviceModelInfo)
134 execution.setVariable(prefix + 'vnfModelInfo', vnfModelInfo)
136 def vnfType = execution.getVariable('vnfType')
137 execution.setVariable(prefix + 'vnfType', vnfType)
138 def vfModuleId = execution.getVariable('vfModuleId')
139 execution.setVariable(prefix + 'vfModuleId', vfModuleId)
140 def volumeGroupId = execution.getVariable('volumeGroupId')
141 execution.setVariable(prefix + 'volumeGroupId', volumeGroupId)
142 def userParams = reqMap.requestDetails?.requestParameters?.userParams
144 Map<String, String> userParamsMap = [:]
145 if (userParams != null) {
146 userParams.each { userParam ->
147 userParamsMap.put(userParam.name, userParam.value.toString())
151 //msoLogger.debug('Processed user params: ' + userParamsMap)
153 execution.setVariable(prefix + 'vfModuleInputParams', userParamsMap)
155 def isBaseVfModule = "false"
156 if (execution.getVariable('isBaseVfModule') == true) {
157 isBaseVfModule = "true"
160 execution.setVariable(prefix + 'isBaseVfModule', isBaseVfModule)
162 def requestId = execution.getVariable("mso-request-id")
163 execution.setVariable(prefix + 'requestId', requestId)
165 def vfModuleModelInfo = jsonOutput.toJson(reqMap.requestDetails?.modelInfo)
166 execution.setVariable(prefix + 'vfModuleModelInfo', vfModuleModelInfo)
168 def suppressRollback = reqMap.requestDetails?.requestInfo?.suppressRollback
171 def backoutOnFailure = ""
172 if(suppressRollback != null){
173 if ( suppressRollback == true) {
174 backoutOnFailure = "false"
175 } else if ( suppressRollback == false) {
176 backoutOnFailure = "true"
180 execution.setVariable('disableRollback', suppressRollback)
182 def vfModuleName = reqMap.requestDetails?.requestInfo?.instanceName ?: null
183 execution.setVariable(prefix + 'vfModuleName', vfModuleName)
185 def serviceId = reqMap.requestDetails?.requestParameters?.serviceId ?: ''
186 execution.setVariable(prefix + 'serviceId', serviceId)
188 def usePreload = reqMap.requestDetails?.requestParameters?.usePreload
189 execution.setVariable(prefix + 'usePreload', usePreload)
191 def cloudConfiguration = reqMap.requestDetails?.cloudConfiguration
192 def lcpCloudRegionId = cloudConfiguration.lcpCloudRegionId
193 execution.setVariable(prefix + 'lcpCloudRegionId', lcpCloudRegionId)
195 def cloudOwner = cloudConfiguration.cloudOwner
196 execution.setVariable(prefix + 'cloudOwner', cloudOwner)
198 def tenantId = cloudConfiguration.tenantId
199 execution.setVariable(prefix + 'tenantId', tenantId)
201 def globalSubscriberId = reqMap.requestDetails?.subscriberInfo?.globalSubscriberId ?: ''
202 execution.setVariable(prefix + 'globalSubscriberId', globalSubscriberId)
204 execution.setVariable(prefix + 'sdncVersion', '1702')
206 execution.setVariable("UpdateVfModuleInfraSuccessIndicator", false)
211 def source = reqMap.requestDetails?.requestInfo?.source
212 execution.setVariable(prefix + "source", source)
214 //For Completion Handler & Fallout Handler
216 """<request-info xmlns="http://org.onap/so/infra/vnf-request/v1">
217 <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
218 <action>UPDATE</action>
219 <source>${MsoUtils.xmlEscape(source)}</source>
222 execution.setVariable(prefix + "requestInfo", requestInfo)
226 //msoLogger.debug('RequestInfo: ' + execution.getVariable(prefix + "requestInfo"))
228 //msoLogger.trace('Exited ' + method)
231 catch(groovy.json.JsonException je) {
232 //msoLogger.debug(" Request is not in JSON format.")
233 exceptionUtil.buildAndThrowWorkflowException(execution, 5000, "Invalid request format")
236 String restFaultMessage = e.getMessage()
237 //msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, " Exception Encountered - " + "\n" + restFaultMessage, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "Exception is:\n" + e);
238 exceptionUtil.buildAndThrowWorkflowException(execution, 5000, restFaultMessage)
243 * Prepare and send the synchronous response for this flow.
245 * @param execution The flow's execution instance.
247 public void sendSynchResponse(DelegateExecution execution) {
248 System.out.print("*****************************SendSynchResponse**************************")
250 def method = getClass().getSimpleName() + '.sendSynchResponse(' +
251 'execution=' + execution.getId() +
254 //msoLogger.trace('Entered ' + method)
258 def requestInfo = execution.getVariable('UPDVfModI_requestInfo')
259 def requestId = execution.getVariable('UPDVfModI_requestId')
260 def source = execution.getVariable('UPDVfModI_source')
262 def progress = getNodeTextForce(requestInfo, 'progress')
263 if (progress.isEmpty()) {
266 def startTime = getNodeTextForce(requestInfo, 'start-time')
267 if (startTime.isEmpty()) {
268 startTime = System.currentTimeMillis()
270 // RESTResponse (for API Handler (APIH) Reply Task)
271 def vfModuleId = execution.getVariable("vfModuleId")
272 String synchResponse = """{"requestReferences":{"instanceId":"${vfModuleId}","requestId":"${requestId}"}}""".trim()
273 sendWorkflowResponse(execution, 200, synchResponse)
274 //msoLogger.trace('Exited ' + method)
275 } catch (BpmnError e) {
277 } catch (Exception e) {
278 //msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, 'Caught exception in ' + method, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "Exception is:\n" + e);
279 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in sendResponse(): ' + e.getMessage())
283 //check to see if the Pserver Flag is locked
284 public void checkPserverFlag(DelegateExecution execution) {
286 System.out.println("*****************************CheckingPserverFlag*************************")
287 String vnfId = (String)execution.getVariable('vnfId')
288 AAIValidatorImpl aaiVI = new AAIValidatorImpl()
289 boolean flag = aaiVI.isPhysicalServerLocked(vnfId)
292 //check to see if the VFFlag is locked
293 public void vfFlagCheck(DelegateExecution execution) {
295 System.out.print("*****************************VfFlagCheck*************************")
296 String vnfId = (String)execution.getVariable('vnfId')
297 AAIValidatorImpl aaiVI = new AAIValidatorImpl()
298 boolean flag = aaiVI.isVNFLocked(vnfId)
302 public void vfFlagSet(DelegateExecution execution) {
304 System.out.print("*****************************VfFlagSet*************************")
305 String vnfId = (String)execution.getVariable('vnfId')
306 String uuid = (String)execution.getVariable('moduleUuid')
307 AAIValidatorImpl aaiVI = new AAIValidatorImpl()
308 aaiVI.updateVnfToLocked(vnfId,uuid);
313 public void lockAppC(DelegateExecution execution) {
315 System.out.print("*****************************lockAppC*************************")
317 ApplicationControllerClient aCC = new ApplicationControllerClient(getLCMProperties())
318 def status = aCC.runCommand("Lock",vfModuleId)
323 public void healthCheckAppC(DelegateExecution execution) {
325 System.out.print("*****************************healthCheckAppC*************************")
327 ApplicationControllerClient aCC = new ApplicationControllerClient(getLCMProperties())
328 def status = aCC.runCommand("HealthCheck",vfModuleId)
331 //SDNO health diagnostic
332 public void healthDiagnosticSDNO(DelegateExecution execution) {
334 System.out.print("*****************************healthDiagnosticSDNO is currently ignored*************************")
335 //SDNOValidatorImpl.healthDiagnostic("","");
338 //stop VF module controller
339 public void stopVfModuleController(DelegateExecution execution) {
341 System.out.print("*****************************stopVfModuleController*************************")
343 ApplicationControllerClient aCC = new ApplicationControllerClient(getLCMProperties())
344 def status = aCC.runCommand("Stop",vfModuleId)
349 public void doUpdateVfModulePrep(DelegateExecution execution) {
351 System.out.print("*****************************doUpdateVfModulePrep*************************")
352 def method = getClass().getSimpleName() + '.prepDoUpdateVfModule(' +
353 'execution=' + execution.getId() +
356 //msoLogger.trace('Entered ' + method)
360 //msoLogger.trace('Exited ' + method)
361 } catch (BpmnError e) {
363 } catch (Exception e) {
364 //msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, 'Caught exception in ' + method, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "Exception is:\n" + e);
365 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in prepDoUpdateVfModule(): ' + e.getMessage())
371 public void completionHandlerPrep(DelegateExecution execution,String resultVar) {
373 System.out.print("*****************************completionHandlerPrep*************************")
374 def method = getClass().getSimpleName() + '.completionHandlerPrep(' +
375 'execution=' + execution.getId() +
376 ', resultVar=' + resultVar +
379 //msoLogger.trace('Entered ' + method)
382 def requestInfo = getVariable(execution, 'UPDVfModI_requestInfo')
385 <sdncadapterworkflow:MsoCompletionRequest xmlns:sdncadapterworkflow="http://org.onap/so/workflow/schema/v1"
386 xmlns:reqtype="http://org.onap/so/request/types/v1">
388 <sdncadapterworkflow:mso-bpel-name>MSO_ACTIVATE_BPEL</sdncadapterworkflow:mso-bpel-name>
389 </sdncadapterworkflow:MsoCompletionRequest>
392 content = utils.formatXml(content)
393 //msoLogger.debug(resultVar + ' = ' + System.lineSeparator() + content)
394 execution.setVariable(resultVar, content)
396 //msoLogger.trace('Exited ' + method)
397 } catch (BpmnError e) {
399 } catch (Exception e) {
400 //msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, 'Caught exception in ' + method, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "Exception is:\n" + e);
401 exceptionUtil.buildAndThrowWorkflowException(execution, 2000, 'Internal Error')
407 public void healthCheckController(DelegateExecution execution) {
409 System.out.print("*****************************healthCheckController*************************")
411 ApplicationControllerClient aCC = new ApplicationControllerClient(getLCMProperties())
412 def status = aCC.runCommand("HealthCheck",vfModuleId)
416 public void startVfModuleController(DelegateExecution execution) {
418 System.out.print("*****************************startVfModuleController*************************")
420 ApplicationControllerClient aCC = new ApplicationControllerClient(getLCMProperties())
421 def status = aCC.runCommand("Start",vfModuleId)
425 public void vFFlagUnset(DelegateExecution execution) {
427 System.out.print("*****************************vFFlagUnset*************************")
428 String vnfId = (String)execution.getVariable('vnfId')
429 String uuid = (String)execution.getVariable('moduleUuid')
430 AAIValidatorImpl aaiVI = new AAIValidatorImpl()
431 aaiVI.updateVnfToUnLocked(vnfId,uuid);
436 public void unlockAppC(DelegateExecution execution) {
438 System.out.print("*****************************unlockAppC*************************")
440 ApplicationControllerClient aCC = new ApplicationControllerClient(getLCMProperties())
441 def status = aCC.runCommand("Unlock",vfModuleId)
445 public void postUpgradeHealthCheckController(DelegateExecution execution) {
447 System.out.print("*****************************postUpgradeHealthCheckController*************************")
449 ApplicationControllerClient aCC = new ApplicationControllerClient(getLCMProperties())
450 def status = aCC.runCommand("HealthCheck",vfModuleId)
454 Properties getLCMProperties() {
455 Properties properties = new Properties()
457 properties.put("topic.read", UrnPropertiesReader.getVariable("appc.client.topic.read.name"))
458 properties.put("topic.read.timeout", UrnPropertiesReader.getVariable("appc.client.topic.read.timeout"))
459 properties.put("client.response.timeout", UrnPropertiesReader.getVariable("appc.client.response.timeout"))
460 properties.put("topic.write", UrnPropertiesReader.getVariable("appc.client.topic.write"))
461 properties.put("poolMembers", UrnPropertiesReader.getVariable("appc.client.poolMembers"))
462 properties.put("client.key", UrnPropertiesReader.getVariable("appc.client.key"))
463 properties.put("client.secret", UrnPropertiesReader.getVariable("appc.client.secret"))
464 properties.put("client.name", "MSO")
465 properties.put("service", UrnPropertiesReader.getVariable("appc.client.service"))