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