Merge "Add CDS client"
[so.git] / bpmn / so-bpmn-tasks / src / main / java / org / onap / so / client / orchestration / SDNCVnfResources.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.sdnc.northbound.client.model.GenericResourceApiRequestActionEnumeration;
24 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfOperationInformation;
25 import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion;
26 import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer;
27 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
28 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
29 import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext;
30 import org.onap.so.client.exception.BadResponseException;
31 import org.onap.so.client.exception.MapperException;
32 import org.onap.so.client.sdnc.SDNCClient;
33 import org.onap.so.client.sdnc.beans.SDNCSvcAction;
34 import org.onap.so.client.sdnc.beans.SDNCSvcOperation;
35 import org.onap.so.client.sdnc.mapper.VnfTopologyOperationRequestMapper;
36 import org.onap.so.logger.MsoLogger;
37 import org.springframework.beans.factory.annotation.Autowired;
38 import org.springframework.stereotype.Component;
39
40 @Component
41 public class SDNCVnfResources {
42         private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, SDNCVnfResources.class);
43
44         @Autowired
45         private VnfTopologyOperationRequestMapper sdncRM;
46         
47         @Autowired
48         private SDNCClient sdncClient;
49         
50         public GenericResourceApiVnfOperationInformation assignVnf(GenericVnf vnf, ServiceInstance serviceInstance, Customer customer,
51                         CloudRegion cloudRegion, RequestContext requestContext, boolean homing) {
52                 return sdncRM.reqMapper(SDNCSvcOperation.VNF_TOPOLOGY_OPERATION,
53                                 SDNCSvcAction.ASSIGN,GenericResourceApiRequestActionEnumeration.CREATEVNFINSTANCE, vnf, serviceInstance, customer, cloudRegion, requestContext, homing);
54         }
55
56         public GenericResourceApiVnfOperationInformation activateVnf(GenericVnf vnf, ServiceInstance serviceInstance, Customer customer,
57                         CloudRegion cloudRegion, RequestContext requestContext) {
58                  return sdncRM.reqMapper(SDNCSvcOperation.VNF_TOPOLOGY_OPERATION,
59                                 SDNCSvcAction.ACTIVATE,GenericResourceApiRequestActionEnumeration.CREATEVNFINSTANCE, vnf, serviceInstance, customer,cloudRegion, requestContext, false);
60         }
61
62         
63         public GenericResourceApiVnfOperationInformation deactivateVnf(GenericVnf vnf, ServiceInstance serviceInstance, Customer customer,
64                         CloudRegion cloudRegion, RequestContext requestContext) {
65                 return sdncRM.reqMapper(SDNCSvcOperation.VNF_TOPOLOGY_OPERATION,
66                                 SDNCSvcAction.DEACTIVATE,GenericResourceApiRequestActionEnumeration.DELETEVNFINSTANCE, vnf, serviceInstance, customer,cloudRegion, requestContext, false);
67         }
68
69   
70         public GenericResourceApiVnfOperationInformation unassignVnf(GenericVnf vnf, ServiceInstance serviceInstance, Customer customer,
71                         CloudRegion cloudRegion, RequestContext requestContext) {
72                 return sdncRM.reqMapper(SDNCSvcOperation.VNF_TOPOLOGY_OPERATION,
73                                 SDNCSvcAction.UNASSIGN,GenericResourceApiRequestActionEnumeration.DELETEVNFINSTANCE, vnf, serviceInstance, customer, cloudRegion, requestContext, false);
74         }
75         
76         public GenericResourceApiVnfOperationInformation deleteVnf(GenericVnf vnf, ServiceInstance serviceInstance, Customer customer,
77                         CloudRegion cloudRegion, RequestContext requestContext) {
78                 return sdncRM.reqMapper(SDNCSvcOperation.VNF_TOPOLOGY_OPERATION,
79                                 SDNCSvcAction.DEACTIVATE, GenericResourceApiRequestActionEnumeration.DELETEVNFINSTANCE,vnf, serviceInstance, customer, cloudRegion, requestContext, false);
80         }
81         
82         public GenericResourceApiVnfOperationInformation changeModelVnf(GenericVnf vnf, ServiceInstance serviceInstance, Customer customer, 
83                         CloudRegion cloudRegion, RequestContext requestContext) {
84                 return sdncRM.reqMapper(SDNCSvcOperation.VNF_TOPOLOGY_OPERATION, 
85                                 SDNCSvcAction.CHANGE_ASSIGN,GenericResourceApiRequestActionEnumeration.CREATEVNFINSTANCE, vnf, serviceInstance, customer, cloudRegion, requestContext, false);
86         }
87         
88         public String queryVnf(GenericVnf vnf) throws MapperException, BadResponseException {
89                 String queryPath = vnf.getSelflink();           
90                 return sdncClient.get(queryPath);
91         }
92 }