|
19 | 19 | import io.kubernetes.client.openapi.models.V1EnvVar; |
20 | 20 | import io.kubernetes.client.openapi.models.V1LocalObjectReference; |
21 | 21 | import io.kubernetes.client.openapi.models.V1ObjectMeta; |
22 | | -import io.kubernetes.client.openapi.models.V1Pod; |
23 | 22 | import io.kubernetes.client.openapi.models.V1Secret; |
24 | 23 | import io.kubernetes.client.openapi.models.V1SecretList; |
25 | 24 | import io.kubernetes.client.openapi.models.V1SecretReference; |
|
51 | 50 | import static oracle.weblogic.kubernetes.TestConstants.DOMAIN_API_VERSION; |
52 | 51 | import static oracle.weblogic.kubernetes.TestConstants.GRAFANA_REPO_NAME; |
53 | 52 | import static oracle.weblogic.kubernetes.TestConstants.GRAFANA_REPO_URL; |
54 | | -import static oracle.weblogic.kubernetes.TestConstants.HTTPS_PROXY; |
55 | 53 | import static oracle.weblogic.kubernetes.TestConstants.K8S_NODEPORT_HOST; |
56 | 54 | import static oracle.weblogic.kubernetes.TestConstants.MANAGED_SERVER_NAME_BASE; |
57 | 55 | import static oracle.weblogic.kubernetes.TestConstants.MONITORING_EXPORTER_BRANCH; |
|
64 | 62 | import static oracle.weblogic.kubernetes.actions.ActionConstants.MONITORING_EXPORTER_DOWNLOAD_URL; |
65 | 63 | import static oracle.weblogic.kubernetes.actions.ActionConstants.RESOURCE_DIR; |
66 | 64 | import static oracle.weblogic.kubernetes.actions.TestActions.deleteSecret; |
67 | | -import static oracle.weblogic.kubernetes.actions.TestActions.getPod; |
68 | 65 | import static oracle.weblogic.kubernetes.actions.TestActions.installGrafana; |
69 | 66 | import static oracle.weblogic.kubernetes.actions.TestActions.installPrometheus; |
70 | | -import static oracle.weblogic.kubernetes.actions.impl.primitive.Kubernetes.copyFileToPod; |
71 | 67 | import static oracle.weblogic.kubernetes.actions.impl.primitive.Kubernetes.listSecrets; |
72 | 68 | import static oracle.weblogic.kubernetes.assertions.TestAssertions.isGrafanaReady; |
73 | 69 | import static oracle.weblogic.kubernetes.assertions.TestAssertions.isHelmReleaseDeployed; |
|
80 | 76 | import static oracle.weblogic.kubernetes.utils.DomainUtils.createDomainAndVerify; |
81 | 77 | import static oracle.weblogic.kubernetes.utils.FileUtils.checkFile; |
82 | 78 | import static oracle.weblogic.kubernetes.utils.FileUtils.replaceStringInFile; |
| 79 | +import static oracle.weblogic.kubernetes.utils.ImageUtils.createImageAndPushToRepo; |
83 | 80 | import static oracle.weblogic.kubernetes.utils.ImageUtils.createMiiImageAndVerify; |
84 | 81 | import static oracle.weblogic.kubernetes.utils.ImageUtils.createTestRepoSecret; |
85 | 82 | import static oracle.weblogic.kubernetes.utils.ImageUtils.dockerLoginAndPushImageToRegistry; |
86 | | -import static oracle.weblogic.kubernetes.utils.PodUtils.execInPod; |
87 | 83 | import static oracle.weblogic.kubernetes.utils.PodUtils.setPodAntiAffinity; |
88 | 84 | import static oracle.weblogic.kubernetes.utils.SecretUtils.createSecretWithUsernamePassword; |
89 | 85 | import static oracle.weblogic.kubernetes.utils.ThreadSafeLogger.getLogger; |
|
94 | 90 | import static org.junit.jupiter.api.Assertions.assertTrue; |
95 | 91 |
|
96 | 92 | /** |
97 | | - * A utility class for Monitoring Weblogic Domain via Weblogic MonitoringExporter and Prometheus. |
| 93 | + * A utility class for Monitoring WebLogic Domain via WebLogic MonitoringExporter and Prometheus. |
98 | 94 | */ |
99 | 95 | public class MonitoringUtils { |
100 | 96 |
|
@@ -771,53 +767,6 @@ public static void createAndVerifyDomain(String miiImage, |
771 | 767 | } |
772 | 768 | } |
773 | 769 |
|
774 | | - /** |
775 | | - * Install wls dashboard from endtoend sample and verify it is accessable. |
776 | | - * |
777 | | - * @param hostPort host:nodeport string for grafana |
778 | | - * @param monitoringExporterEndToEndDir endtoend sample directory |
779 | | - * |
780 | | - */ |
781 | | - //public static void installVerifyGrafanaDashBoard(int nodeportGrafana, String monitoringExporterEndToEndDir) { |
782 | | - public static void installVerifyGrafanaDashBoard(String hostPort, String monitoringExporterEndToEndDir) { |
783 | | - //wait until it starts dashboard |
784 | | - String curlCmd = String.format("curl -v -H 'Content-Type: application/json' " |
785 | | - + " -X GET http://admin:12345678@%s/api/dashboards", |
786 | | - hostPort); |
787 | | - testUntil( |
788 | | - assertDoesNotThrow(() -> searchForKey(curlCmd, "grafana"), |
789 | | - String.format("Check access to grafana dashboard")), |
790 | | - logger, |
791 | | - "Check access to grafana dashboard"); |
792 | | - logger.info("installing grafana dashboard"); |
793 | | - // url |
794 | | - String curlCmd0 = |
795 | | - String.format("curl -v -H 'Content-Type: application/json' -H \"Content-Type: application/json\"" |
796 | | - + " -X POST http://admin:12345678@%s/api/datasources/" |
797 | | - + " --data-binary @%s/grafana/datasource.json", |
798 | | - hostPort, monitoringExporterEndToEndDir); |
799 | | - |
800 | | - logger.info("Executing Curl cmd {0}", curlCmd); |
801 | | - assertDoesNotThrow(() -> ExecCommand.exec(curlCmd0)); |
802 | | - |
803 | | - String curlCmd1 = |
804 | | - String.format("curl -v -H 'Content-Type: application/json' -H \"Content-Type: application/json\"" |
805 | | - + " -X POST http://admin:12345678@%s/api/dashboards/db/" |
806 | | - + " --data-binary @%s/grafana/dashboard.json", |
807 | | - hostPort, monitoringExporterEndToEndDir); |
808 | | - logger.info("Executing Curl cmd {0}", curlCmd1); |
809 | | - assertDoesNotThrow(() -> ExecCommand.exec(curlCmd1)); |
810 | | - |
811 | | - String curlCmd2 = String.format("curl -v -H 'Content-Type: application/json' " |
812 | | - + " -X GET http://admin:12345678@%s/api/dashboards/db/weblogic-server-dashboard", |
813 | | - hostPort); |
814 | | - testUntil( |
815 | | - assertDoesNotThrow(() -> searchForKey(curlCmd2, "wls_jvm_uptime"), |
816 | | - String.format("Check grafana dashboard wls against expected %s", "wls_jvm_uptime")), |
817 | | - logger, |
818 | | - "Check grafana dashboard metric against expected wls_jvm_uptime"); |
819 | | - } |
820 | | - |
821 | 770 | /** |
822 | 771 | * Verify the monitoring exporter app can be accessed from all managed servers in the domain through NGINX. |
823 | 772 | * |
@@ -953,63 +902,25 @@ public static boolean verifyMonExpAppAccessSideCar(String searchKey, |
953 | 902 | return isFound; |
954 | 903 | } |
955 | 904 |
|
956 | | - /** To build monitoring exporter sidecar image. |
| 905 | + /** |
| 906 | + * Build exporter, create image with unique name, create corresponding repo secret and push to registry. |
957 | 907 | * |
958 | | - * @param imageName image nmae |
959 | | - * @param monitoringExporterSrcDir path to monitoring exporter src location |
| 908 | + * @param srcDir directory where source is located |
| 909 | + * @param baseImageName base image name |
| 910 | + * @param namespace image namespace |
| 911 | + * @param secretName repo secretname for image |
| 912 | + * @param extraImageBuilderArgs user specified extra args |
| 913 | + * @return image name |
960 | 914 | */ |
961 | | - public static void buildMonitoringExporterImage(String imageName, String monitoringExporterSrcDir) { |
962 | | - String httpsproxy = HTTPS_PROXY; |
963 | | - logger.info(" httpsproxy : " + httpsproxy); |
964 | | - String proxyHost = ""; |
965 | | - String command; |
966 | | - if (httpsproxy != null) { |
967 | | - int firstIndex = httpsproxy.lastIndexOf("www"); |
968 | | - int lastIndex = httpsproxy.lastIndexOf(":"); |
969 | | - logger.info("Got indexes : " + firstIndex + " : " + lastIndex); |
970 | | - proxyHost = httpsproxy.substring(firstIndex,lastIndex); |
971 | | - logger.info(" proxyHost: " + proxyHost); |
972 | | - |
973 | | - command = String.format("cd %s && mvn clean install -Dmaven.test.skip=true " |
974 | | - + " && docker build . -t " |
975 | | - + imageName |
976 | | - + " --build-arg MAVEN_OPTS=\"-Dhttps.proxyHost=%s -Dhttps.proxyPort=80\" --build-arg https_proxy=%s", |
977 | | - monitoringExporterSrcDir, proxyHost, httpsproxy); |
978 | | - } else { |
979 | | - command = String.format("cd %s && mvn clean install -Dmaven.test.skip=true " |
980 | | - + " && docker build . -t " |
981 | | - + imageName |
982 | | - + monitoringExporterSrcDir); |
983 | | - } |
| 915 | + public static String buildMonitoringExporterCreateImageAndPushToRepo( |
| 916 | + String srcDir, String baseImageName, String namespace, String secretName, |
| 917 | + String extraImageBuilderArgs) throws ApiException { |
| 918 | + String command = String.format("cd %s && mvn clean install -Dmaven.test.skip=true", srcDir); |
984 | 919 | logger.info("Executing command " + command); |
985 | 920 | assertTrue(Command |
986 | 921 | .withParams(new CommandParams() |
987 | 922 | .command(command)) |
988 | | - .execute(), "Failed to build monitoring exporter image"); |
989 | | - // docker login and push image to docker registry if necessary |
990 | | - dockerLoginAndPushImageToRegistry(imageName); |
| 923 | + .execute(), "Failed to build monitoring exporter"); |
| 924 | + return createImageAndPushToRepo(srcDir, baseImageName, namespace, secretName, extraImageBuilderArgs); |
991 | 925 | } |
992 | | - |
993 | | - /** Change monitoring exporter webapp confiuration inside the pod. |
994 | | - * |
995 | | - * @param podName pod name |
996 | | - * @param namespace pod namespace |
997 | | - * @param configYaml monitorin exporter configuration |
998 | | - */ |
999 | | - public static void changeConfigInPod(String podName, String namespace, String configYaml) { |
1000 | | - V1Pod exporterPod = assertDoesNotThrow(() -> getPod(namespace, "", podName), |
1001 | | - " Can't retreive pod " + podName); |
1002 | | - logger.info("Copying config file {0} to pod directory {1}", |
1003 | | - Paths.get(RESOURCE_DIR,"/exporter/" + configYaml).toString(), "/tmp/" + configYaml); |
1004 | | - assertDoesNotThrow(() -> copyFileToPod(namespace, podName, "monitoring-exporter", |
1005 | | - Paths.get(RESOURCE_DIR,"/exporter/" + configYaml), Paths.get("/tmp/" + configYaml)), |
1006 | | - "Copying file to pod failed"); |
1007 | | - execInPod(exporterPod, "monitoring-exporter", true, |
1008 | | - "curl -X PUT -H \"content-type: application/yaml\" --data-binary \"@/tmp/" |
1009 | | - + configYaml + "\" -i -u weblogic:welcome1 http://localhost:8080/configuration"); |
1010 | | - execInPod(exporterPod, "monitoring-exporter", true, "curl -X GET " |
1011 | | - + " -i -u weblogic:welcome1 http://localhost:8080/metrics"); |
1012 | | - |
1013 | | - } |
1014 | | - |
1015 | 926 | } |
0 commit comments