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 com.att.bpm.scripts
22 import java.io.Serializable;
24 import org.camunda.bpm.engine.runtime.Execution
26 import org.openecomp.mso.rest.APIResponse
27 import org.openecomp.mso.rest.RESTClient
28 import org.openecomp.mso.rest.RESTConfig
29 import org.openecomp.mso.bpmn.core.RollbackData
30 import org.openecomp.mso.bpmn.core.WorkflowException
33 public class ConfirmVolumeGroupName extends AbstractServiceTaskProcessor{
37 public void initProcessVariables(Execution execution) {
38 execution.setVariable("prefix",Prefix)
39 execution.setVariable("CVGN_volumeGroupId",null)
40 execution.setVariable("CVGN_volumeGroupName",null)
41 execution.setVariable("CVGN_aicCloudRegion", null)
42 execution.setVariable("CVGN_volumeGroupGetEndpoint",null)
44 // ConfirmVolumeGroupName workflow response variable placeholders
45 execution.setVariable("CVGN_volumeGroupNameMatches", false)
46 execution.setVariable("CVGN_queryVolumeGroupResponseCode",null)
47 execution.setVariable("CVGN_queryVolumeGroupResponse","")
48 execution.setVariable("CVGN_ResponseCode",null)
49 // execution.setVariable("CVGN_ErrorResponse","")
50 execution.setVariable("RollbackData", null)
53 // store the incoming data in the flow Execution
54 public void preProcessRequest(Execution execution) {
55 def isDebugLogEnabled=execution.getVariable("isDebugLogEnabled")
56 def volumeGroupId = execution.getVariable("ConfirmVolumeGroupName_volumeGroupId")
57 def volumeGroupName= execution.getVariable("ConfirmVolumeGroupName_volumeGroupName")
58 def aicCloudRegion = execution.getVariable("ConfirmVolumeGroupName_aicCloudRegion")
60 initProcessVariables(execution)
61 execution.setVariable("CVGN_volumeGroupId", volumeGroupId)
62 execution.setVariable("CVGN_volumeGroupName", volumeGroupName)
63 execution.setVariable("CVGN_aicCloudRegion", aicCloudRegion)
65 AaiUtil aaiUriUtil = new AaiUtil(this)
66 def aai_uri = aaiUriUtil.getCloudInfrastructureCloudRegionUri(execution)
67 logDebug('AAI URI is: ' + aai_uri, isDebugLogEnabled)
69 execution.setVariable("CVGN_volumeGroupGetEndpoint","${aai_uri}/${aicCloudRegion}/volume-groups/volume-group/" +
73 // send a GET request to AA&I to retrieve the Volume information based on volume-group-id
74 // expect a 200 response with the information in the response body or a 404 if the volume group id does not exist
75 public void queryAAIForVolumeGroupId(Execution execution) {
76 def isDebugLogEnabled=execution.getVariable("isDebugLogEnabled")
77 def endPoint = execution.getVariable("URN_aai_endpoint") + execution.getVariable("CVGN_volumeGroupGetEndpoint")
78 def aaiRequestId = UUID.randomUUID().toString()
80 String basicAuthCred = utils.getBasicAuth(execution.getVariable("URN_aai_auth"),execution.getVariable("URN_mso_msoKey"))
82 RESTConfig config = new RESTConfig(endPoint);
83 utils.log("DEBUG","queryAAIForVolumeGroupId() endpoint-" + endPoint, isDebugLogEnabled)
86 RESTClient client = new RESTClient(config).addHeader("X-TransactionId", aaiRequestId).addHeader("X-FromAppId", "MSO").addHeader("Content-Type", "application/xml").
87 addHeader("Accept","application/xml");
88 if (basicAuthCred != null && !"".equals(basicAuthCred)) {
89 client.addAuthorizationHeader(basicAuthCred)
91 logDebug("invoking GET call to AAI endpoint :"+System.lineSeparator()+endPoint,isDebugLogEnabled)
92 APIResponse response = client.httpGet()
94 responseData = response.getResponseBodyAsString()
95 execution.setVariable("CVGN_queryVolumeGroupResponseCode", response.getStatusCode())
96 execution.setVariable("CVGN_queryVolumeGroupResponse", responseData)
97 logDebug("Response code:" + response.getStatusCode(), isDebugLogEnabled)
98 logDebug("Response:" + System.lineSeparator()+responseData,isDebugLogEnabled)
99 } catch (Exception ex) {
101 logDebug("Exception occurred while executing AAI GET:" + ex.getMessage(),isDebugLogEnabled)
102 execution.setVariable("CVGN_queryVolumeGroupResponseCode", 500)
103 execution.setVariable("CVGN_queryVolumeGroupResponse", "AAI GET Failed:" + ex.getMessage())
107 // process the result from queryAAIVolumeGroupId()
109 public void checkAAIQueryResult(Execution execution) {
110 def isDebugLogEnabled=execution.getVariable("isDebugLogEnabled")
111 def result = execution.getVariable("CVGN_queryVolumeGroupResponse")
113 if (execution.getVariable("CVGN_queryVolumeGroupResponseCode") == 404) {
114 logDebug('volumeGroupId does not exist in AAI', isDebugLogEnabled)
116 else if (execution.getVariable("CVGN_queryVolumeGroupResponseCode") == 200) {
117 logDebug("volumeGroupId exists in AAI", isDebugLogEnabled)
119 def xml = execution.getVariable("CVGN_queryVolumeGroupResponse")
120 def actualVolumeGroupName = ""
121 if (utils.nodeExists(xml, "volume-group-name")) {
122 actualVolumeGroupName = utils.getNodeText(xml, "volume-group-name")
124 execution.setVariable("CVGN_volumeGroupNameMatches", false)
125 def volumeGroupName = execution.getVariable("CVGN_volumeGroupName")
127 if (volumeGroupName.equals(actualVolumeGroupName)) {
128 logDebug('Volume Group Name Matches AAI records', isDebugLogEnabled)
129 execution.setVariable("CVGN_volumeGroupNameMatches", true)
134 // generates a WorkflowException if the A&AI query returns a response code other than 200/404
135 public void handleAAIQueryFailure(Execution execution) {
136 def isDebugLogEnabled=execution.getVariable("isDebugLogEnabled")
138 logError("Error occurred attempting to query AAI, Response Code " +
139 execution.getVariable("CVGN_queryVolumeGroupResponseCode") + ", Error Response " +
140 execution.getVariable("CVGN_queryVolumeGroupResponse"))
141 //String processKey = getProcessKey(execution);
142 //WorkflowException exception = new WorkflowException(processKey, 5000,
143 //execution.getVariable("CVGN_queryVolumeGroupResponse"))
144 //execution.setVariable("WorkflowException", exception)
147 // generates a WorkflowException if the volume group name does not match AAI record for this volume group
148 public void handleVolumeGroupNameNoMatch(Execution execution) {
149 def isDebugLogEnabled=execution.getVariable("isDebugLogEnabled")
151 def errorNotAssociated = "Error occurred - volume group id " + execution.getVariable("CVGN_volumeGroupId") +
152 " is not associated with " + execution.getVariable("CVGN_volumeGroupName")
153 logError(errorNotAssociated)
154 createWorkflowException(execution, 1002, errorNotAssociated)
155 //String processKey = getProcessKey(execution);
156 //WorkflowException exception = new WorkflowException(processKey, 1002,
157 // errorNotAssociated)
158 //execution.setVariable("WorkflowException", exception)
161 // sends a successful WorkflowResponse
162 public void reportSuccess(Execution execution) {
163 def isDebugLogEnabled=execution.getVariable("isDebugLogEnabled")
164 logDebug("Sending 200 back to the caller", isDebugLogEnabled)
166 execution.setVariable("WorkflowResponse", responseXML)