e3c7d2ea81e94275a329ca048bc25640a1223704
[dcaegen2/services/sdk.git] /
1 /*
2  * ============LICENSE_START====================================
3  * DCAEGEN2-SERVICES-SDK
4  * =========================================================
5  * Copyright (C) 2019 Nokia. 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
10  *
11  *       http://www.apache.org/licenses/LICENSE-2.0
12  *
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=====================================
19  */
20
21 package org.onap.dcaegen2.services.sdk.rest.services.cbs.client.model;
22
23 import org.immutables.value.Value;
24 import org.jetbrains.annotations.Nullable;
25
26 /**
27  * Immutable object which helps with construction of cloudRequestObject for specified Client. For usage take a look in
28  * CloudConfigurationClient.class
29  *
30  * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 11/16/18
31  * @version 1.0.0 can be passed to ReactiveCloudConfigurationProvider, can be constructed out of
32  * org.onap.dcaegen2.services.sdk library.
33  * @since 1.0.0
34  */
35 @Value.Immutable(prehash = true)
36 public interface CbsClientConfiguration {
37
38     /**
39      * Name of environment variable containing Config Binding Service network hostname.
40      */
41     String ENV_CBS_HOSTNAME = "CONFIG_BINDING_SERVICE";
42
43     /**
44      * Name of environment variable containing Config Binding Service network port.
45      */
46     String ENV_CBS_PORT = "CONFIG_BINDING_SERVICE_SERVICE_PORT";
47
48     /**
49      * Name of environment variable containing current application name.
50      */
51     String ENV_APP_NAME = "HOSTNAME";
52
53     /**
54      * Name of environment variable containing Consul host name.
55      *
56      * @deprecated CBS lookup in Consul service should not be needed,
57      * instead {@link #ENV_CBS_HOSTNAME} should be used directly.
58      */
59     @Deprecated
60     String ENV_CONSUL_HOST = "CONSUL_HOST";
61
62     /**
63      * Name of environment variable containing Config Binding Service <em>service name</em> as registered in Consul
64      * services API.
65      *
66      * @deprecated CBS lookup in Consul service should not be needed,
67      * instead {@link #ENV_CBS_HOSTNAME} should be used directly.
68      */
69     @Deprecated
70     String ENV_CBS_NAME = "CONFIG_BINDING_SERVICE";
71
72     @Value.Parameter
73     @Nullable
74     String hostname();
75
76     @Value.Parameter
77     @Nullable
78     Integer port();
79
80     @Value.Parameter
81     String appName();
82
83     @Value.Default
84     @Deprecated
85     default String consulHost() {
86         return "consul-server";
87     }
88
89     @Value.Default
90     @Deprecated
91     default Integer consulPort() {
92         return 8500;
93     }
94
95     @Value.Default
96     @Deprecated
97     default String cbsName() {
98         return "config-binding-service";
99     }
100
101     /**
102      * Creates CbsClientConfiguration from system environment variables.
103      *
104      * @return an instance of CbsClientConfiguration
105      * @throws NullPointerException when at least one of required parameters is missing
106      */
107     static CbsClientConfiguration fromEnvironment() {
108         return ImmutableCbsClientConfiguration.builder()
109                 .consulHost(System.getenv(ENV_CONSUL_HOST))
110                 .hostname(System.getenv(ENV_CBS_HOSTNAME))
111                 .port(Integer.valueOf(System.getenv(ENV_CBS_PORT)))
112                 .appName(System.getenv(ENV_APP_NAME))
113                 .build();
114     }
115 }