35
35
import oracle .weblogic .kubernetes .actions .impl .primitive .HelmParams ;
36
36
import oracle .weblogic .kubernetes .extensions .InitializationTasks ;
37
37
import oracle .weblogic .kubernetes .logging .LoggingFacade ;
38
+ import org .jetbrains .annotations .Nullable ;
38
39
39
40
import static oracle .weblogic .kubernetes .TestConstants .ADMIN_SERVER_NAME_BASE ;
40
41
import static oracle .weblogic .kubernetes .TestConstants .COMPARTMENT_OCID ;
@@ -385,13 +386,15 @@ public static String getLoadBalancerIP(String namespace, String lbName, boolean
385
386
return null ;
386
387
}
387
388
388
- private static boolean checkLoadBalancerHealthy (String namespace , String lbServiceName ) {
389
+ private static boolean checkLoadBalancerHealthy (String namespace , String lbServiceName ) {
390
+
389
391
String lbPublicIP = assertDoesNotThrow (() -> getLoadBalancerIP (namespace , lbServiceName ));
390
392
InitializationTasks .registerLoadBalancerExternalIP (lbPublicIP );
391
393
LoggingFacade logger = getLogger ();
392
394
String testcompartmentid = System .getProperty ("wko.it.oci.compartment.ocid" );
393
395
logger .info ("wko.it.oci.compartment.ocid property " + testcompartmentid );
394
396
397
+
395
398
final String command = "oci lb load-balancer list --compartment-id "
396
399
+ testcompartmentid + " --query \" data[?contains(\\ \" ip-addresses\\ \" [0].\\ \" ip-address\\ \" , '"
397
400
+ lbPublicIP + "')].id | [0]\" --raw-output --all" ;
@@ -409,13 +412,44 @@ private static boolean checkLoadBalancerHealthy(String namespace, String lbServi
409
412
// Clean up the string to extract the Load Balancer ID
410
413
String lbOCID = result .stdout ().trim ();
411
414
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
+
412
446
//check health status
413
447
final String command1 = "oci lb load-balancer-health get --load-balancer-id " + lbOCID ;
414
448
logger .info ("Command to retrieve Load Balancer health status is: {0} " , command1 );
415
449
result = assertDoesNotThrow (() -> exec (command1 , true ));
416
450
logger .info ("The command returned exit value: " + result .exitValue ()
417
451
+ " command output: " + result .stderr () + "\n " + result .stdout ());
418
-
452
+ logger . info ( "result.stderr: \n {0}" , result . stderr ());
419
453
if (result == null || result .exitValue () != 0 || result .stdout () == null ) {
420
454
return false ;
421
455
}
@@ -424,6 +458,58 @@ private static boolean checkLoadBalancerHealthy(String namespace, String lbServi
424
458
425
459
}
426
460
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
+ }
427
513
428
514
/** Upgrade Traefik and wait for up to five minutes for the Traefik pod to be ready.
429
515
*
0 commit comments