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=========================================================
20 package org.onap.so.bpmn.infrastructure.flowspecific.tasks;
22 import org.onap.so.bpmn.common.BuildingBlockExecution;
23 import org.onap.so.bpmn.servicedecomposition.bbobjects.Collection;
24 import org.onap.so.bpmn.servicedecomposition.bbobjects.InstanceGroup;
25 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
26 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
27 import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
28 import org.onap.so.client.exception.ExceptionBuilder;
29 import org.onap.so.client.orchestration.AAINetworkResources;
30 import org.onap.so.logger.MsoLogger;
31 import org.springframework.beans.factory.annotation.Autowired;
32 import org.springframework.stereotype.Component;
35 public class CreateNetworkCollection {
36 private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, CreateNetworkCollection.class);
38 private ExceptionBuilder exceptionUtil;
40 private ExtractPojosForBB extractPojosForBB;
42 private AAINetworkResources aaiNetworkResources;
44 private static final String UNDERSCORE = "_";
45 private static final String NETWORK_COLLECTION_NAME = "networkCollectionName";
48 * BPMN access method to build Network Collection Name
52 public void buildNetworkCollectionName(BuildingBlockExecution execution) throws Exception {
54 ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID, execution.getLookupMap().get(ResourceKey.SERVICE_INSTANCE_ID));
55 InstanceGroup instanceGroup = serviceInstance.getCollection().getInstanceGroup();
56 if(instanceGroup.getModelInfoInstanceGroup() != null) {
57 //Build collection name assembling SI name and IG function
58 if(serviceInstance.getServiceInstanceName() != null
59 && instanceGroup.getModelInfoInstanceGroup().getFunction() != null) {
60 String networkCollectionName = serviceInstance.getServiceInstanceName().concat(UNDERSCORE).concat(instanceGroup.getModelInfoInstanceGroup().getFunction());
61 //set networkCollectionName object on execution to be re-used within current BB
62 execution.setVariable(NETWORK_COLLECTION_NAME, networkCollectionName);
64 throw new IllegalArgumentException("Cannot generate collection name because either one or both fields are null: "
65 + " Service Instance Name: " + serviceInstance.getServiceInstanceName()
66 + ", Instance Group Function: " + instanceGroup.getModelInfoInstanceGroup().getFunction());
69 throw new IllegalArgumentException("Instance group model info is null");
71 } catch (Exception ex) {
72 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
77 * BPMN access method to connect Network Collection
81 public void connectCollectionToInstanceGroup(BuildingBlockExecution execution) throws Exception {
82 execution.setVariable("connectCollectionToInstanceGroupRollback", false);
84 ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID, execution.getLookupMap().get(ResourceKey.SERVICE_INSTANCE_ID));
85 Collection networkCollection = serviceInstance.getCollection();
86 aaiNetworkResources.connectNetworkCollectionInstanceGroupToNetworkCollection(networkCollection.getInstanceGroup(), networkCollection);
87 execution.setVariable("connectCollectionToInstanceGroupRollback", true);
88 } catch (Exception ex) {
89 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
94 * BPMN access method to connect Network Collection
98 public void connectCollectionToServiceInstance(BuildingBlockExecution execution) throws Exception {
99 execution.setVariable("connectCollectionToServiceInstanceRollback", false);
101 ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID, execution.getLookupMap().get(ResourceKey.SERVICE_INSTANCE_ID));
102 Collection networkCollection = serviceInstance.getCollection();
103 aaiNetworkResources.connectNetworkCollectionToServiceInstance(networkCollection, serviceInstance);
104 execution.setVariable("connectCollectionToServiceInstanceRollback", true);
105 } catch (Exception ex) {
106 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);