new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItIntrospectVersion.java
@Order(2)
  @Test
  @DisplayName("Test introspectVersion rolling server pods when admin server port is changed")
  public void testDomainIntrospectVersionRolling() {

    final String domainUid = "mydomain";
    final String clusterName = "mycluster";

    final String adminServerName = "admin-server";
    final String adminServerPodName = domainUid + "-" + adminServerName;

    final String managedServerNameBase = "ms-";
    String managedServerPodNamePrefix = domainUid + "-" + managedServerNameBase;

    final int replicaCount = 3;
    final int newAdminPort = 7005;

    // get the pod creation time stamps
    LinkedHashMap<String, DateTime> pods = new LinkedHashMap<>();
    // get the creation time of the admin server pod before patching
    DateTime adminPodCreationTime = getPodCreationTime(introDomainNamespace, adminServerPodName);
    pods.put(adminServerPodName, adminPodCreationTime);
    // get the creation time of the managed server pods before patching
    for (int i = 1; i <= replicaCount; i++) {
      pods.put(managedServerPodNamePrefix + i,
          getPodCreationTime(introDomainNamespace, managedServerPodNamePrefix + i));
    }

    logger.info("Getting node port for default channel");
    int adminServerT3Port = assertDoesNotThrow(()
        -> getServiceNodePort(introDomainNamespace, adminServerPodName + "-external", "t3channel"),
        "Getting admin server node port failed");

    // create a temporary WebLogic WLST property file
    File wlstPropertiesFile = assertDoesNotThrow(() -> File.createTempFile("wlst", "properties"),
        "Creating WLST properties file failed");
    Properties p = new Properties();
    p.setProperty("admin_host", K8S_NODEPORT_HOST);
    p.setProperty("admin_port", Integer.toString(adminServerT3Port));
    p.setProperty("admin_username", ADMIN_USERNAME_DEFAULT);
    p.setProperty("admin_password", ADMIN_PASSWORD_DEFAULT);
    p.setProperty("cluster_name", clusterName);
    p.setProperty("new_admin_port", Integer.toString(newAdminPort));
    p.setProperty("test_name", "change_admin_port");
    assertDoesNotThrow(() -> p.store(new FileOutputStream(wlstPropertiesFile), "wlst properties file"),
        "Failed to write the WLST properties to file");

    // change the admin server port to a different value to force pod restart
    logger.info("changing the admin server port to a different value to force pod restart");
    Path configScript = Paths.get(RESOURCE_DIR, "python-scripts", "introspect_version_script.py");
    executeWLSTScript(configScript, wlstPropertiesFile.toPath(), introDomainNamespace);

    assertTrue(assertDoesNotThrow(() ->
            patchDomainResourceWithNewIntrospectVersion(domainUid, introDomainNamespace),
        "Patch domain with new IntrospectVersion threw ApiException"),
        "Failed to patch domain with new IntrospectVersion");

    //verify the introspector pod is created and runs
    String introspectPodName = domainUid + "-" + "introspect-domain-job";

    checkPodExists(introspectPodName, domainUid, introDomainNamespace);
    checkPodDoesNotExist(introspectPodName, domainUid, introDomainNamespace);

    //verify the pods are restarted
    verifyRollingRestartOccurred(pods, 1, introDomainNamespace);
    
    // verify the admin server service created
    checkServiceExists(adminServerPodName, introDomainNamespace);

    // verify admin server pod is ready
    checkPodReady(adminServerPodName, domainUid, introDomainNamespace);

    // verify managed server services created
    for (int i = 1; i <= replicaCount; i++) {
      logger.info("Checking managed server service {0} is created in namespace {1}",
          managedServerPodNamePrefix + i, introDomainNamespace);
      checkServiceExists(managedServerPodNamePrefix + i, introDomainNamespace);
    }

    // verify managed server pods are ready
    for (int i = 1; i <= replicaCount; i++) {
      logger.info("Waiting for managed server pod {0} to be ready in namespace {1}",
          managedServerPodNamePrefix + i, introDomainNamespace);
      checkPodReady(managedServerPodNamePrefix + i, domainUid, introDomainNamespace);
    }

    // verify the admin port is changed to newAdminPort
    assertEquals(newAdminPort, assertDoesNotThrow(()
        -> getServicePort(introDomainNamespace, adminServerPodName + "-external", "default"),
        "Getting admin server port failed"),
        "Updated admin server port is not equal to expected value");

    logger.info("Getting node port for default channel");
    int adminServerNodePort = assertDoesNotThrow(()
        -> getServiceNodePort(introDomainNamespace, adminServerPodName + "-external", "default"),
        "Getting admin server node port failed");

    //access application from admin server to validate the new port
    String url = "http://" + K8S_NODEPORT_HOST + ":" + adminServerNodePort + "/testwebapp/index.jsp";
    assertEquals(200,
        assertDoesNotThrow(() -> OracleHttpClient.get(url, true),
            "Accessing sample application on admin server failed")
            .statusCode(), "Status code not equals to 200");

    logger.info("Getting the list of servers using the listServers");
    String baseUri = "http://" + K8S_NODEPORT_HOST + ":" + adminServerNodePort + "/clusterview/";
    String serverListUri = "ClusterViewServlet?listServers=true";
    for (int i = 0; i < 5; i++) {
      assertDoesNotThrow(() -> TimeUnit.SECONDS.sleep(30));
      HttpResponse<String> response = assertDoesNotThrow(() -> OracleHttpClient.get(baseUri + serverListUri, true));
      assertEquals(200, response.statusCode(), "Status code not equals to 200");
    }

    //access application in managed servers through NGINX load balancer
    logger.info("Accessing the clusterview app through NGINX load balancer");
    String curlRequest = String.format("curl --silent --show-error --noproxy '*' "
            + "-H 'host: %s' http://%s:%s/clusterview/ClusterViewServlet",
        domainUid + "." + introDomainNamespace + "." + clusterName + ".test", K8S_NODEPORT_HOST, nodeportshttp);
    List<String> managedServers = new ArrayList<>();
    for (int i = 1; i <= replicaCount; i++) {
      managedServers.add(managedServerNameBase + i);
    }
    assertThat(verifyClusterMemberCommunication(curlRequest, managedServers, 20))
        .as("Verify all managed servers can see each other")
        .withFailMessage("managed servers cannot see other")
        .isTrue();

  }
/**
   * Test server pods are rolling restarted and updated when domain is patched
   * with introSpectVersion when non dynamic changes are made.
   * Updates the admin server listen port using online WLST.
   * Patches the domain custom resource with introSpectVersion.
   * Verifies the introspector runs and pods are restated in a rolling fashion.
   * Verifies the new admin port of the admin server in services.
   * Verifies accessing sample application in admin server works.
   */
Test server pods are rolling restarted and updated when domain is patched
with introSpectVersion when non dynamic changes are made.
Updates the admin server listen port using online WLST.
Patches the domain custom resource with introSpectVersion.
Verifies the introspector runs and pods are restated in a rolling fashion.
Verifies the new admin port of the admin server in services.
Verifies accessing sample application in admin server works.
Test server pods are rolling restarted and updated when domain is patched with introSpectVersion when non dynamic changes are made . Updates the admin server listen port using online WLST . Patches the domain custom resource with introSpectVersion . Verifies the introspector runs and pods are restated in a rolling fashion . Verifies the new admin port of the admin server in services . Verifies accessing sample application in admin server works .
@Order(2)
  @Test
  @DisplayName("Test introspectVersion rolling server pods when admin server port is changed")
  public void testDomainIntrospectVersionRolling() {
    final String domainUid = "mydomain";
    final String clusterName = "mycluster";
    final String adminServerName = "admin-server";
    final String adminServerPodName = domainUid + "-" + adminServerName;
    final String managedServerNameBase = "ms-";
    String managedServerPodNamePrefix = domainUid + "-" + managedServerNameBase;
    final int replicaCount = 3;
    final int newAdminPort = 7005;
    LinkedHashMap<String, DateTime> pods = new LinkedHashMap<>();
    DateTime adminPodCreationTime = getPodCreationTime(introDomainNamespace, adminServerPodName);
    pods.put(adminServerPodName, adminPodCreationTime);
    for (int i = 1; i <= replicaCount; i++) {
      pods.put(managedServerPodNamePrefix + i,
          getPodCreationTime(introDomainNamespace, managedServerPodNamePrefix + i));
    }
    logger.info("Getting node port for default channel");
    int adminServerT3Port = assertDoesNotThrow(()
        -> getServiceNodePort(introDomainNamespace, adminServerPodName + "-external", "t3channel"),
        "Getting admin server node port failed");
    File wlstPropertiesFile = assertDoesNotThrow(() -> File.createTempFile("wlst", "properties"),
        "Creating WLST properties file failed");
    Properties p = new Properties();
    p.setProperty("admin_host", K8S_NODEPORT_HOST);
    p.setProperty("admin_port", Integer.toString(adminServerT3Port));
    p.setProperty("admin_username", ADMIN_USERNAME_DEFAULT);
    p.setProperty("admin_password", ADMIN_PASSWORD_DEFAULT);
    p.setProperty("cluster_name", clusterName);
    p.setProperty("new_admin_port", Integer.toString(newAdminPort));
    p.setProperty("test_name", "change_admin_port");
    assertDoesNotThrow(() -> p.store(new FileOutputStream(wlstPropertiesFile), "wlst properties file"),
        "Failed to write the WLST properties to file");
    logger.info("changing the admin server port to a different value to force pod restart");
    Path configScript = Paths.get(RESOURCE_DIR, "python-scripts", "introspect_version_script.py");
    executeWLSTScript(configScript, wlstPropertiesFile.toPath(), introDomainNamespace);
    assertTrue(assertDoesNotThrow(() ->
            patchDomainResourceWithNewIntrospectVersion(domainUid, introDomainNamespace),
        "Patch domain with new IntrospectVersion threw ApiException"),
        "Failed to patch domain with new IntrospectVersion");
    String introspectPodName = domainUid + "-" + "introspect-domain-job";
    checkPodExists(introspectPodName, domainUid, introDomainNamespace);
    checkPodDoesNotExist(introspectPodName, domainUid, introDomainNamespace);
    verifyRollingRestartOccurred(pods, 1, introDomainNamespace);
    checkServiceExists(adminServerPodName, introDomainNamespace);
    checkPodReady(adminServerPodName, domainUid, introDomainNamespace);
    for (int i = 1; i <= replicaCount; i++) {
      logger.info("Checking managed server service {0} is created in namespace {1}",
          managedServerPodNamePrefix + i, introDomainNamespace);
      checkServiceExists(managedServerPodNamePrefix + i, introDomainNamespace);
    }
    for (int i = 1; i <= replicaCount; i++) {
      logger.info("Waiting for managed server pod {0} to be ready in namespace {1}",
          managedServerPodNamePrefix + i, introDomainNamespace);
      checkPodReady(managedServerPodNamePrefix + i, domainUid, introDomainNamespace);
    }
    assertEquals(newAdminPort, assertDoesNotThrow(()
        -> getServicePort(introDomainNamespace, adminServerPodName + "-external", "default"),
        "Getting admin server port failed"),
        "Updated admin server port is not equal to expected value");
    logger.info("Getting node port for default channel");
    int adminServerNodePort = assertDoesNotThrow(()
        -> getServiceNodePort(introDomainNamespace, adminServerPodName + "-external", "default"),
        "Getting admin server node port failed");
    String url = "http://" + K8S_NODEPORT_HOST + ":" + adminServerNodePort + "/testwebapp/index.jsp";
    assertEquals(200,
        assertDoesNotThrow(() -> OracleHttpClient.get(url, true),
            "Accessing sample application on admin server failed")
            .statusCode(), "Status code not equals to 200");
    logger.info("Getting the list of servers using the listServers");
    String baseUri = "http://" + K8S_NODEPORT_HOST + ":" + adminServerNodePort + "/clusterview/";
    String serverListUri = "ClusterViewServlet?listServers=true";
    for (int i = 0; i < 5; i++) {
      assertDoesNotThrow(() -> TimeUnit.SECONDS.sleep(30));
      HttpResponse<String> response = assertDoesNotThrow(() -> OracleHttpClient.get(baseUri + serverListUri, true));
      assertEquals(200, response.statusCode(), "Status code not equals to 200");
    }
    logger.info("Accessing the clusterview app through NGINX load balancer");
    String curlRequest = String.format("curl --silent --show-error --noproxy '*' "
            + "-H 'host: %s' http://%s:%s/clusterview/ClusterViewServlet",
        domainUid + "." + introDomainNamespace + "." + clusterName + ".test", K8S_NODEPORT_HOST, nodeportshttp);
    List<String> managedServers = new ArrayList<>();
    for (int i = 1; i <= replicaCount; i++) {
      managedServers.add(managedServerNameBase + i);
    }
    assertThat(verifyClusterMemberCommunication(curlRequest, managedServers, 20))
        .as("Verify all managed servers can see each other")
        .withFailMessage("managed servers cannot see other")
        .isTrue();
  }
@ Order ( 2 ) @ Test @ DisplayName ( "Test introspectVersion rolling server pods when admin server port is changed" ) public void testDomainIntrospectVersionRolling ( ) { final String domainUid = "mydomain" ; final String clusterName = "mycluster" ; final String adminServerName = "admin-server" ; final String adminServerPodName = domainUid + "-" + adminServerName ; final String managedServerNameBase = "ms-" ; String managedServerPodNamePrefix = domainUid + "-" + managedServerNameBase ; final int replicaCount = 3 ; final int newAdminPort = 7005 ; LinkedHashMap < String , DateTime > pods = new LinkedHashMap < > ( ) ; DateTime adminPodCreationTime = getPodCreationTime ( introDomainNamespace , adminServerPodName ) ; pods . put ( adminServerPodName , adminPodCreationTime ) ; for ( int i = 1 ; i <= replicaCount ; i ++ ) { pods . put ( managedServerPodNamePrefix + i , getPodCreationTime ( introDomainNamespace , managedServerPodNamePrefix + i ) ) ; } logger . info ( "Getting node port for default channel" ) ; int adminServerT3Port = assertDoesNotThrow ( ( ) -> getServiceNodePort ( introDomainNamespace , adminServerPodName + "-external" , "t3channel" ) , "Getting admin server node port failed" ) ; File wlstPropertiesFile = assertDoesNotThrow ( ( ) -> File . createTempFile ( "wlst" , "properties" ) , "Creating WLST properties file failed" ) ; Properties p = new Properties ( ) ; p . setProperty ( "admin_host" , K8S_NODEPORT_HOST ) ; p . setProperty ( "admin_port" , Integer . toString ( adminServerT3Port ) ) ; p . setProperty ( "admin_username" , ADMIN_USERNAME_DEFAULT ) ; p . setProperty ( "admin_password" , ADMIN_PASSWORD_DEFAULT ) ; p . setProperty ( "cluster_name" , clusterName ) ; p . setProperty ( "new_admin_port" , Integer . toString ( newAdminPort ) ) ; p . setProperty ( "test_name" , "change_admin_port" ) ; assertDoesNotThrow ( ( ) -> p . store ( new FileOutputStream ( wlstPropertiesFile ) , "wlst properties file" ) , "Failed to write the WLST properties to file" ) ; logger . info ( "changing the admin server port to a different value to force pod restart" ) ; Path configScript = Paths . get ( RESOURCE_DIR , "python-scripts" , "introspect_version_script.py" ) ; executeWLSTScript ( configScript , wlstPropertiesFile . toPath ( ) , introDomainNamespace ) ; assertTrue ( assertDoesNotThrow ( ( ) -> patchDomainResourceWithNewIntrospectVersion ( domainUid , introDomainNamespace ) , "Patch domain with new IntrospectVersion threw ApiException" ) , "Failed to patch domain with new IntrospectVersion" ) ; String introspectPodName = domainUid + "-" + "introspect-domain-job" ; checkPodExists ( introspectPodName , domainUid , introDomainNamespace ) ; checkPodDoesNotExist ( introspectPodName , domainUid , introDomainNamespace ) ; verifyRollingRestartOccurred ( pods , 1 , introDomainNamespace ) ; checkServiceExists ( adminServerPodName , introDomainNamespace ) ; checkPodReady ( adminServerPodName , domainUid , introDomainNamespace ) ; for ( int i = 1 ; i <= replicaCount ; i ++ ) { logger . info ( "Checking managed server service {0} is created in namespace {1}" , managedServerPodNamePrefix + i , introDomainNamespace ) ; checkServiceExists ( managedServerPodNamePrefix + i , introDomainNamespace ) ; } for ( int i = 1 ; i <= replicaCount ; i ++ ) { logger . info ( "Waiting for managed server pod {0} to be ready in namespace {1}" , managedServerPodNamePrefix + i , introDomainNamespace ) ; checkPodReady ( managedServerPodNamePrefix + i , domainUid , introDomainNamespace ) ; } assertEquals ( newAdminPort , assertDoesNotThrow ( ( ) -> getServicePort ( introDomainNamespace , adminServerPodName + "-external" , "default" ) , "Getting admin server port failed" ) , "Updated admin server port is not equal to expected value" ) ; logger . info ( "Getting node port for default channel" ) ; int adminServerNodePort = assertDoesNotThrow ( ( ) -> getServiceNodePort ( introDomainNamespace , adminServerPodName + "-external" , "default" ) , "Getting admin server node port failed" ) ; String url = "http://" + K8S_NODEPORT_HOST + ":" + adminServerNodePort + "/testwebapp/index.jsp" ; assertEquals ( 200 , assertDoesNotThrow ( ( ) -> OracleHttpClient . get ( url , true ) , "Accessing sample application on admin server failed" ) . statusCode ( ) , "Status code not equals to 200" ) ; logger . info ( "Getting the list of servers using the listServers" ) ; String baseUri = "http://" + K8S_NODEPORT_HOST + ":" + adminServerNodePort + "/clusterview/" ; String serverListUri = "ClusterViewServlet?listServers=true" ; for ( int i = 0 ; i < 5 ; i ++ ) { assertDoesNotThrow ( ( ) -> TimeUnit . SECONDS . sleep ( 30 ) ) ; HttpResponse < String > response = assertDoesNotThrow ( ( ) -> OracleHttpClient . get ( baseUri + serverListUri , true ) ) ; assertEquals ( 200 , response . statusCode ( ) , "Status code not equals to 200" ) ; } logger . info ( "Accessing the clusterview app through NGINX load balancer" ) ; String curlRequest = String . format ( "curl --silent --show-error --noproxy '*' " + "-H 'host: %s' http://%s:%s/clusterview/ClusterViewServlet" , domainUid + "." + introDomainNamespace + "." + clusterName + ".test" , K8S_NODEPORT_HOST , nodeportshttp ) ; List < String > managedServers = new ArrayList < > ( ) ; for ( int i = 1 ; i <= replicaCount ; i ++ ) { managedServers . add ( managedServerNameBase + i ) ; } assertThat ( verifyClusterMemberCommunication ( curlRequest , managedServers , 20 ) ) . as ( "Verify all managed servers can see each other" ) . withFailMessage ( "managed servers cannot see other" ) . isTrue ( ) ; }
Test server pods are rolling restarted and updated when domain is patched
 with introSpectVersion when non dynamic changes are made.
Test server pods are rolling restarted and updated when domain is patched with introSpectVersion when non dynamic changes are made .
// get the pod creation time stamps // get the creation time of the admin server pod before patching // get the creation time of the managed server pods before patching // create a temporary WebLogic WLST property file // change the admin server port to a different value to force pod restart //verify the introspector pod is created and runs //verify the pods are restarted // verify the admin server service created // verify admin server pod is ready // verify managed server services created // verify managed server pods are ready // verify the admin port is changed to newAdminPort //access application from admin server to validate the new port //access application in managed servers through NGINX load balancer