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 {
39 private static final Logger logger = LoggerFactory.getLogger(CreateNetworkCollection.class);
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
55 public void buildNetworkCollectionName(BuildingBlockExecution execution) throws Exception {
57 ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
58 InstanceGroup instanceGroup = serviceInstance.getCollection().getInstanceGroup();
59 if(instanceGroup.getModelInfoInstanceGroup() != null) {
60 //Build collection name assembling SI name and IG function
61 if(serviceInstance.getServiceInstanceName() != null
62 && instanceGroup.getModelInfoInstanceGroup().getFunction() != null) {
63 String networkCollectionName = serviceInstance.getServiceInstanceName().concat(UNDERSCORE).concat(instanceGroup.getModelInfoInstanceGroup().getFunction());
64 //set networkCollectionName object on execution to be re-used within current BB
65 execution.setVariable(NETWORK_COLLECTION_NAME, networkCollectionName);
67 throw new IllegalArgumentException("Cannot generate collection name because either one or both fields are null: "
68 + " Service Instance Name: " + serviceInstance.getServiceInstanceName()
69 + ", Instance Group Function: " + instanceGroup.getModelInfoInstanceGroup().getFunction());
72 throw new IllegalArgumentException("Instance group model info is null");
74 } catch (Exception ex) {
75 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
80 * BPMN access method to connect Network Collection
84 public void connectCollectionToInstanceGroup(BuildingBlockExecution execution) throws Exception {
85 execution.setVariable("connectCollectionToInstanceGroupRollback", false);
87 ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
88 Collection networkCollection = serviceInstance.getCollection();
89 aaiNetworkResources.connectNetworkCollectionInstanceGroupToNetworkCollection(networkCollection.getInstanceGroup(), networkCollection);
90 execution.setVariable("connectCollectionToInstanceGroupRollback", true);
91 } catch (Exception ex) {
92 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
97 * BPMN access method to connect Instance Group to Cloud Region
101 public void connectInstanceGroupToCloudRegion(BuildingBlockExecution execution) throws Exception {
102 execution.setVariable("connectInstanceGroupToCloudRegionRollback", false);
104 ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
105 Collection networkCollection = serviceInstance.getCollection();
106 aaiNetworkResources.connectInstanceGroupToCloudRegion(networkCollection.getInstanceGroup(), execution.getGeneralBuildingBlock().getCloudRegion());
107 execution.setVariable("connectInstanceGroupToCloudRegionRollback", true);
108 } catch (Exception ex) {
109 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
114 * BPMN access method to connect Network Collection
118 public void connectCollectionToServiceInstance(BuildingBlockExecution execution) throws Exception {
119 execution.setVariable("connectCollectionToServiceInstanceRollback", false);
121 ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
122 Collection networkCollection = serviceInstance.getCollection();
123 aaiNetworkResources.connectNetworkCollectionToServiceInstance(networkCollection, serviceInstance);
124 execution.setVariable("connectCollectionToServiceInstanceRollback", true);
125 } catch (Exception ex) {
126 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);