new-integration-tests/src/test/java/oracle/weblogic/kubernetes/utils/CommonTestUtils.java
public static void scaleAndVerifyCluster(String clusterName,
                                           String domainUid,
                                           String domainNamespace,
                                           String manageServerPodNamePrefix,
                                           int replicasBeforeScale,
                                           int replicasAfterScale,
                                           boolean withRestApi,
                                           int externalRestHttpsPort,
                                           String opNamespace,
                                           String opServiceAccount,
                                           boolean withWLDF,
                                           String domainHomeLocation,
                                           String scalingAction,
                                           int scalingSize,
                                           String myWebAppName,
                                           String curlCmdForWLDFApp,
                                           String curlCmd,
                                           List<String> expectedServerNames) {
    LoggingFacade logger = getLogger();
    // get the original managed server pod creation timestamp before scale
    List<DateTime> listOfPodCreationTimestamp = new ArrayList<>();
    for (int i = 1; i <= replicasBeforeScale; i++) {
      String managedServerPodName = manageServerPodNamePrefix + i;
      DateTime originalCreationTimestamp =
          assertDoesNotThrow(() -> getPodCreationTimestamp(domainNamespace, "", managedServerPodName),
              String.format("getPodCreationTimestamp failed with ApiException for pod %s in namespace %s",
                  managedServerPodName, domainNamespace));
      listOfPodCreationTimestamp.add(originalCreationTimestamp);
    }

    // scale the cluster in the domain
    logger.info("Scaling cluster {0} of domain {1} in namespace {2} to {3} servers",
        clusterName, domainUid, domainNamespace, replicasAfterScale);
    if (withRestApi) {
      assertThat(assertDoesNotThrow(() -> scaleClusterWithRestApi(domainUid, clusterName,
          replicasAfterScale, externalRestHttpsPort, opNamespace, opServiceAccount)))
          .as("Verify scaling cluster {0} of domain {1} in namespace {2} with REST API succeeds",
              clusterName, domainUid, domainNamespace)
          .withFailMessage("Scaling cluster {0} of domain {1} in namespace {2} with REST API failed",
              clusterName, domainUid, domainNamespace)
          .isTrue();
    } else if (withWLDF) {
      // scale the cluster using WLDF policy
      assertThat(assertDoesNotThrow(() -> scaleClusterWithWLDF(clusterName, domainUid, domainNamespace,
          domainHomeLocation, scalingAction, scalingSize, opNamespace, opServiceAccount, myWebAppName,
          curlCmdForWLDFApp)))
          .as("Verify scaling cluster {0} of domain {1} in namespace {2} with WLDF policy succeeds",
              clusterName, domainUid, domainNamespace)
          .withFailMessage("Scaling cluster {0} of domain {1} in namespace {2} with WLDF policy failed",
              clusterName, domainUid, domainNamespace)
          .isTrue();
    } else {
      assertThat(assertDoesNotThrow(() -> scaleCluster(domainUid, domainNamespace, clusterName, replicasAfterScale)))
          .as("Verify scaling cluster {0} of domain {1} in namespace {2} succeeds",
              clusterName, domainUid, domainNamespace)
          .withFailMessage("Scaling cluster {0} of domain {1} in namespace {2} failed",
              clusterName, domainUid, domainNamespace)
          .isTrue();
    }

    if (replicasBeforeScale <= replicasAfterScale) {

      // scale up
      // check that the original managed server pod state is not changed during scaling the cluster
      for (int i = 1; i <= replicasBeforeScale; i++) {
        String manageServerPodName = manageServerPodNamePrefix + i;

        // check the original managed server pod state is not changed
        logger.info("Checking that the state of manged server pod {0} is not changed in namespace {1}",
            manageServerPodName, domainNamespace);
        podStateNotChanged(manageServerPodName, domainUid, domainNamespace, listOfPodCreationTimestamp.get(i - 1));
      }

      if (curlCmd != null && expectedServerNames != null) {
        // check that NGINX can access the sample apps from the original managed servers in the domain
        logger.info("Checking that NGINX can access the sample app from the original managed servers in the domain "
            + "while the domain is scaling up.");
        logger.info("expected server name list which should be in the sample app response: {0} before scale",
            expectedServerNames);

        assertThat(callWebAppAndCheckForServerNameInResponse(curlCmd, expectedServerNames, 50))
            .as("Verify NGINX can access the sample app from the original managed servers in the domain")
            .withFailMessage("NGINX can not access the sample app from one or more of the managed servers")
            .isTrue();
      }

      // check that new managed server pods were created and wait for them to be ready
      for (int i = replicasBeforeScale + 1; i <= replicasAfterScale; i++) {
        String manageServerPodName = manageServerPodNamePrefix + i;

        // check new managed server pod exists in the namespace
        logger.info("Checking that the new managed server pod {0} exists in namespace {1}",
            manageServerPodName, domainNamespace);
        checkPodExists(manageServerPodName, domainUid, domainNamespace);

        // check new managed server pod is ready
        logger.info("Checking that the new managed server pod {0} is ready in namespace {1}",
            manageServerPodName, domainNamespace);
        checkPodReady(manageServerPodName, domainUid, domainNamespace);

        // check new managed server service exists in the namespace
        logger.info("Checking that the new managed server service {0} exists in namespace {1}",
            manageServerPodName, domainNamespace);
        checkServiceExists(manageServerPodName, domainNamespace);

        if (expectedServerNames != null) {
          // add the new managed server to the list
          expectedServerNames.add(clusterName + "-" + MANAGED_SERVER_NAME_BASE + i);
        }
      }

      if (curlCmd != null && expectedServerNames != null) {
        // check that NGINX can access the sample apps from new and original managed servers
        logger.info("Checking that NGINX can access the sample app from the new and original managed servers "
            + "in the domain after the cluster is scaled up.");
        assertThat(callWebAppAndCheckForServerNameInResponse(curlCmd, expectedServerNames, 50))
            .as("Verify NGINX can access the sample app from all managed servers in the domain")
            .withFailMessage("NGINX can not access the sample app from one or more of the managed servers")
            .isTrue();
      }
    } else {
      // scale down
      // wait and check the pods are deleted
      for (int i = replicasBeforeScale; i > replicasAfterScale; i--) {
        logger.info("Checking that managed server pod {0} was deleted from namespace {1}",
            manageServerPodNamePrefix + i, domainNamespace);
        checkPodDoesNotExist(manageServerPodNamePrefix + i, domainUid, domainNamespace);
        if (expectedServerNames != null) {
          expectedServerNames.remove(clusterName + "-" + MANAGED_SERVER_NAME_BASE + i);
        }
      }

      if (curlCmd != null && expectedServerNames != null) {
        // check that NGINX can access the app from the remaining managed servers in the domain
        logger.info("Checking that NGINX can access the sample app from the remaining managed servers in the domain "
            + "after the cluster is scaled down.");
        assertThat(callWebAppAndCheckForServerNameInResponse(curlCmd, expectedServerNames, 50))
            .as("Verify NGINX can access the sample app from the remaining managed server in the domain")
            .withFailMessage("NGINX can not access the sample app from the remaining managed server")
            .isTrue();
      }
    }
  }
/**
   * Scale the WebLogic cluster to specified number of servers.
   * Verify the sample app can be accessed through NGINX if curlCmd is not null.
   *
   * @param clusterName the WebLogic cluster name in the domain to be scaled
   * @param domainUid the domain to which the cluster belongs
   * @param domainNamespace the namespace in which the domain exists
   * @param manageServerPodNamePrefix managed server pod name prefix
   * @param replicasBeforeScale the replicas of the WebLogic cluster before the scale
   * @param replicasAfterScale the replicas of the WebLogic cluster after the scale
   * @param withRestApi whether to use REST API to scale the cluster
   * @param externalRestHttpsPort the node port allocated for the external operator REST HTTPS interface
   * @param opNamespace the namespace of WebLogic operator
   * @param opServiceAccount the service account for operator
   * @param withWLDF whether to use WLDF to scale cluster
   * @param domainHomeLocation the domain home location of the domain
   * @param scalingAction scaling action, accepted value: scaleUp or scaleDown
   * @param scalingSize the number of servers to scale up or scale down
   * @param myWebAppName the web app name deployed to the domain
   * @param curlCmdForWLDFApp the curl command to call the web app used in the WLDF script
   * @param curlCmd the curl command to verify ingress controller can access the sample apps from all managed servers
   *                in the cluster, if curlCmd is null, the method will not verify the accessibility of the sample app
   *                through ingress controller
   * @param expectedServerNames list of managed servers in the cluster before scale, if curlCmd is null,
   *                            set expectedServerNames to null too
   */
Scale the WebLogic cluster to specified number of servers.
Verify the sample app can be accessed through NGINX if curlCmd is not null.


Scale the WebLogic cluster to specified number of servers . Verify the sample app can be accessed through NGINX if curlCmd is not null .
public static void scaleAndVerifyCluster(String clusterName,
                                           String domainUid,
                                           String domainNamespace,
                                           String manageServerPodNamePrefix,
                                           int replicasBeforeScale,
                                           int replicasAfterScale,
                                           boolean withRestApi,
                                           int externalRestHttpsPort,
                                           String opNamespace,
                                           String opServiceAccount,
                                           boolean withWLDF,
                                           String domainHomeLocation,
                                           String scalingAction,
                                           int scalingSize,
                                           String myWebAppName,
                                           String curlCmdForWLDFApp,
                                           String curlCmd,
                                           List<String> expectedServerNames) {
    LoggingFacade logger = getLogger();
    List<DateTime> listOfPodCreationTimestamp = new ArrayList<>();
    for (int i = 1; i <= replicasBeforeScale; i++) {
      String managedServerPodName = manageServerPodNamePrefix + i;
      DateTime originalCreationTimestamp =
          assertDoesNotThrow(() -> getPodCreationTimestamp(domainNamespace, "", managedServerPodName),
              String.format("getPodCreationTimestamp failed with ApiException for pod %s in namespace %s",
                  managedServerPodName, domainNamespace));
      listOfPodCreationTimestamp.add(originalCreationTimestamp);
    }
    logger.info("Scaling cluster {0} of domain {1} in namespace {2} to {3} servers",
        clusterName, domainUid, domainNamespace, replicasAfterScale);
    if (withRestApi) {
      assertThat(assertDoesNotThrow(() -> scaleClusterWithRestApi(domainUid, clusterName,
          replicasAfterScale, externalRestHttpsPort, opNamespace, opServiceAccount)))
          .as("Verify scaling cluster {0} of domain {1} in namespace {2} with REST API succeeds",
              clusterName, domainUid, domainNamespace)
          .withFailMessage("Scaling cluster {0} of domain {1} in namespace {2} with REST API failed",
              clusterName, domainUid, domainNamespace)
          .isTrue();
    } else if (withWLDF) {
      assertThat(assertDoesNotThrow(() -> scaleClusterWithWLDF(clusterName, domainUid, domainNamespace,
          domainHomeLocation, scalingAction, scalingSize, opNamespace, opServiceAccount, myWebAppName,
          curlCmdForWLDFApp)))
          .as("Verify scaling cluster {0} of domain {1} in namespace {2} with WLDF policy succeeds",
              clusterName, domainUid, domainNamespace)
          .withFailMessage("Scaling cluster {0} of domain {1} in namespace {2} with WLDF policy failed",
              clusterName, domainUid, domainNamespace)
          .isTrue();
    } else {
      assertThat(assertDoesNotThrow(() -> scaleCluster(domainUid, domainNamespace, clusterName, replicasAfterScale)))
          .as("Verify scaling cluster {0} of domain {1} in namespace {2} succeeds",
              clusterName, domainUid, domainNamespace)
          .withFailMessage("Scaling cluster {0} of domain {1} in namespace {2} failed",
              clusterName, domainUid, domainNamespace)
          .isTrue();
    }
    if (replicasBeforeScale <= replicasAfterScale) {
      for (int i = 1; i <= replicasBeforeScale; i++) {
        String manageServerPodName = manageServerPodNamePrefix + i;
        logger.info("Checking that the state of manged server pod {0} is not changed in namespace {1}",
            manageServerPodName, domainNamespace);
        podStateNotChanged(manageServerPodName, domainUid, domainNamespace, listOfPodCreationTimestamp.get(i - 1));
      }
      if (curlCmd != null && expectedServerNames != null) {
        logger.info("Checking that NGINX can access the sample app from the original managed servers in the domain "
            + "while the domain is scaling up.");
        logger.info("expected server name list which should be in the sample app response: {0} before scale",
            expectedServerNames);
        assertThat(callWebAppAndCheckForServerNameInResponse(curlCmd, expectedServerNames, 50))
            .as("Verify NGINX can access the sample app from the original managed servers in the domain")
            .withFailMessage("NGINX can not access the sample app from one or more of the managed servers")
            .isTrue();
      }
      for (int i = replicasBeforeScale + 1; i <= replicasAfterScale; i++) {
        String manageServerPodName = manageServerPodNamePrefix + i;
        logger.info("Checking that the new managed server pod {0} exists in namespace {1}",
            manageServerPodName, domainNamespace);
        checkPodExists(manageServerPodName, domainUid, domainNamespace);
        logger.info("Checking that the new managed server pod {0} is ready in namespace {1}",
            manageServerPodName, domainNamespace);
        checkPodReady(manageServerPodName, domainUid, domainNamespace);
        logger.info("Checking that the new managed server service {0} exists in namespace {1}",
            manageServerPodName, domainNamespace);
        checkServiceExists(manageServerPodName, domainNamespace);
        if (expectedServerNames != null) {
          expectedServerNames.add(clusterName + "-" + MANAGED_SERVER_NAME_BASE + i);
        }
      }
      if (curlCmd != null && expectedServerNames != null) {
        logger.info("Checking that NGINX can access the sample app from the new and original managed servers "
            + "in the domain after the cluster is scaled up.");
        assertThat(callWebAppAndCheckForServerNameInResponse(curlCmd, expectedServerNames, 50))
            .as("Verify NGINX can access the sample app from all managed servers in the domain")
            .withFailMessage("NGINX can not access the sample app from one or more of the managed servers")
            .isTrue();
      }
    } else {
      for (int i = replicasBeforeScale; i > replicasAfterScale; i--) {
        logger.info("Checking that managed server pod {0} was deleted from namespace {1}",
            manageServerPodNamePrefix + i, domainNamespace);
        checkPodDoesNotExist(manageServerPodNamePrefix + i, domainUid, domainNamespace);
        if (expectedServerNames != null) {
          expectedServerNames.remove(clusterName + "-" + MANAGED_SERVER_NAME_BASE + i);
        }
      }
      if (curlCmd != null && expectedServerNames != null) {
        logger.info("Checking that NGINX can access the sample app from the remaining managed servers in the domain "
            + "after the cluster is scaled down.");
        assertThat(callWebAppAndCheckForServerNameInResponse(curlCmd, expectedServerNames, 50))
            .as("Verify NGINX can access the sample app from the remaining managed server in the domain")
            .withFailMessage("NGINX can not access the sample app from the remaining managed server")
            .isTrue();
      }
    }
  }
public static void scaleAndVerifyCluster ( String clusterName , String domainUid , String domainNamespace , String manageServerPodNamePrefix , int replicasBeforeScale , int replicasAfterScale , boolean withRestApi , int externalRestHttpsPort , String opNamespace , String opServiceAccount , boolean withWLDF , String domainHomeLocation , String scalingAction , int scalingSize , String myWebAppName , String curlCmdForWLDFApp , String curlCmd , List < String > expectedServerNames ) { LoggingFacade logger = getLogger ( ) ; List < DateTime > listOfPodCreationTimestamp = new ArrayList < > ( ) ; for ( int i = 1 ; i <= replicasBeforeScale ; i ++ ) { String managedServerPodName = manageServerPodNamePrefix + i ; DateTime originalCreationTimestamp = assertDoesNotThrow ( ( ) -> getPodCreationTimestamp ( domainNamespace , "" , managedServerPodName ) , String . format ( "getPodCreationTimestamp failed with ApiException for pod %s in namespace %s" , managedServerPodName , domainNamespace ) ) ; listOfPodCreationTimestamp . add ( originalCreationTimestamp ) ; } logger . info ( "Scaling cluster {0} of domain {1} in namespace {2} to {3} servers" , clusterName , domainUid , domainNamespace , replicasAfterScale ) ; if ( withRestApi ) { assertThat ( assertDoesNotThrow ( ( ) -> scaleClusterWithRestApi ( domainUid , clusterName , replicasAfterScale , externalRestHttpsPort , opNamespace , opServiceAccount ) ) ) . as ( "Verify scaling cluster {0} of domain {1} in namespace {2} with REST API succeeds" , clusterName , domainUid , domainNamespace ) . withFailMessage ( "Scaling cluster {0} of domain {1} in namespace {2} with REST API failed" , clusterName , domainUid , domainNamespace ) . isTrue ( ) ; } else if ( withWLDF ) { assertThat ( assertDoesNotThrow ( ( ) -> scaleClusterWithWLDF ( clusterName , domainUid , domainNamespace , domainHomeLocation , scalingAction , scalingSize , opNamespace , opServiceAccount , myWebAppName , curlCmdForWLDFApp ) ) ) . as ( "Verify scaling cluster {0} of domain {1} in namespace {2} with WLDF policy succeeds" , clusterName , domainUid , domainNamespace ) . withFailMessage ( "Scaling cluster {0} of domain {1} in namespace {2} with WLDF policy failed" , clusterName , domainUid , domainNamespace ) . isTrue ( ) ; } else { assertThat ( assertDoesNotThrow ( ( ) -> scaleCluster ( domainUid , domainNamespace , clusterName , replicasAfterScale ) ) ) . as ( "Verify scaling cluster {0} of domain {1} in namespace {2} succeeds" , clusterName , domainUid , domainNamespace ) . withFailMessage ( "Scaling cluster {0} of domain {1} in namespace {2} failed" , clusterName , domainUid , domainNamespace ) . isTrue ( ) ; } if ( replicasBeforeScale <= replicasAfterScale ) { for ( int i = 1 ; i <= replicasBeforeScale ; i ++ ) { String manageServerPodName = manageServerPodNamePrefix + i ; logger . info ( "Checking that the state of manged server pod {0} is not changed in namespace {1}" , manageServerPodName , domainNamespace ) ; podStateNotChanged ( manageServerPodName , domainUid , domainNamespace , listOfPodCreationTimestamp . get ( i - 1 ) ) ; } if ( curlCmd != null && expectedServerNames != null ) { logger . info ( "Checking that NGINX can access the sample app from the original managed servers in the domain " + "while the domain is scaling up." ) ; logger . info ( "expected server name list which should be in the sample app response: {0} before scale" , expectedServerNames ) ; assertThat ( callWebAppAndCheckForServerNameInResponse ( curlCmd , expectedServerNames , 50 ) ) . as ( "Verify NGINX can access the sample app from the original managed servers in the domain" ) . withFailMessage ( "NGINX can not access the sample app from one or more of the managed servers" ) . isTrue ( ) ; } for ( int i = replicasBeforeScale + 1 ; i <= replicasAfterScale ; i ++ ) { String manageServerPodName = manageServerPodNamePrefix + i ; logger . info ( "Checking that the new managed server pod {0} exists in namespace {1}" , manageServerPodName , domainNamespace ) ; checkPodExists ( manageServerPodName , domainUid , domainNamespace ) ; logger . info ( "Checking that the new managed server pod {0} is ready in namespace {1}" , manageServerPodName , domainNamespace ) ; checkPodReady ( manageServerPodName , domainUid , domainNamespace ) ; logger . info ( "Checking that the new managed server service {0} exists in namespace {1}" , manageServerPodName , domainNamespace ) ; checkServiceExists ( manageServerPodName , domainNamespace ) ; if ( expectedServerNames != null ) { expectedServerNames . add ( clusterName + "-" + MANAGED_SERVER_NAME_BASE + i ) ; } } if ( curlCmd != null && expectedServerNames != null ) { logger . info ( "Checking that NGINX can access the sample app from the new and original managed servers " + "in the domain after the cluster is scaled up." ) ; assertThat ( callWebAppAndCheckForServerNameInResponse ( curlCmd , expectedServerNames , 50 ) ) . as ( "Verify NGINX can access the sample app from all managed servers in the domain" ) . withFailMessage ( "NGINX can not access the sample app from one or more of the managed servers" ) . isTrue ( ) ; } } else { for ( int i = replicasBeforeScale ; i > replicasAfterScale ; i -- ) { logger . info ( "Checking that managed server pod {0} was deleted from namespace {1}" , manageServerPodNamePrefix + i , domainNamespace ) ; checkPodDoesNotExist ( manageServerPodNamePrefix + i , domainUid , domainNamespace ) ; if ( expectedServerNames != null ) { expectedServerNames . remove ( clusterName + "-" + MANAGED_SERVER_NAME_BASE + i ) ; } } if ( curlCmd != null && expectedServerNames != null ) { logger . info ( "Checking that NGINX can access the sample app from the remaining managed servers in the domain " + "after the cluster is scaled down." ) ; assertThat ( callWebAppAndCheckForServerNameInResponse ( curlCmd , expectedServerNames , 50 ) ) . as ( "Verify NGINX can access the sample app from the remaining managed server in the domain" ) . withFailMessage ( "NGINX can not access the sample app from the remaining managed server" ) . isTrue ( ) ; } } }
Scale the WebLogic cluster to specified number of servers.
Scale the WebLogic cluster to specified number of servers .
// get the original managed server pod creation timestamp before scale // scale the cluster in the domain // scale the cluster using WLDF policy // scale up // check that the original managed server pod state is not changed during scaling the cluster // check the original managed server pod state is not changed // check that NGINX can access the sample apps from the original managed servers in the domain // check that new managed server pods were created and wait for them to be ready // check new managed server pod exists in the namespace // check new managed server pod is ready // check new managed server service exists in the namespace // add the new managed server to the list // check that NGINX can access the sample apps from new and original managed servers // scale down // wait and check the pods are deleted // check that NGINX can access the app from the remaining managed servers in the domain