1 /*******************************************************************************
2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 Wipro Limited.
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 *******************************************************************************/
22 package org.onap.dcaegen2.services.sonhms;
24 import java.time.Duration;
26 import javax.sql.DataSource;
28 import org.onap.dcaegen2.services.sonhms.controller.ConfigFetchFromCbs;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
31 import org.springframework.boot.SpringApplication;
32 import org.springframework.boot.autoconfigure.SpringBootApplication;
33 import org.springframework.boot.jdbc.DataSourceBuilder;
34 import org.springframework.context.annotation.Bean;
36 @SpringBootApplication
37 public class Application {
39 private static Logger log = LoggerFactory.getLogger(Application.class);
42 * Main method where the pci context is initially set.
44 public static void main(String[] args) {
46 ConfigFetchFromCbs configFetchFromCbs = new ConfigFetchFromCbs(Duration.ofSeconds(60));
47 Thread configFetchThread = new Thread(configFetchFromCbs);
48 configFetchThread.start();
51 } catch (InterruptedException e) {
52 log.debug("InterruptedException : {}", e);
54 log.info("after 10s sleep");
55 log.info("Starting spring boot application");
56 SpringApplication.run(Application.class);
64 public DataSource dataSource() {
65 Configuration configuration = Configuration.getInstance();
67 String url = "jdbc:postgresql://" + configuration.getPgHost() + ":" + configuration.getPgPort() + "/sonhms";
69 return DataSourceBuilder.create().url(url).username(configuration.getPgUsername())
70 .password(configuration.getPgPassword()).build();