new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiAddCluster.java
@Test
  @Order(2)
  @DisplayName("Add a dynamic cluster to model in image domain")
  @Slow
  @MustNotRunInParallel
  public void testAddMiiDynamicCluster() {

    // This test uses the WebLogic domain created in BeforeAll method
    // BeforeEach method ensures that the server pods are running

    String configMapName = "dynamicclusterconfigmap";
    createClusterConfigMap(configMapName, "model.dynamic.cluster.yaml");

    LinkedHashMap<String, DateTime> pods = new LinkedHashMap<>();
    // get the creation time of the admin server pod before patching
    DateTime adminPodCreationTime = getPodCreationTime(domainNamespace, 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(managedServerPrefix + i, getPodCreationTime(domainNamespace, managedServerPrefix + i));
    }

    StringBuffer patchStr = null;
    patchStr = new StringBuffer("[{");
    patchStr.append("\"op\": \"replace\",")
        .append(" \"path\": \"/spec/configuration/model/configMap\",")
        .append(" \"value\":  \"" + configMapName + "\"")
        .append(" }]");
    logger.log(Level.INFO, "Configmap patch string: {0}", patchStr);

    patch = new V1Patch(new String(patchStr));
    boolean cmPatched = assertDoesNotThrow(() ->
            patchDomainCustomResource(domainUid, domainNamespace, patch, "application/json-patch+json"),
        "patchDomainCustomResource(configMap)  failed ");
    assertTrue(cmPatched, "patchDomainCustomResource(configMap) failed");

    patchStr = new StringBuffer("[{");
    patchStr.append(" \"op\": \"replace\",")
        .append(" \"path\": \"/spec/replicas\",")
        .append(" \"value\": 1")
        .append(" }]");
    logger.log(Level.INFO, "Replicas patch string: {0}", patchStr);

    patch = new V1Patch(new String(patchStr));
    boolean repilcaPatched = assertDoesNotThrow(() ->
            patchDomainCustomResource(domainUid, domainNamespace, patch, "application/json-patch+json"),
        "patchDomainCustomResource(restartVersion)  failed ");
    assertTrue(repilcaPatched, "patchDomainCustomResource(repilcas) failed");

    String newRestartVersion = patchDomainResourceWithNewRestartVersion(domainUid, domainNamespace);
    logger.log(Level.INFO, "New restart version : {0}", newRestartVersion);

    // Check if the admin server pod has been restarted
    // by comparing the PodCreationTime before and after rolling restart

    assertTrue(assertDoesNotThrow(
        () -> (verifyRollingRestartOccurred(pods, 1, domainNamespace)),
         "More than one pod was restarted at same time"),
        "Rolling restart failed");

    // The ServerNamePrefix for the new dynamic cluster is dynamic-server
    // Make sure the managed server from the new cluster is running

    String newServerPodName = domainUid + "-dynamic-server1";
    checkPodReady(newServerPodName, domainUid, domainNamespace);
    checkServiceExists(newServerPodName, domainNamespace);

    boolean isServerConfigured = checkManagedServerConfiguration("dynamic-server1");
    assertTrue(isServerConfigured, "Could not find new managed server configuration");
    logger.info("Found new managed server configuration");
  }
/**
   * Create a configmap with a sparse model file to add a dynamic cluster.
   * Patch the domain resource with the configmap.
   * Update the restart version of the domain resource to 2.
   * Patch the domain resource with the spec/replicas set to 1.
   * Verify rolling restart of the domain by comparing PodCreationTimestamp
   * before and after rolling restart.
   * Verify servers from new cluster are in running state.
   */
Create a configmap with a sparse model file to add a dynamic cluster.
Patch the domain resource with the configmap.
Update the restart version of the domain resource to 2.
Patch the domain resource with the spec/replicas set to 1.
Verify rolling restart of the domain by comparing PodCreationTimestamp
before and after rolling restart.
Verify servers from new cluster are in running state.
Create a configmap with a sparse model file to add a dynamic cluster . Patch the domain resource with the configmap . Update the restart version of the domain resource to 2 . Patch the domain resource with the spec / replicas set to 1 . Verify rolling restart of the domain by comparing PodCreationTimestamp before and after rolling restart . Verify servers from new cluster are in running state .
@Test
  @Order(2)
  @DisplayName("Add a dynamic cluster to model in image domain")
  @Slow
  @MustNotRunInParallel
  public void testAddMiiDynamicCluster() {
    String configMapName = "dynamicclusterconfigmap";
    createClusterConfigMap(configMapName, "model.dynamic.cluster.yaml");
    LinkedHashMap<String, DateTime> pods = new LinkedHashMap<>();
    DateTime adminPodCreationTime = getPodCreationTime(domainNamespace, adminServerPodName);
    pods.put(adminServerPodName, adminPodCreationTime);
    for (int i = 1; i <= replicaCount; i++) {
      pods.put(managedServerPrefix + i, getPodCreationTime(domainNamespace, managedServerPrefix + i));
    }
    StringBuffer patchStr = null;
    patchStr = new StringBuffer("[{");
    patchStr.append("\"op\": \"replace\",")
        .append(" \"path\": \"/spec/configuration/model/configMap\",")
        .append(" \"value\":  \"" + configMapName + "\"")
        .append(" }]");
    logger.log(Level.INFO, "Configmap patch string: {0}", patchStr);
    patch = new V1Patch(new String(patchStr));
    boolean cmPatched = assertDoesNotThrow(() ->
            patchDomainCustomResource(domainUid, domainNamespace, patch, "application/json-patch+json"),
        "patchDomainCustomResource(configMap)  failed ");
    assertTrue(cmPatched, "patchDomainCustomResource(configMap) failed");
    patchStr = new StringBuffer("[{");
    patchStr.append(" \"op\": \"replace\",")
        .append(" \"path\": \"/spec/replicas\",")
        .append(" \"value\": 1")
        .append(" }]");
    logger.log(Level.INFO, "Replicas patch string: {0}", patchStr);
    patch = new V1Patch(new String(patchStr));
    boolean repilcaPatched = assertDoesNotThrow(() ->
            patchDomainCustomResource(domainUid, domainNamespace, patch, "application/json-patch+json"),
        "patchDomainCustomResource(restartVersion)  failed ");
    assertTrue(repilcaPatched, "patchDomainCustomResource(repilcas) failed");
    String newRestartVersion = patchDomainResourceWithNewRestartVersion(domainUid, domainNamespace);
    logger.log(Level.INFO, "New restart version : {0}", newRestartVersion);
    assertTrue(assertDoesNotThrow(
        () -> (verifyRollingRestartOccurred(pods, 1, domainNamespace)),
         "More than one pod was restarted at same time"),
        "Rolling restart failed");
    String newServerPodName = domainUid + "-dynamic-server1";
    checkPodReady(newServerPodName, domainUid, domainNamespace);
    checkServiceExists(newServerPodName, domainNamespace);
    boolean isServerConfigured = checkManagedServerConfiguration("dynamic-server1");
    assertTrue(isServerConfigured, "Could not find new managed server configuration");
    logger.info("Found new managed server configuration");
  }
@ Test @ Order ( 2 ) @ DisplayName ( "Add a dynamic cluster to model in image domain" ) @ Slow @ MustNotRunInParallel public void testAddMiiDynamicCluster ( ) { String configMapName = "dynamicclusterconfigmap" ; createClusterConfigMap ( configMapName , "model.dynamic.cluster.yaml" ) ; LinkedHashMap < String , DateTime > pods = new LinkedHashMap < > ( ) ; DateTime adminPodCreationTime = getPodCreationTime ( domainNamespace , adminServerPodName ) ; pods . put ( adminServerPodName , adminPodCreationTime ) ; for ( int i = 1 ; i <= replicaCount ; i ++ ) { pods . put ( managedServerPrefix + i , getPodCreationTime ( domainNamespace , managedServerPrefix + i ) ) ; } StringBuffer patchStr = null ; patchStr = new StringBuffer ( "[{" ) ; patchStr . append ( "\"op\": \"replace\"," ) . append ( " \"path\": \"/spec/configuration/model/configMap\"," ) . append ( " \"value\":  \"" + configMapName + "\"" ) . append ( " }]" ) ; logger . log ( Level . INFO , "Configmap patch string: {0}" , patchStr ) ; patch = new V1Patch ( new String ( patchStr ) ) ; boolean cmPatched = assertDoesNotThrow ( ( ) -> patchDomainCustomResource ( domainUid , domainNamespace , patch , "application/json-patch+json" ) , "patchDomainCustomResource(configMap)  failed " ) ; assertTrue ( cmPatched , "patchDomainCustomResource(configMap) failed" ) ; patchStr = new StringBuffer ( "[{" ) ; patchStr . append ( " \"op\": \"replace\"," ) . append ( " \"path\": \"/spec/replicas\"," ) . append ( " \"value\": 1" ) . append ( " }]" ) ; logger . log ( Level . INFO , "Replicas patch string: {0}" , patchStr ) ; patch = new V1Patch ( new String ( patchStr ) ) ; boolean repilcaPatched = assertDoesNotThrow ( ( ) -> patchDomainCustomResource ( domainUid , domainNamespace , patch , "application/json-patch+json" ) , "patchDomainCustomResource(restartVersion)  failed " ) ; assertTrue ( repilcaPatched , "patchDomainCustomResource(repilcas) failed" ) ; String newRestartVersion = patchDomainResourceWithNewRestartVersion ( domainUid , domainNamespace ) ; logger . log ( Level . INFO , "New restart version : {0}" , newRestartVersion ) ; assertTrue ( assertDoesNotThrow ( ( ) -> ( verifyRollingRestartOccurred ( pods , 1 , domainNamespace ) ) , "More than one pod was restarted at same time" ) , "Rolling restart failed" ) ; String newServerPodName = domainUid + "-dynamic-server1" ; checkPodReady ( newServerPodName , domainUid , domainNamespace ) ; checkServiceExists ( newServerPodName , domainNamespace ) ; boolean isServerConfigured = checkManagedServerConfiguration ( "dynamic-server1" ) ; assertTrue ( isServerConfigured , "Could not find new managed server configuration" ) ; logger . info ( "Found new managed server configuration" ) ; }
Create a configmap with a sparse model file to add a dynamic cluster.
Create a configmap with a sparse model file to add a dynamic cluster .
// This test uses the WebLogic domain created in BeforeAll method // BeforeEach method ensures that the server pods are running // get the creation time of the admin server pod before patching // get the creation time of the managed server pods before patching // Check if the admin server pod has been restarted // by comparing the PodCreationTime before and after rolling restart // The ServerNamePrefix for the new dynamic cluster is dynamic-server // Make sure the managed server from the new cluster is running