new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItIntrospectVersion.java
@Order(3)
  @Test
  @DisplayName("Test new cluster creation on demand using WLST and introspection")
  public void testCreateNewCluster() {

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

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

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

    final int replicaCount = 2;

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

    // 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("test_name", "create_cluster");
    p.setProperty("cluster_name", clusterName);
    p.setProperty("server_prefix", managedServerNameBase);
    p.setProperty("server_count", "3");
    assertDoesNotThrow(() -> p.store(new FileOutputStream(wlstPropertiesFile), "wlst properties file"),
        "Failed to write the WLST properties to file");

    // changet 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);

    String introspectVersion = assertDoesNotThrow(() -> getNextIntrospectVersion(domainUid, introDomainNamespace));

    logger.info("patch the domain resource with new cluster and introspectVersion");
    String patchStr
        = "["
        + "{\"op\": \"add\",\"path\": \"/spec/clusters/-\", \"value\": "
        + "    {\"clusterName\" : \"" + clusterName + "\", \"replicas\": 2, \"serverStartState\": \"RUNNING\"}"
        + "},"
        + "{\"op\": \"replace\", \"path\": \"/spec/introspectVersion\", \"value\": \"" + introspectVersion + "\"}"
        + "]";
    logger.info("Updating domain configuration using patch string: {0}\n", patchStr);
    V1Patch patch = new V1Patch(patchStr);
    assertTrue(patchDomainCustomResource(domainUid, introDomainNamespace, patch, V1Patch.PATCH_FORMAT_JSON_PATCH),
        "Failed to patch domain");

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

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

    // verify new cluster 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 new cluster 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);
    }

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

    // verify managed server pods are ready
    for (int i = 1; i <= replicaCount; i++) {
      logger.info("Checking {0} health", managedServerNameBase + i);
      assertTrue(response.body().contains(managedServerNameBase + i + ":HEALTH_OK"),
          "Didn't get " + managedServerNameBase + i + ":HEALTH_OK");
    }

  }
/**
   * Test brings up a new cluster and verifies it can successfully start by doing the following.
   * a. Creates new WebLogic static cluster using WLST.
   * b. Patch the Domain Resource with cluster
   * c. Update the introspectVersion version
   * d. Verifies the servers in the new WebLogic cluster comes up without affecting any of the running servers on
   * pre-existing WebLogic cluster.
   */
Test brings up a new cluster and verifies it can successfully start by doing the following.
a. Creates new WebLogic static cluster using WLST.
b. Patch the Domain Resource with cluster
c. Update the introspectVersion version
d. Verifies the servers in the new WebLogic cluster comes up without affecting any of the running servers on
pre-existing WebLogic cluster.
Test brings up a new cluster and verifies it can successfully start by doing the following . a . Creates new WebLogic static cluster using WLST . b . Patch the Domain Resource with cluster c . Update the introspectVersion version d . Verifies the servers in the new WebLogic cluster comes up without affecting any of the running servers on pre - existing WebLogic cluster .
@Order(3)
  @Test
  @DisplayName("Test new cluster creation on demand using WLST and introspection")
  public void testCreateNewCluster() {
    final String domainUid = "mydomain";
    final String clusterName = "cl2";
    final String adminServerName = "admin-server";
    final String adminServerPodName = domainUid + "-" + adminServerName;
    final String managedServerNameBase = "cl2-ms-";
    String managedServerPodNamePrefix = domainUid + "-" + managedServerNameBase;
    final int replicaCount = 2;
    logger.info("Getting node port for default channel");
    int adminServerT3Port = getServiceNodePort(introDomainNamespace, adminServerPodName + "-external", "t3channel");
    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("test_name", "create_cluster");
    p.setProperty("cluster_name", clusterName);
    p.setProperty("server_prefix", managedServerNameBase);
    p.setProperty("server_count", "3");
    assertDoesNotThrow(() -> p.store(new FileOutputStream(wlstPropertiesFile), "wlst properties file"),
        "Failed to write the WLST properties to file");
    Path configScript = Paths.get(RESOURCE_DIR, "python-scripts", "introspect_version_script.py");
    executeWLSTScript(configScript, wlstPropertiesFile.toPath(), introDomainNamespace);
    String introspectVersion = assertDoesNotThrow(() -> getNextIntrospectVersion(domainUid, introDomainNamespace));
    logger.info("patch the domain resource with new cluster and introspectVersion");
    String patchStr
        = "["
        + "{\"op\": \"add\",\"path\": \"/spec/clusters/-\", \"value\": "
        + "    {\"clusterName\" : \"" + clusterName + "\", \"replicas\": 2, \"serverStartState\": \"RUNNING\"}"
        + "},"
        + "{\"op\": \"replace\", \"path\": \"/spec/introspectVersion\", \"value\": \"" + introspectVersion + "\"}"
        + "]";
    logger.info("Updating domain configuration using patch string: {0}\n", patchStr);
    V1Patch patch = new V1Patch(patchStr);
    assertTrue(patchDomainCustomResource(domainUid, introDomainNamespace, patch, V1Patch.PATCH_FORMAT_JSON_PATCH),
        "Failed to patch domain");
    String introspectPodName = domainUid + "-" + "introspect-domain-job";
    checkPodExists(introspectPodName, domainUid, introDomainNamespace);
    checkPodDoesNotExist(introspectPodName, 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);
    }
    logger.info("Getting the list of servers using the listServers");
    String baseUri = "http://" + K8S_NODEPORT_HOST + ":" + adminServerT3Port + "/clusterview/";
    String serverListUri = "ClusterViewServlet?listServers=true";
    HttpResponse<String> response = null;
    for (int i = 0; i < 5; i++) {
      assertDoesNotThrow(() -> TimeUnit.SECONDS.sleep(30));
      response = assertDoesNotThrow(() -> OracleHttpClient.get(baseUri + serverListUri, true));
      assertEquals(200, response.statusCode(), "Status code not equals to 200");
    }
    for (int i = 1; i <= replicaCount; i++) {
      logger.info("Checking {0} health", managedServerNameBase + i);
      assertTrue(response.body().contains(managedServerNameBase + i + ":HEALTH_OK"),
          "Didn't get " + managedServerNameBase + i + ":HEALTH_OK");
    }
  }
@ Order ( 3 ) @ Test @ DisplayName ( "Test new cluster creation on demand using WLST and introspection" ) public void testCreateNewCluster ( ) { final String domainUid = "mydomain" ; final String clusterName = "cl2" ; final String adminServerName = "admin-server" ; final String adminServerPodName = domainUid + "-" + adminServerName ; final String managedServerNameBase = "cl2-ms-" ; String managedServerPodNamePrefix = domainUid + "-" + managedServerNameBase ; final int replicaCount = 2 ; logger . info ( "Getting node port for default channel" ) ; int adminServerT3Port = getServiceNodePort ( introDomainNamespace , adminServerPodName + "-external" , "t3channel" ) ; 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 ( "test_name" , "create_cluster" ) ; p . setProperty ( "cluster_name" , clusterName ) ; p . setProperty ( "server_prefix" , managedServerNameBase ) ; p . setProperty ( "server_count" , "3" ) ; assertDoesNotThrow ( ( ) -> p . store ( new FileOutputStream ( wlstPropertiesFile ) , "wlst properties file" ) , "Failed to write the WLST properties to file" ) ; Path configScript = Paths . get ( RESOURCE_DIR , "python-scripts" , "introspect_version_script.py" ) ; executeWLSTScript ( configScript , wlstPropertiesFile . toPath ( ) , introDomainNamespace ) ; String introspectVersion = assertDoesNotThrow ( ( ) -> getNextIntrospectVersion ( domainUid , introDomainNamespace ) ) ; logger . info ( "patch the domain resource with new cluster and introspectVersion" ) ; String patchStr = "[" + "{\"op\": \"add\",\"path\": \"/spec/clusters/-\", \"value\": " + "    {\"clusterName\" : \"" + clusterName + "\", \"replicas\": 2, \"serverStartState\": \"RUNNING\"}" + "}," + "{\"op\": \"replace\", \"path\": \"/spec/introspectVersion\", \"value\": \"" + introspectVersion + "\"}" + "]" ; logger . info ( "Updating domain configuration using patch string: {0}\n" , patchStr ) ; V1Patch patch = new V1Patch ( patchStr ) ; assertTrue ( patchDomainCustomResource ( domainUid , introDomainNamespace , patch , V1Patch . PATCH_FORMAT_JSON_PATCH ) , "Failed to patch domain" ) ; String introspectPodName = domainUid + "-" + "introspect-domain-job" ; checkPodExists ( introspectPodName , domainUid , introDomainNamespace ) ; checkPodDoesNotExist ( introspectPodName , 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 ) ; } logger . info ( "Getting the list of servers using the listServers" ) ; String baseUri = "http://" + K8S_NODEPORT_HOST + ":" + adminServerT3Port + "/clusterview/" ; String serverListUri = "ClusterViewServlet?listServers=true" ; HttpResponse < String > response = null ; for ( int i = 0 ; i < 5 ; i ++ ) { assertDoesNotThrow ( ( ) -> TimeUnit . SECONDS . sleep ( 30 ) ) ; response = assertDoesNotThrow ( ( ) -> OracleHttpClient . get ( baseUri + serverListUri , true ) ) ; assertEquals ( 200 , response . statusCode ( ) , "Status code not equals to 200" ) ; } for ( int i = 1 ; i <= replicaCount ; i ++ ) { logger . info ( "Checking {0} health" , managedServerNameBase + i ) ; assertTrue ( response . body ( ) . contains ( managedServerNameBase + i + ":HEALTH_OK" ) , "Didn't get " + managedServerNameBase + i + ":HEALTH_OK" ) ; } }
Test brings up a new cluster and verifies it can successfully start by doing the following.
Test brings up a new cluster and verifies it can successfully start by doing the following .
// create a temporary WebLogic WLST property file // changet the admin server port to a different value to force pod restart //verify the introspector pod is created and runs // verify new cluster managed server services created // verify new cluster managed server pods are ready // verify managed server pods are ready