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
29 import inventory.aai.att.com.v10.GenericVnf
\r
30 import inventory.aai.att.com.v10.GenericVnfs
\r
31 import inventory.aai.att.com.v10.Pserver
\r
33 import org.camunda.bpm.engine.delegate.BpmnError
\r
34 import org.camunda.bpm.engine.impl.cmd.AbstractSetVariableCmd
\r
35 import org.camunda.bpm.engine.runtime.Execution
\r
37 import java.io.Serializable;
\r
38 import java.util.List
\r
40 import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil
\r
41 import org.openecomp.mso.rest.APIResponse
\r
42 import org.openecomp.mso.rest.RESTClient
\r
43 import org.openecomp.mso.rest.RESTConfig
\r
44 import org.springframework.beans.factory.annotation.Autowired
\r
46 import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor
\r
47 import org.openecomp.mso.bpmn.common.scripts.VidUtils
\r
48 import org.openecomp.mso.bpmn.core.RollbackData
\r
49 import org.openecomp.mso.bpmn.core.WorkflowException
\r
50 import org.openecomp.mso.client.aai.AAIValidatorImpl
\r
51 import org.openecomp.mso.client.aai.AAIUpdatorImpl
\r
52 import org.openecomp.mso.client.appc.ApplicationControllerClient
\r
53 import org.openecomp.mso.client.sdno.SDNOValidatorImpl
\r
57 public class UpdateVfModuleInfraV2 {
\r
59 ExceptionUtil exceptionUtil = new ExceptionUtil()
\r
61 boolean preProcessRequestCheck = true;
\r
62 boolean sendSynchResponseCheck = true;
\r
63 boolean checkPserverFlagCheck = true;
\r
64 boolean vfFlagCheckSetCheck = true;
\r
65 boolean lockAppCCheck = true;
\r
66 boolean healthDiagnosticSDNOCheck = true;
\r
67 boolean healthCheckAppCCheck = true;
\r
68 boolean stopVfModuleControllerCheck = true;
\r
69 boolean healthCheckControllerCheck = true;
\r
70 boolean doUpdateVfModulePrepCheck = true;
\r
71 boolean completionHandlerPrepCheck = true;
\r
72 boolean startVfModuleControllerCheck = true;
\r
73 boolean vFFlagUnsetCheck = true;
\r
74 boolean unlockAppCCheck = true;
\r
75 boolean postUpgradeHealthCheckControllerCheck = true;
\r
79 public void initProcessVariables(Execution execution) {
\r
80 execution.setVariable('prefix', 'UPDVfModI_')
\r
81 execution.setVariable('UPDVfModI_Request', null)
\r
82 execution.setVariable('UPDVfModI_requestInfo', null)
\r
83 execution.setVariable('UPDVfModI_requestId', null)
\r
84 execution.setVariable('UPDVfModI_source', null)
\r
85 execution.setVariable('UPDVfModI_vnfInputs', null)
\r
86 execution.setVariable('UPDVfModI_vnfId', null)
\r
87 execution.setVariable('UPDVFModI_moduleUuid', null)
\r
88 execution.setVariable('UPDVfModI_vfModuleId', null)
\r
89 execution.setVariable('UPDVfModI_tenantId', null)
\r
90 execution.setVariable('UPDVfModI_volumeGroupId', null)
\r
91 execution.setVariable('UPDVfModI_vnfParams', null)
\r
92 execution.setVariable('UPDVfModI_updateInfraRequest', null)
\r
93 execution.setVariable('UpdateVfModuleSuccessIndicator', false)
\r
97 * Check for missing elements in the received request.
\r
99 * @param execution The flow's execution instance.
\r
101 public void preProcessRequest(Execution execution) {
\r
102 System.out.print("*****************************PreProcessRequest**************************")
\r
104 def method = getClass().getSimpleName() + '.preProcessRequest(' +
\r
105 'execution=' + execution.getId() +
\r
107 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
\r
108 //logDebug('Entered ' + method, isDebugLogEnabled)
\r
110 initProcessVariables(execution)
\r
112 def prefix = "UPDVfModI_"
\r
114 def incomingRequest = execution.getVariable('bpmnRequest')
\r
116 //utils.log("DEBUG", "Incoming Infra Request: " + incomingRequest, isDebugLogEnabled)
\r
118 def jsonSlurper = new JsonSlurper()
\r
119 def jsonOutput = new JsonOutput()
\r
120 Map reqMap = jsonSlurper.parseText(incomingRequest)
\r
121 //utils.log("DEBUG", " Request is in JSON format.", isDebugLogEnabled)
\r
123 def serviceInstanceId = execution.getVariable('serviceInstanceId')
\r
124 def vnfId = execution.getVariable('vnfId')
\r
125 def moduleUuid = execution.getVariable('moduleUuid')
\r
126 execution.setVariable(prefix + 'moduleUuid',moduleUuid)
\r
127 execution.setVariable(prefix + 'serviceInstanceId', serviceInstanceId)
\r
128 execution.setVariable(prefix+'vnfId', vnfId)
\r
129 execution.setVariable("isVidRequest", "true")
\r
132 def asdcServiceModelVersion = ''
\r
133 def serviceModelInfo = null
\r
134 def vnfModelInfo = null
\r
136 def relatedInstanceList = reqMap.requestDetails?.relatedInstanceList
\r
138 if (relatedInstanceList != null) {
\r
139 relatedInstanceList.each {
\r
140 if (it.relatedInstance.modelInfo?.modelType == 'service') {
\r
141 asdcServiceModelVersion = it.relatedInstance.modelInfo?.modelVersion
\r
142 serviceModelInfo = jsonOutput.toJson(it.relatedInstance.modelInfo)
\r
144 if (it.relatedInstance.modelInfo.modelType == 'vnf') {
\r
145 vnfName = it.relatedInstance.instanceName ?: ''
\r
146 vnfModelInfo = jsonOutput.toJson(it.relatedInstance.modelInfo)
\r
151 execution.setVariable(prefix + 'vnfName', vnfName)
\r
152 execution.setVariable(prefix + 'asdcServiceModelVersion', asdcServiceModelVersion)
\r
153 execution.setVariable(prefix + 'serviceModelInfo', serviceModelInfo)
\r
154 execution.setVariable(prefix + 'vnfModelInfo', vnfModelInfo)
\r
156 def vnfType = execution.getVariable('vnfType')
\r
157 execution.setVariable(prefix + 'vnfType', vnfType)
\r
158 def vfModuleId = execution.getVariable('vfModuleId')
\r
159 execution.setVariable(prefix + 'vfModuleId', vfModuleId)
\r
160 def volumeGroupId = execution.getVariable('volumeGroupId')
\r
161 execution.setVariable(prefix + 'volumeGroupId', volumeGroupId)
\r
162 def userParams = reqMap.requestDetails?.requestParameters?.userParams
\r
164 Map<String, String> userParamsMap = [:]
\r
165 if (userParams != null) {
\r
166 userParams.each { userParam ->
\r
167 userParamsMap.put(userParam.name, userParam.value)
\r
171 //utils.log("DEBUG", 'Processed user params: ' + userParamsMap, isDebugLogEnabled)
\r
173 execution.setVariable(prefix + 'vfModuleInputParams', userParamsMap)
\r
175 def isBaseVfModule = "false"
\r
176 if (execution.getVariable('isBaseVfModule') == true) {
\r
177 isBaseVfModule = "true"
\r
180 execution.setVariable(prefix + 'isBaseVfModule', isBaseVfModule)
\r
182 def requestId = execution.getVariable("mso-request-id")
\r
183 execution.setVariable(prefix + 'requestId', requestId)
\r
185 def vfModuleModelInfo = jsonOutput.toJson(reqMap.requestDetails?.modelInfo)
\r
186 execution.setVariable(prefix + 'vfModuleModelInfo', vfModuleModelInfo)
\r
188 def suppressRollback = reqMap.requestDetails?.requestInfo?.suppressRollback
\r
191 def backoutOnFailure = ""
\r
192 if(suppressRollback != null){
\r
193 if ( suppressRollback == true) {
\r
194 backoutOnFailure = "false"
\r
195 } else if ( suppressRollback == false) {
\r
196 backoutOnFailure = "true"
\r
200 execution.setVariable('disableRollback', suppressRollback)
\r
202 def vfModuleName = reqMap.requestDetails?.requestInfo?.instanceName ?: null
\r
203 execution.setVariable(prefix + 'vfModuleName', vfModuleName)
\r
205 def serviceId = reqMap.requestDetails?.requestParameters?.serviceId ?: ''
\r
206 execution.setVariable(prefix + 'serviceId', serviceId)
\r
208 def usePreload = reqMap.requestDetails?.requestParameters?.usePreload
\r
209 execution.setVariable(prefix + 'usePreload', usePreload)
\r
211 def cloudConfiguration = reqMap.requestDetails?.cloudConfiguration
\r
212 def lcpCloudRegionId = cloudConfiguration.lcpCloudRegionId
\r
213 execution.setVariable(prefix + 'lcpCloudRegionId', lcpCloudRegionId)
\r
214 def tenantId = cloudConfiguration.tenantId
\r
215 execution.setVariable(prefix + 'tenantId', tenantId)
\r
217 def globalSubscriberId = reqMap.requestDetails?.subscriberInfo?.globalSubscriberId ?: ''
\r
218 execution.setVariable(prefix + 'globalSubscriberId', globalSubscriberId)
\r
220 execution.setVariable(prefix + 'sdncVersion', '1702')
\r
222 execution.setVariable("UpdateVfModuleInfraSuccessIndicator", false)
\r
224 execution.setVariable("isDebugLogEnabled", isDebugLogEnabled)
\r
227 def source = reqMap.requestDetails?.requestInfo?.source
\r
228 execution.setVariable(prefix + "source", source)
\r
230 //For Completion Handler & Fallout Handler
\r
231 String requestInfo =
\r
232 """<request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">
\r
233 <request-id>${requestId}</request-id>
\r
234 <action>UPDATE</action>
\r
235 <source>${source}</source>
\r
238 execution.setVariable(prefix + "requestInfo", requestInfo)
\r
242 //logDebug('RequestInfo: ' + execution.getVariable(prefix + "requestInfo"), isDebugLogEnabled)
\r
244 //logDebug('Exited ' + method, isDebugLogEnabled)
\r
247 catch(groovy.json.JsonException je) {
\r
248 //utils.log("DEBUG", " Request is not in JSON format.", isDebugLogEnabled)
\r
249 exceptionUtil.buildAndThrowWorkflowException(execution, 5000, "Invalid request format")
\r
251 catch(Exception e) {
\r
252 String restFaultMessage = e.getMessage()
\r
253 //utils.log("ERROR", " Exception Encountered - " + "\n" + restFaultMessage, isDebugLogEnabled)
\r
254 exceptionUtil.buildAndThrowWorkflowException(execution, 5000, restFaultMessage)
\r
259 * Prepare and send the synchronous response for this flow.
\r
261 * @param execution The flow's execution instance.
\r
263 public void sendSynchResponse(Execution execution) {
\r
264 System.out.print("*****************************SendSynchResponse**************************")
\r
266 def method = getClass().getSimpleName() + '.sendSynchResponse(' +
\r
267 'execution=' + execution.getId() +
\r
269 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
\r
270 //logDebug('Entered ' + method, isDebugLogEnabled)
\r
274 def requestInfo = execution.getVariable('UPDVfModI_requestInfo')
\r
275 def requestId = execution.getVariable('UPDVfModI_requestId')
\r
276 def source = execution.getVariable('UPDVfModI_source')
\r
278 def progress = getNodeTextForce(requestInfo, 'progress')
\r
279 if (progress.isEmpty()) {
\r
282 def startTime = getNodeTextForce(requestInfo, 'start-time')
\r
283 if (startTime.isEmpty()) {
\r
284 startTime = System.currentTimeMillis()
\r
286 // RESTResponse (for API Handler (APIH) Reply Task)
\r
287 def vfModuleId = execution.getVariable("vfModuleId")
\r
288 String synchResponse = """{"requestReferences":{"instanceId":"${vfModuleId}","requestId":"${requestId}"}}""".trim()
\r
289 sendWorkflowResponse(execution, 200, synchResponse)
\r
290 //logDebug('Exited ' + method, isDebugLogEnabled)
\r
291 } catch (BpmnError e) {
\r
293 } catch (Exception e) {
\r
294 //logError('Caught exception in ' + method, e)
\r
295 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in sendResponse(): ' + e.getMessage())
\r
299 //check to see if the Pserver Flag is locked
\r
300 public void checkPserverFlag(Execution execution) {
\r
302 System.out.println("*****************************CheckingPserverFlag*************************")
\r
303 String vnfId = (String)execution.getVariable('vnfId')
\r
304 String uuid = (String)execution.getVariable('moduleUuid')
\r
305 AAIValidatorImpl aaiVI = new AAIValidatorImpl()
\r
306 boolean flag = aaiVI.isPhysicalServerLocked(vnfId, uuid)
\r
309 //check to see if the VFFlag is locked
\r
310 public void vfFlagCheck(Execution execution) {
\r
312 System.out.print("*****************************VfFlagCheck*************************")
\r
313 String vnfId = (String)execution.getVariable('vnfId')
\r
314 String uuid = (String)execution.getVariable('moduleUuid')
\r
315 AAIValidatorImpl aaiVI = new AAIValidatorImpl()
\r
316 boolean flag = aaiVI.isVNFLocked(vnfId, uuid)
\r
320 public void vfFlagSet(Execution execution) {
\r
322 System.out.print("*****************************VfFlagSet*************************")
\r
323 String vnfId = (String)execution.getVariable('vnfId')
\r
324 String uuid = (String)execution.getVariable('moduleUuid')
\r
325 AAIValidatorImpl aaiVI = new AAIValidatorImpl()
\r
326 aaiVI.updateVnfToLocked(vnfId,uuid);
\r
331 public void lockAppC(Execution execution) {
\r
333 System.out.print("*****************************lockAppC*************************")
\r
334 def vfModuleId = ""
\r
335 ApplicationControllerClient aCC = new ApplicationControllerClient();
\r
336 def status = aCC.runCommand("Lock",vfModuleId)
\r
341 public void healthCheckAppC(Execution execution) {
\r
343 System.out.print("*****************************healthCheckAppC*************************")
\r
344 def vfModuleId = ""
\r
345 ApplicationControllerClient aCC = new ApplicationControllerClient();
\r
346 def status = aCC.runCommand("HealthCheck",vfModuleId)
\r
349 //SDNO health diagnostic
\r
350 public void healthDiagnosticSDNO(Execution execution) {
\r
352 System.out.print("*****************************healthDiagnosticSDNO is currently ignored*************************")
\r
353 //SDNOValidatorImpl.healthDiagnostic("","");
\r
356 //stop VF module controller
\r
357 public void stopVfModuleController(Execution execution) {
\r
359 System.out.print("*****************************stopVfModuleController*************************")
\r
360 def vfModuleId = ""
\r
361 ApplicationControllerClient aCC = new ApplicationControllerClient();
\r
362 def status = aCC.runCommand("Stop",vfModuleId)
\r
367 public void doUpdateVfModulePrep(Execution execution) {
\r
369 System.out.print("*****************************doUpdateVfModulePrep*************************")
\r
370 def method = getClass().getSimpleName() + '.prepDoUpdateVfModule(' +
\r
371 'execution=' + execution.getId() +
\r
373 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
\r
374 //logDebug('Entered ' + method, isDebugLogEnabled)
\r
378 //logDebug('Exited ' + method, isDebugLogEnabled)
\r
379 } catch (BpmnError e) {
\r
381 } catch (Exception e) {
\r
382 //logError('Caught exception in ' + method, e)
\r
383 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in prepDoUpdateVfModule(): ' + e.getMessage())
\r
389 public void completionHandlerPrep(Execution execution,String resultVar) {
\r
391 System.out.print("*****************************completionHandlerPrep*************************")
\r
392 def method = getClass().getSimpleName() + '.completionHandlerPrep(' +
\r
393 'execution=' + execution.getId() +
\r
394 ', resultVar=' + resultVar +
\r
396 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
\r
397 //logDebug('Entered ' + method, isDebugLogEnabled)
\r
400 def requestInfo = getVariable(execution, 'UPDVfModI_requestInfo')
\r
402 String content = """
\r
403 <sdncadapterworkflow:MsoCompletionRequest xmlns:sdncadapterworkflow="http://org.openecomp/mso/workflow/schema/v1"
\r
404 xmlns:reqtype="http://org.openecomp/mso/request/types/v1">
\r
406 <sdncadapterworkflow:mso-bpel-name>MSO_ACTIVATE_BPEL</sdncadapterworkflow:mso-bpel-name>
\r
407 </sdncadapterworkflow:MsoCompletionRequest>
\r
410 content = utils.formatXml(content)
\r
411 //logDebug(resultVar + ' = ' + System.lineSeparator() + content, isDebugLogEnabled)
\r
412 execution.setVariable(resultVar, content)
\r
414 //logDebug('Exited ' + method, isDebugLogEnabled)
\r
415 } catch (BpmnError e) {
\r
417 } catch (Exception e) {
\r
418 //logError('Caught exception in ' + method, e)
\r
419 exceptionUtil.buildAndThrowWorkflowException(execution, 2000, 'Internal Error')
\r
425 public void healthCheckController(Execution execution) {
\r
427 System.out.print("*****************************healthCheckController*************************")
\r
428 def vfModuleId = ""
\r
429 ApplicationControllerClient aCC = new ApplicationControllerClient();
\r
430 def status = aCC.runCommand("HealthCheck",vfModuleId)
\r
434 public void startVfModuleController(Execution execution) {
\r
436 System.out.print("*****************************startVfModuleController*************************")
\r
437 def vfModuleId = ""
\r
438 ApplicationControllerClient aCC = new ApplicationControllerClient();
\r
439 def status = aCC.runCommand("Start",vfModuleId)
\r
443 public void vFFlagUnset(Execution execution) {
\r
445 System.out.print("*****************************vFFlagUnset*************************")
\r
446 String vnfId = (String)execution.getVariable('vnfId')
\r
447 String uuid = (String)execution.getVariable('moduleUuid')
\r
448 AAIValidatorImpl aaiVI = new AAIValidatorImpl()
\r
449 aaiVI.updateVnfToUnLocked(vnfId,uuid);
\r
454 public void unlockAppC(Execution execution) {
\r
456 System.out.print("*****************************unlockAppC*************************")
\r
457 def vfModuleId = ""
\r
458 ApplicationControllerClient aCC = new ApplicationControllerClient();
\r
459 def status = aCC.runCommand("Unlock",vfModuleId)
\r
463 public void postUpgradeHealthCheckController(Execution execution) {
\r
465 System.out.print("*****************************postUpgradeHealthCheckController*************************")
\r
466 def vfModuleId = ""
\r
467 ApplicationControllerClient aCC = new ApplicationControllerClient();
\r
468 def status = aCC.runCommand("HealthCheck",vfModuleId)
\r