new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItConfigDistributionStrategy.java
@Order(4)
  @Test
  @DisplayName("Test overrideDistributionStrategy value ON_RESTART")
  public void testOnRestartOverride() {

    //patching the domain with /spec/configuration/overrideDistributionStrategy: ON_RESTART
    String patchStr = "["
        + "{\"op\": \"add\", \"path\": \"/spec/configuration/overrideDistributionStrategy\", "
        + "\"value\": \"ON_RESTART\"}"
        + "]";
    logger.info("Updating domain configuration using patch string: {0}", patchStr);
    V1Patch patch = new V1Patch(patchStr);
    assertTrue(patchDomainCustomResource(domainUid, domainNamespace, patch, V1Patch.PATCH_FORMAT_JSON_PATCH),
        "Failed to patch domain");

    //TODO: - does changing overrideDistributionStrategy needs restart of server pods?
    restartDomain(); // if above is a bug, remove this after the above bug is fixed

    //store the pod creation timestamps
    storePodCreationTimestamps();

    logger.info("Creating secrets for JDBC datasource overrides");
    //create new secrets for jdbc datasource
    Map<String, String> secretMap = new HashMap<>();
    secretMap.put("dbusername", "root");
    secretMap.put("dbpassword", "root456");

    boolean secretCreated = assertDoesNotThrow(() -> createSecret(new V1Secret()
        .metadata(new V1ObjectMeta()
            .name(dsSecret)
            .namespace(domainNamespace))
        .stringData(secretMap)), "Creating secret for datasource failed.");
    assertTrue(secretCreated, String.format("creating secret failed %s", dsSecret));

    //copy the template datasource file for override after replacing JDBC_URL with new datasource url
    Path srcDsOverrideFile = Paths.get(RESOURCE_DIR, "configfiles/configoverridesset1/jdbc-JdbcTestDataSource-1.xml");
    Path dstDsOverrideFile = Paths.get(WORK_DIR, "jdbc-JdbcTestDataSource-1.xml");
    String tempString = assertDoesNotThrow(()
        -> Files.readString(srcDsOverrideFile).replaceAll("JDBC_URL", dsUrl2));
    assertDoesNotThrow(()
        -> Files.write(dstDsOverrideFile, tempString.getBytes(StandardCharsets.UTF_8)));

    List<Path> overrideFiles = new ArrayList<>();
    overrideFiles.add(dstDsOverrideFile);
    overrideFiles.add(Paths.get(RESOURCE_DIR, "configfiles/configoverridesset1/config.xml"));
    overrideFiles.add(Paths.get(RESOURCE_DIR, "configfiles/configoverridesset1/version.txt"));

    //create config override map
    createConfigMapFromFiles(overridecm, overrideFiles, domainNamespace);

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

    //patch the domain resource with overridesConfigMap, secrets and introspectVersion
    patchStr
        = "["
        + "{\"op\": \"add\", \"path\": \"/spec/configuration/overridesConfigMap\", \"value\": \"" + overridecm + "\"},"
        + "{\"op\": \"add\", \"path\": \"/spec/configuration/secrets\", \"value\": [\"" + dsSecret + "\"]  },"
        + "{\"op\": \"replace\", \"path\": \"/spec/introspectVersion\", \"value\": \"" + introspectVersion + "\"}"
        + "]";
    logger.info("Updating domain configuration using patch string: {0}", patchStr);
    patch = new V1Patch(patchStr);
    assertTrue(patchDomainCustomResource(domainUid, domainNamespace, patch, V1Patch.PATCH_FORMAT_JSON_PATCH),
        "Failed to patch domain");

    verifyIntrospectorRuns();
    verifyPodsStateNotChanged();

    try {
      //wait for a minute to see if the overrides are not applied
      TimeUnit.MINUTES.sleep(1);
    } catch (InterruptedException ex) {
      //ignore
    }

    //verify the overrides are not applied
    verifyConfigXMLOverride(false);
    verifyResourceJDBC0Override(false);

    //restart domain for the distributionstrategy to take effect
    restartDomain();

    //verify on restart the overrides are applied
    verifyConfigXMLOverride(true);
    verifyResourceJDBC1Override(true);

    //cleanup secret
    deleteSecret(dsSecret, domainNamespace);
    patchStr
        = "["
        + "{\"op\": \"remove\", \"path\": \"/spec/configuration/overrideDistributionStrategy\"},"
        + "{\"op\": \"remove\", \"path\": \"/spec/configuration/secrets\"}"
        + "]";
    logger.info("Updating domain configuration using patch string: {0}", patchStr);
    patch = new V1Patch(patchStr);
    assertTrue(patchDomainCustomResource(domainUid, domainNamespace, patch, V1Patch.PATCH_FORMAT_JSON_PATCH),
        "Failed to patch domain");
  }
/**
   * Test server configuration and JDBC datasource configurations are overridden on restart of pods when
   * /spec/configuration/overrideDistributionStrategy is set to ON_RESTART.
   *
   * <p>Test sets the above field to ON_RESTART and overrides the /spec/configuration/overridesConfigMap and
   * /spec/configuration/secrets with new configuration and new secrets.
   *
   * <p>Verifies after introspector runs the server configuration and JDBC datasource configurations are not
   * updated. Verifies the overrides are applied only after a domain restart.
   */
Test server configuration and JDBC datasource configurations are overridden on restart of pods when
/spec/configuration/overrideDistributionStrategy is set to ON_RESTART.



Verifies after introspector runs the server configuration and JDBC datasource configurations are not
updated. Verifies the overrides are applied only after a domain restart.
Test server configuration and JDBC datasource configurations are overridden on restart of pods when / spec / configuration / overrideDistributionStrategy is set to ON_RESTART . Verifies after introspector runs the server configuration and JDBC datasource configurations are not updated . Verifies the overrides are applied only after a domain restart .
@Order(4)
  @Test
  @DisplayName("Test overrideDistributionStrategy value ON_RESTART")
  public void testOnRestartOverride() {
    String patchStr = "["
        + "{\"op\": \"add\", \"path\": \"/spec/configuration/overrideDistributionStrategy\", "
        + "\"value\": \"ON_RESTART\"}"
        + "]";
    logger.info("Updating domain configuration using patch string: {0}", patchStr);
    V1Patch patch = new V1Patch(patchStr);
    assertTrue(patchDomainCustomResource(domainUid, domainNamespace, patch, V1Patch.PATCH_FORMAT_JSON_PATCH),
        "Failed to patch domain");
    restartDomain(); 
    storePodCreationTimestamps();
    logger.info("Creating secrets for JDBC datasource overrides");
    Map<String, String> secretMap = new HashMap<>();
    secretMap.put("dbusername", "root");
    secretMap.put("dbpassword", "root456");
    boolean secretCreated = assertDoesNotThrow(() -> createSecret(new V1Secret()
        .metadata(new V1ObjectMeta()
            .name(dsSecret)
            .namespace(domainNamespace))
        .stringData(secretMap)), "Creating secret for datasource failed.");
    assertTrue(secretCreated, String.format("creating secret failed %s", dsSecret));
    Path srcDsOverrideFile = Paths.get(RESOURCE_DIR, "configfiles/configoverridesset1/jdbc-JdbcTestDataSource-1.xml");
    Path dstDsOverrideFile = Paths.get(WORK_DIR, "jdbc-JdbcTestDataSource-1.xml");
    String tempString = assertDoesNotThrow(()
        -> Files.readString(srcDsOverrideFile).replaceAll("JDBC_URL", dsUrl2));
    assertDoesNotThrow(()
        -> Files.write(dstDsOverrideFile, tempString.getBytes(StandardCharsets.UTF_8)));
    List<Path> overrideFiles = new ArrayList<>();
    overrideFiles.add(dstDsOverrideFile);
    overrideFiles.add(Paths.get(RESOURCE_DIR, "configfiles/configoverridesset1/config.xml"));
    overrideFiles.add(Paths.get(RESOURCE_DIR, "configfiles/configoverridesset1/version.txt"));
    createConfigMapFromFiles(overridecm, overrideFiles, domainNamespace);
    String introspectVersion = assertDoesNotThrow(() -> getNextIntrospectVersion(domainUid, domainNamespace));
    patchStr
        = "["
        + "{\"op\": \"add\", \"path\": \"/spec/configuration/overridesConfigMap\", \"value\": \"" + overridecm + "\"},"
        + "{\"op\": \"add\", \"path\": \"/spec/configuration/secrets\", \"value\": [\"" + dsSecret + "\"]  },"
        + "{\"op\": \"replace\", \"path\": \"/spec/introspectVersion\", \"value\": \"" + introspectVersion + "\"}"
        + "]";
    logger.info("Updating domain configuration using patch string: {0}", patchStr);
    patch = new V1Patch(patchStr);
    assertTrue(patchDomainCustomResource(domainUid, domainNamespace, patch, V1Patch.PATCH_FORMAT_JSON_PATCH),
        "Failed to patch domain");
    verifyIntrospectorRuns();
    verifyPodsStateNotChanged();
    try {
      TimeUnit.MINUTES.sleep(1);
    } catch (InterruptedException ex) {
    }
    verifyConfigXMLOverride(false);
    verifyResourceJDBC0Override(false);
    restartDomain();
    verifyConfigXMLOverride(true);
    verifyResourceJDBC1Override(true);
    deleteSecret(dsSecret, domainNamespace);
    patchStr
        = "["
        + "{\"op\": \"remove\", \"path\": \"/spec/configuration/overrideDistributionStrategy\"},"
        + "{\"op\": \"remove\", \"path\": \"/spec/configuration/secrets\"}"
        + "]";
    logger.info("Updating domain configuration using patch string: {0}", patchStr);
    patch = new V1Patch(patchStr);
    assertTrue(patchDomainCustomResource(domainUid, domainNamespace, patch, V1Patch.PATCH_FORMAT_JSON_PATCH),
        "Failed to patch domain");
  }
@ Order ( 4 ) @ Test @ DisplayName ( "Test overrideDistributionStrategy value ON_RESTART" ) public void testOnRestartOverride ( ) { String patchStr = "[" + "{\"op\": \"add\", \"path\": \"/spec/configuration/overrideDistributionStrategy\", " + "\"value\": \"ON_RESTART\"}" + "]" ; logger . info ( "Updating domain configuration using patch string: {0}" , patchStr ) ; V1Patch patch = new V1Patch ( patchStr ) ; assertTrue ( patchDomainCustomResource ( domainUid , domainNamespace , patch , V1Patch . PATCH_FORMAT_JSON_PATCH ) , "Failed to patch domain" ) ; restartDomain ( ) ; storePodCreationTimestamps ( ) ; logger . info ( "Creating secrets for JDBC datasource overrides" ) ; Map < String , String > secretMap = new HashMap < > ( ) ; secretMap . put ( "dbusername" , "root" ) ; secretMap . put ( "dbpassword" , "root456" ) ; boolean secretCreated = assertDoesNotThrow ( ( ) -> createSecret ( new V1Secret ( ) . metadata ( new V1ObjectMeta ( ) . name ( dsSecret ) . namespace ( domainNamespace ) ) . stringData ( secretMap ) ) , "Creating secret for datasource failed." ) ; assertTrue ( secretCreated , String . format ( "creating secret failed %s" , dsSecret ) ) ; Path srcDsOverrideFile = Paths . get ( RESOURCE_DIR , "configfiles/configoverridesset1/jdbc-JdbcTestDataSource-1.xml" ) ; Path dstDsOverrideFile = Paths . get ( WORK_DIR , "jdbc-JdbcTestDataSource-1.xml" ) ; String tempString = assertDoesNotThrow ( ( ) -> Files . readString ( srcDsOverrideFile ) . replaceAll ( "JDBC_URL" , dsUrl2 ) ) ; assertDoesNotThrow ( ( ) -> Files . write ( dstDsOverrideFile , tempString . getBytes ( StandardCharsets . UTF_8 ) ) ) ; List < Path > overrideFiles = new ArrayList < > ( ) ; overrideFiles . add ( dstDsOverrideFile ) ; overrideFiles . add ( Paths . get ( RESOURCE_DIR , "configfiles/configoverridesset1/config.xml" ) ) ; overrideFiles . add ( Paths . get ( RESOURCE_DIR , "configfiles/configoverridesset1/version.txt" ) ) ; createConfigMapFromFiles ( overridecm , overrideFiles , domainNamespace ) ; String introspectVersion = assertDoesNotThrow ( ( ) -> getNextIntrospectVersion ( domainUid , domainNamespace ) ) ; patchStr = "[" + "{\"op\": \"add\", \"path\": \"/spec/configuration/overridesConfigMap\", \"value\": \"" + overridecm + "\"}," + "{\"op\": \"add\", \"path\": \"/spec/configuration/secrets\", \"value\": [\"" + dsSecret + "\"]  }," + "{\"op\": \"replace\", \"path\": \"/spec/introspectVersion\", \"value\": \"" + introspectVersion + "\"}" + "]" ; logger . info ( "Updating domain configuration using patch string: {0}" , patchStr ) ; patch = new V1Patch ( patchStr ) ; assertTrue ( patchDomainCustomResource ( domainUid , domainNamespace , patch , V1Patch . PATCH_FORMAT_JSON_PATCH ) , "Failed to patch domain" ) ; verifyIntrospectorRuns ( ) ; verifyPodsStateNotChanged ( ) ; try { TimeUnit . MINUTES . sleep ( 1 ) ; } catch ( InterruptedException ex ) { } verifyConfigXMLOverride ( false ) ; verifyResourceJDBC0Override ( false ) ; restartDomain ( ) ; verifyConfigXMLOverride ( true ) ; verifyResourceJDBC1Override ( true ) ; deleteSecret ( dsSecret , domainNamespace ) ; patchStr = "[" + "{\"op\": \"remove\", \"path\": \"/spec/configuration/overrideDistributionStrategy\"}," + "{\"op\": \"remove\", \"path\": \"/spec/configuration/secrets\"}" + "]" ; logger . info ( "Updating domain configuration using patch string: {0}" , patchStr ) ; patch = new V1Patch ( patchStr ) ; assertTrue ( patchDomainCustomResource ( domainUid , domainNamespace , patch , V1Patch . PATCH_FORMAT_JSON_PATCH ) , "Failed to patch domain" ) ; }
Test server configuration and JDBC datasource configurations are overridden on restart of pods when
 /spec/configuration/overrideDistributionStrategy is set to ON_RESTART.
Test server configuration and JDBC datasource configurations are overridden on restart of pods when / spec / configuration / overrideDistributionStrategy is set to ON_RESTART .
//patching the domain with /spec/configuration/overrideDistributionStrategy: ON_RESTART //TODO: - does changing overrideDistributionStrategy needs restart of server pods? // if above is a bug, remove this after the above bug is fixed //store the pod creation timestamps //create new secrets for jdbc datasource //copy the template datasource file for override after replacing JDBC_URL with new datasource url //create config override map //patch the domain resource with overridesConfigMap, secrets and introspectVersion //wait for a minute to see if the overrides are not applied //ignore //verify the overrides are not applied //restart domain for the distributionstrategy to take effect //verify on restart the overrides are applied //cleanup secret