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=========================================================
21 package org.onap.so.bpmn.infrastructure.sdnc.tasks;
24 import javax.ws.rs.core.UriBuilder;
25 import org.onap.sdnc.northbound.client.model.GenericResourceApiNetworkOperationInformation;
26 import org.onap.sdnc.northbound.client.model.GenericResourceApiServiceOperationInformation;
27 import org.onap.sdnc.northbound.client.model.GenericResourceApiVfModuleOperationInformation;
28 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfOperationInformation;
29 import org.onap.so.bpmn.common.BuildingBlockExecution;
30 import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion;
31 import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer;
32 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
33 import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network;
34 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
35 import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule;
36 import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock;
37 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
38 import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext;
39 import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
40 import org.onap.so.client.exception.ExceptionBuilder;
41 import org.onap.so.client.orchestration.SDNCNetworkResources;
42 import org.onap.so.client.orchestration.SDNCServiceInstanceResources;
43 import org.onap.so.client.orchestration.SDNCVfModuleResources;
44 import org.onap.so.client.orchestration.SDNCVnfResources;
45 import org.onap.so.client.sdnc.beans.SDNCRequest;
46 import org.onap.so.client.sdnc.endpoint.SDNCTopology;
47 import org.springframework.beans.factory.annotation.Autowired;
48 import org.springframework.core.env.Environment;
49 import org.springframework.stereotype.Component;
52 public class SDNCChangeAssignTasks {
53 public static final String SDNC_REQUEST = "SDNCRequest";
55 private SDNCNetworkResources sdncNetworkResources;
57 private SDNCServiceInstanceResources sdncServiceInstanceResources;
59 private SDNCVnfResources sdncVnfResources;
61 private ExtractPojosForBB extractPojosForBB;
63 private ExceptionBuilder exceptionUtil;
65 private SDNCVfModuleResources sdncVfModuleResources;
67 private Environment env;
69 public void changeModelServiceInstance(BuildingBlockExecution execution) {
71 GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock();
72 ServiceInstance serviceInstance =
73 extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
74 GenericResourceApiServiceOperationInformation req = sdncServiceInstanceResources
75 .changeModelServiceInstance(serviceInstance, gBBInput.getCustomer(), gBBInput.getRequestContext());
76 SDNCRequest sdncRequest = new SDNCRequest();
77 sdncRequest.setSDNCPayload(req);
78 sdncRequest.setTopology(SDNCTopology.SERVICE);
79 execution.setVariable(SDNC_REQUEST, sdncRequest);
80 } catch (Exception ex) {
81 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
85 public void changeModelVnf(BuildingBlockExecution execution) {
87 GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock();
88 GenericVnf genericVnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
89 ServiceInstance serviceInstance =
90 extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
91 GenericResourceApiVnfOperationInformation req = sdncVnfResources.changeModelVnf(genericVnf, serviceInstance,
92 gBBInput.getCustomer(), gBBInput.getCloudRegion(), gBBInput.getRequestContext());
93 SDNCRequest sdncRequest = new SDNCRequest();
94 sdncRequest.setSDNCPayload(req);
95 sdncRequest.setTopology(SDNCTopology.VNF);
96 execution.setVariable(SDNC_REQUEST, sdncRequest);
97 } catch (Exception ex) {
98 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
102 public void changeAssignNetwork(BuildingBlockExecution execution) {
104 GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock();
105 L3Network network = extractPojosForBB.extractByKey(execution, ResourceKey.NETWORK_ID);
106 ServiceInstance serviceInstance =
107 extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
108 GenericResourceApiNetworkOperationInformation req = sdncNetworkResources.changeAssignNetwork(network,
109 serviceInstance, gBBInput.getCustomer(), gBBInput.getRequestContext(), gBBInput.getCloudRegion());
110 SDNCRequest sdncRequest = new SDNCRequest();
111 sdncRequest.setSDNCPayload(req);
112 sdncRequest.setTopology(SDNCTopology.NETWORK);
113 execution.setVariable(SDNC_REQUEST, sdncRequest);
114 } catch (Exception ex) {
115 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
119 public void changeAssignModelVfModule(BuildingBlockExecution execution) throws Exception {
121 GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock();
122 RequestContext requestContext = gBBInput.getRequestContext();
123 CloudRegion cloudRegion = gBBInput.getCloudRegion();
124 ServiceInstance serviceInstance =
125 extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
126 GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
127 VfModule vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID);
128 Customer customer = gBBInput.getCustomer();
129 SDNCRequest sdncRequest = new SDNCRequest();
130 UriBuilder builder = UriBuilder.fromPath(env.getRequiredProperty("mso.workflow.message.endpoint"))
131 .path(sdncRequest.getCorrelationName()).path(sdncRequest.getCorrelationValue());
132 URI uri = builder.build();
133 GenericResourceApiVfModuleOperationInformation req = sdncVfModuleResources.changeAssignVfModule(vfModule,
134 vnf, serviceInstance, customer, cloudRegion, requestContext, uri);
135 sdncRequest.setSDNCPayload(req);
136 sdncRequest.setTopology(SDNCTopology.VFMODULE);
137 execution.setVariable(SDNC_REQUEST, sdncRequest);
138 } catch (Exception ex) {
139 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);