|
21 | 21 | import io.kubernetes.client.openapi.models.V1EnvVar; |
22 | 22 | import io.kubernetes.client.openapi.models.V1LocalObjectReference; |
23 | 23 | import io.kubernetes.client.openapi.models.V1ObjectMeta; |
24 | | -import io.kubernetes.client.openapi.models.V1Pod; |
25 | 24 | import io.kubernetes.client.openapi.models.V1Secret; |
26 | 25 | import io.kubernetes.client.openapi.models.V1SecretList; |
27 | 26 | import oracle.weblogic.domain.AdminServer; |
|
57 | 56 | import static oracle.weblogic.kubernetes.TestConstants.FAILURE_RETRY_LIMIT_MINUTES; |
58 | 57 | import static oracle.weblogic.kubernetes.TestConstants.GRAFANA_REPO_NAME; |
59 | 58 | import static oracle.weblogic.kubernetes.TestConstants.GRAFANA_REPO_URL; |
60 | | -import static oracle.weblogic.kubernetes.TestConstants.HTTPS_PROXY; |
61 | 59 | import static oracle.weblogic.kubernetes.TestConstants.IMAGE_PULL_POLICY; |
62 | 60 | import static oracle.weblogic.kubernetes.TestConstants.K8S_NODEPORT_HOST; |
63 | 61 | import static oracle.weblogic.kubernetes.TestConstants.KUBERNETES_CLI; |
|
69 | 67 | import static oracle.weblogic.kubernetes.TestConstants.PROMETHEUS_REPO_NAME; |
70 | 68 | import static oracle.weblogic.kubernetes.TestConstants.PROMETHEUS_REPO_URL; |
71 | 69 | import static oracle.weblogic.kubernetes.TestConstants.TEST_IMAGES_REPO_SECRET_NAME; |
72 | | -import static oracle.weblogic.kubernetes.TestConstants.WLSIMG_BUILDER; |
73 | 70 | import static oracle.weblogic.kubernetes.actions.ActionConstants.MONITORING_EXPORTER_DOWNLOAD_URL; |
74 | 71 | import static oracle.weblogic.kubernetes.actions.ActionConstants.RESOURCE_DIR; |
75 | 72 | import static oracle.weblogic.kubernetes.actions.TestActions.deleteSecret; |
76 | | -import static oracle.weblogic.kubernetes.actions.TestActions.getPod; |
77 | 73 | import static oracle.weblogic.kubernetes.actions.TestActions.installGrafana; |
78 | 74 | import static oracle.weblogic.kubernetes.actions.TestActions.installPrometheus; |
79 | | -import static oracle.weblogic.kubernetes.actions.impl.primitive.Kubernetes.copyFileToPod; |
80 | 75 | import static oracle.weblogic.kubernetes.actions.impl.primitive.Kubernetes.listSecrets; |
81 | 76 | import static oracle.weblogic.kubernetes.assertions.TestAssertions.callTestWebAppAndCheckForServerNameInResponse; |
82 | 77 | import static oracle.weblogic.kubernetes.assertions.TestAssertions.isGrafanaReady; |
|
94 | 89 | import static oracle.weblogic.kubernetes.utils.DomainUtils.createDomainAndVerify; |
95 | 90 | import static oracle.weblogic.kubernetes.utils.FileUtils.checkFile; |
96 | 91 | import static oracle.weblogic.kubernetes.utils.FileUtils.replaceStringInFile; |
| 92 | +import static oracle.weblogic.kubernetes.utils.ImageUtils.createImageAndPushToRepo; |
97 | 93 | import static oracle.weblogic.kubernetes.utils.ImageUtils.createMiiImageAndVerify; |
98 | 94 | import static oracle.weblogic.kubernetes.utils.ImageUtils.createTestRepoSecret; |
99 | 95 | import static oracle.weblogic.kubernetes.utils.ImageUtils.imageRepoLoginAndPushImageToRegistry; |
100 | | -import static oracle.weblogic.kubernetes.utils.PodUtils.execInPod; |
101 | 96 | import static oracle.weblogic.kubernetes.utils.PodUtils.getPodName; |
102 | 97 | import static oracle.weblogic.kubernetes.utils.PodUtils.setPodAntiAffinity; |
103 | 98 | import static oracle.weblogic.kubernetes.utils.SecretUtils.createSecretWithUsernamePassword; |
|
109 | 104 | import static org.junit.jupiter.api.Assertions.assertTrue; |
110 | 105 |
|
111 | 106 | /** |
112 | | - * A utility class for Monitoring Weblogic Domain via Weblogic MonitoringExporter and Prometheus. |
| 107 | + * A utility class for Monitoring WebLogic Domain via WebLogic MonitoringExporter and Prometheus. |
113 | 108 | */ |
114 | 109 | public class MonitoringUtils { |
115 | 110 |
|
@@ -1000,52 +995,6 @@ public static void createAndVerifyDomain(String miiImage, |
1000 | 995 | } |
1001 | 996 | } |
1002 | 997 |
|
1003 | | - /** |
1004 | | - * Install wls dashboard from endtoend sample and verify it is accessable. |
1005 | | - * |
1006 | | - * @param hostPort host:nodeport string for grafana |
1007 | | - * @param monitoringExporterEndToEndDir endtoend sample directory |
1008 | | - * |
1009 | | - */ |
1010 | | - //public static void installVerifyGrafanaDashBoard(int nodeportGrafana, String monitoringExporterEndToEndDir) { |
1011 | | - public static void installVerifyGrafanaDashBoard(String hostPort, String monitoringExporterEndToEndDir) { |
1012 | | - //wait until it starts dashboard |
1013 | | - String curlCmd = String.format("curl -v -H 'Content-Type: application/json' " |
1014 | | - + " -X GET http://admin:12345678@%s/api/dashboards", |
1015 | | - hostPort); |
1016 | | - testUntil( |
1017 | | - assertDoesNotThrow(() -> searchForKey(curlCmd, "grafana"), "Check access to grafana dashboard"), |
1018 | | - logger, |
1019 | | - "Check access to grafana dashboard"); |
1020 | | - logger.info("installing grafana dashboard"); |
1021 | | - // url |
1022 | | - String curlCmd0 = |
1023 | | - String.format("curl -v -H 'Content-Type: application/json' -H \"Content-Type: application/json\"" |
1024 | | - + " -X POST http://admin:12345678@%s/api/datasources/" |
1025 | | - + " --data-binary @%s/grafana/datasource.json", |
1026 | | - hostPort, monitoringExporterEndToEndDir); |
1027 | | - |
1028 | | - logger.info("Executing Curl cmd {0}", curlCmd); |
1029 | | - assertDoesNotThrow(() -> ExecCommand.exec(curlCmd0)); |
1030 | | - |
1031 | | - String curlCmd1 = |
1032 | | - String.format("curl -v -H 'Content-Type: application/json' -H \"Content-Type: application/json\"" |
1033 | | - + " -X POST http://admin:12345678@%s/api/dashboards/db/" |
1034 | | - + " --data-binary @%s/grafana/dashboard.json", |
1035 | | - hostPort, monitoringExporterEndToEndDir); |
1036 | | - logger.info("Executing Curl cmd {0}", curlCmd1); |
1037 | | - assertDoesNotThrow(() -> ExecCommand.exec(curlCmd1)); |
1038 | | - |
1039 | | - String curlCmd2 = String.format("curl -v -H 'Content-Type: application/json' " |
1040 | | - + " -X GET http://admin:12345678@%s/api/dashboards/db/weblogic-server-dashboard", |
1041 | | - hostPort); |
1042 | | - testUntil( |
1043 | | - assertDoesNotThrow(() -> searchForKey(curlCmd2, "wls_jvm_uptime"), |
1044 | | - String.format("Check grafana dashboard wls against expected %s", "wls_jvm_uptime")), |
1045 | | - logger, |
1046 | | - "Check grafana dashboard metric against expected wls_jvm_uptime"); |
1047 | | - } |
1048 | | - |
1049 | 998 | /** |
1050 | 999 | * Verify the monitoring exporter app can be accessed from all managed servers in the domain through NGINX. |
1051 | 1000 | * |
@@ -1180,63 +1129,25 @@ public static boolean verifyMonExpAppAccessSideCar(String searchKey, |
1180 | 1129 | return isFound; |
1181 | 1130 | } |
1182 | 1131 |
|
1183 | | - /** To build monitoring exporter sidecar image. |
| 1132 | + /** |
| 1133 | + * Build exporter, create image with unique name, create corresponding repo secret and push to registry. |
1184 | 1134 | * |
1185 | | - * @param imageName image nmae |
1186 | | - * @param monitoringExporterSrcDir path to monitoring exporter src location |
| 1135 | + * @param srcDir directory where source is located |
| 1136 | + * @param baseImageName base image name |
| 1137 | + * @param namespace image namespace |
| 1138 | + * @param secretName repo secretname for image |
| 1139 | + * @param extraImageBuilderArgs user specified extra args |
| 1140 | + * @return image name |
1187 | 1141 | */ |
1188 | | - public static void buildMonitoringExporterImage(String imageName, String monitoringExporterSrcDir) { |
1189 | | - String httpsproxy = HTTPS_PROXY; |
1190 | | - logger.info(" httpsproxy : " + httpsproxy); |
1191 | | - String proxyHost = ""; |
1192 | | - String command; |
1193 | | - if (httpsproxy != null) { |
1194 | | - int firstIndex = httpsproxy.lastIndexOf("www"); |
1195 | | - int lastIndex = httpsproxy.lastIndexOf(":"); |
1196 | | - logger.info("Got indexes : " + firstIndex + " : " + lastIndex); |
1197 | | - proxyHost = httpsproxy.substring(firstIndex,lastIndex); |
1198 | | - logger.info(" proxyHost: " + proxyHost); |
1199 | | - |
1200 | | - command = String.format("cd %s && mvn clean install -Dmaven.test.skip=true " |
1201 | | - + " && " + WLSIMG_BUILDER + " build . -t " |
1202 | | - + imageName |
1203 | | - + " --build-arg MAVEN_OPTS=\"-Dhttps.proxyHost=%s -Dhttps.proxyPort=80\" --build-arg https_proxy=%s", |
1204 | | - monitoringExporterSrcDir, proxyHost, httpsproxy); |
1205 | | - } else { |
1206 | | - command = String.format("cd %s && mvn clean install -Dmaven.test.skip=true " |
1207 | | - + " && " + WLSIMG_BUILDER + " build . -t " |
1208 | | - + imageName |
1209 | | - + monitoringExporterSrcDir); |
1210 | | - } |
| 1142 | + public static String buildMonitoringExporterCreateImageAndPushToRepo(String srcDir, String baseImageName, |
| 1143 | + String namespace, String secretName, |
| 1144 | + String extraImageBuilderArgs) throws ApiException { |
| 1145 | + String command = String.format("cd %s && mvn clean install -Dmaven.test.skip=true", srcDir); |
1211 | 1146 | logger.info("Executing command " + command); |
1212 | 1147 | assertTrue(Command |
1213 | 1148 | .withParams(new CommandParams() |
1214 | 1149 | .command(command)) |
1215 | | - .execute(), "Failed to build monitoring exporter image"); |
1216 | | - // login and push image to registry if necessary |
1217 | | - imageRepoLoginAndPushImageToRegistry(imageName); |
| 1150 | + .execute(), "Failed to build monitoring exporter"); |
| 1151 | + return createImageAndPushToRepo(srcDir, baseImageName, namespace, secretName, extraImageBuilderArgs); |
1218 | 1152 | } |
1219 | | - |
1220 | | - /** Change monitoring exporter webapp confiuration inside the pod. |
1221 | | - * |
1222 | | - * @param podName pod name |
1223 | | - * @param namespace pod namespace |
1224 | | - * @param configYaml monitorin exporter configuration |
1225 | | - */ |
1226 | | - public static void changeConfigInPod(String podName, String namespace, String configYaml) { |
1227 | | - V1Pod exporterPod = assertDoesNotThrow(() -> getPod(namespace, "", podName), |
1228 | | - " Can't retreive pod " + podName); |
1229 | | - logger.info("Copying config file {0} to pod directory {1}", |
1230 | | - Paths.get(RESOURCE_DIR,"/exporter/" + configYaml).toString(), "/tmp/" + configYaml); |
1231 | | - assertDoesNotThrow(() -> copyFileToPod(namespace, podName, "monitoring-exporter", |
1232 | | - Paths.get(RESOURCE_DIR,"/exporter/" + configYaml), Paths.get("/tmp/" + configYaml)), |
1233 | | - "Copying file to pod failed"); |
1234 | | - execInPod(exporterPod, "monitoring-exporter", true, |
1235 | | - "curl -X PUT -H \"content-type: application/yaml\" --data-binary \"@/tmp/" |
1236 | | - + configYaml + "\" -i -u weblogic:welcome1 http://localhost:8080/configuration"); |
1237 | | - execInPod(exporterPod, "monitoring-exporter", true, "curl -X GET " |
1238 | | - + " -i -u weblogic:welcome1 http://localhost:8080/metrics"); |
1239 | | - |
1240 | | - } |
1241 | | - |
1242 | 1153 | } |
0 commit comments