Skip to content

Commit 86cc280

Browse files
authored
Merge pull request #149 from russgold/watcher_tests
Watcher tests
2 parents 50dcc1d + c4af9e1 commit 86cc280

21 files changed

+872
-892
lines changed

docs/apidocs/oracle/kubernetes/operator/watcher/Watching.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ <h3>Method Summary</h3>
173173
</tr>
174174
</table>
175175
<ul class="blockList">
176-
<li class="blockList"><a name="methods.inherited.from.class.oracle.kubernetes.operator.watcher.WatchingEventDestination">
176+
<li class="blockList"><a name="methods.inherited.from.class.oracle.kubernetes.operator.watcher.WatchListener">
177177
<!-- -->
178178
</a>
179179
<h3>Methods inherited from interface&nbsp;oracle.kubernetes.operator.watcher.<a href="../../../../oracle/kubernetes/operator/watcher/WatchingEventDestination.html" title="interface in oracle.kubernetes.operator.watcher">WatchingEventDestination</a></h3>

docs/apidocs/oracle/kubernetes/operator/watcher/class-use/WatchingEventDestination.html

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<html lang="en">
44
<head>
55
<!-- Generated by javadoc (9.0.4) on Wed Mar 07 11:29:56 EST 2018 -->
6-
<title>Uses of Interface oracle.kubernetes.operator.watcher.WatchingEventDestination (weblogic-kubernetes-operator 0.1.0 API)</title>
6+
<title>Uses of Interface oracle.kubernetes.operator.watcher.WatchListener (weblogic-kubernetes-operator 0.1.0 API)</title>
77
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
88
<meta name="date" content="2018-03-07">
99
<link rel="stylesheet" type="text/css" href="../../../../../stylesheet.css" title="Style">
@@ -21,13 +21,12 @@
2121
<script type="text/javascript"><!--
2222
try {
2323
if (location.href.indexOf('is-external=true') == -1) {
24-
parent.document.title="Uses of Interface oracle.kubernetes.operator.watcher.WatchingEventDestination (weblogic-kubernetes-operator 0.1.0 API)";
24+
parent.document.title="Uses of Interface oracle.kubernetes.operator.watcher.WatchListener (weblogic-kubernetes-operator 0.1.0 API)";
2525
}
2626
}
2727
catch(err) {
2828
}
29-
//-->
30-
var pathtoroot = "../../../../../";loadScripts(document, 'script');</script>
29+
//--></script>
3130
<noscript>
3231
<div>JavaScript is disabled on your browser.</div>
3332
</noscript>
@@ -95,7 +94,7 @@
9594
//-->
9695
</script>
9796
<div class="header">
98-
<h2 title="Uses of Interface oracle.kubernetes.operator.watcher.WatchingEventDestination" class="title">Uses of Interface<br>oracle.kubernetes.operator.watcher.WatchingEventDestination</h2>
97+
<h2 title="Uses of Interface oracle.kubernetes.operator.watcher.WatchListener" class="title">Uses of Interface<br>oracle.kubernetes.operator.watcher.WatchingEventDestination</h2>
9998
</div>
10099
<div class="classUseContainer">
101100
<ul class="blockList">

pom.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,9 @@
140140
<artifactId>maven-compiler-plugin</artifactId>
141141
<version>3.7.0</version>
142142
<configuration>
143-
<!-- none yet -->
143+
<compilerArgs>
144+
<arg>-Xpkginfo:always</arg>
145+
</compilerArgs>
144146
</configuration>
145147
</plugin>
146148

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

Lines changed: 12 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -5,93 +5,34 @@
55

66
import io.kubernetes.client.ApiException;
77
import io.kubernetes.client.models.V1ConfigMap;
8-
import io.kubernetes.client.util.Watch;
98
import oracle.kubernetes.operator.builders.WatchBuilder;
109
import oracle.kubernetes.operator.builders.WatchI;
11-
import oracle.kubernetes.operator.helpers.ClientHelper;
12-
import oracle.kubernetes.operator.helpers.ClientHolder;
13-
import oracle.kubernetes.operator.watcher.Watcher;
14-
import oracle.kubernetes.operator.watcher.Watching;
15-
import oracle.kubernetes.operator.watcher.WatchingEventDestination;
10+
import oracle.kubernetes.operator.watcher.WatchListener;
1611

1712
import java.util.concurrent.atomic.AtomicBoolean;
1813

1914
/**
2015
* This class handles ConfigMap watching. It receives config map change events and sends
2116
* them into the operator for processing.
2217
*/
23-
public class ConfigMapWatcher implements Runnable {
18+
public class ConfigMapWatcher extends Watcher<V1ConfigMap> {
2419
private final String ns;
25-
private final String initialResourceVersion;
26-
private final WatchingEventDestination<V1ConfigMap> destination;
27-
private final AtomicBoolean isStopping;
28-
29-
public static ConfigMapWatcher create(String ns, String initialResourceVersion, WatchingEventDestination<V1ConfigMap> destination, AtomicBoolean isStopping) {
30-
ConfigMapWatcher dlw = new ConfigMapWatcher(ns, initialResourceVersion, destination, isStopping);
31-
Thread thread = new Thread(dlw);
32-
thread.setName("Thread-ConfigMapWatcher-" + ns);
33-
thread.setDaemon(true);
34-
thread.start();
35-
return dlw;
20+
21+
public static ConfigMapWatcher create(String ns, String initialResourceVersion, WatchListener<V1ConfigMap> listener, AtomicBoolean isStopping) {
22+
ConfigMapWatcher watcher = new ConfigMapWatcher(ns, initialResourceVersion, listener, isStopping);
23+
watcher.start("Thread-ConfigMapWatcher-" + ns);
24+
return watcher;
3625
}
3726

38-
private ConfigMapWatcher(String ns, String initialResourceVersion, WatchingEventDestination<V1ConfigMap> destination, AtomicBoolean isStopping) {
27+
private ConfigMapWatcher(String ns, String initialResourceVersion, WatchListener<V1ConfigMap> listener, AtomicBoolean isStopping) {
28+
super(initialResourceVersion, isStopping, listener);
3929
this.ns = ns;
40-
this.initialResourceVersion = initialResourceVersion;
41-
this.destination = destination;
42-
this.isStopping = isStopping;
4330
}
4431

45-
/**
46-
* Polling loop. Get the next ConfigMap object event and process it.
47-
*/
4832
@Override
49-
public void run() {
50-
ClientHelper helper = ClientHelper.getInstance();
51-
ClientHolder client = helper.take();
52-
try {
53-
Watching<V1ConfigMap> w = createWatching(client);
54-
Watcher<V1ConfigMap> watcher = new Watcher<>(w, initialResourceVersion);
55-
56-
// invoke watch on current Thread. Won't return until watch stops
57-
watcher.doWatch();
58-
59-
} finally {
60-
helper.recycle(client);
61-
}
33+
public WatchI<V1ConfigMap> initiateWatch(WatchBuilder watchBuilder) throws ApiException {
34+
return watchBuilder.withLabelSelector(LabelConstants.CREATEDBYOPERATOR_LABEL)
35+
.createConfigMapWatch(ns);
6236
}
63-
64-
protected Watching<V1ConfigMap> createWatching(ClientHolder client) {
65-
return new Watching<V1ConfigMap>() {
66-
67-
/**
68-
* Watcher callback to issue the list ConfigMap changes. It is driven by the
69-
* Watcher wrapper to issue repeated watch requests.
70-
* @param resourceVersion resource version to omit older events
71-
* @return Watch object or null if the operation should end
72-
* @throws ApiException if there is an API error.
73-
*/
74-
@Override
75-
public WatchI<V1ConfigMap> initiateWatch(String resourceVersion) throws ApiException {
76-
return new WatchBuilder(client)
77-
.withResourceVersion(resourceVersion)
78-
.withLabelSelector(LabelConstants.CREATEDBYOPERATOR_LABEL)
79-
.createConfigMapWatch(ns);
80-
}
81-
82-
@Override
83-
public void eventCallback(Watch.Response<V1ConfigMap> item) {
84-
processEventCallback(item);
85-
}
8637

87-
@Override
88-
public boolean isStopping() {
89-
return isStopping.get();
90-
}
91-
};
92-
}
93-
94-
public void processEventCallback(Watch.Response<V1ConfigMap> item) {
95-
destination.eventCallback(item);
96-
}
9738
}

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

Lines changed: 11 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -4,93 +4,34 @@
44
package oracle.kubernetes.operator;
55

66
import io.kubernetes.client.ApiException;
7-
import io.kubernetes.client.util.Watch;
87
import oracle.kubernetes.operator.builders.WatchBuilder;
98
import oracle.kubernetes.operator.builders.WatchI;
9+
import oracle.kubernetes.operator.watcher.WatchListener;
1010
import oracle.kubernetes.weblogic.domain.v1.Domain;
11-
import oracle.kubernetes.operator.helpers.ClientHelper;
12-
import oracle.kubernetes.operator.helpers.ClientHolder;
13-
import oracle.kubernetes.operator.watcher.Watcher;
14-
import oracle.kubernetes.operator.watcher.Watching;
15-
import oracle.kubernetes.operator.watcher.WatchingEventDestination;
1611

1712
import java.util.concurrent.atomic.AtomicBoolean;
1813

1914
/**
2015
* This class handles Domain watching. It receives domain events and sends
2116
* them into the operator for processing.
2217
*/
23-
public class DomainWatcher implements Runnable {
18+
public class DomainWatcher extends Watcher<Domain> {
2419
private final String ns;
25-
private final String initialResourceVersion;
26-
private final WatchingEventDestination<Domain> destination;
27-
private final AtomicBoolean isStopping;
28-
29-
public static DomainWatcher create(String ns, String initialResourceVersion, WatchingEventDestination<Domain> destination, AtomicBoolean isStopping) {
30-
DomainWatcher dlw = new DomainWatcher(ns, initialResourceVersion, destination, isStopping);
31-
Thread thread = new Thread(dlw);
32-
thread.setName("Thread-DomainWatcher-" + ns);
33-
thread.setDaemon(true);
34-
thread.start();
35-
return dlw;
20+
21+
public static DomainWatcher create(String ns, String initialResourceVersion, WatchListener<Domain> listener, AtomicBoolean isStopping) {
22+
DomainWatcher watcher = new DomainWatcher(ns, initialResourceVersion, listener, isStopping);
23+
watcher.start("Thread-DomainWatcher-" + ns);
24+
return watcher;
3625
}
3726

38-
private DomainWatcher(String ns, String initialResourceVersion, WatchingEventDestination<Domain> destination, AtomicBoolean isStopping) {
27+
private DomainWatcher(String ns, String initialResourceVersion, WatchListener<Domain> listener, AtomicBoolean isStopping) {
28+
super(initialResourceVersion, isStopping, listener);
3929
this.ns = ns;
40-
this.initialResourceVersion = initialResourceVersion;
41-
this.destination = destination;
42-
this.isStopping = isStopping;
4330
}
4431

45-
/**
46-
* Polling loop. Get the next Domain object event and process it.
47-
*/
4832
@Override
49-
public void run() {
50-
ClientHelper helper = ClientHelper.getInstance();
51-
ClientHolder client = helper.take();
52-
try {
53-
Watching<Domain> w = createWatching(client);
54-
Watcher<Domain> watcher = new Watcher<>(w, initialResourceVersion);
55-
56-
// invoke watch on current Thread. Won't return until watch stops
57-
watcher.doWatch();
58-
59-
} finally {
60-
helper.recycle(client);
61-
}
33+
public WatchI<Domain> initiateWatch(WatchBuilder watchBuilder) throws ApiException {
34+
return watchBuilder.createDomainWatch(ns);
6235
}
63-
64-
protected Watching<Domain> createWatching(ClientHolder client) {
65-
return new Watching<Domain>() {
66-
67-
/**
68-
* Watcher callback to issue the list Domain changes. It is driven by the
69-
* Watcher wrapper to issue repeated watch requests.
70-
* @param resourceVersion resource version to omit older events
71-
* @return Watch object or null if the operation should end
72-
* @throws ApiException if there is an API error.
73-
*/
74-
@Override
75-
public WatchI<Domain> initiateWatch(String resourceVersion) throws ApiException {
76-
return new WatchBuilder(client)
77-
.withResourceVersion(resourceVersion)
78-
.createDomainWatch(ns);
79-
}
80-
81-
@Override
82-
public void eventCallback(Watch.Response<Domain> item) {
83-
processEventCallback(item);
84-
}
8536

86-
@Override
87-
public boolean isStopping() {
88-
return isStopping.get();
89-
}
90-
};
91-
}
92-
93-
public void processEventCallback(Watch.Response<Domain> item) {
94-
destination.eventCallback(item);
95-
}
9637
}

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

Lines changed: 15 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,9 @@
66
import io.kubernetes.client.ApiException;
77
import io.kubernetes.client.models.V1ObjectMeta;
88
import io.kubernetes.client.models.V1beta1Ingress;
9-
import io.kubernetes.client.util.Watch;
10-
import oracle.kubernetes.operator.builders.WatchI;
11-
import oracle.kubernetes.operator.helpers.ClientHelper;
12-
import oracle.kubernetes.operator.helpers.ClientHolder;
139
import oracle.kubernetes.operator.builders.WatchBuilder;
14-
import oracle.kubernetes.operator.watcher.Watcher;
15-
import oracle.kubernetes.operator.watcher.Watching;
16-
import oracle.kubernetes.operator.watcher.WatchingEventDestination;
10+
import oracle.kubernetes.operator.builders.WatchI;
11+
import oracle.kubernetes.operator.watcher.WatchListener;
1712

1813
import java.util.Map;
1914
import java.util.concurrent.atomic.AtomicBoolean;
@@ -22,78 +17,27 @@
2217
* This class handles Ingress watching. It receives Ingress change events and sends
2318
* them into the operator for processing.
2419
*/
25-
public class IngressWatcher implements Runnable {
20+
public class IngressWatcher extends Watcher<V1beta1Ingress> {
2621
private final String ns;
27-
private final String initialResourceVersion;
28-
private final WatchingEventDestination<V1beta1Ingress> destination;
29-
private final AtomicBoolean isStopping;
30-
31-
public static IngressWatcher create(String ns, String initialResourceVersion, WatchingEventDestination<V1beta1Ingress> destination, AtomicBoolean isStopping) {
32-
IngressWatcher dlw = new IngressWatcher(ns, initialResourceVersion, destination, isStopping);
33-
Thread thread = new Thread(dlw);
34-
thread.setName("Thread-IngressWatcher-" + ns);
35-
thread.setDaemon(true);
36-
thread.start();
37-
return dlw;
22+
23+
public static IngressWatcher create(String ns, String initialResourceVersion, WatchListener<V1beta1Ingress> listener, AtomicBoolean isStopping) {
24+
IngressWatcher watcher = new IngressWatcher(ns, initialResourceVersion, listener, isStopping);
25+
watcher.start("Thread-IngressWatcher-" + ns);
26+
return watcher;
3827
}
3928

40-
private IngressWatcher(String ns, String initialResourceVersion, WatchingEventDestination<V1beta1Ingress> destination, AtomicBoolean isStopping) {
29+
private IngressWatcher(String ns, String initialResourceVersion, WatchListener<V1beta1Ingress> listener, AtomicBoolean isStopping) {
30+
super(initialResourceVersion, isStopping, listener);
4131
this.ns = ns;
42-
this.initialResourceVersion = initialResourceVersion;
43-
this.destination = destination;
44-
this.isStopping = isStopping;
4532
}
4633

47-
/**
48-
* Polling loop. Get the next Ingress object event and process it.
49-
*/
5034
@Override
51-
public void run() {
52-
ClientHelper helper = ClientHelper.getInstance();
53-
ClientHolder client = helper.take();
54-
try {
55-
Watching<V1beta1Ingress> w = createWatching(client);
56-
Watcher<V1beta1Ingress> watcher = new Watcher<>(w, initialResourceVersion);
57-
58-
// invoke watch on current Thread. Won't return until watch stops
59-
watcher.doWatch();
60-
61-
} finally {
62-
helper.recycle(client);
63-
}
35+
public WatchI<V1beta1Ingress> initiateWatch(WatchBuilder watchBuilder) throws ApiException {
36+
return watchBuilder
37+
.withLabelSelectors(LabelConstants.DOMAINUID_LABEL, LabelConstants.CREATEDBYOPERATOR_LABEL)
38+
.createIngressWatch(ns);
6439
}
65-
66-
protected Watching<V1beta1Ingress> createWatching(ClientHolder client) {
67-
return new Watching<V1beta1Ingress>() {
68-
69-
/**
70-
* Watcher callback to issue the list Ingress changes. It is driven by the
71-
* Watcher wrapper to issue repeated watch requests.
72-
* @param resourceVersion resource version to omit older events
73-
* @return Watch object or null if the operation should end
74-
* @throws ApiException if there is an API error.
75-
*/
76-
@Override
77-
public WatchI<V1beta1Ingress> initiateWatch(String resourceVersion) throws ApiException {
78-
return new WatchBuilder(client)
79-
.withResourceVersion(resourceVersion)
80-
.withLabelSelector(LabelConstants.DOMAINUID_LABEL
81-
+ "," + LabelConstants.CREATEDBYOPERATOR_LABEL)
82-
.createIngressWatch(ns);
83-
}
8440

85-
@Override
86-
public void eventCallback(Watch.Response<V1beta1Ingress> item) {
87-
processEventCallback(item);
88-
}
89-
90-
@Override
91-
public boolean isStopping() {
92-
return isStopping.get();
93-
}
94-
};
95-
}
96-
9741
static String getIngressDomainUID(V1beta1Ingress ingress) {
9842
V1ObjectMeta meta = ingress.getMetadata();
9943
Map<String, String> labels = meta.getLabels();
@@ -111,8 +55,5 @@ static String getIngressClusterName(V1beta1Ingress ingress) {
11155
}
11256
return null;
11357
}
114-
115-
public void processEventCallback(Watch.Response<V1beta1Ingress> item) {
116-
destination.eventCallback(item);
117-
}
58+
11859
}

0 commit comments

Comments
 (0)