3535import oracle .weblogic .kubernetes .actions .impl .primitive .HelmParams ;
3636import oracle .weblogic .kubernetes .extensions .InitializationTasks ;
3737import oracle .weblogic .kubernetes .logging .LoggingFacade ;
38+ import org .jetbrains .annotations .Nullable ;
3839
3940import static oracle .weblogic .kubernetes .TestConstants .ADMIN_SERVER_NAME_BASE ;
4041import static oracle .weblogic .kubernetes .TestConstants .COMPARTMENT_OCID ;
@@ -385,13 +386,15 @@ public static String getLoadBalancerIP(String namespace, String lbName, boolean
385386 return null ;
386387 }
387388
388- private static boolean checkLoadBalancerHealthy (String namespace , String lbServiceName ) {
389+ private static boolean checkLoadBalancerHealthy (String namespace , String lbServiceName ) {
390+
389391 String lbPublicIP = assertDoesNotThrow (() -> getLoadBalancerIP (namespace , lbServiceName ));
390392 InitializationTasks .registerLoadBalancerExternalIP (lbPublicIP );
391393 LoggingFacade logger = getLogger ();
392394 String testcompartmentid = System .getProperty ("wko.it.oci.compartment.ocid" );
393395 logger .info ("wko.it.oci.compartment.ocid property " + testcompartmentid );
394396
397+
395398 final String command = "oci lb load-balancer list --compartment-id "
396399 + testcompartmentid + " --query \" data[?contains(\\ \" ip-addresses\\ \" [0].\\ \" ip-address\\ \" , '"
397400 + lbPublicIP + "')].id | [0]\" --raw-output --all" ;
@@ -409,13 +412,44 @@ private static boolean checkLoadBalancerHealthy(String namespace, String lbServi
409412 // Clean up the string to extract the Load Balancer ID
410413 String lbOCID = result .stdout ().trim ();
411414
415+ boolean isFlexible = isLoadBalancerShapeFlexible (lbOCID );
416+
417+ if (!isFlexible ) {
418+ logger .info ("Updating load balancer shape to flexible" );
419+
420+ final String command2 = "oci lb load-balancer update-load-balancer-shape --load-balancer-id "
421+ + lbOCID + " --shape-name flexible --shape-details"
422+ + " '{\" minimumBandwidthInMbps\" : 10, \" maximumBandwidthInMbps\" : 400}' --force" ;
423+
424+ result = assertDoesNotThrow (() -> exec (command2 , true ));
425+ logger .info ("Command: {}, Exit value: {}, Stdout: {}, Stderr: {}" ,
426+ command2 , result .exitValue (), result .stdout (), result .stderr ());
427+
428+ if (result == null || result .stdout () == null ) {
429+ return false ;
430+ } else if (result .exitValue () != 0 && !result .stdout ().contains ("is currently being modified" )) {
431+ return false ;
432+ }
433+
434+ testUntil (
435+ assertDoesNotThrow (() -> checkWorkRequestUpdateShapeSucceeded (
436+ lbOCID ), "isOCILoadBalancer work request to update shape is not ready" ),
437+ logger ,
438+ "load balancer shape is updating " );
439+ testUntil (
440+ assertDoesNotThrow (() -> checkLoadBalancerShapeFlexible (
441+ lbOCID ), "checkLoadBalancerShape is not flexible " ),
442+ logger ,
443+ "load balancer shape can't be checked, retrying " );
444+ }
445+
412446 //check health status
413447 final String command1 = "oci lb load-balancer-health get --load-balancer-id " + lbOCID ;
414448 logger .info ("Command to retrieve Load Balancer health status is: {0} " , command1 );
415449 result = assertDoesNotThrow (() -> exec (command1 , true ));
416450 logger .info ("The command returned exit value: " + result .exitValue ()
417451 + " command output: " + result .stderr () + "\n " + result .stdout ());
418-
452+ logger . info ( "result.stderr: \n {0}" , result . stderr ());
419453 if (result == null || result .exitValue () != 0 || result .stdout () == null ) {
420454 return false ;
421455 }
@@ -424,6 +458,58 @@ private static boolean checkLoadBalancerHealthy(String namespace, String lbServi
424458
425459 }
426460
461+ @ Nullable
462+ private static boolean isLoadBalancerShapeFlexible (String lbOCID ) {
463+ LoggingFacade logger = getLogger ();
464+
465+ final String checkShapeCommand = "oci lb load-balancer get --load-balancer-id "
466+ + lbOCID + " | jq '.data[\" shape-name\" ], .data[\" shape-details\" ]'" ;
467+ ExecResult result = assertDoesNotThrow (() -> exec (checkShapeCommand , true ));
468+ logger .info ("The command " + checkShapeCommand + " returned exit value: " + result .exitValue ()
469+ + " command output: " + result .stderr () + "\n " + result .stdout ());
470+ logger .info ("result.stderr: \n {0}" , result .stderr ());
471+ if (result == null || result .exitValue () != 0 || result .stdout () == null || !result .stdout ().contains ("flexible" )) {
472+ return false ;
473+ }
474+ return true ;
475+ }
476+
477+ private static Callable <Boolean > checkLoadBalancerShapeFlexible (String loadBalancerOCID ) {
478+ return () -> isLoadBalancerShapeFlexible (loadBalancerOCID );
479+ }
480+
481+ /**
482+ * Check work request status for load balancer.
483+ * @param loadBalancerOCID - load balancer OCID
484+ * @return true if succeeded , false over vise.
485+ */
486+ public static boolean isWorkRequestUpdateShapeSucceeded (String loadBalancerOCID ) {
487+
488+ LoggingFacade logger = getLogger ();
489+ final String command = "oci lb work-request list --load-balancer-id "
490+ + loadBalancerOCID
491+ + " --query 'data[?type == `UpdateShape`].{id:id, lifecycleState:\" lifecycle-state\" , "
492+ + "message:message, timeFinished:\" time-finished\" }' "
493+ + "| jq '.[] | select(.lifecycleState == \" SUCCEEDED\" )'" ;
494+ ExecResult result = assertDoesNotThrow (() -> exec (command , true ));
495+ logger .info ("The command " + command + " returned exit value: " + result .exitValue ()
496+ + " command output: " + result .stderr () + "\n " + result .stdout ());
497+ logger .info ("result.stderr: \n {0}" , result .stderr ());
498+ if (result == null || result .exitValue () != 0 || result .stdout () == null || result .stderr ().contains ("ERROR" )) {
499+ return false ;
500+ }
501+ return true ;
502+ }
503+
504+ /**
505+ * Check if lb work request status is succeeded.
506+ *
507+ * @param loadBalancerOCID lb ocid
508+ * @return true if succeeded, false otherwise
509+ */
510+ public static Callable <Boolean > checkWorkRequestUpdateShapeSucceeded (String loadBalancerOCID ) {
511+ return () -> isWorkRequestUpdateShapeSucceeded (loadBalancerOCID );
512+ }
427513
428514 /** Upgrade Traefik and wait for up to five minutes for the Traefik pod to be ready.
429515 *
0 commit comments