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