Containerization feature of SO
[so.git] / bpmn / so-bpmn-tasks / src / main / java / org / onap / so / client / orchestration / AAIVnfResources.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 java.util.Optional;
24
25 import org.onap.so.bpmn.common.InjectionHelper;
26 import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion;
27 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
28 import org.onap.so.bpmn.servicedecomposition.bbobjects.LineOfBusiness;
29 import org.onap.so.bpmn.servicedecomposition.bbobjects.Platform;
30 import org.onap.so.bpmn.servicedecomposition.bbobjects.Project;
31 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
32 import org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup;
33 import org.onap.so.client.aai.AAIObjectType;
34 import org.onap.so.client.aai.entities.uri.AAIResourceUri;
35 import org.onap.so.client.aai.entities.uri.AAIUriFactory;
36 import org.onap.so.client.aai.mapper.AAIObjectMapper;
37 import org.onap.so.db.catalog.beans.OrchestrationStatus;
38 import org.onap.so.logger.MsoLogger;
39 import org.springframework.beans.factory.annotation.Autowired;
40 import org.springframework.stereotype.Component;
41
42 @Component
43 public class AAIVnfResources {
44         private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, AAIVnfResources.class);
45         
46         @Autowired
47         private InjectionHelper injectionHelper;
48         
49         @Autowired
50         private AAIObjectMapper aaiObjectMapper;
51         
52         public void createVnfandConnectServiceInstance(GenericVnf vnf, ServiceInstance serviceInstance) {
53                 AAIResourceUri vnfURI = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnf.getVnfId());
54                 vnf.setOrchestrationStatus(OrchestrationStatus.INVENTORIED);
55                 AAIResourceUri serviceInstanceURI = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE,
56                                 serviceInstance.getServiceInstanceId());
57                 injectionHelper.getAaiClient().createIfNotExists(vnfURI, Optional.of(aaiObjectMapper.mapVnf(vnf))).connect(vnfURI, serviceInstanceURI);
58         }
59         
60         public void createPlatformandConnectVnf(Platform platform, GenericVnf vnf) {
61                 AAIResourceUri platformURI = AAIUriFactory.createResourceUri(AAIObjectType.PLATFORM, platform.getPlatformName());       
62                 AAIResourceUri vnfURI = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnf.getVnfId());
63                 injectionHelper.getAaiClient().createIfNotExists(platformURI, Optional.of(platform)).connect(vnfURI, platformURI);
64         }
65         
66         public void createLineOfBusinessandConnectVnf(LineOfBusiness lineOfBusiness, GenericVnf vnf) {
67                 AAIResourceUri lineOfBusinessURI = AAIUriFactory.createResourceUri(AAIObjectType.LINE_OF_BUSINESS, lineOfBusiness.getLineOfBusinessName());     
68                 AAIResourceUri vnfURI = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnf.getVnfId());
69                 injectionHelper.getAaiClient().createIfNotExists(lineOfBusinessURI, Optional.of(lineOfBusiness)).connect(vnfURI, lineOfBusinessURI);
70         }
71         
72         public void deleteVnf(GenericVnf vnf) {
73                 AAIResourceUri vnfURI = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnf.getVnfId());
74                 injectionHelper.getAaiClient().delete(vnfURI);
75         }
76
77         public void updateOrchestrationStatusVnf(GenericVnf vnf, OrchestrationStatus orchestrationStatus) {
78                 AAIResourceUri vnfURI = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnf.getVnfId());
79
80                 GenericVnf copiedVnf = vnf.shallowCopyId();
81
82                 vnf.setOrchestrationStatus(orchestrationStatus);
83                 copiedVnf.setOrchestrationStatus(orchestrationStatus);
84                 injectionHelper.getAaiClient().update(vnfURI, aaiObjectMapper.mapVnf(copiedVnf));
85         }
86         
87         public void updateObjectVnf(GenericVnf vnf) {
88                 AAIResourceUri vnfUri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnf.getVnfId());
89                 injectionHelper.getAaiClient().update(vnfUri, aaiObjectMapper.mapVnf(vnf));
90         }
91
92         /**
93          * Retrieve Generic VNF from AAI using vnf Id
94          * @param vnfId - vnf-id required vnf
95          * @return AAI Generic Vnf
96          */
97         public Optional<org.onap.aai.domain.yang.GenericVnf> getGenericVnf( String vnfId) {
98                 return injectionHelper.getAaiClient()
99                                 .get(org.onap.aai.domain.yang.GenericVnf.class, AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId));
100         }
101         
102         /**
103          * Check inMaint flag value of Generic VNF from AAI using vnf Id
104          * @param vnfId - vnf-id required vnf
105          * @return inMaint flag value
106          */
107         public boolean checkInMaintFlag(String vnfId) {         
108                 org.onap.aai.domain.yang.GenericVnf vnf = injectionHelper.getAaiClient()
109                                 .get(org.onap.aai.domain.yang.GenericVnf.class, AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId))
110                                 .orElse(new org.onap.aai.domain.yang.GenericVnf());
111                 return vnf.isInMaint();
112         }
113 }