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
23 import org.camunda.bpm.engine.delegate.BpmnError
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.AAIResultWrapper
28 import org.onap.so.client.aai.entities.Relationships
29 import org.onap.so.client.aai.entities.uri.AAIResourceUri
30 import org.onap.so.client.aai.entities.uri.AAIUriFactory
31 import org.onap.so.constants.Defaults
32 import org.onap.so.logger.MessageEnum
33 import org.onap.so.logger.MsoLogger
36 * Vnf Module Subflow for confirming the volume group belongs
40 * @param volumeGroupId
43 class ConfirmVolumeGroupTenant extends AbstractServiceTaskProcessor{
44 private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, ConfirmVolumeGroupTenant.class);
47 ExceptionUtil exceptionUtil = new ExceptionUtil()
49 public void preProcessRequest(DelegateExecution execution){
50 execution.setVariable("prefix", Prefix)
51 msoLogger.trace("STARTED Confirm Volume Group Tenant Subflow ")
53 msoLogger.trace("Started QueryAAIForVolumeGroup Process ")
55 String volumeGroupId = execution.getVariable("volumeGroupId")
56 String incomingGroupName = execution.getVariable("volumeGroupName")
57 String incomingTenantId = execution.getVariable("tenantId")
58 String aicCloudRegion = execution.getVariable("aicCloudRegion")
59 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.VOLUME_GROUP, Defaults.CLOUD_OWNER.toString(), aicCloudRegion, volumeGroupId)
60 AAIResultWrapper wrapper = getAAIClient().get(uri);
61 Optional<VolumeGroup> volumeGroup = wrapper.asBean(VolumeGroup.class)
62 Optional<Relationships> relationships = wrapper.getRelationships()
63 if(volumeGroup.isPresent()){
64 execution.setVariable("queryAAIVolumeGroupResponse", volumeGroup.get())
65 String volumeGroupTenantId = ""
66 if(relationships.isPresent()){
67 List<AAIResourceUri> tenantUris = relationships.get().getRelatedAAIUris(AAIObjectType.TENANT)
68 for (AAIResourceUri tenantURI: tenantUris){
69 volumeGroupTenantId = tenantURI.getURIKeys().get("tenant-id")
72 //Determine if Tenant Ids match
73 if(incomingTenantId.equals(volumeGroupTenantId)){
74 msoLogger.debug("Tenant Ids Match")
75 execution.setVariable("tenantIdsMatch", true)
77 msoLogger.debug("Tenant Ids DO NOT Match")
78 execution.setVariable("tenantIdsMatch", false)
81 //Determine if Volume Group Names match
82 String volumeGroupName = volumeGroup.get().getVolumeGroupName()
83 if(incomingGroupName == null || incomingGroupName.length() < 1){
84 msoLogger.debug("Incoming Volume Group Name is NOT Provided.")
85 execution.setVariable("groupNamesMatch", true)
87 msoLogger.debug("Incoming Volume Group Name is: " + incomingGroupName)
88 if(volumeGroupName.equals(incomingGroupName)){
89 msoLogger.debug("Volume Group Names Match.")
90 execution.setVariable("groupNamesMatch", true)
92 msoLogger.debug("Volume Group Names DO NOT Match.")
93 execution.setVariable("groupNamesMatch", false)
97 msoLogger.debug("QueryAAIForVolumeGroup Bad REST Response!")
98 exceptionUtil.buildAndThrowWorkflowException(execution, 1, "Error Searching AAI for Volume Group. Received a Bad Response.")
104 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception Occured Processing queryAAIForVolumeGroup.", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, e.getMessage());
105 exceptionUtil.buildAndThrowWorkflowException(execution, 5000, "Internal Error - Occured in preProcessRequest.")
107 msoLogger.trace("COMPLETED queryAAIForVolumeGroup Process ")
110 public void assignVolumeHeatId(DelegateExecution execution){
111 execution.setVariable("prefix", Prefix)
113 msoLogger.trace("Started assignVolumeHeatId Process ")
115 VolumeGroup volumeGroup = execution.getVariable("queryAAIVolumeGroupResponse")
116 String heatStackId = volumeGroup.getHeatStackId()
117 execution.setVariable("volumeHeatStackId", heatStackId)
118 execution.setVariable("ConfirmVolumeGroupTenantResponse", heatStackId)
119 // TODO: Should deprecate use of processKey+Response variable for the response. Will use "WorkflowResponse" instead
120 execution.setVariable("WorkflowResponse", heatStackId)
121 msoLogger.debug("Volume Heat Stack Id is: " + heatStackId)
124 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception Occured Processing assignVolumeHeatId.", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, e);
125 exceptionUtil.buildAndThrowWorkflowException(execution, 5000, "Internal Error - Occured in assignVolumeHeatId.")
127 msoLogger.trace("COMPLETED assignVolumeHeatId Process ")
128 msoLogger.trace("COMPLETED Confirm Volume Group Tenant Subflow ")
131 public void assignWorkflowException(DelegateExecution execution, String message){
132 execution.setVariable("prefix", Prefix)
133 String processKey = getProcessKey(execution);
134 msoLogger.trace("STARTED Assign Workflow Exception ")
136 String volumeGroupId = execution.getVariable("volumeGroupId")
138 String errorMessage = "Volume Group " + volumeGroupId + " " + message
140 exceptionUtil.buildWorkflowException(execution, errorCode, errorMessage)
142 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception Occured Processing assignWorkflowException.", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, e);
144 msoLogger.trace("COMPLETED Assign Workflow Exception =")