4040import oracle .weblogic .kubernetes .actions .impl .primitive .CommandParams ;
4141import oracle .weblogic .kubernetes .actions .impl .primitive .HelmParams ;
4242import oracle .weblogic .kubernetes .actions .impl .primitive .Kubernetes ;
43+ import oracle .weblogic .kubernetes .assertions .TestAssertions ;
4344import oracle .weblogic .kubernetes .assertions .impl .ClusterRole ;
4445import oracle .weblogic .kubernetes .assertions .impl .ClusterRoleBinding ;
4546import oracle .weblogic .kubernetes .logging .LoggingFacade ;
4647import org .apache .commons .io .FileUtils ;
4748
4849import static oracle .weblogic .kubernetes .TestConstants .ADMIN_PASSWORD_DEFAULT ;
4950import static oracle .weblogic .kubernetes .TestConstants .ADMIN_USERNAME_DEFAULT ;
51+ import static oracle .weblogic .kubernetes .TestConstants .BUSYBOX_IMAGE ;
52+ import static oracle .weblogic .kubernetes .TestConstants .BUSYBOX_TAG ;
5053import static oracle .weblogic .kubernetes .TestConstants .DOMAIN_API_VERSION ;
54+ import static oracle .weblogic .kubernetes .TestConstants .GRAFANA_IMAGE_NAME ;
55+ import static oracle .weblogic .kubernetes .TestConstants .GRAFANA_IMAGE_TAG ;
5156import static oracle .weblogic .kubernetes .TestConstants .GRAFANA_REPO_NAME ;
5257import static oracle .weblogic .kubernetes .TestConstants .GRAFANA_REPO_URL ;
5358import static oracle .weblogic .kubernetes .TestConstants .K8S_NODEPORT_HOST ;
5459import static oracle .weblogic .kubernetes .TestConstants .MANAGED_SERVER_NAME_BASE ;
5560import static oracle .weblogic .kubernetes .TestConstants .MONITORING_EXPORTER_BRANCH ;
5661import static oracle .weblogic .kubernetes .TestConstants .MONITORING_EXPORTER_WEBAPP_VERSION ;
5762import static oracle .weblogic .kubernetes .TestConstants .OKD ;
63+ import static oracle .weblogic .kubernetes .TestConstants .OKE_CLUSTER ;
64+ import static oracle .weblogic .kubernetes .TestConstants .PROMETHEUS_ALERT_MANAGER_IMAGE_NAME ;
65+ import static oracle .weblogic .kubernetes .TestConstants .PROMETHEUS_ALERT_MANAGER_IMAGE_TAG ;
66+ import static oracle .weblogic .kubernetes .TestConstants .PROMETHEUS_CONFIG_MAP_RELOAD_IMAGE_NAME ;
67+ import static oracle .weblogic .kubernetes .TestConstants .PROMETHEUS_CONFIG_MAP_RELOAD_IMAGE_TAG ;
68+ import static oracle .weblogic .kubernetes .TestConstants .PROMETHEUS_IMAGE_NAME ;
69+ import static oracle .weblogic .kubernetes .TestConstants .PROMETHEUS_IMAGE_TAG ;
70+ import static oracle .weblogic .kubernetes .TestConstants .PROMETHEUS_NODE_EXPORTER_IMAGE_NAME ;
71+ import static oracle .weblogic .kubernetes .TestConstants .PROMETHEUS_NODE_EXPORTER_IMAGE_TAG ;
72+ import static oracle .weblogic .kubernetes .TestConstants .PROMETHEUS_PUSHGATEWAY_IMAGE_NAME ;
73+ import static oracle .weblogic .kubernetes .TestConstants .PROMETHEUS_PUSHGATEWAY_IMAGE_TAG ;
5874import static oracle .weblogic .kubernetes .TestConstants .PROMETHEUS_REPO_NAME ;
5975import static oracle .weblogic .kubernetes .TestConstants .PROMETHEUS_REPO_URL ;
6076import static oracle .weblogic .kubernetes .TestConstants .RESULTS_ROOT ;
7389import static oracle .weblogic .kubernetes .utils .CommonTestUtils .checkPodReadyAndServiceExists ;
7490import static oracle .weblogic .kubernetes .utils .CommonTestUtils .getNextFreePort ;
7591import static oracle .weblogic .kubernetes .utils .CommonTestUtils .testUntil ;
92+ import static oracle .weblogic .kubernetes .utils .CommonTestUtils .withLongRetryPolicy ;
7693import static oracle .weblogic .kubernetes .utils .DomainUtils .createDomainAndVerify ;
7794import static oracle .weblogic .kubernetes .utils .FileUtils .checkFile ;
7895import static oracle .weblogic .kubernetes .utils .FileUtils .replaceStringInFile ;
@@ -315,15 +332,48 @@ public static PrometheusParams installAndVerifyPrometheus(String promReleaseSuff
315332 assertDoesNotThrow (() -> Files .copy (srcPromFile , targetPromFile ,
316333 StandardCopyOption .REPLACE_EXISTING )," Failed to copy files" );
317334 String oldValue = "regex: default;domain1" ;
318- assertDoesNotThrow (() -> replaceStringInFile (targetPromFile .toString (),
319- oldValue ,
320- prometheusRegexValue ), "Failed to replace String " );
321- assertDoesNotThrow (() -> replaceStringInFile (targetPromFile .toString (),
322- "pvc-alertmanager" ,
323- "pvc-alertmanager" + promReleaseSuffix ), "Failed to replace String " );;
324- assertDoesNotThrow (() -> replaceStringInFile (targetPromFile .toString (),
325- "pvc-prometheus" ,
326- "pvc-" + prometheusReleaseName ),"Failed to replace String " );
335+ logger .info ("copy the promvalues.yaml to staging location" );
336+ assertDoesNotThrow (() -> {
337+ replaceStringInFile (targetPromFile .toString (),
338+ oldValue ,
339+ prometheusRegexValue );
340+ replaceStringInFile (targetPromFile .toString (),
341+ "pvc-alertmanager" ,
342+ "pvc-alertmanager" + promReleaseSuffix );
343+ replaceStringInFile (targetPromFile .toString (),
344+ "pvc-prometheus" ,
345+ "pvc-" + prometheusReleaseName );
346+ replaceStringInFile (targetPromFile .toString (),
347+ "pushgateway_image" ,
348+ PROMETHEUS_PUSHGATEWAY_IMAGE_NAME );
349+ replaceStringInFile (targetPromFile .toString (),
350+ "pushgateway_tag" ,
351+ PROMETHEUS_PUSHGATEWAY_IMAGE_TAG );
352+ replaceStringInFile (targetPromFile .toString (),
353+ "prometheus_image" ,
354+ PROMETHEUS_IMAGE_NAME );
355+ replaceStringInFile (targetPromFile .toString (),
356+ "prometheus_tag" ,
357+ PROMETHEUS_IMAGE_TAG );
358+ replaceStringInFile (targetPromFile .toString (),
359+ "prometheus_alertmanager_image" ,
360+ PROMETHEUS_ALERT_MANAGER_IMAGE_NAME );
361+ replaceStringInFile (targetPromFile .toString (),
362+ "prometheus_alertmanager_tag" ,
363+ PROMETHEUS_ALERT_MANAGER_IMAGE_TAG );
364+ replaceStringInFile (targetPromFile .toString (),
365+ "prometheus_configmap_reload_image" ,
366+ PROMETHEUS_CONFIG_MAP_RELOAD_IMAGE_NAME );
367+ replaceStringInFile (targetPromFile .toString (),
368+ "prometheus_configmap_reload_tag" ,
369+ PROMETHEUS_CONFIG_MAP_RELOAD_IMAGE_TAG );
370+ replaceStringInFile (targetPromFile .toString (),
371+ "prometheus_node_exporter_image" ,
372+ PROMETHEUS_NODE_EXPORTER_IMAGE_NAME );
373+ replaceStringInFile (targetPromFile .toString (),
374+ "prometheus_node_exporter_tag" ,
375+ PROMETHEUS_NODE_EXPORTER_IMAGE_TAG );
376+ }, "Failed to create " + targetPromFile );
327377 if (OKD ) {
328378 assertDoesNotThrow (() -> replaceStringInFile (targetPromFile .toString (),
329379 "65534" ,
@@ -389,23 +439,53 @@ public static PrometheusParams installAndVerifyPrometheus(String promReleaseSuff
389439 *
390440 * @param grafanaReleaseName the grafana release name
391441 * @param grafanaNamespace the grafana namespace in which the operator will be installed
392- * @param grafanaValueFile the grafana value .yaml file path
442+ * @param grafanaHelmValuesFileDir the grafana helm values .yaml file directory
393443 * @param grafanaVersion the version of the grafana helm chart
394444 * @return the grafana Helm installation parameters
395445 */
396446 public static GrafanaParams installAndVerifyGrafana (String grafanaReleaseName ,
397447 String grafanaNamespace ,
398- String grafanaValueFile ,
448+ String grafanaHelmValuesFileDir ,
399449 String grafanaVersion ) {
400450 LoggingFacade logger = getLogger ();
451+ logger .info ("create a staging location for grafana scripts" );
452+ Path fileTemp = Paths .get (grafanaHelmValuesFileDir );
453+ assertDoesNotThrow (() -> FileUtils .deleteDirectory (fileTemp .toFile ()),"Failed to delete temp dir for grafana" );
454+
455+ assertDoesNotThrow (() -> Files .createDirectories (fileTemp ), "Failed to create temp dir for grafana" );
456+
457+ logger .info ("copy the grafanavalues.yaml to staging location" );
458+ Path srcGrafanaFile = Paths .get (RESOURCE_DIR , "exporter" , "grafanavalues.yaml" );
459+ Path targetGrafanaFile = Paths .get (fileTemp .toString (), "grafanavalues.yaml" );
460+ assertDoesNotThrow (() -> Files .copy (srcGrafanaFile , targetGrafanaFile ,
461+ StandardCopyOption .REPLACE_EXISTING )," Failed to copy files" );
462+ assertDoesNotThrow (() -> replaceStringInFile (targetGrafanaFile .toString (),
463+ "pvc-grafana" , "pvc-" + grafanaReleaseName ));
464+ assertDoesNotThrow (() -> replaceStringInFile (targetGrafanaFile .toString (),
465+ "grafana_image" ,
466+ GRAFANA_IMAGE_NAME ),"Failed to replace String " );
467+ assertDoesNotThrow (() -> replaceStringInFile (targetGrafanaFile .toString (),
468+ "grafana_tag" ,
469+ GRAFANA_IMAGE_TAG ),"Failed to replace String " );
470+ assertDoesNotThrow (() -> replaceStringInFile (targetGrafanaFile .toString (),
471+ "busybox_image" ,
472+ BUSYBOX_IMAGE ), "Failed to replace String " );
473+ assertDoesNotThrow (() -> replaceStringInFile (targetGrafanaFile .toString (),
474+ "busybox_tag" ,
475+ BUSYBOX_TAG ), "Failed to replace String " );
476+
477+ if (!OKE_CLUSTER ) {
478+ assertDoesNotThrow (() -> replaceStringInFile (targetGrafanaFile .toString (),
479+ "enabled: false" , "enabled: true" ));
480+ }
401481 // Helm install parameters
402482 HelmParams grafanaHelmParams = new HelmParams ()
403483 .releaseName (grafanaReleaseName )
404484 .namespace (grafanaNamespace )
405485 .repoUrl (GRAFANA_REPO_URL )
406486 .repoName (GRAFANA_REPO_NAME )
407487 .chartName ("grafana" )
408- .chartValuesFile (grafanaValueFile );
488+ .chartValuesFile (targetGrafanaFile . toString () );
409489
410490 if (grafanaVersion != null ) {
411491 grafanaHelmParams .chartVersion (grafanaVersion );
@@ -429,6 +509,7 @@ public static GrafanaParams installAndVerifyGrafana(String grafanaReleaseName,
429509 logger .info ("Installing grafana in namespace {0}" , grafanaNamespace );
430510 int grafanaNodePort = getNextFreePort ();
431511 logger .info ("Installing grafana with node port {0}" , grafanaNodePort );
512+ assertDoesNotThrow (() -> logger .info (Files .readString (targetGrafanaFile )));
432513 // grafana chart values to override
433514 GrafanaParams grafanaParams = new GrafanaParams ()
434515 .helmParams (grafanaHelmParams )
@@ -454,7 +535,7 @@ public static GrafanaParams installAndVerifyGrafana(String grafanaReleaseName,
454535 logger .info ("Wait for the grafana pod is ready in namespace {0}" , grafanaNamespace );
455536 testUntil (
456537 assertDoesNotThrow (() -> isGrafanaReady (grafanaNamespace ),
457- "grafanaIsReady failed with ApiException" ),
538+ "grafanaIsReady failed with ApiException" ),
458539 logger ,
459540 "grafana to be running in namespace {0}" ,
460541 grafanaNamespace );
@@ -789,12 +870,11 @@ public static void verifyMonExpAppAccessThroughNginx(String nginxHost, int repli
789870 ADMIN_PASSWORD_DEFAULT ,
790871 K8S_NODEPORT_HOST ,
791872 nodeport );
792- assertThat (callWebAppAndCheckForServerNameInResponse (curlCmd , managedServerNames , 50 ))
793- .as ("Verify NGINX can access the monitoring exporter metrics "
794- + "from all managed servers in the domain via http" )
795- .withFailMessage ("NGINX can not access the monitoring exporter metrics "
796- + "from one or more of the managed servers via http" )
797- .isTrue ();
873+ testUntil (withLongRetryPolicy ,
874+ TestAssertions .callTestWebAppAndCheckForServerNameInResponse (curlCmd , managedServerNames , 200 ),
875+ logger ,
876+ "Verify NGINX can access the monitoring exporter metrics \n "
877+ + "from all managed servers in the domain via http" );
798878 }
799879
800880 /**
0 commit comments