Containerization feature of SO
[so.git] / bpmn / so-bpmn-tasks / src / main / java / org / onap / so / client / orchestration / AAIVfModuleResources.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.VfModule;
29 import org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup;
30 import org.onap.so.client.aai.AAIObjectType;
31 import org.onap.so.client.aai.entities.uri.AAIResourceUri;
32 import org.onap.so.client.aai.entities.uri.AAIUriFactory;
33 import org.onap.so.client.aai.mapper.AAIObjectMapper;
34 import org.onap.so.db.catalog.beans.OrchestrationStatus;
35 import org.onap.so.logger.MsoLogger;
36 import org.springframework.beans.factory.annotation.Autowired;
37 import org.springframework.stereotype.Component;
38
39 @Component
40 public class AAIVfModuleResources {
41         private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, AAIVfModuleResources.class);
42         
43         @Autowired
44         private InjectionHelper injectionHelper;
45         
46         @Autowired
47         private AAIObjectMapper aaiObjectMapper;
48
49         public void createVfModule(VfModule vfModule, GenericVnf vnf) {
50                 AAIResourceUri vfModuleURI = AAIUriFactory.createResourceUri(AAIObjectType.VF_MODULE, vnf.getVnfId(), vfModule.getVfModuleId());
51                 vfModule.setOrchestrationStatus(OrchestrationStatus.INVENTORIED);
52                 injectionHelper.getAaiClient().createIfNotExists(vfModuleURI, Optional.of(aaiObjectMapper.mapVfModule(vfModule)));
53         }
54         
55         public void deleteVfModule(VfModule vfModule, GenericVnf vnf) {
56                 AAIResourceUri vfModuleURI = AAIUriFactory.createResourceUri(AAIObjectType.VF_MODULE, vnf.getVnfId(), vfModule.getVfModuleId());
57                 injectionHelper.getAaiClient().delete(vfModuleURI);
58         }
59
60         public void updateOrchestrationStatusVfModule(VfModule vfModule, GenericVnf vnf, OrchestrationStatus orchestrationStatus) {
61                 AAIResourceUri vfModuleURI = AAIUriFactory.createResourceUri(AAIObjectType.VF_MODULE, vnf.getVnfId(), vfModule.getVfModuleId());
62                 VfModule copiedVfModule = vfModule.shallowCopyId();
63
64                 vfModule.setOrchestrationStatus(orchestrationStatus);
65                 copiedVfModule.setOrchestrationStatus(orchestrationStatus);
66                 org.onap.aai.domain.yang.VfModule aaiVfModule = aaiObjectMapper.mapVfModule(copiedVfModule);
67                 injectionHelper.getAaiClient().update(vfModuleURI, aaiVfModule);
68         }
69         
70         public void changeAssignVfModule(VfModule vfModule, GenericVnf vnf) {
71                 AAIResourceUri vfModuleURI = AAIUriFactory.createResourceUri(AAIObjectType.VF_MODULE, vnf.getVnfId(), vfModule.getVfModuleId());
72                 org.onap.aai.domain.yang.VfModule AAIVfModule = aaiObjectMapper.mapVfModule(vfModule);
73                 injectionHelper.getAaiClient().update(vfModuleURI, AAIVfModule);
74         }
75         
76         public void connectVfModuleToVolumeGroup(GenericVnf vnf, VfModule vfModule, VolumeGroup volumeGroup, CloudRegion cloudRegion) {
77                 AAIResourceUri vfModuleURI = AAIUriFactory.createResourceUri(AAIObjectType.VF_MODULE, vnf.getVnfId(), vfModule.getVfModuleId());
78                 AAIResourceUri volumeGroupURI = AAIUriFactory.createResourceUri(AAIObjectType.VOLUME_GROUP, cloudRegion.getCloudOwner(), cloudRegion.getLcpCloudRegionId(), volumeGroup.getVolumeGroupId());
79                 injectionHelper.getAaiClient().connect(vfModuleURI, volumeGroupURI);
80         }
81 }