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;
24 import com.fasterxml.jackson.annotation.JsonRootName;
25 import org.onap.so.db.catalog.beans.CloudSite;
26 import org.onap.so.db.catalog.beans.CloudifyManager;
27 import org.onap.so.db.catalog.client.CatalogDbClient;
28 import org.springframework.beans.factory.annotation.Autowired;
29 import org.springframework.stereotype.Component;
32 * JavaBean JSON class for a CloudConfig. This bean maps a JSON-format cloud configuration file to Java. The CloudConfig
33 * contains information about Openstack cloud configurations. It includes: - CloudIdentity objects,representing DCP
34 * nodes (Openstack Identity Service) - CloudSite objects, representing LCP nodes (Openstack Compute & other services)
36 * Note that this is only used to access Cloud Configurations loaded from a JSON config file, so there are no explicit
39 * This class also contains methods to query cloud sites and/or identity services by ID.
43 @JsonRootName("cloud_config")
45 public class CloudConfig {
47 private static final String CLOUD_SITE_VERSION = "2.5";
48 private static final String DEFAULT_CLOUD_SITE_ID = "DEFAULT";
51 private CatalogDbClient catalogDbClient;
54 * Get a specific CloudSites, based on an ID. The ID is first checked against the regions, and if no match is found
55 * there, then against individual entries to try and find one with a CLLI that matches the ID and an AIC version of
58 * @param id the ID to match
59 * @return an Optional of CloudSite object.
61 public synchronized Optional<CloudSite> getCloudSite(String id) {
63 return Optional.empty();
65 CloudSite cloudSite = catalogDbClient.getCloudSite(id);
67 if (cloudSite != null) {
68 return Optional.of(cloudSite);
70 return getCloudSiteWithClli(id);
75 * Get a specific CloudSites, based on a CLLI and (optional) version, which will be matched against the aic_version
76 * field of the CloudSite.
78 * @param clli the CLLI to match
79 * @return a CloudSite, or null of no match found
81 private Optional<CloudSite> getCloudSiteWithClli(String clli) {
82 Optional<CloudSite> cloudSiteOptional =
83 Optional.ofNullable(catalogDbClient.getCloudSiteByClliAndAicVersion(clli, CLOUD_SITE_VERSION));
84 if (cloudSiteOptional.isPresent()) {
85 return cloudSiteOptional;
87 return getDefaultCloudSite(clli);
91 private Optional<CloudSite> getDefaultCloudSite(String clli) {
92 Optional<CloudSite> cloudSiteOpt = Optional.ofNullable(catalogDbClient.getCloudSite(DEFAULT_CLOUD_SITE_ID));
93 if (cloudSiteOpt.isPresent()) {
94 CloudSite defaultCloudSite = cloudSiteOpt.get();
95 CloudSite clone = new CloudSite(defaultCloudSite);
96 clone.setRegionId(clli);
98 return Optional.of(clone);
100 return Optional.empty();
105 * Get a specific CloudifyManager, based on an ID.
107 * @param id the ID to match
108 * @return a CloudifyManager, or null of no match found
110 public CloudifyManager getCloudifyManager(String id) {
111 return catalogDbClient.getCloudifyManager(id);