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 org.onap.so.bpmn.common.scripts
22 import javax.ws.rs.core.UriBuilder
24 import org.camunda.bpm.engine.delegate.DelegateExecution
25 import org.onap.aai.domain.yang.VolumeGroup
26 import org.onap.so.client.aai.AAIObjectType
27 import org.onap.so.client.aai.entities.uri.AAIResourceUri
28 import org.onap.so.client.aai.entities.uri.AAIUriFactory
29 import org.onap.so.constants.Defaults
30 import org.onap.so.logger.MessageEnum
31 import org.onap.so.logger.MsoLogger
33 public class ConfirmVolumeGroupName extends AbstractServiceTaskProcessor{
34 private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, ConfirmVolumeGroupName.class);
37 ExceptionUtil exceptionUtil = new ExceptionUtil()
39 public void initProcessVariables(DelegateExecution execution) {
40 execution.setVariable("prefix",Prefix)
41 execution.setVariable("CVGN_volumeGroupId",null)
42 execution.setVariable("CVGN_volumeGroupName",null)
43 execution.setVariable("CVGN_aicCloudRegion", null)
44 execution.setVariable("CVGN_volumeGroupGetEndpoint",null)
46 // ConfirmVolumeGroupName workflow response variable placeholders
47 execution.setVariable("CVGN_volumeGroupNameMatches", false)
48 execution.setVariable("CVGN_queryVolumeGroupResponseCode",null)
49 execution.setVariable("CVGN_queryVolumeGroupResponse","")
50 execution.setVariable("CVGN_ResponseCode",null)
51 execution.setVariable("RollbackData", null)
54 // store the incoming data in the flow DelegateExecution
55 public void preProcessRequest(DelegateExecution execution) {
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 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.VOLUME_GROUP, Defaults.CLOUD_OWNER.toString(), aicCloudRegion, volumeGroupId)
66 execution.setVariable("CVGN_volumeGroupGetEndpoint", uri)
69 // send a GET request to AA&I to retrieve the Volume information based on volume-group-id
70 // expect a 200 response with the information in the response body or a 404 if the volume group id does not exist
71 public void queryAAIForVolumeGroupId(DelegateExecution execution) {
72 AAIResourceUri resourceUri = execution.getVariable("CVGN_volumeGroupGetEndpoint")
75 Optional<VolumeGroup> volumeGroupOp = getAAIClient().get(VolumeGroup.class, resourceUri)
76 if(volumeGroupOp.isPresent()){
77 execution.setVariable("CVGN_queryVolumeGroupResponseCode", 200)
78 execution.setVariable("CVGN_queryVolumeGroupResponse", volumeGroupOp.get())
80 execution.setVariable("CVGN_queryVolumeGroupResponseCode", 404)
81 execution.setVariable("CVGN_queryVolumeGroupResponse", "Volume Group not Found!")
83 } catch (Exception ex) {
84 msoLogger.debug("Exception occurred while executing AAI GET:" + ex.getMessage())
85 execution.setVariable("CVGN_queryVolumeGroupResponseCode", 500)
86 execution.setVariable("CVGN_queryVolumeGroupResponse", "AAI GET Failed:" + ex.getMessage())
87 exceptionUtil.buildAndThrowWorkflowException(execution, 500, "AAI GET Failed")
91 // process the result from queryAAIVolumeGroupId()
93 public void checkAAIQueryResult(DelegateExecution execution) {
94 def result = execution.getVariable("CVGN_queryVolumeGroupResponse")
96 def actualVolumeGroupName = ""
97 if (execution.getVariable("CVGN_queryVolumeGroupResponseCode") == 404) {
98 msoLogger.debug('volumeGroupId does not exist in AAI')
100 else if (execution.getVariable("CVGN_queryVolumeGroupResponseCode") == 200) {
101 VolumeGroup volumeGroup = execution.getVariable("CVGN_queryVolumeGroupResponse")
102 if(volumeGroup.getVolumeGroupName()!=null){
103 actualVolumeGroupName = volumeGroup.getVolumeGroupName()
105 msoLogger.debug("volumeGroupId exists in AAI")
107 execution.setVariable("CVGN_volumeGroupNameMatches", false)
108 def volumeGroupName = execution.getVariable("CVGN_volumeGroupName")
110 if (volumeGroupName.equals(actualVolumeGroupName)) {
111 msoLogger.debug('Volume Group Name Matches AAI records')
112 execution.setVariable("CVGN_volumeGroupNameMatches", true)
117 // generates a WorkflowException if the A&AI query returns a response code other than 200/404
118 public void handleAAIQueryFailure(DelegateExecution execution) {
119 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Error occurred attempting to query AAI, Response Code " + execution.getVariable("CVGN_queryVolumeGroupResponseCode"), "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "ErrorResponse is:\n" + execution.getVariable("CVGN_queryVolumeGroupResponse"));
122 // generates a WorkflowException if the volume group name does not match AAI record for this volume group
123 public void handleVolumeGroupNameNoMatch(DelegateExecution execution) {
124 def errorNotAssociated = "Error occurred - volume group id " + execution.getVariable("CVGN_volumeGroupId") +
125 " is not associated with " + execution.getVariable("CVGN_volumeGroupName")
126 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, errorNotAssociated, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "");
127 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, errorNotAssociated)
130 // sends a successful WorkflowResponse
131 public void reportSuccess(DelegateExecution execution) {
132 msoLogger.debug("Sending 200 back to the caller")
134 execution.setVariable("WorkflowResponse", responseXML)