2 * ============LICENSE_START=======================================================
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
23 package org.onap.so.adapters.vnf;
25 import java.util.Optional;
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;
35 public class VnfAdapterRestUtils
37 private static Logger logger = LoggerFactory.getLogger(VnfAdapterRestUtils.class);
39 private static final String HEAT_MODE = "HEAT";
40 private static final String CLOUDIFY_MODE = "CLOUDIFY";
41 private static final String MULTICLOUD_MODE = "MULTICLOUD";
44 private CloudConfig cloudConfig;
47 private MsoVnfCloudifyAdapterImpl cloudifyImpl;
50 private MsoVnfAdapterImpl vnfImpl;
53 private MsoVnfPluginAdapterImpl vnfPluginImpl;
56 * Choose which implementation of VNF Adapter to use, based on the orchestration mode.
57 * Currently, the two supported orchestrators are HEAT and CLOUDIFY.
59 public MsoVnfAdapter getVnfAdapterImpl (String mode, String cloudSiteId)
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.
65 logger.debug("Entered GetVnfAdapterImpl: mode=" + mode + ", cloudSite=" + cloudSiteId);
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) {
76 } else if (MULTICLOUD_MODE.equalsIgnoreCase(cloudSite.get().getOrchestrator())) {
77 mode = MULTICLOUD_MODE;
85 logger.debug ("GetVnfAdapterImpl: mode=" + mode);
87 MsoVnfAdapter vnfAdapter = null;
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;
94 else if (HEAT_MODE.equalsIgnoreCase(mode)) {
95 logger.debug("GetVnfAdapterImpl: Return Heat Adapter");
98 else if (MULTICLOUD_MODE.equalsIgnoreCase(mode)) {
99 logger.debug("GetVnfAdapterImpl: Return Plugin (multicloud) Adapter");
100 vnfAdapter = vnfPluginImpl;
103 // Don't expect this, but default is the HEAT adapter
104 logger.debug("GetVnfAdapterImpl: Return Default (Heat) Adapter");
105 vnfAdapter = vnfImpl;