946c2f2f41fc229d849b1556b8a6ae43da0f416d
[dcaegen2/analytics/tca-gen2.git] / dcae-analytics / dcae-analytics-web / src / main / java / org / onap / dcae / analytics / web / config / SystemConfig.java
1 /*-
2  * ============LICENSE_START======================================================================
3  * Copyright (C) 2019-2020 China Mobile.  All rights reserved.
4  * ===============================================================================================
5  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
6  * in compliance with the License. You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software distributed under the License
11  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12  * or implied. See the License for the specific language governing permissions and limitations under
13  * the License.
14  * ============LICENSE_END========================================================================
15  */
16
17 package org.onap.dcae.analytics.web.config;
18
19 import java.util.Optional;
20
21 import org.onap.dcae.analytics.model.configbindingservice.ConfigBindingServiceConstants;
22 import org.onap.dcae.analytics.web.exception.EnvironmentLoaderException;
23
24 /**
25  * 
26  * get consul config and cbs config.
27  *
28  * @author Kai Lu
29  */
30 public class SystemConfig {
31
32     /**
33      * 
34      * private constructor.
35      *
36      */
37     private SystemConfig() {
38     }
39
40     /**
41      * getConsulHost.
42      *
43      * @return consulHost consulHost
44      *
45      */
46     public static String getConsulHost() throws EnvironmentLoaderException {
47         return Optional.ofNullable(ConfigBindingServiceConstants.CONSUL_HOST_ENV_VARIABLE_VALUE)
48                 .orElseThrow(() -> new EnvironmentLoaderException("$CONSUL_HOST environment has not been defined"));
49     }
50
51     /**
52      * getConsultPort.
53      *
54      * @return consulPort consulPort
55      *
56      */
57     public static Integer getConsultPort() {
58         return ConfigBindingServiceConstants.DEFAULT_CONSUL_PORT_ENV_VARIABLE_VALUE;
59     }
60
61     /**
62      * getConfigBindingService.
63      *
64      * @return configBindingService configBindingService
65      *
66      */
67     public static String getConfigBindingService() throws EnvironmentLoaderException {
68         return Optional.ofNullable(ConfigBindingServiceConstants.CONFIG_BINDING_SERVICE_ENV_VARIABLE_VALUE) //
69                 .orElseThrow(() -> new EnvironmentLoaderException(
70                         "$CONFIG_BINDING_SERVICE environment has not been defined"));
71     }
72
73     /**
74      * getService.
75      *
76      * @return service service
77      *
78      */
79     public static String getService() throws EnvironmentLoaderException {
80         return Optional.ofNullable(ConfigBindingServiceConstants.SERVICE_NAME_ENV_VARIABLE_VALUE).orElseThrow(
81                 () -> new EnvironmentLoaderException("$HOSTNAME have not been defined as system environment"));
82     }
83
84 }