2 * ============LICENSE_START=======================================================
\r
4 * ================================================================================
\r
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
\r
6 * ================================================================================
\r
7 * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * you may not use this file except in compliance with the License.
\r
9 * You may obtain a copy of the License at
\r
11 * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * Unless required by applicable law or agreed to in writing, software
\r
14 * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * See the License for the specific language governing permissions and
\r
17 * limitations under the License.
\r
18 * ============LICENSE_END=========================================================
\r
21 package org.openecomp.mso.bpmn.infrastructure.scripts
\r
24 import groovy.json.JsonOutput
\r
25 import groovy.json.JsonSlurper
\r
26 import groovy.util.Node
\r
27 import groovy.util.XmlParser;
\r
28 import groovy.xml.QName
\r
30 import org.camunda.bpm.engine.delegate.BpmnError
\r
31 import org.camunda.bpm.engine.impl.cmd.AbstractSetVariableCmd
\r
32 import org.camunda.bpm.engine.delegate.DelegateExecution
\r
34 import java.io.Serializable;
\r
35 import java.util.List
\r
37 import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil
\r
38 import org.openecomp.mso.rest.APIResponse
\r
39 import org.openecomp.mso.rest.RESTClient
\r
40 import org.openecomp.mso.rest.RESTConfig
\r
41 import org.springframework.beans.factory.annotation.Autowired
\r
43 import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor
\r
44 import org.openecomp.mso.bpmn.common.scripts.VidUtils
\r
45 import org.openecomp.mso.bpmn.core.RollbackData
\r
46 import org.openecomp.mso.bpmn.core.WorkflowException
\r
47 import org.openecomp.mso.client.aai.AAIValidatorImpl
\r
48 import org.openecomp.mso.client.aai.AAIUpdatorImpl
\r
49 import org.openecomp.mso.client.appc.ApplicationControllerClient
\r
50 import org.openecomp.mso.client.sdno.SDNOValidatorImpl
\r
54 public class UpdateVfModuleInfraV2 {
\r
56 ExceptionUtil exceptionUtil = new ExceptionUtil()
\r
58 boolean preProcessRequestCheck = true;
\r
59 boolean sendSynchResponseCheck = true;
\r
60 boolean checkPserverFlagCheck = true;
\r
61 boolean vfFlagCheckSetCheck = true;
\r
62 boolean lockAppCCheck = true;
\r
63 boolean healthDiagnosticSDNOCheck = true;
\r
64 boolean healthCheckAppCCheck = true;
\r
65 boolean stopVfModuleControllerCheck = true;
\r
66 boolean healthCheckControllerCheck = true;
\r
67 boolean doUpdateVfModulePrepCheck = true;
\r
68 boolean completionHandlerPrepCheck = true;
\r
69 boolean startVfModuleControllerCheck = true;
\r
70 boolean vFFlagUnsetCheck = true;
\r
71 boolean unlockAppCCheck = true;
\r
72 boolean postUpgradeHealthCheckControllerCheck = true;
\r
76 public void initProcessVariables(DelegateExecution execution) {
\r
77 execution.setVariable('prefix', 'UPDVfModI_')
\r
78 execution.setVariable('UPDVfModI_Request', null)
\r
79 execution.setVariable('UPDVfModI_requestInfo', null)
\r
80 execution.setVariable('UPDVfModI_requestId', null)
\r
81 execution.setVariable('UPDVfModI_source', null)
\r
82 execution.setVariable('UPDVfModI_vnfInputs', null)
\r
83 execution.setVariable('UPDVfModI_vnfId', null)
\r
84 execution.setVariable('UPDVFModI_moduleUuid', null)
\r
85 execution.setVariable('UPDVfModI_vfModuleId', null)
\r
86 execution.setVariable('UPDVfModI_tenantId', null)
\r
87 execution.setVariable('UPDVfModI_volumeGroupId', null)
\r
88 execution.setVariable('UPDVfModI_vnfParams', null)
\r
89 execution.setVariable('UPDVfModI_updateInfraRequest', null)
\r
90 execution.setVariable('UpdateVfModuleSuccessIndicator', false)
\r
94 * Check for missing elements in the received request.
\r
96 * @param execution The flow's execution instance.
\r
98 public void preProcessRequest(DelegateExecution execution) {
\r
99 System.out.print("*****************************PreProcessRequest**************************")
\r
101 def method = getClass().getSimpleName() + '.preProcessRequest(' +
\r
102 'execution=' + execution.getId() +
\r
104 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
\r
105 //logDebug('Entered ' + method, isDebugLogEnabled)
\r
107 initProcessVariables(execution)
\r
109 def prefix = "UPDVfModI_"
\r
111 def incomingRequest = execution.getVariable('bpmnRequest')
\r
113 //utils.log("DEBUG", "Incoming Infra Request: " + incomingRequest, isDebugLogEnabled)
\r
115 def jsonSlurper = new JsonSlurper()
\r
116 def jsonOutput = new JsonOutput()
\r
117 Map reqMap = jsonSlurper.parseText(incomingRequest)
\r
118 //utils.log("DEBUG", " Request is in JSON format.", isDebugLogEnabled)
\r
120 def serviceInstanceId = execution.getVariable('serviceInstanceId')
\r
121 def vnfId = execution.getVariable('vnfId')
\r
122 def moduleUuid = execution.getVariable('moduleUuid')
\r
123 execution.setVariable(prefix + 'moduleUuid',moduleUuid)
\r
124 execution.setVariable(prefix + 'serviceInstanceId', serviceInstanceId)
\r
125 execution.setVariable(prefix+'vnfId', vnfId)
\r
126 execution.setVariable("isVidRequest", "true")
\r
129 def asdcServiceModelVersion = ''
\r
130 def serviceModelInfo = null
\r
131 def vnfModelInfo = null
\r
133 def relatedInstanceList = reqMap.requestDetails?.relatedInstanceList
\r
135 if (relatedInstanceList != null) {
\r
136 relatedInstanceList.each {
\r
137 if (it.relatedInstance.modelInfo?.modelType == 'service') {
\r
138 asdcServiceModelVersion = it.relatedInstance.modelInfo?.modelVersion
\r
139 serviceModelInfo = jsonOutput.toJson(it.relatedInstance.modelInfo)
\r
141 if (it.relatedInstance.modelInfo.modelType == 'vnf') {
\r
142 vnfName = it.relatedInstance.instanceName ?: ''
\r
143 vnfModelInfo = jsonOutput.toJson(it.relatedInstance.modelInfo)
\r
148 execution.setVariable(prefix + 'vnfName', vnfName)
\r
149 execution.setVariable(prefix + 'asdcServiceModelVersion', asdcServiceModelVersion)
\r
150 execution.setVariable(prefix + 'serviceModelInfo', serviceModelInfo)
\r
151 execution.setVariable(prefix + 'vnfModelInfo', vnfModelInfo)
\r
153 def vnfType = execution.getVariable('vnfType')
\r
154 execution.setVariable(prefix + 'vnfType', vnfType)
\r
155 def vfModuleId = execution.getVariable('vfModuleId')
\r
156 execution.setVariable(prefix + 'vfModuleId', vfModuleId)
\r
157 def volumeGroupId = execution.getVariable('volumeGroupId')
\r
158 execution.setVariable(prefix + 'volumeGroupId', volumeGroupId)
\r
159 def userParams = reqMap.requestDetails?.requestParameters?.userParams
\r
161 Map<String, String> userParamsMap = [:]
\r
162 if (userParams != null) {
\r
163 userParams.each { userParam ->
\r
164 userParamsMap.put(userParam.name, userParam.value.toString())
\r
168 //utils.log("DEBUG", 'Processed user params: ' + userParamsMap, isDebugLogEnabled)
\r
170 execution.setVariable(prefix + 'vfModuleInputParams', userParamsMap)
\r
172 def isBaseVfModule = "false"
\r
173 if (execution.getVariable('isBaseVfModule') == true) {
\r
174 isBaseVfModule = "true"
\r
177 execution.setVariable(prefix + 'isBaseVfModule', isBaseVfModule)
\r
179 def requestId = execution.getVariable("mso-request-id")
\r
180 execution.setVariable(prefix + 'requestId', requestId)
\r
182 def vfModuleModelInfo = jsonOutput.toJson(reqMap.requestDetails?.modelInfo)
\r
183 execution.setVariable(prefix + 'vfModuleModelInfo', vfModuleModelInfo)
\r
185 def suppressRollback = reqMap.requestDetails?.requestInfo?.suppressRollback
\r
188 def backoutOnFailure = ""
\r
189 if(suppressRollback != null){
\r
190 if ( suppressRollback == true) {
\r
191 backoutOnFailure = "false"
\r
192 } else if ( suppressRollback == false) {
\r
193 backoutOnFailure = "true"
\r
197 execution.setVariable('disableRollback', suppressRollback)
\r
199 def vfModuleName = reqMap.requestDetails?.requestInfo?.instanceName ?: null
\r
200 execution.setVariable(prefix + 'vfModuleName', vfModuleName)
\r
202 def serviceId = reqMap.requestDetails?.requestParameters?.serviceId ?: ''
\r
203 execution.setVariable(prefix + 'serviceId', serviceId)
\r
205 def usePreload = reqMap.requestDetails?.requestParameters?.usePreload
\r
206 execution.setVariable(prefix + 'usePreload', usePreload)
\r
208 def cloudConfiguration = reqMap.requestDetails?.cloudConfiguration
\r
209 def lcpCloudRegionId = cloudConfiguration.lcpCloudRegionId
\r
210 execution.setVariable(prefix + 'lcpCloudRegionId', lcpCloudRegionId)
\r
211 def tenantId = cloudConfiguration.tenantId
\r
212 execution.setVariable(prefix + 'tenantId', tenantId)
\r
214 def globalSubscriberId = reqMap.requestDetails?.subscriberInfo?.globalSubscriberId ?: ''
\r
215 execution.setVariable(prefix + 'globalSubscriberId', globalSubscriberId)
\r
217 execution.setVariable(prefix + 'sdncVersion', '1702')
\r
219 execution.setVariable("UpdateVfModuleInfraSuccessIndicator", false)
\r
221 execution.setVariable("isDebugLogEnabled", isDebugLogEnabled)
\r
224 def source = reqMap.requestDetails?.requestInfo?.source
\r
225 execution.setVariable(prefix + "source", source)
\r
227 //For Completion Handler & Fallout Handler
\r
228 String requestInfo =
\r
229 """<request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">
\r
230 <request-id>${requestId}</request-id>
\r
231 <action>UPDATE</action>
\r
232 <source>${source}</source>
\r
235 execution.setVariable(prefix + "requestInfo", requestInfo)
\r
239 //logDebug('RequestInfo: ' + execution.getVariable(prefix + "requestInfo"), isDebugLogEnabled)
\r
241 //logDebug('Exited ' + method, isDebugLogEnabled)
\r
244 catch(groovy.json.JsonException je) {
\r
245 //utils.log("DEBUG", " Request is not in JSON format.", isDebugLogEnabled)
\r
246 exceptionUtil.buildAndThrowWorkflowException(execution, 5000, "Invalid request format")
\r
248 catch(Exception e) {
\r
249 String restFaultMessage = e.getMessage()
\r
250 //utils.log("ERROR", " Exception Encountered - " + "\n" + restFaultMessage, isDebugLogEnabled)
\r
251 exceptionUtil.buildAndThrowWorkflowException(execution, 5000, restFaultMessage)
\r
256 * Prepare and send the synchronous response for this flow.
\r
258 * @param execution The flow's execution instance.
\r
260 public void sendSynchResponse(DelegateExecution execution) {
\r
261 System.out.print("*****************************SendSynchResponse**************************")
\r
263 def method = getClass().getSimpleName() + '.sendSynchResponse(' +
\r
264 'execution=' + execution.getId() +
\r
266 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
\r
267 //logDebug('Entered ' + method, isDebugLogEnabled)
\r
271 def requestInfo = execution.getVariable('UPDVfModI_requestInfo')
\r
272 def requestId = execution.getVariable('UPDVfModI_requestId')
\r
273 def source = execution.getVariable('UPDVfModI_source')
\r
275 def progress = getNodeTextForce(requestInfo, 'progress')
\r
276 if (progress.isEmpty()) {
\r
279 def startTime = getNodeTextForce(requestInfo, 'start-time')
\r
280 if (startTime.isEmpty()) {
\r
281 startTime = System.currentTimeMillis()
\r
283 // RESTResponse (for API Handler (APIH) Reply Task)
\r
284 def vfModuleId = execution.getVariable("vfModuleId")
\r
285 String synchResponse = """{"requestReferences":{"instanceId":"${vfModuleId}","requestId":"${requestId}"}}""".trim()
\r
286 sendWorkflowResponse(execution, 200, synchResponse)
\r
287 //logDebug('Exited ' + method, isDebugLogEnabled)
\r
288 } catch (BpmnError e) {
\r
290 } catch (Exception e) {
\r
291 //logError('Caught exception in ' + method, e)
\r
292 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in sendResponse(): ' + e.getMessage())
\r
296 //check to see if the Pserver Flag is locked
\r
297 public void checkPserverFlag(DelegateExecution execution) {
\r
299 System.out.println("*****************************CheckingPserverFlag*************************")
\r
300 String vnfId = (String)execution.getVariable('vnfId')
\r
301 String uuid = (String)execution.getVariable('moduleUuid')
\r
302 AAIValidatorImpl aaiVI = new AAIValidatorImpl()
\r
303 boolean flag = aaiVI.isPhysicalServerLocked(vnfId, uuid)
\r
306 //check to see if the VFFlag is locked
\r
307 public void vfFlagCheck(DelegateExecution execution) {
\r
309 System.out.print("*****************************VfFlagCheck*************************")
\r
310 String vnfId = (String)execution.getVariable('vnfId')
\r
311 String uuid = (String)execution.getVariable('moduleUuid')
\r
312 AAIValidatorImpl aaiVI = new AAIValidatorImpl()
\r
313 boolean flag = aaiVI.isVNFLocked(vnfId, uuid)
\r
317 public void vfFlagSet(DelegateExecution execution) {
\r
319 System.out.print("*****************************VfFlagSet*************************")
\r
320 String vnfId = (String)execution.getVariable('vnfId')
\r
321 String uuid = (String)execution.getVariable('moduleUuid')
\r
322 AAIValidatorImpl aaiVI = new AAIValidatorImpl()
\r
323 aaiVI.updateVnfToLocked(vnfId,uuid);
\r
328 public void lockAppC(DelegateExecution execution) {
\r
330 System.out.print("*****************************lockAppC*************************")
\r
331 def vfModuleId = ""
\r
332 ApplicationControllerClient aCC = new ApplicationControllerClient();
\r
333 def status = aCC.runCommand("Lock",vfModuleId)
\r
338 public void healthCheckAppC(DelegateExecution execution) {
\r
340 System.out.print("*****************************healthCheckAppC*************************")
\r
341 def vfModuleId = ""
\r
342 ApplicationControllerClient aCC = new ApplicationControllerClient();
\r
343 def status = aCC.runCommand("HealthCheck",vfModuleId)
\r
346 //SDNO health diagnostic
\r
347 public void healthDiagnosticSDNO(DelegateExecution execution) {
\r
349 System.out.print("*****************************healthDiagnosticSDNO is currently ignored*************************")
\r
350 //SDNOValidatorImpl.healthDiagnostic("","");
\r
353 //stop VF module controller
\r
354 public void stopVfModuleController(DelegateExecution execution) {
\r
356 System.out.print("*****************************stopVfModuleController*************************")
\r
357 def vfModuleId = ""
\r
358 ApplicationControllerClient aCC = new ApplicationControllerClient();
\r
359 def status = aCC.runCommand("Stop",vfModuleId)
\r
364 public void doUpdateVfModulePrep(DelegateExecution execution) {
\r
366 System.out.print("*****************************doUpdateVfModulePrep*************************")
\r
367 def method = getClass().getSimpleName() + '.prepDoUpdateVfModule(' +
\r
368 'execution=' + execution.getId() +
\r
370 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
\r
371 //logDebug('Entered ' + method, isDebugLogEnabled)
\r
375 //logDebug('Exited ' + method, isDebugLogEnabled)
\r
376 } catch (BpmnError e) {
\r
378 } catch (Exception e) {
\r
379 //logError('Caught exception in ' + method, e)
\r
380 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in prepDoUpdateVfModule(): ' + e.getMessage())
\r
386 public void completionHandlerPrep(DelegateExecution execution,String resultVar) {
\r
388 System.out.print("*****************************completionHandlerPrep*************************")
\r
389 def method = getClass().getSimpleName() + '.completionHandlerPrep(' +
\r
390 'execution=' + execution.getId() +
\r
391 ', resultVar=' + resultVar +
\r
393 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
\r
394 //logDebug('Entered ' + method, isDebugLogEnabled)
\r
397 def requestInfo = getVariable(execution, 'UPDVfModI_requestInfo')
\r
399 String content = """
\r
400 <sdncadapterworkflow:MsoCompletionRequest xmlns:sdncadapterworkflow="http://org.openecomp/mso/workflow/schema/v1"
\r
401 xmlns:reqtype="http://org.openecomp/mso/request/types/v1">
\r
403 <sdncadapterworkflow:mso-bpel-name>MSO_ACTIVATE_BPEL</sdncadapterworkflow:mso-bpel-name>
\r
404 </sdncadapterworkflow:MsoCompletionRequest>
\r
407 content = utils.formatXml(content)
\r
408 //logDebug(resultVar + ' = ' + System.lineSeparator() + content, isDebugLogEnabled)
\r
409 execution.setVariable(resultVar, content)
\r
411 //logDebug('Exited ' + method, isDebugLogEnabled)
\r
412 } catch (BpmnError e) {
\r
414 } catch (Exception e) {
\r
415 //logError('Caught exception in ' + method, e)
\r
416 exceptionUtil.buildAndThrowWorkflowException(execution, 2000, 'Internal Error')
\r
422 public void healthCheckController(DelegateExecution execution) {
\r
424 System.out.print("*****************************healthCheckController*************************")
\r
425 def vfModuleId = ""
\r
426 ApplicationControllerClient aCC = new ApplicationControllerClient();
\r
427 def status = aCC.runCommand("HealthCheck",vfModuleId)
\r
431 public void startVfModuleController(DelegateExecution execution) {
\r
433 System.out.print("*****************************startVfModuleController*************************")
\r
434 def vfModuleId = ""
\r
435 ApplicationControllerClient aCC = new ApplicationControllerClient();
\r
436 def status = aCC.runCommand("Start",vfModuleId)
\r
440 public void vFFlagUnset(DelegateExecution execution) {
\r
442 System.out.print("*****************************vFFlagUnset*************************")
\r
443 String vnfId = (String)execution.getVariable('vnfId')
\r
444 String uuid = (String)execution.getVariable('moduleUuid')
\r
445 AAIValidatorImpl aaiVI = new AAIValidatorImpl()
\r
446 aaiVI.updateVnfToUnLocked(vnfId,uuid);
\r
451 public void unlockAppC(DelegateExecution execution) {
\r
453 System.out.print("*****************************unlockAppC*************************")
\r
454 def vfModuleId = ""
\r
455 ApplicationControllerClient aCC = new ApplicationControllerClient();
\r
456 def status = aCC.runCommand("Unlock",vfModuleId)
\r
460 public void postUpgradeHealthCheckController(DelegateExecution execution) {
\r
462 System.out.print("*****************************postUpgradeHealthCheckController*************************")
\r
463 def vfModuleId = ""
\r
464 ApplicationControllerClient aCC = new ApplicationControllerClient();
\r
465 def status = aCC.runCommand("HealthCheck",vfModuleId)
\r