Skip to content

Commit c93aae4

Browse files
author
Tom Barnes
committed
Merge remote-tracking branch 'origin/master' into issue--41
2 parents cc5ac01 + 31e82ef commit c93aae4

File tree

19 files changed

+996
-725
lines changed

19 files changed

+996
-725
lines changed

pom.xml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,17 +445,42 @@
445445
<version>2.3.0</version>
446446
</dependency>
447447
<!-- test dependencies -->
448+
<dependency>
449+
<groupId>org.hamcrest</groupId>
450+
<artifactId>hamcrest-junit</artifactId>
451+
<version>2.0.0.0</version>
452+
<scope>test</scope>
453+
</dependency>
448454
<dependency>
449455
<groupId>junit</groupId>
450456
<artifactId>junit</artifactId>
451457
<version>${junit-version}</version>
458+
<scope>test</scope>
452459
</dependency>
453460
<dependency>
454461
<groupId>org.apache.commons</groupId>
455462
<artifactId>commons-exec</artifactId>
456463
<version>1.3</version>
457464
<scope>test</scope>
458465
</dependency>
466+
<dependency>
467+
<groupId>com.google.guava</groupId>
468+
<artifactId>guava</artifactId>
469+
<version>18.0</version>
470+
<scope>test</scope>
471+
</dependency>
472+
<dependency>
473+
<groupId>org.httpunit</groupId>
474+
<artifactId>httpunit</artifactId>
475+
<version>1.7.2</version>
476+
<scope>test</scope>
477+
</dependency>
478+
<dependency>
479+
<groupId>com.meterware.simplestub</groupId>
480+
<artifactId>simplestub</artifactId>
481+
<version>1.2.9</version>
482+
<scope>test</scope>
483+
</dependency>
459484

460485
</dependencies>
461486

src/main/java/oracle/kubernetes/operator/DomainWatcher.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55

66
import io.kubernetes.client.ApiException;
77
import io.kubernetes.client.util.Watch;
8+
import oracle.kubernetes.operator.builders.WatchBuilder;
9+
import oracle.kubernetes.operator.builders.WatchI;
810
import oracle.kubernetes.operator.domain.model.oracle.kubernetes.weblogic.domain.v1.Domain;
911
import oracle.kubernetes.operator.helpers.ClientHelper;
1012
import oracle.kubernetes.operator.helpers.ClientHolder;
11-
import oracle.kubernetes.operator.builders.WatchBuilder;
1213
import oracle.kubernetes.operator.watcher.Watcher;
1314
import oracle.kubernetes.operator.watcher.Watching;
1415
import oracle.kubernetes.operator.watcher.WatchingEventDestination;
@@ -50,7 +51,7 @@ public void run() {
5051
ClientHolder client = helper.take();
5152
try {
5253
Watching<Domain> w = createWatching(client);
53-
Watcher<Domain> watcher = new Watcher<Domain>(w, null, initialResourceVersion);
54+
Watcher<Domain> watcher = new Watcher<>(w, initialResourceVersion);
5455

5556
// invoke watch on current Thread. Won't return until watch stops
5657
watcher.doWatch();
@@ -66,16 +67,15 @@ protected Watching<Domain> createWatching(ClientHolder client) {
6667
/**
6768
* Watcher callback to issue the list Domain changes. It is driven by the
6869
* Watcher wrapper to issue repeated watch requests.
69-
* @param context user defined contact object or null
7070
* @param resourceVersion resource version to omit older events
7171
* @return Watch object or null if the operation should end
7272
* @throws ApiException if there is an API error.
7373
*/
7474
@Override
75-
public Watch<Domain> initiateWatch(Object context, String resourceVersion) throws ApiException {
75+
public WatchI<Domain> initiateWatch(String resourceVersion) throws ApiException {
7676
return new WatchBuilder(client)
7777
.withResourceVersion(resourceVersion)
78-
.createDomainsInNamespaceWatch(ns);
78+
.createDomainWatch(ns);
7979
}
8080

8181
@Override

src/main/java/oracle/kubernetes/operator/IngressWatcher.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import io.kubernetes.client.models.V1ObjectMeta;
88
import io.kubernetes.client.models.V1beta1Ingress;
99
import io.kubernetes.client.util.Watch;
10+
import oracle.kubernetes.operator.builders.WatchI;
1011
import oracle.kubernetes.operator.helpers.ClientHelper;
1112
import oracle.kubernetes.operator.helpers.ClientHolder;
1213
import oracle.kubernetes.operator.builders.WatchBuilder;
@@ -52,7 +53,7 @@ public void run() {
5253
ClientHolder client = helper.take();
5354
try {
5455
Watching<V1beta1Ingress> w = createWatching(client);
55-
Watcher<V1beta1Ingress> watcher = new Watcher<V1beta1Ingress>(w, null, initialResourceVersion);
56+
Watcher<V1beta1Ingress> watcher = new Watcher<>(w, initialResourceVersion);
5657

5758
// invoke watch on current Thread. Won't return until watch stops
5859
watcher.doWatch();
@@ -68,13 +69,12 @@ protected Watching<V1beta1Ingress> createWatching(ClientHolder client) {
6869
/**
6970
* Watcher callback to issue the list Ingress changes. It is driven by the
7071
* Watcher wrapper to issue repeated watch requests.
71-
* @param context user defined contact object or null
7272
* @param resourceVersion resource version to omit older events
7373
* @return Watch object or null if the operation should end
7474
* @throws ApiException if there is an API error.
7575
*/
7676
@Override
77-
public Watch<V1beta1Ingress> initiateWatch(Object context, String resourceVersion) throws ApiException {
77+
public WatchI<V1beta1Ingress> initiateWatch(String resourceVersion) throws ApiException {
7878
return new WatchBuilder(client)
7979
.withResourceVersion(resourceVersion)
8080
.withLabelSelector(LabelConstants.DOMAINUID_LABEL) // Any Ingress with a domainUID label

src/main/java/oracle/kubernetes/operator/PodWatcher.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@
88
import io.kubernetes.client.models.V1PodCondition;
99
import io.kubernetes.client.models.V1PodStatus;
1010
import io.kubernetes.client.util.Watch;
11+
import oracle.kubernetes.operator.builders.WatchBuilder;
12+
import oracle.kubernetes.operator.builders.WatchI;
1113
import oracle.kubernetes.operator.helpers.CallBuilder;
1214
import oracle.kubernetes.operator.helpers.ClientHelper;
1315
import oracle.kubernetes.operator.helpers.ClientHolder;
1416
import oracle.kubernetes.operator.helpers.ResponseStep;
1517
import oracle.kubernetes.operator.logging.LoggingFacade;
1618
import oracle.kubernetes.operator.logging.LoggingFactory;
1719
import oracle.kubernetes.operator.logging.MessageKeys;
18-
import oracle.kubernetes.operator.builders.WatchBuilder;
1920
import oracle.kubernetes.operator.watcher.Watcher;
2021
import oracle.kubernetes.operator.watcher.Watching;
2122
import oracle.kubernetes.operator.watcher.WatchingEventDestination;
@@ -77,7 +78,7 @@ public void run() {
7778
ClientHolder client = helper.take();
7879
try {
7980
Watching<V1Pod> w = createWatching(client);
80-
Watcher<V1Pod> watcher = new Watcher<V1Pod>(w, null, initialResourceVersion);
81+
Watcher<V1Pod> watcher = new Watcher<>(w, initialResourceVersion);
8182

8283
// invoke watch on current Thread. Won't return until watch stops
8384
watcher.doWatch();
@@ -93,13 +94,12 @@ private Watching<V1Pod> createWatching(ClientHolder client) {
9394
/**
9495
* Watcher callback to issue the list Pod changes. It is driven by the
9596
* Watcher wrapper to issue repeated watch requests.
96-
* @param context user defined contact object or null
9797
* @param resourceVersion resource version to omit older events
9898
* @return Watch object or null if the operation should end
9999
* @throws ApiException if there is an API error.
100100
*/
101101
@Override
102-
public Watch<V1Pod> initiateWatch(Object context, String resourceVersion) throws ApiException {
102+
public WatchI<V1Pod> initiateWatch(String resourceVersion) throws ApiException {
103103
return new WatchBuilder(client)
104104
.withResourceVersion(resourceVersion)
105105
.withLabelSelector(LabelConstants.DOMAINUID_LABEL) // Any Pod with a domainUID label

src/main/java/oracle/kubernetes/operator/ServiceWatcher.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77
import io.kubernetes.client.models.V1ObjectMeta;
88
import io.kubernetes.client.models.V1Service;
99
import io.kubernetes.client.util.Watch;
10+
import oracle.kubernetes.operator.builders.WatchBuilder;
11+
import oracle.kubernetes.operator.builders.WatchI;
1012
import oracle.kubernetes.operator.helpers.ClientHelper;
1113
import oracle.kubernetes.operator.helpers.ClientHolder;
12-
import oracle.kubernetes.operator.builders.WatchBuilder;
1314
import oracle.kubernetes.operator.watcher.Watcher;
1415
import oracle.kubernetes.operator.watcher.Watching;
1516
import oracle.kubernetes.operator.watcher.WatchingEventDestination;
@@ -52,7 +53,7 @@ public void run() {
5253
ClientHolder client = helper.take();
5354
try {
5455
Watching<V1Service> w = createWatching(client);
55-
Watcher<V1Service> watcher = new Watcher<V1Service>(w, null, initialResourceVersion);
56+
Watcher<V1Service> watcher = new Watcher<>(w, initialResourceVersion);
5657

5758
// invoke watch on current Thread. Won't return until watch stops
5859
watcher.doWatch();
@@ -68,13 +69,12 @@ protected Watching<V1Service> createWatching(ClientHolder client) {
6869
/**
6970
* Watcher callback to issue the list Service changes. It is driven by the
7071
* Watcher wrapper to issue repeated watch requests.
71-
* @param context user defined contact object or null
7272
* @param resourceVersion resource version to omit older events
7373
* @return Watch object or null if the operation should end
7474
* @throws ApiException if there is an API error.
7575
*/
7676
@Override
77-
public Watch<V1Service> initiateWatch(Object context, String resourceVersion) throws ApiException {
77+
public WatchI<V1Service> initiateWatch(String resourceVersion) throws ApiException {
7878
return new WatchBuilder(client)
7979
.withResourceVersion(resourceVersion)
8080
.withLabelSelector(LabelConstants.DOMAINUID_LABEL) // Any Service with a domainUID label

src/main/java/oracle/kubernetes/operator/builders/WatchBuilder.java

Lines changed: 14 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@
33
package oracle.kubernetes.operator.builders;
44

55
import com.squareup.okhttp.Call;
6-
import io.kubernetes.client.ApiClient;
76
import io.kubernetes.client.ApiException;
87
import io.kubernetes.client.ProgressRequestBody;
98
import io.kubernetes.client.ProgressResponseBody;
10-
import io.kubernetes.client.models.V1Namespace;
119
import io.kubernetes.client.models.V1Pod;
1210
import io.kubernetes.client.models.V1Service;
1311
import io.kubernetes.client.models.V1beta1Ingress;
@@ -19,7 +17,7 @@
1917
import java.lang.reflect.Type;
2018
import java.util.function.BiFunction;
2119

22-
@SuppressWarnings("unused")
20+
@SuppressWarnings("WeakerAccess")
2321
public class WatchBuilder {
2422

2523
/** Always true for watches. */
@@ -34,39 +32,14 @@ public class WatchBuilder {
3432
private CallParamsImpl callParams = new CallParamsImpl();
3533

3634
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;
3836
}
3937

4038
public WatchBuilder(ClientHolder clientHolder) {
4139
this.clientHolder = clientHolder;
4240
}
4341

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) {
7043
return new ParameterizedType() {
7144
@Override
7245
public Type[] getActualTypeArguments() {
@@ -90,7 +63,7 @@ public Type getOwnerType() {
9063
* @return the active web hook
9164
* @throws ApiException if there is an error on the call that sets up the web hook.
9265
*/
93-
public Watch<V1Service> createServiceWatch(String namespace) throws ApiException {
66+
public WatchI<V1Service> createServiceWatch(String namespace) throws ApiException {
9467
return FACTORY.createWatch(clientHolder, callParams, V1Service.class, new ListNamespacedServiceCall(namespace));
9568
}
9669

@@ -119,7 +92,7 @@ public Call apply(ClientHolder clientHolder, CallParams callParams) {
11992
* @return the active web hook
12093
* @throws ApiException if there is an error on the call that sets up the web hook.
12194
*/
122-
public Watch<V1Pod> createPodWatch(String namespace) throws ApiException {
95+
public WatchI<V1Pod> createPodWatch(String namespace) throws ApiException {
12396
return FACTORY.createWatch(clientHolder, callParams, V1Pod.class, new ListPodCall(namespace));
12497
}
12598

@@ -148,7 +121,7 @@ public Call apply(ClientHolder clientHolder, CallParams callParams) {
148121
* @return the active web hook
149122
* @throws ApiException if there is an error on the call that sets up the web hook.
150123
*/
151-
public Watch<V1beta1Ingress> createIngressWatch(String namespace) throws ApiException {
124+
public WatchI<V1beta1Ingress> createIngressWatch(String namespace) throws ApiException {
152125
return FACTORY.createWatch(clientHolder, callParams, V1beta1Ingress.class, new ListIngressCall(namespace));
153126
}
154127

@@ -172,40 +145,20 @@ public Call apply(ClientHolder clientHolder, CallParams callParams) {
172145
}
173146
}
174147

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-
195148
/**
196149
* Creates a web hook object to track changes to weblogic domains in one namespaces
197150
* @param namespace the namespace in which to track domains
198151
* @return the active web hook
199152
* @throws ApiException if there is an error on the call that sets up the web hook.
200153
*/
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));
203156
}
204157

205-
private class ListDomainsInNamespaceCall implements BiFunction<ClientHolder, CallParams, Call> {
158+
private class ListDomainsCall implements BiFunction<ClientHolder, CallParams, Call> {
206159
private String namespace;
207160

208-
ListDomainsInNamespaceCall(String namespace) {
161+
ListDomainsCall(String namespace) {
209162
this.namespace = namespace;
210163
}
211164

@@ -222,45 +175,6 @@ public Call apply(ClientHolder clientHolder, CallParams callParams) {
222175
}
223176
}
224177

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-
264178
/**
265179
* Sets a value for the fieldSelector parameter for the call that will set up this watch. Defaults to null.
266180
* @param fieldSelector the desired value
@@ -301,21 +215,23 @@ public WatchBuilder withTimeoutSeconds(Integer timeoutSeconds) {
301215
return this;
302216
}
303217

218+
@SuppressWarnings("unused")
304219
public WatchBuilder withProgressListener(ProgressResponseBody.ProgressListener progressListener) {
305220
callParams.setProgressListener(progressListener);
306221
return this;
307222
}
308223

224+
@SuppressWarnings("unused")
309225
public WatchBuilder withProgressRequestListener(ProgressRequestBody.ProgressRequestListener progressRequestListener) {
310226
callParams.setProgressRequestListener(progressRequestListener);
311227
return this;
312228
}
313229

314230
static class WatchFactoryImpl implements WatchFactory {
315231
@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 {
317233
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)));
319235
} catch (UncheckedApiException e) {
320236
throw e.getCause();
321237
}

0 commit comments

Comments
 (0)