Containerization feature of SO
[so.git] / bpmn / so-bpmn-tasks / src / main / java / org / onap / so / client / orchestration / SDNCConfigurationResources.java
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.client.orchestration;
22
23
24 import org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration;
25 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
26 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
27 import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext;
28 import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer;
29 import org.onap.so.client.exception.BadResponseException;
30 import org.onap.so.client.exception.MapperException;
31 import org.onap.so.client.sdnc.SDNCClient;
32 import org.onap.so.client.sdnc.beans.SDNCSvcAction;
33 import org.onap.so.client.sdnc.endpoint.SDNCTopology;
34 import org.onap.so.client.sdnc.mapper.GCTopologyOperationRequestMapper;
35 import org.springframework.beans.factory.annotation.Autowired;
36 import org.springframework.stereotype.Component;
37
38 import org.onap.sdnc.apps.client.model.GenericResourceApiGcTopologyOperationInformation;
39 import org.onap.sdnc.apps.client.model.GenericResourceApiRequestActionEnumeration;
40
41 @Component
42 public class SDNCConfigurationResources {
43     @Autowired
44     private GCTopologyOperationRequestMapper sdncRM;
45     
46     @Autowired
47     private SDNCClient sdncClient;
48
49     /**
50      * SDN-C call to assign configuration after it was created in A&AI
51      *
52      * @param serviceInstance
53      * @param requestContext
54      * @param vnrConfiguration
55      * @param voiceVnf
56      * @return
57      * @throws MapperException
58      * @throws BadResponseException
59      */
60     public String assignVnrConfiguration(ServiceInstance serviceInstance,
61                                          RequestContext requestContext,
62                                          Customer customer,
63                                          Configuration vnrConfiguration,
64                                          GenericVnf voiceVnf)
65             throws MapperException, BadResponseException {
66         GenericResourceApiGcTopologyOperationInformation sdncReq = sdncRM.assignOrActivateVnrReqMapper(
67                 SDNCSvcAction.ASSIGN,
68                 GenericResourceApiRequestActionEnumeration.CREATEGENERICCONFIGURATIONINSTANCE ,
69       serviceInstance , requestContext, customer, vnrConfiguration,voiceVnf);
70         return sdncClient.post(sdncReq, SDNCTopology.CONFIGURATION);
71     }
72
73     /**
74      * SDNC Call to Activate VNR Configuration
75      *
76      * @param serviceInstance
77      * @param requestContext
78      * @param vnrConfiguration
79      * @param voiceVnf
80      * @return
81      * @throws MapperException
82      * @throws BadResponseException
83      */
84     public String activateVnrConfiguration(ServiceInstance serviceInstance,
85                                            RequestContext requestContext,
86                                            Customer customer,
87                                            Configuration vnrConfiguration,
88                                            GenericVnf voiceVnf)
89             throws MapperException, BadResponseException {
90
91         GenericResourceApiGcTopologyOperationInformation sdncReq = sdncRM.assignOrActivateVnrReqMapper(
92                 SDNCSvcAction.ACTIVATE,
93                 GenericResourceApiRequestActionEnumeration.CREATEGENERICCONFIGURATIONINSTANCE ,
94                 serviceInstance , requestContext, customer, vnrConfiguration, voiceVnf);
95         return sdncClient.post(sdncReq, SDNCTopology.CONFIGURATION);
96     }
97
98     /**
99      * method to unAssign Vnr Configuration in SDNC
100      *
101      * @param serviceInstance
102      * @param requestContext
103      * @param vnrConfiguration
104      * @return
105      * @throws BadResponseException
106      * @throws MapperException
107      */
108     public String unAssignVnrConfiguration(ServiceInstance serviceInstance, RequestContext requestContext,
109                                            Configuration vnrConfiguration) throws BadResponseException, MapperException {
110
111         GenericResourceApiGcTopologyOperationInformation sdncReq = sdncRM.deactivateOrUnassignVnrReqMapper
112                 (SDNCSvcAction.UNASSIGN,serviceInstance, requestContext, vnrConfiguration);
113         return sdncClient.post(sdncReq,  SDNCTopology.CONFIGURATION);
114     }
115
116     /***
117      *  Deactivate VNR SDNC Call
118      * @param serviceInstance
119      * @param requestContext
120      * @param vnrConfiguration
121      * @throws BadResponseException
122      * @throws MapperException
123      */
124     public String deactivateVnrConfiguration(ServiceInstance serviceInstance, RequestContext requestContext, Configuration vnrConfiguration) throws BadResponseException, MapperException {
125         GenericResourceApiGcTopologyOperationInformation sdncReq = sdncRM.deactivateOrUnassignVnrReqMapper(
126                 SDNCSvcAction.DEACTIVATE,
127                 serviceInstance , requestContext, vnrConfiguration);
128         return sdncClient.post(sdncReq, SDNCTopology.CONFIGURATION);
129     }
130 }