Skip to content

Commit 8842add

Browse files
committed
Added more tests
1 parent 7b83b11 commit 8842add

File tree

2 files changed

+160
-60
lines changed

2 files changed

+160
-60
lines changed

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

Lines changed: 118 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Copyright 2019, Oracle Corporation and/or its affiliates. All rights reserved.
22
// Licensed under the Universal Permissive License v 1.0 as shown at
33
// http://oss.oracle.com/licenses/upl.
4-
54
package oracle.kubernetes.operator;
65

76
import java.nio.charset.Charset;
@@ -322,35 +321,147 @@ public void testServerPodsRestartByChangingResource() throws Exception {
322321
}
323322

324323
@Test
325-
public void testAdminServerRestartVersions() throws Exception {
324+
public void testAdminServerRestartVersion() throws Exception {
326325
Assume.assumeFalse(QUICKTEST);
327326
String testMethodName = new Object() {}.getClass().getEnclosingMethod().getName();
328327
logTestBegin(testMethodName);
329-
330328
try {
331-
logger.info("Modifying the Domain CRD..");
329+
// Modify the original domain yaml to include restartVersion in admin server node
332330
DomainCRD crd = new DomainCRD(originalYaml);
333331
Map<String, String> admin = new HashMap();
334332
admin.put("restartVersion", "v1.1");
335333
crd.addObjectNodeToAdminServer(admin);
336334
String modYaml = crd.getYamlTree();
337335
logger.info(modYaml);
336+
337+
// Write the modified yaml to a new file
338338
Path path = Paths.get(restartTmpDir, "restart.admin.yaml");
339339
logger.log(Level.INFO, "Path of the modified domain.yaml :{0}", path.toString());
340340
Charset charset = StandardCharsets.UTF_8;
341341
Files.write(path, modYaml.getBytes(charset));
342-
logger.log(Level.INFO, "Running kubectl apply -f {0}", path.toString());
342+
343+
// Apply the new yaml to update the domain crd
344+
logger.log(Level.INFO, "kubectl apply -f {0}", path.toString());
343345
ExecResult exec = TestUtils.exec("kubectl apply -f " + path.toString());
344346
logger.info(exec.stdout());
345347
logger.info("Verifying if the admin server is restarted");
346348
domain.verifyAdminServerRestarted();
347349
} finally {
348-
logger.log(Level.INFO, "Running kubectl apply -f {0}", originalYaml);
350+
logger.log(
351+
Level.INFO, "Reverting back the domain to old crd\n kubectl apply -f {0}", originalYaml);
349352
TestUtils.exec("kubectl apply -f " + originalYaml);
350353
logger.info("Verifying if the admin server is restarted");
351354
domain.verifyAdminServerRestarted();
352355
}
353-
logger.info("SUCCESS - " + testMethodName);
356+
logger.log(Level.INFO, "SUCCESS - {0}", testMethodName);
357+
}
358+
359+
@Test
360+
public void testClusterRestartVersion() throws Exception {
361+
Assume.assumeFalse(QUICKTEST);
362+
String testMethodName = new Object() {}.getClass().getEnclosingMethod().getName();
363+
logTestBegin(testMethodName);
364+
try {
365+
// Modify the original domain yaml to include restartVersion in admin server node
366+
DomainCRD crd = new DomainCRD(originalYaml);
367+
Map<String, String> cluster = new HashMap();
368+
cluster.put("restartVersion", "v1.1");
369+
crd.addObjectNodeToCluster("cluster-1", cluster);
370+
String modYaml = crd.getYamlTree();
371+
logger.info(modYaml);
372+
373+
// Write the modified yaml to a new file
374+
Path path = Paths.get(restartTmpDir, "restart.cluster.yaml");
375+
logger.log(Level.INFO, "Path of the modified domain.yaml :{0}", path.toString());
376+
Charset charset = StandardCharsets.UTF_8;
377+
Files.write(path, modYaml.getBytes(charset));
378+
379+
// Apply the new yaml to update the domain crd
380+
logger.log(Level.INFO, "kubectl apply -f {0}", path.toString());
381+
ExecResult exec = TestUtils.exec("kubectl apply -f " + path.toString());
382+
logger.info(exec.stdout());
383+
logger.info("Verifying if the cluster is restarted");
384+
// Pending
385+
} finally {
386+
logger.log(
387+
Level.INFO, "Reverting back the domain to old crd\n kubectl apply -f {0}", originalYaml);
388+
TestUtils.exec("kubectl apply -f " + originalYaml);
389+
logger.info("Verifying if the cluster is restarted");
390+
// Pending
391+
}
392+
logger.log(Level.INFO, "SUCCESS - {0}", testMethodName);
393+
}
394+
395+
@Test
396+
public void testMSRestartVersion() throws Exception {
397+
Assume.assumeFalse(QUICKTEST);
398+
String testMethodName = new Object() {}.getClass().getEnclosingMethod().getName();
399+
logTestBegin(testMethodName);
400+
try {
401+
// Modify the original domain yaml to include restartVersion in admin server node
402+
DomainCRD crd = new DomainCRD(originalYaml);
403+
Map<String, String> ms = new HashMap();
404+
ms.put("restartVersion", "v1.1");
405+
crd.addObjectNodeToMS("managed-server1", ms);
406+
String modYaml = crd.getYamlTree();
407+
logger.info(modYaml);
408+
409+
// Write the modified yaml to a new file
410+
Path path = Paths.get(restartTmpDir, "restart.managed.yaml");
411+
logger.log(Level.INFO, "Path of the modified domain.yaml :{0}", path.toString());
412+
Charset charset = StandardCharsets.UTF_8;
413+
Files.write(path, modYaml.getBytes(charset));
414+
415+
// Apply the new yaml to update the domain crd
416+
logger.log(Level.INFO, "kubectl apply -f {0}", path.toString());
417+
ExecResult exec = TestUtils.exec("kubectl apply -f " + path.toString());
418+
logger.info(exec.stdout());
419+
logger.info("Verifying if the managed server is restarted");
420+
// Pending
421+
} finally {
422+
logger.log(
423+
Level.INFO, "Reverting back the domain to old crd\n kubectl apply -f {0}", originalYaml);
424+
TestUtils.exec("kubectl apply -f " + originalYaml);
425+
logger.info("Verifying if the managed server is restarted");
426+
// Pending
427+
}
428+
logger.log(Level.INFO, "SUCCESS - {0}", testMethodName);
429+
}
430+
431+
@Test
432+
public void testDomainRestartVersion() throws Exception {
433+
Assume.assumeFalse(QUICKTEST);
434+
String testMethodName = new Object() {}.getClass().getEnclosingMethod().getName();
435+
logTestBegin(testMethodName);
436+
try {
437+
// Modify the original domain yaml to include restartVersion in admin server node
438+
DomainCRD crd = new DomainCRD(originalYaml);
439+
Map<String, String> domain = new HashMap();
440+
domain.put("restartVersion", "v1.1");
441+
crd.addObjectNodeToDomain(domain);
442+
String modYaml = crd.getYamlTree();
443+
logger.info(modYaml);
444+
445+
// Write the modified yaml to a new file
446+
Path path = Paths.get(restartTmpDir, "restart.domain.yaml");
447+
logger.log(Level.INFO, "Path of the modified domain.yaml :{0}", path.toString());
448+
Charset charset = StandardCharsets.UTF_8;
449+
Files.write(path, modYaml.getBytes(charset));
450+
451+
// Apply the new yaml to update the domain crd
452+
logger.log(Level.INFO, "kubectl apply -f {0}", path.toString());
453+
ExecResult exec = TestUtils.exec("kubectl apply -f " + path.toString());
454+
logger.info(exec.stdout());
455+
logger.info("Verifying if the domain is restarted");
456+
// Pending
457+
} finally {
458+
logger.log(
459+
Level.INFO, "Reverting back the domain to old crd\n kubectl apply -f {0}", originalYaml);
460+
TestUtils.exec("kubectl apply -f " + originalYaml);
461+
logger.info("Verifying if the domain is restarted");
462+
// Pending
463+
}
464+
logger.log(Level.INFO, "SUCCESS - {0}", testMethodName);
354465
}
355466

356467
private static Domain createPodsRestartdomain() throws Exception {

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

Lines changed: 42 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import java.util.HashMap;
1818
import java.util.Map;
1919

20-
/** A Parser utility class to manipulate domain.yaml file */
20+
/** A Domain CRD utility class to manipulate domain yaml files */
2121
public class DomainCRD {
2222

2323
private final ObjectMapper objectMapper;
@@ -37,24 +37,24 @@ public static void main(String args[]) throws IOException {
3737
Map<String, String> cluster = new HashMap();
3838
cluster.put("restartVersion", "v1.1");
3939
crd.addObjectNodeToCluster("cluster-1", cluster);
40-
cluster = new HashMap();
41-
cluster.put("restartVersion2", "v1.2");
42-
crd.addObjectNodeToCluster("cluster-1", cluster);
4340
System.out.println(crd.getYamlTree());
4441

4542
Map<String, String> ms = new HashMap();
4643
ms.put("restartVersion", "v1.1");
47-
crd.addObjectNodeToMS("managedserver-1", ms);
48-
ms = new HashMap();
4944
ms.put("serverStartPolicy", "IF_NEEDED");
50-
crd.addObjectNodeToMS("managedserver-1", ms);
51-
ms = new HashMap();
5245
ms.put("serverStartState", "RUNNING");
5346
crd.addObjectNodeToMS("managedserver-1", ms);
5447

5548
System.out.println(crd.getYamlTree());
5649
}
5750

51+
/**
52+
* Constructor to read the yaml file and initialize the root JsonNode with yaml equivalent of JSON
53+
* tree
54+
*
55+
* @param yamlFile - Name of the yaml file containing the Domain CRD
56+
* @throws IOException
57+
*/
5858
public DomainCRD(String yamlFile) throws IOException {
5959
this.objectMapper = new ObjectMapper();
6060

@@ -66,20 +66,23 @@ public DomainCRD(String yamlFile) throws IOException {
6666
this.root = objectMapper.readTree(writeValueAsString);
6767
}
6868

69+
/**
70+
* To convert the JSON tree back into Yaml and return it as a String
71+
*
72+
* @return - Domain CRD in Yaml format
73+
* @throws JsonProcessingException when JSON tree cannot be converted as a Yaml string
74+
*/
6975
public String getYamlTree() throws JsonProcessingException {
7076
String jsonAsYaml = new YAMLMapper().writerWithDefaultPrettyPrinter().writeValueAsString(root);
7177
return jsonAsYaml;
7278
}
7379

7480
/**
75-
* A utility method to add restartVersion attribute to domain in domain.yaml
81+
* A utility method to add attributes to domain in domain.yaml
7682
*
77-
* @param key Object key to add as a String
78-
* @param value Version value for the restartVersion attribute
79-
* @return Yaml String with added restartVersion attribute in domain
80-
* @throws IOException
83+
* @param attributes - A HashMap of key value pairs
8184
*/
82-
public void addObjectNodeToDomain(Map<String, String> attributes) throws IOException {
85+
public void addObjectNodeToDomain(Map<String, String> attributes) {
8386
// modify admin server restartVersion
8487
JsonNode specNode = getSpecNode();
8588
for (Map.Entry<String, String> entry : attributes.entrySet()) {
@@ -88,74 +91,56 @@ public void addObjectNodeToDomain(Map<String, String> attributes) throws IOExcep
8891
}
8992

9093
/**
91-
* A utility method to add restartVersion attribute to administration server in domain.yaml
94+
* A utility method to add attributes to adminServer node in domain.yaml
9295
*
93-
* @param key Object key to add as a String
94-
* @param value Version value for the restartVersion attribute
95-
* @return Yaml String with added restartVersion attribute in administration server
96-
* @throws IOException
96+
* @param attributes - A HashMap of key value pairs
9797
*/
98-
public void addObjectNodeToAdminServer(Map<String, String> attributes) throws IOException {
99-
// modify admin server restartVersion
100-
JsonNode adminServerNode = getAdminServerNode(root);
98+
public void addObjectNodeToAdminServer(Map<String, String> attributes) {
99+
100+
JsonNode adminServerNode = getAdminServerNode();
101101
for (Map.Entry<String, String> entry : attributes.entrySet()) {
102102
((ObjectNode) adminServerNode).put(entry.getKey(), entry.getValue());
103103
}
104104
}
105105

106106
/**
107-
* A utility method to add restartVersion attribute to cluster in domain.yaml
107+
* A utility method to add attributes to cluster node in domain.yaml
108108
*
109-
* @param domainCRD String representation of the domain.yaml as JSON tree
110-
* @param ClusterName Name of the cluster in which to add the restartVersion attribute
111-
* @param version Version value for the restartVersion attribute
112-
* @return Yaml String with added restartVersion attribute in cluster
113-
* @throws IOException when the JSON tree cannot be read
109+
* @param ClusterName - Name of the cluster to which the attributes to be added
110+
* @param attributes - A HashMap of key value pairs
114111
*/
115-
public void addObjectNodeToCluster(String ClusterName, Map<String, String> attributes)
116-
throws IOException {
117-
// modify cluster restartVersion
112+
public void addObjectNodeToCluster(String ClusterName, Map<String, String> attributes) {
113+
118114
JsonNode clusterNode = getClusterNode(ClusterName);
119115
for (Map.Entry<String, String> entry : attributes.entrySet()) {
120116
((ObjectNode) clusterNode).put(entry.getKey(), entry.getValue());
121117
}
122118
}
123119

124120
/**
125-
* A utility method to add restartVersion attribute to managed server in domain.yaml
121+
* A utility method to add attributes to managed server node in domain.yaml
126122
*
127-
* @param domainCRD domainCRD String representation of the domain.yaml as JSON tree
128-
* @param managedServerName Name of the managed server in which to add the restartVersion
129-
* attribute
130-
* @param version Version value for the restartVersion attribute
131-
* @return Yaml String with added restartVersion attribute in managed server
132-
* @throws IOException when the JSON tree cannot be read
123+
* @param managedServerName - Name of the managed server to which the attributes to be added
124+
* @param attributes - A HashMap of key value pairs
133125
*/
134-
public void addObjectNodeToMS(String managedServerName, Map<String, String> attributes)
135-
throws IOException {
126+
public void addObjectNodeToMS(String managedServerName, Map<String, String> attributes) {
136127
JsonNode managedServerNode = getManagedServerNode(managedServerName);
137128
for (Map.Entry<String, String> entry : attributes.entrySet()) {
138129
((ObjectNode) managedServerNode).put(entry.getKey(), entry.getValue());
139130
}
140131
}
141132

142-
/**
143-
* Gets the spec node entry from Domain CRD JSON tree
144-
*
145-
* @param root - Root JSON node of the Domain CRD JSON tree
146-
* @return - spec node entry from Domain CRD JSON tree
147-
*/
133+
/** Gets the spec node entry from Domain CRD JSON tree */
148134
private JsonNode getSpecNode() {
149135
return root.path("spec");
150136
}
151137

152138
/**
153139
* Gets the administration server node entry from Domain CRD JSON tree
154140
*
155-
* @param root - Root JSON node of the Domain CRD JSON tree
156-
* @return - administration server node entry from Domain CRD JSON tree
141+
* @return
157142
*/
158-
private JsonNode getAdminServerNode(JsonNode root) {
143+
private JsonNode getAdminServerNode() {
159144
return root.path("spec").path("adminServer");
160145
}
161146

@@ -166,6 +151,12 @@ private JsonNode getAdminServerNode(JsonNode root) {
166151
* @param clusterName - Name of the cluster
167152
* @return - cluster node entry from Domain CRD JSON tree
168153
*/
154+
/**
155+
* Gets the cluster node entry from Domain CRD JSON tree for the given cluster name
156+
*
157+
* @param clusterName - Name of the cluster
158+
* @return - JsonNode of named cluster
159+
*/
169160
private JsonNode getClusterNode(String clusterName) {
170161
ArrayNode clusters = (ArrayNode) root.path("spec").path("clusters");
171162
JsonNode clusterNode = null;
@@ -181,10 +172,8 @@ private JsonNode getClusterNode(String clusterName) {
181172
/**
182173
* Gets the managed server node entry from Domain CRD JSON tree
183174
*
184-
* @param objectMapper - Instance of the ObjectMapper to use for creating a missing node
185-
* @param root - Root JSON node of the Domain CRD JSON tree
186-
* @param managedServerName - Name of the managed server for which to get the JSON node
187-
* @return administration server node entry from Domain CRD JSON tree
175+
* @param managedServerName Name of the managed server for which to get the JSON node
176+
* @return managed server node entry from Domain CRD JSON tree
188177
*/
189178
private JsonNode getManagedServerNode(String managedServerName) {
190179
ArrayNode managedservers = null;

0 commit comments

Comments
 (0)