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=========================================================
22 package org.onap.so.bpmn.infrastructure.flowspecific.tasks;
24 import org.onap.so.bpmn.common.BuildingBlockExecution;
25 import org.onap.so.bpmn.servicedecomposition.bbobjects.Collection;
26 import org.onap.so.bpmn.servicedecomposition.bbobjects.InstanceGroup;
27 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
28 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
29 import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
30 import org.onap.so.client.exception.ExceptionBuilder;
31 import org.onap.so.client.orchestration.AAINetworkResources;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
34 import org.springframework.beans.factory.annotation.Autowired;
35 import org.springframework.stereotype.Component;
38 public class CreateNetworkCollection {
41 private ExceptionBuilder exceptionUtil;
43 private ExtractPojosForBB extractPojosForBB;
45 private AAINetworkResources aaiNetworkResources;
47 private static final String UNDERSCORE = "_";
48 private static final String NETWORK_COLLECTION_NAME = "networkCollectionName";
51 * BPMN access method to build Network Collection Name
56 public void buildNetworkCollectionName(BuildingBlockExecution execution) throws Exception {
58 ServiceInstance serviceInstance =
59 extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
60 InstanceGroup instanceGroup = serviceInstance.getCollection().getInstanceGroup();
61 if (instanceGroup.getModelInfoInstanceGroup() != null) {
62 // Build collection name assembling SI name and IG function
63 if (serviceInstance.getServiceInstanceName() != null
64 && instanceGroup.getModelInfoInstanceGroup().getFunction() != null) {
65 String networkCollectionName = serviceInstance.getServiceInstanceName().concat(UNDERSCORE)
66 .concat(instanceGroup.getModelInfoInstanceGroup().getFunction());
67 // set networkCollectionName object on execution to be re-used within current BB
68 execution.setVariable(NETWORK_COLLECTION_NAME, networkCollectionName);
70 throw new IllegalArgumentException(
71 "Cannot generate collection name because either one or both fields are null: "
72 + " Service Instance Name: " + serviceInstance.getServiceInstanceName()
73 + ", Instance Group Function: "
74 + instanceGroup.getModelInfoInstanceGroup().getFunction());
77 throw new IllegalArgumentException("Instance group model info is null");
79 } catch (Exception ex) {
80 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
85 * BPMN access method to connect Network Collection
90 public void connectCollectionToInstanceGroup(BuildingBlockExecution execution) throws Exception {
91 execution.setVariable("connectCollectionToInstanceGroupRollback", false);
93 ServiceInstance serviceInstance =
94 extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
95 Collection networkCollection = serviceInstance.getCollection();
96 aaiNetworkResources.connectNetworkCollectionInstanceGroupToNetworkCollection(
97 networkCollection.getInstanceGroup(), networkCollection);
98 execution.setVariable("connectCollectionToInstanceGroupRollback", true);
99 } catch (Exception ex) {
100 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
105 * BPMN access method to connect Instance Group to Cloud Region
110 public void connectInstanceGroupToCloudRegion(BuildingBlockExecution execution) throws Exception {
111 execution.setVariable("connectInstanceGroupToCloudRegionRollback", false);
113 ServiceInstance serviceInstance =
114 extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
115 Collection networkCollection = serviceInstance.getCollection();
116 aaiNetworkResources.connectInstanceGroupToCloudRegion(networkCollection.getInstanceGroup(),
117 execution.getGeneralBuildingBlock().getCloudRegion());
118 execution.setVariable("connectInstanceGroupToCloudRegionRollback", true);
119 } catch (Exception ex) {
120 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
125 * BPMN access method to connect Network Collection
130 public void connectCollectionToServiceInstance(BuildingBlockExecution execution) throws Exception {
131 execution.setVariable("connectCollectionToServiceInstanceRollback", false);
133 ServiceInstance serviceInstance =
134 extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
135 Collection networkCollection = serviceInstance.getCollection();
136 aaiNetworkResources.connectNetworkCollectionToServiceInstance(networkCollection, serviceInstance);
137 execution.setVariable("connectCollectionToServiceInstanceRollback", true);
138 } catch (Exception ex) {
139 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);