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;
31 import java.util.Optional;
33 public class OofInfraUtils {
35 private static final Logger logger = LoggerFactory.getLogger(OofInfraUtils.class);
38 * This method creates a cloudsite in catalog database.
44 public void createCloudSite(CloudSite cloudSite, DelegateExecution execution) {
45 String endpoint = UrnPropertiesReader.getVariable("mso.catalog.db.spring.endpoint", execution);
46 String auth = UrnPropertiesReader.getVariable("mso.db.auth", execution);
48 CloudSite getCloudsite;
50 CatalogDbClient client = new CatalogDbClient(endpoint, auth);
52 getCloudsite = Optional.ofNullable(client.getCloudSite(cloudSite.getId(), endpoint + "/cloudSite/"))
53 .orElse(new CloudSite());
54 if (!cloudSite.getId().equals(getCloudsite.getId())) {
55 client.postOofHomingCloudSite(cloudSite);
56 logger.debug("Did not findd cloudsite : {}", cloudSite.getId());
57 logger.debug("Will create cloudSite: {}", cloudSite.toString());
59 logger.debug("Found cloudsite : {}", cloudSite.getId());
60 logger.debug("Will not create cloudSite: {}", cloudSite.toString());
62 } catch (Exception e) {
63 logger.debug("Error looking up or creating cloudsite : {}", cloudSite.getId());
64 logger.debug("CloudSite Lookup/Creation Error: " + e);
71 * This method creates a HomingInstance in catalog database.
73 * @param homingInstance
77 public void createHomingInstance(HomingInstance homingInstance, DelegateExecution execution) {
78 String endpoint = UrnPropertiesReader.getVariable("mso.catalog.db.spring.endpoint", execution);
79 String auth = UrnPropertiesReader.getVariable("mso.db.auth", execution);
81 CatalogDbClient client = new CatalogDbClient(endpoint, auth);
83 client.postHomingInstance(homingInstance);
84 } catch (Exception exception) {
85 logger.debug("Could not create HomingInstance : {}", homingInstance.getServiceInstanceId());
86 logger.debug("HomingInstance Creation Error: {}", exception);
92 * This method gets a HomingInstance in catalog database.
94 * @param serviceInstanceId
96 * @return HomingInstance
98 public HomingInstance getHomingInstance(String serviceInstanceId, DelegateExecution execution) {
99 String endpoint = UrnPropertiesReader.getVariable("mso.catalog.db.spring.endpoint", execution);
100 String auth = UrnPropertiesReader.getVariable("mso.db.auth", execution);
102 CatalogDbClient client = new CatalogDbClient(endpoint, auth);
104 return client.getHomingInstance(serviceInstanceId, endpoint + "/homingInstance/");
105 } catch (Exception exception) {
106 logger.debug("Could not get HomingInstance for serviceInstanceId : {}", serviceInstanceId);
107 logger.debug("Get HomingInstance Error: {}", exception);