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