2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Modifications Copyright (c) 2019 Samsung
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=========================================================
23 package org.onap.so.bpmn.common.scripts
25 import org.onap.so.logger.LoggingAnchor
26 import org.camunda.bpm.engine.delegate.BpmnError
27 import org.camunda.bpm.engine.delegate.DelegateExecution
28 import org.onap.aai.domain.yang.VolumeGroup
29 import org.onap.so.client.aai.AAIObjectType
30 import org.onap.so.client.aai.entities.AAIResultWrapper
31 import org.onap.so.client.aai.entities.Relationships
32 import org.onap.so.client.aai.entities.uri.AAIResourceUri
33 import org.onap.so.client.aai.entities.uri.AAIUriFactory
34 import org.onap.so.constants.Defaults
35 import org.onap.so.logger.ErrorCode
36 import org.onap.so.logger.MessageEnum
37 import org.slf4j.Logger
38 import org.slf4j.LoggerFactory
41 * Vnf Module Subflow for confirming the volume group belongs
45 * @param volumeGroupId
48 class ConfirmVolumeGroupTenant extends AbstractServiceTaskProcessor{
49 private static final Logger logger = LoggerFactory.getLogger( ConfirmVolumeGroupTenant.class);
52 ExceptionUtil exceptionUtil = new ExceptionUtil()
54 public void preProcessRequest(DelegateExecution execution){
55 execution.setVariable("prefix", Prefix)
56 logger.trace("STARTED Confirm Volume Group Tenant Subflow ")
58 logger.trace("Started QueryAAIForVolumeGroup Process ")
60 String volumeGroupId = execution.getVariable("volumeGroupId")
61 String incomingGroupName = execution.getVariable("volumeGroupName")
62 String incomingTenantId = execution.getVariable("tenantId")
63 String aicCloudRegion = execution.getVariable("aicCloudRegion")
64 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.VOLUME_GROUP, Defaults.CLOUD_OWNER.toString(), aicCloudRegion, volumeGroupId)
65 AAIResultWrapper wrapper = getAAIClient().get(uri);
66 Optional<VolumeGroup> volumeGroup = wrapper.asBean(VolumeGroup.class)
67 Optional<Relationships> relationships = wrapper.getRelationships()
68 if(volumeGroup.isPresent()){
69 execution.setVariable("queryAAIVolumeGroupResponse", volumeGroup.get())
70 String volumeGroupTenantId = ""
71 if(relationships.isPresent()){
72 List<AAIResourceUri> tenantUris = relationships.get().getRelatedAAIUris(AAIObjectType.TENANT)
73 for (AAIResourceUri tenantURI: tenantUris){
74 volumeGroupTenantId = tenantURI.getURIKeys().get("tenant-id")
77 //Determine if Tenant Ids match
78 if(incomingTenantId.equals(volumeGroupTenantId)){
79 logger.debug("Tenant Ids Match")
80 execution.setVariable("tenantIdsMatch", true)
82 logger.debug("Tenant Ids DO NOT Match")
83 execution.setVariable("tenantIdsMatch", false)
86 //Determine if Volume Group Names match
87 String volumeGroupName = volumeGroup.get().getVolumeGroupName()
88 if(incomingGroupName == null || incomingGroupName.length() < 1){
89 logger.debug("Incoming Volume Group Name is NOT Provided.")
90 execution.setVariable("groupNamesMatch", true)
92 logger.debug("Incoming Volume Group Name is: " + incomingGroupName)
93 if(volumeGroupName.equals(incomingGroupName)){
94 logger.debug("Volume Group Names Match.")
95 execution.setVariable("groupNamesMatch", true)
97 logger.debug("Volume Group Names DO NOT Match.")
98 execution.setVariable("groupNamesMatch", false)
102 logger.debug("QueryAAIForVolumeGroup Bad REST Response!")
103 exceptionUtil.buildAndThrowWorkflowException(execution, 1, "Error Searching AAI for Volume Group. Received a Bad Response.")
109 logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
110 "Exception Occured Processing queryAAIForVolumeGroup.", "BPMN",
111 ErrorCode.UnknownError.getValue(), e.getMessage());
112 exceptionUtil.buildAndThrowWorkflowException(execution, 5000, "Internal Error - Occured in preProcessRequest.")
114 logger.trace("COMPLETED queryAAIForVolumeGroup Process ")
117 public void assignVolumeHeatId(DelegateExecution execution){
118 execution.setVariable("prefix", Prefix)
120 logger.trace("Started assignVolumeHeatId Process ")
122 VolumeGroup volumeGroup = execution.getVariable("queryAAIVolumeGroupResponse")
123 String heatStackId = volumeGroup.getHeatStackId()
124 execution.setVariable("volumeHeatStackId", heatStackId)
125 execution.setVariable("ConfirmVolumeGroupTenantResponse", heatStackId)
126 // TODO: Should deprecate use of processKey+Response variable for the response. Will use "WorkflowResponse" instead
127 execution.setVariable("WorkflowResponse", heatStackId)
128 logger.debug("Volume Heat Stack Id is: " + heatStackId)
131 logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
132 "Exception Occured Processing assignVolumeHeatId.", "BPMN",
133 ErrorCode.UnknownError.getValue(), e);
134 exceptionUtil.buildAndThrowWorkflowException(execution, 5000, "Internal Error - Occured in assignVolumeHeatId.")
136 logger.trace("COMPLETED assignVolumeHeatId Process ")
137 logger.trace("COMPLETED Confirm Volume Group Tenant Subflow ")
140 public void assignWorkflowException(DelegateExecution execution, String message){
141 execution.setVariable("prefix", Prefix)
142 String processKey = getProcessKey(execution);
143 logger.trace("STARTED Assign Workflow Exception ")
145 String volumeGroupId = execution.getVariable("volumeGroupId")
147 String errorMessage = "Volume Group " + volumeGroupId + " " + message
149 exceptionUtil.buildWorkflowException(execution, errorCode, errorMessage)
151 logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
152 "Exception Occured Processing assignWorkflowException.", "BPMN",
153 ErrorCode.UnknownError.getValue(), e);
155 logger.trace("COMPLETED Assign Workflow Exception =")