From 51824d6a6dd3a0e43a5344885606e5956b44843b Mon Sep 17 00:00:00 2001 From: doxiao Date: Thu, 16 Apr 2020 13:23:48 +0000 Subject: [PATCH 01/69] Initial changes to test application update --- .../weblogic/kubernetes/ItWITValidation.java | 49 ++++++++++++++++++- .../kubernetes/actions/impl/AppBuilder.java | 23 +++++---- .../kubernetes/actions/impl/AppParams.java | 38 +++++++++++--- .../actions/impl/primitive/Command.java | 9 ++-- .../actions/impl/primitive/CommandParams.java | 25 ++++++++++ .../kubernetes/assertions/TestAssertions.java | 11 +++++ .../weblogic/kubernetes/utils/FileUtils.java | 18 +++++-- 7 files changed, 147 insertions(+), 26 deletions(-) diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItWITValidation.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItWITValidation.java index 9b5d3f29f77..aa403471003 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItWITValidation.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItWITValidation.java @@ -3,6 +3,7 @@ package oracle.weblogic.kubernetes; +import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -28,6 +29,7 @@ class ItWITValidation implements LoggedTest { private static final String WDT_MODEL_FILE = "model1-wls.yaml"; private static final String IMAGE_NAME = "test-mii-image-2"; private static final String IMAGE_TAG = "v1"; + private static final String IMAGE_TAG_V2 = "v2"; private static final String APP_NAME = "sample-app"; @@ -43,7 +45,7 @@ public void testCreatingMIIImage() { // build an application archive using what is in resources/apps/APP_NAME boolean archiveBuilt = buildAppArchive( defaultAppParams() - .srcDir(APP_NAME)); + .srcDirList(Collections.singletonList(APP_NAME))); assertThat(archiveBuilt) .as("Create an app archive") @@ -77,5 +79,50 @@ public void testCreatingMIIImage() { dockerImageExists(IMAGE_NAME, IMAGE_TAG); } + + @Test + @DisplayName("Create a MII image with a version 2 of the application") + public void testCreatingMIIImageWithAppVersion2() { + + // build the model file list + List modelList = Collections.singletonList(MODEL_DIR + "/" + WDT_MODEL_FILE); + + // build an application archive using what is in resources/apps/APP_NAME + boolean archiveBuilt = buildAppArchive( + defaultAppParams() + .srcDirList(Arrays.asList(APP_NAME, "sample-app-2"))); + + assertThat(archiveBuilt) + .as("Create an app archive") + .withFailMessage("Failed to create app archive for " + APP_NAME) + .isTrue(); + + // build the archive list + String zipFile = String.format("%s/%s.zip", ARCHIVE_DIR, APP_NAME); + List archiveList = Collections.singletonList(zipFile); + + // Set additional environment variables for WIT + checkDirectory(WIT_BUILD_DIR); + Map env = new HashMap(); + env.put("WLSIMG_BLDDIR", WIT_BUILD_DIR); + + // build an image using WebLogic Image Tool + boolean success = createMIIImage( + defaultWITParams() + .modelImageName(IMAGE_NAME) + .modelImageTag(IMAGE_TAG_V2) + .modelFiles(modelList) + .modelArchiveFiles(archiveList) + .wdtVersion("latest") + .env(env) + .redirect(true)); + + assertThat(success) + .as("Test the Docker image creation has succeeded") + .withFailMessage("Failed to create the image using WebLogic Image Tool") + .isTrue(); + + dockerImageExists(IMAGE_NAME, IMAGE_TAG_V2); + } } diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/AppBuilder.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/AppBuilder.java index d3d61b883f9..d34c2f5ac48 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/AppBuilder.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/AppBuilder.java @@ -6,11 +6,12 @@ import java.io.IOException; import oracle.weblogic.kubernetes.actions.impl.primitive.Command; +import oracle.weblogic.kubernetes.logging.LoggingFacade; +import oracle.weblogic.kubernetes.logging.LoggingFactory; import static oracle.weblogic.kubernetes.actions.ActionConstants.APP_DIR; import static oracle.weblogic.kubernetes.actions.ActionConstants.ARCHIVE_DIR; import static oracle.weblogic.kubernetes.actions.impl.primitive.Command.defaultCommandParams; -import static oracle.weblogic.kubernetes.extensions.LoggedTest.logger; import static oracle.weblogic.kubernetes.utils.FileUtils.checkDirectory; import static oracle.weblogic.kubernetes.utils.FileUtils.cleanupDirectory; import static oracle.weblogic.kubernetes.utils.FileUtils.copyFolder; @@ -20,6 +21,8 @@ */ public class AppBuilder { + private static final LoggingFacade logger = LoggingFactory.getLogger(AppBuilder.class); + private static final String ARCHIVE_SRC_DIR = ARCHIVE_DIR + "/wlsdeploy/applications"; private AppParams params; @@ -54,20 +57,22 @@ public boolean build() { try { cleanupDirectory(ARCHIVE_DIR); checkDirectory(ARCHIVE_SRC_DIR); - copyFolder( - APP_DIR + "/" + params.srcDir(), - ARCHIVE_SRC_DIR); - } catch (IOException ioe) { - logger.warning("Failed to get the directory " + ARCHIVE_DIR + " ready"); + for (String item: params.srcDirList()) { + copyFolder( + APP_DIR + "/" + item, + ARCHIVE_SRC_DIR); + } + } catch (IOException | RuntimeException e) { + logger.info("Failed to get the directory " + ARCHIVE_DIR + " ready", e); return false; } // build the app archive - String jarPath = String.format("%s.ear", params.srcDir()); + String jarPath = String.format("%s.ear", params.appName()); boolean jarBuilt = buildJarArchive(jarPath, ARCHIVE_SRC_DIR); // build a zip file that can be passed to WIT - String zipPath = String.format("%s/%s.zip", ARCHIVE_DIR, params.srcDir()); + String zipPath = String.format("%s/%s.zip", ARCHIVE_DIR, params.appName()); boolean zipBuilt = buildZipArchive(zipPath, ARCHIVE_DIR); return jarBuilt && zipBuilt; @@ -108,7 +113,7 @@ private boolean buildZipArchive( "cd %s ; zip %s wlsdeploy/applications/%s.ear ", srcDir, zipPath, - params.srcDir()); + params.appName()); return Command.withParams( defaultCommandParams() diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/AppParams.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/AppParams.java index 8337983d8b1..8185fada5f0 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/AppParams.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/AppParams.java @@ -3,30 +3,52 @@ package oracle.weblogic.kubernetes.actions.impl; +import java.util.List; + /** * Contains the parameters for creating an application archive. */ public class AppParams { - // Location of the source code. - // This is the name of the directory under resources/apps for an application - private String srcDir; + // Locations of the source code. + // This are the directory names under resources/apps for an application. + // Note: the order of the directory names are signaficant. Files are copied into + // the staging directory in the order that corresponds to the order that the + // directories are locates in the list. + private List srcDirList; + + // The name of the final ear file. + // When there is only one srcDir in the srcDirList, this is + // the name of that directory by default. + private String appName; // Whether the output of the command is redirected to system out private boolean redirect = true; - + public AppParams defaults() { return this; } - public AppParams srcDir(String srcDir) { - this.srcDir = srcDir; + public AppParams srcDirList(List srcDirList) { + this.srcDirList = srcDirList; + return this; + } + + public List srcDirList() { + return srcDirList; + } + + public AppParams appName(String appName) { + this.appName = appName; return this; } - public String srcDir() { - return srcDir; + public String appName() { + if (appName == null) { + return srcDirList.get(0); + } + return appName; } public AppParams redirect(boolean redirect) { diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/primitive/Command.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/primitive/Command.java index d5a38a610e3..387b535693a 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/primitive/Command.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/primitive/Command.java @@ -46,12 +46,15 @@ public boolean execute() { params.command(), params.redirect(), params.env()); + if (params.saveStdOut()) { + params.stdOut(result.stdout()); + } if (result.exitValue() != 0) { - logger.warning("The command execution failed with the result: {0}", result); + logger.severe("The command execution failed with the result: {0}", result); } return result.exitValue() == 0; - } catch (IOException | InterruptedException ie) { - logger.warning("The command execution failed due to {0}", ie.getMessage()); + } catch (IOException | InterruptedException e) { + logger.severe("The command execution failed", e); return false; } } diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/primitive/CommandParams.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/primitive/CommandParams.java index bbeccf097ae..efca5b67e9b 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/primitive/CommandParams.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/primitive/CommandParams.java @@ -20,6 +20,12 @@ public class CommandParams { // Whether the output of the command is redirected to system out private boolean redirect = true; + // Whether the stdout of the command needs to be saved + private boolean saveStdOut = false; + + // The stdout of the command run + private String stdOut; + public CommandParams defaults() { return this; } @@ -50,4 +56,23 @@ public CommandParams redirect(boolean redirect) { public boolean redirect() { return redirect; } + + public CommandParams saveStdOut(boolean saveStdOut) { + this.saveStdOut = saveStdOut; + return this; + } + + public boolean saveStdOut() { + return saveStdOut; + } + + public CommandParams stdOut(String stdOut) { + this.stdOut = stdOut; + return this; + } + + public String stdOut() { + return stdOut; + } + } diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/TestAssertions.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/TestAssertions.java index 882ef0d344a..526ecaaa507 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/TestAssertions.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/TestAssertions.java @@ -7,6 +7,7 @@ import java.util.concurrent.Callable; import io.kubernetes.client.openapi.ApiException; +import oracle.weblogic.kubernetes.assertions.impl.Application; import oracle.weblogic.kubernetes.assertions.impl.Domain; import oracle.weblogic.kubernetes.assertions.impl.Kubernetes; import oracle.weblogic.kubernetes.assertions.impl.Operator; @@ -164,4 +165,14 @@ public static boolean dockerImageExists(String imageName, String imageTag) { return WITAssertion.doesImageExist(imageName, imageTag); } + /** + * Check if an application can be accessed within a managed server pod. + * @param imageName the name of the image to be checked + * @param imageTag the tag of the image to be checked + * @return true if the image does exist, false otherwise + */ + public static boolean appAccessibleInPod(String ns, String port, String appPath, String expectedStr) { + return Application.appAccessibleInPod(ns, port, appPath, expectedStr); + } + } diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/utils/FileUtils.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/utils/FileUtils.java index 8fc2195e27b..89b22c607d8 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/utils/FileUtils.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/utils/FileUtils.java @@ -11,6 +11,9 @@ import java.nio.file.Paths; import java.util.stream.Stream; +import oracle.weblogic.kubernetes.logging.LoggingFacade; +import oracle.weblogic.kubernetes.logging.LoggingFactory; + import static java.nio.file.StandardCopyOption.REPLACE_EXISTING; import static oracle.weblogic.kubernetes.extensions.LoggedTest.logger; import static org.apache.commons.io.FileUtils.cleanDirectory; @@ -19,6 +22,7 @@ * The utility class for file operations. */ public class FileUtils { + private static final LoggingFacade logger = LoggingFactory.getLogger(FileUtils.class); /** * Check if the required directories exist. @@ -31,7 +35,7 @@ public static void checkDirectory(String dir) { File file = new File(dir); if (!(file.exists() && file.isDirectory())) { file.mkdirs(); - logger.info("Made a new dir " + dir); + logger.info("Made a new dir {0}.", dir); } } @@ -44,7 +48,7 @@ public static void checkDirectory(String dir) { public static void checkFile(String fileName) throws FileNotFoundException { File file = new File(fileName); if (!(file.exists() && file.isFile())) { - logger.warning("The expected file " + fileName + " was not found."); + logger.warning("The expected file {0} was not found.", fileName); throw new FileNotFoundException("The expected file " + fileName + " was not found."); } } @@ -70,7 +74,7 @@ public static boolean doesFileExist(String fileName) { */ public static void cleanupDirectory(String dir) throws IOException { File file = new File(dir); - logger.info("Cleaning up directory " + dir); + logger.info("Cleaning up directory {0}.", dir); if (!file.exists()) { // nothing to do return; @@ -98,14 +102,18 @@ public static void copyFolder(String srcDir, String destDir) throws IOException try { copy(source, destPath.resolve(srcPath.relativize(source))); } catch (IOException e) { + e.printStackTrace(); // cannot throw non runtime exception. the caller checks throwable - throw new RuntimeException("Failed to copy file " + source); + throw new RuntimeException("Failed to copy file " + source + " due to:" + e.getMessage()); } }); } } private static void copy(Path source, Path dest) throws IOException { - Files.copy(source, dest, REPLACE_EXISTING); + logger.info("Copying {0} to {1} source.fileName = {2}", source, dest, source.getFileName()); + if (!dest.toFile().isDirectory()) { + Files.copy(source, dest, REPLACE_EXISTING); + } } } From c9dc18a32a815da9588a2f2f1705b47fabc96bcd Mon Sep 17 00:00:00 2001 From: doxiao Date: Thu, 16 Apr 2020 13:28:12 +0000 Subject: [PATCH 02/69] Add app assertions --- .../assertions/impl/Application.java | 91 +++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Application.java diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Application.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Application.java new file mode 100644 index 00000000000..31732a3948c --- /dev/null +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Application.java @@ -0,0 +1,91 @@ +// Copyright (c) 2020, Oracle Corporation and/or its affiliates. +// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + +package oracle.weblogic.kubernetes.assertions.impl; + +import oracle.weblogic.kubernetes.actions.impl.primitive.Command; +import oracle.weblogic.kubernetes.actions.impl.primitive.CommandParams; + +/** + * Assertions for applications in a domain. + * + */ + +public class Application { + + /** + * Check if an application is accessible inside a WebLogic server pod. + * @param ns Kubernetes namespace where the WebLogic servers are running + * @param port internal port of the managed servers + * @param appPath the path to access the application + * @return true if the command succeeds + */ + public static boolean appAccessibleInPod( + String ns, + String port, + String appPath, + String expectedStr) { + + return expectedStr.contentEquals(verifyAppInPod(ns, port, appPath)); + } + + /** + * Check if an application is accessible externally. + * @param ns Kubernetes namespace where the WebLogic servers are running + * @param port external port of the managed servers + * @param appPath the path to access the application + * @return true if the command succeeds + */ + public static boolean appAccessibleExternally( + String ns, + String port, + String appPath, + String expectedStr) { + + return expectedStr.contentEquals(verifyAppExternally(ns, port, appPath)); + } + + private static String verifyAppInPod(String domainNS, String port, String appPath) { + String appStr = ""; + // get managed server pod name + String cmd = String.format( + "kubectl get pod -n %s -o=jsonpath='{.items[1].metadata.name}' | grep managed-server1", + domainNS); + + appStr = exec(cmd, true); + + return appStr; + } + + private static String verifyAppExternally(String domainNS, String port, String appPath) { + String appStr = ""; + // get managed server pod name + String cmd = String.format( + "kubectl get pod -n %s -o=jsonpath='{.items[1].metadata.name}' | grep managed-server1", + domainNS); + + String msPodName = exec(cmd, true); + + // access the application deployed in managed-server1 + cmd = String.format( + "kubectl -n %s exec -it %s -- bash -c 'curl http://%s:%s/%s'", + domainNS, + msPodName, + port, + appPath); + + appStr = exec(cmd, true); + return appStr; + } + + private static String exec(String command, boolean redirectOutput) { + CommandParams params = Command + .defaultCommandParams() + .command(command) + .saveStdOut(true) + .redirect(false); + Command.withParams(params).execute(); + return params.stdOut(); + } + +} From 351bc8a1172bc7be3d41eeb24eb3d34ed2691519 Mon Sep 17 00:00:00 2001 From: doxiao Date: Fri, 17 Apr 2020 17:57:04 +0000 Subject: [PATCH 03/69] Save the current change --- .../oracle/weblogic/kubernetes/actions/impl/AppBuilder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/AppBuilder.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/AppBuilder.java index d34c2f5ac48..5d372a6ad88 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/AppBuilder.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/AppBuilder.java @@ -63,7 +63,7 @@ public boolean build() { ARCHIVE_SRC_DIR); } } catch (IOException | RuntimeException e) { - logger.info("Failed to get the directory " + ARCHIVE_DIR + " ready", e); + logger.severe("Failed to get the directory " + ARCHIVE_DIR + " ready", e); return false; } From 9b50a627b242a87880a04a6f414caf3f59218b89 Mon Sep 17 00:00:00 2001 From: doxiao Date: Mon, 20 Apr 2020 00:08:47 +0000 Subject: [PATCH 04/69] Update ItMiiDomain test --- .../src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java index 33c1f033a16..e63eb63be76 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java @@ -418,7 +418,8 @@ private String createImageAndVerify() { // build an application archive using what is in resources/apps/APP_NAME assertTrue(buildAppArchive(defaultAppParams() - .srcDir(APP_NAME)), String.format("Failed to create app archive for %s", APP_NAME)); + .srcDirList(Collections.singletonList(APP_NAME))), + String.format("Failed to create app archive for %s", APP_NAME)); // build the archive list String zipFile = String.format("%s/%s.zip", ARCHIVE_DIR, APP_NAME); From 36f7b34daabe18d019ae4029af489b5086d2f351 Mon Sep 17 00:00:00 2001 From: doxiao Date: Tue, 21 Apr 2020 13:26:10 +0000 Subject: [PATCH 05/69] More changes --- .../weblogic/kubernetes/ItMiiDomain.java | 45 ++++++++++++++++++- .../kubernetes/assertions/TestAssertions.java | 19 ++++++-- .../assertions/impl/Application.java | 26 +++++++++-- 3 files changed, 81 insertions(+), 9 deletions(-) diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java index e63eb63be76..2c3f7580375 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java @@ -68,6 +68,8 @@ import static oracle.weblogic.kubernetes.actions.TestActions.helmList; import static oracle.weblogic.kubernetes.actions.TestActions.installOperator; import static oracle.weblogic.kubernetes.actions.TestActions.uninstallOperator; +import static oracle.weblogic.kubernetes.assertions.TestAssertions.appAccessibleExternally; +import static oracle.weblogic.kubernetes.assertions.TestAssertions.appAccessibleInPod; import static oracle.weblogic.kubernetes.assertions.TestAssertions.dockerImageExists; import static oracle.weblogic.kubernetes.assertions.TestAssertions.domainExists; import static oracle.weblogic.kubernetes.assertions.TestAssertions.operatorIsRunning; @@ -352,7 +354,16 @@ public void testCreateMiiDomain() { managedServerPrefix + i, domainNamespace); checkServiceCreated(managedServerPrefix + i); } - + checkAppRunning(domainNamespace, "30711", "8801", "sample-war/index.jsp", "Hello World."); + } + + @Test + @Order(2) + @DisplayName("Update application to version2") + @Slow + @MustNotRunInParallel + public void testUpdateAppVersion2() { + } @AfterEach @@ -498,6 +509,38 @@ private void checkServiceCreated(String serviceName) { } + private void checkAppRunning( + String ns, + String nodePort, + String internalPort, + String appPath, + String expectedStr) { + withStandardRetryPolicy + .conditionEvaluationListener( + condition -> logger.info("Waiting for application {0} to be ready in namespace {1} " + + "(elapsed time {2}ms, remaining time {3}ms)", + appPath, + domainNamespace, + condition.getElapsedTimeInMS(), + condition.getRemainingTimeInMS())) + .until(assertDoesNotThrow(() -> appAccessibleExternally(ns, nodePort, appPath, expectedStr), + String.format( + "App %s is not ready in namespace %s", appPath, domainNamespace))); + + withStandardRetryPolicy + .conditionEvaluationListener( + condition -> logger.info("Waiting for application {0} to be ready in namespace {1} " + + "(elapsed time {2}ms, remaining time {3}ms)", + appPath, + domainNamespace, + condition.getElapsedTimeInMS(), + condition.getRemainingTimeInMS())) + .until(assertDoesNotThrow(() -> appAccessibleInPod(ns, internalPort, appPath, expectedStr), + String.format( + "App %s is not ready in namespace %s", appPath, domainNamespace))); + + } + private static JsonObject getDockerConfigJson(String username, String password, String email, String registry) { JsonObject authObject = new JsonObject(); authObject.addProperty("username", username); diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/TestAssertions.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/TestAssertions.java index 55979d776ec..3ce40e376d7 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/TestAssertions.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/TestAssertions.java @@ -170,12 +170,23 @@ public static boolean dockerImageExists(String imageName, String imageTag) { /** * Check if an application can be accessed within a managed server pod. - * @param imageName the name of the image to be checked - * @param imageTag the tag of the image to be checked + * @param ins the namespace of the domain that hosts the application + * @param port the port of the cluster's clusterIP + * @param appPath the path for the application url + * @param expectedStr the expected text from the application's response * @return true if the image does exist, false otherwise */ - public static boolean appAccessibleInPod(String ns, String port, String appPath, String expectedStr) { - return Application.appAccessibleInPod(ns, port, appPath, expectedStr); + + public static Callable appAccessibleInPod(String ns, String port, String appPath, String expectedStr) { + return () -> { + return Application.appAccessibleInPod(ns, port, appPath, expectedStr); + }; + } + + public static Callable appAccessibleExternally(String ns, String port, String appPath, String expectedStr) { + return () -> { + return Application.appAccessibleExternally(ns, port, appPath, expectedStr); + }; } } diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Application.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Application.java index 31732a3948c..ae7773bedcd 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Application.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Application.java @@ -5,6 +5,8 @@ import oracle.weblogic.kubernetes.actions.impl.primitive.Command; import oracle.weblogic.kubernetes.actions.impl.primitive.CommandParams; +import oracle.weblogic.kubernetes.logging.LoggingFacade; +import oracle.weblogic.kubernetes.logging.LoggingFactory; /** * Assertions for applications in a domain. @@ -12,6 +14,7 @@ */ public class Application { + private static final LoggingFacade logger = LoggingFactory.getLogger(Application.class); /** * Check if an application is accessible inside a WebLogic server pod. @@ -26,7 +29,7 @@ public static boolean appAccessibleInPod( String appPath, String expectedStr) { - return expectedStr.contentEquals(verifyAppInPod(ns, port, appPath)); + return verifyAppInPod(ns, port, appPath).contains(expectedStr); } /** @@ -52,8 +55,21 @@ private static String verifyAppInPod(String domainNS, String port, String appPat "kubectl get pod -n %s -o=jsonpath='{.items[1].metadata.name}' | grep managed-server1", domainNS); - appStr = exec(cmd, true); + String msPodName = exec(cmd, true); + logger.info("msPodName = " + msPodName); + + // access the application deployed in managed-server1 + cmd = String.format( + "kubectl -n %s exec -it %s -- /bin/bash -c 'curl http://%s:%s/%s'", + domainNS, + msPodName, + msPodName, + port, + appPath); + + appStr = exec(cmd, true); + logger.info("appStr =" + appStr); return appStr; } @@ -68,13 +84,14 @@ private static String verifyAppExternally(String domainNS, String port, String a // access the application deployed in managed-server1 cmd = String.format( - "kubectl -n %s exec -it %s -- bash -c 'curl http://%s:%s/%s'", + "curl -H 'host: domain1.org' http://localhost:%s/%s", domainNS, msPodName, port, appPath); appStr = exec(cmd, true); + logger.info("appStr =" + appStr); return appStr; } @@ -83,8 +100,9 @@ private static String exec(String command, boolean redirectOutput) { .defaultCommandParams() .command(command) .saveStdOut(true) - .redirect(false); + .redirect(true); Command.withParams(params).execute(); + logger.info("Stdout = " + params.stdOut()); return params.stdOut(); } From 8a1164effc5061aec4367b63e0bf4ea92f7e1453 Mon Sep 17 00:00:00 2001 From: doxiao Date: Tue, 21 Apr 2020 20:39:43 +0000 Subject: [PATCH 06/69] verify an app from a server pod --- .../weblogic/kubernetes/ItMiiDomain.java | 148 ++++++++++++++---- .../assertions/impl/Application.java | 13 +- 2 files changed, 121 insertions(+), 40 deletions(-) diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java index 2c3f7580375..c9bb80a65f3 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java @@ -68,7 +68,7 @@ import static oracle.weblogic.kubernetes.actions.TestActions.helmList; import static oracle.weblogic.kubernetes.actions.TestActions.installOperator; import static oracle.weblogic.kubernetes.actions.TestActions.uninstallOperator; -import static oracle.weblogic.kubernetes.assertions.TestAssertions.appAccessibleExternally; +//import static oracle.weblogic.kubernetes.assertions.TestAssertions.appAccessibleExternally; import static oracle.weblogic.kubernetes.assertions.TestAssertions.appAccessibleInPod; import static oracle.weblogic.kubernetes.assertions.TestAssertions.dockerImageExists; import static oracle.weblogic.kubernetes.assertions.TestAssertions.domainExists; @@ -198,7 +198,7 @@ public void testCreateMiiDomain() { final int replicaCount = 2; // create image with model files - miiImage = createImageAndVerify(); + miiImage = createFirstDomainImage(); // push the image to OCIR to make the test work in multi node cluster if (System.getenv("REPO_REGISTRY") != null && System.getenv("REPO_USERNAME") != null @@ -354,32 +354,82 @@ public void testCreateMiiDomain() { managedServerPrefix + i, domainNamespace); checkServiceCreated(managedServerPrefix + i); } - checkAppRunning(domainNamespace, "30711", "8801", "sample-war/index.jsp", "Hello World."); + checkAppRunning( + domainNamespace, + "30711", + "8001", + "sample-war/index.jsp", + "Hello World, you have reached server managed-server1"); } @Test @Order(2) - @DisplayName("Update application to version2") + @DisplayName("Update the application to version2") @Slow @MustNotRunInParallel - public void testUpdateAppVersion2() { + public void testAppVersion2Patching() { + final String adminServerPodName = domainUID + "-admin-server"; + final String managedServerPrefix = domainUID + "-managed-server"; + final int replicaCount = 2; - } + // app here is what is in the original app dir plus the delta in the second app dir + final String appDir1 = "sample-app"; + final String appDir2 = "sample-app-2"; + + // create another image with app V2 + String image = updateImageWithAppV2Patch( + MII_IMAGE_NAME, + Arrays.asList(appDir1, appDir2)); + + // modify the domain resource to use the new image + patchDomainResourceWithNewIamge(domainUID, image); + + // check and wait for the admin server pod to be started + logger.info("Check for admin server pod {0} existence in namespace {1}", + adminServerPodName, domainNamespace); + checkPodCreated(adminServerPodName); - @AfterEach - public void tearDown() { + // check and wait for the managed server pods to be started + for (int i = 1; i <= replicaCount; i++) { + logger.info("Check for managed server pod {0} existence in namespace {1}", + managedServerPrefix + i, domainNamespace); + checkPodCreated(managedServerPrefix + i); + } - // Delete domain custom resource - logger.info("Delete domain custom resource in namespace {0}", domainNamespace); - assertDoesNotThrow(() -> deleteDomainCustomResource(domainUID, domainNamespace), - "deleteDomainCustomResource failed with ApiException"); - logger.info("Deleted Domain Custom Resource " + domainUID + " from " + domainNamespace); + // check and wait for the admin server pod to be in running state + logger.info("Wait for admin server pod {0} to be ready in namespace {1}", + adminServerPodName, domainNamespace); + checkPodRunning(adminServerPodName); - // delete the domain image created for the test - if (miiImage != null) { - deleteImage(miiImage); + // check and wait for the managed server pods to be in running state + for (int i = 1; i <= replicaCount; i++) { + logger.info("Wait for managed server pod {0} to be ready in namespace {1}", + managedServerPrefix + i, domainNamespace); + checkPodRunning(managedServerPrefix + i); + } + + logger.info("Check admin service {0} is created in namespace {1}", + adminServerPodName, domainNamespace); + checkServiceCreated(adminServerPodName); + + // check and wait for the managed server services to be created + for (int i = 1; i <= replicaCount; i++) { + logger.info("Check managed server service {0} is created in namespace {1}", + managedServerPrefix + i, domainNamespace); + checkServiceCreated(managedServerPrefix + i); } + + // check and wait for the app to be ready + checkAppRunning( + domainNamespace, + "30711", + "8001", + "sample-war/index.jsp", + "Hello World again, you have reached the server managed-server1"); + } + private void patchDomainResourceWithNewIamge(String domainUID2, String image) { + // TODO Auto-generated method stub } /** @@ -388,6 +438,17 @@ public void tearDown() { */ @AfterAll public void tearDownAll() { + // Delete domain custom resource + logger.info("Delete domain custom resource in namespace {0}", domainNamespace); + assertDoesNotThrow(() -> deleteDomainCustomResource(domainUID, domainNamespace), + "deleteDomainCustomResource failed with ApiException"); + logger.info("Deleted Domain Custom Resource " + domainUID + " from " + domainNamespace); + + // delete the domain image created for the test + if (miiImage != null) { + deleteImage(miiImage); + } + // uninstall operator release logger.info("Uninstall Operator in namespace {0}", opNamespace); if (opHelmParams != null) { @@ -418,7 +479,7 @@ public void tearDownAll() { } - private String createImageAndVerify() { + private String createFirstDomainImage() { // create unique image name with date DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); Date date = new Date(); @@ -436,6 +497,37 @@ private String createImageAndVerify() { String zipFile = String.format("%s/%s.zip", ARCHIVE_DIR, APP_NAME); List archiveList = Collections.singletonList(zipFile); + createImageAndVerify(MII_IMAGE_NAME, imageTag, modelList, archiveList); + + return MII_IMAGE_NAME + ":" + imageTag; + } + + private String updateImageWithAppV2Patch(String imageName, List appDirList) { + // build the model file list + List modelList = Collections.singletonList(MODEL_DIR + "/" + WDT_MODEL_FILE); + + // build an application archive using what is in resources/apps/APP_NAME + boolean archiveBuilt = buildAppArchive( + defaultAppParams() + .srcDirList(appDirList)); + + assertTrue(archiveBuilt, String.format("Failed to create app archive for %s" + APP_NAME)); + + // build the archive list + String zipFile = String.format("%s/%s.zip", ARCHIVE_DIR, APP_NAME); + List archiveList = Collections.singletonList(zipFile); + createImageAndVerify( + imageName, "v2", modelList, archiveList); + return imageName + ":" + "v2"; + + } + + private void createImageAndVerify( + String imageName, + String imageTag, + List modelList, + List archiveList) { + // Set additional environment variables for WIT checkDirectory(WIT_BUILD_DIR); Map env = new HashMap(); @@ -443,10 +535,10 @@ private String createImageAndVerify() { // build an image using WebLogic Image Tool logger.info("Create image {0}:{1} using model directory {2}", - MII_IMAGE_NAME, imageTag, MODEL_DIR); + imageName, imageTag, MODEL_DIR); boolean result = createMIIImage( defaultWITParams() - .modelImageName(MII_IMAGE_NAME) + .modelImageName(imageName) .modelImageTag(imageTag) .modelFiles(modelList) .modelArchiveFiles(archiveList) @@ -454,16 +546,13 @@ private String createImageAndVerify() { .env(env) .redirect(true)); - assertTrue(result, String.format("Failed to create the image %s using WebLogic Image Tool", MII_IMAGE_NAME)); + assertTrue(result, String.format("Failed to create the image %s using WebLogic Image Tool", imageName)); // check image exists - assertTrue(dockerImageExists(MII_IMAGE_NAME, imageTag), - String.format("Image %s doesn't exist", MII_IMAGE_NAME + ":" + imageTag)); - - return MII_IMAGE_NAME + ":" + imageTag; + assertTrue(dockerImageExists(imageName, imageTag), + String.format("Image %s doesn't exist", imageName + ":" + imageTag)); } - private void checkPodCreated(String podName) { withStandardRetryPolicy .conditionEvaluationListener( @@ -510,11 +599,12 @@ private void checkServiceCreated(String serviceName) { } private void checkAppRunning( - String ns, - String nodePort, - String internalPort, + String ns, + String nodePort, + String internalPort, String appPath, String expectedStr) { + /* enable this once the load balancer is deployed withStandardRetryPolicy .conditionEvaluationListener( condition -> logger.info("Waiting for application {0} to be ready in namespace {1} " @@ -526,7 +616,7 @@ private void checkAppRunning( .until(assertDoesNotThrow(() -> appAccessibleExternally(ns, nodePort, appPath, expectedStr), String.format( "App %s is not ready in namespace %s", appPath, domainNamespace))); - + */ withStandardRetryPolicy .conditionEvaluationListener( condition -> logger.info("Waiting for application {0} to be ready in namespace {1} " diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Application.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Application.java index ae7773bedcd..b4be5af6086 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Application.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Application.java @@ -74,23 +74,14 @@ private static String verifyAppInPod(String domainNS, String port, String appPat } private static String verifyAppExternally(String domainNS, String port, String appPath) { - String appStr = ""; - // get managed server pod name - String cmd = String.format( - "kubectl get pod -n %s -o=jsonpath='{.items[1].metadata.name}' | grep managed-server1", - domainNS); - - String msPodName = exec(cmd, true); // access the application deployed in managed-server1 - cmd = String.format( + String cmd = String.format( "curl -H 'host: domain1.org' http://localhost:%s/%s", - domainNS, - msPodName, port, appPath); - appStr = exec(cmd, true); + String appStr = exec(cmd, true); logger.info("appStr =" + appStr); return appStr; } From 75d6028c66cba27976c044efa25ef3a0c8faad1d Mon Sep 17 00:00:00 2001 From: doxiao Date: Wed, 22 Apr 2020 17:07:23 +0000 Subject: [PATCH 07/69] add code to patch the domain with a new image and verify --- .../weblogic/kubernetes/ItMiiDomain.java | 158 ++++++++++-------- .../actions/impl/primitive/Command.java | 6 +- .../actions/impl/primitive/CommandParams.java | 12 ++ .../kubernetes/assertions/TestAssertions.java | 47 ++++-- .../assertions/impl/Application.java | 74 +++----- 5 files changed, 162 insertions(+), 135 deletions(-) diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java index 28615a894ce..02ededf11ee 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java @@ -12,8 +12,10 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.concurrent.TimeUnit; import com.google.gson.JsonObject; +import io.kubernetes.client.custom.V1Patch; import io.kubernetes.client.openapi.models.V1EnvVar; import io.kubernetes.client.openapi.models.V1LocalObjectReference; import io.kubernetes.client.openapi.models.V1ObjectMeta; @@ -37,7 +39,6 @@ import oracle.weblogic.kubernetes.extensions.Timing; import org.awaitility.core.ConditionFactory; import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.MethodOrderer; @@ -68,9 +69,10 @@ import static oracle.weblogic.kubernetes.actions.TestActions.dockerPush; import static oracle.weblogic.kubernetes.actions.TestActions.helmList; import static oracle.weblogic.kubernetes.actions.TestActions.installOperator; +import static oracle.weblogic.kubernetes.actions.TestActions.patchDomainCustomResource; import static oracle.weblogic.kubernetes.actions.TestActions.uninstallOperator; -//import static oracle.weblogic.kubernetes.assertions.TestAssertions.appAccessibleExternally; import static oracle.weblogic.kubernetes.assertions.TestAssertions.appAccessibleInPod; +import static oracle.weblogic.kubernetes.assertions.TestAssertions.appAccessibleInPodCallable; import static oracle.weblogic.kubernetes.assertions.TestAssertions.dockerImageExists; import static oracle.weblogic.kubernetes.assertions.TestAssertions.domainExists; import static oracle.weblogic.kubernetes.assertions.TestAssertions.operatorIsRunning; @@ -80,6 +82,7 @@ import static oracle.weblogic.kubernetes.utils.FileUtils.checkDirectory; import static org.awaitility.Awaitility.with; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; // Test to create model in image domain and verify the domain started successfully @@ -104,6 +107,10 @@ class ItMiiDomain implements LoggedTest { // domain constants private static final String DOMAIN_VERSION = "v7"; private static final String API_VERSION = "weblogic.oracle/" + DOMAIN_VERSION; + + // app constants + private static final String APP_RESPONSE_V1 = "Hello World, you have reached server managed-server1"; + private static final String APP_RESPONSE_V2 = "Hello World AGAIN, you have reached server managed-server1"; private static HelmParams opHelmParams = null; private static V1ServiceAccount serviceAccount = null; @@ -355,23 +362,25 @@ public void testCreateMiiDomain() { managedServerPrefix + i, domainNamespace); checkServiceCreated(managedServerPrefix + i); } + checkAppRunning( + domainUID, domainNamespace, "30711", "8001", "sample-war/index.jsp", - "Hello World, you have reached server managed-server1"); + APP_RESPONSE_V1); + + logger.info(String.format("Domain %s is fully started - servers are running and application is deployed corretly.", + domainUID)); } @Test @Order(2) - @DisplayName("Update the application to version2") + @DisplayName("Update the application to version 2") @Slow @MustNotRunInParallel public void testAppVersion2Patching() { - final String adminServerPodName = domainUID + "-admin-server"; - final String managedServerPrefix = domainUID + "-managed-server"; - final int replicaCount = 2; // app here is what is in the original app dir plus the delta in the second app dir final String appDir1 = "sample-app"; @@ -381,56 +390,79 @@ public void testAppVersion2Patching() { String image = updateImageWithAppV2Patch( MII_IMAGE_NAME, Arrays.asList(appDir1, appDir2)); + + // check and V1 app is running + assertTrue(appAccessibleInPod( + domainUID, + domainNamespace, + "8001", + "sample-war/index.jsp", + APP_RESPONSE_V1), + "The expected app is not accessible inside the server pod"); + + // check and make sure that the version 2 app is NOT running + assertFalse(appAccessibleInPod( + domainUID, + domainNamespace, + "8001", + "sample-war/index.jsp", + APP_RESPONSE_V2), + "The second version of the app is not supposed to be running!!"); // modify the domain resource to use the new image - patchDomainResourceWithNewIamge(domainUID, image); + patchDomainResourceIamge(domainUID, domainNamespace, image); - // check and wait for the admin server pod to be started - logger.info("Check for admin server pod {0} existence in namespace {1}", - adminServerPodName, domainNamespace); - checkPodCreated(adminServerPodName); - - // check and wait for the managed server pods to be started - for (int i = 1; i <= replicaCount; i++) { - logger.info("Check for managed server pod {0} existence in namespace {1}", - managedServerPrefix + i, domainNamespace); - checkPodCreated(managedServerPrefix + i); - } - - // check and wait for the admin server pod to be in running state - logger.info("Wait for admin server pod {0} to be ready in namespace {1}", - adminServerPodName, domainNamespace); - checkPodRunning(adminServerPodName); - - // check and wait for the managed server pods to be in running state - for (int i = 1; i <= replicaCount; i++) { - logger.info("Wait for managed server pod {0} to be ready in namespace {1}", - managedServerPrefix + i, domainNamespace); - checkPodRunning(managedServerPrefix + i); - } - - logger.info("Check admin service {0} is created in namespace {1}", - adminServerPodName, domainNamespace); - checkServiceCreated(adminServerPodName); - - // check and wait for the managed server services to be created - for (int i = 1; i <= replicaCount; i++) { - logger.info("Check managed server service {0} is created in namespace {1}", - managedServerPrefix + i, domainNamespace); - checkServiceCreated(managedServerPrefix + i); + // Ideally we want to verify that the server pods were rolling restarted. + // But it is hard to time the pod state transitions. + // Instead, sleep for 2 minutes and check the newer version of the application. + // The application check is sufficient to verify that the version2 application + // is running, thus the servers have been patched. + try { + TimeUnit.MINUTES.sleep(2); + } catch (InterruptedException ie) { + // do nothing } // check and wait for the app to be ready checkAppRunning( + domainUID, domainNamespace, "30711", "8001", "sample-war/index.jsp", - "Hello World again, you have reached the server managed-server1"); + APP_RESPONSE_V2); + + logger.info("The cluster has been rolling started, and the version 2 application has been deployed correctly."); } - private void patchDomainResourceWithNewIamge(String domainUID2, String image) { - // TODO Auto-generated method stub + /** + * Patch the domain resource with a new image that contains a newer version of the application. + * + * Here is an example of the JSON patch string that is constructed in this method. + * + * [ + * {"op": "replace", "path": "/spec/image", "value": "mii-image:v2" } + * ] + * + * @param domainUID the unique identifier of the domain resource + * @param namespace the Kubernetes namespace that the domain is hosted + * @param image the name of the image that contains a newer version of the application + */ + private void patchDomainResourceIamge( + String domainUID, + String namespace, + String image + ) { + String patch = + String.format("[\n {\"op\": \"replace\", \"path\": \"/spec/image\", \"value\": \"%s\"}\n]\n", image); + logger.info("Patch string is : " + patch); + + assertTrue(patchDomainCustomResource( + domainUID, + namespace, + new V1Patch(patch), + V1Patch.PATCH_FORMAT_JSON_PATCH), + "Failed to patch the domain resource with a a different image."); } /** @@ -446,9 +478,9 @@ public void tearDownAll() { logger.info("Deleted Domain Custom Resource " + domainUID + " from " + domainNamespace); // delete the domain image created for the test - if (miiImage != null) { - deleteImage(miiImage); - } + if (miiImage != null) { + deleteImage(miiImage); + } // uninstall operator release logger.info("Uninstall Operator in namespace {0}", opNamespace); @@ -477,7 +509,6 @@ public void tearDownAll() { "deleteNamespace failed with ApiException"); logger.info("Deleted namespace: " + opNamespace); } - } private String createFirstDomainImage() { @@ -503,7 +534,10 @@ private String createFirstDomainImage() { return MII_IMAGE_NAME + ":" + imageTag; } - private String updateImageWithAppV2Patch(String imageName, List appDirList) { + private String updateImageWithAppV2Patch( + String imageName, + List appDirList + ) { // build the model file list List modelList = Collections.singletonList(MODEL_DIR + "/" + WDT_MODEL_FILE); @@ -512,7 +546,7 @@ private String updateImageWithAppV2Patch(String imageName, List appDirLi defaultAppParams() .srcDirList(appDirList)); - assertTrue(archiveBuilt, String.format("Failed to create app archive for %s" + APP_NAME)); + assertTrue(archiveBuilt, String.format("Failed to create app archive for %s", APP_NAME)); // build the archive list String zipFile = String.format("%s/%s.zip", ARCHIVE_DIR, APP_NAME); @@ -527,7 +561,8 @@ private void createImageAndVerify( String imageName, String imageTag, List modelList, - List archiveList) { + List archiveList + ) { // Set additional environment variables for WIT checkDirectory(WIT_BUILD_DIR); @@ -600,24 +635,15 @@ private void checkServiceCreated(String serviceName) { } private void checkAppRunning( + String domainUID, String ns, String nodePort, String internalPort, String appPath, - String expectedStr) { - /* enable this once the load balancer is deployed - withStandardRetryPolicy - .conditionEvaluationListener( - condition -> logger.info("Waiting for application {0} to be ready in namespace {1} " - + "(elapsed time {2}ms, remaining time {3}ms)", - appPath, - domainNamespace, - condition.getElapsedTimeInMS(), - condition.getRemainingTimeInMS())) - .until(assertDoesNotThrow(() -> appAccessibleExternally(ns, nodePort, appPath, expectedStr), - String.format( - "App %s is not ready in namespace %s", appPath, domainNamespace))); - */ + String expectedStr + ) { + + // check if the app is accessible inside of a server pod withStandardRetryPolicy .conditionEvaluationListener( condition -> logger.info("Waiting for application {0} to be ready in namespace {1} " @@ -626,7 +652,7 @@ private void checkAppRunning( domainNamespace, condition.getElapsedTimeInMS(), condition.getRemainingTimeInMS())) - .until(assertDoesNotThrow(() -> appAccessibleInPod(ns, internalPort, appPath, expectedStr), + .until(assertDoesNotThrow(() -> appAccessibleInPodCallable(domainUID, ns, internalPort, appPath, expectedStr), String.format( "App %s is not ready in namespace %s", appPath, domainNamespace))); diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/primitive/Command.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/primitive/Command.java index cd54f3a3b74..cca0c077463 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/primitive/Command.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/primitive/Command.java @@ -40,7 +40,9 @@ private Command params(CommandParams params) { } public boolean execute() { - logger.info("Executing command {0}", params.command()); + if (params.debug()) { + logger.info("Executing command {0}", params.command()); + } try { ExecResult result = ExecCommand.exec( params.command(), @@ -52,7 +54,7 @@ public boolean execute() { } // check exitValue to determine if the command execution has failed. - if (result.exitValue() != 0) { + if (params.debug() && result.exitValue() != 0) { logger.severe("The command execution failed because it returned non-zero exit value: {0}.", result); } diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/primitive/CommandParams.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/primitive/CommandParams.java index 0d9c88517a2..577df4bf39e 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/primitive/CommandParams.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/primitive/CommandParams.java @@ -29,6 +29,8 @@ public class CommandParams { // The stderr of the command execution private String stderr; + private boolean debug = false; + public CommandParams defaults() { return this; } @@ -86,4 +88,14 @@ public CommandParams stdout(String stdout) { public String stdout() { return stdout; } + + public CommandParams debug(boolean debug) { + this.debug = debug; + return this; + } + + public boolean debug() { + return debug; + } + } diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/TestAssertions.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/TestAssertions.java index 3ce40e376d7..395a0762ca4 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/TestAssertions.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/TestAssertions.java @@ -169,24 +169,43 @@ public static boolean dockerImageExists(String imageName, String imageTag) { } /** - * Check if an application can be accessed within a managed server pod. - * @param ins the namespace of the domain that hosts the application - * @param port the port of the cluster's clusterIP - * @param appPath the path for the application url - * @param expectedStr the expected text from the application's response - * @return true if the image does exist, false otherwise + * Check if an application is accessible inside a WebLogic server pod. + * @param domainUID unique identifier of the Kubernetes domain custom resource instance + * @param domainNS Kubernetes namespace where the WebLogic servers are running + * @param port internal port of the managed servers + * @param appPath the path to access the application + * @param expectedStr the expected response from the application + * @return true if the command succeeds */ - - public static Callable appAccessibleInPod(String ns, String port, String appPath, String expectedStr) { - return () -> { - return Application.appAccessibleInPod(ns, port, appPath, expectedStr); - }; + public static boolean appAccessibleInPod( + String domainUID, + String domainNS, + String port, + String appPath, + String expectedStr + ) { + return Application.appAccessibleInPod(domainUID, domainNS, port, appPath, expectedStr); } - public static Callable appAccessibleExternally(String ns, String port, String appPath, String expectedStr) { + /** + * Check if an application is accessible inside a server pod. + * . + * @param domainUID unique identifier of the Kubernetes domain custom resource instance + * @param domainNS Kubernetes namespace where the WebLogic servers are running + * @param port internal port of the managed servers + * @param appPath the path to access the application + * @param expectedStr the expected response from the application + * @return Callable true if the command succeeds + */ + public static Callable appAccessibleInPodCallable( + String domainUID, + String domainNS, + String port, + String appPath, + String expectedStr + ) { return () -> { - return Application.appAccessibleExternally(ns, port, appPath, expectedStr); + return Application.appAccessibleInPod(domainUID, domainNS, port, appPath, expectedStr); }; } - } diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Application.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Application.java index b4be5af6086..30a5b268001 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Application.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Application.java @@ -18,49 +18,32 @@ public class Application { /** * Check if an application is accessible inside a WebLogic server pod. - * @param ns Kubernetes namespace where the WebLogic servers are running + * @param domainUID unique identifier of the Kubernetes domain custom resource instance + * @param domainNS Kubernetes namespace where the WebLogic servers are running * @param port internal port of the managed servers * @param appPath the path to access the application * @return true if the command succeeds */ public static boolean appAccessibleInPod( - String ns, + String domainUID, + String domainNS, String port, String appPath, - String expectedStr) { - - return verifyAppInPod(ns, port, appPath).contains(expectedStr); + String expectedStr + ) { + return verifyAppInPod(domainUID, domainNS, port, appPath).contains(expectedStr); } - - /** - * Check if an application is accessible externally. - * @param ns Kubernetes namespace where the WebLogic servers are running - * @param port external port of the managed servers - * @param appPath the path to access the application - * @return true if the command succeeds - */ - public static boolean appAccessibleExternally( - String ns, - String port, - String appPath, - String expectedStr) { - return expectedStr.contentEquals(verifyAppExternally(ns, port, appPath)); - } - - private static String verifyAppInPod(String domainNS, String port, String appPath) { - String appStr = ""; - // get managed server pod name - String cmd = String.format( - "kubectl get pod -n %s -o=jsonpath='{.items[1].metadata.name}' | grep managed-server1", - domainNS); - - String msPodName = exec(cmd, true); - logger.info("msPodName = " + msPodName); - + private static String verifyAppInPod( + String domainUID, + String domainNS, + String port, + String appPath + ) { + String msPodName = domainUID + "-managed-server1"; - // access the application deployed in managed-server1 - cmd = String.format( + // access the application deployed on managed-server1 + String cmd = String.format( "kubectl -n %s exec -it %s -- /bin/bash -c 'curl http://%s:%s/%s'", domainNS, msPodName, @@ -68,33 +51,18 @@ private static String verifyAppInPod(String domainNS, String port, String appPat port, appPath); - appStr = exec(cmd, true); - logger.info("appStr =" + appStr); - return appStr; + return exec(cmd, true); } - - private static String verifyAppExternally(String domainNS, String port, String appPath) { - // access the application deployed in managed-server1 - String cmd = String.format( - "curl -H 'host: domain1.org' http://localhost:%s/%s", - port, - appPath); - - String appStr = exec(cmd, true); - logger.info("appStr =" + appStr); - return appStr; - } - private static String exec(String command, boolean redirectOutput) { CommandParams params = Command .defaultCommandParams() .command(command) - .saveStdOut(true) - .redirect(true); + .saveResults(true) + .redirect(false) + .debug(false); Command.withParams(params).execute(); - logger.info("Stdout = " + params.stdOut()); - return params.stdOut(); + return params.stdout(); } } From b2b169f89526f38c2deaf40a426bf67e2bb198de Mon Sep 17 00:00:00 2001 From: doxiao Date: Wed, 22 Apr 2020 17:14:26 +0000 Subject: [PATCH 08/69] Revert unintended changes --- .../weblogic/kubernetes/ItWITValidation.java | 129 ------------------ .../kubernetes/actions/impl/AppParams.java | 4 +- 2 files changed, 2 insertions(+), 131 deletions(-) delete mode 100644 new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItWITValidation.java diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItWITValidation.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItWITValidation.java deleted file mode 100644 index a561d6225f4..00000000000 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItWITValidation.java +++ /dev/null @@ -1,129 +0,0 @@ -// Copyright (c) 2020, Oracle Corporation and/or its affiliates. -// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. - -package oracle.weblogic.kubernetes; - -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import oracle.weblogic.kubernetes.extensions.LoggedTest; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; - -import static oracle.weblogic.kubernetes.actions.ActionConstants.ARCHIVE_DIR; -import static oracle.weblogic.kubernetes.actions.ActionConstants.MODEL_DIR; -import static oracle.weblogic.kubernetes.actions.ActionConstants.WDT_VERSION; -import static oracle.weblogic.kubernetes.actions.ActionConstants.WIT_BUILD_DIR; -import static oracle.weblogic.kubernetes.actions.TestActions.buildAppArchive; -import static oracle.weblogic.kubernetes.actions.TestActions.createMIIImage; -import static oracle.weblogic.kubernetes.actions.TestActions.defaultAppParams; -import static oracle.weblogic.kubernetes.actions.TestActions.defaultWITParams; -import static oracle.weblogic.kubernetes.assertions.TestAssertions.dockerImageExists; -import static oracle.weblogic.kubernetes.utils.FileUtils.checkDirectory; -import static org.assertj.core.api.Assertions.assertThat; - -@DisplayName("Simple validation of basic WIT functions") -class ItWITValidation implements LoggedTest { - private static final String WDT_MODEL_FILE = "model1-wls.yaml"; - private static final String IMAGE_NAME = "test-mii-image-2"; - private static final String IMAGE_TAG = "v1"; - private static final String IMAGE_TAG_V2 = "v2"; - - private static final String APP_NAME = "sample-app"; - - @Test - @DisplayName("Create a MII image") - public void testCreatingMIIImage() { - - logger.info("WDT model directory is {0}", MODEL_DIR); - - // build the model file list - List modelList = Collections.singletonList(MODEL_DIR + "/" + WDT_MODEL_FILE); - - // build an application archive using what is in resources/apps/APP_NAME - boolean archiveBuilt = buildAppArchive( - defaultAppParams() - .srcDirList(Collections.singletonList(APP_NAME))); - - assertThat(archiveBuilt) - .as("Create an app archive") - .withFailMessage("Failed to create app archive for " + APP_NAME) - .isTrue(); - - // build the archive list - String zipFile = String.format("%s/%s.zip", ARCHIVE_DIR, APP_NAME); - List archiveList = Collections.singletonList(zipFile); - - // Set additional environment variables for WIT - checkDirectory(WIT_BUILD_DIR); - Map env = new HashMap(); - env.put("WLSIMG_BLDDIR", WIT_BUILD_DIR); - - // build an image using WebLogic Image Tool - boolean success = createMIIImage( - defaultWITParams() - .modelImageName(IMAGE_NAME) - .modelImageTag(IMAGE_TAG) - .modelFiles(modelList) - .modelArchiveFiles(archiveList) - .wdtVersion(WDT_VERSION) - .env(env) - .redirect(true)); - - assertThat(success) - .as("Test the Docker image creation") - .withFailMessage("Failed to create the image using WebLogic Image Tool") - .isTrue(); - - dockerImageExists(IMAGE_NAME, IMAGE_TAG); - } - - @Test - @DisplayName("Create a MII image with a version 2 of the application") - public void testCreatingMIIImageWithAppVersion2() { - - // build the model file list - List modelList = Collections.singletonList(MODEL_DIR + "/" + WDT_MODEL_FILE); - - // build an application archive using what is in resources/apps/APP_NAME - boolean archiveBuilt = buildAppArchive( - defaultAppParams() - .srcDirList(Arrays.asList(APP_NAME, "sample-app-2"))); - - assertThat(archiveBuilt) - .as("Create an app archive") - .withFailMessage("Failed to create app archive for " + APP_NAME) - .isTrue(); - - // build the archive list - String zipFile = String.format("%s/%s.zip", ARCHIVE_DIR, APP_NAME); - List archiveList = Collections.singletonList(zipFile); - - // Set additional environment variables for WIT - checkDirectory(WIT_BUILD_DIR); - Map env = new HashMap(); - env.put("WLSIMG_BLDDIR", WIT_BUILD_DIR); - - // build an image using WebLogic Image Tool - boolean success = createMIIImage( - defaultWITParams() - .modelImageName(IMAGE_NAME) - .modelImageTag(IMAGE_TAG_V2) - .modelFiles(modelList) - .modelArchiveFiles(archiveList) - .wdtVersion("latest") - .env(env) - .redirect(true)); - - assertThat(success) - .as("Test the Docker image creation has succeeded") - .withFailMessage("Failed to create the image using WebLogic Image Tool") - .isTrue(); - - dockerImageExists(IMAGE_NAME, IMAGE_TAG_V2); - } -} - diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/AppParams.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/AppParams.java index 8185fada5f0..ee728903557 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/AppParams.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/AppParams.java @@ -13,9 +13,9 @@ public class AppParams { // Locations of the source code. // This are the directory names under resources/apps for an application. - // Note: the order of the directory names are signaficant. Files are copied into + // Note: the order of the directory names are significant. Files are copied into // the staging directory in the order that corresponds to the order that the - // directories are locates in the list. + // directories are located in the list. private List srcDirList; // The name of the final ear file. From e76239b16e4ffbf7dbbce9ab4cdd7b6fc0b5adf6 Mon Sep 17 00:00:00 2001 From: doxiao Date: Wed, 22 Apr 2020 18:33:01 +0000 Subject: [PATCH 09/69] Fix merge issues --- .../weblogic/kubernetes/ItMiiDomain.java | 89 ++++++++++--------- .../weblogic/kubernetes/ItWitValidation.java | 2 +- .../assertions/impl/Application.java | 13 +-- .../weblogic/kubernetes/utils/FileUtils.java | 4 +- 4 files changed, 51 insertions(+), 57 deletions(-) diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java index c321e21c041..fb5f4f7fa19 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java @@ -206,7 +206,7 @@ public void testCreateMiiDomain() { final int replicaCount = 2; // create image with model files - miiImage = createFirstDomainImage(); + miiImage = createInitialDomainImage(); // push the image to OCIR to make the test work in multi node cluster if (System.getenv("REPO_REGISTRY") != null && System.getenv("REPO_USERNAME") != null @@ -306,7 +306,7 @@ public void testCreateMiiDomain() { .domainType("WLS") .runtimeEncryptionSecret(encryptionSecretName)))); - logger.info("Create domain custom resource for domainUID {0} in namespace {1}", + logger.info("Create domain custom resource for domainUid {0} in namespace {1}", domainUid, domainNamespace); assertTrue(assertDoesNotThrow(() -> createDomainCustomResource(domain), String.format("Create domain custom resource failed with ApiException for %s in namespace %s", @@ -364,7 +364,7 @@ public void testCreateMiiDomain() { } checkAppRunning( - domainUID, + domainUid, domainNamespace, "30711", "8001", @@ -372,12 +372,12 @@ public void testCreateMiiDomain() { APP_RESPONSE_V1); logger.info(String.format("Domain %s is fully started - servers are running and application is deployed corretly.", - domainUID)); + domainUid)); } @Test @Order(2) - @DisplayName("Update the application to version 2") + @DisplayName("Update the sample-app application to version 2") @Slow @MustNotRunInParallel public void testAppVersion2Patching() { @@ -393,7 +393,7 @@ public void testAppVersion2Patching() { // check and V1 app is running assertTrue(appAccessibleInPod( - domainUID, + domainUid, domainNamespace, "8001", "sample-war/index.jsp", @@ -402,7 +402,7 @@ public void testAppVersion2Patching() { // check and make sure that the version 2 app is NOT running assertFalse(appAccessibleInPod( - domainUID, + domainUid, domainNamespace, "8001", "sample-war/index.jsp", @@ -410,7 +410,7 @@ public void testAppVersion2Patching() { "The second version of the app is not supposed to be running!!"); // modify the domain resource to use the new image - patchDomainResourceIamge(domainUID, domainNamespace, image); + patchDomainResourceIamge(domainUid, domainNamespace, image); // Ideally we want to verify that the server pods were rolling restarted. // But it is hard to time the pod state transitions. @@ -425,7 +425,7 @@ public void testAppVersion2Patching() { // check and wait for the app to be ready checkAppRunning( - domainUID, + domainUid, domainNamespace, "30711", "8001", @@ -435,36 +435,6 @@ public void testAppVersion2Patching() { logger.info("The cluster has been rolling started, and the version 2 application has been deployed correctly."); } - /** - * Patch the domain resource with a new image that contains a newer version of the application. - * - * Here is an example of the JSON patch string that is constructed in this method. - * - * [ - * {"op": "replace", "path": "/spec/image", "value": "mii-image:v2" } - * ] - * - * @param domainUID the unique identifier of the domain resource - * @param namespace the Kubernetes namespace that the domain is hosted - * @param image the name of the image that contains a newer version of the application - */ - private void patchDomainResourceIamge( - String domainUID, - String namespace, - String image - ) { - String patch = - String.format("[\n {\"op\": \"replace\", \"path\": \"/spec/image\", \"value\": \"%s\"}\n]\n", image); - logger.info("Patch string is : " + patch); - - assertTrue(patchDomainCustomResource( - domainUID, - namespace, - new V1Patch(patch), - V1Patch.PATCH_FORMAT_JSON_PATCH), - "Failed to patch the domain resource with a a different image."); - } - /** * Uninstall Operator, delete service account, domain namespace and * operator namespace. @@ -511,7 +481,7 @@ public void tearDownAll() { } } - private String createFirstDomainImage() { + private String createInitialDomainImage() { // create unique image name with date DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); Date date = new Date(); @@ -557,6 +527,37 @@ private String updateImageWithAppV2Patch( } + /** + * Patch the domain resource with a new image that contains a newer version of the application. + * + * Here is an example of the JSON patch string that is constructed in this method. + * + * [ + * {"op": "replace", "path": "/spec/image", "value": "mii-image:v2" } + * ] + * + * @param domainUid the unique identifier of the domain resource + * @param namespace the Kubernetes namespace that the domain is hosted + * @param image the name of the image that contains a newer version of the application + */ + private void patchDomainResourceIamge( + String domainUid, + String namespace, + String image + ) { + String patch = + String.format("[\n {\"op\": \"replace\", \"path\": \"/spec/image\", \"value\": \"%s\"}\n]\n", + image); + logger.info("Patch string is : " + patch); + + assertTrue(patchDomainCustomResource( + domainUid, + namespace, + new V1Patch(patch), + V1Patch.PATCH_FORMAT_JSON_PATCH), + "Failed to patch the domain resource with a a different image."); + } + private void createImageAndVerify( String imageName, String imageTag, @@ -572,8 +573,8 @@ private void createImageAndVerify( // build an image using WebLogic Image Tool logger.info("Create image {0}:{1} using model directory {2}", imageName, imageTag, MODEL_DIR); - boolean result = createMIIImage( - defaultWITParams() + boolean result = createMiiImage( + defaultWitParams() .modelImageName(imageName) .modelImageTag(imageTag) .modelFiles(modelList) @@ -635,7 +636,7 @@ private void checkServiceCreated(String serviceName) { } private void checkAppRunning( - String domainUID, + String domainUid, String ns, String nodePort, String internalPort, @@ -652,7 +653,7 @@ private void checkAppRunning( domainNamespace, condition.getElapsedTimeInMS(), condition.getRemainingTimeInMS())) - .until(assertDoesNotThrow(() -> appAccessibleInPodCallable(domainUID, ns, internalPort, appPath, expectedStr), + .until(assertDoesNotThrow(() -> appAccessibleInPodCallable(domainUid, ns, internalPort, appPath, expectedStr), String.format( "App %s is not ready in namespace %s", appPath, domainNamespace))); diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItWitValidation.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItWitValidation.java index e84691b8944..832cd93c51a 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItWitValidation.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItWitValidation.java @@ -44,7 +44,7 @@ public void testCreatingMiiImage() { // build an application archive using what is in resources/apps/APP_NAME boolean archiveBuilt = buildAppArchive( defaultAppParams() - .srcDir(APP_NAME)); + .srcDirList(Collections.singletonList(APP_NAME))); assertThat(archiveBuilt) .as("Create an app archive") diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Application.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Application.java index 30a5b268001..745caf7e4a7 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Application.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Application.java @@ -5,20 +5,17 @@ import oracle.weblogic.kubernetes.actions.impl.primitive.Command; import oracle.weblogic.kubernetes.actions.impl.primitive.CommandParams; -import oracle.weblogic.kubernetes.logging.LoggingFacade; -import oracle.weblogic.kubernetes.logging.LoggingFactory; /** - * Assertions for applications in a domain. + * Assertions for applications that are deployed in a domain custom resource. * */ public class Application { - private static final LoggingFacade logger = LoggingFactory.getLogger(Application.class); /** * Check if an application is accessible inside a WebLogic server pod. - * @param domainUID unique identifier of the Kubernetes domain custom resource instance + * @param domainUID identifier of the Kubernetes domain custom resource instance * @param domainNS Kubernetes namespace where the WebLogic servers are running * @param port internal port of the managed servers * @param appPath the path to access the application @@ -51,13 +48,9 @@ private static String verifyAppInPod( port, appPath); - return exec(cmd, true); - } - - private static String exec(String command, boolean redirectOutput) { CommandParams params = Command .defaultCommandParams() - .command(command) + .command(cmd) .saveResults(true) .redirect(false) .debug(false); diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/utils/FileUtils.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/utils/FileUtils.java index 89b22c607d8..c79fec2b8c1 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/utils/FileUtils.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/utils/FileUtils.java @@ -102,9 +102,9 @@ public static void copyFolder(String srcDir, String destDir) throws IOException try { copy(source, destPath.resolve(srcPath.relativize(source))); } catch (IOException e) { - e.printStackTrace(); + logger.severe(String.format("Failed to copy file %s", source), e); // cannot throw non runtime exception. the caller checks throwable - throw new RuntimeException("Failed to copy file " + source + " due to:" + e.getMessage()); + throw new RuntimeException("Failed to copy file " + source); } }); } From dd2745f0a5fbb7ccd60004f10d66d7592cd97152 Mon Sep 17 00:00:00 2001 From: doxiao Date: Wed, 22 Apr 2020 19:53:36 +0000 Subject: [PATCH 10/69] more cleanup --- .../test/java/oracle/weblogic/kubernetes/ItMiiDomain.java | 2 -- .../oracle/weblogic/kubernetes/actions/impl/AppBuilder.java | 5 +++++ .../oracle/weblogic/kubernetes/actions/impl/AppParams.java | 3 --- .../weblogic/kubernetes/actions/impl/primitive/Command.java | 4 ++++ .../weblogic/kubernetes/assertions/impl/Application.java | 2 ++ 5 files changed, 11 insertions(+), 5 deletions(-) diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java index fb5f4f7fa19..8381387bfb6 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java @@ -529,9 +529,7 @@ private String updateImageWithAppV2Patch( /** * Patch the domain resource with a new image that contains a newer version of the application. - * * Here is an example of the JSON patch string that is constructed in this method. - * * [ * {"op": "replace", "path": "/spec/image", "value": "mii-image:v2" } * ] diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/AppBuilder.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/AppBuilder.java index 5d372a6ad88..71e26f5a52f 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/AppBuilder.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/AppBuilder.java @@ -66,6 +66,11 @@ public boolean build() { logger.severe("Failed to get the directory " + ARCHIVE_DIR + " ready", e); return false; } + + // make sure that we always have an app name + if (params.appName() == null) { + params.appName(params.srcDirList().get(0)); + } // build the app archive String jarPath = String.format("%s.ear", params.appName()); diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/AppParams.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/AppParams.java index ee728903557..bd00cdb4f1d 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/AppParams.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/AppParams.java @@ -45,9 +45,6 @@ public AppParams appName(String appName) { } public String appName() { - if (appName == null) { - return srcDirList.get(0); - } return appName; } diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/primitive/Command.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/primitive/Command.java index 0f829a2940b..d2b6077087c 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/primitive/Command.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/primitive/Command.java @@ -18,6 +18,10 @@ public class Command { private CommandParams params; + // This is private because the static methods are supposed to be used from outside + private Command() { + } + /** * Create a CommandParams instance with the default values. * @return a CommandParams instance diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Application.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Application.java index 745caf7e4a7..7867debe05a 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Application.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Application.java @@ -39,6 +39,8 @@ private static String verifyAppInPod( ) { String msPodName = domainUID + "-managed-server1"; + // TODO currently calling "kubectl exec" command; will change it to use a Kubernetes + // action once that action for "exec" command is available. // access the application deployed on managed-server1 String cmd = String.format( "kubectl -n %s exec -it %s -- /bin/bash -c 'curl http://%s:%s/%s'", From fa28b4c77f3d8c9a5694a49dd877693fb5e5740d Mon Sep 17 00:00:00 2001 From: doxiao Date: Wed, 22 Apr 2020 20:38:59 +0000 Subject: [PATCH 11/69] Initial change for test number 6 --- .../weblogic/kubernetes/ItMiiDomain.java | 90 ++++++++++++++++++- .../kubernetes/actions/ActionConstants.java | 4 +- .../actions/impl/primitive/Command.java | 4 - 3 files changed, 91 insertions(+), 7 deletions(-) diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java index 8381387bfb6..4c9faf85fc0 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java @@ -102,6 +102,7 @@ class ItMiiDomain implements LoggedTest { // mii constants private static final String WDT_MODEL_FILE = "model1-wls.yaml"; private static final String MII_IMAGE_NAME = "mii-image"; + private static final String MII_IMAGE_NAME_2 = "mii-image-2"; private static final String APP_NAME = "sample-app"; // domain constants @@ -376,7 +377,7 @@ public void testCreateMiiDomain() { } @Test - @Order(2) + @Order(4) @DisplayName("Update the sample-app application to version 2") @Slow @MustNotRunInParallel @@ -435,6 +436,67 @@ public void testAppVersion2Patching() { logger.info("The cluster has been rolling started, and the version 2 application has been deployed correctly."); } + @Test + @Order(5) + @DisplayName("Update the domain with another application") + @Slow + @MustNotRunInParallel + public void testAnotherAppDeployment() { + + // app here is what is in the original app dir plus the delta in the second app dir + final String appDir1 = "sample-app"; + final String appDir2 = "sample-app-3"; + + // create another image with app V2 + String image = updateImageWithApp3( + MII_IMAGE_NAME_2, + Arrays.asList(appDir1), + appDir2); + + // check and V1 app is running + assertTrue(appAccessibleInPod( + domainUid, + domainNamespace, + "8001", + "sample-war/index.jsp", + APP_RESPONSE_V1), + "The expected app is not accessible inside the server pod"); + + // check and make sure that the version 2 app is NOT running + assertFalse(appAccessibleInPod( + domainUid, + domainNamespace, + "8001", + "sample-war/index.jsp", + APP_RESPONSE_V2), + "The second version of the app is not supposed to be running!!"); + + // modify the domain resource to use the new image + patchDomainResourceIamge(domainUid, domainNamespace, image); + + // Ideally we want to verify that the server pods were rolling restarted. + // But it is hard to time the pod state transitions. + // Instead, sleep for 2 minutes and check the newer version of the application. + // The application check is sufficient to verify that the version2 application + // is running, thus the servers have been patched. + try { + TimeUnit.MINUTES.sleep(2); + } catch (InterruptedException ie) { + // do nothing + } + + // check and wait for the app to be ready + checkAppRunning( + domainUid, + domainNamespace, + "30711", + "8001", + "sample-war/index.jsp", + APP_RESPONSE_V2); + + logger.info("The cluster has been rolling started, and the version 2 application has been deployed correctly."); + } + /** * Uninstall Operator, delete service account, domain namespace and * operator namespace. @@ -527,6 +589,32 @@ private String updateImageWithAppV2Patch( } + private String updateImageWithApp3( + String imageName, + List appDirList, + String appName + ) { + // build the model file list + List modelList = Collections.singletonList(MODEL_DIR + "/" + WDT_MODEL_FILE); + + // build an application archive using what is in resources/apps/{appDirList(0)} + + boolean archiveBuilt = buildAppArchive( + defaultAppParams() + .srcDirList(appDirList) + .appName(appName)); + + assertTrue(archiveBuilt, String.format("Failed to create app archive for %s", appName)); + + // build the archive list + String zipFile = String.format("%s/%s.zip", ARCHIVE_DIR, appName); + List archiveList = Collections.singletonList(zipFile); + createImageAndVerify( + imageName, "v2", modelList, archiveList); + return imageName + ":" + "v2"; + + } + /** * Patch the domain resource with a new image that contains a newer version of the application. * Here is an example of the JSON patch string that is constructed in this method. diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/ActionConstants.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/ActionConstants.java index f5d0d30cbeb..e8987abc275 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/ActionConstants.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/ActionConstants.java @@ -43,12 +43,12 @@ public interface ActionConstants { public static final String WIT_DOWNLOAD_URL = "https://github.com/oracle/weblogic-image-tool"; - public static final String WIT_VERSION = System.getProperty("wit.version"); + public static final String WIT_VERSION = System.getProperty("wit.version", "latest"); public static final String WIT_FILE_NAME = "imagetool.zip"; public static final String WDT_DOWNLOAD_URL = "https://github.com/oracle/weblogic-deploy-tooling"; - public static final String WDT_VERSION = System.getProperty("wdt.version"); + public static final String WDT_VERSION = System.getProperty("wdt.version", "latest"); public static final String WDT_FILE_NAME = "weblogic-deploy.zip"; public static final String IMAGE_TOOL = WORK_DIR + "/imagetool/bin/imagetool.sh"; diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/primitive/Command.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/primitive/Command.java index d2b6077087c..0f829a2940b 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/primitive/Command.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/primitive/Command.java @@ -18,10 +18,6 @@ public class Command { private CommandParams params; - // This is private because the static methods are supposed to be used from outside - private Command() { - } - /** * Create a CommandParams instance with the default values. * @return a CommandParams instance From 32d0238959c9528f1f83a486594c12f9ef96113c Mon Sep 17 00:00:00 2001 From: doxiao Date: Wed, 22 Apr 2020 23:31:31 +0000 Subject: [PATCH 12/69] Fix ExecCommand to allow both redirect and saveResults enabled the same time --- .../weblogic/kubernetes/utils/ExecCommand.java | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/utils/ExecCommand.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/utils/ExecCommand.java index c5b30272576..9635060dac0 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/utils/ExecCommand.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/utils/ExecCommand.java @@ -64,8 +64,13 @@ public static ExecResult exec( Thread out = null; try { + String stdout = null; if (isRedirectToOut) { InputStream i = in.getInputStream(); + i.mark(0); + // read the stdout first, and reset before we redirect the output + stdout = read(i); + i.reset(); @SuppressWarnings("resource") CopyingOutputStream copyOut = new CopyingOutputStream(System.out); // this makes sense because CopyingOutputStream is an InputStreamWrapper @@ -80,10 +85,16 @@ public static ExecResult exec( } }); out.start(); - } - + } + p.waitFor(); - return new ExecResult(p.exitValue(), read(in.getInputStream()), read(p.getErrorStream())); + + // if we have not read the stdout, we do it now + if (stdout == null) { + stdout = read(in.getInputStream()); + } + return new ExecResult(p.exitValue(), stdout, read(p.getErrorStream())); + } finally { if (out != null) { out.join(); From 92ac716d86b1e08e42b052d9152c2f13d625a2a4 Mon Sep 17 00:00:00 2001 From: doxiao Date: Thu, 23 Apr 2020 14:30:22 +0000 Subject: [PATCH 13/69] Initial change for adding another app --- .../weblogic/kubernetes/ItMiiDomain.java | 104 +++++++++++------- .../weblogic/kubernetes/utils/FileUtils.java | 6 +- 2 files changed, 70 insertions(+), 40 deletions(-) diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java index 4c9faf85fc0..51b4d3ccb1a 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java @@ -3,6 +3,7 @@ package oracle.weblogic.kubernetes; +import java.io.IOException; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Arrays; @@ -50,6 +51,7 @@ import static java.util.concurrent.TimeUnit.MINUTES; import static java.util.concurrent.TimeUnit.SECONDS; import static oracle.weblogic.kubernetes.actions.ActionConstants.ARCHIVE_DIR; +import static oracle.weblogic.kubernetes.actions.ActionConstants.DOWNLOAD_DIR; import static oracle.weblogic.kubernetes.actions.ActionConstants.MODEL_DIR; import static oracle.weblogic.kubernetes.actions.ActionConstants.WDT_VERSION; import static oracle.weblogic.kubernetes.actions.ActionConstants.WIT_BUILD_DIR; @@ -80,6 +82,7 @@ import static oracle.weblogic.kubernetes.assertions.TestAssertions.podReady; import static oracle.weblogic.kubernetes.assertions.TestAssertions.serviceExists; import static oracle.weblogic.kubernetes.utils.FileUtils.checkDirectory; +import static oracle.weblogic.kubernetes.utils.FileUtils.cleanupDirectory; import static org.awaitility.Awaitility.with; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertFalse; @@ -102,7 +105,6 @@ class ItMiiDomain implements LoggedTest { // mii constants private static final String WDT_MODEL_FILE = "model1-wls.yaml"; private static final String MII_IMAGE_NAME = "mii-image"; - private static final String MII_IMAGE_NAME_2 = "mii-image-2"; private static final String APP_NAME = "sample-app"; // domain constants @@ -112,6 +114,7 @@ class ItMiiDomain implements LoggedTest { // app constants private static final String APP_RESPONSE_V1 = "Hello World, you have reached server managed-server1"; private static final String APP_RESPONSE_V2 = "Hello World AGAIN, you have reached server managed-server1"; + private static final String APP_RESPONSE_V3 = "How are you doing!"; private static HelmParams opHelmParams = null; private static V1ServiceAccount serviceAccount = null; @@ -367,7 +370,6 @@ public void testCreateMiiDomain() { checkAppRunning( domainUid, domainNamespace, - "30711", "8001", "sample-war/index.jsp", APP_RESPONSE_V1); @@ -383,7 +385,7 @@ public void testCreateMiiDomain() { @MustNotRunInParallel public void testAppVersion2Patching() { - // app here is what is in the original app dir plus the delta in the second app dir + // app here is what is in the original app dir plus the replacement in the second app dir final String appDir1 = "sample-app"; final String appDir2 = "sample-app-2"; @@ -428,7 +430,6 @@ public void testAppVersion2Patching() { checkAppRunning( domainUid, domainNamespace, - "30711", "8001", "sample-war/index.jsp", APP_RESPONSE_V2); @@ -441,35 +442,37 @@ public void testAppVersion2Patching() { @DisplayName("Update the domain with another application") @Slow @MustNotRunInParallel - public void testAnotherAppDeployment() { + public void testAddAnotherApp() { // app here is what is in the original app dir plus the delta in the second app dir final String appDir1 = "sample-app"; - final String appDir2 = "sample-app-3"; - - // create another image with app V2 + final String appDir2 = "sample-app-2"; + final String appDir3 = "sample-app-3"; + + // create another image with an additional app String image = updateImageWithApp3( - MII_IMAGE_NAME_2, - Arrays.asList(appDir1), - appDir2); + MII_IMAGE_NAME, + Arrays.asList(appDir1, appDir2), + Collections.singletonList(appDir3), + "model2-wls.yaml"); - // check and V1 app is running + // check and V2 app is still running assertTrue(appAccessibleInPod( domainUid, domainNamespace, "8001", "sample-war/index.jsp", - APP_RESPONSE_V1), + APP_RESPONSE_V2), "The expected app is not accessible inside the server pod"); - // check and make sure that the version 2 app is NOT running + // check and make sure that the new app is not already running assertFalse(appAccessibleInPod( domainUid, domainNamespace, "8001", - "sample-war/index.jsp", - APP_RESPONSE_V2), - "The second version of the app is not supposed to be running!!"); + "sample-war-3/index.jsp", + APP_RESPONSE_V3), + "The second app is not supposed to be running!!"); // modify the domain resource to use the new image patchDomainResourceIamge(domainUid, domainNamespace, image); @@ -485,16 +488,23 @@ public void testAnotherAppDeployment() { // do nothing } - // check and wait for the app to be ready + // check and wait for the original app to be ready + checkAppRunning( + domainUid, + domainNamespace, + "8001", + "sample-war/index.jsp", + APP_RESPONSE_V2); + + // check and wait for the new app to be ready checkAppRunning( domainUid, domainNamespace, - "30711", "8001", - "sample-war/index.jsp", - APP_RESPONSE_V2); + "sample-war-3/index.jsp", + APP_RESPONSE_V3); - logger.info("The cluster has been rolling started, and the version 2 application has been deployed correctly."); + logger.info("The cluster has been rolling started, and the two applications are both running correctly."); } /** @@ -541,6 +551,14 @@ public void tearDownAll() { "deleteNamespace failed with ApiException"); logger.info("Deleted namespace: " + opNamespace); } + + // clean up the download directory so that we can get always the latest + // versions of the tools + try { + cleanupDirectory(DOWNLOAD_DIR); + } catch (IOException | RuntimeException e) { + logger.severe("Failed to cleanup the download directory " + DOWNLOAD_DIR + " ready", e); + } } private String createInitialDomainImage() { @@ -591,27 +609,40 @@ private String updateImageWithAppV2Patch( private String updateImageWithApp3( String imageName, - List appDirList, - String appName + List appDirList1, + List appDirList2, + String modelFile ) { // build the model file list - List modelList = Collections.singletonList(MODEL_DIR + "/" + WDT_MODEL_FILE); - - // build an application archive using what is in resources/apps/{appDirList(0)} - + List modelList = Collections.singletonList(MODEL_DIR + "/" + modelFile); + + String appName1 = appDirList1.get(0); + String appName2 = appDirList2.get(0); + + // build an application archive using for the first app, which is the same after + // patching the original app. boolean archiveBuilt = buildAppArchive( defaultAppParams() - .srcDirList(appDirList) - .appName(appName)); + .srcDirList(appDirList1) + .appName(appName1)); - assertTrue(archiveBuilt, String.format("Failed to create app archive for %s", appName)); + assertTrue(archiveBuilt, String.format("Failed to create app archive for %s", appName1)); + + archiveBuilt = buildAppArchive( + defaultAppParams() + .srcDirList(appDirList2) + .appName(appName2)); + + assertTrue(archiveBuilt, String.format("Failed to create app archive for %s", appName2)); + + // build the archive list with two zip files + List archiveList = Arrays.asList( + String.format("%s/%s.zip", ARCHIVE_DIR, appName1), + String.format("%s/%s.zip", ARCHIVE_DIR, appName2)); - // build the archive list - String zipFile = String.format("%s/%s.zip", ARCHIVE_DIR, appName); - List archiveList = Collections.singletonList(zipFile); createImageAndVerify( - imageName, "v2", modelList, archiveList); - return imageName + ":" + "v2"; + imageName, "v3", modelList, archiveList); + return imageName + ":" + "v3"; } @@ -724,7 +755,6 @@ private void checkServiceCreated(String serviceName) { private void checkAppRunning( String domainUid, String ns, - String nodePort, String internalPort, String appPath, String expectedStr diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/utils/FileUtils.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/utils/FileUtils.java index c79fec2b8c1..6aef84c781a 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/utils/FileUtils.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/utils/FileUtils.java @@ -35,7 +35,7 @@ public static void checkDirectory(String dir) { File file = new File(dir); if (!(file.exists() && file.isDirectory())) { file.mkdirs(); - logger.info("Made a new dir {0}.", dir); + logger.fine("Made a new dir {0}.", dir); } } @@ -74,7 +74,7 @@ public static boolean doesFileExist(String fileName) { */ public static void cleanupDirectory(String dir) throws IOException { File file = new File(dir); - logger.info("Cleaning up directory {0}.", dir); + logger.fine("Cleaning up directory {0}.", dir); if (!file.exists()) { // nothing to do return; @@ -111,7 +111,7 @@ public static void copyFolder(String srcDir, String destDir) throws IOException } private static void copy(Path source, Path dest) throws IOException { - logger.info("Copying {0} to {1} source.fileName = {2}", source, dest, source.getFileName()); + logger.finest("Copying {0} to {1} source.fileName = {2}", source, dest, source.getFileName()); if (!dest.toFile().isDirectory()) { Files.copy(source, dest, REPLACE_EXISTING); } From d41efedb81bf0d4cd2137cf846a266da65dbfa95 Mon Sep 17 00:00:00 2001 From: doxiao Date: Thu, 23 Apr 2020 21:12:40 +0000 Subject: [PATCH 14/69] More impl for the second test case --- .../oracle/weblogic/kubernetes/ItMiiDomain.java | 5 ++++- .../kubernetes/actions/impl/AppBuilder.java | 2 +- .../actions/impl/primitive/Command.java | 4 ++-- .../actions/impl/primitive/CommandParams.java | 10 +++++----- .../actions/impl/primitive/Installer.java | 2 +- .../actions/impl/primitive/WebLogicImageTool.java | 6 +++++- .../kubernetes/assertions/impl/Application.java | 2 +- .../apps/sample-app-3/META-INF/MANIFEST.MF | 3 +++ .../apps/sample-app-3/META-INF/application.xml | 15 +++++++++++++++ .../META-INF/weblogic-application.xml | 7 +++++++ .../sample-app-3/sample-war-3/WEB-INF/web.xml | 7 +++++++ .../sample-war-3/WEB-INF/weblogic.xml | 15 +++++++++++++++ .../apps/sample-app-3/sample-war-3/index.jsp | 7 +++++++ 13 files changed, 73 insertions(+), 12 deletions(-) create mode 100644 new-integration-tests/src/test/resources/apps/sample-app-3/META-INF/MANIFEST.MF create mode 100644 new-integration-tests/src/test/resources/apps/sample-app-3/META-INF/application.xml create mode 100644 new-integration-tests/src/test/resources/apps/sample-app-3/META-INF/weblogic-application.xml create mode 100644 new-integration-tests/src/test/resources/apps/sample-app-3/sample-war-3/WEB-INF/web.xml create mode 100644 new-integration-tests/src/test/resources/apps/sample-app-3/sample-war-3/WEB-INF/weblogic.xml create mode 100644 new-integration-tests/src/test/resources/apps/sample-app-3/sample-war-3/index.jsp diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java index 6dae9516c53..ef9eb0c047d 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java @@ -12,6 +12,7 @@ import java.util.Date; import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.concurrent.TimeUnit; import com.google.gson.JsonObject; @@ -458,7 +459,7 @@ public void testAddSecondApp() { Arrays.asList(appDir1, appDir2), Collections.singletonList(appDir3), "model2-wls.yaml"); - + logger.info("Image is successfully created"); // check and V2 app is still running assertTrue(appAccessibleInPod( domainUid, @@ -467,6 +468,7 @@ public void testAddSecondApp() { "sample-war/index.jsp", APP_RESPONSE_V2), "The expected app is not accessible inside the server pod"); + logger.info("App version 2 is still running"); // check and make sure that the new app is not already running assertFalse(appAccessibleInPod( @@ -476,6 +478,7 @@ public void testAddSecondApp() { "sample-war-3/index.jsp", APP_RESPONSE_V3), "The second app is not supposed to be running!!"); + logger.info("About to patch the domain with new image"); // modify the domain resource to use the new image patchDomainResourceIamge(domainUid, domainNamespace, miiImageAddSecondApp); diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/AppBuilder.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/AppBuilder.java index 71e26f5a52f..eb6535c56a8 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/AppBuilder.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/AppBuilder.java @@ -55,7 +55,7 @@ private AppBuilder params(AppParams params) { public boolean build() { // prepare the archive directory and copy over the app src try { - cleanupDirectory(ARCHIVE_DIR); + cleanupDirectory(ARCHIVE_SRC_DIR); checkDirectory(ARCHIVE_SRC_DIR); for (String item: params.srcDirList()) { copyFolder( diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/primitive/Command.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/primitive/Command.java index 0f829a2940b..77f0a01b9c6 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/primitive/Command.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/primitive/Command.java @@ -44,7 +44,7 @@ private Command params(CommandParams params) { * @return true, on success */ public boolean execute() { - if (params.debug()) { + if (params.verbose()) { logger.info("Executing command {0}", params.command()); } try { @@ -58,7 +58,7 @@ public boolean execute() { } // check exitValue to determine if the command execution has failed. - if (params.debug() && result.exitValue() != 0) { + if (params.verbose() && result.exitValue() != 0) { logger.severe("The command execution failed because it returned non-zero exit value: {0}.", result); } diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/primitive/CommandParams.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/primitive/CommandParams.java index 577df4bf39e..f34db0faa33 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/primitive/CommandParams.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/primitive/CommandParams.java @@ -29,7 +29,7 @@ public class CommandParams { // The stderr of the command execution private String stderr; - private boolean debug = false; + private boolean verbose = true; public CommandParams defaults() { return this; @@ -89,13 +89,13 @@ public String stdout() { return stdout; } - public CommandParams debug(boolean debug) { - this.debug = debug; + public CommandParams verbose(boolean verbose) { + this.verbose = verbose; return this; } - public boolean debug() { - return debug; + public boolean verbose() { + return verbose; } } diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/primitive/Installer.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/primitive/Installer.java index 41de0d84bac..0a58c29fbba 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/primitive/Installer.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/primitive/Installer.java @@ -90,7 +90,7 @@ public boolean download() { boolean unzipSucceeded = true; if (params.verify() && new File(DOWNLOAD_DIR, params.fileName()).exists()) { - logger.info("File {0} already exists.", params.fileName()); + logger.fine("File {0} already exists.", params.fileName()); } else { // check and make sure DOWNLOAD_DIR exists; will create it if it is missing checkDirectory(DOWNLOAD_DIR); diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/primitive/WebLogicImageTool.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/primitive/WebLogicImageTool.java index cf3b5640f93..0580d85ef5d 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/primitive/WebLogicImageTool.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/primitive/WebLogicImageTool.java @@ -53,11 +53,15 @@ public boolean updateImage() { if (!downloadWit()) { return false; } - + + logger.info("Image Tool is ready"); + // download WDT if it is not in the expected location if (!downloadWdt()) { return false; } + + logger.info("WDT installer is ready"); // delete the old cache entry for the WDT installer if (!deleteEntry()) { diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Application.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Application.java index 7867debe05a..8154997aae7 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Application.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Application.java @@ -55,7 +55,7 @@ private static String verifyAppInPod( .command(cmd) .saveResults(true) .redirect(false) - .debug(false); + .verbose(false); Command.withParams(params).execute(); return params.stdout(); } diff --git a/new-integration-tests/src/test/resources/apps/sample-app-3/META-INF/MANIFEST.MF b/new-integration-tests/src/test/resources/apps/sample-app-3/META-INF/MANIFEST.MF new file mode 100644 index 00000000000..8a636006c23 --- /dev/null +++ b/new-integration-tests/src/test/resources/apps/sample-app-3/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Created-By: 1.8.0_201 (Oracle Corporation) + diff --git a/new-integration-tests/src/test/resources/apps/sample-app-3/META-INF/application.xml b/new-integration-tests/src/test/resources/apps/sample-app-3/META-INF/application.xml new file mode 100644 index 00000000000..0f9a5fc527b --- /dev/null +++ b/new-integration-tests/src/test/resources/apps/sample-app-3/META-INF/application.xml @@ -0,0 +1,15 @@ + + + + JSP 2.0 Expression Language Example + JSP 2.0 Expression Language Example + + + sample-war-3 + sample-war-3 + + + diff --git a/new-integration-tests/src/test/resources/apps/sample-app-3/META-INF/weblogic-application.xml b/new-integration-tests/src/test/resources/apps/sample-app-3/META-INF/weblogic-application.xml new file mode 100644 index 00000000000..90f03062d3c --- /dev/null +++ b/new-integration-tests/src/test/resources/apps/sample-app-3/META-INF/weblogic-application.xml @@ -0,0 +1,7 @@ + + + + diff --git a/new-integration-tests/src/test/resources/apps/sample-app-3/sample-war-3/WEB-INF/web.xml b/new-integration-tests/src/test/resources/apps/sample-app-3/sample-war-3/WEB-INF/web.xml new file mode 100644 index 00000000000..8640ebd65af --- /dev/null +++ b/new-integration-tests/src/test/resources/apps/sample-app-3/sample-war-3/WEB-INF/web.xml @@ -0,0 +1,7 @@ + + + + diff --git a/new-integration-tests/src/test/resources/apps/sample-app-3/sample-war-3/WEB-INF/weblogic.xml b/new-integration-tests/src/test/resources/apps/sample-app-3/sample-war-3/WEB-INF/weblogic.xml new file mode 100644 index 00000000000..9d45e41cb8b --- /dev/null +++ b/new-integration-tests/src/test/resources/apps/sample-app-3/sample-war-3/WEB-INF/weblogic.xml @@ -0,0 +1,15 @@ + + + + + 15 + 60 + + + 1 + true + + diff --git a/new-integration-tests/src/test/resources/apps/sample-app-3/sample-war-3/index.jsp b/new-integration-tests/src/test/resources/apps/sample-app-3/sample-war-3/index.jsp new file mode 100644 index 00000000000..5deeda03004 --- /dev/null +++ b/new-integration-tests/src/test/resources/apps/sample-app-3/sample-war-3/index.jsp @@ -0,0 +1,7 @@ +<%-- +Copyright (c) 2020, Oracle Corporation and/or its affiliates. +Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. +--%> +<% + out.println("How are you doing!); +%> From 754bf4497d8fd23bc3b9771cb8aa0d0cef7ab3cf Mon Sep 17 00:00:00 2001 From: doxiao Date: Thu, 23 Apr 2020 21:40:32 +0000 Subject: [PATCH 15/69] Add model file for the second app --- .../weblogic/kubernetes/ItMiiDomain.java | 63 +++++++++++-------- .../test/resources/wdt-models/model2-wls.yaml | 38 +++++++++++ 2 files changed, 74 insertions(+), 27 deletions(-) create mode 100644 new-integration-tests/src/test/resources/wdt-models/model2-wls.yaml diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java index ef9eb0c047d..ae480e2086e 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java @@ -578,7 +578,8 @@ private String createInitialDomainImage() { final String imageTag = dateFormat.format(date) + "-" + System.currentTimeMillis(); // build the model file list - final List modelList = Collections.singletonList(MODEL_DIR + "/" + WDT_MODEL_FILE); + final List modelList = + Collections.singletonList(String.format("%s/%s", MODEL_DIR, WDT_MODEL_FILE)); // build an application archive using what is in resources/apps/APP_NAME assertTrue(buildAppArchive(defaultAppParams() @@ -586,8 +587,8 @@ private String createInitialDomainImage() { String.format("Failed to create app archive for %s", APP_NAME)); // build the archive list - String zipFile = String.format("%s/%s.zip", ARCHIVE_DIR, APP_NAME); - List archiveList = Collections.singletonList(zipFile); + List archiveList = + Collections.singletonList(String.format("%s/%s.zip", ARCHIVE_DIR, APP_NAME)); createImageAndVerify(MII_IMAGE_NAME, imageTag, modelList, archiveList); @@ -600,22 +601,25 @@ private String updateImageWithAppV2Patch( List appDirList ) { // build the model file list - List modelList = Collections.singletonList(MODEL_DIR + "/" + WDT_MODEL_FILE); + List modelList = + Collections.singletonList(String.format("%s/%s", MODEL_DIR, WDT_MODEL_FILE)); // build an application archive using what is in resources/apps/APP_NAME - boolean archiveBuilt = buildAppArchive( - defaultAppParams() - .srcDirList(appDirList)); - - assertTrue(archiveBuilt, String.format("Failed to create app archive for %s", APP_NAME)); + assertTrue( + buildAppArchive( + defaultAppParams() + .srcDirList(appDirList)), + String.format("Failed to create app archive for %s", + APP_NAME)); // build the archive list - String zipFile = String.format("%s/%s.zip", ARCHIVE_DIR, APP_NAME); - List archiveList = Collections.singletonList(zipFile); - createImageAndVerify( - imageName, imageTag, modelList, archiveList); + List archiveList = + Collections.singletonList( + String.format("%s/%s.zip", ARCHIVE_DIR, APP_NAME)); + + createImageAndVerify(imageName, imageTag, modelList, archiveList); + return imageName + ":" + imageTag; - } private String updateImageWithApp3( @@ -633,29 +637,34 @@ private String updateImageWithApp3( // build an application archive using for the first app, which is the same after // patching the original app. - boolean archiveBuilt = buildAppArchive( - defaultAppParams() - .srcDirList(appDirList1) - .appName(appName1)); + assertTrue( + buildAppArchive( + defaultAppParams() + .srcDirList(appDirList1) + .appName(appName1)), + String.format("Failed to create app archive for %s", + appName1)); - assertTrue(archiveBuilt, String.format("Failed to create app archive for %s", appName1)); logger.info("Successfully created app zip file: " + appName1); - archiveBuilt = buildAppArchive( + + assertTrue( + buildAppArchive( defaultAppParams() .srcDirList(appDirList2) - .appName(appName2)); - - assertTrue(archiveBuilt, String.format("Failed to create app archive for %s", appName2)); - logger.info("Successfully cteated app zip file: " + appName2); + .appName(appName2)), + String.format("Failed to create app archive for %s", + appName2)); + + logger.info("Successfully cteated app zip file: " + appName2); + // build the archive list with two zip files List archiveList = Arrays.asList( String.format("%s/%s.zip", ARCHIVE_DIR, appName1), String.format("%s/%s.zip", ARCHIVE_DIR, appName2)); - createImageAndVerify( - imageName, imageTag, modelList, archiveList); + createImageAndVerify(imageName, imageTag, modelList, archiveList); + return imageName + ":" + imageTag; - } /** diff --git a/new-integration-tests/src/test/resources/wdt-models/model2-wls.yaml b/new-integration-tests/src/test/resources/wdt-models/model2-wls.yaml new file mode 100644 index 00000000000..c7b67b3e8c5 --- /dev/null +++ b/new-integration-tests/src/test/resources/wdt-models/model2-wls.yaml @@ -0,0 +1,38 @@ +# Copyright (c) 2020, Oracle Corporation and/or its affiliates. +# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + +domainInfo: + AdminUserName: '@@SECRET:__weblogic-credentials__:username@@' + AdminPassword: '@@SECRET:__weblogic-credentials__:password@@' + ServerStartMode: 'prod' + +topology: + Name: "wls-domain1" + AdminServerName: "admin-server" + Cluster: + "cluster-1": + DynamicServers: + ServerTemplate: "cluster-1-template" + ServerNamePrefix: "managed-server" + DynamicClusterSize: 2 + MaxDynamicClusterSize: 5 + CalculatedListenPorts: false + Server: + "admin-server": + ListenPort: 7001 + ServerTemplate: + "cluster-1-template": + Cluster: "cluster-1" + ListenPort : 8001 + +appDeployments: + Application: + myear: + SourcePath: "wlsdeploy/applications/sample-app.ear" + ModuleType: ear + Target: 'cluster-1' + + myear3: + SourcePath: "wlsdeploy/applications/sample-app-3.ear" + ModuleType: ear + Target: 'cluster-1' From c5532b3d39e36c8062d588ced8abc7d5795da0e1 Mon Sep 17 00:00:00 2001 From: doxiao Date: Thu, 23 Apr 2020 21:42:50 +0000 Subject: [PATCH 16/69] Minor cleanup --- .../java/oracle/weblogic/kubernetes/utils/ExecCommand.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/utils/ExecCommand.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/utils/ExecCommand.java index 9635060dac0..13136c56a4b 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/utils/ExecCommand.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/utils/ExecCommand.java @@ -85,8 +85,8 @@ public static ExecResult exec( } }); out.start(); - } - + } + p.waitFor(); // if we have not read the stdout, we do it now From be44a53d60cfe75b6ff342288af3c4e1ce399811 Mon Sep 17 00:00:00 2001 From: doxiao Date: Fri, 24 Apr 2020 01:30:23 +0000 Subject: [PATCH 17/69] Clean up comments --- .../weblogic/kubernetes/ItMiiDomain.java | 49 ++++++++++--------- .../kubernetes/actions/impl/AppParams.java | 9 ++-- 2 files changed, 30 insertions(+), 28 deletions(-) diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java index ae480e2086e..6ac8f3941b1 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java @@ -391,12 +391,6 @@ public void testPatchAppV2() { final String appDir1 = "sample-app"; final String appDir2 = "sample-app-2"; - // create another image with app V2 - miiImagePatchAppV2 = updateImageWithAppV2Patch( - MII_IMAGE_NAME, - "testPatchAppV2", - Arrays.asList(appDir1, appDir2)); - // check and V1 app is running assertTrue(appAccessibleInPod( domainUid, @@ -414,10 +408,18 @@ public void testPatchAppV2() { "sample-war/index.jsp", APP_RESPONSE_V2), "The second version of the app is not supposed to be running!!"); - + + // create another image with app V2 + miiImagePatchAppV2 = updateImageWithAppV2Patch( + MII_IMAGE_NAME, + "testPatchAppV2", + Arrays.asList(appDir1, appDir2)); + // modify the domain resource to use the new image patchDomainResourceIamge(domainUid, domainNamespace, miiImagePatchAppV2); + logger.info("Sleep for 2 minutes and allow the servers to be rolling restarted"); + // Ideally we want to verify that the server pods were rolling restarted. // But it is hard to time the pod state transitions. // Instead, sleep for 2 minutes and check the newer version of the application. @@ -451,15 +453,7 @@ public void testAddSecondApp() { final String appDir1 = "sample-app"; final String appDir2 = "sample-app-2"; final String appDir3 = "sample-app-3"; - - // create another image with an additional app - miiImageAddSecondApp = updateImageWithApp3( - MII_IMAGE_NAME, - "testAddSecondApp", - Arrays.asList(appDir1, appDir2), - Collections.singletonList(appDir3), - "model2-wls.yaml"); - logger.info("Image is successfully created"); + // check and V2 app is still running assertTrue(appAccessibleInPod( domainUid, @@ -477,12 +471,23 @@ public void testAddSecondApp() { "8001", "sample-war-3/index.jsp", APP_RESPONSE_V3), - "The second app is not supposed to be running!!"); + "The second app is not supposed to be running!!"); + logger.info("About to patch the domain with new image"); + // create another image with an additional app + miiImageAddSecondApp = updateImageWithApp3( + MII_IMAGE_NAME, + "testAddSecondApp", + Arrays.asList(appDir1, appDir2), + Collections.singletonList(appDir3), + logger.info("Image is successfully created"); + // modify the domain resource to use the new image patchDomainResourceIamge(domainUid, domainNamespace, miiImageAddSecondApp); + logger.info("Sleep for 2 minutes and allow the servers to be rolling restarted"); + // Ideally we want to verify that the server pods were rolling restarted. // But it is hard to time the pod state transitions. // Instead, sleep for 2 minutes and check the newer version of the application. @@ -496,11 +501,11 @@ public void testAddSecondApp() { // check and wait for the original app to be ready checkAppRunning( - domainUid, - domainNamespace, - "8001", - "sample-war/index.jsp", - APP_RESPONSE_V2); + domainUid, + domainNamespace, + "8001", + "sample-war/index.jsp", + APP_RESPONSE_V2); // check and wait for the new app to be ready checkAppRunning( diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/AppParams.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/AppParams.java index bd00cdb4f1d..e0be97a4c7f 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/AppParams.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/AppParams.java @@ -11,16 +11,13 @@ public class AppParams { - // Locations of the source code. - // This are the directory names under resources/apps for an application. + // A list of directories under resources/apps that are part of the application. // Note: the order of the directory names are significant. Files are copied into - // the staging directory in the order that corresponds to the order that the - // directories are located in the list. + // the staging directory in this order. private List srcDirList; // The name of the final ear file. - // When there is only one srcDir in the srcDirList, this is - // the name of that directory by default. + // The name of the first dir in srcDirList will be used if the appName is absent. private String appName; // Whether the output of the command is redirected to system out From 6f586f78d2bbae877c30eb8038216779af76294f Mon Sep 17 00:00:00 2001 From: doxiao Date: Fri, 24 Apr 2020 01:46:52 +0000 Subject: [PATCH 18/69] Minor fix --- .../src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java | 1 + 1 file changed, 1 insertion(+) diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java index 6ac8f3941b1..3dcc811d726 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java @@ -481,6 +481,7 @@ public void testAddSecondApp() { "testAddSecondApp", Arrays.asList(appDir1, appDir2), Collections.singletonList(appDir3), + "model2-wls.yaml"); logger.info("Image is successfully created"); // modify the domain resource to use the new image From 4d0b7bd398fdd7bf26902a85745bc510b6103378 Mon Sep 17 00:00:00 2001 From: doxiao Date: Fri, 24 Apr 2020 02:08:48 +0000 Subject: [PATCH 19/69] Move delete images to the end of AfterAll --- .../weblogic/kubernetes/ItMiiDomain.java | 26 ++++++++++--------- .../kubernetes/assertions/TestAssertions.java | 3 ++- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java index 3dcc811d726..a3b734d607b 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java @@ -418,7 +418,7 @@ public void testPatchAppV2() { // modify the domain resource to use the new image patchDomainResourceIamge(domainUid, domainNamespace, miiImagePatchAppV2); - logger.info("Sleep for 2 minutes and allow the servers to be rolling restarted"); + logger.info("Sleep for 2 minutes and wait for the servers to be rolling-restarted"); // Ideally we want to verify that the server pods were rolling restarted. // But it is hard to time the pod state transitions. @@ -487,7 +487,7 @@ public void testAddSecondApp() { // modify the domain resource to use the new image patchDomainResourceIamge(domainUid, domainNamespace, miiImageAddSecondApp); - logger.info("Sleep for 2 minutes and allow the servers to be rolling restarted"); + logger.info("Sleep for 2 minutes and wait for the servers to be rolling-restarted"); // Ideally we want to verify that the server pods were rolling restarted. // But it is hard to time the pod state transitions. @@ -531,15 +531,6 @@ public void tearDownAll() { "deleteDomainCustomResource failed with ApiException"); logger.info("Deleted Domain Custom Resource " + domainUid + " from " + domainNamespace); - // delete the domain image created for the test - if (miiImage != null) { - deleteImage(miiImage); - } - - // delete the domain images created in test #4 and #5 - deleteImage(miiImagePatchAppV2); - deleteImage(miiImageAddSecondApp); - // uninstall operator release logger.info("Uninstall Operator in namespace {0}", opNamespace); if (opHelmParams != null) { @@ -568,7 +559,18 @@ public void tearDownAll() { logger.info("Deleted namespace: " + opNamespace); } - // clean up the download directory so that we can get always the latest + // delete the domain images created in the test class + if (miiImage != null) { + deleteImage(miiImage); + } + if (miiImagePatchAppV2 != null) { + deleteImage(miiImagePatchAppV2); + } + if (miiImageAddSecondApp != null) { + deleteImage(miiImageAddSecondApp); + } + + // clean up the download directory so that we always get the latest // versions of the tools try { cleanupDirectory(DOWNLOAD_DIR); diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/TestAssertions.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/TestAssertions.java index c04fec1891c..4b4094489fb 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/TestAssertions.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/TestAssertions.java @@ -170,6 +170,7 @@ public static boolean dockerImageExists(String imageName, String imageTag) { /** * Check if an application is accessible inside a WebLogic server pod. + * * @param domainUID unique identifier of the Kubernetes domain custom resource instance * @param domainNS Kubernetes namespace where the WebLogic servers are running * @param port internal port of the managed servers @@ -188,7 +189,7 @@ public static boolean appAccessibleInPod( } /** - * Check if an application is accessible inside a server pod. + * Check if an application is accessible inside a WebLogic server pod. * . * @param domainUID unique identifier of the Kubernetes domain custom resource instance * @param domainNS Kubernetes namespace where the WebLogic servers are running From 3e714627616e7b5a40c04aa9aefd3b553dc22a89 Mon Sep 17 00:00:00 2001 From: doxiao Date: Fri, 24 Apr 2020 15:59:30 +0000 Subject: [PATCH 20/69] Update command to check response --- .../weblogic/kubernetes/ItMiiDomain.java | 62 +++++++++---------- .../actions/impl/primitive/Command.java | 38 +++++++++++- .../assertions/impl/Application.java | 15 +---- 3 files changed, 69 insertions(+), 46 deletions(-) diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java index a3b734d607b..5accfd2562f 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java @@ -122,7 +122,7 @@ class ItMiiDomain implements LoggedTest { private static String domainNamespace = null; private static ConditionFactory withStandardRetryPolicy = null; - private String domainUid = "domain1"; + private String domainUID = "domain1"; private String repoSecretName = "reposecret"; private String miiImage = null; private String miiImagePatchAppV2 = null; @@ -207,8 +207,8 @@ public static void initAll(@Namespaces(2) List namespaces) { @MustNotRunInParallel public void testCreateMiiDomain() { // admin/managed server name here should match with model yaml in WDT_MODEL_FILE - final String adminServerPodName = domainUid + "-admin-server"; - final String managedServerPrefix = domainUid + "-managed-server"; + final String adminServerPodName = domainUID + "-admin-server"; + final String managedServerPrefix = domainUID + "-managed-server"; final int replicaCount = 2; // create image with model files @@ -277,10 +277,10 @@ public void testCreateMiiDomain() { .apiVersion(API_VERSION) .kind("Domain") .metadata(new V1ObjectMeta() - .name(domainUid) + .name(domainUID) .namespace(domainNamespace)) .spec(new DomainSpec() - .domainUid(domainUid) + .domainUID(domainUID) .domainHomeSourceType("FromModel") .image(miiImage) .addImagePullSecretsItem(new V1LocalObjectReference() @@ -312,13 +312,13 @@ public void testCreateMiiDomain() { .domainType("WLS") .runtimeEncryptionSecret(encryptionSecretName)))); - logger.info("Create domain custom resource for domainUid {0} in namespace {1}", - domainUid, domainNamespace); + logger.info("Create domain custom resource for domainUID {0} in namespace {1}", + domainUID, domainNamespace); assertTrue(assertDoesNotThrow(() -> createDomainCustomResource(domain), String.format("Create domain custom resource failed with ApiException for %s in namespace %s", - domainUid, domainNamespace)), + domainUID, domainNamespace)), String.format("Create domain custom resource failed with ApiException for %s in namespace %s", - domainUid, domainNamespace)); + domainUID, domainNamespace)); // wait for the domain to exist @@ -327,11 +327,11 @@ public void testCreateMiiDomain() { .conditionEvaluationListener( condition -> logger.info("Waiting for domain {0} to be created in namespace {1} " + "(elapsed time {2}ms, remaining time {3}ms)", - domainUid, + domainUID, domainNamespace, condition.getElapsedTimeInMS(), condition.getRemainingTimeInMS())) - .until(domainExists(domainUid, DOMAIN_VERSION, domainNamespace)); + .until(domainExists(domainUID, DOMAIN_VERSION, domainNamespace)); // check admin server pod exist @@ -370,14 +370,14 @@ public void testCreateMiiDomain() { } checkAppRunning( - domainUid, + domainUID, domainNamespace, "8001", "sample-war/index.jsp", APP_RESPONSE_V1); logger.info(String.format("Domain %s is fully started - servers are running and application is deployed corretly.", - domainUid)); + domainUID)); } @Test @@ -393,7 +393,7 @@ public void testPatchAppV2() { // check and V1 app is running assertTrue(appAccessibleInPod( - domainUid, + domainUID, domainNamespace, "8001", "sample-war/index.jsp", @@ -402,7 +402,7 @@ public void testPatchAppV2() { // check and make sure that the version 2 app is NOT running assertFalse(appAccessibleInPod( - domainUid, + domainUID, domainNamespace, "8001", "sample-war/index.jsp", @@ -416,7 +416,7 @@ public void testPatchAppV2() { Arrays.asList(appDir1, appDir2)); // modify the domain resource to use the new image - patchDomainResourceIamge(domainUid, domainNamespace, miiImagePatchAppV2); + patchDomainResourceIamge(domainUID, domainNamespace, miiImagePatchAppV2); logger.info("Sleep for 2 minutes and wait for the servers to be rolling-restarted"); @@ -433,7 +433,7 @@ public void testPatchAppV2() { // check and wait for the app to be ready checkAppRunning( - domainUid, + domainUID, domainNamespace, "8001", "sample-war/index.jsp", @@ -456,7 +456,7 @@ public void testAddSecondApp() { // check and V2 app is still running assertTrue(appAccessibleInPod( - domainUid, + domainUID, domainNamespace, "8001", "sample-war/index.jsp", @@ -466,7 +466,7 @@ public void testAddSecondApp() { // check and make sure that the new app is not already running assertFalse(appAccessibleInPod( - domainUid, + domainUID, domainNamespace, "8001", "sample-war-3/index.jsp", @@ -485,7 +485,7 @@ public void testAddSecondApp() { logger.info("Image is successfully created"); // modify the domain resource to use the new image - patchDomainResourceIamge(domainUid, domainNamespace, miiImageAddSecondApp); + patchDomainResourceIamge(domainUID, domainNamespace, miiImageAddSecondApp); logger.info("Sleep for 2 minutes and wait for the servers to be rolling-restarted"); @@ -502,7 +502,7 @@ public void testAddSecondApp() { // check and wait for the original app to be ready checkAppRunning( - domainUid, + domainUID, domainNamespace, "8001", "sample-war/index.jsp", @@ -510,7 +510,7 @@ public void testAddSecondApp() { // check and wait for the new app to be ready checkAppRunning( - domainUid, + domainUID, domainNamespace, "8001", "sample-war-3/index.jsp", @@ -527,9 +527,9 @@ public void testAddSecondApp() { public void tearDownAll() { // Delete domain custom resource logger.info("Delete domain custom resource in namespace {0}", domainNamespace); - assertDoesNotThrow(() -> deleteDomainCustomResource(domainUid, domainNamespace), + assertDoesNotThrow(() -> deleteDomainCustomResource(domainUID, domainNamespace), "deleteDomainCustomResource failed with ApiException"); - logger.info("Deleted Domain Custom Resource " + domainUid + " from " + domainNamespace); + logger.info("Deleted Domain Custom Resource " + domainUID + " from " + domainNamespace); // uninstall operator release logger.info("Uninstall Operator in namespace {0}", opNamespace); @@ -682,12 +682,12 @@ private String updateImageWithApp3( * {"op": "replace", "path": "/spec/image", "value": "mii-image:v2" } * ] * - * @param domainUid the unique identifier of the domain resource + * @param domainUID the unique identifier of the domain resource * @param namespace the Kubernetes namespace that the domain is hosted * @param image the name of the image that contains a newer version of the application */ private void patchDomainResourceIamge( - String domainUid, + String domainUID, String namespace, String image ) { @@ -697,7 +697,7 @@ private void patchDomainResourceIamge( logger.info("About to patch the domain resource with:\n" + patch); assertTrue(patchDomainCustomResource( - domainUid, + domainUID, namespace, new V1Patch(patch), V1Patch.PATCH_FORMAT_JSON_PATCH), @@ -745,7 +745,7 @@ private void checkPodCreated(String podName) { domainNamespace, condition.getElapsedTimeInMS(), condition.getRemainingTimeInMS())) - .until(assertDoesNotThrow(() -> podExists(podName, domainUid, domainNamespace), + .until(assertDoesNotThrow(() -> podExists(podName, domainUID, domainNamespace), String.format("podExists failed with ApiException for %s in namespace in %s", podName, domainNamespace))); @@ -760,7 +760,7 @@ private void checkPodRunning(String podName) { domainNamespace, condition.getElapsedTimeInMS(), condition.getRemainingTimeInMS())) - .until(assertDoesNotThrow(() -> podReady(podName, domainUid, domainNamespace), + .until(assertDoesNotThrow(() -> podReady(podName, domainUID, domainNamespace), String.format( "pod %s is not ready in namespace %s", podName, domainNamespace))); @@ -782,7 +782,7 @@ private void checkServiceCreated(String serviceName) { } private void checkAppRunning( - String domainUid, + String domainUID, String ns, String internalPort, String appPath, @@ -798,7 +798,7 @@ private void checkAppRunning( domainNamespace, condition.getElapsedTimeInMS(), condition.getRemainingTimeInMS())) - .until(assertDoesNotThrow(() -> appAccessibleInPodCallable(domainUid, ns, internalPort, appPath, expectedStr), + .until(assertDoesNotThrow(() -> appAccessibleInPodCallable(domainUID, ns, internalPort, appPath, expectedStr), String.format( "App %s is not ready in namespace %s", appPath, domainNamespace))); diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/primitive/Command.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/primitive/Command.java index 77f0a01b9c6..7df0f6055cc 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/primitive/Command.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/primitive/Command.java @@ -40,8 +40,8 @@ private Command params(CommandParams params) { } /** - * Executes command. - * @return true, on success + * Execute a command. + * @return true on success */ public boolean execute() { if (params.verbose()) { @@ -68,4 +68,38 @@ public boolean execute() { return false; } } + + /** + * Execute a command and verify the response. + * + * @params expectedResponse the expected response to verify + * @return true on success + */ + public boolean executeAndVerify(String expectedResponse) { + if (params.verbose()) { + logger.info("Executing command {0}", params.command()); + } + try { + ExecResult result = ExecCommand.exec( + params.command(), + params.redirect(), + params.env()); + if (params.saveResults()) { + params.stdout(result.stdout()); + params.stderr(result.stderr()); + } + + // check exitValue to determine if the command execution has failed. + if (params.verbose() && result.exitValue() != 0) { + logger.severe("The command execution failed because it returned non-zero exit value: {0}.", result); + } + + return result.exitValue() == 0 + && result.stdout() != null + && result.stdout().contains(expectedResponse); + } catch (IOException | InterruptedException ie) { + logger.severe("The command execution failed", ie); + return false; + } + } } diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Application.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Application.java index 8154997aae7..b71614253e2 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Application.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Application.java @@ -28,15 +28,6 @@ public static boolean appAccessibleInPod( String appPath, String expectedStr ) { - return verifyAppInPod(domainUID, domainNS, port, appPath).contains(expectedStr); - } - - private static String verifyAppInPod( - String domainUID, - String domainNS, - String port, - String appPath - ) { String msPodName = domainUID + "-managed-server1"; // TODO currently calling "kubectl exec" command; will change it to use a Kubernetes @@ -56,8 +47,6 @@ private static String verifyAppInPod( .saveResults(true) .redirect(false) .verbose(false); - Command.withParams(params).execute(); - return params.stdout(); - } - + return Command.withParams(params).executeAndVerify(expectedStr); + } } From 937c92372d9348213abd44909be4d72b1f2f223d Mon Sep 17 00:00:00 2001 From: doxiao Date: Fri, 24 Apr 2020 18:06:42 +0000 Subject: [PATCH 21/69] Fix a merge error --- .../weblogic/kubernetes/ItMiiDomain.java | 27 ++++--------------- .../kubernetes/assertions/impl/Docker.java | 7 ++--- 2 files changed, 7 insertions(+), 27 deletions(-) diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java index d37b77e8a92..d102d558e8b 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java @@ -83,7 +83,6 @@ import static oracle.weblogic.kubernetes.actions.TestActions.uninstallOperator; import static oracle.weblogic.kubernetes.assertions.TestAssertions.appAccessibleInPod; import static oracle.weblogic.kubernetes.assertions.TestAssertions.appAccessibleInPodCallable; -import static oracle.weblogic.kubernetes.assertions.TestAssertions.dockerImageExists; import static oracle.weblogic.kubernetes.assertions.TestAssertions.doesImageExist; import static oracle.weblogic.kubernetes.assertions.TestAssertions.domainExists; import static oracle.weblogic.kubernetes.assertions.TestAssertions.isHelmReleaseDeployed; @@ -301,7 +300,7 @@ public void testCreateMiiDomain() { .name(domainUID) .namespace(domainNamespace)) .spec(new DomainSpec() - .domainUID(domainUID) + .domainUid(domainUID) .domainHomeSourceType("FromModel") .image(miiImage) .addImagePullSecretsItem(new V1LocalObjectReference() @@ -624,7 +623,7 @@ private String createInitialDomainImage() { createImageAndVerify(MII_IMAGE_NAME, imageTag, modelList, archiveList); - return MII_IMAGE_NAME + ":" + imageTag; + return image; } private String updateImageWithAppV2Patch( @@ -734,6 +733,7 @@ private void createImageAndVerify( List modelList, List archiveList ) { + final String image = imageName + ":" + imageTag; // Set additional environment variables for WIT checkDirectory(WIT_BUILD_DIR); @@ -753,7 +753,7 @@ private void createImageAndVerify( .env(env) .redirect(true)); - assertTrue(result, String.format("Failed to create the image %s using WebLogic Image Tool", image)); + assertTrue(result, String.format("Failed to create the image %s using WebLogic Image Tool", image)); /* Check image exists using docker images | grep image tag. * Tag name is unique as it contains date and timestamp. @@ -763,8 +763,6 @@ private void createImageAndVerify( */ assertTrue(doesImageExist(imageTag), String.format("Image %s doesn't exist", image)); - - return image; } private void checkPodCreated(String podName) { @@ -834,20 +832,5 @@ private void checkAppRunning( "App %s is not ready in namespace %s", appPath, domainNamespace))); } - - private static JsonObject getDockerConfigJson(String username, String password, String email, String registry) { - JsonObject authObject = new JsonObject(); - authObject.addProperty("username", username); - authObject.addProperty("password", password); - authObject.addProperty("email", email); - String auth = username + ":" + password; - String authEncoded = Base64.getEncoder().encodeToString(auth.getBytes()); - System.out.println("auth encoded: " + authEncoded); - authObject.addProperty("auth", authEncoded); - JsonObject registryObject = new JsonObject(); - registryObject.add(registry, authObject); - JsonObject configJsonObject = new JsonObject(); - configJsonObject.add("auths", registryObject); - return configJsonObject; - } + } diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Docker.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Docker.java index 2aff43a9553..e5e5d514970 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Docker.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Docker.java @@ -22,10 +22,7 @@ public static boolean doesImageExist(String searchString) { .saveResults(true) .redirect(false); - if (Command.withParams(cmdParams) - .execute()) { - return cmdParams.stdout().contains(searchString); - } - return false; + return Command.withParams(cmdParams) + .executeAndVerify(searchString); } } From 5bc4f4f82d81369273d5d5d59108d39c4396984d Mon Sep 17 00:00:00 2001 From: doxiao Date: Fri, 24 Apr 2020 18:29:38 +0000 Subject: [PATCH 22/69] Fix exec command --- .../weblogic/kubernetes/utils/ExecCommand.java | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/utils/ExecCommand.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/utils/ExecCommand.java index 13136c56a4b..6311badec88 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/utils/ExecCommand.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/utils/ExecCommand.java @@ -67,10 +67,6 @@ public static ExecResult exec( String stdout = null; if (isRedirectToOut) { InputStream i = in.getInputStream(); - i.mark(0); - // read the stdout first, and reset before we redirect the output - stdout = read(i); - i.reset(); @SuppressWarnings("resource") CopyingOutputStream copyOut = new CopyingOutputStream(System.out); // this makes sense because CopyingOutputStream is an InputStreamWrapper @@ -88,12 +84,8 @@ public static ExecResult exec( } p.waitFor(); - - // if we have not read the stdout, we do it now - if (stdout == null) { - stdout = read(in.getInputStream()); - } - return new ExecResult(p.exitValue(), stdout, read(p.getErrorStream())); + + return new ExecResult(p.exitValue(), read(in.getInputStream()), read(p.getErrorStream())); } finally { if (out != null) { From d3e17ca1bfcde308bae1a128edd5135af2aaa9f3 Mon Sep 17 00:00:00 2001 From: doxiao Date: Fri, 24 Apr 2020 18:59:22 +0000 Subject: [PATCH 23/69] Add code for remote repo stuff for the new tests --- .../weblogic/kubernetes/ItMiiDomain.java | 54 +++++++++++++------ 1 file changed, 39 insertions(+), 15 deletions(-) diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java index d102d558e8b..435db8c22a4 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java @@ -246,13 +246,7 @@ public void testCreateMiiDomain() { miiImage = createInitialDomainImage(); // push the image to OCIR to make the test work in multi node cluster - if (!REPO_USERNAME.equals(REPO_DUMMY_VALUE)) { - logger.info("docker login"); - assertTrue(dockerLogin(REPO_REGISTRY, REPO_USERNAME, REPO_PASSWORD), "docker login failed"); - - logger.info("docker push image {0} to OCIR", miiImage); - assertTrue(dockerPush(miiImage), String.format("docker push failed for image %s", miiImage)); - } + pushImageIfNeeded(miiImage); // Create the V1Secret configuration V1Secret repoSecret = new V1Secret() @@ -434,7 +428,10 @@ public void testPatchAppV2() { MII_IMAGE_NAME, "testPatchAppV2", Arrays.asList(appDir1, appDir2)); - + + // push the image to OCIR to make the test work in multi node cluster + pushImageIfNeeded(miiImagePatchAppV2); + // modify the domain resource to use the new image patchDomainResourceIamge(domainUID, domainNamespace, miiImagePatchAppV2); @@ -502,8 +499,12 @@ public void testAddSecondApp() { Arrays.asList(appDir1, appDir2), Collections.singletonList(appDir3), "model2-wls.yaml"); + logger.info("Image is successfully created"); + // push the image to OCIR to make the test work in multi node cluster + pushImageIfNeeded(miiImageAddSecondApp); + // modify the domain resource to use the new image patchDomainResourceIamge(domainUID, domainNamespace, miiImageAddSecondApp); @@ -599,6 +600,17 @@ public void tearDownAll() { } } + private void pushImageIfNeeded(String image) { + // push the image to OCIR to make the test work in multi node cluster + if (!REPO_USERNAME.equals(REPO_DUMMY_VALUE)) { + logger.info("docker login"); + assertTrue(dockerLogin(REPO_REGISTRY, REPO_USERNAME, REPO_PASSWORD), "docker login failed"); + + logger.info("docker push image {0} to OCIR", image); + assertTrue(dockerPush(miiImage), String.format("docker push failed for image %s", image)); + } + } + private String createInitialDomainImage() { // create unique image name with date DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); @@ -621,16 +633,22 @@ private String createInitialDomainImage() { List archiveList = Collections.singletonList(String.format("%s/%s.zip", ARCHIVE_DIR, APP_NAME)); - createImageAndVerify(MII_IMAGE_NAME, imageTag, modelList, archiveList); + createImageAndVerify(imageName, imageTag, modelList, archiveList); return image; } private String updateImageWithAppV2Patch( String imageName, - String imageTag, List appDirList ) { + DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); + Date date = new Date(); + final String imageTag = dateFormat.format(date) + "-" + System.currentTimeMillis(); + // Add repository name in image name for Jenkins runs + final String imageNameReal = REPO_USERNAME.equals(REPO_DUMMY_VALUE) ? imageName : REPO_NAME + imageName; + String image = String.format("%s:%s", imageNameReal, imageTag); + // build the model file list List modelList = Collections.singletonList(String.format("%s/%s", MODEL_DIR, WDT_MODEL_FILE)); @@ -648,18 +666,24 @@ private String updateImageWithAppV2Patch( Collections.singletonList( String.format("%s/%s.zip", ARCHIVE_DIR, APP_NAME)); - createImageAndVerify(imageName, imageTag, modelList, archiveList); + createImageAndVerify(imageNameReal, imageTag, modelList, archiveList); - return imageName + ":" + imageTag; + return image; } private String updateImageWithApp3( String imageName, - String imageTag, List appDirList1, List appDirList2, String modelFile ) { + DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); + Date date = new Date(); + final String imageTag = dateFormat.format(date) + "-" + System.currentTimeMillis(); + // Add repository name in image name for Jenkins runs + final String imageNameReal = REPO_USERNAME.equals(REPO_DUMMY_VALUE) ? imageName : REPO_NAME + imageName; + String image = String.format("%s:%s", imageNameReal, imageTag); + // build the model file list List modelList = Collections.singletonList(MODEL_DIR + "/" + modelFile); @@ -693,9 +717,9 @@ private String updateImageWithApp3( String.format("%s/%s.zip", ARCHIVE_DIR, appName1), String.format("%s/%s.zip", ARCHIVE_DIR, appName2)); - createImageAndVerify(imageName, imageTag, modelList, archiveList); + createImageAndVerify(imageNameReal, imageTag, modelList, archiveList); - return imageName + ":" + imageTag; + return image; } /** From 45c965af628f3056b9858b1d392cce7fe58d1ff8 Mon Sep 17 00:00:00 2001 From: doxiao Date: Fri, 24 Apr 2020 19:01:44 +0000 Subject: [PATCH 24/69] Minor fixes --- .../java/oracle/weblogic/kubernetes/ItMiiDomain.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java index 435db8c22a4..361a6ce5a68 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java @@ -642,10 +642,10 @@ private String updateImageWithAppV2Patch( String imageName, List appDirList ) { - DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); + DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); Date date = new Date(); - final String imageTag = dateFormat.format(date) + "-" + System.currentTimeMillis(); - // Add repository name in image name for Jenkins runs + final String imageTag = dateFormat.format(date) + "-" + System.currentTimeMillis(); + // Add repository name in image name for Jenkins runs final String imageNameReal = REPO_USERNAME.equals(REPO_DUMMY_VALUE) ? imageName : REPO_NAME + imageName; String image = String.format("%s:%s", imageNameReal, imageTag); @@ -660,7 +660,7 @@ private String updateImageWithAppV2Patch( .srcDirList(appDirList)), String.format("Failed to create app archive for %s", APP_NAME)); - + // build the archive list List archiveList = Collections.singletonList( @@ -680,7 +680,7 @@ private String updateImageWithApp3( DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); Date date = new Date(); final String imageTag = dateFormat.format(date) + "-" + System.currentTimeMillis(); - // Add repository name in image name for Jenkins runs + // Add repository name in image name for Jenkins runs final String imageNameReal = REPO_USERNAME.equals(REPO_DUMMY_VALUE) ? imageName : REPO_NAME + imageName; String image = String.format("%s:%s", imageNameReal, imageTag); From cdc828239fa53cdb58e43ae2ce387319c37af5aa Mon Sep 17 00:00:00 2001 From: doxiao Date: Fri, 24 Apr 2020 19:08:54 +0000 Subject: [PATCH 25/69] Cleanup --- .../test/java/oracle/weblogic/kubernetes/ItMiiDomain.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java index 361a6ce5a68..4142f5ded97 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java @@ -425,8 +425,7 @@ public void testPatchAppV2() { // create another image with app V2 miiImagePatchAppV2 = updateImageWithAppV2Patch( - MII_IMAGE_NAME, - "testPatchAppV2", + String.format("%s-%s", MII_IMAGE_NAME, "testPatchAppV2"), Arrays.asList(appDir1, appDir2)); // push the image to OCIR to make the test work in multi node cluster @@ -494,8 +493,7 @@ public void testAddSecondApp() { // create another image with an additional app miiImageAddSecondApp = updateImageWithApp3( - MII_IMAGE_NAME, - "testAddSecondApp", + String.format("%s-%s", MII_IMAGE_NAME, "testAddSecondApp"), Arrays.asList(appDir1, appDir2), Collections.singletonList(appDir3), "model2-wls.yaml"); From 2c729d7d8d1999cc5fef03fba0a3f3e0d564736d Mon Sep 17 00:00:00 2001 From: doxiao Date: Fri, 24 Apr 2020 19:15:05 +0000 Subject: [PATCH 26/69] Fix image name --- .../src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java index 4142f5ded97..6baaedc89ef 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java @@ -425,7 +425,7 @@ public void testPatchAppV2() { // create another image with app V2 miiImagePatchAppV2 = updateImageWithAppV2Patch( - String.format("%s-%s", MII_IMAGE_NAME, "testPatchAppV2"), + String.format("%s-%s", MII_IMAGE_NAME, "test-patch-app-v2"), Arrays.asList(appDir1, appDir2)); // push the image to OCIR to make the test work in multi node cluster @@ -493,7 +493,7 @@ public void testAddSecondApp() { // create another image with an additional app miiImageAddSecondApp = updateImageWithApp3( - String.format("%s-%s", MII_IMAGE_NAME, "testAddSecondApp"), + String.format("%s-%s", MII_IMAGE_NAME, "test-add-second-app"), Arrays.asList(appDir1, appDir2), Collections.singletonList(appDir3), "model2-wls.yaml"); From e5c5d46c0553584003cf170380d4173db6cb7447 Mon Sep 17 00:00:00 2001 From: doxiao Date: Fri, 24 Apr 2020 20:08:33 +0000 Subject: [PATCH 27/69] Add an app file --- .../test/resources/apps/sample-app-2/sample-war/index.jsp | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 new-integration-tests/src/test/resources/apps/sample-app-2/sample-war/index.jsp diff --git a/new-integration-tests/src/test/resources/apps/sample-app-2/sample-war/index.jsp b/new-integration-tests/src/test/resources/apps/sample-app-2/sample-war/index.jsp new file mode 100644 index 00000000000..4f0c4ee7217 --- /dev/null +++ b/new-integration-tests/src/test/resources/apps/sample-app-2/sample-war/index.jsp @@ -0,0 +1,7 @@ +<%-- +Copyright (c) 2020, Oracle Corporation and/or its affiliates. +Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. +--%> +<% + out.println("Hello World AGAIN, you have reached server " + System.getProperty("weblogic.Name" )); +%> From 4094e4efc3e2b34370d2c937f6bf00fdd01dabb4 Mon Sep 17 00:00:00 2001 From: doxiao Date: Fri, 24 Apr 2020 20:34:57 +0000 Subject: [PATCH 28/69] Make sure the thread joins before we save the stdout --- .../oracle/weblogic/kubernetes/ItMiiDomain.java | 14 +++++++------- .../weblogic/kubernetes/utils/ExecCommand.java | 7 ++++++- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java index 6baaedc89ef..ed93862246d 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java @@ -519,21 +519,21 @@ public void testAddSecondApp() { // do nothing } - // check and wait for the original app to be ready + // check and wait for the new app to be ready checkAppRunning( domainUID, domainNamespace, "8001", - "sample-war/index.jsp", - APP_RESPONSE_V2); - - // check and wait for the new app to be ready + "sample-war-3/index.jsp", + APP_RESPONSE_V3); + + // check and wait for the original app to be ready checkAppRunning( domainUID, domainNamespace, "8001", - "sample-war-3/index.jsp", - APP_RESPONSE_V3); + "sample-war/index.jsp", + APP_RESPONSE_V2); logger.info("The cluster has been rolling started, and the two applications are both running correctly."); } diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/utils/ExecCommand.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/utils/ExecCommand.java index 6311badec88..0bdccad91f6 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/utils/ExecCommand.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/utils/ExecCommand.java @@ -84,7 +84,12 @@ public static ExecResult exec( } p.waitFor(); - + + if (out != null) { + out.join(); + out = null; + } + return new ExecResult(p.exitValue(), read(in.getInputStream()), read(p.getErrorStream())); } finally { From c243b49296820acca34af5192841491c0ac30802 Mon Sep 17 00:00:00 2001 From: doxiao Date: Fri, 24 Apr 2020 20:47:19 +0000 Subject: [PATCH 29/69] Remove ItWitValidation class becuase the test in it has been copied to ItMiiDomain class --- .../weblogic/kubernetes/ItWitValidation.java | 83 ------------------- 1 file changed, 83 deletions(-) delete mode 100644 new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItWitValidation.java diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItWitValidation.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItWitValidation.java deleted file mode 100644 index e94cffa091d..00000000000 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItWitValidation.java +++ /dev/null @@ -1,83 +0,0 @@ -// Copyright (c) 2020, Oracle Corporation and/or its affiliates. -// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. - -package oracle.weblogic.kubernetes; - -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import oracle.weblogic.kubernetes.annotations.IntegrationTest; -import oracle.weblogic.kubernetes.extensions.LoggedTest; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; - -import static oracle.weblogic.kubernetes.actions.ActionConstants.ARCHIVE_DIR; -import static oracle.weblogic.kubernetes.actions.ActionConstants.MODEL_DIR; -import static oracle.weblogic.kubernetes.actions.ActionConstants.WDT_VERSION; -import static oracle.weblogic.kubernetes.actions.ActionConstants.WIT_BUILD_DIR; -import static oracle.weblogic.kubernetes.actions.TestActions.buildAppArchive; -import static oracle.weblogic.kubernetes.actions.TestActions.createMiiImage; -import static oracle.weblogic.kubernetes.actions.TestActions.defaultAppParams; -import static oracle.weblogic.kubernetes.actions.TestActions.defaultWitParams; -import static oracle.weblogic.kubernetes.assertions.TestAssertions.dockerImageExists; -import static oracle.weblogic.kubernetes.utils.FileUtils.checkDirectory; -import static org.assertj.core.api.Assertions.assertThat; - -@DisplayName("Simple validation of basic WIT functions") -@IntegrationTest -class ItWitValidation implements LoggedTest { - private static final String WDT_MODEL_FILE = "model1-wls.yaml"; - private static final String IMAGE_NAME = "test-mii-image-2"; - private static final String IMAGE_TAG = "v1"; - - private static final String APP_NAME = "sample-app"; - - @Test - @DisplayName("Create a MII image") - public void testCreatingMiiImage() { - - logger.info("WDT model directory is {0}", MODEL_DIR); - - // build the model file list - final List modelList = Collections.singletonList(MODEL_DIR + "/" + WDT_MODEL_FILE); - - // build an application archive using what is in resources/apps/APP_NAME - boolean archiveBuilt = buildAppArchive( - defaultAppParams() - .srcDirList(Collections.singletonList(APP_NAME))); - - assertThat(archiveBuilt) - .as("Create an app archive") - .withFailMessage("Failed to create app archive for " + APP_NAME) - .isTrue(); - - // build the archive list - String zipFile = String.format("%s/%s.zip", ARCHIVE_DIR, APP_NAME); - List archiveList = Collections.singletonList(zipFile); - - // Set additional environment variables for WIT - checkDirectory(WIT_BUILD_DIR); - Map env = new HashMap(); - env.put("WLSIMG_BLDDIR", WIT_BUILD_DIR); - - // build an image using WebLogic Image Tool - boolean success = createMiiImage( - defaultWitParams() - .modelImageName(IMAGE_NAME) - .modelImageTag(IMAGE_TAG) - .modelFiles(modelList) - .modelArchiveFiles(archiveList) - .wdtVersion(WDT_VERSION) - .env(env) - .redirect(true)); - - assertThat(success) - .as("Test the Docker image creation") - .withFailMessage("Failed to create the image using WebLogic Image Tool") - .isTrue(); - - dockerImageExists(IMAGE_NAME, IMAGE_TAG); - } -} From 3e2b97eb4dbeafbb4a14a737302c9b9efab4e5a5 Mon Sep 17 00:00:00 2001 From: doxiao Date: Fri, 24 Apr 2020 21:25:09 +0000 Subject: [PATCH 30/69] Revert "Remove ItWitValidation class becuase the test in it has been copied to ItMiiDomain class" This reverts commit c243b49296820acca34af5192841491c0ac30802. --- .../src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java index ed93862246d..a09a93211f0 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java @@ -442,7 +442,7 @@ public void testPatchAppV2() { // The application check is sufficient to verify that the version2 application // is running, thus the servers have been patched. try { - TimeUnit.MINUTES.sleep(2); + TimeUnit.MINUTES.sleep(3); } catch (InterruptedException ie) { // do nothing } @@ -514,7 +514,7 @@ public void testAddSecondApp() { // The application check is sufficient to verify that the version2 application // is running, thus the servers have been patched. try { - TimeUnit.MINUTES.sleep(2); + TimeUnit.MINUTES.sleep(3); } catch (InterruptedException ie) { // do nothing } From 0591fbf66b92ce9dc993214815878aedadf4732c Mon Sep 17 00:00:00 2001 From: doxiao Date: Sat, 25 Apr 2020 02:43:11 +0000 Subject: [PATCH 31/69] Debugging --- .../weblogic/kubernetes/ItMiiDomain.java | 27 ++++++++++++++++- .../kubernetes/assertions/TestAssertions.java | 16 ++++++++++ .../assertions/impl/Application.java | 4 +-- .../kubernetes/assertions/impl/Domain.java | 30 ++++++++++++++++++- 4 files changed, 73 insertions(+), 4 deletions(-) diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java index a09a93211f0..0e52ed7bf2e 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java @@ -85,6 +85,7 @@ import static oracle.weblogic.kubernetes.assertions.TestAssertions.appAccessibleInPodCallable; import static oracle.weblogic.kubernetes.assertions.TestAssertions.doesImageExist; import static oracle.weblogic.kubernetes.assertions.TestAssertions.domainExists; +import static oracle.weblogic.kubernetes.assertions.TestAssertions.domainPatchedWithImage; import static oracle.weblogic.kubernetes.assertions.TestAssertions.isHelmReleaseDeployed; import static oracle.weblogic.kubernetes.assertions.TestAssertions.operatorIsRunning; import static oracle.weblogic.kubernetes.assertions.TestAssertions.podExists; @@ -140,7 +141,7 @@ public static void initAll(@Namespaces(2) List namespaces) { // create standard, reusable retry/backoff policy withStandardRetryPolicy = with().pollDelay(2, SECONDS) .and().with().pollInterval(10, SECONDS) - .atMost(5, MINUTES).await(); + .atMost(10, MINUTES).await(); // get a new unique opNamespace logger.info("Creating unique namespace for Operator"); @@ -447,6 +448,8 @@ public void testPatchAppV2() { // do nothing } + checkDomainPatched(domainUID, domainNamespace, miiImagePatchAppV2); + // check and wait for the app to be ready checkAppRunning( domainUID, @@ -519,6 +522,8 @@ public void testAddSecondApp() { // do nothing } + checkDomainPatched(domainUID, domainNamespace, miiImageAddSecondApp); + // check and wait for the new app to be ready checkAppRunning( domainUID, @@ -854,5 +859,25 @@ private void checkAppRunning( "App %s is not ready in namespace %s", appPath, domainNamespace))); } + + private void checkDomainPatched( + String domainUID, + String ns, + String image + ) { + + // check if the app is accessible inside of a server pod + withStandardRetryPolicy + .conditionEvaluationListener( + condition -> logger.info("Waiting for domain {0} to be patched in namespace {1} " + + "(elapsed time {2}ms, remaining time {3}ms)", + domainUID, + ns, + condition.getElapsedTimeInMS(), + condition.getRemainingTimeInMS())) + .until(assertDoesNotThrow(() -> domainPatchedWithImage(domainUID, ns, image), + String.format( + "Domain %s is not patched in namespace %s with image %s", domainUID, domainNamespace, image))); + } } diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/TestAssertions.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/TestAssertions.java index 8c422fe4a73..d286e939475 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/TestAssertions.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/TestAssertions.java @@ -55,6 +55,22 @@ public static Callable domainExists(String domainUid, String domainVers return Domain.doesDomainExist(domainUid, domainVersion, namespace); } + /** + * Check if a WebLogic domain custom resource has been patched with a new image. + * + * @param domainUid ID of the domain + * @param namespace in which the domain custom resource object exists + * @param image that was used to patch the domain resource + * @return true if the domain is patched + */ + public static Callable domainPatchedWithImage( + String domainUid, + String namespace, + String image + ) { + return Domain.domainPatchedWithImage(domainUid, namespace, image); + } + /** * Check if a Kubernetes pod exists in any state in the given namespace. * diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Application.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Application.java index b71614253e2..1b907470a26 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Application.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Application.java @@ -45,8 +45,8 @@ public static boolean appAccessibleInPod( .defaultCommandParams() .command(cmd) .saveResults(true) - .redirect(false) - .verbose(false); + .redirect(true) + .verbose(true); return Command.withParams(params).executeAndVerify(expectedStr); } } diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Domain.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Domain.java index 81d5c050387..71053165d8b 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Domain.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Domain.java @@ -77,6 +77,34 @@ public static Callable doesDomainExist(String domainUid, String domainV }; } + /** + * Checks if domain resource has been patched with a new image. + * + * @param domainUID domain UID of the domain object + * @param namespace in which the domain object exists + * @param image image that has been patch + * @return true if domain object 's image does not match what is expected + */ + public static Callable domainPatchedWithImage( + String domainUID, + String namespace, + String image + ) { + return () -> { + oracle.weblogic.domain.Domain domain = null; + try { + domain = oracle.weblogic.kubernetes.actions.impl.primitive.Kubernetes + .getDomainCustomResource(domainUID, namespace); + } catch (ApiException apex) { + logger.info(apex.getMessage()); + } + + boolean domainPatched = (domain.spec().image().equals(image)); + logger.info("Domain Object patched : " + domainPatched + " domain image = " + domain.spec().image()); + return domainPatched; + }; + } + public static boolean adminT3ChannelAccessible(String domainUid, String namespace) { return true; } @@ -85,4 +113,4 @@ public static boolean adminNodePortAccessible(String domainUid, String namespace return true; } -} \ No newline at end of file +} From e8f50c7bca30d768a00eaf0473714504de12baf3 Mon Sep 17 00:00:00 2001 From: doxiao Date: Sat, 25 Apr 2020 03:10:34 +0000 Subject: [PATCH 32/69] Fix pushed image name --- .../src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java index 0e52ed7bf2e..2cb8d9860e5 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java @@ -610,7 +610,7 @@ private void pushImageIfNeeded(String image) { assertTrue(dockerLogin(REPO_REGISTRY, REPO_USERNAME, REPO_PASSWORD), "docker login failed"); logger.info("docker push image {0} to OCIR", image); - assertTrue(dockerPush(miiImage), String.format("docker push failed for image %s", image)); + assertTrue(dockerPush(image), String.format("docker push failed for image %s", image)); } } From 713a3bb6b43b97481990a100e073095a9e5a4a88 Mon Sep 17 00:00:00 2001 From: doxiao Date: Sat, 25 Apr 2020 14:28:00 +0000 Subject: [PATCH 33/69] Turn off debugging --- .../src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java | 2 +- .../weblogic/kubernetes/assertions/impl/Application.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java index 2cb8d9860e5..2a8c9c00e64 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java @@ -141,7 +141,7 @@ public static void initAll(@Namespaces(2) List namespaces) { // create standard, reusable retry/backoff policy withStandardRetryPolicy = with().pollDelay(2, SECONDS) .and().with().pollInterval(10, SECONDS) - .atMost(10, MINUTES).await(); + .atMost(5, MINUTES).await(); // get a new unique opNamespace logger.info("Creating unique namespace for Operator"); diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Application.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Application.java index 1b907470a26..b71614253e2 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Application.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Application.java @@ -45,8 +45,8 @@ public static boolean appAccessibleInPod( .defaultCommandParams() .command(cmd) .saveResults(true) - .redirect(true) - .verbose(true); + .redirect(false) + .verbose(false); return Command.withParams(params).executeAndVerify(expectedStr); } } From 5c6c391aac1b0baace56f358d44295b25c07f17d Mon Sep 17 00:00:00 2001 From: doxiao Date: Sat, 25 Apr 2020 20:51:39 +0000 Subject: [PATCH 34/69] Testing --- .../weblogic/kubernetes/ItMiiDomain.java | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java index 2a8c9c00e64..2742ca3b49b 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java @@ -435,18 +435,18 @@ public void testPatchAppV2() { // modify the domain resource to use the new image patchDomainResourceIamge(domainUID, domainNamespace, miiImagePatchAppV2); - logger.info("Sleep for 2 minutes and wait for the servers to be rolling-restarted"); + //logger.info("Sleep for 2 minutes and wait for the servers to be rolling-restarted"); // Ideally we want to verify that the server pods were rolling restarted. // But it is hard to time the pod state transitions. // Instead, sleep for 2 minutes and check the newer version of the application. // The application check is sufficient to verify that the version2 application // is running, thus the servers have been patched. - try { - TimeUnit.MINUTES.sleep(3); - } catch (InterruptedException ie) { - // do nothing - } + //try { + // TimeUnit.MINUTES.sleep(3); + //} catch (InterruptedException ie) { + // do nothing + //} checkDomainPatched(domainUID, domainNamespace, miiImagePatchAppV2); @@ -509,18 +509,18 @@ public void testAddSecondApp() { // modify the domain resource to use the new image patchDomainResourceIamge(domainUID, domainNamespace, miiImageAddSecondApp); - logger.info("Sleep for 2 minutes and wait for the servers to be rolling-restarted"); + //logger.info("Sleep for 2 minutes and wait for the servers to be rolling-restarted"); // Ideally we want to verify that the server pods were rolling restarted. // But it is hard to time the pod state transitions. // Instead, sleep for 2 minutes and check the newer version of the application. // The application check is sufficient to verify that the version2 application // is running, thus the servers have been patched. - try { - TimeUnit.MINUTES.sleep(3); - } catch (InterruptedException ie) { - // do nothing - } + //try { + // TimeUnit.MINUTES.sleep(3); + //} catch (InterruptedException ie) { + // do nothing + //} checkDomainPatched(domainUID, domainNamespace, miiImageAddSecondApp); From 818af8094c15a8e85bd5a170ca078d3fc21dafad Mon Sep 17 00:00:00 2001 From: doxiao Date: Mon, 27 Apr 2020 15:56:25 +0000 Subject: [PATCH 35/69] Change single check of expected condition to quick retry --- .../weblogic/kubernetes/ItMiiDomain.java | 110 ++++++++++++------ .../kubernetes/assertions/TestAssertions.java | 14 ++- 2 files changed, 82 insertions(+), 42 deletions(-) diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java index 2742ca3b49b..56811897fa0 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java @@ -12,7 +12,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.concurrent.TimeUnit; import com.google.gson.JsonObject; import io.kubernetes.client.custom.V1Patch; @@ -82,7 +81,7 @@ import static oracle.weblogic.kubernetes.actions.TestActions.patchDomainCustomResource; import static oracle.weblogic.kubernetes.actions.TestActions.uninstallOperator; import static oracle.weblogic.kubernetes.assertions.TestAssertions.appAccessibleInPod; -import static oracle.weblogic.kubernetes.assertions.TestAssertions.appAccessibleInPodCallable; +import static oracle.weblogic.kubernetes.assertions.TestAssertions.appNotAccessibleInPod; import static oracle.weblogic.kubernetes.assertions.TestAssertions.doesImageExist; import static oracle.weblogic.kubernetes.assertions.TestAssertions.domainExists; import static oracle.weblogic.kubernetes.assertions.TestAssertions.domainPatchedWithImage; @@ -124,6 +123,7 @@ class ItMiiDomain implements LoggedTest { private static String opNamespace = null; private static String domainNamespace = null; private static ConditionFactory withStandardRetryPolicy = null; + private static ConditionFactory withQuickRetryPolicy = null; private static String dockerConfigJson = ""; private String domainUID = "domain1"; @@ -141,7 +141,11 @@ public static void initAll(@Namespaces(2) List namespaces) { // create standard, reusable retry/backoff policy withStandardRetryPolicy = with().pollDelay(2, SECONDS) .and().with().pollInterval(10, SECONDS) - .atMost(5, MINUTES).await(); + .atMost(6, MINUTES).await(); + + withQuickRetryPolicy = with().pollDelay(1, SECONDS) + .and().with().pollInterval(2, SECONDS) + .atMost(5, SECONDS).await(); // get a new unique opNamespace logger.info("Creating unique namespace for Operator"); @@ -407,22 +411,23 @@ public void testPatchAppV2() { final String appDir2 = "sample-app-2"; // check and V1 app is running - assertTrue(appAccessibleInPod( + quickCheckAppRunning( domainUID, domainNamespace, "8001", "sample-war/index.jsp", - APP_RESPONSE_V1), - "The expected app is not accessible inside the server pod"); + APP_RESPONSE_V1, + String.format("App sample-war/index.jsp is not running in namespace %s as expected.", + domainNamespace)); // check and make sure that the version 2 app is NOT running - assertFalse(appAccessibleInPod( + quickCheckAppNotRunning( domainUID, domainNamespace, "8001", "sample-war/index.jsp", - APP_RESPONSE_V2), - "The second version of the app is not supposed to be running!!"); + APP_RESPONSE_V2, + "The second version of the app is not supposed to be running."); // create another image with app V2 miiImagePatchAppV2 = updateImageWithAppV2Patch( @@ -435,18 +440,11 @@ public void testPatchAppV2() { // modify the domain resource to use the new image patchDomainResourceIamge(domainUID, domainNamespace, miiImagePatchAppV2); - //logger.info("Sleep for 2 minutes and wait for the servers to be rolling-restarted"); - // Ideally we want to verify that the server pods were rolling restarted. // But it is hard to time the pod state transitions. - // Instead, sleep for 2 minutes and check the newer version of the application. - // The application check is sufficient to verify that the version2 application - // is running, thus the servers have been patched. - //try { - // TimeUnit.MINUTES.sleep(3); - //} catch (InterruptedException ie) { - // do nothing - //} + // Instead, check the domain spec and make sure that the image has been patched + // with the new image, and also check the accessibility of the application, which + // was not running before patching. checkDomainPatched(domainUID, domainNamespace, miiImagePatchAppV2); @@ -474,23 +472,24 @@ public void testAddSecondApp() { final String appDir3 = "sample-app-3"; // check and V2 app is still running - assertTrue(appAccessibleInPod( + quickCheckAppRunning( domainUID, domainNamespace, "8001", "sample-war/index.jsp", - APP_RESPONSE_V2), - "The expected app is not accessible inside the server pod"); + APP_RESPONSE_V2, + "The expected app is not accessible inside the server pod"); + logger.info("App version 2 is still running"); // check and make sure that the new app is not already running - assertFalse(appAccessibleInPod( + quickCheckAppNotRunning( domainUID, domainNamespace, "8001", "sample-war-3/index.jsp", - APP_RESPONSE_V3), - "The second app is not supposed to be running!!"); + APP_RESPONSE_V3, + "The second app is not supposed to be running!!"); logger.info("About to patch the domain with new image"); @@ -509,18 +508,11 @@ public void testAddSecondApp() { // modify the domain resource to use the new image patchDomainResourceIamge(domainUID, domainNamespace, miiImageAddSecondApp); - //logger.info("Sleep for 2 minutes and wait for the servers to be rolling-restarted"); - // Ideally we want to verify that the server pods were rolling restarted. // But it is hard to time the pod state transitions. - // Instead, sleep for 2 minutes and check the newer version of the application. - // The application check is sufficient to verify that the version2 application - // is running, thus the servers have been patched. - //try { - // TimeUnit.MINUTES.sleep(3); - //} catch (InterruptedException ie) { - // do nothing - //} + // Instead, check the domain spec and make sure that the image has been patched + // with the new image, and also check the accessibility of the application, which + // was not running before patching. checkDomainPatched(domainUID, domainNamespace, miiImageAddSecondApp); @@ -854,12 +846,58 @@ private void checkAppRunning( domainNamespace, condition.getElapsedTimeInMS(), condition.getRemainingTimeInMS())) - .until(assertDoesNotThrow(() -> appAccessibleInPodCallable(domainUID, ns, internalPort, appPath, expectedStr), + .until(assertDoesNotThrow(() -> appAccessibleInPod(domainUID, ns, internalPort, appPath, expectedStr), String.format( "App %s is not ready in namespace %s", appPath, domainNamespace))); } + private void quickCheckAppRunning( + String domainUID, + String ns, + String internalPort, + String appPath, + String expectedStr, + String failMessage + ) { + + // check if the app is accessible inside of a server pod + withQuickRetryPolicy + .conditionEvaluationListener( + condition -> logger.info("Checking if application {0} is running in namespace {1} " + + "(elapsed time {2}ms, remaining time {3}ms)", + appPath, + domainNamespace, + condition.getElapsedTimeInMS(), + condition.getRemainingTimeInMS())) + .until(assertDoesNotThrow(() -> appAccessibleInPod(domainUID, ns, internalPort, appPath, expectedStr), + failMessage)); + + } + + private void quickCheckAppNotRunning( + String domainUID, + String ns, + String internalPort, + String appPath, + String expectedStr, + String failMessage + ) { + + // check if the app is not running inside of a server pod + withQuickRetryPolicy + .conditionEvaluationListener( + condition -> logger.info("Checking if application {0} is not running in namespace {1} " + + "(elapsed time {2}ms, remaining time {3}ms)", + appPath, + domainNamespace, + condition.getElapsedTimeInMS(), + condition.getRemainingTimeInMS())) + .until(assertDoesNotThrow(() -> appNotAccessibleInPod(domainUID, ns, internalPort, appPath, expectedStr), + failMessage)); + + } + private void checkDomainPatched( String domainUID, String ns, diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/TestAssertions.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/TestAssertions.java index d286e939475..97e9d659d9a 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/TestAssertions.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/TestAssertions.java @@ -196,27 +196,29 @@ public static boolean dockerImageExists(String imageName, String imageTag) { * @param expectedStr the expected response from the application * @return true if the command succeeds */ - public static boolean appAccessibleInPod( + public static Callable appAccessibleInPod( String domainUID, String domainNS, String port, String appPath, String expectedStr ) { - return Application.appAccessibleInPod(domainUID, domainNS, port, appPath, expectedStr); + return () -> { + return Application.appAccessibleInPod(domainUID, domainNS, port, appPath, expectedStr); + }; } /** - * Check if an application is accessible inside a WebLogic server pod. + * Check if an application is Not running inside a WebLogic server pod. * . * @param domainUID unique identifier of the Kubernetes domain custom resource instance * @param domainNS Kubernetes namespace where the WebLogic servers are running * @param port internal port of the managed servers * @param appPath the path to access the application * @param expectedStr the expected response from the application - * @return Callable true if the command succeeds + * @return true if the command succeeds */ - public static Callable appAccessibleInPodCallable( + public static Callable appNotAccessibleInPod( String domainUID, String domainNS, String port, @@ -224,7 +226,7 @@ public static Callable appAccessibleInPodCallable( String expectedStr ) { return () -> { - return Application.appAccessibleInPod(domainUID, domainNS, port, appPath, expectedStr); + return !Application.appAccessibleInPod(domainUID, domainNS, port, appPath, expectedStr); }; } From a2fb039a8730392531560b536b9880eaaf5c71b3 Mon Sep 17 00:00:00 2001 From: doxiao Date: Mon, 27 Apr 2020 18:56:50 +0000 Subject: [PATCH 36/69] Check app on all managed servers --- .../weblogic/kubernetes/ItMiiDomain.java | 169 +++++++++++------- .../kubernetes/assertions/TestAssertions.java | 12 +- .../assertions/impl/Application.java | 11 +- .../kubernetes/assertions/impl/Domain.java | 2 +- 4 files changed, 124 insertions(+), 70 deletions(-) diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java index 56811897fa0..e6db0ec16c2 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java @@ -84,7 +84,7 @@ import static oracle.weblogic.kubernetes.assertions.TestAssertions.appNotAccessibleInPod; import static oracle.weblogic.kubernetes.assertions.TestAssertions.doesImageExist; import static oracle.weblogic.kubernetes.assertions.TestAssertions.domainExists; -import static oracle.weblogic.kubernetes.assertions.TestAssertions.domainPatchedWithImage; +import static oracle.weblogic.kubernetes.assertions.TestAssertions.domainResourceImagePatched; import static oracle.weblogic.kubernetes.assertions.TestAssertions.isHelmReleaseDeployed; import static oracle.weblogic.kubernetes.assertions.TestAssertions.operatorIsRunning; import static oracle.weblogic.kubernetes.assertions.TestAssertions.podExists; @@ -114,8 +114,8 @@ class ItMiiDomain implements LoggedTest { private static final String API_VERSION = "weblogic.oracle/" + DOMAIN_VERSION; // app constants - private static final String APP_RESPONSE_V1 = "Hello World, you have reached server managed-server1"; - private static final String APP_RESPONSE_V2 = "Hello World AGAIN, you have reached server managed-server1"; + private static final String APP_RESPONSE_V1 = "Hello World, you have reached server managed-server"; + private static final String APP_RESPONSE_V2 = "Hello World AGAIN, you have reached server managed-server"; private static final String APP_RESPONSE_V3 = "How are you doing!"; private static HelmParams opHelmParams = null; @@ -388,13 +388,16 @@ public void testCreateMiiDomain() { checkServiceCreated(managedServerPrefix + i); } - checkAppRunning( - domainUID, - domainNamespace, - "8001", - "sample-war/index.jsp", - APP_RESPONSE_V1); - + for (int i = 1; i <= replicaCount; i++) { + checkAppRunning( + domainUID, + domainNamespace, + managedServerPrefix + i, + "8001", + "sample-war/index.jsp", + APP_RESPONSE_V1 + i); + } + logger.info(String.format("Domain %s is fully started - servers are running and application is deployed corretly.", domainUID)); } @@ -409,26 +412,34 @@ public void testPatchAppV2() { // app here is what is in the original app dir plus the replacement in the second app dir final String appDir1 = "sample-app"; final String appDir2 = "sample-app-2"; + final String managedServerPrefix = domainUID + "-managed-server"; + final int replicaCount = 2; - // check and V1 app is running - quickCheckAppRunning( + // check and make sure that V1 app is running + for (int i = 1; i <= replicaCount; i++) { + quickCheckAppRunning( domainUID, domainNamespace, + managedServerPrefix + i, "8001", "sample-war/index.jsp", - APP_RESPONSE_V1, + APP_RESPONSE_V1 + i, String.format("App sample-war/index.jsp is not running in namespace %s as expected.", domainNamespace)); - + } + // check and make sure that the version 2 app is NOT running - quickCheckAppNotRunning( + for (int i = 1; i <= replicaCount; i++) { + quickCheckAppNotRunning( domainUID, domainNamespace, + managedServerPrefix + i, "8001", "sample-war/index.jsp", - APP_RESPONSE_V2, + APP_RESPONSE_V2 + i, "The second version of the app is not supposed to be running."); - + } + // create another image with app V2 miiImagePatchAppV2 = updateImageWithAppV2Patch( String.format("%s-%s", MII_IMAGE_NAME, "test-patch-app-v2"), @@ -449,12 +460,15 @@ public void testPatchAppV2() { checkDomainPatched(domainUID, domainNamespace, miiImagePatchAppV2); // check and wait for the app to be ready - checkAppRunning( - domainUID, - domainNamespace, - "8001", - "sample-war/index.jsp", - APP_RESPONSE_V2); + for (int i = 1; i <= replicaCount; i++) { + checkAppRunning( + domainUID, + domainNamespace, + managedServerPrefix + i, + "8001", + "sample-war/index.jsp", + APP_RESPONSE_V2 + i); + } logger.info("The cluster has been rolling started, and the version 2 application has been deployed correctly."); } @@ -470,27 +484,35 @@ public void testAddSecondApp() { final String appDir1 = "sample-app"; final String appDir2 = "sample-app-2"; final String appDir3 = "sample-app-3"; + final String managedServerPrefix = domainUID + "-managed-server"; + final int replicaCount = 2; // check and V2 app is still running - quickCheckAppRunning( - domainUID, - domainNamespace, - "8001", - "sample-war/index.jsp", - APP_RESPONSE_V2, - "The expected app is not accessible inside the server pod"); + for (int i = 1; i <= replicaCount; i++) { + quickCheckAppRunning( + domainUID, + domainNamespace, + managedServerPrefix + i, + "8001", + "sample-war/index.jsp", + APP_RESPONSE_V2 + i, + "The expected app is not accessible inside the server pods"); + } logger.info("App version 2 is still running"); // check and make sure that the new app is not already running - quickCheckAppNotRunning( - domainUID, - domainNamespace, - "8001", - "sample-war-3/index.jsp", - APP_RESPONSE_V3, - "The second app is not supposed to be running!!"); - + for (int i = 1; i <= replicaCount; i++) { + quickCheckAppNotRunning( + domainUID, + domainNamespace, + managedServerPrefix + i, + "8001", + "sample-war-3/index.jsp", + APP_RESPONSE_V3, + "The second app is not supposed to be running!!"); + } + logger.info("About to patch the domain with new image"); // create another image with an additional app @@ -517,20 +539,26 @@ public void testAddSecondApp() { checkDomainPatched(domainUID, domainNamespace, miiImageAddSecondApp); // check and wait for the new app to be ready - checkAppRunning( - domainUID, - domainNamespace, - "8001", - "sample-war-3/index.jsp", - APP_RESPONSE_V3); - + for (int i = 1; i <= replicaCount; i++) { + checkAppRunning( + domainUID, + domainNamespace, + managedServerPrefix + i, + "8001", + "sample-war-3/index.jsp", + APP_RESPONSE_V3); + } + // check and wait for the original app to be ready - checkAppRunning( - domainUID, - domainNamespace, - "8001", - "sample-war/index.jsp", - APP_RESPONSE_V2); + for (int i = 1; i <= replicaCount; i++) { + checkAppRunning( + domainUID, + domainNamespace, + managedServerPrefix + i, + "8001", + "sample-war/index.jsp", + APP_RESPONSE_V2 + i); + } logger.info("The cluster has been rolling started, and the two applications are both running correctly."); } @@ -832,6 +860,7 @@ private void checkServiceCreated(String serviceName) { private void checkAppRunning( String domainUID, String ns, + String podName, String internalPort, String appPath, String expectedStr @@ -840,21 +869,29 @@ private void checkAppRunning( // check if the app is accessible inside of a server pod withStandardRetryPolicy .conditionEvaluationListener( - condition -> logger.info("Waiting for application {0} to be ready in namespace {1} " - + "(elapsed time {2}ms, remaining time {3}ms)", + condition -> logger.info("Waiting for application {0} to be ready on {1} in namespace {2} " + + "(elapsed time {3}ms, remaining time {4}ms)", appPath, + podName, domainNamespace, condition.getElapsedTimeInMS(), condition.getRemainingTimeInMS())) - .until(assertDoesNotThrow(() -> appAccessibleInPod(domainUID, ns, internalPort, appPath, expectedStr), + .until(assertDoesNotThrow(() -> appAccessibleInPod( + domainUID, + ns, + podName, + internalPort, + appPath, + expectedStr), String.format( - "App %s is not ready in namespace %s", appPath, domainNamespace))); + "App %s is not ready on pod %s in namespace %s", appPath, podName, domainNamespace))); } private void quickCheckAppRunning( String domainUID, String ns, + String podName, String internalPort, String appPath, String expectedStr, @@ -870,7 +907,13 @@ private void quickCheckAppRunning( domainNamespace, condition.getElapsedTimeInMS(), condition.getRemainingTimeInMS())) - .until(assertDoesNotThrow(() -> appAccessibleInPod(domainUID, ns, internalPort, appPath, expectedStr), + .until(assertDoesNotThrow(() -> appAccessibleInPod( + domainUID, + ns, + podName, + internalPort, + appPath, + expectedStr), failMessage)); } @@ -878,6 +921,7 @@ private void quickCheckAppRunning( private void quickCheckAppNotRunning( String domainUID, String ns, + String podName, String internalPort, String appPath, String expectedStr, @@ -893,9 +937,14 @@ private void quickCheckAppNotRunning( domainNamespace, condition.getElapsedTimeInMS(), condition.getRemainingTimeInMS())) - .until(assertDoesNotThrow(() -> appNotAccessibleInPod(domainUID, ns, internalPort, appPath, expectedStr), - failMessage)); - + .until(assertDoesNotThrow(() -> appNotAccessibleInPod( + domainUID, + ns, + podName, + internalPort, + appPath, + expectedStr), + failMessage)); } private void checkDomainPatched( @@ -913,7 +962,7 @@ private void checkDomainPatched( ns, condition.getElapsedTimeInMS(), condition.getRemainingTimeInMS())) - .until(assertDoesNotThrow(() -> domainPatchedWithImage(domainUID, ns, image), + .until(assertDoesNotThrow(() -> domainResourceImagePatched(domainUID, ns, image), String.format( "Domain %s is not patched in namespace %s with image %s", domainUID, domainNamespace, image))); diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/TestAssertions.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/TestAssertions.java index 97e9d659d9a..4123d3546e9 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/TestAssertions.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/TestAssertions.java @@ -63,12 +63,12 @@ public static Callable domainExists(String domainUid, String domainVers * @param image that was used to patch the domain resource * @return true if the domain is patched */ - public static Callable domainPatchedWithImage( + public static Callable domainResourceImagePatched( String domainUid, String namespace, String image ) { - return Domain.domainPatchedWithImage(domainUid, namespace, image); + return Domain.domainResourceImagePatched(domainUid, namespace, image); } /** @@ -191,6 +191,7 @@ public static boolean dockerImageExists(String imageName, String imageTag) { * * @param domainUID unique identifier of the Kubernetes domain custom resource instance * @param domainNS Kubernetes namespace where the WebLogic servers are running + * @param podName name of the WebLogic server pod * @param port internal port of the managed servers * @param appPath the path to access the application * @param expectedStr the expected response from the application @@ -199,12 +200,13 @@ public static boolean dockerImageExists(String imageName, String imageTag) { public static Callable appAccessibleInPod( String domainUID, String domainNS, + String podName, String port, String appPath, String expectedStr ) { return () -> { - return Application.appAccessibleInPod(domainUID, domainNS, port, appPath, expectedStr); + return Application.appAccessibleInPod(domainUID, domainNS, podName, port, appPath, expectedStr); }; } @@ -213,6 +215,7 @@ public static Callable appAccessibleInPod( * . * @param domainUID unique identifier of the Kubernetes domain custom resource instance * @param domainNS Kubernetes namespace where the WebLogic servers are running + * @param podName name of the WebLogic server pod * @param port internal port of the managed servers * @param appPath the path to access the application * @param expectedStr the expected response from the application @@ -221,12 +224,13 @@ public static Callable appAccessibleInPod( public static Callable appNotAccessibleInPod( String domainUID, String domainNS, + String podName, String port, String appPath, String expectedStr ) { return () -> { - return !Application.appAccessibleInPod(domainUID, domainNS, port, appPath, expectedStr); + return !Application.appAccessibleInPod(domainUID, domainNS, podName, port, appPath, expectedStr); }; } diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Application.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Application.java index b71614253e2..1690e41c797 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Application.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Application.java @@ -17,6 +17,7 @@ public class Application { * Check if an application is accessible inside a WebLogic server pod. * @param domainUID identifier of the Kubernetes domain custom resource instance * @param domainNS Kubernetes namespace where the WebLogic servers are running + * @param podName name of the WebLogic server pod * @param port internal port of the managed servers * @param appPath the path to access the application * @return true if the command succeeds @@ -24,11 +25,11 @@ public class Application { public static boolean appAccessibleInPod( String domainUID, String domainNS, + String podName, String port, String appPath, String expectedStr ) { - String msPodName = domainUID + "-managed-server1"; // TODO currently calling "kubectl exec" command; will change it to use a Kubernetes // action once that action for "exec" command is available. @@ -36,8 +37,8 @@ public static boolean appAccessibleInPod( String cmd = String.format( "kubectl -n %s exec -it %s -- /bin/bash -c 'curl http://%s:%s/%s'", domainNS, - msPodName, - msPodName, + podName, + podName, port, appPath); @@ -45,8 +46,8 @@ public static boolean appAccessibleInPod( .defaultCommandParams() .command(cmd) .saveResults(true) - .redirect(false) - .verbose(false); + .redirect(true) + .verbose(true); return Command.withParams(params).executeAndVerify(expectedStr); } } diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Domain.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Domain.java index 71053165d8b..100f86b2d74 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Domain.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Domain.java @@ -85,7 +85,7 @@ public static Callable doesDomainExist(String domainUid, String domainV * @param image image that has been patch * @return true if domain object 's image does not match what is expected */ - public static Callable domainPatchedWithImage( + public static Callable domainResourceImagePatched( String domainUID, String namespace, String image From 9b9f6aa2b92e156fea3d3787071e2253d83e9963 Mon Sep 17 00:00:00 2001 From: doxiao Date: Mon, 27 Apr 2020 21:11:34 +0000 Subject: [PATCH 37/69] Check each pod to verify if the image has been patched --- .../weblogic/kubernetes/ItMiiDomain.java | 68 ++++++++++++++----- .../kubernetes/assertions/TestAssertions.java | 20 ++++++ .../assertions/impl/Kubernetes.java | 37 ++++++++++ 3 files changed, 109 insertions(+), 16 deletions(-) diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java index e6db0ec16c2..7d463906af2 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java @@ -88,6 +88,7 @@ import static oracle.weblogic.kubernetes.assertions.TestAssertions.isHelmReleaseDeployed; import static oracle.weblogic.kubernetes.assertions.TestAssertions.operatorIsRunning; import static oracle.weblogic.kubernetes.assertions.TestAssertions.podExists; +import static oracle.weblogic.kubernetes.assertions.TestAssertions.podImagePatched; import static oracle.weblogic.kubernetes.assertions.TestAssertions.podReady; import static oracle.weblogic.kubernetes.assertions.TestAssertions.serviceExists; import static oracle.weblogic.kubernetes.utils.FileUtils.checkDirectory; @@ -451,13 +452,17 @@ public void testPatchAppV2() { // modify the domain resource to use the new image patchDomainResourceIamge(domainUID, domainNamespace, miiImagePatchAppV2); - // Ideally we want to verify that the server pods were rolling restarted. - // But it is hard to time the pod state transitions. - // Instead, check the domain spec and make sure that the image has been patched - // with the new image, and also check the accessibility of the application, which - // was not running before patching. - + // check if domain resource has been patched with the new image checkDomainPatched(domainUID, domainNamespace, miiImagePatchAppV2); + + // check and wait for the managed server pods to be patched with the new image + for (int i = 1; i <= replicaCount; i++) { + checkPodImagePatched( + domainUID, + domainNamespace, + managedServerPrefix + i, + miiImagePatchAppV2); + } // check and wait for the app to be ready for (int i = 1; i <= replicaCount; i++) { @@ -530,13 +535,17 @@ public void testAddSecondApp() { // modify the domain resource to use the new image patchDomainResourceIamge(domainUID, domainNamespace, miiImageAddSecondApp); - // Ideally we want to verify that the server pods were rolling restarted. - // But it is hard to time the pod state transitions. - // Instead, check the domain spec and make sure that the image has been patched - // with the new image, and also check the accessibility of the application, which - // was not running before patching. - + // check if the domain resource has been patched with the new image checkDomainPatched(domainUID, domainNamespace, miiImageAddSecondApp); + + // check and wait for the managed server pods to be patched with the new image + for (int i = 1; i <= replicaCount; i++) { + checkPodImagePatched( + domainUID, + domainNamespace, + managedServerPrefix + i, + miiImageAddSecondApp); + } // check and wait for the new app to be ready for (int i = 1; i <= replicaCount; i++) { @@ -901,9 +910,10 @@ private void quickCheckAppRunning( // check if the app is accessible inside of a server pod withQuickRetryPolicy .conditionEvaluationListener( - condition -> logger.info("Checking if application {0} is running in namespace {1} " - + "(elapsed time {2}ms, remaining time {3}ms)", + condition -> logger.info("Checking if application {0} is running on pod {1} in namespace {2} " + + "(elapsed time {3}ms, remaining time {4}ms)", appPath, + podName, domainNamespace, condition.getElapsedTimeInMS(), condition.getRemainingTimeInMS())) @@ -931,9 +941,10 @@ private void quickCheckAppNotRunning( // check if the app is not running inside of a server pod withQuickRetryPolicy .conditionEvaluationListener( - condition -> logger.info("Checking if application {0} is not running in namespace {1} " - + "(elapsed time {2}ms, remaining time {3}ms)", + condition -> logger.info("Checking if application {0} is not running on pod {1} in namespace {2} " + + "(elapsed time {3}ms, remaining time {4}ms)", appPath, + podName, domainNamespace, condition.getElapsedTimeInMS(), condition.getRemainingTimeInMS())) @@ -967,4 +978,29 @@ private void checkDomainPatched( "Domain %s is not patched in namespace %s with image %s", domainUID, domainNamespace, image))); } + + private void checkPodImagePatched( + String domainUID, + String ns, + String podName, + String image + ) { + + // check if the app is accessible inside of a server pod + withStandardRetryPolicy + .conditionEvaluationListener( + condition -> logger.info("Waiting for pod {0} to be patched in namespace {1} " + + "(elapsed time {2}ms, remaining time {3}ms)", + podName, + ns, + condition.getElapsedTimeInMS(), + condition.getRemainingTimeInMS())) + .until(assertDoesNotThrow(() -> podImagePatched(domainUID, ns, podName, image), + String.format( + "Domain %s pod %s is not patched with image %s in namespace %s.", + domainUID, + podName, + domainNamespace, + image))); + } } diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/TestAssertions.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/TestAssertions.java index 4123d3546e9..2ddb5ee9ac8 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/TestAssertions.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/TestAssertions.java @@ -71,6 +71,26 @@ public static Callable domainResourceImagePatched( return Domain.domainResourceImagePatched(domainUid, namespace, image); } + /** + * Check if a WebLogic domain custom resource has been patched with a new image. + * + * @param domainUid ID of the domain + * @param namespace in which the domain custom resource object exists + * @param podName name of the WebLogic server pod + * @param image that was used to patch the domain resource + * @return true if the domain is patched + */ + public static Callable podImagePatched( + String domainUid, + String namespace, + String podName, + String image + ) throws ApiException { + return () -> { + return Kubernetes.isPodImagePatched(namespace, domainUid, podName, image); + }; + } + /** * Check if a Kubernetes pod exists in any state in the given namespace. * diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Kubernetes.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Kubernetes.java index 429b8f9c97e..e3d8e04ea7c 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Kubernetes.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Kubernetes.java @@ -14,6 +14,7 @@ import io.kubernetes.client.openapi.Configuration; import io.kubernetes.client.openapi.apis.CoreV1Api; import io.kubernetes.client.openapi.apis.CustomObjectsApi; +import io.kubernetes.client.openapi.models.V1Container; import io.kubernetes.client.openapi.models.V1Pod; import io.kubernetes.client.openapi.models.V1PodList; import io.kubernetes.client.openapi.models.V1Service; @@ -111,6 +112,42 @@ public static boolean isPodTerminating(String namespace, String domainUid, Strin return status; } + /** + * Checks if a pod has been patched with an expected image. + * + * @param namespace in which the pod is running + * @param domainUid the label the pod is decorated with + * @param image name of the image to check for + * @param podName name of the pod to check for + * @return true if pod's image has been patched + * @throws ApiException when there is error in querying the cluster + */ + public static boolean isPodImagePatched( + String namespace, + String domainUid, + String podName, + String image + ) throws ApiException { + boolean podPatched = false; + String labelSelector = null; + if (domainUid != null) { + labelSelector = String.format("weblogic.domainUID in (%s)", domainUid); + } + V1Pod pod = getPod(namespace, labelSelector, podName); + if (pod != null && pod.getSpec() != null) { + List containers = pod.getSpec().getContainers(); + for (V1Container c : containers) { + // find the weblogic server container + if (c.getName().equals("weblogic-server")) { + if (c.getImage().equals(image)) { + podPatched = true; + } + } + } + } + return podPatched; + } + /** * Checks if a Operator pod running in a given namespace. * The method assumes the operator name to starts with weblogic-operator- From 5ca8fc5246cbcb851b6809c751d4ca343d12883f Mon Sep 17 00:00:00 2001 From: doxiao Date: Tue, 28 Apr 2020 02:00:36 +0000 Subject: [PATCH 38/69] Fine tuning --- .../weblogic/kubernetes/ItMiiDomain.java | 82 ++++++++++--------- 1 file changed, 45 insertions(+), 37 deletions(-) diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java index 77e3ef62b7c..199b26ce321 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java @@ -534,7 +534,7 @@ public void testPatchAppV2() { // app here is what is in the original app dir plus the replacement in the second app dir final String appDir1 = "sample-app"; final String appDir2 = "sample-app-2"; - final String adminServerPodName = domainUid1 + "-admin-server"; + final String adminServerPodName = domainUid + "-admin-server"; final String managedServerPrefix = domainUid + "-managed-server"; final int replicaCount = 2; @@ -571,28 +571,16 @@ public void testPatchAppV2() { // push the image to OCIR to make the test work in multi node cluster pushImageIfNeeded(miiImagePatchAppV2); - // modify the domain resource to use the new image - patchDomainResourceIamge(domainUid, domainNamespace, miiImagePatchAppV2); - - // check if domain resource has been patched with the new image - checkDomainPatched(domainUid, domainNamespace, miiImagePatchAppV2); - - // check and wait for the admin server pod to be patched with the new image - checkPodImagePatched( + // patch the domain resource with the new image and verify that the domain resource is patched, + // and all server pods are patched as well. + patchAndVerify( domainUid, domainNamespace, adminServerPodName, + managedServerPrefix, + replicaCount, miiImagePatchAppV2); - // check and wait for the managed server pods to be patched with the new image - for (int i = 1; i <= replicaCount; i++) { - checkPodImagePatched( - domainUid, - domainNamespace, - managedServerPrefix + i, - miiImagePatchAppV2); - } - // check and wait for the app to be ready for (int i = 1; i <= replicaCount; i++) { checkAppRunning( @@ -618,7 +606,7 @@ public void testAddSecondApp() { final String appDir1 = "sample-app"; final String appDir2 = "sample-app-2"; final String appDir3 = "sample-app-3"; - final String adminServerPodName = domainUid1 + "-admin-server"; + final String adminServerPodName = domainUid + "-admin-server"; final String managedServerPrefix = domainUid + "-managed-server"; final int replicaCount = 2; @@ -662,27 +650,15 @@ public void testAddSecondApp() { // push the image to OCIR to make the test work in multi node cluster pushImageIfNeeded(miiImageAddSecondApp); - // modify the domain resource to use the new image - patchDomainResourceIamge(domainUid, domainNamespace, miiImageAddSecondApp); - - // check if the domain resource has been patched with the new image - checkDomainPatched(domainUid, domainNamespace, miiImageAddSecondApp); - - // check and wait for the admin server pod to be patched with the new image - checkPodImagePatched( + // patch the domain resource with the new image and verify that the domain resource is patched, + // and all server pods are patched as well. + patchAndVerify( domainUid, domainNamespace, adminServerPodName, - miiImagePatchAppV2); - - // check and wait for the managed server pods to be patched with the new image - for (int i = 1; i <= replicaCount; i++) { - checkPodImagePatched( - domainUid, - domainNamespace, - managedServerPrefix + i, - miiImageAddSecondApp); - } + managedServerPrefix, + replicaCount, + miiImageAddSecondApp); // check and wait for the new app to be ready for (int i = 1; i <= replicaCount; i++) { @@ -1083,6 +1059,38 @@ private void checkPodCreated(String podName, String domainUid, String domNamespa } + private void patchAndVerify( + final String domainUid, + final String domainNamespace, + final String adminServerPodName, + final String managedServerPrefix, + final int replicaCount, + final String image + ) { + // modify the domain resource to use the new image + patchDomainResourceIamge(domainUid, domainNamespace, image); + + // check if domain resource has been patched with the new image + checkDomainPatched(domainUid, domainNamespace, image); + + // check and wait for the admin server pod to be patched with the new image + checkPodImagePatched( + domainUid, + domainNamespace, + adminServerPodName, + image); + + // check and wait for the managed server pods to be patched with the new image + for (int i = 1; i <= replicaCount; i++) { + checkPodImagePatched( + domainUid, + domainNamespace, + managedServerPrefix + i, + image); + } + } + + private void checkPodReady(String podName, String domainUid, String domNamespace) { withStandardRetryPolicy .conditionEvaluationListener( From c68d8ea12418fcff6bb73e67a2bb4f994da9c035 Mon Sep 17 00:00:00 2001 From: doxiao Date: Tue, 28 Apr 2020 15:25:06 +0000 Subject: [PATCH 39/69] clean up --- .../impl/primitive/WebLogicImageTool.java | 4 ---- .../kubernetes/assertions/TestAssertions.java | 14 +++++++------- .../assertions/impl/Application.java | 5 +++-- .../kubernetes/assertions/impl/Domain.java | 13 +++++++------ .../assertions/impl/Kubernetes.java | 19 +++++++++---------- 5 files changed, 26 insertions(+), 29 deletions(-) diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/primitive/WebLogicImageTool.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/primitive/WebLogicImageTool.java index 0580d85ef5d..2508cf83013 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/primitive/WebLogicImageTool.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/primitive/WebLogicImageTool.java @@ -54,14 +54,10 @@ public boolean updateImage() { return false; } - logger.info("Image Tool is ready"); - // download WDT if it is not in the expected location if (!downloadWdt()) { return false; } - - logger.info("WDT installer is ready"); // delete the old cache entry for the WDT installer if (!deleteEntry()) { diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/TestAssertions.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/TestAssertions.java index 2ddb5ee9ac8..33031227d57 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/TestAssertions.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/TestAssertions.java @@ -72,12 +72,12 @@ public static Callable domainResourceImagePatched( } /** - * Check if a WebLogic domain custom resource has been patched with a new image. + * Check if a WebLogic server pod has been patched with a new image. * * @param domainUid ID of the domain - * @param namespace in which the domain custom resource object exists + * @param namespace in which the pod is running * @param podName name of the WebLogic server pod - * @param image that was used to patch the domain resource + * @param image name of the image that the pod is supposed to use * @return true if the domain is patched */ public static Callable podImagePatched( @@ -210,9 +210,9 @@ public static boolean dockerImageExists(String imageName, String imageTag) { * Check if an application is accessible inside a WebLogic server pod. * * @param domainUID unique identifier of the Kubernetes domain custom resource instance - * @param domainNS Kubernetes namespace where the WebLogic servers are running + * @param domainNS Kubernetes namespace where the WebLogic server pod is running * @param podName name of the WebLogic server pod - * @param port internal port of the managed servers + * @param port internal port of the managed server running in the pod * @param appPath the path to access the application * @param expectedStr the expected response from the application * @return true if the command succeeds @@ -234,9 +234,9 @@ public static Callable appAccessibleInPod( * Check if an application is Not running inside a WebLogic server pod. * . * @param domainUID unique identifier of the Kubernetes domain custom resource instance - * @param domainNS Kubernetes namespace where the WebLogic servers are running + * @param domainNS Kubernetes namespace where the WebLogic server pod is running * @param podName name of the WebLogic server pod - * @param port internal port of the managed servers + * @param port internal port of the managed server running in the pod * @param appPath the path to access the application * @param expectedStr the expected response from the application * @return true if the command succeeds diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Application.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Application.java index 1690e41c797..6e1e4f582a0 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Application.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Application.java @@ -15,10 +15,11 @@ public class Application { /** * Check if an application is accessible inside a WebLogic server pod. + * * @param domainUID identifier of the Kubernetes domain custom resource instance - * @param domainNS Kubernetes namespace where the WebLogic servers are running + * @param domainNS Kubernetes namespace where the WebLogic server pod is running * @param podName name of the WebLogic server pod - * @param port internal port of the managed servers + * @param port internal port of the managed server running in the pod * @param appPath the path to access the application * @return true if the command succeeds */ diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Domain.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Domain.java index 100f86b2d74..d3b426a6563 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Domain.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Domain.java @@ -78,12 +78,12 @@ public static Callable doesDomainExist(String domainUid, String domainV } /** - * Checks if domain resource has been patched with a new image. + * Checks if the domain resource has been patched with a new image. * - * @param domainUID domain UID of the domain object - * @param namespace in which the domain object exists - * @param image image that has been patch - * @return true if domain object 's image does not match what is expected + * @param domainUID identifier of the domain resource + * @param namespace in which the domain exists + * @param image name of the image that the pod is supposed to use + * @return true if domain resource's image does not match the expected value */ public static Callable domainResourceImagePatched( String domainUID, @@ -96,7 +96,8 @@ public static Callable domainResourceImagePatched( domain = oracle.weblogic.kubernetes.actions.impl.primitive.Kubernetes .getDomainCustomResource(domainUID, namespace); } catch (ApiException apex) { - logger.info(apex.getMessage()); + logger.severe("Failed to obtain the domain resource object from the API server", apex); + return false; } boolean domainPatched = (domain.spec().image().equals(image)); diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Kubernetes.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Kubernetes.java index e3d8e04ea7c..a7625d4efa6 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Kubernetes.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Kubernetes.java @@ -113,14 +113,14 @@ public static boolean isPodTerminating(String namespace, String domainUid, Strin } /** - * Checks if a pod has been patched with an expected image. + * Checks if a WebLogic server pod has been patched with an expected image. * - * @param namespace in which the pod is running + * @param namespace Kubernetes namespace in which the pod is running * @param domainUid the label the pod is decorated with + * @param podName name of the WebLogic server pod * @param image name of the image to check for - * @param podName name of the pod to check for * @return true if pod's image has been patched - * @throws ApiException when there is error in querying the cluster + * @throws ApiException when there is an error in querying the Kubernetes cluster */ public static boolean isPodImagePatched( String namespace, @@ -136,12 +136,11 @@ public static boolean isPodImagePatched( V1Pod pod = getPod(namespace, labelSelector, podName); if (pod != null && pod.getSpec() != null) { List containers = pod.getSpec().getContainers(); - for (V1Container c : containers) { - // find the weblogic server container - if (c.getName().equals("weblogic-server")) { - if (c.getImage().equals(image)) { - podPatched = true; - } + for (V1Container container : containers) { + // look for the weblogic server container + if (container.getName().equals("weblogic-server") + && (container.getImage().equals(image))) { + podPatched = true; } } } From 6fde567ab1dec7596fb572438b788da77c03f722 Mon Sep 17 00:00:00 2001 From: doxiao Date: Tue, 28 Apr 2020 17:59:49 +0000 Subject: [PATCH 40/69] More cleanup --- .../weblogic/kubernetes/ItMiiDomain.java | 22 ++++++++++--------- .../kubernetes/assertions/TestAssertions.java | 2 +- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java index 199b26ce321..a8e1c05abad 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java @@ -151,7 +151,8 @@ public static void initAll(@Namespaces(3) List namespaces) { .and().with().pollInterval(10, SECONDS) .atMost(6, MINUTES).await(); - withQuickRetryPolicy = with().pollDelay(1, SECONDS) + // create a reusable quick retry policy + withQuickRetryPolicy = with().pollDelay(0, SECONDS) .and().with().pollInterval(2, SECONDS) .atMost(5, SECONDS).await(); @@ -333,6 +334,7 @@ public void testCreateMiiDomain() { checkServiceCreated(managedServerPrefix + i, domainNamespace); } + // check and wait for the app to be accessible in all server pods for (int i = 1; i <= replicaCount; i++) { checkAppRunning( domainUid, @@ -563,7 +565,7 @@ public void testPatchAppV2() { "The second version of the app is not supposed to be running."); } - // create another image with app V2 + // create an image with app V2 miiImagePatchAppV2 = updateImageWithAppV2Patch( String.format("%s-%s", MII_IMAGE_NAME, "test-patch-app-v2"), Arrays.asList(appDir1, appDir2)); @@ -581,7 +583,7 @@ public void testPatchAppV2() { replicaCount, miiImagePatchAppV2); - // check and wait for the app to be ready + // check and wait for the V2 app to be ready for (int i = 1; i <= replicaCount; i++) { checkAppRunning( domainUid, @@ -592,7 +594,7 @@ public void testPatchAppV2() { APP_RESPONSE_V2 + i); } - logger.info("The cluster has been rolling started, and the version 2 application has been deployed correctly."); + logger.info("The cluster has been rolling restarted, and the version 2 application has been deployed correctly."); } @Test @@ -610,7 +612,7 @@ public void testAddSecondApp() { final String managedServerPrefix = domainUid + "-managed-server"; final int replicaCount = 2; - // check and V2 app is still running + // check and V2 app is still running after the previous test for (int i = 1; i <= replicaCount; i++) { quickCheckAppRunning( domainUid, @@ -635,10 +637,8 @@ public void testAddSecondApp() { APP_RESPONSE_V3, "The second app is not supposed to be running!!"); } - - logger.info("About to patch the domain with new image"); - - // create another image with an additional app + + // create an image with an additional app miiImageAddSecondApp = updateImageWithApp3( String.format("%s-%s", MII_IMAGE_NAME, "test-add-second-app"), Arrays.asList(appDir1, appDir2), @@ -649,6 +649,8 @@ public void testAddSecondApp() { // push the image to OCIR to make the test work in multi node cluster pushImageIfNeeded(miiImageAddSecondApp); + + logger.info("About to patch the domain with new image"); // patch the domain resource with the new image and verify that the domain resource is patched, // and all server pods are patched as well. @@ -671,7 +673,7 @@ public void testAddSecondApp() { APP_RESPONSE_V3); } - // check and wait for the original app to be ready + // check and wait for V2 app to be ready for (int i = 1; i <= replicaCount; i++) { checkAppRunning( domainUid, diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/TestAssertions.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/TestAssertions.java index 33031227d57..dfcc80a17a4 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/TestAssertions.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/TestAssertions.java @@ -78,7 +78,7 @@ public static Callable domainResourceImagePatched( * @param namespace in which the pod is running * @param podName name of the WebLogic server pod * @param image name of the image that the pod is supposed to use - * @return true if the domain is patched + * @return true if the pod is patched correctly */ public static Callable podImagePatched( String domainUid, From e15b34b65cc85710bba70d3fefc221f8332ebcdb Mon Sep 17 00:00:00 2001 From: doxiao Date: Tue, 28 Apr 2020 18:54:53 +0000 Subject: [PATCH 41/69] Continue work in progress --- .../weblogic/kubernetes/ItMiiDomain.java | 35 +++++++------------ .../kubernetes/assertions/TestAssertions.java | 12 +++---- 2 files changed, 16 insertions(+), 31 deletions(-) diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java index a8e1c05abad..a53190d5120 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java @@ -548,9 +548,7 @@ public void testPatchAppV2() { managedServerPrefix + i, "8001", "sample-war/index.jsp", - APP_RESPONSE_V1 + i, - String.format("App sample-war/index.jsp is not running in namespace %s as expected.", - domainNamespace)); + APP_RESPONSE_V1 + i); } // check and make sure that the version 2 app is NOT running @@ -561,8 +559,7 @@ public void testPatchAppV2() { managedServerPrefix + i, "8001", "sample-war/index.jsp", - APP_RESPONSE_V2 + i, - "The second version of the app is not supposed to be running."); + APP_RESPONSE_V2 + i); } // create an image with app V2 @@ -620,8 +617,7 @@ public void testAddSecondApp() { managedServerPrefix + i, "8001", "sample-war/index.jsp", - APP_RESPONSE_V2 + i, - "The expected app is not accessible inside the server pods"); + APP_RESPONSE_V2 + i); } logger.info("App version 2 is still running"); @@ -634,8 +630,7 @@ public void testAddSecondApp() { managedServerPrefix + i, "8001", "sample-war-3/index.jsp", - APP_RESPONSE_V3, - "The second app is not supposed to be running!!"); + APP_RESPONSE_V3); } // create an image with an additional app @@ -1142,15 +1137,13 @@ private void checkAppRunning( domainNamespace, condition.getElapsedTimeInMS(), condition.getRemainingTimeInMS())) - .until(assertDoesNotThrow(() -> appAccessibleInPod( + .until(() -> appAccessibleInPod( domainUid, ns, podName, internalPort, appPath, - expectedStr), - String.format( - "App %s is not ready on pod %s in namespace %s", appPath, podName, domainNamespace))); + expectedStr)); } @@ -1160,8 +1153,7 @@ private void quickCheckAppRunning( String podName, String internalPort, String appPath, - String expectedStr, - String failMessage + String expectedStr ) { // check if the app is accessible inside of a server pod @@ -1174,14 +1166,13 @@ private void quickCheckAppRunning( domainNamespace, condition.getElapsedTimeInMS(), condition.getRemainingTimeInMS())) - .until(assertDoesNotThrow(() -> appAccessibleInPod( + .until(() -> appAccessibleInPod( domainUid, ns, podName, internalPort, appPath, - expectedStr), - failMessage)); + expectedStr)); } @@ -1191,8 +1182,7 @@ private void quickCheckAppNotRunning( String podName, String internalPort, String appPath, - String expectedStr, - String failMessage + String expectedStr ) { // check if the app is not running inside of a server pod @@ -1205,14 +1195,13 @@ private void quickCheckAppNotRunning( domainNamespace, condition.getElapsedTimeInMS(), condition.getRemainingTimeInMS())) - .until(assertDoesNotThrow(() -> appNotAccessibleInPod( + .until(() -> appNotAccessibleInPod( domainUid, ns, podName, internalPort, appPath, - expectedStr), - failMessage)); + expectedStr)); } private void checkDomainPatched( diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/TestAssertions.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/TestAssertions.java index dfcc80a17a4..06a4e54a001 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/TestAssertions.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/TestAssertions.java @@ -217,7 +217,7 @@ public static boolean dockerImageExists(String imageName, String imageTag) { * @param expectedStr the expected response from the application * @return true if the command succeeds */ - public static Callable appAccessibleInPod( + public static boolean appAccessibleInPod( String domainUID, String domainNS, String podName, @@ -225,9 +225,7 @@ public static Callable appAccessibleInPod( String appPath, String expectedStr ) { - return () -> { - return Application.appAccessibleInPod(domainUID, domainNS, podName, port, appPath, expectedStr); - }; + return Application.appAccessibleInPod(domainUID, domainNS, podName, port, appPath, expectedStr); } /** @@ -241,7 +239,7 @@ public static Callable appAccessibleInPod( * @param expectedStr the expected response from the application * @return true if the command succeeds */ - public static Callable appNotAccessibleInPod( + public static boolean appNotAccessibleInPod( String domainUID, String domainNS, String podName, @@ -249,9 +247,7 @@ public static Callable appNotAccessibleInPod( String appPath, String expectedStr ) { - return () -> { - return !Application.appAccessibleInPod(domainUID, domainNS, podName, port, appPath, expectedStr); - }; + return !Application.appAccessibleInPod(domainUID, domainNS, podName, port, appPath, expectedStr); } /** From b8a267c36e2d09af33d923af4515d60f83516b46 Mon Sep 17 00:00:00 2001 From: doxiao Date: Thu, 30 Apr 2020 21:17:14 +0000 Subject: [PATCH 42/69] Add app continuous availability check and enable it with a system property --- .../weblogic/kubernetes/ItMiiDomain.java | 226 +++++++++++++----- .../assertions/impl/Application.java | 4 +- 2 files changed, 168 insertions(+), 62 deletions(-) diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java index a53190d5120..085ca4f4eb7 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java @@ -6,12 +6,14 @@ import java.io.IOException; import java.text.DateFormat; import java.text.SimpleDateFormat; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.concurrent.TimeUnit; import com.google.gson.JsonObject; import io.kubernetes.client.custom.V1Patch; @@ -533,65 +535,107 @@ public void testCreateMiiDomainSameDomainUidDiffNS() { @MustNotRunInParallel public void testPatchAppV2() { - // app here is what is in the original app dir plus the replacement in the second app dir + // app in the new image contains what is in the original app dir sample-app, + // plus the replacement in the second app dir sample-app-2. final String appDir1 = "sample-app"; final String appDir2 = "sample-app-2"; final String adminServerPodName = domainUid + "-admin-server"; final String managedServerPrefix = domainUid + "-managed-server"; final int replicaCount = 2; - // check and make sure that V1 app is running - for (int i = 1; i <= replicaCount; i++) { - quickCheckAppRunning( + // The verification of app's continuous availability during patching can be enabled + // using the following system property for now because it fails intermittently right now. + // We'll remove the property and enable it all the time once the product problem (tracked + // by owls-81575) is fixed. + final String enableAppAvailbilityCheck = + System.getProperty("weblogic.operator.enableAppAvailabilityCheck", "false"); + Thread accountingThread = null; + List appAvailability = new ArrayList(); + + if (enableAppAvailbilityCheck.equalsIgnoreCase("true")) { + // start a new thread to collect the availability data of the app while the + // main thread performs patching operation, and checking of the results. + accountingThread = + new Thread( + () -> { + collectAppAvaiability( + domainUid, + domainNamespace, + appAvailability, + managedServerPrefix, + replicaCount, + "8001", + "sample-war/index.jsp"); + }); + accountingThread.start(); + } + + try { + // check and make sure that V1 app is running + for (int i = 1; i <= replicaCount; i++) { + quickCheckAppRunning( domainUid, domainNamespace, managedServerPrefix + i, "8001", "sample-war/index.jsp", APP_RESPONSE_V1 + i); - } + } - // check and make sure that the version 2 app is NOT running - for (int i = 1; i <= replicaCount; i++) { - quickCheckAppNotRunning( + // check and make sure that the version 2 app is NOT running + for (int i = 1; i <= replicaCount; i++) { + quickCheckAppNotRunning( domainUid, domainNamespace, managedServerPrefix + i, "8001", "sample-war/index.jsp", APP_RESPONSE_V2 + i); - } + } - // create an image with app V2 - miiImagePatchAppV2 = updateImageWithAppV2Patch( - String.format("%s-%s", MII_IMAGE_NAME, "test-patch-app-v2"), - Arrays.asList(appDir1, appDir2)); - - // push the image to OCIR to make the test work in multi node cluster - pushImageIfNeeded(miiImagePatchAppV2); + // create an image with app V2 + miiImagePatchAppV2 = updateImageWithAppV2Patch( + String.format("%s-%s", MII_IMAGE_NAME, "test-patch-app-v2"), + Arrays.asList(appDir1, appDir2)); - // patch the domain resource with the new image and verify that the domain resource is patched, - // and all server pods are patched as well. - patchAndVerify( - domainUid, - domainNamespace, - adminServerPodName, - managedServerPrefix, - replicaCount, - miiImagePatchAppV2); + // push the image to OCIR to make the test work in multi node cluster + pushImageIfNeeded(miiImagePatchAppV2); - // check and wait for the V2 app to be ready - for (int i = 1; i <= replicaCount; i++) { - checkAppRunning( + // patch the domain resource with the new image and verify that the domain resource is patched, + // and all server pods are patched as well. + patchAndVerify( domainUid, domainNamespace, - managedServerPrefix + i, - "8001", - "sample-war/index.jsp", - APP_RESPONSE_V2 + i); + adminServerPodName, + managedServerPrefix, + replicaCount, + miiImagePatchAppV2); + + // check and wait for the V2 app to be ready + for (int i = 1; i <= replicaCount; i++) { + checkAppRunning( + domainUid, + domainNamespace, + managedServerPrefix + i, + "8001", + "sample-war/index.jsp", + APP_RESPONSE_V2 + i); + } + } finally { + + if (accountingThread != null) { + try { + accountingThread.join(); + } catch (InterruptedException ie) { + // do nothing + } + + assertTrue(appAlwaysAvailable(appAvailability), + "App does not always avaiable when the domain is being patched with a newer version of the app."); + } } - - logger.info("The cluster has been rolling restarted, and the version 2 application has been deployed correctly."); + + logger.info("The cluster has been rolling restarted, and the version 2 app has been deployed correctly."); } @Test @@ -632,7 +676,7 @@ public void testAddSecondApp() { "sample-war-3/index.jsp", APP_RESPONSE_V3); } - + // create an image with an additional app miiImageAddSecondApp = updateImageWithApp3( String.format("%s-%s", MII_IMAGE_NAME, "test-add-second-app"), @@ -668,7 +712,7 @@ public void testAddSecondApp() { APP_RESPONSE_V3); } - // check and wait for V2 app to be ready + // check and wait for the V2 app to be ready for (int i = 1; i <= replicaCount; i++) { checkAppRunning( domainUid, @@ -751,7 +795,7 @@ public void tearDownAll() { } // clean up the download directory so that we always get the latest - // versions of the tools + // versions of the tools in every run of the test class. try { cleanupDirectory(DOWNLOAD_DIR); } catch (IOException | RuntimeException e) { @@ -1058,22 +1102,22 @@ private void checkPodCreated(String podName, String domainUid, String domNamespa private void patchAndVerify( final String domainUid, - final String domainNamespace, + final String namespace, final String adminServerPodName, final String managedServerPrefix, final int replicaCount, final String image ) { // modify the domain resource to use the new image - patchDomainResourceIamge(domainUid, domainNamespace, image); + patchDomainResourceIamge(domainUid, namespace, image); // check if domain resource has been patched with the new image - checkDomainPatched(domainUid, domainNamespace, image); + checkDomainPatched(domainUid, namespace, image); // check and wait for the admin server pod to be patched with the new image checkPodImagePatched( domainUid, - domainNamespace, + namespace, adminServerPodName, image); @@ -1081,7 +1125,7 @@ private void patchAndVerify( for (int i = 1; i <= replicaCount; i++) { checkPodImagePatched( domainUid, - domainNamespace, + namespace, managedServerPrefix + i, image); } @@ -1114,13 +1158,13 @@ private void checkServiceCreated(String serviceName, String domNamespace) { condition.getRemainingTimeInMS())) .until(assertDoesNotThrow(() -> serviceExists(serviceName, null, domNamespace), String.format( - "Service %s is not ready in namespace %s", serviceName, domainNamespace))); + "Service %s is not ready in namespace %s", serviceName, domNamespace))); } private void checkAppRunning( String domainUid, - String ns, + String namespace, String podName, String internalPort, String appPath, @@ -1134,12 +1178,12 @@ private void checkAppRunning( + "(elapsed time {3}ms, remaining time {4}ms)", appPath, podName, - domainNamespace, + namespace, condition.getElapsedTimeInMS(), condition.getRemainingTimeInMS())) .until(() -> appAccessibleInPod( domainUid, - ns, + namespace, podName, internalPort, appPath, @@ -1149,7 +1193,7 @@ private void checkAppRunning( private void quickCheckAppRunning( String domainUid, - String ns, + String namespace, String podName, String internalPort, String appPath, @@ -1163,12 +1207,12 @@ private void quickCheckAppRunning( + "(elapsed time {3}ms, remaining time {4}ms)", appPath, podName, - domainNamespace, + namespace, condition.getElapsedTimeInMS(), condition.getRemainingTimeInMS())) .until(() -> appAccessibleInPod( domainUid, - ns, + namespace, podName, internalPort, appPath, @@ -1178,7 +1222,7 @@ private void quickCheckAppRunning( private void quickCheckAppNotRunning( String domainUid, - String ns, + String namespace, String podName, String internalPort, String appPath, @@ -1192,12 +1236,12 @@ private void quickCheckAppNotRunning( + "(elapsed time {3}ms, remaining time {4}ms)", appPath, podName, - domainNamespace, + namespace, condition.getElapsedTimeInMS(), condition.getRemainingTimeInMS())) .until(() -> appNotAccessibleInPod( domainUid, - ns, + namespace, podName, internalPort, appPath, @@ -1206,7 +1250,7 @@ private void quickCheckAppNotRunning( private void checkDomainPatched( String domainUid, - String ns, + String namespace, String image ) { @@ -1216,18 +1260,18 @@ private void checkDomainPatched( condition -> logger.info("Waiting for domain {0} to be patched in namespace {1} " + "(elapsed time {2}ms, remaining time {3}ms)", domainUid, - ns, + namespace, condition.getElapsedTimeInMS(), condition.getRemainingTimeInMS())) - .until(assertDoesNotThrow(() -> domainResourceImagePatched(domainUid, ns, image), + .until(assertDoesNotThrow(() -> domainResourceImagePatched(domainUid, namespace, image), String.format( - "Domain %s is not patched in namespace %s with image %s", domainUid, domainNamespace, image))); + "Domain %s is not patched in namespace %s with image %s", domainUid, namespace, image))); } private void checkPodImagePatched( String domainUid, - String ns, + String namespace, String podName, String image ) { @@ -1238,15 +1282,77 @@ private void checkPodImagePatched( condition -> logger.info("Waiting for pod {0} to be patched in namespace {1} " + "(elapsed time {2}ms, remaining time {3}ms)", podName, - ns, + namespace, condition.getElapsedTimeInMS(), condition.getRemainingTimeInMS())) - .until(assertDoesNotThrow(() -> podImagePatched(domainUid, ns, podName, image), + .until(assertDoesNotThrow(() -> podImagePatched(domainUid, namespace, podName, image), String.format( "Domain %s pod %s is not patched with image %s in namespace %s.", domainUid, podName, - domainNamespace, + namespace, image))); } + + private static void collectAppAvaiability( + String domainUid, + String namespace, + List appAvailability, + String managedServerPrefix, + int replicaCount, + String internalPort, + String appPath + ) { + boolean v2AppAvailable = false; + // ping the app periodically to check its availability across the duration + // of patching the domain with newer version of the app. + do { + v2AppAvailable = appAccessibleInPod( + domainUid, + namespace, + managedServerPrefix + replicaCount, + internalPort, + appPath, + APP_RESPONSE_V2 + replicaCount); + + int count = 0; + for (int i = 1; i <= replicaCount; i++) { + if (appAccessibleInPod( + domainUid, + namespace, + managedServerPrefix + i, + internalPort, + appPath, + "Hello World")) { + count++; + } + } + appAvailability.add(count); + + // the following log messages are temporarily here for debugging purposes. + // This part of the code is disabled by default right now, and can be enabled by + // -Dweblogic.operator.enableAppAvailabilityCheck=true. + // TODO remove these log messages when this verification is fully enabled. + if (count == 0) { + logger.info("XXXXXXXXXXX: app not available XXXXXXXX"); + } else { + logger.info("YYYYYYYYYYY: app available YYYYYYYY count = " + count); + } + try { + TimeUnit.MILLISECONDS.sleep(50); + } catch (InterruptedException ie) { + // do nothing + } + } while (!v2AppAvailable); + } + + private static boolean appAlwaysAvailable(List appAvailability) { + for (Integer count: appAvailability) { + if (count == 0) { + logger.warning("App was not continuously available during patching."); + return false; + } + } + return true; + } } diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Application.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Application.java index 6e1e4f582a0..eb475e4c695 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Application.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Application.java @@ -47,8 +47,8 @@ public static boolean appAccessibleInPod( .defaultCommandParams() .command(cmd) .saveResults(true) - .redirect(true) - .verbose(true); + .redirect(false) + .verbose(false); return Command.withParams(params).executeAndVerify(expectedStr); } } From 497ad2759d14b73a6d20d02a8e4ac1a4ad5a819e Mon Sep 17 00:00:00 2001 From: doxiao Date: Thu, 30 Apr 2020 21:33:21 +0000 Subject: [PATCH 43/69] Clean up --- .../test/java/oracle/weblogic/kubernetes/ItMiiDomain.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java index 085ca4f4eb7..71311bb46a6 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java @@ -350,7 +350,7 @@ public void testCreateMiiDomain() { logger.info(String.format("Domain %s is fully started - servers are running and application is deployed corretly.", domainUid)); } - + @Test @Order(2) @DisplayName("Create a second domain with the image from the the first test") @@ -738,6 +738,7 @@ public void tearDownAll() { "deleteDomainCustomResource failed with ApiException"); logger.info("Deleted Domain Custom Resource " + domainUid + " from " + domainNamespace); + logger.info("Delete domain custom resource in namespace {0}", domainNamespace1); assertDoesNotThrow(() -> deleteDomainCustomResource(domainUid1, domainNamespace1), "deleteDomainCustomResource failed with ApiException"); logger.info("Deleted Domain Custom Resource " + domainUid1 + " from " + domainNamespace1); @@ -980,7 +981,7 @@ private void createImageAndVerify( .env(env) .redirect(true)); - assertTrue(result, String.format("Failed to create the image %s using WebLogic Image Tool", image)); + assertTrue(result, String.format("Failed to create the image %s using WebLogic Image Tool", image)); /* Check image exists using docker images | grep image tag. * Tag name is unique as it contains date and timestamp. From 32cab300710b9395956599c77913dc16dd09aeb7 Mon Sep 17 00:00:00 2001 From: doxiao Date: Fri, 1 May 2020 14:56:25 +0000 Subject: [PATCH 44/69] More javadoc --- .../weblogic/kubernetes/actions/impl/primitive/Command.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/primitive/Command.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/primitive/Command.java index 7df0f6055cc..1f125c29bdb 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/primitive/Command.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/primitive/Command.java @@ -41,7 +41,8 @@ private Command params(CommandParams params) { /** * Execute a command. - * @return true on success + * + * @return true if the execution succeeded with an exitValue of zero */ public boolean execute() { if (params.verbose()) { @@ -73,7 +74,7 @@ public boolean execute() { * Execute a command and verify the response. * * @params expectedResponse the expected response to verify - * @return true on success + * @return true if the execution succeeded and response contains the expected value */ public boolean executeAndVerify(String expectedResponse) { if (params.verbose()) { From 9570c024c5659630e84f9ce6e869df5f5c27d86f Mon Sep 17 00:00:00 2001 From: doxiao Date: Fri, 1 May 2020 19:51:59 +0000 Subject: [PATCH 45/69] javadoc and cleanup --- .../weblogic/kubernetes/ItMiiDomain.java | 71 +++++++------------ .../actions/impl/primitive/CommandParams.java | 3 +- .../actions/impl/primitive/Kubernetes.java | 2 +- .../kubernetes/assertions/TestAssertions.java | 36 +++++----- .../assertions/impl/Application.java | 8 +-- .../kubernetes/assertions/impl/Domain.java | 4 +- .../assertions/impl/Kubernetes.java | 2 +- .../apps/sample-app-3/sample-war-3/index.jsp | 2 +- 8 files changed, 51 insertions(+), 77 deletions(-) diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java index 58353989274..0a8f96cc410 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java @@ -125,7 +125,7 @@ class ItMiiDomain implements LoggedTest { // app constants private static final String APP_RESPONSE_V1 = "Hello World, you have reached server managed-server"; private static final String APP_RESPONSE_V2 = "Hello World AGAIN, you have reached server managed-server"; - private static final String APP_RESPONSE_V3 = "How are you doing!"; + private static final String APP_RESPONSE_V3 = "How are you doing! You have reached server managed-server"; private static final String READ_STATE_COMMAND = "/weblogic-operator/scripts/readState.sh"; @@ -348,7 +348,6 @@ public void testCreateMiiDomain() { // check and wait for the app to be accessible in all server pods for (int i = 1; i <= replicaCount; i++) { checkAppRunning( - domainUid, domainNamespace, managedServerPrefix + i, "8001", @@ -545,15 +544,15 @@ public void testCreateMiiDomainSameDomainUidDiffNS() { public void testPatchAppV2() { // app in the new image contains what is in the original app dir sample-app, - // plus the replacement in the second app dir sample-app-2. + // plus the replacements or/and additions in the second app dir sample-app-2. final String appDir1 = "sample-app"; final String appDir2 = "sample-app-2"; final String adminServerPodName = domainUid + "-admin-server"; final String managedServerPrefix = domainUid + "-managed-server"; final int replicaCount = 2; - // The verification of app's continuous availability during patching can be enabled - // using the following system property for now because it fails intermittently right now. + // The verification of app's continuous availability during patching is turned off + // because it fails intermittently right now. It can be enabled using the following system property. // We'll remove the property and enable it all the time once the product problem (tracked // by owls-81575) is fixed. final String enableAppAvailbilityCheck = @@ -568,7 +567,6 @@ public void testPatchAppV2() { new Thread( () -> { collectAppAvaiability( - domainUid, domainNamespace, appAvailability, managedServerPrefix, @@ -583,7 +581,6 @@ public void testPatchAppV2() { // check and make sure that V1 app is running for (int i = 1; i <= replicaCount; i++) { quickCheckAppRunning( - domainUid, domainNamespace, managedServerPrefix + i, "8001", @@ -594,7 +591,6 @@ public void testPatchAppV2() { // check and make sure that the version 2 app is NOT running for (int i = 1; i <= replicaCount; i++) { quickCheckAppNotRunning( - domainUid, domainNamespace, managedServerPrefix + i, "8001", @@ -623,7 +619,6 @@ public void testPatchAppV2() { // check and wait for the V2 app to be ready for (int i = 1; i <= replicaCount; i++) { checkAppRunning( - domainUid, domainNamespace, managedServerPrefix + i, "8001", @@ -634,7 +629,7 @@ public void testPatchAppV2() { if (accountingThread != null) { try { - accountingThread.join(); + accountingThread.join(50); } catch (InterruptedException ie) { // do nothing } @@ -654,7 +649,8 @@ public void testPatchAppV2() { @MustNotRunInParallel public void testAddSecondApp() { - // app here is what is in the original app dir plus the delta in the second app dir + // the existing app is the combination of what are in appDir1 and appDir2 as in test case number 4, + // the second app is in appDir3. final String appDir1 = "sample-app"; final String appDir2 = "sample-app-2"; final String appDir3 = "sample-app-3"; @@ -665,7 +661,6 @@ public void testAddSecondApp() { // check and V2 app is still running after the previous test for (int i = 1; i <= replicaCount; i++) { quickCheckAppRunning( - domainUid, domainNamespace, managedServerPrefix + i, "8001", @@ -675,18 +670,17 @@ public void testAddSecondApp() { logger.info("App version 2 is still running"); - // check and make sure that the new app is not already running + // check and make sure that the new app is NOT already running for (int i = 1; i <= replicaCount; i++) { quickCheckAppNotRunning( - domainUid, domainNamespace, managedServerPrefix + i, "8001", "sample-war-3/index.jsp", - APP_RESPONSE_V3); + APP_RESPONSE_V3 + i); } - // create an image with an additional app + // create an image with the additional app miiImageAddSecondApp = updateImageWithApp3( String.format("%s-%s", MII_IMAGE_NAME, "test-add-second-app"), Arrays.asList(appDir1, appDir2), @@ -713,18 +707,16 @@ public void testAddSecondApp() { // check and wait for the new app to be ready for (int i = 1; i <= replicaCount; i++) { checkAppRunning( - domainUid, domainNamespace, managedServerPrefix + i, "8001", "sample-war-3/index.jsp", - APP_RESPONSE_V3); + APP_RESPONSE_V3 + i); } // check and wait for the V2 app to be ready for (int i = 1; i <= replicaCount; i++) { checkAppRunning( - domainUid, domainNamespace, managedServerPrefix + i, "8001", @@ -866,7 +858,7 @@ private String updateImageWithAppV2Patch( List modelList = Collections.singletonList(String.format("%s/%s", MODEL_DIR, WDT_MODEL_FILE)); - // build an application archive using what is in resources/apps/APP_NAME + // build an application archive assertTrue( buildAppArchive( defaultAppParams() @@ -903,8 +895,7 @@ private String updateImageWithApp3( String appName1 = appDirList1.get(0); String appName2 = appDirList2.get(0); - // build an application archive using for the first app, which is the same after - // patching the original app. + // build an application archive that contains the existing app assertTrue( buildAppArchive( defaultAppParams() @@ -914,7 +905,8 @@ private String updateImageWithApp3( appName1)); logger.info("Successfully created app zip file: " + appName1); - + + // build an application archive that contains the new app assertTrue( buildAppArchive( defaultAppParams() @@ -936,15 +928,15 @@ private String updateImageWithApp3( } /** - * Patch the domain resource with a new image that contains a newer version of the application. + * Patch the domain resource with a new image. * Here is an example of the JSON patch string that is constructed in this method. * [ * {"op": "replace", "path": "/spec/image", "value": "mii-image:v2" } * ] * - * @param domainUid the unique identifier of the domain resource - * @param namespace the Kubernetes namespace that the domain is hosted - * @param image the name of the image that contains a newer version of the application + * @param domainUid unique identifier of the domain resource + * @param namespace Kubernetes namespace that the domain is hosted + * @param image name of the new image */ private void patchDomainResourceIamge( String domainUid, @@ -1126,7 +1118,6 @@ private void patchAndVerify( // check and wait for the admin server pod to be patched with the new image checkPodImagePatched( - domainUid, namespace, adminServerPodName, image); @@ -1134,7 +1125,6 @@ private void patchAndVerify( // check and wait for the managed server pods to be patched with the new image for (int i = 1; i <= replicaCount; i++) { checkPodImagePatched( - domainUid, namespace, managedServerPrefix + i, image); @@ -1173,11 +1163,10 @@ private void checkServiceCreated(String serviceName, String domNamespace) { } private void checkAppRunning( - String domainUid, String namespace, String podName, String internalPort, - String appPath, + String appPath, String expectedStr ) { @@ -1192,7 +1181,6 @@ private void checkAppRunning( condition.getElapsedTimeInMS(), condition.getRemainingTimeInMS())) .until(() -> appAccessibleInPod( - domainUid, namespace, podName, internalPort, @@ -1202,11 +1190,10 @@ private void checkAppRunning( } private void quickCheckAppRunning( - String domainUid, String namespace, String podName, String internalPort, - String appPath, + String appPath, String expectedStr ) { @@ -1221,7 +1208,6 @@ private void quickCheckAppRunning( condition.getElapsedTimeInMS(), condition.getRemainingTimeInMS())) .until(() -> appAccessibleInPod( - domainUid, namespace, podName, internalPort, @@ -1231,11 +1217,10 @@ private void quickCheckAppRunning( } private void quickCheckAppNotRunning( - String domainUid, String namespace, String podName, String internalPort, - String appPath, + String appPath, String expectedStr ) { @@ -1250,7 +1235,6 @@ private void quickCheckAppNotRunning( condition.getElapsedTimeInMS(), condition.getRemainingTimeInMS())) .until(() -> appNotAccessibleInPod( - domainUid, namespace, podName, internalPort, @@ -1264,7 +1248,7 @@ private void checkDomainPatched( String image ) { - // check if the domain is patched with the new image + // check if the domain resource has been patched with the given image withStandardRetryPolicy .conditionEvaluationListener( condition -> logger.info("Waiting for domain {0} to be patched in namespace {1} " @@ -1280,13 +1264,12 @@ private void checkDomainPatched( } private void checkPodImagePatched( - String domainUid, String namespace, String podName, String image ) { - // check if the app is accessible inside of a server pod + // check if the server pod has been patched with the given image withStandardRetryPolicy .conditionEvaluationListener( condition -> logger.info("Waiting for pod {0} to be patched in namespace {1} " @@ -1297,15 +1280,13 @@ private void checkPodImagePatched( condition.getRemainingTimeInMS())) .until(assertDoesNotThrow(() -> podImagePatched(domainUid, namespace, podName, image), String.format( - "Domain %s pod %s is not patched with image %s in namespace %s.", - domainUid, + "Pod od %s is not patched with image %s in namespace %s.", podName, namespace, image))); } private static void collectAppAvaiability( - String domainUid, String namespace, List appAvailability, String managedServerPrefix, @@ -1318,7 +1299,6 @@ private static void collectAppAvaiability( // of patching the domain with newer version of the app. do { v2AppAvailable = appAccessibleInPod( - domainUid, namespace, managedServerPrefix + replicaCount, internalPort, @@ -1328,7 +1308,6 @@ private static void collectAppAvaiability( int count = 0; for (int i = 1; i <= replicaCount; i++) { if (appAccessibleInPod( - domainUid, namespace, managedServerPrefix + i, internalPort, diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/primitive/CommandParams.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/primitive/CommandParams.java index f34db0faa33..7030b6d737e 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/primitive/CommandParams.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/primitive/CommandParams.java @@ -28,7 +28,8 @@ public class CommandParams { // The stderr of the command execution private String stderr; - + + // Whether to turn on verbose logging private boolean verbose = true; public CommandParams defaults() { diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/primitive/Kubernetes.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/primitive/Kubernetes.java index 80ee261704f..1530cd7dad0 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/primitive/Kubernetes.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/primitive/Kubernetes.java @@ -1416,7 +1416,7 @@ public static ExecResult exec(V1Pod pod, String containerName, boolean redirectT // wait for reading thread to finish any last remaining output if (out != null) { - // need to timeout here, otherwise the command can take a couple of seconds to return. + // need to time out here, otherwise the command can take a couple of seconds to return. // don't know if we'll need a different timeout value for different environments. out.join(1000); } diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/TestAssertions.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/TestAssertions.java index 783b760d7f5..2cdaf9f1482 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/TestAssertions.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/TestAssertions.java @@ -58,10 +58,10 @@ public static Callable domainExists(String domainUid, String domainVers /** * Check if a WebLogic domain custom resource has been patched with a new image. * - * @param domainUid ID of the domain - * @param namespace in which the domain custom resource object exists - * @param image that was used to patch the domain resource - * @return true if the domain is patched + * @param domainUid ID of the domain resource + * @param namespace Kubernetes namespace in which the domain custom resource object exists + * @param image name of the image that was used to patch the domain resource + * @return true if the domain is patched correctly */ public static Callable domainResourceImagePatched( String domainUid, @@ -74,10 +74,10 @@ public static Callable domainResourceImagePatched( /** * Check if a WebLogic server pod has been patched with a new image. * - * @param domainUid ID of the domain - * @param namespace in which the pod is running + * @param domainUid ID of the domain resource + * @param namespace Kubernetes namespace in which the domain custom resource object exists * @param podName name of the WebLogic server pod - * @param image name of the image that the pod is supposed to use + * @param image name of the image that was used to patch the domain resource * @return true if the pod is patched correctly */ public static Callable podImagePatched( @@ -187,7 +187,7 @@ public static boolean adminT3ChannelAccessible(String domainUid, String namespac /** * Check if a admin server pod admin node port is accessible. * - * @param domainUid domainUID id of the domain in which admin server pod is running + * @param domainUid domainUid id of the domain in which admin server pod is running * @param namespace in which the WebLogic server pod exists * @return true if the admin node port is accessible otherwise false */ @@ -209,45 +209,41 @@ public static boolean dockerImageExists(String imageName, String imageTag) { /** * Check if an application is accessible inside a WebLogic server pod. * - * @param domainUID unique identifier of the Kubernetes domain custom resource instance - * @param domainNS Kubernetes namespace where the WebLogic server pod is running + * @param namespace Kubernetes namespace where the WebLogic server pod is running * @param podName name of the WebLogic server pod * @param port internal port of the managed server running in the pod - * @param appPath the path to access the application + * @param appPath path to access the application * @param expectedStr the expected response from the application * @return true if the command succeeds */ public static boolean appAccessibleInPod( - String domainUID, - String domainNS, + String namespace, String podName, String port, String appPath, String expectedStr ) { - return Application.appAccessibleInPod(domainNS, podName, port, appPath, expectedStr); + return Application.appAccessibleInPod(namespace, podName, port, appPath, expectedStr); } /** * Check if an application is Not running inside a WebLogic server pod. * . - * @param domainUID unique identifier of the Kubernetes domain custom resource instance - * @param domainNS Kubernetes namespace where the WebLogic server pod is running + * @param namespace Kubernetes namespace where the WebLogic server pod is running * @param podName name of the WebLogic server pod * @param port internal port of the managed server running in the pod - * @param appPath the path to access the application + * @param appPath path to access the application * @param expectedStr the expected response from the application * @return true if the command succeeds */ public static boolean appNotAccessibleInPod( - String domainUID, - String domainNS, + String namespace, String podName, String port, String appPath, String expectedStr ) { - return !Application.appAccessibleInPod(domainNS, podName, port, appPath, expectedStr); + return !Application.appAccessibleInPod(namespace, podName, port, appPath, expectedStr); } /** diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Application.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Application.java index 6172b96eab1..1faf90ab3c2 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Application.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Application.java @@ -26,8 +26,7 @@ public class Application { * @param namespace Kubernetes namespace where the WebLogic server pod is running * @param podName name of the WebLogic server pod * @param port internal port of the managed server running in the pod - * @param appPath the path to access the application - * + * @param appPath path to access the application * @return true if the command succeeds */ public static boolean appAccessibleInPod( @@ -50,9 +49,8 @@ public static boolean appAccessibleInPod( ExecResult execResult = execCommand( namespace, podName, - //"weblogic-server", // container name - null, - true, // redirectOutput + "weblogic-server", // container name + false, // redirectOutput cmd); if (execResult.exitValue() == 0 && execResult.stdout() != null diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Domain.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Domain.java index d3b426a6563..ecc9e4637b9 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Domain.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Domain.java @@ -81,9 +81,9 @@ public static Callable doesDomainExist(String domainUid, String domainV * Checks if the domain resource has been patched with a new image. * * @param domainUID identifier of the domain resource - * @param namespace in which the domain exists + * @param namespace Kubernetes namespace in which the domain exists * @param image name of the image that the pod is supposed to use - * @return true if domain resource's image does not match the expected value + * @return true if domain resource's image matches the expected value */ public static Callable domainResourceImagePatched( String domainUID, diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Kubernetes.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Kubernetes.java index c78ba3518cb..6fda1e500e0 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Kubernetes.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Kubernetes.java @@ -116,7 +116,7 @@ public static boolean isPodTerminating(String namespace, String domainUid, Strin * Checks if a WebLogic server pod has been patched with an expected image. * * @param namespace Kubernetes namespace in which the pod is running - * @param domainUid the label the pod is decorated with + * @param domainUid label that the pod is decorated with * @param podName name of the WebLogic server pod * @param image name of the image to check for * @return true if pod's image has been patched diff --git a/new-integration-tests/src/test/resources/apps/sample-app-3/sample-war-3/index.jsp b/new-integration-tests/src/test/resources/apps/sample-app-3/sample-war-3/index.jsp index dabc6182081..49df464bd08 100644 --- a/new-integration-tests/src/test/resources/apps/sample-app-3/sample-war-3/index.jsp +++ b/new-integration-tests/src/test/resources/apps/sample-app-3/sample-war-3/index.jsp @@ -3,5 +3,5 @@ Copyright (c) 2020, Oracle Corporation and/or its affiliates. Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. --%> <% - out.println("How are you doing!, you have reached server " + System.getProperty("weblogic.Name")); + out.println("How are you doing! You have reached server " + System.getProperty("weblogic.Name")); %> From 87451a8c0fb4cad7b2d02260402fa3c90d63abff Mon Sep 17 00:00:00 2001 From: doxiao Date: Fri, 1 May 2020 20:51:45 +0000 Subject: [PATCH 46/69] Adjust timeout values --- .../src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java | 4 ++-- .../kubernetes/actions/impl/primitive/Kubernetes.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java index 0a8f96cc410..20a55568796 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java @@ -161,8 +161,8 @@ public static void initAll(@Namespaces(3) List namespaces) { // create a reusable quick retry policy withQuickRetryPolicy = with().pollDelay(0, SECONDS) - .and().with().pollInterval(2, SECONDS) - .atMost(5, SECONDS).await(); + .and().with().pollInterval(3, SECONDS) + .atMost(7, SECONDS).await(); // get a new unique opNamespace logger.info("Creating unique namespace for Operator"); diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/primitive/Kubernetes.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/primitive/Kubernetes.java index 1530cd7dad0..f9f64ac93fb 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/primitive/Kubernetes.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/primitive/Kubernetes.java @@ -1418,7 +1418,7 @@ public static ExecResult exec(V1Pod pod, String containerName, boolean redirectT if (out != null) { // need to time out here, otherwise the command can take a couple of seconds to return. // don't know if we'll need a different timeout value for different environments. - out.join(1000); + out.join(1500); } // Read data from process's stdout From 31cc7fd29c031fdd1a87d4b46b00a5e043b3969a Mon Sep 17 00:00:00 2001 From: doxiao Date: Fri, 1 May 2020 21:44:23 +0000 Subject: [PATCH 47/69] Fine tuning --- .../java/oracle/weblogic/kubernetes/ItMiiDomain.java | 10 ++++++---- .../kubernetes/assertions/impl/Kubernetes.java | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java index 32c902d89c9..efe2530fad0 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java @@ -626,7 +626,7 @@ public void testPatchAppV2() { if (accountingThread != null) { try { - accountingThread.join(50); + accountingThread.join(1000); } catch (InterruptedException ie) { // do nothing } @@ -1254,16 +1254,18 @@ private static void collectAppAvaiability( String internalPort, String appPath ) { - boolean v2AppAvailable = false; + boolean v2AppAvailable = true; // ping the app periodically to check its availability across the duration // of patching the domain with newer version of the app. do { - v2AppAvailable = appAccessibleInPod( + for (int i = 1; i <= replicaCount; i++) { + v2AppAvailable = v2AppAvailable && appAccessibleInPod( namespace, managedServerPrefix + replicaCount, internalPort, appPath, - APP_RESPONSE_V2 + replicaCount); + APP_RESPONSE_V2 + i); + } int count = 0; for (int i = 1; i <= replicaCount; i++) { diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Kubernetes.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Kubernetes.java index 6fda1e500e0..b0ed8959a23 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Kubernetes.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Kubernetes.java @@ -191,7 +191,7 @@ public static V1Pod getPod(String namespace, String labelSelector, String podNam ); for (V1Pod item : v1PodList.getItems()) { if (item.getMetadata().getName().startsWith(podName.trim())) { - logger.info(String.format("Pod Name :%s, Pod Namespace :%s, Pod UID :%s, Pod Status :%s", + logger.fine(String.format("Pod Name :%s, Pod Namespace :%s, Pod UID :%s, Pod Status :%s", item.getMetadata().getName(), item.getMetadata().getNamespace(), item.getMetadata().getUid(), From 5206a8905a457d4a46b284b7e4d78bff37bb3670 Mon Sep 17 00:00:00 2001 From: doxiao Date: Sat, 2 May 2020 03:29:01 +0000 Subject: [PATCH 48/69] Minor fix --- .../src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java index efe2530fad0..eca4f54beaa 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java @@ -1261,7 +1261,7 @@ private static void collectAppAvaiability( for (int i = 1; i <= replicaCount; i++) { v2AppAvailable = v2AppAvailable && appAccessibleInPod( namespace, - managedServerPrefix + replicaCount, + managedServerPrefix + i, internalPort, appPath, APP_RESPONSE_V2 + i); From ab8ecdfb3362fbd2a507f24da924cd6a3acfe172 Mon Sep 17 00:00:00 2001 From: doxiao Date: Sat, 2 May 2020 07:16:06 +0000 Subject: [PATCH 49/69] Use kubectl exec command for checking app continuous availability --- .../weblogic/kubernetes/ItMiiDomain.java | 25 +++++++---- .../kubernetes/assertions/TestAssertions.java | 24 +++++++++- .../assertions/impl/Application.java | 44 ++++++++++++++++++- .../kubernetes/assertions/impl/Domain.java | 2 +- 4 files changed, 83 insertions(+), 12 deletions(-) diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java index eca4f54beaa..b622c5eeac1 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java @@ -84,6 +84,7 @@ import static oracle.weblogic.kubernetes.actions.TestActions.patchDomainCustomResource; import static oracle.weblogic.kubernetes.actions.TestActions.upgradeOperator; import static oracle.weblogic.kubernetes.assertions.TestAssertions.appAccessibleInPod; +import static oracle.weblogic.kubernetes.assertions.TestAssertions.appAccessibleInPodKubectl; import static oracle.weblogic.kubernetes.assertions.TestAssertions.appNotAccessibleInPod; import static oracle.weblogic.kubernetes.assertions.TestAssertions.doesImageExist; import static oracle.weblogic.kubernetes.assertions.TestAssertions.domainExists; @@ -626,7 +627,7 @@ public void testPatchAppV2() { if (accountingThread != null) { try { - accountingThread.join(1000); + accountingThread.join(); } catch (InterruptedException ie) { // do nothing } @@ -1078,6 +1079,7 @@ private void patchAndVerify( // check and wait for the admin server pod to be patched with the new image checkPodImagePatched( + domainUid, namespace, adminServerPodName, image); @@ -1085,6 +1087,7 @@ private void patchAndVerify( // check and wait for the managed server pods to be patched with the new image for (int i = 1; i <= replicaCount; i++) { checkPodImagePatched( + domainUid, namespace, managedServerPrefix + i, image); @@ -1224,6 +1227,7 @@ private void checkDomainPatched( } private void checkPodImagePatched( + String domainUid, String namespace, String podName, String image @@ -1240,10 +1244,10 @@ private void checkPodImagePatched( condition.getRemainingTimeInMS())) .until(assertDoesNotThrow(() -> podImagePatched(domainUid, namespace, podName, image), String.format( - "Pod od %s is not patched with image %s in namespace %s.", + "Pod %s is not patched with image %s in namespace %s.", podName, - namespace, - image))); + image, + namespace))); } private static void collectAppAvaiability( @@ -1254,12 +1258,17 @@ private static void collectAppAvaiability( String internalPort, String appPath ) { - boolean v2AppAvailable = true; + boolean v2AppAvailable; + // ping the app periodically to check its availability across the duration // of patching the domain with newer version of the app. + // Note: we use the "kubectl exec" command in this method only. This is to avoid + // problems when two threads accessing the same pod at the same time via Kubernetes + // Java client. do { + v2AppAvailable = true; for (int i = 1; i <= replicaCount; i++) { - v2AppAvailable = v2AppAvailable && appAccessibleInPod( + v2AppAvailable = v2AppAvailable && appAccessibleInPodKubectl( namespace, managedServerPrefix + i, internalPort, @@ -1269,7 +1278,7 @@ private static void collectAppAvaiability( int count = 0; for (int i = 1; i <= replicaCount; i++) { - if (appAccessibleInPod( + if (appAccessibleInPodKubectl( namespace, managedServerPrefix + i, internalPort, @@ -1290,7 +1299,7 @@ private static void collectAppAvaiability( logger.info("YYYYYYYYYYY: app available YYYYYYYY count = " + count); } try { - TimeUnit.MILLISECONDS.sleep(50); + TimeUnit.MILLISECONDS.sleep(100); } catch (InterruptedException ie) { // do nothing } diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/TestAssertions.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/TestAssertions.java index 2cdaf9f1482..a37fe69add0 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/TestAssertions.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/TestAssertions.java @@ -207,7 +207,29 @@ public static boolean dockerImageExists(String imageName, String imageTag) { } /** - * Check if an application is accessible inside a WebLogic server pod. + * Check if an application is accessible inside a WebLogic server pod using + * "kubectl exec" command. + * + * @param namespace Kubernetes namespace where the WebLogic server pod is running + * @param podName name of the WebLogic server pod + * @param port internal port of the managed server running in the pod + * @param appPath path to access the application + * @param expectedStr the expected response from the application + * @return true if the command succeeds + */ + public static boolean appAccessibleInPodKubectl( + String namespace, + String podName, + String port, + String appPath, + String expectedStr + ) { + return Application.appAccessibleInPodKubectl(namespace, podName, port, appPath, expectedStr); + } + + /** + * Check if an application is accessible inside a WebLogic server pod using + * Kubernetes Java client API. * * @param namespace Kubernetes namespace where the WebLogic server pod is running * @param podName name of the WebLogic server pod diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Application.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Application.java index 1faf90ab3c2..a3ae061d71e 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Application.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Application.java @@ -6,6 +6,8 @@ import java.io.IOException; import io.kubernetes.client.openapi.ApiException; +import oracle.weblogic.kubernetes.actions.impl.primitive.Command; +import oracle.weblogic.kubernetes.actions.impl.primitive.CommandParams; import oracle.weblogic.kubernetes.logging.LoggingFacade; import oracle.weblogic.kubernetes.logging.LoggingFactory; import oracle.weblogic.kubernetes.utils.ExecResult; @@ -27,6 +29,44 @@ public class Application { * @param podName name of the WebLogic server pod * @param port internal port of the managed server running in the pod * @param appPath path to access the application + * @param expectedResponse expected response from the app + * @return true if the command succeeds + */ + public static boolean appAccessibleInPodKubectl( + String namespace, + String podName, + String port, + String appPath, + String expectedResponse + ) { + + // calling "kubectl exec" command to access the app inside a pod + String cmd = String.format( + "kubectl -n %s exec -it %s -- /bin/bash -c 'curl http://%s:%s/%s'", + namespace, + podName, + podName, + port, + appPath); + + CommandParams params = Command + .defaultCommandParams() + .command(cmd) + .saveResults(true) + .redirect(false) + .verbose(false); + return Command.withParams(params).executeAndVerify(expectedResponse); + } + + /** + * Check if an application is accessible inside a WebLogic server pod using + * Kubernetes Java client. + * + * @param namespace Kubernetes namespace where the WebLogic server pod is running + * @param podName name of the WebLogic server pod + * @param port internal port of the managed server running in the pod + * @param appPath path to access the application + * @param expectedResponse expected response from the app * @return true if the command succeeds */ public static boolean appAccessibleInPod( @@ -34,7 +74,7 @@ public static boolean appAccessibleInPod( String podName, String port, String appPath, - String expectedStr + String expectedResponse ) { // access the application in the given pod @@ -54,7 +94,7 @@ public static boolean appAccessibleInPod( cmd); if (execResult.exitValue() == 0 && execResult.stdout() != null - && execResult.stdout().contains(expectedStr)) { + && execResult.stdout().contains(expectedResponse)) { logger.info( String.format("App is accessible inside pod %s in namespace %s", podName, diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Domain.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Domain.java index ecc9e4637b9..d7fc4609779 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Domain.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Domain.java @@ -78,7 +78,7 @@ public static Callable doesDomainExist(String domainUid, String domainV } /** - * Checks if the domain resource has been patched with a new image. + * Check if the domain resource has been patched with a new image. * * @param domainUID identifier of the domain resource * @param namespace Kubernetes namespace in which the domain exists From 191ea28a650f06521ec87580354839569f556bd0 Mon Sep 17 00:00:00 2001 From: doxiao Date: Sat, 2 May 2020 07:34:34 +0000 Subject: [PATCH 50/69] clean up javadoc --- .../actions/impl/primitive/Kubernetes.java | 4 ++-- .../kubernetes/assertions/TestAssertions.java | 22 +++++++++---------- .../assertions/impl/Kubernetes.java | 2 +- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/primitive/Kubernetes.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/primitive/Kubernetes.java index 697d1768754..cd565d961d3 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/primitive/Kubernetes.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/primitive/Kubernetes.java @@ -1877,8 +1877,8 @@ public static ExecResult exec(V1Pod pod, String containerName, boolean redirectT // wait for reading thread to finish any last remaining output if (out != null) { - // need to time out here, otherwise the command can take a couple of seconds to return. - // don't know if we'll need a different timeout value for different environments. + // need to time out here, otherwise the command can take almost one minute to return. + // yet to see if we'll need a different timeout value for different environments. out.join(1200); } diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/TestAssertions.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/TestAssertions.java index a37fe69add0..6bac0a0365e 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/TestAssertions.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/TestAssertions.java @@ -87,7 +87,7 @@ public static Callable podImagePatched( String image ) throws ApiException { return () -> { - return Kubernetes.isPodImagePatched(namespace, domainUid, podName, image); + return Kubernetes.podImagePatched(namespace, domainUid, podName, image); }; } @@ -187,7 +187,7 @@ public static boolean adminT3ChannelAccessible(String domainUid, String namespac /** * Check if a admin server pod admin node port is accessible. * - * @param domainUid domainUid id of the domain in which admin server pod is running + * @param domainUid id of the domain in which admin server pod is running * @param namespace in which the WebLogic server pod exists * @return true if the admin node port is accessible otherwise false */ @@ -214,7 +214,7 @@ public static boolean dockerImageExists(String imageName, String imageTag) { * @param podName name of the WebLogic server pod * @param port internal port of the managed server running in the pod * @param appPath path to access the application - * @param expectedStr the expected response from the application + * @param expectedResponse the expected response from the application * @return true if the command succeeds */ public static boolean appAccessibleInPodKubectl( @@ -222,9 +222,9 @@ public static boolean appAccessibleInPodKubectl( String podName, String port, String appPath, - String expectedStr + String expectedResponse ) { - return Application.appAccessibleInPodKubectl(namespace, podName, port, appPath, expectedStr); + return Application.appAccessibleInPodKubectl(namespace, podName, port, appPath, expectedResponse); } /** @@ -235,7 +235,7 @@ public static boolean appAccessibleInPodKubectl( * @param podName name of the WebLogic server pod * @param port internal port of the managed server running in the pod * @param appPath path to access the application - * @param expectedStr the expected response from the application + * @param expectedResponse the expected response from the application * @return true if the command succeeds */ public static boolean appAccessibleInPod( @@ -243,9 +243,9 @@ public static boolean appAccessibleInPod( String podName, String port, String appPath, - String expectedStr + String expectedResponse ) { - return Application.appAccessibleInPod(namespace, podName, port, appPath, expectedStr); + return Application.appAccessibleInPod(namespace, podName, port, appPath, expectedResponse); } /** @@ -255,7 +255,7 @@ public static boolean appAccessibleInPod( * @param podName name of the WebLogic server pod * @param port internal port of the managed server running in the pod * @param appPath path to access the application - * @param expectedStr the expected response from the application + * @param expectedResponse the expected response from the application * @return true if the command succeeds */ public static boolean appNotAccessibleInPod( @@ -263,9 +263,9 @@ public static boolean appNotAccessibleInPod( String podName, String port, String appPath, - String expectedStr + String expectedResponse ) { - return !Application.appAccessibleInPod(namespace, podName, port, appPath, expectedStr); + return !Application.appAccessibleInPod(namespace, podName, port, appPath, expectedResponse); } /** diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Kubernetes.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Kubernetes.java index b0ed8959a23..bc9c4b4fb10 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Kubernetes.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Kubernetes.java @@ -122,7 +122,7 @@ public static boolean isPodTerminating(String namespace, String domainUid, Strin * @return true if pod's image has been patched * @throws ApiException when there is an error in querying the Kubernetes cluster */ - public static boolean isPodImagePatched( + public static boolean podImagePatched( String namespace, String domainUid, String podName, From d15f52a885515e5dd87b5ae2dd078305cf071875 Mon Sep 17 00:00:00 2001 From: doxiao Date: Sun, 3 May 2020 14:30:44 +0000 Subject: [PATCH 51/69] Cleanup --- .../test/java/oracle/weblogic/kubernetes/ItMiiDomain.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java index b622c5eeac1..1233c0b1461 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java @@ -632,6 +632,8 @@ public void testPatchAppV2() { // do nothing } + // check the app availability data that we have collected, and see if + // the app has been available all the time since the beginning of this test method assertTrue(appAlwaysAvailable(appAvailability), "App does not always avaiable when the domain is being patched with a newer version of the app."); } @@ -679,7 +681,7 @@ public void testAddSecondApp() { } // create an image with the additional app - miiImageAddSecondApp = updateImageWithApp3( + miiImageAddSecondApp = updateImageWithSampleApp3( String.format("%s-%s", MII_IMAGE_NAME, "test-add-second-app"), Arrays.asList(appDir1, appDir2), Collections.singletonList(appDir3), @@ -837,7 +839,7 @@ private String updateImageWithAppV2Patch( return image; } - private String updateImageWithApp3( + private String updateImageWithSampleApp3( String imageName, List appDirList1, List appDirList2, @@ -1299,7 +1301,7 @@ private static void collectAppAvaiability( logger.info("YYYYYYYYYYY: app available YYYYYYYY count = " + count); } try { - TimeUnit.MILLISECONDS.sleep(100); + TimeUnit.MILLISECONDS.sleep(200); } catch (InterruptedException ie) { // do nothing } From 91718268821b8ff6526d906096e25bbec183499e Mon Sep 17 00:00:00 2001 From: doxiao Date: Mon, 4 May 2020 20:20:48 +0000 Subject: [PATCH 52/69] Minor update --- .../src/test/resources/wdt-models/model2-wls.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/new-integration-tests/src/test/resources/wdt-models/model2-wls.yaml b/new-integration-tests/src/test/resources/wdt-models/model2-wls.yaml index c7b67b3e8c5..e953c861be2 100644 --- a/new-integration-tests/src/test/resources/wdt-models/model2-wls.yaml +++ b/new-integration-tests/src/test/resources/wdt-models/model2-wls.yaml @@ -14,7 +14,7 @@ topology: DynamicServers: ServerTemplate: "cluster-1-template" ServerNamePrefix: "managed-server" - DynamicClusterSize: 2 + DynamicClusterSize: 5 MaxDynamicClusterSize: 5 CalculatedListenPorts: false Server: From bb8af2660c72e38eb737d7b335c30d5bbcbac1b1 Mon Sep 17 00:00:00 2001 From: doxiao Date: Tue, 5 May 2020 20:34:40 +0000 Subject: [PATCH 53/69] Minor update of log messages --- .../weblogic/kubernetes/ItMiiDomain.java | 30 +++++++++---------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java index fa34ce71f9d..33d057228b9 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java @@ -576,7 +576,8 @@ public void testPatchAppV2() { } try { - // check and make sure that V1 app is running + logger.info("Check and make sure that V1 app is still running."); + for (int i = 1; i <= replicaCount; i++) { quickCheckAppRunning( domainNamespace, @@ -596,7 +597,7 @@ public void testPatchAppV2() { APP_RESPONSE_V2 + i); } - // create an image with app V2 + logger.info("Create a new image with app V2."); miiImagePatchAppV2 = updateImageWithAppV2Patch( String.format("%s-%s", MII_IMAGE_NAME, "test-patch-app-v2"), Arrays.asList(appDir1, appDir2)); @@ -604,6 +605,7 @@ public void testPatchAppV2() { // push the image to OCIR to make the test work in multi node cluster pushImageIfNeeded(miiImagePatchAppV2); + logger.info("Patch domain resource with the new image, and verify the results."); // patch the domain resource with the new image and verify that the domain resource is patched, // and all server pods are patched as well. patchAndVerify( @@ -614,7 +616,7 @@ public void testPatchAppV2() { replicaCount, miiImagePatchAppV2); - // check and wait for the V2 app to be ready + logger.info("Check and wait for the V2 app to be ready."); for (int i = 1; i <= replicaCount; i++) { checkAppRunning( domainNamespace, @@ -631,9 +633,10 @@ public void testPatchAppV2() { } catch (InterruptedException ie) { // do nothing } - + // check the app availability data that we have collected, and see if // the app has been available all the time since the beginning of this test method + logger.info("Verify that the app was available in the duration when app was being patched."); assertTrue(appAlwaysAvailable(appAvailability), "App does not always avaiable when the domain is being patched with a newer version of the app."); } @@ -658,7 +661,7 @@ public void testAddSecondApp() { final String managedServerPrefix = domainUid + "-managed-server"; final int replicaCount = 2; - // check and V2 app is still running after the previous test + logger.info("Check V2 app is still running after the previous test."); for (int i = 1; i <= replicaCount; i++) { quickCheckAppRunning( domainNamespace, @@ -668,9 +671,7 @@ public void testAddSecondApp() { APP_RESPONSE_V2 + i); } - logger.info("App version 2 is still running"); - - // check and make sure that the new app is NOT already running + logger.info("Check and make sure that the new app is NOT already running."); for (int i = 1; i <= replicaCount; i++) { quickCheckAppNotRunning( domainNamespace, @@ -680,22 +681,19 @@ public void testAddSecondApp() { APP_RESPONSE_V3 + i); } - // create an image with the additional app + logger.info("Create a new image that contains the additional app."); miiImageAddSecondApp = updateImageWithSampleApp3( String.format("%s-%s", MII_IMAGE_NAME, "test-add-second-app"), Arrays.asList(appDir1, appDir2), Collections.singletonList(appDir3), "model2-wls.yaml"); - logger.info("Image is successfully created"); - // push the image to OCIR to make the test work in multi node cluster pushImageIfNeeded(miiImageAddSecondApp); - logger.info("About to patch the domain with new image"); - // patch the domain resource with the new image and verify that the domain resource is patched, // and all server pods are patched as well. + logger.info("Patch the domain with the new image, and verify the results"); patchAndVerify( domainUid, domainNamespace, @@ -704,7 +702,7 @@ public void testAddSecondApp() { replicaCount, miiImageAddSecondApp); - // check and wait for the new app to be ready + logger.info("Check and wait for the new app to become ready."); for (int i = 1; i <= replicaCount; i++) { checkAppRunning( domainNamespace, @@ -714,7 +712,7 @@ public void testAddSecondApp() { APP_RESPONSE_V3 + i); } - // check and wait for the V2 app to be ready + logger.info("Check and wait for the original app V2 to become ready."); for (int i = 1; i <= replicaCount; i++) { checkAppRunning( domainNamespace, @@ -724,7 +722,7 @@ public void testAddSecondApp() { APP_RESPONSE_V2 + i); } - logger.info("The cluster has been rolling started, and the two applications are both running correctly."); + logger.info("The cluster has been rolling restarted, and the two applications are both running correctly."); } // This method is needed in this test class, since the cleanup util From f1c30255fa251e2db6646acc4c8af541102ca1f2 Mon Sep 17 00:00:00 2001 From: doxiao Date: Tue, 5 May 2020 21:12:46 +0000 Subject: [PATCH 54/69] More cleanup of log messages and comments --- .../weblogic/kubernetes/ItMiiDomain.java | 31 +++++++++---------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java index 33d057228b9..c67e53031df 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java @@ -576,8 +576,7 @@ public void testPatchAppV2() { } try { - logger.info("Check and make sure that V1 app is still running."); - + logger.info("Check and make sure that V1 app is still running"); for (int i = 1; i <= replicaCount; i++) { quickCheckAppRunning( domainNamespace, @@ -587,7 +586,7 @@ public void testPatchAppV2() { APP_RESPONSE_V1 + i); } - // check and make sure that the version 2 app is NOT running + logger.info("Check and make sure that the version 2 app is NOT running"); for (int i = 1; i <= replicaCount; i++) { quickCheckAppNotRunning( domainNamespace, @@ -597,7 +596,7 @@ public void testPatchAppV2() { APP_RESPONSE_V2 + i); } - logger.info("Create a new image with app V2."); + logger.info("Create a new image with app V2"); miiImagePatchAppV2 = updateImageWithAppV2Patch( String.format("%s-%s", MII_IMAGE_NAME, "test-patch-app-v2"), Arrays.asList(appDir1, appDir2)); @@ -605,9 +604,9 @@ public void testPatchAppV2() { // push the image to OCIR to make the test work in multi node cluster pushImageIfNeeded(miiImagePatchAppV2); - logger.info("Patch domain resource with the new image, and verify the results."); // patch the domain resource with the new image and verify that the domain resource is patched, // and all server pods are patched as well. + logger.info("Patch domain resource with the new image, and verify the results"); patchAndVerify( domainUid, domainNamespace, @@ -616,7 +615,7 @@ public void testPatchAppV2() { replicaCount, miiImagePatchAppV2); - logger.info("Check and wait for the V2 app to be ready."); + logger.info("Check and wait for the V2 app to be ready"); for (int i = 1; i <= replicaCount; i++) { checkAppRunning( domainNamespace, @@ -636,13 +635,13 @@ public void testPatchAppV2() { // check the app availability data that we have collected, and see if // the app has been available all the time since the beginning of this test method - logger.info("Verify that the app was available in the duration when app was being patched."); + logger.info("Verify that the app was available in the duration when app was being patched"); assertTrue(appAlwaysAvailable(appAvailability), - "App does not always avaiable when the domain is being patched with a newer version of the app."); + "App does not always avaiable when the domain is being patched with a newer version of the app"); } } - logger.info("The cluster has been rolling restarted, and the version 2 app has been deployed correctly."); + logger.info("The cluster has been rolling restarted, and the version 2 app has been deployed correctly"); } @Test @@ -661,7 +660,7 @@ public void testAddSecondApp() { final String managedServerPrefix = domainUid + "-managed-server"; final int replicaCount = 2; - logger.info("Check V2 app is still running after the previous test."); + logger.info("Check V2 app is still running after the previous test"); for (int i = 1; i <= replicaCount; i++) { quickCheckAppRunning( domainNamespace, @@ -671,7 +670,7 @@ public void testAddSecondApp() { APP_RESPONSE_V2 + i); } - logger.info("Check and make sure that the new app is NOT already running."); + logger.info("Check and make sure that the new app is NOT already running"); for (int i = 1; i <= replicaCount; i++) { quickCheckAppNotRunning( domainNamespace, @@ -681,7 +680,7 @@ public void testAddSecondApp() { APP_RESPONSE_V3 + i); } - logger.info("Create a new image that contains the additional app."); + logger.info("Create a new image that contains the additional app"); miiImageAddSecondApp = updateImageWithSampleApp3( String.format("%s-%s", MII_IMAGE_NAME, "test-add-second-app"), Arrays.asList(appDir1, appDir2), @@ -693,7 +692,7 @@ public void testAddSecondApp() { // patch the domain resource with the new image and verify that the domain resource is patched, // and all server pods are patched as well. - logger.info("Patch the domain with the new image, and verify the results"); + logger.info("Patch the domain with the new image, and verify the result"); patchAndVerify( domainUid, domainNamespace, @@ -702,7 +701,7 @@ public void testAddSecondApp() { replicaCount, miiImageAddSecondApp); - logger.info("Check and wait for the new app to become ready."); + logger.info("Check and wait for the new app to become ready"); for (int i = 1; i <= replicaCount; i++) { checkAppRunning( domainNamespace, @@ -712,7 +711,7 @@ public void testAddSecondApp() { APP_RESPONSE_V3 + i); } - logger.info("Check and wait for the original app V2 to become ready."); + logger.info("Check and wait for the original app V2 to become ready"); for (int i = 1; i <= replicaCount; i++) { checkAppRunning( domainNamespace, @@ -722,7 +721,7 @@ public void testAddSecondApp() { APP_RESPONSE_V2 + i); } - logger.info("The cluster has been rolling restarted, and the two applications are both running correctly."); + logger.info("The cluster has been rolling restarted, and the two applications are both running correctly"); } // This method is needed in this test class, since the cleanup util From d735a7e0e268ec0ecfabf6c4e6e0a889e50b8757 Mon Sep 17 00:00:00 2001 From: doxiao Date: Wed, 6 May 2020 18:17:39 +0000 Subject: [PATCH 55/69] Address review comments --- .../weblogic/kubernetes/ItMiiDomain.java | 247 +++++++++--------- .../kubernetes/actions/TestActions.java | 6 +- .../kubernetes/actions/impl/AppParams.java | 4 +- .../actions/impl/primitive/Command.java | 2 +- .../kubernetes/assertions/TestAssertions.java | 3 +- .../kubernetes/assertions/impl/Domain.java | 2 +- .../assertions/impl/Kubernetes.java | 8 +- .../weblogic/kubernetes/utils/FileUtils.java | 9 +- 8 files changed, 149 insertions(+), 132 deletions(-) diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java index c67e53031df..2f7029dedb3 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java @@ -120,7 +120,7 @@ class ItMiiDomain implements LoggedTest { private static final String DOMAIN_VERSION = "v7"; private static final String API_VERSION = "weblogic.oracle/" + DOMAIN_VERSION; - // app constants + // application constants private static final String APP_RESPONSE_V1 = "Hello World, you have reached server managed-server"; private static final String APP_RESPONSE_V2 = "Hello World AGAIN, you have reached server managed-server"; private static final String APP_RESPONSE_V3 = "How are you doing! You have reached server managed-server"; @@ -162,6 +162,14 @@ public static void initAll(@Namespaces(3) List namespaces) { .and().with().pollInterval(4, SECONDS) .atMost(10, SECONDS).await(); + // clean up the download directory so that we always get the latest + // versions of the tools in every run of the test class. + try { + cleanupDirectory(DOWNLOAD_DIR); + } catch (IOException | RuntimeException e) { + logger.severe("Failed to cleanup the download directory " + DOWNLOAD_DIR, e); + } + // get a new unique opNamespace logger.info("Creating unique namespace for Operator"); assertNotNull(namespaces.get(0), "Namespace list is null"); @@ -267,7 +275,7 @@ public void testCreateMiiDomain() { // create image with model files miiImage = createInitialDomainImage(); - // push the image to OCIR to make the test work in multi node cluster + // push the image to a registry to make the test work in multi node cluster pushImageIfNeeded(miiImage); // Create the repo secret to pull the image @@ -343,7 +351,7 @@ public void testCreateMiiDomain() { checkServiceCreated(managedServerPrefix + i, domainNamespace); } - // check and wait for the app to be accessible in all server pods + // check and wait for the application to be accessible in all server pods for (int i = 1; i <= replicaCount; i++) { checkAppRunning( domainNamespace, @@ -353,8 +361,8 @@ public void testCreateMiiDomain() { APP_RESPONSE_V1 + i); } - logger.info(String.format("Domain %s is fully started - servers are running and application is deployed corretly.", - domainUid)); + logger.info("Domain {0} is fully started - servers are running and application is available", + domainUid); } @Test @@ -541,15 +549,15 @@ public void testCreateMiiDomainSameDomainUidDiffNS() { @MustNotRunInParallel public void testPatchAppV2() { - // app in the new image contains what is in the original app dir sample-app, - // plus the replacements or/and additions in the second app dir sample-app-2. + // application in the new image contains what is in the original application directory sample-app, + // plus the replacements or/and additions in the second application directory sample-app-2. final String appDir1 = "sample-app"; final String appDir2 = "sample-app-2"; final String adminServerPodName = domainUid + "-admin-server"; final String managedServerPrefix = domainUid + "-managed-server"; final int replicaCount = 2; - // The verification of app's continuous availability during patching is turned off + // The verification of application's availability during patching is turned off // because it fails intermittently right now. It can be enabled using the following system property. // We'll remove the property and enable it all the time once the product problem (tracked // by owls-81575) is fixed. @@ -559,7 +567,7 @@ public void testPatchAppV2() { List appAvailability = new ArrayList(); if (enableAppAvailbilityCheck.equalsIgnoreCase("true")) { - // start a new thread to collect the availability data of the app while the + // start a new thread to collect the availability data of the application while the // main thread performs patching operation, and checking of the results. accountingThread = new Thread( @@ -576,7 +584,7 @@ public void testPatchAppV2() { } try { - logger.info("Check and make sure that V1 app is still running"); + logger.info("Check that V1 application is still running"); for (int i = 1; i <= replicaCount; i++) { quickCheckAppRunning( domainNamespace, @@ -586,7 +594,7 @@ public void testPatchAppV2() { APP_RESPONSE_V1 + i); } - logger.info("Check and make sure that the version 2 app is NOT running"); + logger.info("Check that the version 2 application is NOT running"); for (int i = 1; i <= replicaCount; i++) { quickCheckAppNotRunning( domainNamespace, @@ -596,12 +604,12 @@ public void testPatchAppV2() { APP_RESPONSE_V2 + i); } - logger.info("Create a new image with app V2"); + logger.info("Create a new image with application V2"); miiImagePatchAppV2 = updateImageWithAppV2Patch( String.format("%s-%s", MII_IMAGE_NAME, "test-patch-app-v2"), Arrays.asList(appDir1, appDir2)); - // push the image to OCIR to make the test work in multi node cluster + // push the image to a registry to make the test work in multi node cluster pushImageIfNeeded(miiImagePatchAppV2); // patch the domain resource with the new image and verify that the domain resource is patched, @@ -615,7 +623,7 @@ public void testPatchAppV2() { replicaCount, miiImagePatchAppV2); - logger.info("Check and wait for the V2 app to be ready"); + logger.info("Check and wait for the V2 application to become available"); for (int i = 1; i <= replicaCount; i++) { checkAppRunning( domainNamespace, @@ -633,15 +641,17 @@ public void testPatchAppV2() { // do nothing } - // check the app availability data that we have collected, and see if - // the app has been available all the time since the beginning of this test method - logger.info("Verify that the app was available in the duration when app was being patched"); + // check the application availability data that we have collected, and see if + // the application has been available all the time since the beginning of this test method + logger.info("Verify that V2 application was available when domain {0} was being patched with image {1}", + domainUid, miiImagePatchAppV2); assertTrue(appAlwaysAvailable(appAvailability), - "App does not always avaiable when the domain is being patched with a newer version of the app"); + String.format("Application V2 was not always available when domain %s was being patched with image %s", + domainUid, miiImagePatchAppV2)); } } - logger.info("The cluster has been rolling restarted, and the version 2 app has been deployed correctly"); + logger.info("The version 2 application has been deployed correctly on all server Pods"); } @Test @@ -651,8 +661,8 @@ public void testPatchAppV2() { @MustNotRunInParallel public void testAddSecondApp() { - // the existing app is the combination of what are in appDir1 and appDir2 as in test case number 4, - // the second app is in appDir3. + // the existing application is the combination of what are in appDir1 and appDir2 as in test case number 4, + // the second application is in appDir3. final String appDir1 = "sample-app"; final String appDir2 = "sample-app-2"; final String appDir3 = "sample-app-3"; @@ -660,7 +670,7 @@ public void testAddSecondApp() { final String managedServerPrefix = domainUid + "-managed-server"; final int replicaCount = 2; - logger.info("Check V2 app is still running after the previous test"); + logger.info("Check V2 application is still running after the previous test"); for (int i = 1; i <= replicaCount; i++) { quickCheckAppRunning( domainNamespace, @@ -670,7 +680,7 @@ public void testAddSecondApp() { APP_RESPONSE_V2 + i); } - logger.info("Check and make sure that the new app is NOT already running"); + logger.info("Check that the new application is NOT already running"); for (int i = 1; i <= replicaCount; i++) { quickCheckAppNotRunning( domainNamespace, @@ -680,14 +690,14 @@ public void testAddSecondApp() { APP_RESPONSE_V3 + i); } - logger.info("Create a new image that contains the additional app"); + logger.info("Create a new image that contains the additional application"); miiImageAddSecondApp = updateImageWithSampleApp3( String.format("%s-%s", MII_IMAGE_NAME, "test-add-second-app"), Arrays.asList(appDir1, appDir2), Collections.singletonList(appDir3), "model2-wls.yaml"); - // push the image to OCIR to make the test work in multi node cluster + // push the image to a registry to make the test work in multi node cluster pushImageIfNeeded(miiImageAddSecondApp); // patch the domain resource with the new image and verify that the domain resource is patched, @@ -701,7 +711,7 @@ public void testAddSecondApp() { replicaCount, miiImageAddSecondApp); - logger.info("Check and wait for the new app to become ready"); + logger.info("Check and wait for the new application to become ready"); for (int i = 1; i <= replicaCount; i++) { checkAppRunning( domainNamespace, @@ -711,7 +721,7 @@ public void testAddSecondApp() { APP_RESPONSE_V3 + i); } - logger.info("Check and wait for the original app V2 to become ready"); + logger.info("Check and wait for the original application V2 to become ready"); for (int i = 1; i <= replicaCount; i++) { checkAppRunning( domainNamespace, @@ -721,7 +731,7 @@ public void testAddSecondApp() { APP_RESPONSE_V2 + i); } - logger.info("The cluster has been rolling restarted, and the two applications are both running correctly"); + logger.info("Both of the applications are running correctly after patching"); } // This method is needed in this test class, since the cleanup util @@ -755,36 +765,32 @@ public void tearDownAll() { if (miiImageAddSecondApp != null) { deleteImage(miiImageAddSecondApp); } - - // clean up the download directory so that we always get the latest - // versions of the tools in every run of the test class. - try { - cleanupDirectory(DOWNLOAD_DIR); - } catch (IOException | RuntimeException e) { - logger.severe("Failed to cleanup the download directory " + DOWNLOAD_DIR + " ready", e); - } } private void pushImageIfNeeded(String image) { - // push the image to OCIR to make the test work in multi node cluster + // push the image to a registry to make the test work in multi node cluster if (!REPO_USERNAME.equals(REPO_DUMMY_VALUE)) { - logger.info("docker login"); + logger.info("docker login to registry {0}", REPO_REGISTRY); assertTrue(dockerLogin(REPO_REGISTRY, REPO_USERNAME, REPO_PASSWORD), "docker login failed"); - logger.info("docker push image {0} to OCIR", image); + logger.info("docker push image {0} to registry {1}", image, REPO_REGISTRY); assertTrue(dockerPush(image), String.format("docker push failed for image %s", image)); } } - private String createInitialDomainImage() { + private String createUniqueImageTag() { // create unique image name with date DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); Date date = new Date(); - final String imageTag = dateFormat.format(date) + "-" + System.currentTimeMillis(); + return dateFormat.format(date) + "-" + System.currentTimeMillis(); + } + + private String createImageName(String baseImageName) { // Add repository name in image name for Jenkins runs - final String imageName = REPO_USERNAME.equals(REPO_DUMMY_VALUE) ? MII_IMAGE_NAME : REPO_NAME + MII_IMAGE_NAME; - final String image = imageName + ":" + imageTag; + return REPO_USERNAME.equals(REPO_DUMMY_VALUE) ? baseImageName : REPO_NAME + baseImageName; + } + private String createInitialDomainImage() { // build the model file list final List modelList = Collections.singletonList(String.format("%s/%s", MODEL_DIR, WDT_MODEL_FILE)); @@ -792,28 +798,23 @@ private String createInitialDomainImage() { // build an application archive using what is in resources/apps/APP_NAME assertTrue(buildAppArchive(defaultAppParams() .srcDirList(Collections.singletonList(APP_NAME))), - String.format("Failed to create app archive for %s", APP_NAME)); + String.format("Failed to create application archive for %s", APP_NAME)); // build the archive list List archiveList = Collections.singletonList(String.format("%s/%s.zip", ARCHIVE_DIR, APP_NAME)); - createImageAndVerify(imageName, imageTag, modelList, archiveList); - - return image; + return createImageAndVerify( + createImageName(MII_IMAGE_NAME), + createUniqueImageTag(), + modelList, + archiveList); } private String updateImageWithAppV2Patch( - String imageName, + String baseImageName, List appDirList ) { - DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); - Date date = new Date(); - final String imageTag = dateFormat.format(date) + "-" + System.currentTimeMillis(); - // Add repository name in image name for Jenkins runs - final String imageNameReal = REPO_USERNAME.equals(REPO_DUMMY_VALUE) ? imageName : REPO_NAME + imageName; - String image = String.format("%s:%s", imageNameReal, imageTag); - // build the model file list List modelList = Collections.singletonList(String.format("%s/%s", MODEL_DIR, WDT_MODEL_FILE)); @@ -823,7 +824,7 @@ private String updateImageWithAppV2Patch( buildAppArchive( defaultAppParams() .srcDirList(appDirList)), - String.format("Failed to create app archive for %s", + String.format("Failed to create application archive for %s", APP_NAME)); // build the archive list @@ -831,60 +832,57 @@ private String updateImageWithAppV2Patch( Collections.singletonList( String.format("%s/%s.zip", ARCHIVE_DIR, APP_NAME)); - createImageAndVerify(imageNameReal, imageTag, modelList, archiveList); - - return image; + return createImageAndVerify( + createImageName(baseImageName), + createUniqueImageTag(), + modelList, + archiveList); } private String updateImageWithSampleApp3( - String imageName, + String baseImageName, List appDirList1, List appDirList2, String modelFile ) { - DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); - Date date = new Date(); - final String imageTag = dateFormat.format(date) + "-" + System.currentTimeMillis(); - // Add repository name in image name for Jenkins runs - final String imageNameReal = REPO_USERNAME.equals(REPO_DUMMY_VALUE) ? imageName : REPO_NAME + imageName; - String image = String.format("%s:%s", imageNameReal, imageTag); - // build the model file list List modelList = Collections.singletonList(MODEL_DIR + "/" + modelFile); String appName1 = appDirList1.get(0); String appName2 = appDirList2.get(0); - // build an application archive that contains the existing app + // build an application archive that contains the existing application artifacts assertTrue( buildAppArchive( defaultAppParams() .srcDirList(appDirList1) .appName(appName1)), - String.format("Failed to create app archive for %s", + String.format("Failed to create application archive for %s", appName1)); - logger.info("Successfully created app zip file: " + appName1); + logger.info("Successfully created application zip file: " + appName1); - // build an application archive that contains the new app + // build an application archive that contains the new application artifacts assertTrue( buildAppArchive( defaultAppParams() .srcDirList(appDirList2) .appName(appName2)), - String.format("Failed to create app archive for %s", + String.format("Failed to create application archive for %s", appName2)); - logger.info("Successfully cteated app zip file: " + appName2); + logger.info("Successfully cteated application zip file: " + appName2); // build the archive list with two zip files List archiveList = Arrays.asList( String.format("%s/%s.zip", ARCHIVE_DIR, appName1), String.format("%s/%s.zip", ARCHIVE_DIR, appName2)); - createImageAndVerify(imageNameReal, imageTag, modelList, archiveList); - - return image; + return createImageAndVerify( + createImageName(baseImageName), + createUniqueImageTag(), + modelList, + archiveList); } /** @@ -894,35 +892,37 @@ private String updateImageWithSampleApp3( * {"op": "replace", "path": "/spec/image", "value": "mii-image:v2" } * ] * - * @param domainUid unique identifier of the domain resource + * @param domainResourceName name of the domain resource * @param namespace Kubernetes namespace that the domain is hosted * @param image name of the new image */ - private void patchDomainResourceIamge( - String domainUid, + private void patchDomainResourceImage( + String domainResourceName, String namespace, String image ) { String patch = String.format("[\n {\"op\": \"replace\", \"path\": \"/spec/image\", \"value\": \"%s\"}\n]\n", image); - logger.info("About to patch the domain resource with:\n" + patch); + logger.info("About to patch the domain resource {0} in namespace {1} with:{2}\n", + domainResourceName, namespace, patch); assertTrue(patchDomainCustomResource( - domainUid, + domainResourceName, namespace, new V1Patch(patch), V1Patch.PATCH_FORMAT_JSON_PATCH), - "Failed to patch the domain resource with a a different image."); + String.format("Failed to patch the domain resource {0} in namespace {1} with image {2}", + domainResourceName, namespace, image)); } - private void createImageAndVerify( + private String createImageAndVerify( String imageName, String imageTag, List modelList, List archiveList ) { - final String image = imageName + ":" + imageTag; + final String image = String.format("%s:%s", imageName, imageTag); // Set additional environment variables for WIT checkDirectory(WIT_BUILD_DIR); @@ -952,6 +952,8 @@ private void createImageAndVerify( */ assertTrue(doesImageExist(imageTag), String.format("Image %s doesn't exist", image)); + + return image; } private void createRepoSecret(String domNamespace) throws ApiException { @@ -1071,13 +1073,22 @@ private void patchAndVerify( final int replicaCount, final String image ) { - // modify the domain resource to use the new image - patchDomainResourceIamge(domainUid, namespace, image); + logger.info( + "Patch the domain resource {0} in namespace {1} to use the new image {2}", + domainUid, namespace, image); + + patchDomainResourceImage(domainUid, namespace, image); - // check if domain resource has been patched with the new image + logger.info( + "Check that domain resource {0} in namespace {1} has been patched with image {2}", + domainUid, namespace, image); checkDomainPatched(domainUid, namespace, image); // check and wait for the admin server pod to be patched with the new image + logger.info( + "Check that admin server pod for domain resource {0} in namespace {1} has been patched with image {2}", + domainUid, namespace, image); + checkPodImagePatched( domainUid, namespace, @@ -1085,6 +1096,9 @@ private void patchAndVerify( image); // check and wait for the managed server pods to be patched with the new image + logger.info( + "Check that server pods for domain resource {0} in namespace {1} have been patched with image {2}", + domainUid, namespace, image); for (int i = 1; i <= replicaCount; i++) { checkPodImagePatched( domainUid, @@ -1133,23 +1147,8 @@ private void checkAppRunning( String expectedStr ) { - // check if the app is accessible inside of a server pod - withStandardRetryPolicy - .conditionEvaluationListener( - condition -> logger.info("Waiting for application {0} to be ready on {1} in namespace {2} " - + "(elapsed time {3}ms, remaining time {4}ms)", - appPath, - podName, - namespace, - condition.getElapsedTimeInMS(), - condition.getRemainingTimeInMS())) - .until(() -> appAccessibleInPod( - namespace, - podName, - internalPort, - appPath, - expectedStr)); - + // check if the application is accessible inside of a server pod using standard retry policy + checkAppIsRunning(withStandardRetryPolicy, namespace, podName, internalPort, appPath, expectedStr); } private void quickCheckAppRunning( @@ -1159,11 +1158,23 @@ private void quickCheckAppRunning( String appPath, String expectedStr ) { + // check if the application is accessible inside of a server pod using quick retry policy + checkAppIsRunning(withQuickRetryPolicy, namespace, podName, internalPort, appPath, expectedStr); + } + + private void checkAppIsRunning( + ConditionFactory conditionFactory, + String namespace, + String podName, + String internalPort, + String appPath, + String expectedStr + ) { - // check if the app is accessible inside of a server pod - withQuickRetryPolicy + // check if the application is accessible inside of a server pod + conditionFactory .conditionEvaluationListener( - condition -> logger.info("Checking if application {0} is running on pod {1} in namespace {2} " + condition -> logger.info("Waiting for application {0} is running on pod {1} in namespace {2} " + "(elapsed time {3}ms, remaining time {4}ms)", appPath, podName, @@ -1187,7 +1198,7 @@ private void quickCheckAppNotRunning( String expectedStr ) { - // check if the app is not running inside of a server pod + // check if the application is not running inside of a server pod withQuickRetryPolicy .conditionEvaluationListener( condition -> logger.info("Checking if application {0} is not running on pod {1} in namespace {2} " @@ -1242,7 +1253,7 @@ private void checkPodImagePatched( namespace, condition.getElapsedTimeInMS(), condition.getRemainingTimeInMS())) - .until(assertDoesNotThrow(() -> podImagePatched(domainUid, namespace, podName, image), + .until(assertDoesNotThrow(() -> podImagePatched(domainUid, namespace, podName, "weblogic-server", image), String.format( "Pod %s is not patched with image %s in namespace %s.", podName, @@ -1258,14 +1269,14 @@ private static void collectAppAvaiability( String internalPort, String appPath ) { - boolean v2AppAvailable; + boolean v2AppAvailable = false; - // ping the app periodically to check its availability across the duration - // of patching the domain with newer version of the app. + // Access the pod periodically to check application's availability across the duration + // of patching the domain with newer version of the application. // Note: we use the "kubectl exec" command in this method only. This is to avoid // problems when two threads accessing the same pod at the same time via Kubernetes // Java client. - do { + while (!v2AppAvailable) { v2AppAvailable = true; for (int i = 1; i <= replicaCount; i++) { v2AppAvailable = v2AppAvailable && appAccessibleInPodKubectl( @@ -1294,22 +1305,22 @@ private static void collectAppAvaiability( // -Dweblogic.operator.enableAppAvailabilityCheck=true. // TODO remove these log messages when this verification is fully enabled. if (count == 0) { - logger.info("XXXXXXXXXXX: app not available XXXXXXXX"); + logger.info("XXXXXXXXXXX: application not available XXXXXXXX"); } else { - logger.info("YYYYYYYYYYY: app available YYYYYYYY count = " + count); + logger.info("YYYYYYYYYYY: application available YYYYYYYY count = " + count); } try { TimeUnit.MILLISECONDS.sleep(200); } catch (InterruptedException ie) { // do nothing } - } while (!v2AppAvailable); + } } private static boolean appAlwaysAvailable(List appAvailability) { for (Integer count: appAvailability) { if (count == 0) { - logger.warning("App was not continuously available during patching."); + logger.warning("Application was not available during patching."); return false; } } @@ -1324,7 +1335,7 @@ private void checkServerReadyStatusByExec(String podName, String namespace) { assertEquals("RUNNING", execResult.stdout(), "Expected " + podName + ", in namespace " + namespace + ", to be in RUNNING ready status"); } else { - fail("Ready command failed with exit status code: " + execResult.exitValue()); + fail("Read state command failed with exit status code: " + execResult.exitValue()); } } } diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/TestActions.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/TestActions.java index a714cf526cd..0207b919d28 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/TestActions.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/TestActions.java @@ -538,10 +538,10 @@ public static JsonObject createDockerConfigJson(String username, String password // ----------------------- Execute a Command --------------------------- /** - * Execute a command in a container. + * Execute a command in a container of a Kubernetes pod. * * @param namespace The Kubernertes namespace that the pod is in - * @param podName The name of the pod where the command is to be run + * @param podName The name of the Kubernetes pod where the command is expected to run * @param containerName The container in the Pod where the command is to be run. If no * container name is provided than the first container in the Pod is used. * @param redirectToStdout copy process output to stdout @@ -558,6 +558,8 @@ public static ExecResult execCommand( boolean redirectToStdout, String... command ) throws IOException, ApiException, InterruptedException { + // get the pod given the namespace and name of the pod + // no label selector is needed (thus null below) final V1Pod pod = oracle.weblogic.kubernetes.assertions.impl.Kubernetes .getPod(namespace, null, podName); if (pod == null) { diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/AppParams.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/AppParams.java index e0be97a4c7f..621758093d7 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/AppParams.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/AppParams.java @@ -12,11 +12,11 @@ public class AppParams { // A list of directories under resources/apps that are part of the application. - // Note: the order of the directory names are significant. Files are copied into + // Note: the order of the directory names is significant. Files are copied into // the staging directory in this order. private List srcDirList; - // The name of the final ear file. + // The name of the final archive file. // The name of the first dir in srcDirList will be used if the appName is absent. private String appName; diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/primitive/Command.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/primitive/Command.java index 1f125c29bdb..de66cde1854 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/primitive/Command.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/primitive/Command.java @@ -73,7 +73,7 @@ public boolean execute() { /** * Execute a command and verify the response. * - * @params expectedResponse the expected response to verify + * @param expectedResponse the expected response to verify * @return true if the execution succeeded and response contains the expected value */ public boolean executeAndVerify(String expectedResponse) { diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/TestAssertions.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/TestAssertions.java index cab7358e8eb..1a9d3a47b3f 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/TestAssertions.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/TestAssertions.java @@ -84,10 +84,11 @@ public static Callable podImagePatched( String domainUid, String namespace, String podName, + String containerName, String image ) throws ApiException { return () -> { - return Kubernetes.podImagePatched(namespace, domainUid, podName, image); + return Kubernetes.podImagePatched(namespace, domainUid, podName, containerName, image); }; } diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Domain.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Domain.java index d7fc4609779..f3e2a4fa304 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Domain.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Domain.java @@ -82,7 +82,7 @@ public static Callable doesDomainExist(String domainUid, String domainV * * @param domainUID identifier of the domain resource * @param namespace Kubernetes namespace in which the domain exists - * @param image name of the image that the pod is supposed to use + * @param image name of the image that the pod is expected to be using * @return true if domain resource's image matches the expected value */ public static Callable domainResourceImagePatched( diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Kubernetes.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Kubernetes.java index 8c6967c7c4d..6cb9ed25881 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Kubernetes.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Kubernetes.java @@ -153,6 +153,7 @@ public static boolean isPodTerminating(String namespace, String domainUid, Strin * @param namespace Kubernetes namespace in which the pod is running * @param domainUid label that the pod is decorated with * @param podName name of the WebLogic server pod + * @param containerName name of the container * @param image name of the image to check for * @return true if pod's image has been patched * @throws ApiException when there is an error in querying the Kubernetes cluster @@ -161,6 +162,7 @@ public static boolean podImagePatched( String namespace, String domainUid, String podName, + String containerName, String image ) throws ApiException { boolean podPatched = false; @@ -172,8 +174,8 @@ public static boolean podImagePatched( if (pod != null && pod.getSpec() != null) { List containers = pod.getSpec().getContainers(); for (V1Container container : containers) { - // look for the weblogic server container - if (container.getName().equals("weblogic-server") + // look for the container + if (container.getName().equals(containerName) && (container.getImage().equals(image))) { podPatched = true; } @@ -234,7 +236,7 @@ public static V1Pod getPod(String namespace, String labelSelector, String podNam ); for (V1Pod item : v1PodList.getItems()) { if (item.getMetadata().getName().startsWith(podName.trim())) { - logger.fine(String.format("Pod Name :%s, Pod Namespace :%s, Pod UID :%s, Pod Status :%s", + logger.fine(String.format("Pod Name: %s, Pod Namespace: %s, Pod UID: %s, Pod Status: %s", item.getMetadata().getName(), item.getMetadata().getNamespace(), item.getMetadata().getUid(), diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/utils/FileUtils.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/utils/FileUtils.java index 6aef84c781a..2e45ebc3fce 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/utils/FileUtils.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/utils/FileUtils.java @@ -35,7 +35,7 @@ public static void checkDirectory(String dir) { File file = new File(dir); if (!(file.exists() && file.isDirectory())) { file.mkdirs(); - logger.fine("Made a new dir {0}.", dir); + logger.fine("Made a new directory {0}.", dir); } } @@ -74,7 +74,7 @@ public static boolean doesFileExist(String fileName) { */ public static void cleanupDirectory(String dir) throws IOException { File file = new File(dir); - logger.fine("Cleaning up directory {0}.", dir); + logger.info("Cleaning up directory {0}.", dir); if (!file.exists()) { // nothing to do return; @@ -102,9 +102,10 @@ public static void copyFolder(String srcDir, String destDir) throws IOException try { copy(source, destPath.resolve(srcPath.relativize(source))); } catch (IOException e) { - logger.severe(String.format("Failed to copy file %s", source), e); + String msg = String.format("Failed to copy file %s to %s", source, destDir); + logger.severe(msg, e); // cannot throw non runtime exception. the caller checks throwable - throw new RuntimeException("Failed to copy file " + source); + throw new RuntimeException(msg); } }); } From 072aa1f16708bf5c6b7b8cf7d980b5cfce9c7760 Mon Sep 17 00:00:00 2001 From: doxiao Date: Wed, 6 May 2020 19:21:56 +0000 Subject: [PATCH 56/69] Address one more comment --- .../src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java index 2f7029dedb3..49b4d7d0ce3 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java @@ -166,7 +166,7 @@ public static void initAll(@Namespaces(3) List namespaces) { // versions of the tools in every run of the test class. try { cleanupDirectory(DOWNLOAD_DIR); - } catch (IOException | RuntimeException e) { + } catch (IOException | IllegalArgumentException e) { logger.severe("Failed to cleanup the download directory " + DOWNLOAD_DIR, e); } From 3003cd59b6cd0a216ea31f5ddf8775368dbd2be6 Mon Sep 17 00:00:00 2001 From: doxiao Date: Wed, 6 May 2020 20:41:24 +0000 Subject: [PATCH 57/69] Minor fix --- .../java/oracle/weblogic/kubernetes/ItMiiDomain.java | 10 +++++----- .../oracle/weblogic/kubernetes/utils/FileUtils.java | 3 --- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java index 49b4d7d0ce3..1a286157630 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java @@ -166,8 +166,8 @@ public static void initAll(@Namespaces(3) List namespaces) { // versions of the tools in every run of the test class. try { cleanupDirectory(DOWNLOAD_DIR); - } catch (IOException | IllegalArgumentException e) { - logger.severe("Failed to cleanup the download directory " + DOWNLOAD_DIR, e); + } catch (IOException ioe) { + logger.severe("Failed to cleanup the download directory " + DOWNLOAD_DIR, ioe); } // get a new unique opNamespace @@ -922,7 +922,7 @@ private String createImageAndVerify( List modelList, List archiveList ) { - final String image = String.format("%s:%s", imageName, imageTag); + String image = String.format("%s:%s", imageName, imageTag); // Set additional environment variables for WIT checkDirectory(WIT_BUILD_DIR); @@ -930,8 +930,8 @@ private String createImageAndVerify( env.put("WLSIMG_BLDDIR", WIT_BUILD_DIR); // build an image using WebLogic Image Tool - logger.info("Create image {0}:{1} using model directory {2}", - imageName, imageTag, MODEL_DIR); + logger.info("Create image {0} using model directory {1}", + image, MODEL_DIR); boolean result = createMiiImage( defaultWitParams() .modelImageName(imageName) diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/utils/FileUtils.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/utils/FileUtils.java index 2e45ebc3fce..f532867fcfd 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/utils/FileUtils.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/utils/FileUtils.java @@ -80,9 +80,6 @@ public static void cleanupDirectory(String dir) throws IOException { return; } - if (!file.isDirectory()) { - throw new IllegalArgumentException("The parameter " + dir + " should be a directory."); - } cleanDirectory(file); } From d67a4a9473bde201f727a873158bbea6a3ddda6b Mon Sep 17 00:00:00 2001 From: doxiao Date: Wed, 6 May 2020 22:03:48 +0000 Subject: [PATCH 58/69] More logging --- .../weblogic/kubernetes/ItMiiDomain.java | 26 +++++++++---------- .../kubernetes/actions/impl/AppBuilder.java | 4 +-- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java index 1a286157630..6dbd9e67f6d 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java @@ -791,16 +791,16 @@ private String createImageName(String baseImageName) { } private String createInitialDomainImage() { - // build the model file list + logger.info("Build the model file list that contains {0}", WDT_MODEL_FILE); final List modelList = Collections.singletonList(String.format("%s/%s", MODEL_DIR, WDT_MODEL_FILE)); - // build an application archive using what is in resources/apps/APP_NAME + logger.info("Build an application archive using what is in resources/apps/{0}", APP_NAME); assertTrue(buildAppArchive(defaultAppParams() .srcDirList(Collections.singletonList(APP_NAME))), String.format("Failed to create application archive for %s", APP_NAME)); - // build the archive list + logger.info("Build the archive list that contains {0}", String.format("%s/%s.zip", ARCHIVE_DIR, APP_NAME)); List archiveList = Collections.singletonList(String.format("%s/%s.zip", ARCHIVE_DIR, APP_NAME)); @@ -815,11 +815,11 @@ private String updateImageWithAppV2Patch( String baseImageName, List appDirList ) { - // build the model file list + logger.info("Build the model file list that contains {0}", WDT_MODEL_FILE); List modelList = Collections.singletonList(String.format("%s/%s", MODEL_DIR, WDT_MODEL_FILE)); - // build an application archive + logger.info("Build an application archive using what is in {0}", appDirList); assertTrue( buildAppArchive( defaultAppParams() @@ -827,7 +827,7 @@ private String updateImageWithAppV2Patch( String.format("Failed to create application archive for %s", APP_NAME)); - // build the archive list + logger.info("Build the archive list that contains {0}", String.format("%s/%s.zip", ARCHIVE_DIR, APP_NAME)); List archiveList = Collections.singletonList( String.format("%s/%s.zip", ARCHIVE_DIR, APP_NAME)); @@ -845,13 +845,13 @@ private String updateImageWithSampleApp3( List appDirList2, String modelFile ) { - // build the model file list + logger.info("Build the model file list that contains {0}", modelFile); List modelList = Collections.singletonList(MODEL_DIR + "/" + modelFile); String appName1 = appDirList1.get(0); String appName2 = appDirList2.get(0); - // build an application archive that contains the existing application artifacts + logger.info("Build an application archive using what is in {0}", appDirList1); assertTrue( buildAppArchive( defaultAppParams() @@ -860,9 +860,7 @@ private String updateImageWithSampleApp3( String.format("Failed to create application archive for %s", appName1)); - logger.info("Successfully created application zip file: " + appName1); - - // build an application archive that contains the new application artifacts + logger.info("Build an application archive usingt what is in {0}", appDirList2); assertTrue( buildAppArchive( defaultAppParams() @@ -871,9 +869,9 @@ private String updateImageWithSampleApp3( String.format("Failed to create application archive for %s", appName2)); - logger.info("Successfully cteated application zip file: " + appName2); - - // build the archive list with two zip files + logger.info("Build the archive list with two zip files: {0} and {1}", + String.format("%s/%s.zip", ARCHIVE_DIR, appName1), + String.format("%s/%s.zip", ARCHIVE_DIR, appName2)); List archiveList = Arrays.asList( String.format("%s/%s.zip", ARCHIVE_DIR, appName1), String.format("%s/%s.zip", ARCHIVE_DIR, appName2)); diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/AppBuilder.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/AppBuilder.java index eb6535c56a8..02e3269ec76 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/AppBuilder.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/AppBuilder.java @@ -62,8 +62,8 @@ public boolean build() { APP_DIR + "/" + item, ARCHIVE_SRC_DIR); } - } catch (IOException | RuntimeException e) { - logger.severe("Failed to get the directory " + ARCHIVE_DIR + " ready", e); + } catch (IOException ioe) { + logger.severe("Failed to get the directory " + ARCHIVE_DIR + " ready", ioe); return false; } From 745f8831775d3549bc842e5599bf5a9829106026 Mon Sep 17 00:00:00 2001 From: doxiao Date: Fri, 8 May 2020 16:46:37 +0000 Subject: [PATCH 59/69] Minor comment update --- .../src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java index 6dbd9e67f6d..70660a23bb1 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java @@ -651,7 +651,7 @@ public void testPatchAppV2() { } } - logger.info("The version 2 application has been deployed correctly on all server Pods"); + logger.info("The version 2 application has been deployed correctly on all server pods"); } @Test From b5c3a0d0c4df62015eaeca7df87106a9c18a051d Mon Sep 17 00:00:00 2001 From: doxiao Date: Fri, 8 May 2020 17:57:00 +0000 Subject: [PATCH 60/69] Make log messages more informative --- .../weblogic/kubernetes/ItMiiDomain.java | 19 ++++++++++--------- .../kubernetes/actions/impl/AppBuilder.java | 2 +- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java index 70660a23bb1..d9d36cff4a9 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java @@ -567,6 +567,7 @@ public void testPatchAppV2() { List appAvailability = new ArrayList(); if (enableAppAvailbilityCheck.equalsIgnoreCase("true")) { + logger.info("Start a thread to keep track of the application's availability"); // start a new thread to collect the availability data of the application while the // main thread performs patching operation, and checking of the results. accountingThread = @@ -614,7 +615,7 @@ public void testPatchAppV2() { // patch the domain resource with the new image and verify that the domain resource is patched, // and all server pods are patched as well. - logger.info("Patch domain resource with the new image, and verify the results"); + logger.info("Patch domain resource with image {0}, and verify the results", miiImagePatchAppV2); patchAndVerify( domainUid, domainNamespace, @@ -670,7 +671,7 @@ public void testAddSecondApp() { final String managedServerPrefix = domainUid + "-managed-server"; final int replicaCount = 2; - logger.info("Check V2 application is still running after the previous test"); + logger.info("Check that V2 application is still running after the previous test"); for (int i = 1; i <= replicaCount; i++) { quickCheckAppRunning( domainNamespace, @@ -702,7 +703,7 @@ public void testAddSecondApp() { // patch the domain resource with the new image and verify that the domain resource is patched, // and all server pods are patched as well. - logger.info("Patch the domain with the new image, and verify the result"); + logger.info("Patch the domain with image {0}, and verify the results", miiImageAddSecondApp); patchAndVerify( domainUid, domainNamespace, @@ -851,7 +852,7 @@ private String updateImageWithSampleApp3( String appName1 = appDirList1.get(0); String appName2 = appDirList2.get(0); - logger.info("Build an application archive using what is in {0}", appDirList1); + logger.info("Build the first application archive using what is in {0}", appDirList1); assertTrue( buildAppArchive( defaultAppParams() @@ -860,7 +861,7 @@ private String updateImageWithSampleApp3( String.format("Failed to create application archive for %s", appName1)); - logger.info("Build an application archive usingt what is in {0}", appDirList2); + logger.info("Build the second application archive usingt what is in {0}", appDirList2); assertTrue( buildAppArchive( defaultAppParams() @@ -928,8 +929,8 @@ private String createImageAndVerify( env.put("WLSIMG_BLDDIR", WIT_BUILD_DIR); // build an image using WebLogic Image Tool - logger.info("Create image {0} using model directory {1}", - image, MODEL_DIR); + logger.info("Create image {0} using model list {1} and archive list {2}", + image, modelList, archiveList); boolean result = createMiiImage( defaultWitParams() .modelImageName(imageName) @@ -940,7 +941,7 @@ private String createImageAndVerify( .env(env) .redirect(true)); - assertTrue(result, String.format("Failed to create the image %s using WebLogic Image Tool", image)); + assertTrue(result, String.format("Failed to create image %s using WebLogic Image Tool", image)); /* Check image exists using docker images | grep image tag. * Tag name is unique as it contains date and timestamp. @@ -1196,7 +1197,7 @@ private void quickCheckAppNotRunning( String expectedStr ) { - // check if the application is not running inside of a server pod + // check that the application is NOT running inside of a server pod withQuickRetryPolicy .conditionEvaluationListener( condition -> logger.info("Checking if application {0} is not running on pod {1} in namespace {2} " diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/AppBuilder.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/AppBuilder.java index 02e3269ec76..7e5256571c6 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/AppBuilder.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/AppBuilder.java @@ -57,7 +57,7 @@ public boolean build() { try { cleanupDirectory(ARCHIVE_SRC_DIR); checkDirectory(ARCHIVE_SRC_DIR); - for (String item: params.srcDirList()) { + for (String item : params.srcDirList()) { copyFolder( APP_DIR + "/" + item, ARCHIVE_SRC_DIR); From ea8c9552404cb16479feabe225717430958e2f0a Mon Sep 17 00:00:00 2001 From: doxiao Date: Fri, 8 May 2020 21:18:14 +0000 Subject: [PATCH 61/69] Address a new review comment --- .../oracle/weblogic/kubernetes/ItMiiDomain.java | 11 ----------- .../kubernetes/extensions/ImageBuilders.java | 13 ++++++++++++- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java index d9d36cff4a9..50282e793e4 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java @@ -3,7 +3,6 @@ package oracle.weblogic.kubernetes; -import java.io.IOException; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.ArrayList; @@ -62,7 +61,6 @@ import static oracle.weblogic.kubernetes.TestConstants.REPO_SECRET_NAME; import static oracle.weblogic.kubernetes.TestConstants.REPO_USERNAME; import static oracle.weblogic.kubernetes.actions.ActionConstants.ARCHIVE_DIR; -import static oracle.weblogic.kubernetes.actions.ActionConstants.DOWNLOAD_DIR; import static oracle.weblogic.kubernetes.actions.ActionConstants.MODEL_DIR; import static oracle.weblogic.kubernetes.actions.ActionConstants.WDT_VERSION; import static oracle.weblogic.kubernetes.actions.ActionConstants.WIT_BUILD_DIR; @@ -96,7 +94,6 @@ import static oracle.weblogic.kubernetes.assertions.TestAssertions.podReady; import static oracle.weblogic.kubernetes.assertions.TestAssertions.serviceExists; import static oracle.weblogic.kubernetes.utils.FileUtils.checkDirectory; -import static oracle.weblogic.kubernetes.utils.FileUtils.cleanupDirectory; import static org.awaitility.Awaitility.with; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -162,14 +159,6 @@ public static void initAll(@Namespaces(3) List namespaces) { .and().with().pollInterval(4, SECONDS) .atMost(10, SECONDS).await(); - // clean up the download directory so that we always get the latest - // versions of the tools in every run of the test class. - try { - cleanupDirectory(DOWNLOAD_DIR); - } catch (IOException ioe) { - logger.severe("Failed to cleanup the download directory " + DOWNLOAD_DIR, ioe); - } - // get a new unique opNamespace logger.info("Creating unique namespace for Operator"); assertNotNull(namespaces.get(0), "Namespace list is null"); diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/extensions/ImageBuilders.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/extensions/ImageBuilders.java index d62e7abe6c7..ccfe0f7c47d 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/extensions/ImageBuilders.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/extensions/ImageBuilders.java @@ -3,6 +3,7 @@ package oracle.weblogic.kubernetes.extensions; +import java.io.IOException; import java.util.concurrent.CountDownLatch; import java.util.concurrent.atomic.AtomicBoolean; @@ -14,9 +15,11 @@ import static oracle.weblogic.kubernetes.TestConstants.REPO_PASSWORD; import static oracle.weblogic.kubernetes.TestConstants.REPO_REGISTRY; import static oracle.weblogic.kubernetes.TestConstants.REPO_USERNAME; +import static oracle.weblogic.kubernetes.actions.ActionConstants.DOWNLOAD_DIR; import static oracle.weblogic.kubernetes.actions.TestActions.dockerLogin; import static oracle.weblogic.kubernetes.actions.TestActions.dockerPush; import static oracle.weblogic.kubernetes.extensions.LoggedTest.logger; +import static oracle.weblogic.kubernetes.utils.FileUtils.cleanupDirectory; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.extension.ExtensionContext.Namespace.GLOBAL; @@ -39,6 +42,14 @@ public void beforeAll(ExtensionContext context) { */ if (!started.getAndSet(true)) { try { + // clean up the download directory so that we always get the latest + // versions of the WDT and WIT tools in every run of the test suite. + try { + cleanupDirectory(DOWNLOAD_DIR); + } catch (IOException ioe) { + logger.severe("Failed to cleanup the download directory " + DOWNLOAD_DIR, ioe); + } + // Only the first thread will enter this block. logger.info("Building docker Images before any integration test classes are run"); @@ -84,4 +95,4 @@ public void beforeAll(ExtensionContext context) { public void close() { logger.info("Cleanup images after all test suites are run"); } -} \ No newline at end of file +} From 0e3f2412b84b59e609631183d56e7add5b966bef Mon Sep 17 00:00:00 2001 From: doxiao Date: Fri, 8 May 2020 22:01:51 +0000 Subject: [PATCH 62/69] Fix a minor merge error --- .../oracle/weblogic/kubernetes/assertions/impl/Kubernetes.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Kubernetes.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Kubernetes.java index 6fc4db50a45..5901d7dad86 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Kubernetes.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Kubernetes.java @@ -185,7 +185,7 @@ public static boolean podImagePatched( } /** - * Checks if an Operator pod running in a given namespace. + * Checks if an operator pod is running in a given namespace. * The method assumes the operator name to starts with weblogic-operator- * and decorated with label weblogic.operatorName:namespace * @param namespace in which to check for the pod existence From 8a146531f22e0d9b6d8f92f7d40c04a262d810d6 Mon Sep 17 00:00:00 2001 From: doxiao Date: Mon, 11 May 2020 23:57:38 +0000 Subject: [PATCH 63/69] Address more review comments --- .../weblogic/kubernetes/ItMiiDomain.java | 2 +- .../kubernetes/actions/TestActions.java | 4 +-- .../actions/impl/primitive/Kubernetes.java | 36 +++++++++++++++++++ .../assertions/impl/Kubernetes.java | 36 +------------------ ...odel-singlecluster-two-sampleapp-wls.yaml} | 0 5 files changed, 40 insertions(+), 38 deletions(-) rename new-integration-tests/src/test/resources/wdt-models/{model2-wls.yaml => model-singlecluster-two-sampleapp-wls.yaml} (100%) diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java index 09da22d780a..6a24c7364ee 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java @@ -691,7 +691,7 @@ public void testAddSecondApp() { String.format("%s-%s", MII_IMAGE_NAME, "test-add-second-app"), Arrays.asList(appDir1, appDir2), Collections.singletonList(appDir3), - "model2-wls.yaml"); + "model-singlecluster-two-sampleapp-wls.yaml"); // push the image to a registry to make the test work in multi node cluster pushImageIfNeeded(miiImageAddSecondApp); diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/TestActions.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/TestActions.java index 35965633b26..7be3da796fd 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/TestActions.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/TestActions.java @@ -37,6 +37,7 @@ import oracle.weblogic.kubernetes.actions.impl.primitive.Docker; import oracle.weblogic.kubernetes.actions.impl.primitive.Helm; import oracle.weblogic.kubernetes.actions.impl.primitive.HelmParams; +import oracle.weblogic.kubernetes.actions.impl.primitive.Kubernetes; import oracle.weblogic.kubernetes.actions.impl.primitive.WebLogicImageTool; import oracle.weblogic.kubernetes.actions.impl.primitive.WitParams; import oracle.weblogic.kubernetes.utils.ExecResult; @@ -598,8 +599,7 @@ public static ExecResult execCommand( ) throws IOException, ApiException, InterruptedException { // get the pod given the namespace and name of the pod // no label selector is needed (thus null below) - final V1Pod pod = oracle.weblogic.kubernetes.assertions.impl.Kubernetes - .getPod(namespace, null, podName); + final V1Pod pod = Kubernetes.getPod(namespace, null, podName); if (pod == null) { throw new IllegalArgumentException( String.format("The pod %s does not exist in namespace %s!", podName, namespace)); diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/primitive/Kubernetes.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/primitive/Kubernetes.java index 6a62780160a..d3ef4514add 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/primitive/Kubernetes.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/primitive/Kubernetes.java @@ -342,6 +342,42 @@ public static boolean deleteDeployment(String namespace, String name) throws Api } // --------------------------- pods ----------------------------------------- + /** + * Returns the V1Pod object given the following parameters. + * + * @param namespace in which to check for the pod existence + * @param labelSelector for example, in the format "weblogic.domainUID in (%s)" + * @param podName name of the pod to return + * @return V1Pod object if found otherwise null + * @throws ApiException when there is error in querying the cluster + */ + public static V1Pod getPod(String namespace, String labelSelector, String podName) throws ApiException { + V1PodList v1PodList = + coreV1Api.listNamespacedPod( + namespace, // namespace in which to look for the pods. + Boolean.FALSE.toString(), // // pretty print output. + Boolean.FALSE, // allowWatchBookmarks requests watch events with type "BOOKMARK". + null, // continue to query when there is more results to return. + null, // selector to restrict the list of returned objects by their fields + labelSelector, // selector to restrict the list of returned objects by their labels. + null, // maximum number of responses to return for a list call. + null, // shows changes that occur after that particular version of a resource. + null, // Timeout for the list/watch call. + Boolean.FALSE // Watch for changes to the described resources. + ); + for (V1Pod item : v1PodList.getItems()) { + if (item.getMetadata().getName().contains(podName.trim())) { + logger.fine(String.format("Pod Name: %s, Pod Namespace: %s, Pod UID: %s, Pod Status: %s", + item.getMetadata().getName(), + item.getMetadata().getNamespace(), + item.getMetadata().getUid(), + item.getStatus().getPhase())); + return item; + } + } + return null; + } + /** * Get a pod's log. * diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Kubernetes.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Kubernetes.java index 5901d7dad86..eec124857e1 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Kubernetes.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Kubernetes.java @@ -22,6 +22,7 @@ import io.kubernetes.client.openapi.models.V1ServiceList; import io.kubernetes.client.util.ClientBuilder; +import static oracle.weblogic.kubernetes.actions.impl.primitive.Kubernetes.getPod; import static oracle.weblogic.kubernetes.extensions.LoggedTest.logger; public class Kubernetes { @@ -238,41 +239,6 @@ public static boolean isNginxPodReady(String namespace) throws ApiException { return isPodReady(namespace, null, "nginx-ingress-controller"); } - /** - * Returns the V1Pod object given the following parameters. - * @param namespace in which to check for the pod existence - * @param labelSelector in the format "weblogic.domainUID in (%s)" - * @param podName name of the pod to return - * @return V1Pod object if found otherwise null - * @throws ApiException when there is error in querying the cluster - */ - public static V1Pod getPod(String namespace, String labelSelector, String podName) throws ApiException { - V1PodList v1PodList = - coreV1Api.listNamespacedPod( - namespace, // namespace in which to look for the pods. - Boolean.FALSE.toString(), // // pretty print output. - Boolean.FALSE, // allowWatchBookmarks requests watch events with type "BOOKMARK". - null, // continue to query when there is more results to return. - null, // selector to restrict the list of returned objects by their fields - labelSelector, // selector to restrict the list of returned objects by their labels. - null, // maximum number of responses to return for a list call. - null, // shows changes that occur after that particular version of a resource. - null, // Timeout for the list/watch call. - Boolean.FALSE // Watch for changes to the described resources. - ); - for (V1Pod item : v1PodList.getItems()) { - if (item.getMetadata().getName().contains(podName.trim())) { - logger.fine(String.format("Pod Name: %s, Pod Namespace: %s, Pod UID: %s, Pod Status: %s", - item.getMetadata().getName(), - item.getMetadata().getNamespace(), - item.getMetadata().getUid(), - item.getStatus().getPhase())); - return item; - } - } - return null; - } - /** * Checks if a Kubernetes service object exists in a given namespace. * @param serviceName name of the service to check for diff --git a/new-integration-tests/src/test/resources/wdt-models/model2-wls.yaml b/new-integration-tests/src/test/resources/wdt-models/model-singlecluster-two-sampleapp-wls.yaml similarity index 100% rename from new-integration-tests/src/test/resources/wdt-models/model2-wls.yaml rename to new-integration-tests/src/test/resources/wdt-models/model-singlecluster-two-sampleapp-wls.yaml From 24f2579dd20243a773b3b44107772629f34a5de9 Mon Sep 17 00:00:00 2001 From: doxiao Date: Tue, 12 May 2020 00:07:42 +0000 Subject: [PATCH 64/69] Update javadoc --- .../weblogic/kubernetes/actions/impl/primitive/Kubernetes.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/primitive/Kubernetes.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/primitive/Kubernetes.java index d3ef4514add..a8a1ad090c3 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/primitive/Kubernetes.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/primitive/Kubernetes.java @@ -343,7 +343,7 @@ public static boolean deleteDeployment(String namespace, String name) throws Api // --------------------------- pods ----------------------------------------- /** - * Returns the V1Pod object given the following parameters. + * Get the V1Pod object given the following parameters. * * @param namespace in which to check for the pod existence * @param labelSelector for example, in the format "weblogic.domainUID in (%s)" From c352f594a296e8685d9ac8aff883e216ec096101 Mon Sep 17 00:00:00 2001 From: doxiao Date: Tue, 12 May 2020 15:51:15 +0000 Subject: [PATCH 65/69] Fix merge issues --- .../actions/impl/primitive/Kubernetes.java | 35 ------------------- .../kubernetes/assertions/impl/Domain.java | 2 +- 2 files changed, 1 insertion(+), 36 deletions(-) diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/primitive/Kubernetes.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/primitive/Kubernetes.java index 46eae574816..c1e4c56502b 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/primitive/Kubernetes.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/primitive/Kubernetes.java @@ -344,41 +344,6 @@ public static boolean deleteDeployment(String namespace, String name) throws Api } // --------------------------- pods ----------------------------------------- - /** - * Get the V1Pod object given the following parameters. - * - * @param namespace in which to check for the pod existence - * @param labelSelector for example, in the format "weblogic.domainUID in (%s)" - * @param podName name of the pod to return - * @return V1Pod object if found otherwise null - * @throws ApiException when there is error in querying the cluster - */ - public static V1Pod getPod(String namespace, String labelSelector, String podName) throws ApiException { - V1PodList v1PodList = - coreV1Api.listNamespacedPod( - namespace, // namespace in which to look for the pods. - Boolean.FALSE.toString(), // // pretty print output. - Boolean.FALSE, // allowWatchBookmarks requests watch events with type "BOOKMARK". - null, // continue to query when there is more results to return. - null, // selector to restrict the list of returned objects by their fields - labelSelector, // selector to restrict the list of returned objects by their labels. - null, // maximum number of responses to return for a list call. - null, // shows changes that occur after that particular version of a resource. - null, // Timeout for the list/watch call. - Boolean.FALSE // Watch for changes to the described resources. - ); - for (V1Pod item : v1PodList.getItems()) { - if (item.getMetadata().getName().contains(podName.trim())) { - logger.fine(String.format("Pod Name: %s, Pod Namespace: %s, Pod UID: %s, Pod Status: %s", - item.getMetadata().getName(), - item.getMetadata().getNamespace(), - item.getMetadata().getUid(), - item.getStatus().getPhase())); - return item; - } - } - return null; - } /** * Get a pod's log. diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Domain.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Domain.java index 9cb92c3d3b8..000467ff7d7 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Domain.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Domain.java @@ -16,9 +16,9 @@ import org.joda.time.format.DateTimeFormat; import org.joda.time.format.DateTimeFormatter; +import static oracle.weblogic.kubernetes.actions.impl.primitive.Kubernetes.getPod; import static oracle.weblogic.kubernetes.assertions.impl.Kubernetes.doesPodExist; import static oracle.weblogic.kubernetes.assertions.impl.Kubernetes.doesServiceExist; -import static oracle.weblogic.kubernetes.assertions.impl.Kubernetes.getPod; import static oracle.weblogic.kubernetes.assertions.impl.Kubernetes.isPodReady; import static oracle.weblogic.kubernetes.extensions.LoggedTest.logger; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; From 3b4da2f19a4e6235f141dd77f3268f2a1d5c5f50 Mon Sep 17 00:00:00 2001 From: doxiao Date: Tue, 12 May 2020 21:08:54 +0000 Subject: [PATCH 66/69] Update the push image code to check REPO_NAME --- .../test/java/oracle/weblogic/kubernetes/ItMiiDomain.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java index 32aa49a544e..1bb19531fc6 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java @@ -753,8 +753,11 @@ private void pushImageIfNeeded(String image) { if (!REPO_USERNAME.equals(REPO_DUMMY_VALUE)) { logger.info("docker login to registry {0}", REPO_REGISTRY); assertTrue(dockerLogin(REPO_REGISTRY, REPO_USERNAME, REPO_PASSWORD), "docker login failed"); + } - logger.info("docker push image {0} to registry {1}", image, REPO_REGISTRY); + // push image + if (!REPO_NAME.isEmpty()) { + logger.info("docker push image {0} to registry", image); assertTrue(dockerPush(image), String.format("docker push failed for image %s", image)); } } @@ -768,7 +771,7 @@ private String createUniqueImageTag() { private String createImageName(String baseImageName) { // Add repository name in image name for Jenkins runs - return REPO_USERNAME.equals(REPO_DUMMY_VALUE) ? baseImageName : REPO_NAME + baseImageName; + return REPO_NAME.isEmpty() ? baseImageName : REPO_NAME + baseImageName; } private String updateImageWithAppV2Patch( From 294decc6e04c463406ddafbdb92ea0f3561ef917 Mon Sep 17 00:00:00 2001 From: doxiao Date: Tue, 12 May 2020 21:51:36 +0000 Subject: [PATCH 67/69] remove double adding REMO_NAME --- .../java/oracle/weblogic/kubernetes/ItMiiDomain.java | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java index 1bb19531fc6..45fd126851c 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java @@ -769,11 +769,6 @@ private String createUniqueImageTag() { return dateFormat.format(date) + "-" + System.currentTimeMillis(); } - private String createImageName(String baseImageName) { - // Add repository name in image name for Jenkins runs - return REPO_NAME.isEmpty() ? baseImageName : REPO_NAME + baseImageName; - } - private String updateImageWithAppV2Patch( String baseImageName, List appDirList @@ -797,7 +792,7 @@ private String updateImageWithAppV2Patch( String.format("%s/%s.zip", ARCHIVE_DIR, MII_BASIC_APP_NAME)); return createImageAndVerify( - createImageName(baseImageName), + baseImageName, createUniqueImageTag(), modelList, archiveList); @@ -841,7 +836,7 @@ private String updateImageWithSampleApp3( String.format("%s/%s.zip", ARCHIVE_DIR, appName2)); return createImageAndVerify( - createImageName(baseImageName), + baseImageName, createUniqueImageTag(), modelList, archiveList); From 70fbeb1b8ef8598db5aa0d36ed05c651864c24b5 Mon Sep 17 00:00:00 2001 From: doxiao Date: Tue, 12 May 2020 22:02:41 +0000 Subject: [PATCH 68/69] Change baseImageName to image Name --- .../test/java/oracle/weblogic/kubernetes/ItMiiDomain.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java index 45fd126851c..17932c762ce 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java @@ -770,7 +770,7 @@ private String createUniqueImageTag() { } private String updateImageWithAppV2Patch( - String baseImageName, + String imageName, List appDirList ) { logger.info("Build the model file list that contains {0}", MII_BASIC_WDT_MODEL_FILE); @@ -792,14 +792,14 @@ private String updateImageWithAppV2Patch( String.format("%s/%s.zip", ARCHIVE_DIR, MII_BASIC_APP_NAME)); return createImageAndVerify( - baseImageName, + imageName, createUniqueImageTag(), modelList, archiveList); } private String updateImageWithSampleApp3( - String baseImageName, + String imageName, List appDirList1, List appDirList2, String modelFile @@ -836,7 +836,7 @@ private String updateImageWithSampleApp3( String.format("%s/%s.zip", ARCHIVE_DIR, appName2)); return createImageAndVerify( - baseImageName, + imageName, createUniqueImageTag(), modelList, archiveList); From d37858e2048e93323bdd4904f6ac6e25eda7dd78 Mon Sep 17 00:00:00 2001 From: doxiao Date: Sun, 17 May 2020 13:31:13 +0000 Subject: [PATCH 69/69] Fix a typo --- .../java/oracle/weblogic/kubernetes/actions/TestActions.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/TestActions.java b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/TestActions.java index 3d6836579b7..e5d7e3e1d2e 100644 --- a/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/TestActions.java +++ b/new-integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/TestActions.java @@ -618,7 +618,7 @@ public static JsonObject createDockerConfigJson(String username, String password /** * Execute a command in a container of a Kubernetes pod. * - * @param namespace The Kubernertes namespace that the pod is in + * @param namespace The Kubernetes namespace that the pod is in * @param podName The name of the Kubernetes pod where the command is expected to run * @param containerName The container in the Pod where the command is to be run. If no * container name is provided than the first container in the Pod is used.