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