e1dd7affb9f0e32dbe63fd6873d2b39e24e6a7be
[dcaegen2/services/sdk.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  * DCAEGEN2-SERVICES-SDK
4  * ================================================================================
5  * Copyright (C) 2018 NOKIA Intellectual Property. 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
22 package org.onap.dcaegen2.services.sdk.rest.services.cbs.client.providers;
23
24 import com.google.gson.JsonObject;
25 import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.model.CbsClientConfiguration;
26 import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.model.ImmutableCbsClientConfiguration;
27 import reactor.core.publisher.Mono;
28
29 /**
30  * Complete CloudConfiguration HTTPClient API.
31  *
32  * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 11/16/18
33  * @version 1.0.0
34  * @since 1.0.0
35  */
36 public final class CloudConfigurationClient implements CloudConfigurationProvider {
37
38     private final CloudConfigurationProvider cloudConfigurationProvider;
39
40     /**
41      * Default constructor for CloudConfigurationClient, set CloudConfigurationProvider cloudConfigurationProvider
42      * property by calling: {@link ReactiveCloudConfigurationProvider}.
43      * Calls other constructor in this class {@link #CloudConfigurationClient(CloudConfigurationProvider)}.
44      */
45     public CloudConfigurationClient() {
46         this(new ReactiveCloudConfigurationProvider());
47     }
48
49     /**
50      * Constructor for CloudConfigurationClient, set loudConfigurationProvider cloudConfigurationProvider property
51      * by passing them in constructor {@link org.onap.dcaegen2.services.sdk.rest.services.cbs.client.providers.CloudConfigurationProvider}
52      * implementation client.
53      *
54      * @param cloudConfigurationProvider - client provider for calling ConfigBindingService
55      */
56     public CloudConfigurationClient(
57         CloudConfigurationProvider cloudConfigurationProvider) {
58         this.cloudConfigurationProvider = cloudConfigurationProvider;
59     }
60
61     /**
62      * Documentation in {@link org.onap.dcaegen2.services.sdk.rest.services.cbs.client.providers.CloudConfigurationProvider}
63      *
64      * @param consulHost - Hostname/IPAddress of consul Database
65      * @param consulPort - Port number of consul Database
66      * @param cbsName - ConfigBindingService url
67      * @param appName - ApplicationName for each config will be returned
68      */
69     @Override
70     public Mono<JsonObject> callForServiceConfigurationReactive(String consulHost, int consulPort, String cbsName,
71         String appName) {
72         return cloudConfigurationProvider.callForServiceConfigurationReactive(
73             ImmutableCbsClientConfiguration.builder().consulHost(consulHost)
74                 .consulPort(consulPort).cbsName(cbsName)
75                 .appName(appName).build());
76     }
77
78     /**
79      * Documentation in {@link org.onap.dcaegen2.services.sdk.rest.services.cbs.client.providers.CloudConfigurationProvider}.
80      *
81      * @param cbsClientConfiguration - Object holds consulPort, consulURL, configBindingSeriveName, applicationName which have
82      * been defined in dcaegen2 cloud environment.
83      */
84     @Override
85     public Mono<JsonObject> callForServiceConfigurationReactive(CbsClientConfiguration cbsClientConfiguration) {
86         return cloudConfigurationProvider.callForServiceConfigurationReactive(cbsClientConfiguration);
87     }
88
89     /**
90      * Documentation in {@link org.onap.dcaegen2.services.sdk.rest.services.cbs.client.providers.CloudConfigurationProvider}.
91      *
92      * @param consulHost - Hostname/IPAddress of consul Database
93      * @param consulPort - Port number of consul Database
94      * @param cbsName - ConfigBindingService url
95      * @param appName - ApplicationName for each config will be returned
96      */
97     @Override
98     public JsonObject callForServiceConfiguration(String consulHost, int consulPort, String cbsName, String appName) {
99         return cloudConfigurationProvider.callForServiceConfigurationReactive(
100                 ImmutableCbsClientConfiguration.builder().consulHost(consulHost)
101                 .consulPort(consulPort).cbsName(cbsName)
102                 .appName(appName).build()).block();
103     }
104
105     /**
106      * Documentation in {@link org.onap.dcaegen2.services.sdk.rest.services.cbs.client.providers.CloudConfigurationProvider}.
107      *
108      * @param cbsClientConfiguration - Object holds consulPort, consulURL, configBindingSeriveName, applicationName which have
109      */
110     @Override
111     public JsonObject callForServiceConfiguration(CbsClientConfiguration cbsClientConfiguration) {
112         return cloudConfigurationProvider.callForServiceConfigurationReactive(cbsClientConfiguration).block();
113     }
114 }