2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.so.cloud;
23 import java.util.Optional;
25 import com.fasterxml.jackson.annotation.JsonRootName;
27 import org.onap.so.db.catalog.beans.CloudSite;
28 import org.onap.so.db.catalog.beans.CloudifyManager;
29 import org.onap.so.db.catalog.client.CatalogDbClient;
30 import org.springframework.beans.factory.annotation.Autowired;
31 import org.springframework.stereotype.Component;
34 * JavaBean JSON class for a CloudConfig. This bean maps a JSON-format cloud
35 * configuration file to Java. The CloudConfig contains information about
36 * Openstack cloud configurations. It includes:
37 * - CloudIdentity objects,representing DCP nodes (Openstack Identity Service)
38 * - CloudSite objects, representing LCP nodes (Openstack Compute & other services)
40 * Note that this is only used to access Cloud Configurations loaded from a JSON
41 * config file, so there are no explicit property setters.
43 * This class also contains methods to query cloud sites and/or identity
48 @JsonRootName("cloud_config")
50 public class CloudConfig {
52 private static final String CLOUD_SITE_VERSION = "2.5";
53 private static final String DEFAULT_CLOUD_SITE_ID = "DEFAULT";
56 private CatalogDbClient catalogDbClient;
59 * Get a specific CloudSites, based on an ID. The ID is first checked
60 * against the regions, and if no match is found there, then against
61 * individual entries to try and find one with a CLLI that matches the ID
62 * and an AIC version of 2.5.
64 * @param id the ID to match
65 * @return an Optional of CloudSite object.
67 public synchronized Optional<CloudSite> getCloudSite(String id) {
69 return Optional.empty();
71 CloudSite cloudSite = catalogDbClient.getCloudSite(id);
73 if (cloudSite != null) {
74 return Optional.of(cloudSite);
76 return getCloudSiteWithClli(id);
81 * Get a specific CloudSites, based on a CLLI and (optional) version, which
82 * will be matched against the aic_version field of the CloudSite.
86 * @return a CloudSite, or null of no match found
88 private Optional<CloudSite> getCloudSiteWithClli(String clli) {
89 Optional <CloudSite> cloudSiteOptional = Optional.ofNullable(catalogDbClient.getCloudSiteByClliAndAicVersion(clli,CLOUD_SITE_VERSION));
90 if (cloudSiteOptional.isPresent()) {
91 return cloudSiteOptional;
93 return getDefaultCloudSite(clli);
97 private Optional<CloudSite> getDefaultCloudSite(String clli) {
98 Optional<CloudSite> cloudSiteOpt = Optional.ofNullable(catalogDbClient.getCloudSite(DEFAULT_CLOUD_SITE_ID));
99 if (cloudSiteOpt.isPresent()) {
100 CloudSite defaultCloudSite = cloudSiteOpt.get();
101 CloudSite clone = new CloudSite(defaultCloudSite);
102 clone.setRegionId(clli);
104 return Optional.of(clone);
106 return Optional.empty();
111 * Get a specific CloudifyManager, based on an ID.
112 * @param id the ID to match
113 * @return a CloudifyManager, or null of no match found
115 public CloudifyManager getCloudifyManager (String id) {
116 return catalogDbClient.getCloudifyManager(id);