3
3
package oracle .kubernetes .operator .builders ;
4
4
5
5
import com .squareup .okhttp .Call ;
6
- import io .kubernetes .client .ApiClient ;
7
6
import io .kubernetes .client .ApiException ;
8
7
import io .kubernetes .client .ProgressRequestBody ;
9
8
import io .kubernetes .client .ProgressResponseBody ;
10
- import io .kubernetes .client .models .V1Namespace ;
11
9
import io .kubernetes .client .models .V1Pod ;
12
10
import io .kubernetes .client .models .V1Service ;
13
11
import io .kubernetes .client .models .V1beta1Ingress ;
19
17
import java .lang .reflect .Type ;
20
18
import java .util .function .BiFunction ;
21
19
22
- @ SuppressWarnings ("unused " )
20
+ @ SuppressWarnings ("WeakerAccess " )
23
21
public class WatchBuilder {
24
22
25
23
/** Always true for watches. */
@@ -34,39 +32,14 @@ public class WatchBuilder {
34
32
private CallParamsImpl callParams = new CallParamsImpl ();
35
33
36
34
public interface WatchFactory {
37
- <T > Watch <T > createWatch (ClientHolder clientHolder , CallParams callParams , Class <?> responseBodyType , BiFunction <ClientHolder , CallParams , Call > function ) throws ApiException ;
35
+ <T > WatchI <T > createWatch (ClientHolder clientHolder , CallParams callParams , Class <?> responseBodyType , BiFunction <ClientHolder , CallParams , Call > function ) throws ApiException ;
38
36
}
39
37
40
38
public WatchBuilder (ClientHolder clientHolder ) {
41
39
this .clientHolder = clientHolder ;
42
40
}
43
41
44
- /**
45
- * Creates a web hook object to track changes to the namespaces.
46
- * @return the active web hook
47
- * @throws ApiException if there is an error on the call that sets up the web hook.
48
- */
49
- public Watch <V1Namespace > createNamespaceWatch () throws ApiException {
50
- return FACTORY .createWatch (clientHolder , callParams , V1Namespace .class , WatchBuilder ::listNamespaceCall );
51
- }
52
-
53
- private ApiClient getApiClient () {
54
- return clientHolder .getApiClient ();
55
- }
56
-
57
- private static Call listNamespaceCall (ClientHolder clientHolder , CallParams callParams ) {
58
- try {
59
- return clientHolder .getCoreApiClient ().listNamespaceCall (
60
- callParams .getPretty (), START_LIST , callParams .getFieldSelector (),
61
- callParams .getIncludeUninitialized (), callParams .getLabelSelector (), callParams .getLimit (),
62
- callParams .getResourceVersion (), callParams .getTimeoutSeconds (), WATCH ,
63
- callParams .getProgressListener (), callParams .getProgressRequestListener ());
64
- } catch (ApiException e ) {
65
- throw new UncheckedApiException (e );
66
- }
67
- }
68
-
69
- private static <T > Type getType (Class <?> responseBodyType ) {
42
+ private static Type getType (Class <?> responseBodyType ) {
70
43
return new ParameterizedType () {
71
44
@ Override
72
45
public Type [] getActualTypeArguments () {
@@ -90,7 +63,7 @@ public Type getOwnerType() {
90
63
* @return the active web hook
91
64
* @throws ApiException if there is an error on the call that sets up the web hook.
92
65
*/
93
- public Watch <V1Service > createServiceWatch (String namespace ) throws ApiException {
66
+ public WatchI <V1Service > createServiceWatch (String namespace ) throws ApiException {
94
67
return FACTORY .createWatch (clientHolder , callParams , V1Service .class , new ListNamespacedServiceCall (namespace ));
95
68
}
96
69
@@ -119,7 +92,7 @@ public Call apply(ClientHolder clientHolder, CallParams callParams) {
119
92
* @return the active web hook
120
93
* @throws ApiException if there is an error on the call that sets up the web hook.
121
94
*/
122
- public Watch <V1Pod > createPodWatch (String namespace ) throws ApiException {
95
+ public WatchI <V1Pod > createPodWatch (String namespace ) throws ApiException {
123
96
return FACTORY .createWatch (clientHolder , callParams , V1Pod .class , new ListPodCall (namespace ));
124
97
}
125
98
@@ -148,7 +121,7 @@ public Call apply(ClientHolder clientHolder, CallParams callParams) {
148
121
* @return the active web hook
149
122
* @throws ApiException if there is an error on the call that sets up the web hook.
150
123
*/
151
- public Watch <V1beta1Ingress > createIngressWatch (String namespace ) throws ApiException {
124
+ public WatchI <V1beta1Ingress > createIngressWatch (String namespace ) throws ApiException {
152
125
return FACTORY .createWatch (clientHolder , callParams , V1beta1Ingress .class , new ListIngressCall (namespace ));
153
126
}
154
127
@@ -172,40 +145,20 @@ public Call apply(ClientHolder clientHolder, CallParams callParams) {
172
145
}
173
146
}
174
147
175
- /**
176
- * Creates a web hook object to track changes to weblogic domains in all namespaces
177
- * @return the active web hook
178
- * @throws ApiException if there is an error on the call that sets up the web hook.
179
- */
180
- public Watch <Domain > createDomainsInAllNamespacesWatch () throws ApiException {
181
- return FACTORY .createWatch (clientHolder , callParams , Domain .class , WatchBuilder ::listDomainsForAllNamespacesCall );
182
- }
183
-
184
- private static Call listDomainsForAllNamespacesCall (ClientHolder clientHolder , CallParams callParams ) {
185
- try {
186
- return clientHolder .getWeblogicApiClient ().listWebLogicOracleV1DomainForAllNamespacesCall (START_LIST ,
187
- callParams .getFieldSelector (), callParams .getIncludeUninitialized (), callParams .getLabelSelector (),
188
- callParams .getLimit (), callParams .getPretty (), callParams .getResourceVersion (),
189
- callParams .getTimeoutSeconds (), WATCH , callParams .getProgressListener (), callParams .getProgressRequestListener ());
190
- } catch (ApiException e ) {
191
- throw new UncheckedApiException (e );
192
- }
193
- }
194
-
195
148
/**
196
149
* Creates a web hook object to track changes to weblogic domains in one namespaces
197
150
* @param namespace the namespace in which to track domains
198
151
* @return the active web hook
199
152
* @throws ApiException if there is an error on the call that sets up the web hook.
200
153
*/
201
- public Watch <Domain > createDomainsInNamespaceWatch (String namespace ) throws ApiException {
202
- return FACTORY .createWatch (clientHolder , callParams , Domain .class , new ListDomainsInNamespaceCall (namespace ));
154
+ public WatchI <Domain > createDomainWatch (String namespace ) throws ApiException {
155
+ return FACTORY .createWatch (clientHolder , callParams , Domain .class , new ListDomainsCall (namespace ));
203
156
}
204
157
205
- private class ListDomainsInNamespaceCall implements BiFunction <ClientHolder , CallParams , Call > {
158
+ private class ListDomainsCall implements BiFunction <ClientHolder , CallParams , Call > {
206
159
private String namespace ;
207
160
208
- ListDomainsInNamespaceCall (String namespace ) {
161
+ ListDomainsCall (String namespace ) {
209
162
this .namespace = namespace ;
210
163
}
211
164
@@ -222,45 +175,6 @@ public Call apply(ClientHolder clientHolder, CallParams callParams) {
222
175
}
223
176
}
224
177
225
- /**
226
- * Creates a web hook object to track changes to custom objects
227
- * @param namespace the namespace in which to track custom objects.
228
- * @param responseBodyType the type of objects returned in the events
229
- * @param group the custom resource group name
230
- * @param version the custom resource version
231
- * @param plural the custom resource plural name @return the active web hook
232
- * @throws ApiException if there is an error on the call that sets up the web hook.
233
- */
234
- public <T > Watch <T > createCustomObjectWatch (String namespace , Class <?> responseBodyType , String group , String version , String plural ) throws ApiException {
235
- return FACTORY .createWatch (clientHolder , callParams , responseBodyType , new ListCustomObjectsInNamespaceCall (namespace , group , version , plural ));
236
- }
237
-
238
- private class ListCustomObjectsInNamespaceCall implements BiFunction <ClientHolder , CallParams , Call > {
239
- private String namespace ;
240
- private String group ;
241
- private String version ;
242
- private String plural ;
243
-
244
- ListCustomObjectsInNamespaceCall (String namespace , String group , String version , String plural ) {
245
- this .namespace = namespace ;
246
- this .group = group ;
247
- this .version = version ;
248
- this .plural = plural ;
249
- }
250
-
251
- @ Override
252
- public Call apply (ClientHolder clientHolder , CallParams callParams ) {
253
- try {
254
- return clientHolder .getCustomObjectsApiClient ().listNamespacedCustomObjectCall (
255
- group , version , namespace , plural ,
256
- callParams .getPretty (), callParams .getLabelSelector (), callParams .getResourceVersion (),
257
- WATCH , null , null );
258
- } catch (ApiException e ) {
259
- throw new UncheckedApiException (e );
260
- }
261
- }
262
- }
263
-
264
178
/**
265
179
* Sets a value for the fieldSelector parameter for the call that will set up this watch. Defaults to null.
266
180
* @param fieldSelector the desired value
@@ -301,21 +215,23 @@ public WatchBuilder withTimeoutSeconds(Integer timeoutSeconds) {
301
215
return this ;
302
216
}
303
217
218
+ @ SuppressWarnings ("unused" )
304
219
public WatchBuilder withProgressListener (ProgressResponseBody .ProgressListener progressListener ) {
305
220
callParams .setProgressListener (progressListener );
306
221
return this ;
307
222
}
308
223
224
+ @ SuppressWarnings ("unused" )
309
225
public WatchBuilder withProgressRequestListener (ProgressRequestBody .ProgressRequestListener progressRequestListener ) {
310
226
callParams .setProgressRequestListener (progressRequestListener );
311
227
return this ;
312
228
}
313
229
314
230
static class WatchFactoryImpl implements WatchFactory {
315
231
@ Override
316
- public <T > Watch <T > createWatch (ClientHolder clientHolder , CallParams callParams , Class <?> responseBodyType , BiFunction <ClientHolder , CallParams , Call > function ) throws ApiException {
232
+ public <T > WatchI <T > createWatch (ClientHolder clientHolder , CallParams callParams , Class <?> responseBodyType , BiFunction <ClientHolder , CallParams , Call > function ) throws ApiException {
317
233
try {
318
- return Watch .createWatch (clientHolder .getApiClient (), function .apply (clientHolder , callParams ), getType (responseBodyType ));
234
+ return new WatchImpl < T >( Watch .createWatch (clientHolder .getApiClient (), function .apply (clientHolder , callParams ), getType (responseBodyType ) ));
319
235
} catch (UncheckedApiException e ) {
320
236
throw e .getCause ();
321
237
}
0 commit comments