2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018. Intel Corp. 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=========================================================
22 package org.onap.so.bpmn.common.util;
24 import org.camunda.bpm.engine.delegate.DelegateExecution;
25 import org.onap.so.bpmn.core.UrnPropertiesReader;
26 import org.onap.so.db.catalog.beans.CloudSite;
27 import org.onap.so.db.catalog.beans.HomingInstance;
28 import org.onap.so.db.catalog.client.CatalogDbClient;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
32 import java.util.Optional;
34 public class OofInfraUtils {
36 private static final Logger logger = LoggerFactory.getLogger(OofInfraUtils.class);
39 * This method creates a cloudsite in catalog database.
45 public void createCloudSite(CloudSite cloudSite, DelegateExecution execution) {
46 String endpoint = UrnPropertiesReader.getVariable("mso.catalog.db.spring.endpoint", execution);
47 String auth = UrnPropertiesReader.getVariable("mso.db.auth", execution);
49 CloudSite getCloudsite;
51 CatalogDbClient client = new CatalogDbClient(endpoint, auth);
53 getCloudsite = Optional.ofNullable(client.getCloudSite(cloudSite.getId(), endpoint + "/cloudSite/")).orElse(new CloudSite());
54 if (!cloudSite.getId().equals(getCloudsite.getId())) {
55 client.postCloudSite(cloudSite);
56 logger.debug("Did not findd cloudsite : {}", cloudSite.getId());
57 logger.debug("Will create cloudSite: {}", cloudSite.toString());
60 logger.debug("Found cloudsite : {}", cloudSite.getId());
61 logger.debug("Will not create cloudSite: {}", cloudSite.toString());
63 } catch (Exception e) {
64 logger.debug("Error looking up or creating cloudsite : {}", cloudSite.getId());
65 logger.debug("CloudSite Lookup/Creation Error: " + e);
72 * This method creates a HomingInstance in catalog database.
74 * @param homingInstance
78 public void createHomingInstance(HomingInstance homingInstance, DelegateExecution execution) {
79 String endpoint = UrnPropertiesReader.getVariable("mso.catalog.db.spring.endpoint", execution);
80 String auth = UrnPropertiesReader.getVariable("mso.db.auth", execution);
82 CatalogDbClient client = new CatalogDbClient(endpoint, auth);
84 client.postHomingInstance(homingInstance);
85 } catch (Exception exception) {
86 logger.debug("Could not create HomingInstance : {}", homingInstance.getServiceInstanceId());
87 logger.debug("HomingInstance Creation Error: {}", exception);
93 * This method gets a HomingInstance in catalog database.
95 * @param serviceInstanceId
97 * @return HomingInstance
99 public HomingInstance getHomingInstance(String serviceInstanceId, DelegateExecution execution) {
100 String endpoint = UrnPropertiesReader.getVariable("mso.catalog.db.spring.endpoint", execution);
101 String auth = UrnPropertiesReader.getVariable("mso.db.auth", execution);
103 CatalogDbClient client = new CatalogDbClient(endpoint, auth);
105 return client.getHomingInstance(serviceInstanceId, endpoint + "/homingInstance/");
106 } catch (Exception exception) {
107 logger.debug("Could not get HomingInstance for serviceInstanceId : {}", serviceInstanceId);
108 logger.debug("Get HomingInstance Error: {}", exception);