ea0b408e417abe4c635d574c355608684333671c
[so.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.onap.so.bpmn.infrastructure.namingservice.tasks;
22
23 import java.util.List;
24 import java.util.Optional;
25 import org.onap.aai.domain.yang.Zone;
26 import org.onap.so.bpmn.common.BuildingBlockExecution;
27 import org.onap.so.bpmn.common.InjectionHelper;
28 import org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration;
29 import org.onap.so.bpmn.servicedecomposition.bbobjects.InstanceGroup;
30 import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network;
31 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
32 import org.onap.so.bpmn.servicedecomposition.bbobjects.VpnBinding;
33 import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock;
34 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
35 import org.onap.so.bpmn.servicedecomposition.tasks.BBInputSetupUtils;
36 import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
37 import org.onap.so.client.aai.AAIObjectType;
38 import org.onap.so.client.aai.entities.AAIResultWrapper;
39 import org.onap.so.client.aai.entities.Relationships;
40 import org.onap.so.client.aai.entities.uri.AAIResourceUri;
41 import org.onap.so.client.aai.entities.uri.AAIUriFactory;
42 import org.onap.so.client.exception.ExceptionBuilder;
43 import org.onap.so.client.namingservice.NamingRequestObject;
44 import org.onap.so.client.namingservice.NamingServiceConstants;
45 import org.onap.so.client.orchestration.NamingServiceResources;
46 import org.springframework.beans.factory.annotation.Autowired;
47 import org.springframework.stereotype.Component;
48
49 @Component
50 public class NamingServiceCreateTasks {
51
52     @Autowired
53     private ExceptionBuilder exceptionUtil;
54     @Autowired
55     private ExtractPojosForBB extractPojosForBB;
56
57     @Autowired
58     private NamingServiceResources namingServiceResources;
59     @Autowired
60     protected InjectionHelper injectionHelper;
61     @Autowired
62     protected BBInputSetupUtils bbInputSetupUtils;
63
64     public void setBbInputSetupUtils(BBInputSetupUtils bbInputSetupUtils) {
65         this.bbInputSetupUtils = bbInputSetupUtils;
66     }
67
68     public void createInstanceGroupName(BuildingBlockExecution execution) throws Exception {
69         InstanceGroup instanceGroup = extractPojosForBB.extractByKey(execution, ResourceKey.INSTANCE_GROUP_ID);
70         String policyInstanceName = execution.getVariable("policyInstanceName");
71         String nfNamingCode = execution.getVariable("nfNamingCode");
72         String generatedInstanceGroupName = "";
73         try {
74             generatedInstanceGroupName =
75                     namingServiceResources.generateInstanceGroupName(instanceGroup, policyInstanceName, nfNamingCode);
76         } catch (Exception ex) {
77             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
78         }
79         instanceGroup.setInstanceGroupName(generatedInstanceGroupName);
80     }
81
82     public void createWanTransportServiceName(BuildingBlockExecution execution) throws Exception {
83         ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
84         NamingRequestObject namingRequestObject = new NamingRequestObject();
85         namingRequestObject.setExternalKeyValue(serviceInstance.getServiceInstanceId());
86         namingRequestObject.setNamingTypeValue(NamingServiceConstants.NAMING_TYPE_SERVICE);
87         namingRequestObject.setResourceNameValue(NamingServiceConstants.RESOURCE_NAME_SERVICE_INSTANCE_NAME);
88         namingRequestObject.setPolicyInstanceNameValue(serviceInstance.getModelInfoServiceInstance().getNamingPolicy());
89         namingRequestObject.setServiceModelNameValue(serviceInstance.getModelInfoServiceInstance().getModelName());
90         namingRequestObject.setModelVersionValue(serviceInstance.getModelInfoServiceInstance().getModelVersion());
91
92         String generatedWanTransportServiceName = "";
93         try {
94             generatedWanTransportServiceName = namingServiceResources.generateServiceInstanceName(namingRequestObject);
95         } catch (Exception ex) {
96             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
97         }
98         serviceInstance.setServiceInstanceName(generatedWanTransportServiceName);
99     }
100
101     public void createVpnBondingServiceName(BuildingBlockExecution execution) throws Exception {
102         ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
103         L3Network network = extractPojosForBB.extractByKey(execution, ResourceKey.NETWORK_ID);
104         VpnBinding vpnBinding = extractPojosForBB.extractByKey(execution, ResourceKey.VPN_ID);
105         NamingRequestObject namingRequestObject = new NamingRequestObject();
106         namingRequestObject.setExternalKeyValue(serviceInstance.getServiceInstanceId());
107         namingRequestObject.setPolicyInstanceNameValue(serviceInstance.getModelInfoServiceInstance().getNamingPolicy());
108         namingRequestObject.setNamingTypeValue(NamingServiceConstants.NAMING_TYPE_SERVICE);
109         namingRequestObject.setServiceModelNameValue(serviceInstance.getModelInfoServiceInstance().getModelName());
110         namingRequestObject.setModelVersionValue(serviceInstance.getModelInfoServiceInstance().getModelVersion());
111         namingRequestObject.setNetworkNameValue(network.getNetworkName());
112         namingRequestObject.setVpnNameValue(vpnBinding.getVpnName());
113         namingRequestObject.setResourceNameValue(NamingServiceConstants.RESOURCE_NAME_SERVICE_INSTANCE_NAME);
114
115         String generatedVpnBondingServiceName = "";
116         try {
117             generatedVpnBondingServiceName = namingServiceResources.generateServiceInstanceName(namingRequestObject);
118         } catch (Exception ex) {
119             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
120         }
121         serviceInstance.setServiceInstanceName(generatedVpnBondingServiceName);
122     }
123 }