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 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 logger.debug("*****************************SendSynchResponse**************************")
250 def method = getClass().getSimpleName() + '.sendSynchResponse(' +
251 'execution=' + execution.getId() +
254 //logger.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 //logger.trace('Exited ' + method)
275 } catch (BpmnError e) {
277 } catch (Exception e) {
278 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in sendResponse(): ' + e.getMessage())
282 //check to see if the Pserver Flag is locked
283 public void checkPserverFlag(DelegateExecution execution) {
285 logger.debug("*****************************CheckingPserverFlag*************************")
286 String vnfId = (String)execution.getVariable('vnfId')
287 AAIValidatorImpl aaiVI = new AAIValidatorImpl()
288 boolean flag = aaiVI.isPhysicalServerLocked(vnfId)
291 //check to see if the VFFlag is locked
292 public void vfFlagCheck(DelegateExecution execution) {
294 logger.debug("*****************************VfFlagCheck*************************")
295 String vnfId = (String)execution.getVariable('vnfId')
296 AAIValidatorImpl aaiVI = new AAIValidatorImpl()
297 boolean flag = aaiVI.isVNFLocked(vnfId)
301 public void vfFlagSet(DelegateExecution execution) {
303 logger.debug("*****************************VfFlagSet*************************")
304 String vnfId = (String)execution.getVariable('vnfId')
305 String uuid = (String)execution.getVariable('moduleUuid')
306 AAIValidatorImpl aaiVI = new AAIValidatorImpl()
307 aaiVI.updateVnfToLocked(vnfId,uuid);
312 public void lockAppC(DelegateExecution execution) {
314 logger.debug("*****************************lockAppC*************************")
316 ApplicationControllerClient aCC = new ApplicationControllerClient(getLCMProperties())
317 def status = aCC.runCommand("Lock",vfModuleId)
322 public void healthCheckAppC(DelegateExecution execution) {
324 logger.debug("*****************************healthCheckAppC*************************")
326 ApplicationControllerClient aCC = new ApplicationControllerClient(getLCMProperties())
327 def status = aCC.runCommand("HealthCheck",vfModuleId)
330 //SDNO health diagnostic
331 public void healthDiagnosticSDNO(DelegateExecution execution) {
333 logger.debug("*****************************healthDiagnosticSDNO is currently ignored*************************")
334 //SDNOValidatorImpl.healthDiagnostic("","");
337 //stop VF module controller
338 public void stopVfModuleController(DelegateExecution execution) {
340 logger.debug("*****************************stopVfModuleController*************************")
342 ApplicationControllerClient aCC = new ApplicationControllerClient(getLCMProperties())
343 def status = aCC.runCommand("Stop",vfModuleId)
348 public void doUpdateVfModulePrep(DelegateExecution execution) {
350 logger.debug("*****************************doUpdateVfModulePrep*************************")
351 def method = getClass().getSimpleName() + '.prepDoUpdateVfModule(' +
352 'execution=' + execution.getId() +
355 //logger.trace('Entered ' + method)
359 //logger.trace('Exited ' + method)
360 } catch (BpmnError e) {
362 } catch (Exception e) {
363 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in prepDoUpdateVfModule(): ' + e.getMessage())
369 public void completionHandlerPrep(DelegateExecution execution,String resultVar) {
371 logger.debug("*****************************completionHandlerPrep*************************")
372 def method = getClass().getSimpleName() + '.completionHandlerPrep(' +
373 'execution=' + execution.getId() +
374 ', resultVar=' + resultVar +
377 //logger.trace('Entered ' + method)
380 def requestInfo = getVariable(execution, 'UPDVfModI_requestInfo')
383 <sdncadapterworkflow:MsoCompletionRequest xmlns:sdncadapterworkflow="http://org.onap/so/workflow/schema/v1"
384 xmlns:reqtype="http://org.onap/so/request/types/v1">
386 <sdncadapterworkflow:mso-bpel-name>MSO_ACTIVATE_BPEL</sdncadapterworkflow:mso-bpel-name>
387 </sdncadapterworkflow:MsoCompletionRequest>
390 content = utils.formatXml(content)
391 //logger.debug(resultVar + ' = ' + System.lineSeparator() + content)
392 execution.setVariable(resultVar, content)
394 //logger.trace('Exited ' + method)
395 } catch (BpmnError e) {
397 } catch (Exception e) {
398 exceptionUtil.buildAndThrowWorkflowException(execution, 2000, 'Internal Error')
404 public void healthCheckController(DelegateExecution execution) {
406 logger.debug("*****************************healthCheckController*************************")
408 ApplicationControllerClient aCC = new ApplicationControllerClient(getLCMProperties())
409 def status = aCC.runCommand("HealthCheck",vfModuleId)
413 public void startVfModuleController(DelegateExecution execution) {
415 logger.debug("*****************************startVfModuleController*************************")
417 ApplicationControllerClient aCC = new ApplicationControllerClient(getLCMProperties())
418 def status = aCC.runCommand("Start",vfModuleId)
422 public void vFFlagUnset(DelegateExecution execution) {
424 logger.debug("*****************************vFFlagUnset*************************")
425 String vnfId = (String)execution.getVariable('vnfId')
426 String uuid = (String)execution.getVariable('moduleUuid')
427 AAIValidatorImpl aaiVI = new AAIValidatorImpl()
428 aaiVI.updateVnfToUnLocked(vnfId,uuid);
433 public void unlockAppC(DelegateExecution execution) {
435 logger.debug("*****************************unlockAppC*************************")
437 ApplicationControllerClient aCC = new ApplicationControllerClient(getLCMProperties())
438 def status = aCC.runCommand("Unlock",vfModuleId)
442 public void postUpgradeHealthCheckController(DelegateExecution execution) {
444 logger.debug("*****************************postUpgradeHealthCheckController*************************")
446 ApplicationControllerClient aCC = new ApplicationControllerClient(getLCMProperties())
447 def status = aCC.runCommand("HealthCheck",vfModuleId)
451 Properties getLCMProperties() {
452 Properties properties = new Properties()
454 properties.put("topic.read", UrnPropertiesReader.getVariable("appc.client.topic.read.name"))
455 properties.put("topic.read.timeout", UrnPropertiesReader.getVariable("appc.client.topic.read.timeout"))
456 properties.put("client.response.timeout", UrnPropertiesReader.getVariable("appc.client.response.timeout"))
457 properties.put("topic.write", UrnPropertiesReader.getVariable("appc.client.topic.write"))
458 properties.put("poolMembers", UrnPropertiesReader.getVariable("appc.client.poolMembers"))
459 properties.put("client.key", UrnPropertiesReader.getVariable("appc.client.key"))
460 properties.put("client.secret", UrnPropertiesReader.getVariable("appc.client.secret"))
461 properties.put("client.name", "MSO")
462 properties.put("service", UrnPropertiesReader.getVariable("appc.client.service"))