new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItPodsRestart.java
@Test
  @DisplayName("Verify server pods are restarted by changing the resources")
  public void testServerPodsRestartByChangingResource() {

    // get the original domain resource before update
    Domain domain1 = assertDoesNotThrow(() -> getDomainCustomResource(domainUid, domainNamespace),
        String.format("getDomainCustomResource failed with ApiException when tried to get domain %s in namespace %s",
            domainUid, domainNamespace));

    assertNotNull(domain1, domain1 + " is null");
    assertNotNull(domain1.getSpec(), domain1 + "/spec is null");
    assertNotNull(domain1.getSpec().getServerPod(), domain1 + "/spec/serverPod is null");
    assertNotNull(domain1.getSpec().getServerPod().getResources(), domain1 + "/spec/serverPod/resources is null");

    // get the current server pod compute resource limit
    Map<String, Quantity> limits = domain1.getSpec().getServerPod().getResources().getLimits();
    assertNotNull(limits, domain1 + "/spec/serverPod/resources/limits is null");

    // print out current server pod compute resource limits
    logger.info("Current value for server pod compute resource limits:");
    limits.forEach((key, value) -> logger.info(key + ": " + value.toString()));

    // get the current server pod compute resource requests
    Map<String, Quantity> requests = domain1.getSpec().getServerPod().getResources().getRequests();
    assertNotNull(requests, domain1 + "/spec/serverPod/resources/requests is null");

    // print out current server pod compute resource requests
    logger.info("Current value for server pod compute resource requests:");
    requests.forEach((key, value) -> logger.info(key + ": " + value.toString()));

    // create the map with server pods and their original creation timestamps
    Map<String, DateTime> podsWithTimeStamps = new LinkedHashMap<>();
    podsWithTimeStamps.put(adminServerPodName,
        assertDoesNotThrow(() -> getPodCreationTimestamp(domainNamespace, "", adminServerPodName),
        String.format("getPodCreationTimestamp failed with ApiException for pod %s in namespace %s",
            adminServerPodName, domainNamespace)));

    for (int i = 1; i <= replicaCount; i++) {
      String managedServerPodName = managedServerPrefix + i;
      podsWithTimeStamps.put(managedServerPodName,
          assertDoesNotThrow(() -> getPodCreationTimestamp(domainNamespace, "", managedServerPodName),
              String.format("getPodCreationTimestamp failed with ApiException for pod %s in namespace %s",
                  managedServerPodName, domainNamespace)));
    }

    // add the new server pod compute resources limits: cpu: 1, requests: cpu: 0.5
    BigDecimal cpuLimit = new BigDecimal(1);
    BigDecimal cpuRequest = new BigDecimal(0.5);

    // verify if cpu limit was set then the new value should be different than the original value
    if (limits.get("cpu") != null) {
      assertNotEquals(limits.get("cpu").getNumber().compareTo(cpuLimit), 0,
          String.format("server pod compute resources cpu limit is already set to %s, set cpu limit to "
              + "a different value", cpuLimit));
    }

    // verify if cpu request was set then the new value should be different than the original value
    if (requests.get("cpu") != null) {
      assertNotEquals(requests.get("cpu").getNumber().compareTo(cpuRequest), 0,
          String.format("server pod compute resources cpu request is already set to %s, set cpu request to "
              + "a different value", cpuRequest));
    }

    // add/modify the server pod resources by patching the domain custom resource
    assertTrue(addServerPodResources(cpuLimit, cpuRequest),
        String.format("Failed to add server pod compute resources for domain %s in namespace %s",
            domainUid, domainNamespace));

    // verify the server pods are rolling restarted and back to ready state
    logger.info("Verifying rolling restart occurred for domain {0} in namespace {1}",
        domainUid, domainNamespace);
    assertTrue(assertDoesNotThrow(
        () -> verifyRollingRestartOccurred(podsWithTimeStamps, 1, domainNamespace),
        "More than one pod was restarted at same time"),
        String.format("Rolling restart failed for domain %s in namespace %s", domainUid, domainNamespace));

    // get the patched domain custom resource
    domain1 = assertDoesNotThrow(() -> getDomainCustomResource(domainUid, domainNamespace),
        String.format("getDomainCustomResource failed with ApiException when tried to get domain %s in namespace %s",
            domainUid, domainNamespace));

    assertNotNull(domain1, domain1 + " is null");
    assertNotNull(domain1.getSpec(), domain1 + "/spec is null");
    assertNotNull(domain1.getSpec().getServerPod(), domain1 + "/spec/serverPod is null");
    assertNotNull(domain1.getSpec().getServerPod().getResources(), domain1 + "/spec/serverPod/resources is null");

    // get new server pod compute resources limits
    limits = domain1.getSpec().getServerPod().getResources().getLimits();
    assertNotNull(limits, domain1 + "/spec/serverPod/resources/limits is null");

    // print out server pod compute resource limits
    logger.info("New value for server pod compute resource limits:");
    limits.forEach((key, value) -> logger.info(key + ": " + value.getNumber().toString()));

    // verify the server pod resources limits got updated
    logger.info("Checking that the server pod resources cpu limit was updated correctly");
    assertNotNull(limits.get("cpu"), domain1 + "/spec/serverPod/resources/limits/cpu is null");
    assertEquals(limits.get("cpu").getNumber().compareTo(cpuLimit), 0,
        String.format("server pod compute resource limits were not updated correctly, set cpu limit to %s, got %s",
            cpuLimit, limits.get("cpu").getNumber()));

    // get new server pod compute resources requests
    requests = domain1.getSpec().getServerPod().getResources().getRequests();
    assertNotNull(requests, domain1 + "/spec/serverPod/resources/requests is null");

    // print out server pod compute resource requests
    logger.info("New value for server pod compute resource requests:");
    requests.forEach((key, value) -> logger.info(key + ": " + value.getNumber()));

    // verify the server pod resources requests got updated
    logger.info("Checking that the server pod resources cpu request is updated correctly");
    assertNotNull(requests.get("cpu"), domain1 + "/spec/serverPod/resources/requests/cpu is null");
    assertEquals(requests.get("cpu").getNumber().compareTo(cpuRequest), 0,
        String.format("server pod compute resources requests was not updated correctly, set cpu request to %s, got %s",
            cpuRequest, requests.get("cpu").getNumber()));
  }
/**
   * Add/Modify server pod resources by patching the domain custom resource.
   * Verify all pods are restarted and back to ready state.
   * The resources tested: resources: limits: cpu: "1", resources: requests: cpu: "0.5"
   * Test fails if any server pod is not restarted and back to ready state or the compute resources in the patched
   * domain custom resource do not match the values we planned to add or modify.
   */
Add/Modify server pod resources by patching the domain custom resource.
Verify all pods are restarted and back to ready state.
Add / Modify server pod resources by patching the domain custom resource . Verify all pods are restarted and back to ready state .
@Test
  @DisplayName("Verify server pods are restarted by changing the resources")
  public void testServerPodsRestartByChangingResource() {
    Domain domain1 = assertDoesNotThrow(() -> getDomainCustomResource(domainUid, domainNamespace),
        String.format("getDomainCustomResource failed with ApiException when tried to get domain %s in namespace %s",
            domainUid, domainNamespace));
    assertNotNull(domain1, domain1 + " is null");
    assertNotNull(domain1.getSpec(), domain1 + "/spec is null");
    assertNotNull(domain1.getSpec().getServerPod(), domain1 + "/spec/serverPod is null");
    assertNotNull(domain1.getSpec().getServerPod().getResources(), domain1 + "/spec/serverPod/resources is null");
    Map<String, Quantity> limits = domain1.getSpec().getServerPod().getResources().getLimits();
    assertNotNull(limits, domain1 + "/spec/serverPod/resources/limits is null");
    logger.info("Current value for server pod compute resource limits:");
    limits.forEach((key, value) -> logger.info(key + ": " + value.toString()));
    Map<String, Quantity> requests = domain1.getSpec().getServerPod().getResources().getRequests();
    assertNotNull(requests, domain1 + "/spec/serverPod/resources/requests is null");
    logger.info("Current value for server pod compute resource requests:");
    requests.forEach((key, value) -> logger.info(key + ": " + value.toString()));
    Map<String, DateTime> podsWithTimeStamps = new LinkedHashMap<>();
    podsWithTimeStamps.put(adminServerPodName,
        assertDoesNotThrow(() -> getPodCreationTimestamp(domainNamespace, "", adminServerPodName),
        String.format("getPodCreationTimestamp failed with ApiException for pod %s in namespace %s",
            adminServerPodName, domainNamespace)));
    for (int i = 1; i <= replicaCount; i++) {
      String managedServerPodName = managedServerPrefix + i;
      podsWithTimeStamps.put(managedServerPodName,
          assertDoesNotThrow(() -> getPodCreationTimestamp(domainNamespace, "", managedServerPodName),
              String.format("getPodCreationTimestamp failed with ApiException for pod %s in namespace %s",
                  managedServerPodName, domainNamespace)));
    }
    BigDecimal cpuLimit = new BigDecimal(1);
    BigDecimal cpuRequest = new BigDecimal(0.5);
    if (limits.get("cpu") != null) {
      assertNotEquals(limits.get("cpu").getNumber().compareTo(cpuLimit), 0,
          String.format("server pod compute resources cpu limit is already set to %s, set cpu limit to "
              + "a different value", cpuLimit));
    }
    if (requests.get("cpu") != null) {
      assertNotEquals(requests.get("cpu").getNumber().compareTo(cpuRequest), 0,
          String.format("server pod compute resources cpu request is already set to %s, set cpu request to "
              + "a different value", cpuRequest));
    }
    assertTrue(addServerPodResources(cpuLimit, cpuRequest),
        String.format("Failed to add server pod compute resources for domain %s in namespace %s",
            domainUid, domainNamespace));
    logger.info("Verifying rolling restart occurred for domain {0} in namespace {1}",
        domainUid, domainNamespace);
    assertTrue(assertDoesNotThrow(
        () -> verifyRollingRestartOccurred(podsWithTimeStamps, 1, domainNamespace),
        "More than one pod was restarted at same time"),
        String.format("Rolling restart failed for domain %s in namespace %s", domainUid, domainNamespace));
    domain1 = assertDoesNotThrow(() -> getDomainCustomResource(domainUid, domainNamespace),
        String.format("getDomainCustomResource failed with ApiException when tried to get domain %s in namespace %s",
            domainUid, domainNamespace));
    assertNotNull(domain1, domain1 + " is null");
    assertNotNull(domain1.getSpec(), domain1 + "/spec is null");
    assertNotNull(domain1.getSpec().getServerPod(), domain1 + "/spec/serverPod is null");
    assertNotNull(domain1.getSpec().getServerPod().getResources(), domain1 + "/spec/serverPod/resources is null");
    limits = domain1.getSpec().getServerPod().getResources().getLimits();
    assertNotNull(limits, domain1 + "/spec/serverPod/resources/limits is null");
    logger.info("New value for server pod compute resource limits:");
    limits.forEach((key, value) -> logger.info(key + ": " + value.getNumber().toString()));
    logger.info("Checking that the server pod resources cpu limit was updated correctly");
    assertNotNull(limits.get("cpu"), domain1 + "/spec/serverPod/resources/limits/cpu is null");
    assertEquals(limits.get("cpu").getNumber().compareTo(cpuLimit), 0,
        String.format("server pod compute resource limits were not updated correctly, set cpu limit to %s, got %s",
            cpuLimit, limits.get("cpu").getNumber()));
    requests = domain1.getSpec().getServerPod().getResources().getRequests();
    assertNotNull(requests, domain1 + "/spec/serverPod/resources/requests is null");
    logger.info("New value for server pod compute resource requests:");
    requests.forEach((key, value) -> logger.info(key + ": " + value.getNumber()));
    logger.info("Checking that the server pod resources cpu request is updated correctly");
    assertNotNull(requests.get("cpu"), domain1 + "/spec/serverPod/resources/requests/cpu is null");
    assertEquals(requests.get("cpu").getNumber().compareTo(cpuRequest), 0,
        String.format("server pod compute resources requests was not updated correctly, set cpu request to %s, got %s",
            cpuRequest, requests.get("cpu").getNumber()));
  }
@ Test @ DisplayName ( "Verify server pods are restarted by changing the resources" ) public void testServerPodsRestartByChangingResource ( ) { Domain domain1 = assertDoesNotThrow ( ( ) -> getDomainCustomResource ( domainUid , domainNamespace ) , String . format ( "getDomainCustomResource failed with ApiException when tried to get domain %s in namespace %s" , domainUid , domainNamespace ) ) ; assertNotNull ( domain1 , domain1 + " is null" ) ; assertNotNull ( domain1 . getSpec ( ) , domain1 + "/spec is null" ) ; assertNotNull ( domain1 . getSpec ( ) . getServerPod ( ) , domain1 + "/spec/serverPod is null" ) ; assertNotNull ( domain1 . getSpec ( ) . getServerPod ( ) . getResources ( ) , domain1 + "/spec/serverPod/resources is null" ) ; Map < String , Quantity > limits = domain1 . getSpec ( ) . getServerPod ( ) . getResources ( ) . getLimits ( ) ; assertNotNull ( limits , domain1 + "/spec/serverPod/resources/limits is null" ) ; logger . info ( "Current value for server pod compute resource limits:" ) ; limits . forEach ( ( key , value ) -> logger . info ( key + ": " + value . toString ( ) ) ) ; Map < String , Quantity > requests = domain1 . getSpec ( ) . getServerPod ( ) . getResources ( ) . getRequests ( ) ; assertNotNull ( requests , domain1 + "/spec/serverPod/resources/requests is null" ) ; logger . info ( "Current value for server pod compute resource requests:" ) ; requests . forEach ( ( key , value ) -> logger . info ( key + ": " + value . toString ( ) ) ) ; Map < String , DateTime > podsWithTimeStamps = new LinkedHashMap < > ( ) ; podsWithTimeStamps . put ( adminServerPodName , assertDoesNotThrow ( ( ) -> getPodCreationTimestamp ( domainNamespace , "" , adminServerPodName ) , String . format ( "getPodCreationTimestamp failed with ApiException for pod %s in namespace %s" , adminServerPodName , domainNamespace ) ) ) ; for ( int i = 1 ; i <= replicaCount ; i ++ ) { String managedServerPodName = managedServerPrefix + i ; podsWithTimeStamps . put ( managedServerPodName , assertDoesNotThrow ( ( ) -> getPodCreationTimestamp ( domainNamespace , "" , managedServerPodName ) , String . format ( "getPodCreationTimestamp failed with ApiException for pod %s in namespace %s" , managedServerPodName , domainNamespace ) ) ) ; } BigDecimal cpuLimit = new BigDecimal ( 1 ) ; BigDecimal cpuRequest = new BigDecimal ( 0.5 ) ; if ( limits . get ( "cpu" ) != null ) { assertNotEquals ( limits . get ( "cpu" ) . getNumber ( ) . compareTo ( cpuLimit ) , 0 , String . format ( "server pod compute resources cpu limit is already set to %s, set cpu limit to " + "a different value" , cpuLimit ) ) ; } if ( requests . get ( "cpu" ) != null ) { assertNotEquals ( requests . get ( "cpu" ) . getNumber ( ) . compareTo ( cpuRequest ) , 0 , String . format ( "server pod compute resources cpu request is already set to %s, set cpu request to " + "a different value" , cpuRequest ) ) ; } assertTrue ( addServerPodResources ( cpuLimit , cpuRequest ) , String . format ( "Failed to add server pod compute resources for domain %s in namespace %s" , domainUid , domainNamespace ) ) ; logger . info ( "Verifying rolling restart occurred for domain {0} in namespace {1}" , domainUid , domainNamespace ) ; assertTrue ( assertDoesNotThrow ( ( ) -> verifyRollingRestartOccurred ( podsWithTimeStamps , 1 , domainNamespace ) , "More than one pod was restarted at same time" ) , String . format ( "Rolling restart failed for domain %s in namespace %s" , domainUid , domainNamespace ) ) ; domain1 = assertDoesNotThrow ( ( ) -> getDomainCustomResource ( domainUid , domainNamespace ) , String . format ( "getDomainCustomResource failed with ApiException when tried to get domain %s in namespace %s" , domainUid , domainNamespace ) ) ; assertNotNull ( domain1 , domain1 + " is null" ) ; assertNotNull ( domain1 . getSpec ( ) , domain1 + "/spec is null" ) ; assertNotNull ( domain1 . getSpec ( ) . getServerPod ( ) , domain1 + "/spec/serverPod is null" ) ; assertNotNull ( domain1 . getSpec ( ) . getServerPod ( ) . getResources ( ) , domain1 + "/spec/serverPod/resources is null" ) ; limits = domain1 . getSpec ( ) . getServerPod ( ) . getResources ( ) . getLimits ( ) ; assertNotNull ( limits , domain1 + "/spec/serverPod/resources/limits is null" ) ; logger . info ( "New value for server pod compute resource limits:" ) ; limits . forEach ( ( key , value ) -> logger . info ( key + ": " + value . getNumber ( ) . toString ( ) ) ) ; logger . info ( "Checking that the server pod resources cpu limit was updated correctly" ) ; assertNotNull ( limits . get ( "cpu" ) , domain1 + "/spec/serverPod/resources/limits/cpu is null" ) ; assertEquals ( limits . get ( "cpu" ) . getNumber ( ) . compareTo ( cpuLimit ) , 0 , String . format ( "server pod compute resource limits were not updated correctly, set cpu limit to %s, got %s" , cpuLimit , limits . get ( "cpu" ) . getNumber ( ) ) ) ; requests = domain1 . getSpec ( ) . getServerPod ( ) . getResources ( ) . getRequests ( ) ; assertNotNull ( requests , domain1 + "/spec/serverPod/resources/requests is null" ) ; logger . info ( "New value for server pod compute resource requests:" ) ; requests . forEach ( ( key , value ) -> logger . info ( key + ": " + value . getNumber ( ) ) ) ; logger . info ( "Checking that the server pod resources cpu request is updated correctly" ) ; assertNotNull ( requests . get ( "cpu" ) , domain1 + "/spec/serverPod/resources/requests/cpu is null" ) ; assertEquals ( requests . get ( "cpu" ) . getNumber ( ) . compareTo ( cpuRequest ) , 0 , String . format ( "server pod compute resources requests was not updated correctly, set cpu request to %s, got %s" , cpuRequest , requests . get ( "cpu" ) . getNumber ( ) ) ) ; }
Add/Modify server pod resources by patching the domain custom resource.
Add / Modify server pod resources by patching the domain custom resource .
// get the original domain resource before update // get the current server pod compute resource limit // print out current server pod compute resource limits // get the current server pod compute resource requests // print out current server pod compute resource requests // create the map with server pods and their original creation timestamps // add the new server pod compute resources limits: cpu: 1, requests: cpu: 0.5 // verify if cpu limit was set then the new value should be different than the original value // verify if cpu request was set then the new value should be different than the original value // add/modify the server pod resources by patching the domain custom resource // verify the server pods are rolling restarted and back to ready state // get the patched domain custom resource // get new server pod compute resources limits // print out server pod compute resource limits // verify the server pod resources limits got updated // get new server pod compute resources requests // print out server pod compute resource requests // verify the server pod resources requests got updated