3724338d92564a7b3a6e9a8cfa635814578e07bd
[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.api;
22
23 import org.jetbrains.annotations.NotNull;
24 import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.model.CbsRequest;
25 import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.model.EnvProperties;
26 import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.model.ImmutableCbsRequest;
27 import org.onap.dcaegen2.services.sdk.rest.services.model.logging.RequestDiagnosticContext;
28
29 /**
30  * A factory to various of requests supported by Config Binding Service.
31  *
32  * @author <a href="mailto:piotr.jaszczyk@nokia.com">Piotr Jaszczyk</a>
33  * @since 1.1.4
34  */
35 public final class CbsRequests {
36
37     /**
38      * <p>A get-configuration request.</p>
39      *
40      * <p>Will bind the configuration for given service and return the bound configuration.</p>
41      *
42      * @param diagnosticContext logging diagnostic context (MDC)
43      * @return the CbsRequest ready to be used when calling {@link CbsClient}
44      */
45     public static @NotNull CbsRequest getConfiguration(RequestDiagnosticContext diagnosticContext) {
46         return ImmutableCbsRequest.builder()
47                 .diagnosticContext(diagnosticContext)
48                 .requestPath(serviceName -> "/service_component/" + serviceName)
49                 .build();
50     }
51
52     /**
53      * <p>A get-by-key request.</p>
54      *
55      * <p>This will call an endpoint that fetches a generic service_component_name:key out of Consul</p>
56      *
57      * @param diagnosticContext logging diagnostic context (MDC)
58      * @return the CbsRequest ready to be used when calling {@link CbsClient}
59      */
60     public static @NotNull CbsRequest getByKey(
61             RequestDiagnosticContext diagnosticContext,
62             String key) {
63         return ImmutableCbsRequest.builder()
64                 .diagnosticContext(diagnosticContext)
65                 .requestPath(serviceName -> "/" + key + "/" + serviceName)
66                 .build();
67     }
68
69     /**
70      * <p>A get-all request.</p>
71      *
72      * <p>Will bind the configuration for given service and return the bound configuration, policies, and any other
73      * keys that are in Consul</p>
74      *
75      * @param diagnosticContext logging diagnostic context (MDC)
76      * @return the CbsRequest ready to be used when calling {@link CbsClient}
77      */
78     public static @NotNull CbsRequest getAll(RequestDiagnosticContext diagnosticContext) {
79         return ImmutableCbsRequest.builder()
80                 .diagnosticContext(diagnosticContext)
81                 .requestPath(serviceName -> "/service_component_all/" + serviceName)
82                 .build();
83     }
84
85 }