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
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 * ============LICENSE_END=========================================================
20 package org.openecomp.mso.bpmn.infrastructure.scripts
22 import groovy.json.JsonOutput
23 import groovy.json.JsonSlurper
24 import groovy.util.Node
25 import groovy.util.XmlParser;
26 import groovy.xml.QName
28 import java.io.Serializable;
29 import java.util.UUID;
30 import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil
31 import org.camunda.bpm.engine.delegate.BpmnError
32 import org.camunda.bpm.engine.impl.cmd.AbstractSetVariableCmd
33 import org.camunda.bpm.engine.delegate.DelegateExecution
34 import org.openecomp.mso.rest.APIResponse
35 import org.openecomp.mso.rest.RESTClient
36 import org.openecomp.mso.rest.RESTConfig
37 import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor;
38 import org.openecomp.mso.bpmn.common.scripts.VidUtils;
39 import org.openecomp.mso.bpmn.core.RollbackData
40 import org.openecomp.mso.bpmn.core.WorkflowException
41 import org.openecomp.mso.bpmn.core.json.JsonUtils
42 import org.openecomp.mso.bpmn.core.domain.ModelInfo
43 import org.openecomp.mso.bpmn.core.domain.ServiceDecomposition
44 import org.openecomp.mso.bpmn.core.domain.VnfResource
45 import org.openecomp.mso.client.aai.*
47 import org.openecomp.mso.client.appc.ApplicationControllerClient;
48 import org.openecomp.mso.client.appc.ApplicationControllerSupport;
49 import org.openecomp.mso.client.aai.AAIResourcesClient
50 import org.openecomp.mso.client.aai.entities.AAIResultWrapper
51 import org.openecomp.mso.client.aai.entities.uri.AAIUri
52 import org.openecomp.mso.client.aai.entities.uri.AAIUriFactory
53 import org.onap.appc.client.lcm.model.Action;
54 import org.onap.appc.client.lcm.model.ActionIdentifiers;
55 import org.onap.appc.client.lcm.model.LockInput
56 import org.onap.appc.client.lcm.model.UnlockInput
57 import org.onap.appc.client.lcm.model.HealthCheckInput
58 import org.onap.appc.client.lcm.model.StartInput
59 import org.onap.appc.client.lcm.model.StopInput
60 import org.onap.appc.client.lcm.model.Flags
61 import org.onap.appc.client.lcm.model.Status
64 public class VnfConfigUpdate extends VnfCmBase {
66 ExceptionUtil exceptionUtil = new ExceptionUtil()
67 JsonUtils jsonUtils = new JsonUtils()
68 def prefix = "VnfIPU_"
71 * Initialize the flow's variables.
73 * @param execution The flow's execution instance.
75 public void initProcessVariables(DelegateExecution execution) {
76 execution.setVariable('prefix', 'VnfCU_')
77 execution.setVariable('Request', null)
78 execution.setVariable('source', null)
79 execution.setVariable('UpdateVnfSuccessIndicator', false)
80 execution.setVariable('serviceType', null)
81 execution.setVariable('nfRole', null)
82 execution.setVariable('currentActivity', 'VnfCU')
83 execution.setVariable('workStep', null)
84 execution.setVariable('failedActivity', null)
85 execution.setVariable('errorCode', "0")
86 execution.setVariable('errorText', null)
87 execution.setVariable('healthCheckIndex0', 0)
88 execution.setVariable('healthCheckIndex1', 1)
89 execution.setVariable('maxRetryCount', 3)
90 execution.setVariable('retryCount', 0)
91 execution.setVariable("lcpCloudRegionId", null)
92 execution.setVariable("rollbackSetClosedLoopDisabledFlag", false)
93 execution.setVariable("rollbackVnfStop", false)
94 execution.setVariable("rollbackVnfLock", false)
95 execution.setVariable("rollbackQuiesceTraffic", false)
96 execution.setVariable("rollbackSetVnfInMaintenanceFlag", false)
100 * Check for missing elements in the received request.
102 * @param execution The flow's execution instance.
104 public void preProcessRequest(DelegateExecution execution) {
105 def method = getClass().getSimpleName() + '.preProcessRequest(' +
106 'execution=' + execution.getId() +
108 initProcessVariables(execution)
109 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
110 logDebug('Entered ' + method, isDebugLogEnabled)
112 initProcessVariables(execution)
114 def incomingRequest = execution.getVariable('bpmnRequest')
116 utils.log("DEBUG", "Incoming Infra Request: " + incomingRequest, isDebugLogEnabled)
118 def jsonSlurper = new JsonSlurper()
119 def jsonOutput = new JsonOutput()
120 Map reqMap = jsonSlurper.parseText(incomingRequest)
121 utils.log("DEBUG", " Request is in JSON format.", isDebugLogEnabled)
123 def serviceInstanceId = execution.getVariable('serviceInstanceId')
124 def vnfId = execution.getVariable('vnfId')
126 execution.setVariable('serviceInstanceId', serviceInstanceId)
127 execution.setVariable('vnfId', vnfId)
128 execution.setVariable('serviceType', 'Mobility')
129 execution.setVariable('payload', "")
130 execution.setVariable('actionHealthCheck', Action.HealthCheck)
131 execution.setVariable('actionConfigModify', Action.ConfigModify)
133 def payload = reqMap.requestDetails?.requestParameters?.payload
134 execution.setVariable('payload', payload)
136 utils.log("DEBUG", 'Processed payload: ' + payload, isDebugLogEnabled)
138 def requestId = execution.getVariable("mso-request-id")
139 execution.setVariable('requestId', requestId)
140 execution.setVariable('msoRequestId', requestId)
142 def requestorId = reqMap.requestDetails?.requestInfo?.requestorId ?: null
143 execution.setVariable('requestorId', requestorId)
145 execution.setVariable('sdncVersion', '1702')
147 execution.setVariable("UpdateVnfInfraSuccessIndicator", false)
149 execution.setVariable("isDebugLogEnabled", isDebugLogEnabled)
151 def source = reqMap.requestDetails?.requestInfo?.source
152 execution.setVariable("source", source)
154 //For Completion Handler & Fallout Handler
156 """<request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">
157 <request-id>${requestId}</request-id>
158 <action>UPDATE</action>
159 <source>${source}</source>
162 execution.setVariable("requestInfo", requestInfo)
164 logDebug('RequestInfo: ' + execution.getVariable("requestInfo"), isDebugLogEnabled)
166 logDebug('Exited ' + method, isDebugLogEnabled)
169 catch(groovy.json.JsonException je) {
170 utils.log("DEBUG", " Request is not in JSON format.", isDebugLogEnabled)
171 exceptionUtil.buildAndThrowWorkflowException(execution, 5000, "Invalid request format")
175 String restFaultMessage = e.getMessage()
176 utils.log("ERROR", " Exception Encountered - " + "\n" + restFaultMessage, isDebugLogEnabled)
177 exceptionUtil.buildAndThrowWorkflowException(execution, 5000, restFaultMessage)
182 * Prepare and send the sychronous response for this flow.
184 * @param execution The flow's execution instance.
186 public void sendSynchResponse(DelegateExecution execution) {
187 def method = getClass().getSimpleName() + '.sendSynchResponse(' +
188 'execution=' + execution.getId() +
190 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
191 logDebug('Entered ' + method, isDebugLogEnabled)
195 def requestInfo = execution.getVariable('requestInfo')
196 def requestId = execution.getVariable('requestId')
197 def source = execution.getVariable('source')
198 def progress = getNodeTextForce(requestInfo, 'progress')
199 if (progress.isEmpty()) {
202 def startTime = getNodeTextForce(requestInfo, 'start-time')
203 if (startTime.isEmpty()) {
204 startTime = System.currentTimeMillis()
207 // RESTResponse (for API Handler (APIH) Reply Task)
208 def vnfId = execution.getVariable("vnfId")
209 String synchResponse = """{"requestReferences":{"instanceId":"${vnfId}","requestId":"${requestId}"}}""".trim()
211 sendWorkflowResponse(execution, 200, synchResponse)
213 logDebug('Exited ' + method, isDebugLogEnabled)
214 } catch (BpmnError e) {
216 } catch (Exception e) {
217 logError('Caught exception in ' + method, e)
218 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in sendResponse(): ' + e.getMessage())
224 * Check if this VNF is already in maintenance in A&AI.
227 * @param execution The flow's execution instance.
229 public void checkIfVnfInMaintInAAI(DelegateExecution execution) {
230 def method = getClass().getSimpleName() + '.checkIfVnfInMaintInAAI(' +
231 'execution=' + execution.getId() +
233 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
234 execution.setVariable('errorCode', "0")
235 execution.setVariable("workStep", "checkIfVnfInMaintInAAI")
236 execution.setVariable("failedActivity", "AAI")
237 logDebug('Entered ' + method, isDebugLogEnabled)
240 def transactionLoggingUuid = UUID.randomUUID().toString()
241 AAIRestClientImpl client = new AAIRestClientImpl()
242 AAIValidatorImpl aaiValidator = new AAIValidatorImpl()
243 aaiValidator.setClient(client)
244 def vnfId = execution.getVariable("vnfId")
245 boolean isInMaint = aaiValidator.isVNFLocked(vnfId, transactionLoggingUuid)
246 logDebug("isInMaint result: " + isInMaint, isDebugLogEnabled)
247 execution.setVariable('isVnfInMaintenance', isInMaint)
250 execution.setVariable("errorCode", "1003")
251 execution.setVariable("errorText", "VNF is in maintenance in A&AI")
254 logDebug('Exited ' + method, isDebugLogEnabled)
255 } catch (BpmnError e) {
257 } catch (Exception e) {
258 logError('Caught exception in ' + method, e)
259 execution.setVariable("errorCode", "1002")
260 execution.setVariable("errorText", e.getMessage())
261 //exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in checkIfVnfInMaintInAAI(): ' + e.getMessage())
267 * Check if this VNF's pservers are locked in A&AI.
270 * @param execution The flow's execution instance.
272 public void checkIfPserversInMaintInAAI(DelegateExecution execution) {
273 def method = getClass().getSimpleName() + '.checkIfPserversInMaintInAAI(' +
274 'execution=' + execution.getId() +
276 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
277 execution.setVariable('errorCode', "0")
278 logDebug('Entered ' + method, isDebugLogEnabled)
279 execution.setVariable("workStep", "checkIfPserversInMaintInAAI")
280 execution.setVariable("failedActivity", "AAI")
283 def transactionLoggingUuid = UUID.randomUUID().toString()
284 AAIRestClientImpl client = new AAIRestClientImpl()
285 AAIValidatorImpl aaiValidator = new AAIValidatorImpl()
286 aaiValidator.setClient(client)
287 def vnfId = execution.getVariable("vnfId")
288 boolean areLocked = aaiValidator.isPhysicalServerLocked(vnfId, transactionLoggingUuid)
289 logDebug("areLocked result: " + areLocked, isDebugLogEnabled)
290 execution.setVariable('arePserversLocked', areLocked)
293 execution.setVariable("errorCode", "1003")
294 execution.setVariable("errorText", "pServers are locked in A&AI")
298 logDebug('Exited ' + method, isDebugLogEnabled)
299 } catch (BpmnError e) {
301 } catch (Exception e) {
302 logError('Caught exception in ' + method, e)
303 execution.setVariable("errorCode", "1002")
304 execution.setVariable("errorText", e.getMessage())
305 //exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in checkIfPserversInMaintInAAI(): ' + e.getMessage())
310 * Set inMaint flag for this VNF to the specified value in A&AI.
313 * @param execution The flow's execution instance.
314 * @param inMaint The boolean value of the flag to set
316 public void setVnfInMaintFlagInAAI(DelegateExecution execution, boolean inMaint) {
317 def method = getClass().getSimpleName() + '.setVnfInMaintFlagInAAI(' +
318 'execution=' + execution.getId() +
320 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
321 execution.setVariable('errorCode', "0")
322 logDebug('Entered ' + method, isDebugLogEnabled)
324 execution.setVariable("workStep", "setVnfInMaintFlagInAAI")
325 execution.setVariable("rollbackSetVnfInMaintenanceFlag", true)
328 execution.setVariable("workStep", "unsetVnfInMaintFlagInAAI")
330 execution.setVariable("failedActivity", "AAI")
333 def transactionLoggingUuid = UUID.randomUUID().toString()
334 AAIRestClientImpl client = new AAIRestClientImpl()
335 AAIUpdatorImpl aaiUpdator = new AAIUpdatorImpl()
336 aaiUpdator.setClient(client)
337 def vnfId = execution.getVariable("vnfId")
339 aaiUpdator.updateVnfToLocked(vnfId, transactionLoggingUuid)
340 execution.setVariable("rollbackSetVnfInMaintenanceFlag", true)
343 aaiUpdator.updateVnfToUnLocked(vnfId, transactionLoggingUuid)
346 logDebug('Exited ' + method, isDebugLogEnabled)
347 } catch (BpmnError e) {
349 } catch (Exception e) {
350 logError('Caught exception in ' + method, e)
351 execution.setVariable("errorCode", "1002")
352 execution.setVariable("errorText", e.getMessage())
353 //exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in setVnfInMaintFlagInAAI(): ' + e.getMessage())
358 * Check if VF Closed Loop Disabled in A&AI.
361 * @param execution The flow's execution instance.
363 public void checkIfClosedLoopDisabledInAAI(DelegateExecution execution) {
364 def method = getClass().getSimpleName() + '.checkIfClosedLoopDisabledInAAI(' +
365 'execution=' + execution.getId() +
367 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
368 execution.setVariable('errorCode', "0")
369 execution.setVariable("workStep", "checkClosedLoopDisabledFlagInAAI")
370 execution.setVariable("failedActivity", "AAI")
371 logDebug('Entered ' + method, isDebugLogEnabled)
374 def transactionLoggingUuid = UUID.randomUUID().toString()
375 def vnfId = execution.getVariable("vnfId")
376 logDebug("vnfId is: " + vnfId, isDebugLogEnabled)
377 AAIResourcesClient client = new AAIResourcesClient()
378 AAIUri genericVnfUri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId)
379 AAIResultWrapper aaiRW = client.get(genericVnfUri)
380 Map<String, Object> result = aaiRW.asMap()
381 boolean isClosedLoopDisabled = result.getOrDefault("is-closed-loop-disabled", false)
383 logDebug("isClosedLoopDisabled result: " + isClosedLoopDisabled, isDebugLogEnabled)
384 execution.setVariable('isClosedLoopDisabled', isClosedLoopDisabled)
386 if (isClosedLoopDisabled) {
387 execution.setVariable("errorCode", "1004")
388 execution.setVariable("errorText", "closedLoop is disabled in A&AI")
391 logDebug('Exited ' + method, isDebugLogEnabled)
392 } catch (BpmnError e) {
394 } catch (Exception e) {
395 logError('Caught exception in ' + method, e)
396 execution.setVariable("errorCode", "1002")
397 execution.setVariable("errorText", e.getMessage())
398 //exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in checkIfVnfInMaintInAAI(): ' + e.getMessage())
403 * Set VF Closed Loop Disabled Flag in A&AI.
406 * @param execution The flow's execution instance.
408 public void setClosedLoopDisabledInAAI(DelegateExecution execution, boolean setDisabled) {
409 def method = getClass().getSimpleName() + '.setClosedLoopDisabledInAAI(' +
410 'execution=' + execution.getId() +
412 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
413 execution.setVariable('errorCode', "0")
415 execution.setVariable("workStep", "setClosedLoopDisabledFlagInAAI")
416 execution.setVariable("rollbackSetClosedLoopDisabledFlag", true)
419 execution.setVariable("workStep", "unsetClosedLoopDisabledFlagInAAI")
422 execution.setVariable("failedActivity", "AAI")
423 logDebug('Entered ' + method, isDebugLogEnabled)
426 def transactionLoggingUuid = UUID.randomUUID().toString()
427 def vnfId = execution.getVariable("vnfId")
428 AAIResourcesClient client = new AAIResourcesClient()
429 AAIUri genericVnfUri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId)
431 Map<String, Boolean> request = new HashMap<>()
432 request.put("is-closed-loop-disabled", setDisabled)
433 client.update(genericVnfUri, request)
434 logDebug("set isClosedLoop to: " + setDisabled, isDebugLogEnabled)
437 logDebug('Exited ' + method, isDebugLogEnabled)
438 } catch (BpmnError e) {
440 } catch (Exception e) {
441 logError('Caught exception in ' + method, e)
442 execution.setVariable("errorCode", "1002")
443 execution.setVariable("errorText", e.getMessage())
444 //exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in checkIfVnfInMaintInAAI(): ' + e.getMessage())
450 * Handle Abort disposition from RainyDayHandler
452 * @param execution The flow's execution instance.
454 public void abortProcessing(DelegateExecution execution) {
455 def method = getClass().getSimpleName() + '.abortProcessing(' +
456 'execution=' + execution.getId() +
458 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
459 logDebug('Entered ' + method, isDebugLogEnabled)
461 def errorText = execution.getVariable("errorText")
462 def errorCode = execution.getVariable("errorCode")
464 exceptionUtil.buildAndThrowWorkflowException(execution, errorCode as Integer, errorText)
468 * Increment Retry Count for Current Work Step
470 * @param execution The flow's execution instance.
472 public void incrementRetryCount(DelegateExecution execution) {
473 def method = getClass().getSimpleName() + '.incrementRetryCount(' +
474 'execution=' + execution.getId() +
476 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
477 logDebug('Entered ' + method, isDebugLogEnabled)
479 String retryCountVariableName = execution.getVariable("workStep") + "RetryCount"
480 execution.setVariable("retryCountVariableName", retryCountVariableName)
482 def retryCountVariable = execution.getVariable(retryCountVariableName)
485 if (retryCountVariable != null) {
486 retryCount = (int) retryCountVariable
491 execution.setVariable(retryCountVariableName, retryCount)
493 logDebug("value of " + retryCountVariableName + " is " + retryCount, isDebugLogEnabled)
494 logDebug('Exited ' + method, isDebugLogEnabled)