Skip to content

Commit 5ac0155

Browse files
committed
Merge remote-tracking branch 'origin/develop' into domain-introspector
2 parents ab65691 + e89c2f4 commit 5ac0155

File tree

6 files changed

+63
-47
lines changed

6 files changed

+63
-47
lines changed

integration-tests/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,12 @@ mvn -Dit.test="ITOperator#test6CreateConfiguredDomainInTest2NS" -DfailIfNoTests=
268268

269269
mvn -Dit.test="ITOperator#test6CreateConfiguredDomainInTest2NS+test7CreateDomainPVReclaimPolicyRecycle" -DfailIfNoTests=false integration-test -P java-integration-tests
270270

271+
# How to run cleanup script
272+
273+
cleanup script deletes the k8s artifacts, local test tmp directory, delete all helm charts and the potentially remote domain pv directories.
274+
cd weblogic-kubernetes-operator
275+
src/integration-tests/bash/cleanup.sh
276+
271277
# Logging/Archiving
272278

273279
Java utils logging is used, writes all the messages to console and java_test_suite.out in $RESULT_ROOT/acceptance_test_tmp directory.

integration-tests/src/test/java/oracle/kubernetes/operator/ITOperator.java

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ public void test1CreateFirstOperatorAndDomain() throws Exception {
9494
logTestBegin("test1CreateFirstOperatorAndDomain");
9595
testCreateOperatorManagingDefaultAndTest1NS();
9696
domain1 = testAllUseCasesForADomain(operator1, domain1YamlFile);
97+
domain1.testWlsLivenessProbe();
98+
domain1.destroy();
99+
97100
logger.info("SUCCESS - test1CreateFirstOperatorAndDomain");
98101
}
99102

@@ -128,6 +131,7 @@ public void test3CreateDomainInTest1NS() throws Exception {
128131
// create domain3
129132
Domain domain3 = testDomainCreation(domain3YamlFile);
130133
testWLDFScaling(operator1, domain3);
134+
domain3.destroy();
131135
logger.info("SUCCESS - test3CreateDomainInTest1NS");
132136
}
133137

@@ -157,6 +161,8 @@ public void test5CreateConfiguredDomainInTest2NS() throws Exception {
157161
}
158162
if (domain1 == null) {
159163
domain1 = TestUtils.createDomain(domain1YamlFile);
164+
} else {
165+
domain1.create();
160166
}
161167
logger.info("Checking if operator2 is running, if not creating");
162168
if (operator2 == null) {
@@ -179,6 +185,8 @@ public void test5CreateConfiguredDomainInTest2NS() throws Exception {
179185

180186
logger.info("Verify no impact on domain4");
181187
domain4.verifyDomainCreated();
188+
domain4.destroy();
189+
domain1.destroy();
182190
logger.info("SUCCESS - test5CreateConfiguredDomainInTest2NS");
183191
}
184192

@@ -194,7 +202,8 @@ public void test6CreateDomainWithStartPolicyAdminOnly() throws Exception {
194202
}
195203
logger.info("Creating Domain domain5 & verifing the domain creation");
196204
// create domain5
197-
TestUtils.createDomain(domain5YamlFile);
205+
Domain domain5 = TestUtils.createDomain(domain5YamlFile);
206+
domain5.destroy();
198207
logger.info("SUCCESS - test6CreateDomainWithStartPolicyAdminOnly");
199208
}
200209

@@ -216,25 +225,6 @@ public void test7CreateDomainPVReclaimPolicyRecycle() throws Exception {
216225
logger.info("SUCCESS - test7CreateDomainPVReclaimPolicyRecycle");
217226
}
218227

219-
@Test
220-
public void test8WlsLivenessProbe() throws Exception {
221-
222-
logTestBegin("test8WlsLivenessProbe");
223-
logger.info("Checking if operator1 is running, if not creating");
224-
if (operator1 == null) {
225-
operator1 = TestUtils.createOperator(op1YamlFile);
226-
}
227-
if (domain1 == null) {
228-
domain1 = TestUtils.createDomain(domain1YamlFile);
229-
}
230-
// test managed server1 pod auto restart
231-
String domain = domain1.getDomainUid();
232-
String namespace = domain1.getDomainMap().get("namespace").toString();
233-
String serverName = domain1.getDomainMap().get("managedServerNameBase").toString() + "1";
234-
TestUtils.testWlsLivenessProbe(domain, serverName, namespace);
235-
logger.info("SUCCESS - test8WlsLivenessProbe");
236-
}
237-
238228
@Test
239229
public void test9CreateDomainOnExistingDir() throws Exception {
240230
Assume.assumeFalse(
@@ -246,10 +236,10 @@ public void test9CreateDomainOnExistingDir() throws Exception {
246236
}
247237
if (domain1 == null) {
248238
domain1 = TestUtils.createDomain(domain1YamlFile);
239+
// create domain on existing dir
240+
domain1.destroy();
249241
}
250242
logger.info("domain1 " + domain1);
251-
// create domain on existing dir
252-
domain1.destroy();
253243
domain1.createDomainOnExistingDirectory();
254244
logger.info("SUCCESS - test9CreateDomainOnExistingDir");
255245
}
@@ -267,6 +257,7 @@ public void testACreateDomainApacheLB() throws Exception {
267257
// create domain7
268258
Domain domain7 = TestUtils.createDomain(domain7YamlFile);
269259
domain7.verifyAdminConsoleViaLB();
260+
domain7.destroy();
270261
logger.info("SUCCESS - testACreateDomainApacheLB");
271262
}
272263

@@ -281,7 +272,8 @@ public void testBCreateDomainWithDefaultValuesInSampleInputs() throws Exception
281272
}
282273

283274
// create domain8
284-
testAllUseCasesForADomain(operator1, domain8YamlFile);
275+
Domain domain8 = testAllUseCasesForADomain(operator1, domain8YamlFile);
276+
domain8.destroy();
285277
logger.info("SUCCESS - testBCreateDomainWithDefaultValuesInSampleInputs");
286278
}
287279

integration-tests/src/test/java/oracle/kubernetes/operator/utils/Domain.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,13 @@ public String getDomainUid() {
510510
return domainUid;
511511
}
512512

513+
public void testWlsLivenessProbe() throws Exception {
514+
515+
// test managed server1 pod auto restart
516+
String serverName = managedServerNameBase + "1";
517+
TestUtils.testWlsLivenessProbe(domainUid, serverName, domainNS);
518+
}
519+
513520
private int getAdminSericeLBNodePort() throws Exception {
514521

515522
String adminServerLBNodePortService = domainUid + "-apache-webtier";

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

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@
2929
abstract class Watcher<T> {
3030
static final String HAS_NEXT_EXCEPTION_MESSAGE = "IO Exception during hasNext method.";
3131
private static final LoggingFacade LOGGER = LoggingFactory.getLogger("Operator", "Operator");
32-
private static final String IGNORED_RESOURCE_VERSION = "0";
32+
private static final long IGNORED_RESOURCE_VERSION = 0;
3333

3434
private final AtomicBoolean isDraining = new AtomicBoolean(false);
35-
private String resourceVersion;
35+
private Long resourceVersion;
3636
private AtomicBoolean stopping;
3737
private WatchListener<T> listener;
3838
private Thread thread = null;
@@ -45,7 +45,8 @@ abstract class Watcher<T> {
4545
* @param stopping an atomic boolean to watch to determine when to stop the watcher
4646
*/
4747
Watcher(String resourceVersion, AtomicBoolean stopping) {
48-
this.resourceVersion = resourceVersion;
48+
this.resourceVersion =
49+
!isNullOrEmptyString(resourceVersion) ? Long.parseLong(resourceVersion) : 0;
4950
this.stopping = stopping;
5051
}
5152

@@ -110,7 +111,8 @@ protected boolean isStopping() {
110111
}
111112

112113
private void watchForEvents() {
113-
try (WatchI<T> watch = initiateWatch(new WatchBuilder().withResourceVersion(resourceVersion))) {
114+
try (WatchI<T> watch =
115+
initiateWatch(new WatchBuilder().withResourceVersion(resourceVersion.toString()))) {
114116
while (watch.hasNext()) {
115117
Watch.Response<T> item = watch.next();
116118

@@ -139,9 +141,11 @@ private boolean isError(Watch.Response<T> item) {
139141
}
140142

141143
private void handleRegularUpdate(Watch.Response<T> item) {
142-
LOGGER.fine(MessageKeys.WATCH_EVENT, item.type, item.object);
143-
trackResourceVersion(item.type, item.object);
144-
if (listener != null) listener.receivedResponse(item);
144+
if (isFresh(item.type, item.object)) {
145+
LOGGER.fine(MessageKeys.WATCH_EVENT, item.type, item.object);
146+
trackResourceVersion(item.type, item.object);
147+
if (listener != null) listener.receivedResponse(item);
148+
}
145149
}
146150

147151
private void handleErrorResponse(Watch.Response<T> item) {
@@ -152,7 +156,8 @@ private void handleErrorResponse(Watch.Response<T> item) {
152156
if (index1 > 0) {
153157
int index2 = message.indexOf(')', index1 + 1);
154158
if (index2 > 0) {
155-
resourceVersion = message.substring(index1 + 1, index2);
159+
String val = message.substring(index1 + 1, index2);
160+
resourceVersion = !isNullOrEmptyString(val) ? Long.parseLong(val) : 0;
156161
}
157162
}
158163
}
@@ -170,27 +175,34 @@ private void trackResourceVersion(String type, Object object) {
170175
updateResourceVersion(getNewResourceVersion(type, object));
171176
}
172177

173-
private String getNewResourceVersion(String type, Object object) {
174-
if (type.equalsIgnoreCase("DELETED"))
175-
return Integer.toString(1 + Integer.parseInt(resourceVersion));
178+
private long getNewResourceVersion(String type, Object object) {
179+
if (type.equalsIgnoreCase("DELETED")) return 1 + resourceVersion;
176180
else return getResourceVersionFromMetadata(object);
177181
}
178182

179-
private String getResourceVersionFromMetadata(Object object) {
183+
private long getResourceVersionFromMetadata(Object object) {
180184
try {
181185
Method getMetadata = object.getClass().getDeclaredMethod("getMetadata");
182186
V1ObjectMeta metadata = (V1ObjectMeta) getMetadata.invoke(object);
183-
return metadata.getResourceVersion();
187+
String val = metadata.getResourceVersion();
188+
return !isNullOrEmptyString(val) ? Long.parseLong(val) : 0;
184189
} catch (Exception e) {
185190
LOGGER.warning(MessageKeys.EXCEPTION, e);
186191
return IGNORED_RESOURCE_VERSION;
187192
}
188193
}
189194

190-
private void updateResourceVersion(String newResourceVersion) {
191-
if (isNullOrEmptyString(resourceVersion)) resourceVersion = newResourceVersion;
192-
else if (newResourceVersion.compareTo(resourceVersion) > 0)
193-
resourceVersion = newResourceVersion;
195+
private boolean isFresh(String type, Object object) {
196+
if (resourceVersion == 0) return true;
197+
long newResourceVersion = getResourceVersionFromMetadata(object);
198+
return type.equalsIgnoreCase("DELETED")
199+
? newResourceVersion >= resourceVersion
200+
: newResourceVersion > resourceVersion;
201+
}
202+
203+
private void updateResourceVersion(long newResourceVersion) {
204+
if (resourceVersion == 0) resourceVersion = newResourceVersion;
205+
else if (newResourceVersion > resourceVersion) resourceVersion = newResourceVersion;
194206
}
195207

196208
private static boolean isNullOrEmptyString(String s) {

operator/src/test/java/oracle/kubernetes/operator/WatcherTestBase.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
package oracle.kubernetes.operator;
66

77
import static java.net.HttpURLConnection.HTTP_GONE;
8-
import static oracle.kubernetes.operator.builders.EventMatcher.addEvent;
98
import static oracle.kubernetes.operator.builders.EventMatcher.modifyEvent;
109
import static org.hamcrest.MatcherAssert.assertThat;
1110
import static org.hamcrest.Matchers.contains;
@@ -107,12 +106,13 @@ private Watch.Response createHttpGoneErrorResponse(int nextResourceVersion) {
107106
@SuppressWarnings({"unchecked", "rawtypes"})
108107
@Test
109108
public void receivedEvents_areSentToListeners() {
110-
Object object = createObjectWithMetaData();
111-
StubWatchFactory.addCallResponses(createAddResponse(object), createModifyResponse(object));
109+
Object object1 = createObjectWithMetaData();
110+
Object object2 = createObjectWithMetaData();
111+
StubWatchFactory.addCallResponses(createAddResponse(object1), createModifyResponse(object2));
112112

113113
createAndRunWatcher(NAMESPACE, stopping, INITIAL_RESOURCE_VERSION);
114114

115-
assertThat(callBacks, contains(addEvent(object), modifyEvent(object)));
115+
assertThat(callBacks, contains(modifyEvent(object2)));
116116
}
117117

118118
@SuppressWarnings({"rawtypes", "unchecked"})
@@ -121,15 +121,14 @@ public void afterFirstSetOfEvents_nextRequestSendsLastResourceVersion() {
121121
Object object1 = createObjectWithMetaData();
122122
Object object2 = createObjectWithMetaData();
123123
Watch.Response[] firstSet = {createAddResponse(object1), createModifyResponse(object2)};
124-
int resourceAfterFirstSet = resourceVersion - 1;
125124
StubWatchFactory.addCallResponses(firstSet);
126125
scheduleAddResponse(createObjectWithMetaData());
127126

128127
createAndRunWatcher(NAMESPACE, stopping, INITIAL_RESOURCE_VERSION);
129128

130129
assertThat(
131130
StubWatchFactory.getRequestParameters().get(1),
132-
hasEntry("resourceVersion", Integer.toString(resourceAfterFirstSet)));
131+
hasEntry("resourceVersion", String.valueOf(resourceVersion - 2)));
133132
}
134133

135134
@SuppressWarnings({"unchecked", "rawtypes"})

wercker.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ integration-test-java:
181181
goals: clean verify
182182
version: 3.5.2
183183
profiles: java-integration-tests
184-
184+
185185
after-steps:
186186
- script:
187187
name: cleanup and store

0 commit comments

Comments
 (0)