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.camunda.bpm.engine.delegate.BpmnError
26 import org.camunda.bpm.engine.delegate.DelegateExecution
27 import org.onap.aai.domain.yang.VolumeGroup
28 import org.onap.aaiclient.client.aai.AAIObjectType
29 import org.onap.aaiclient.client.aai.entities.AAIResultWrapper
30 import org.onap.aaiclient.client.aai.entities.Relationships
31 import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri
32 import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory
33 import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder
34 import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types
35 import org.onap.logging.filter.base.ErrorCode
36 import org.onap.so.constants.Defaults
37 import org.onap.so.logger.LoggingAnchor
38 import org.onap.so.logger.MessageEnum
39 import org.slf4j.Logger
40 import org.slf4j.LoggerFactory
43 * Vnf Module Subflow for confirming the volume group belongs
47 * @param volumeGroupId
50 class ConfirmVolumeGroupTenant extends AbstractServiceTaskProcessor{
51 private static final Logger logger = LoggerFactory.getLogger( ConfirmVolumeGroupTenant.class);
54 ExceptionUtil exceptionUtil = new ExceptionUtil()
56 public void preProcessRequest(DelegateExecution execution){
57 execution.setVariable("prefix", Prefix)
58 logger.trace("STARTED Confirm Volume Group Tenant Subflow ")
60 logger.trace("Started QueryAAIForVolumeGroup Process ")
62 String volumeGroupId = execution.getVariable("volumeGroupId")
63 String incomingGroupName = execution.getVariable("volumeGroupName")
64 String incomingTenantId = execution.getVariable("tenantId")
65 String aicCloudRegion = execution.getVariable("aicCloudRegion")
66 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.cloudInfrastructure().cloudRegion(Defaults.CLOUD_OWNER.toString(), aicCloudRegion).volumeGroup(volumeGroupId))
67 AAIResultWrapper wrapper = getAAIClient().get(uri);
68 Optional<VolumeGroup> volumeGroup = wrapper.asBean(VolumeGroup.class)
69 Optional<Relationships> relationships = wrapper.getRelationships()
70 if(volumeGroup.isPresent()){
71 execution.setVariable("queryAAIVolumeGroupResponse", volumeGroup.get())
72 String volumeGroupTenantId = ""
73 if(relationships.isPresent()){
74 List<AAIResourceUri> tenantUris = relationships.get().getRelatedUris(Types.TENANT)
75 for (AAIResourceUri tenantURI: tenantUris){
76 volumeGroupTenantId = tenantURI.getURIKeys().get(AAIFluentTypeBuilder.Types.TENANT.getUriParams().tenantId)
79 //Determine if Tenant Ids match
80 if(incomingTenantId.equals(volumeGroupTenantId)){
81 logger.debug("Tenant Ids Match")
82 execution.setVariable("tenantIdsMatch", true)
84 logger.debug("Tenant Ids DO NOT Match")
85 execution.setVariable("tenantIdsMatch", false)
88 //Determine if Volume Group Names match
89 String volumeGroupName = volumeGroup.get().getVolumeGroupName()
90 if(incomingGroupName == null || incomingGroupName.length() < 1){
91 logger.debug("Incoming Volume Group Name is NOT Provided.")
92 execution.setVariable("groupNamesMatch", true)
94 logger.debug("Incoming Volume Group Name is: " + incomingGroupName)
95 if(volumeGroupName.equals(incomingGroupName)){
96 logger.debug("Volume Group Names Match.")
97 execution.setVariable("groupNamesMatch", true)
99 logger.debug("Volume Group Names DO NOT Match.")
100 execution.setVariable("groupNamesMatch", false)
104 logger.debug("QueryAAIForVolumeGroup Bad REST Response!")
105 exceptionUtil.buildAndThrowWorkflowException(execution, 1, "Error Searching AAI for Volume Group. Received a Bad Response.")
111 logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
112 "Exception Occured Processing queryAAIForVolumeGroup.", "BPMN",
113 ErrorCode.UnknownError.getValue(), e.getMessage());
114 exceptionUtil.buildAndThrowWorkflowException(execution, 5000, "Internal Error - Occured in preProcessRequest.")
116 logger.trace("COMPLETED queryAAIForVolumeGroup Process ")
119 public void assignVolumeHeatId(DelegateExecution execution){
120 execution.setVariable("prefix", Prefix)
122 logger.trace("Started assignVolumeHeatId Process ")
124 VolumeGroup volumeGroup = execution.getVariable("queryAAIVolumeGroupResponse")
125 String heatStackId = volumeGroup.getHeatStackId()
126 execution.setVariable("volumeHeatStackId", heatStackId)
127 execution.setVariable("ConfirmVolumeGroupTenantResponse", heatStackId)
128 // TODO: Should deprecate use of processKey+Response variable for the response. Will use "WorkflowResponse" instead
129 execution.setVariable("WorkflowResponse", heatStackId)
130 logger.debug("Volume Heat Stack Id is: " + heatStackId)
133 logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
134 "Exception Occured Processing assignVolumeHeatId.", "BPMN",
135 ErrorCode.UnknownError.getValue(), e);
136 exceptionUtil.buildAndThrowWorkflowException(execution, 5000, "Internal Error - Occured in assignVolumeHeatId.")
138 logger.trace("COMPLETED assignVolumeHeatId Process ")
139 logger.trace("COMPLETED Confirm Volume Group Tenant Subflow ")
142 public void assignWorkflowException(DelegateExecution execution, String message){
143 execution.setVariable("prefix", Prefix)
144 String processKey = getProcessKey(execution);
145 logger.trace("STARTED Assign Workflow Exception ")
147 String volumeGroupId = execution.getVariable("volumeGroupId")
149 String errorMessage = "Volume Group " + volumeGroupId + " " + message
151 exceptionUtil.buildWorkflowException(execution, errorCode, errorMessage)
153 logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
154 "Exception Occured Processing assignWorkflowException.", "BPMN",
155 ErrorCode.UnknownError.getValue(), e);
157 logger.trace("COMPLETED Assign Workflow Exception =")