Merge "update install and configure document"
[so.git] / bpmn / so-bpmn-tasks / src / main / java / org / onap / so / client / orchestration / SDNCServiceInstanceResources.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 import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer;
24 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
25 import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext;
26 import org.onap.so.client.exception.BadResponseException;
27 import org.onap.so.client.exception.MapperException;
28 import org.onap.so.client.sdnc.SDNCClient;
29 import org.onap.so.client.sdnc.beans.SDNCSvcAction;
30 import org.onap.so.client.sdnc.beans.SDNCSvcOperation;
31 import org.onap.so.client.sdnc.endpoint.SDNCTopology;
32 import org.onap.so.client.sdnc.mapper.ServiceTopologyOperationMapper;
33 import org.onap.so.logger.MsoLogger;
34 import org.springframework.beans.factory.annotation.Autowired;
35 import org.springframework.stereotype.Component;
36
37 import org.onap.sdnc.northbound.client.model.GenericResourceApiRequestActionEnumeration;
38 import org.onap.sdnc.northbound.client.model.GenericResourceApiServiceOperationInformation;
39
40 @Component
41 public class SDNCServiceInstanceResources {
42
43         private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL,
44                         SDNCServiceInstanceResources.class);
45
46         @Autowired
47         private ServiceTopologyOperationMapper sdncRM;
48         
49         @Autowired
50         private SDNCClient sdncClient;
51         
52         /**
53          * SDNC call to perform Service Topology Assign for ServiceInsatnce 
54          * @param serviceInstance
55          * @param customer
56          * @param requestContext
57          * @throws MapperException
58          * @throws BadResponseException
59          * @return the response as a String
60          */
61         public String assignServiceInstance(ServiceInstance serviceInstance, Customer customer,
62                         RequestContext requestContext) throws MapperException, BadResponseException {
63                 GenericResourceApiServiceOperationInformation sdncReq = sdncRM.reqMapper(
64                                 SDNCSvcOperation.SERVICE_TOPOLOGY_OPERATION, SDNCSvcAction.ASSIGN,GenericResourceApiRequestActionEnumeration.CREATESERVICEINSTANCE, serviceInstance, customer,
65                                 requestContext);
66                 return sdncClient.post(sdncReq, SDNCTopology.SERVICE);
67         }
68
69         /**
70          * SDNC call to perform Service Topology Delete for ServiceInsatnce 
71          * @param serviceInstance
72          * @param customer
73          * @param requestContext
74          * @throws MapperException
75          * @throws BadResponseException
76          * @return the response as a String
77          */
78         public String deleteServiceInstance(ServiceInstance serviceInstance, Customer customer,
79                         RequestContext requestContext) throws MapperException, BadResponseException {
80                 GenericResourceApiServiceOperationInformation sdncReq = sdncRM.reqMapper(
81                                 SDNCSvcOperation.SERVICE_TOPOLOGY_OPERATION, SDNCSvcAction.DELETE, GenericResourceApiRequestActionEnumeration.DELETESERVICEINSTANCE, serviceInstance, customer,
82                                 requestContext);
83                 return sdncClient.post(sdncReq, SDNCTopology.SERVICE);
84         }
85         
86         public String unassignServiceInstance(ServiceInstance serviceInstance, Customer customer,
87                         RequestContext requestContext) throws MapperException, BadResponseException {
88                 GenericResourceApiServiceOperationInformation sdncReq = sdncRM.reqMapper(
89                                 SDNCSvcOperation.SERVICE_TOPOLOGY_OPERATION, SDNCSvcAction.DELETE, GenericResourceApiRequestActionEnumeration.DELETESERVICEINSTANCE, serviceInstance, customer,
90                                 requestContext);
91                 return sdncClient.post(sdncReq, SDNCTopology.SERVICE);
92         }
93         
94         /**
95          * SDNC call to perform Service Topology Deactivate for ServiceInstance
96          * @param serviceInstance
97          * @param customer
98          * @param requestContext
99          * @throws MapperException
100          * @throws BadResponseException
101          * @return the response as a String
102          */
103         public String deactivateServiceInstance(ServiceInstance serviceInstance, Customer customer,
104                         RequestContext requestContext) throws MapperException, BadResponseException {
105                 GenericResourceApiServiceOperationInformation sdncReq = sdncRM.reqMapper(
106                                 SDNCSvcOperation.SERVICE_TOPOLOGY_OPERATION, SDNCSvcAction.DEACTIVATE, GenericResourceApiRequestActionEnumeration.DELETESERVICEINSTANCE, serviceInstance, customer,
107                                 requestContext);
108                 return sdncClient.post(sdncReq, SDNCTopology.SERVICE);
109         }
110         
111         /**
112          * SDNC call to perform Service Topology Change Assign for the ServiceInstance 
113          * @param serviceInstance
114          * @param customer
115          * @param requestContext
116          * @throws MapperException
117          * @throws BadResponseException
118          * @return the response as a String
119          */
120         public String changeModelServiceInstance(ServiceInstance serviceInstance, Customer customer, RequestContext requestContext) throws MapperException, BadResponseException {
121                 GenericResourceApiServiceOperationInformation sdncReq = sdncRM.reqMapper(SDNCSvcOperation.SERVICE_TOPOLOGY_OPERATION, SDNCSvcAction.CHANGE_ASSIGN, GenericResourceApiRequestActionEnumeration.CREATESERVICEINSTANCE, serviceInstance, customer, requestContext);
122                 return sdncClient.post(sdncReq, SDNCTopology.SERVICE);
123         }
124 }