Merge changes Id0369478,I82d8306f
[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  * 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.adapters.vnf;
24
25 import java.util.Optional;
26
27 import org.onap.so.cloud.CloudConfig;
28 import org.onap.so.db.catalog.beans.CloudSite;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
31 import org.springframework.beans.factory.annotation.Autowired;
32 import org.springframework.stereotype.Component;
33
34 @Component
35 public class VnfAdapterRestUtils
36 {
37         private static Logger logger = LoggerFactory.getLogger(VnfAdapterRestUtils.class);
38
39         private static final String HEAT_MODE = "HEAT";
40         private static final String CLOUDIFY_MODE = "CLOUDIFY";
41         private static final String MULTICLOUD_MODE = "MULTICLOUD";
42
43         @Autowired
44         private CloudConfig cloudConfig;
45
46         @Autowired
47         private MsoVnfCloudifyAdapterImpl cloudifyImpl;
48
49         @Autowired
50         private MsoVnfAdapterImpl vnfImpl;
51
52         @Autowired
53         private MsoVnfPluginAdapterImpl vnfPluginImpl;
54
55         /*
56          * Choose which implementation of VNF Adapter to use, based on the orchestration mode.
57          * Currently, the two supported orchestrators are HEAT and CLOUDIFY.
58          */
59         public MsoVnfAdapter getVnfAdapterImpl (String mode, String cloudSiteId)
60         {
61                 // First, determine the orchestration mode to use.
62                 // If was explicitly provided as a parameter, use that.  Else if specified for the
63                 // cloudsite, use that.  Otherwise, the default is the (original) HEAT-based impl.
64
65                 logger.debug("Entered GetVnfAdapterImpl: mode=" + mode + ", cloudSite=" + cloudSiteId);
66
67                 if (mode == null) {
68                         // Didn't get an explicit mode type requested.
69                         // Use the CloudSite to determine which Impl to use, based on whether the target cloutSite
70                         // has a CloudifyManager assigned to it
71                         Optional<CloudSite> cloudSite = cloudConfig.getCloudSite(cloudSiteId);
72                         if (cloudSite.isPresent()) {
73                                 logger.debug("Got CloudSite: " + cloudSite.toString());
74                                 if (cloudConfig.getCloudifyManager(cloudSite.get().getCloudifyId()) != null) {
75                                         mode = CLOUDIFY_MODE;
76                                 } else if (MULTICLOUD_MODE.equalsIgnoreCase(cloudSite.get().getOrchestrator())) {
77                                         mode = MULTICLOUD_MODE;
78                                 }
79                                 else {
80                                         mode = HEAT_MODE;
81                                 }
82                         }
83                 }
84
85                 logger.debug ("GetVnfAdapterImpl: mode=" + mode);
86
87                 MsoVnfAdapter vnfAdapter = null;
88
89                 // TODO:  Make this more dynamic (e.g. Service Loader)
90                 if (CLOUDIFY_MODE.equalsIgnoreCase(mode)) {
91                         logger.debug("GetVnfAdapterImpl: Return Cloudify Adapter");
92                         vnfAdapter = cloudifyImpl;
93                 }
94                 else if (HEAT_MODE.equalsIgnoreCase(mode)) {
95                         logger.debug("GetVnfAdapterImpl: Return Heat Adapter");
96                         vnfAdapter = vnfImpl;
97                 }
98                 else if (MULTICLOUD_MODE.equalsIgnoreCase(mode)) {
99                         logger.debug("GetVnfAdapterImpl: Return Plugin (multicloud) Adapter");
100                         vnfAdapter = vnfPluginImpl;
101                 }
102                 else {
103                         // Don't expect this, but default is the HEAT adapter
104                         logger.debug("GetVnfAdapterImpl: Return Default (Heat) Adapter");
105                         vnfAdapter = vnfImpl;
106                 }
107
108                 return vnfAdapter;
109         }
110
111 }