new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItOperatorRestartWhenPodRoll.java
@Test
  @DisplayName("Restart operator when the domain is rolling after the admin credentials are changed")
  @Slow
  @MustNotRunInParallel
  public void testOperatorRestartWhenPodRoll() {
    final boolean VALID = true;
    final boolean INVALID = false;

    LinkedHashMap<String, DateTime> pods = new LinkedHashMap<>();

    // get the creation time of the admin server pod before patching
    DateTime adminPodCreationTime =
        assertDoesNotThrow(() -> getPodCreationTimestamp(domainNamespace, "", adminServerPodName),
        String.format("Failed to get creationTimestamp for pod %s", adminServerPodName));
    assertNotNull(adminPodCreationTime, "creationTimestamp of the admin server pod is null");

    logger.info("Domain {0} in namespace {1}, admin server pod {2} creationTimestamp before patching is {3}",
        domainUid,
        domainNamespace,
        adminServerPodName,
        adminPodCreationTime);

    pods.put(adminServerPodName, adminPodCreationTime);

    List<DateTime> msLastCreationTime = new ArrayList<DateTime>();
    // get the creation time of the managed server pods before patching
    assertDoesNotThrow(
        () -> {
            for (int i = 1; i <= replicaCount; i++) {
              String managedServerPodName = managedServerPrefix + i;
              DateTime creationTime = getPodCreationTimestamp(domainNamespace, "", managedServerPodName);
              msLastCreationTime.add(creationTime);
              pods.put(managedServerPodName, creationTime);

              logger.info("Domain {0} in namespace {1}, server pod {2} creationTimestamp before patching is {3}",
                  domainUid,
                  domainNamespace,
                  managedServerPodName,
                  creationTime);
            }
        },
        String.format("Failed to get creationTimestamp for managed server pods"));

    logger.info("Check that before patching current credentials are valid and new credentials are not");
    verifyCredentials(adminServerPodName, domainNamespace, ADMIN_USERNAME_DEFAULT, ADMIN_PASSWORD_DEFAULT, VALID);
    verifyCredentials(adminServerPodName, domainNamespace, ADMIN_USERNAME_PATCH, ADMIN_PASSWORD_PATCH, INVALID);

    // create a new secret for admin credentials
    logger.info("Create a new secret that contains new WebLogic admin credentials");
    String adminSecretName = "weblogic-credentials-new";
    assertDoesNotThrow(() -> createSecretWithUsernamePassword(
        adminSecretName,
        domainNamespace,
        ADMIN_USERNAME_PATCH,
        ADMIN_PASSWORD_PATCH),
        String.format("createSecret failed for %s", adminSecretName));

    // patch the domain resource with the new secret and verify that the domain resource is patched.
    logger.info("Patch domain {0} in namespace {1} with the secret {2}, and verify the result",
        domainUid, domainNamespace, adminSecretName);

    String restartVersion = CommonPatchTestUtils.patchDomainWithNewSecretAndVerify(
        domainUid,
        domainNamespace,
        adminServerPodName,
        managedServerPrefix,
        replicaCount,
        adminSecretName);

    logger.info("Delete the operator pod in namespace {0} and wait for it to be restarted", opNamespace);
    restartOperatorAndVerify();

    logger.info("Wait for domain {0} admin server pod {1} in namespace {2} to be restarted",
        domainUid, adminServerPodName, domainNamespace);

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

    for (int i = 1; i <= replicaCount; i++) {
      final String podName = managedServerPrefix + i;
      final DateTime lastCreationTime = msLastCreationTime.get(i - 1);
      // check that the managed server pod's label has been updated with the new restartVersion
      checkPodRestartVersionUpdated(podName, domainUid, domainNamespace, restartVersion);
    }

    // check if the new credentials are valid and the old credentials are not valid any more
    logger.info("Check that after patching current credentials are not valid and new credentials are");
    verifyCredentials(adminServerPodName, domainNamespace, ADMIN_USERNAME_DEFAULT, ADMIN_PASSWORD_DEFAULT, INVALID);
    verifyCredentials(adminServerPodName, domainNamespace, ADMIN_USERNAME_PATCH, ADMIN_PASSWORD_PATCH, VALID);

    logger.info("Domain {0} in namespace {1} is fully started after changing WebLogic credentials secret",
        domainUid, domainNamespace);
  }
/**
   * Test patching a running model-in-image domain with a new WebLogic credentials secret.
   * Perform two patching operations to the domain spec. First, change the webLogicCredentialsSecret to
   * a new secret, and then change the domainRestartVersion to trigger a rolling restart of the server pods.
   * While the rolling is on-going, restart the operator pod.
   * Verify that after the operator is restarted, the domain spec's webLogicCredentialsSecret and,
   * restartVersion are updated, and the server pods are recreated, the server pods' weblogic.domainRestartVersion
   * label is updated, and the new credentials are valid and can be used to access WebLogic RESTful
   * Management Services.
   */
Test patching a running model-in-image domain with a new WebLogic credentials secret.
Perform two patching operations to the domain spec. First, change the webLogicCredentialsSecret to
a new secret, and then change the domainRestartVersion to trigger a rolling restart of the server pods.
While the rolling is on-going, restart the operator pod.
Verify that after the operator is restarted, the domain spec's webLogicCredentialsSecret and,
restartVersion are updated, and the server pods are recreated, the server pods' weblogic.domainRestartVersion
label is updated, and the new credentials are valid and can be used to access WebLogic RESTful
Management Services.
Test patching a running model - in - image domain with a new WebLogic credentials secret . Perform two patching operations to the domain spec . First change the webLogicCredentialsSecret to a new secret and then change the domainRestartVersion to trigger a rolling restart of the server pods . While the rolling is on - going restart the operator pod . Verify that after the operator is restarted the domain spec ' s webLogicCredentialsSecret and restartVersion are updated and the server pods are recreated the server pods ' weblogic . domainRestartVersion label is updated and the new credentials are valid and can be used to access WebLogic RESTful Management Services .
@Test
  @DisplayName("Restart operator when the domain is rolling after the admin credentials are changed")
  @Slow
  @MustNotRunInParallel
  public void testOperatorRestartWhenPodRoll() {
    final boolean VALID = true;
    final boolean INVALID = false;
    LinkedHashMap<String, DateTime> pods = new LinkedHashMap<>();
    DateTime adminPodCreationTime =
        assertDoesNotThrow(() -> getPodCreationTimestamp(domainNamespace, "", adminServerPodName),
        String.format("Failed to get creationTimestamp for pod %s", adminServerPodName));
    assertNotNull(adminPodCreationTime, "creationTimestamp of the admin server pod is null");
    logger.info("Domain {0} in namespace {1}, admin server pod {2} creationTimestamp before patching is {3}",
        domainUid,
        domainNamespace,
        adminServerPodName,
        adminPodCreationTime);
    pods.put(adminServerPodName, adminPodCreationTime);
    List<DateTime> msLastCreationTime = new ArrayList<DateTime>();
    assertDoesNotThrow(
        () -> {
            for (int i = 1; i <= replicaCount; i++) {
              String managedServerPodName = managedServerPrefix + i;
              DateTime creationTime = getPodCreationTimestamp(domainNamespace, "", managedServerPodName);
              msLastCreationTime.add(creationTime);
              pods.put(managedServerPodName, creationTime);
              logger.info("Domain {0} in namespace {1}, server pod {2} creationTimestamp before patching is {3}",
                  domainUid,
                  domainNamespace,
                  managedServerPodName,
                  creationTime);
            }
        },
        String.format("Failed to get creationTimestamp for managed server pods"));
    logger.info("Check that before patching current credentials are valid and new credentials are not");
    verifyCredentials(adminServerPodName, domainNamespace, ADMIN_USERNAME_DEFAULT, ADMIN_PASSWORD_DEFAULT, VALID);
    verifyCredentials(adminServerPodName, domainNamespace, ADMIN_USERNAME_PATCH, ADMIN_PASSWORD_PATCH, INVALID);
    logger.info("Create a new secret that contains new WebLogic admin credentials");
    String adminSecretName = "weblogic-credentials-new";
    assertDoesNotThrow(() -> createSecretWithUsernamePassword(
        adminSecretName,
        domainNamespace,
        ADMIN_USERNAME_PATCH,
        ADMIN_PASSWORD_PATCH),
        String.format("createSecret failed for %s", adminSecretName));
    logger.info("Patch domain {0} in namespace {1} with the secret {2}, and verify the result",
        domainUid, domainNamespace, adminSecretName);
    String restartVersion = CommonPatchTestUtils.patchDomainWithNewSecretAndVerify(
        domainUid,
        domainNamespace,
        adminServerPodName,
        managedServerPrefix,
        replicaCount,
        adminSecretName);
    logger.info("Delete the operator pod in namespace {0} and wait for it to be restarted", opNamespace);
    restartOperatorAndVerify();
    logger.info("Wait for domain {0} admin server pod {1} in namespace {2} to be restarted",
        domainUid, adminServerPodName, domainNamespace);
    assertTrue(assertDoesNotThrow(
        () -> (verifyRollingRestartOccurred(pods, 1, domainNamespace)),
        "More than one pod was restarted at same time"),
        "Rolling restart failed");
    for (int i = 1; i <= replicaCount; i++) {
      final String podName = managedServerPrefix + i;
      final DateTime lastCreationTime = msLastCreationTime.get(i - 1);
      checkPodRestartVersionUpdated(podName, domainUid, domainNamespace, restartVersion);
    }
    logger.info("Check that after patching current credentials are not valid and new credentials are");
    verifyCredentials(adminServerPodName, domainNamespace, ADMIN_USERNAME_DEFAULT, ADMIN_PASSWORD_DEFAULT, INVALID);
    verifyCredentials(adminServerPodName, domainNamespace, ADMIN_USERNAME_PATCH, ADMIN_PASSWORD_PATCH, VALID);
    logger.info("Domain {0} in namespace {1} is fully started after changing WebLogic credentials secret",
        domainUid, domainNamespace);
  }
@ Test @ DisplayName ( "Restart operator when the domain is rolling after the admin credentials are changed" ) @ Slow @ MustNotRunInParallel public void testOperatorRestartWhenPodRoll ( ) { final boolean VALID = true ; final boolean INVALID = false ; LinkedHashMap < String , DateTime > pods = new LinkedHashMap < > ( ) ; DateTime adminPodCreationTime = assertDoesNotThrow ( ( ) -> getPodCreationTimestamp ( domainNamespace , "" , adminServerPodName ) , String . format ( "Failed to get creationTimestamp for pod %s" , adminServerPodName ) ) ; assertNotNull ( adminPodCreationTime , "creationTimestamp of the admin server pod is null" ) ; logger . info ( "Domain {0} in namespace {1}, admin server pod {2} creationTimestamp before patching is {3}" , domainUid , domainNamespace , adminServerPodName , adminPodCreationTime ) ; pods . put ( adminServerPodName , adminPodCreationTime ) ; List < DateTime > msLastCreationTime = new ArrayList < DateTime > ( ) ; assertDoesNotThrow ( ( ) -> { for ( int i = 1 ; i <= replicaCount ; i ++ ) { String managedServerPodName = managedServerPrefix + i ; DateTime creationTime = getPodCreationTimestamp ( domainNamespace , "" , managedServerPodName ) ; msLastCreationTime . add ( creationTime ) ; pods . put ( managedServerPodName , creationTime ) ; logger . info ( "Domain {0} in namespace {1}, server pod {2} creationTimestamp before patching is {3}" , domainUid , domainNamespace , managedServerPodName , creationTime ) ; } } , String . format ( "Failed to get creationTimestamp for managed server pods" ) ) ; logger . info ( "Check that before patching current credentials are valid and new credentials are not" ) ; verifyCredentials ( adminServerPodName , domainNamespace , ADMIN_USERNAME_DEFAULT , ADMIN_PASSWORD_DEFAULT , VALID ) ; verifyCredentials ( adminServerPodName , domainNamespace , ADMIN_USERNAME_PATCH , ADMIN_PASSWORD_PATCH , INVALID ) ; logger . info ( "Create a new secret that contains new WebLogic admin credentials" ) ; String adminSecretName = "weblogic-credentials-new" ; assertDoesNotThrow ( ( ) -> createSecretWithUsernamePassword ( adminSecretName , domainNamespace , ADMIN_USERNAME_PATCH , ADMIN_PASSWORD_PATCH ) , String . format ( "createSecret failed for %s" , adminSecretName ) ) ; logger . info ( "Patch domain {0} in namespace {1} with the secret {2}, and verify the result" , domainUid , domainNamespace , adminSecretName ) ; String restartVersion = CommonPatchTestUtils . patchDomainWithNewSecretAndVerify ( domainUid , domainNamespace , adminServerPodName , managedServerPrefix , replicaCount , adminSecretName ) ; logger . info ( "Delete the operator pod in namespace {0} and wait for it to be restarted" , opNamespace ) ; restartOperatorAndVerify ( ) ; logger . info ( "Wait for domain {0} admin server pod {1} in namespace {2} to be restarted" , domainUid , adminServerPodName , domainNamespace ) ; assertTrue ( assertDoesNotThrow ( ( ) -> ( verifyRollingRestartOccurred ( pods , 1 , domainNamespace ) ) , "More than one pod was restarted at same time" ) , "Rolling restart failed" ) ; for ( int i = 1 ; i <= replicaCount ; i ++ ) { final String podName = managedServerPrefix + i ; final DateTime lastCreationTime = msLastCreationTime . get ( i - 1 ) ; checkPodRestartVersionUpdated ( podName , domainUid , domainNamespace , restartVersion ) ; } logger . info ( "Check that after patching current credentials are not valid and new credentials are" ) ; verifyCredentials ( adminServerPodName , domainNamespace , ADMIN_USERNAME_DEFAULT , ADMIN_PASSWORD_DEFAULT , INVALID ) ; verifyCredentials ( adminServerPodName , domainNamespace , ADMIN_USERNAME_PATCH , ADMIN_PASSWORD_PATCH , VALID ) ; logger . info ( "Domain {0} in namespace {1} is fully started after changing WebLogic credentials secret" , domainUid , domainNamespace ) ; }
Test patching a running model-in-image domain with a new WebLogic credentials secret.
Test patching a running model - in - image domain with a new WebLogic credentials secret .
// get the creation time of the admin server pod before patching // get the creation time of the managed server pods before patching // create a new secret for admin credentials // patch the domain resource with the new secret and verify that the domain resource is patched. // check that the managed server pod's label has been updated with the new restartVersion // check if the new credentials are valid and the old credentials are not valid any more