Containerization feature of SO
[so.git] / adapters / mso-openstack-adapters / src / main / java / org / onap / so / adapters / vnf / VnfAdapterRestUtils.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * OPENECOMP - 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.adapters.vnf;
22
23 import java.util.Optional;
24
25 import org.onap.so.cloud.CloudConfig;
26 import org.onap.so.cloud.CloudSite;
27 import org.onap.so.logger.MsoLogger;
28 import org.springframework.beans.factory.annotation.Autowired;
29 import org.springframework.stereotype.Component;
30
31 @Component
32 public class VnfAdapterRestUtils
33 {
34         private static MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.RA, VnfAdapterRestUtils.class);
35         
36         @Autowired
37         private CloudConfig cloudConfig;
38         
39         @Autowired
40         private MsoVnfCloudifyAdapterImpl cloudifyImpl;
41         
42         @Autowired
43         private MsoVnfAdapterImpl vnfImpl;
44         
45         /*
46          * Choose which implementation of VNF Adapter to use, based on the orchestration mode.
47          * Currently, the two supported orchestrators are HEAT and CLOUDIFY.
48          */
49         public MsoVnfAdapter getVnfAdapterImpl (String mode, String cloudSiteId)
50         {
51                 // First, determine the orchestration mode to use.
52                 // If was explicitly provided as a parameter, use that.  Else if specified for the
53                 // cloudsite, use that.  Otherwise, the default is the (original) HEAT-based impl.
54
55                 LOGGER.debug ("Entered GetVnfAdapterImpl: mode=" + mode + ", cloudSite=" + cloudSiteId);
56
57                 if (mode == null) {
58                         // Didn't get an explicit mode type requested.
59                         // Use the CloudSite to determine which Impl to use, based on whether the target cloutSite
60                         // has a CloudifyManager assigned to it
61                         Optional<CloudSite> cloudSite = cloudConfig.getCloudSite(cloudSiteId);
62                         if (cloudSite.isPresent()) {
63                                 LOGGER.debug("Got CloudSite: " + cloudSite.toString());
64                                 if (cloudConfig.getCloudifyManager(cloudSite.get().getCloudifyId()) != null) {
65                                         mode = "CLOUDIFY";
66                                 } else {
67                                         mode = "HEAT";
68                                 }
69                         }
70                 }
71
72                 LOGGER.debug ("GetVnfAdapterImpl: mode=" + mode);
73
74                 MsoVnfAdapter vnfAdapter = null;
75                 
76                 // TODO:  Make this more dynamic (e.g. Service Loader)
77                 if ("CLOUDIFY".equalsIgnoreCase(mode)) {
78                         LOGGER.debug ("GetVnfAdapterImpl: Return Cloudify Adapter");
79                         vnfAdapter = cloudifyImpl;
80                 }
81                 else if ("HEAT".equalsIgnoreCase(mode)) {
82                         LOGGER.debug ("GetVnfAdapterImpl: Return Heat Adapter");
83                         vnfAdapter = vnfImpl;
84                 }
85                 else {
86                         // Don't expect this, but default is the HEAT adapter
87                         LOGGER.debug ("GetVnfAdapterImpl: Return Default (Heat) Adapter");
88                         vnfAdapter = vnfImpl;
89                 }
90                 
91                 return vnfAdapter;
92         }
93
94 }