2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018. Intel Corp. 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=========================================================
20 package org.onap.so.bpmn.common.util;
22 import org.camunda.bpm.engine.delegate.DelegateExecution;
23 import org.onap.so.bpmn.core.UrnPropertiesReader;
24 import org.onap.so.db.catalog.beans.CloudSite;
25 import org.onap.so.db.catalog.beans.HomingInstance;
26 import org.onap.so.db.catalog.client.CatalogDbClient;
27 import org.onap.so.logger.MsoLogger;
28 import org.springframework.beans.factory.annotation.Autowired;
29 import org.springframework.stereotype.Component;
31 import java.util.Arrays;
32 import java.util.Optional;
34 public class OofInfraUtils {
36 private static final MsoLogger LOGGER = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, 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);
48 Optional <CloudSite> optCloudsite = Optional.empty();
50 CatalogDbClient client = new CatalogDbClient(endpoint, auth);
52 optCloudsite = Optional.ofNullable(client.getCloudSite(cloudSite.getId(), endpoint + "/cloudSite/"));
53 } catch (Exception e) {
54 LOGGER.debug("Could not find cloudsite : " + cloudSite.getId());
55 LOGGER.debug("Creating cloudSite: " + cloudSite.toString());
57 if (optCloudsite.isPresent() && (cloudSite.getId()) != optCloudsite.get().getId()) {
58 client.postCloudSite(cloudSite);
63 * This method creates a HomingInstance in catalog database.
65 * @param homingInstance
69 public void createHomingInstance(HomingInstance homingInstance, DelegateExecution execution) {
70 String endpoint = UrnPropertiesReader.getVariable("mso.catalog.db.spring.endpoint", execution);
71 String auth = UrnPropertiesReader.getVariable("mso.db.auth", execution);
73 CatalogDbClient client = new CatalogDbClient(endpoint, auth);
75 client.postHomingInstance(homingInstance);
76 } catch (Exception exception) {
77 LOGGER.debug("Could not create HomingInstance : " + homingInstance.getServiceInstanceId());
78 LOGGER.debug("HomingInstance Creation Error: " + exception);
84 * This method gets a HomingInstance in catalog database.
86 * @param serviceInstanceId
88 * @return HomingInstance
90 public HomingInstance getHomingInstance(String serviceInstanceId, DelegateExecution execution) {
91 String endpoint = UrnPropertiesReader.getVariable("mso.catalog.db.spring.endpoint", execution);
92 String auth = UrnPropertiesReader.getVariable("mso.db.auth", execution);
94 CatalogDbClient client = new CatalogDbClient(endpoint, auth);
96 return client.getHomingInstance(serviceInstanceId, endpoint + "/homingInstance/");
97 } catch (Exception exception) {
98 LOGGER.debug("Could not get HomingInstance for serviceInstanceId : " + serviceInstanceId);
99 LOGGER.debug("Get HomingInstance Error: " + exception);