|
46 | 46 | import static oracle.weblogic.kubernetes.TestConstants.OKD;
|
47 | 47 | import static oracle.weblogic.kubernetes.TestConstants.RESULTS_ROOT;
|
48 | 48 | import static oracle.weblogic.kubernetes.actions.ActionConstants.MODEL_DIR;
|
| 49 | +import static oracle.weblogic.kubernetes.actions.ActionConstants.REMOTECONSOLE; |
| 50 | +import static oracle.weblogic.kubernetes.actions.ActionConstants.REMOTECONSOLE_DOWNLOAD_FILENAME_DEFAULT; |
| 51 | +import static oracle.weblogic.kubernetes.actions.ActionConstants.REMOTECONSOLE_DOWNLOAD_URL_DEFAULT; |
| 52 | +import static oracle.weblogic.kubernetes.actions.ActionConstants.SNAKE; |
| 53 | +import static oracle.weblogic.kubernetes.actions.ActionConstants.SNAKE_DOWNLOADED_FILENAME; |
| 54 | +import static oracle.weblogic.kubernetes.actions.ActionConstants.WDT; |
| 55 | +import static oracle.weblogic.kubernetes.actions.ActionConstants.WDT_DOWNLOAD_FILENAME_DEFAULT; |
| 56 | +import static oracle.weblogic.kubernetes.actions.ActionConstants.WDT_DOWNLOAD_URL_DEFAULT; |
| 57 | +import static oracle.weblogic.kubernetes.actions.ActionConstants.WIT; |
| 58 | +import static oracle.weblogic.kubernetes.actions.ActionConstants.WIT_DOWNLOAD_FILENAME_DEFAULT; |
| 59 | +import static oracle.weblogic.kubernetes.actions.ActionConstants.WIT_DOWNLOAD_URL_DEFAULT; |
| 60 | +import static oracle.weblogic.kubernetes.actions.ActionConstants.WLE; |
| 61 | +import static oracle.weblogic.kubernetes.actions.ActionConstants.WLE_DOWNLOAD_FILENAME_DEFAULT; |
| 62 | +import static oracle.weblogic.kubernetes.actions.ActionConstants.WLE_DOWNLOAD_URL_DEFAULT; |
49 | 63 | import static oracle.weblogic.kubernetes.actions.TestActions.getPodCreationTimestamp;
|
50 | 64 | import static oracle.weblogic.kubernetes.actions.TestActions.getServiceNodePort;
|
51 | 65 | import static oracle.weblogic.kubernetes.actions.TestActions.scaleCluster;
|
52 | 66 | import static oracle.weblogic.kubernetes.actions.TestActions.scaleClusterWithRestApi;
|
53 | 67 | import static oracle.weblogic.kubernetes.actions.TestActions.scaleClusterWithWLDF;
|
54 | 68 | import static oracle.weblogic.kubernetes.actions.impl.UniqueName.random;
|
| 69 | +import static oracle.weblogic.kubernetes.actions.impl.primitive.Command.defaultCommandParams; |
55 | 70 | import static oracle.weblogic.kubernetes.assertions.TestAssertions.credentialsNotValid;
|
56 | 71 | import static oracle.weblogic.kubernetes.assertions.TestAssertions.credentialsValid;
|
57 | 72 | import static oracle.weblogic.kubernetes.assertions.TestAssertions.podStateNotChanged;
|
@@ -91,6 +106,7 @@ private static ConditionFactory createStandardRetryPolicyWithAtMost(long minutes
|
91 | 106 |
|
92 | 107 | public static ConditionFactory withStandardRetryPolicy = createStandardRetryPolicyWithAtMost(5);
|
93 | 108 | public static ConditionFactory withLongRetryPolicy = createStandardRetryPolicyWithAtMost(15);
|
| 109 | + private static final String TMP_FILE_NAME = "temp-download-file.out"; |
94 | 110 |
|
95 | 111 | /**
|
96 | 112 | * Test assertion using standard retry policy over time until it passes or the timeout expires.
|
@@ -1249,4 +1265,122 @@ public static String getUniqueName(String prefix, String... suffix) {
|
1249 | 1265 | getLogger().info("Creating unique name {0}", cmName);
|
1250 | 1266 | return cmName;
|
1251 | 1267 | }
|
| 1268 | + |
| 1269 | + /** |
| 1270 | + * If we use actual URL of WDT or WIT return it. If we use the "latest" release figure out the |
| 1271 | + * actual version number and construct the complete URL |
| 1272 | + * @return the actual download URL |
| 1273 | + * @throws RuntimeException if the operation failed for any reason |
| 1274 | + */ |
| 1275 | + public static String getActualLocationIfNeeded( |
| 1276 | + String location, |
| 1277 | + String type, |
| 1278 | + String downloadDir |
| 1279 | + ) throws RuntimeException { |
| 1280 | + String actualLocation = location; |
| 1281 | + if (needToGetActualLocation(location, type)) { |
| 1282 | + String version = ""; |
| 1283 | + String command = String.format( |
| 1284 | + "curl -fL %s -o %s/%s-%s", |
| 1285 | + location, |
| 1286 | + downloadDir, |
| 1287 | + type, |
| 1288 | + TMP_FILE_NAME); |
| 1289 | + |
| 1290 | + CommandParams params = |
| 1291 | + defaultCommandParams() |
| 1292 | + .command(command) |
| 1293 | + .saveResults(true); |
| 1294 | + if (!Command.withParams(params).execute()) { |
| 1295 | + RuntimeException exception = |
| 1296 | + new RuntimeException(String.format("Failed to get the latest %s release information.", type)); |
| 1297 | + getLogger().severe( |
| 1298 | + String.format( |
| 1299 | + "Failed to get the latest %s release information. The stderr is %s", |
| 1300 | + type, |
| 1301 | + params.stderr()), |
| 1302 | + exception); |
| 1303 | + throw exception; |
| 1304 | + } |
| 1305 | + |
| 1306 | + command = String.format( |
| 1307 | + "cat %s/%s-%s | grep 'releases/download' | awk '{ split($0,a,/href=\"/);%s | %s", |
| 1308 | + downloadDir, |
| 1309 | + type, |
| 1310 | + TMP_FILE_NAME, |
| 1311 | + " print a[2] }'", |
| 1312 | + " cut -d/ -f 6"); |
| 1313 | + |
| 1314 | + params = |
| 1315 | + defaultCommandParams() |
| 1316 | + .command(command) |
| 1317 | + .saveResults(true) |
| 1318 | + .redirect(true); |
| 1319 | + |
| 1320 | + // the command is considered successful only if we have got back a real version number in params.stdout() |
| 1321 | + if (Command.withParams(params).execute() |
| 1322 | + && params.stdout() != null |
| 1323 | + && params.stdout().length() != 0) { |
| 1324 | + // Because I've updated the name of the logging exporter to remove the version number in the name, but |
| 1325 | + // also preserved the original, there will be two entries located. Take the first. |
| 1326 | + version = params.stdout().lines().findFirst().get().trim(); |
| 1327 | + } else { |
| 1328 | + RuntimeException exception = |
| 1329 | + new RuntimeException(String.format("Failed to get the version number of the requested %s release.", type)); |
| 1330 | + getLogger().severe( |
| 1331 | + String.format( |
| 1332 | + "Failed to get the version number of the requested %s release. The stderr is %s", |
| 1333 | + type, |
| 1334 | + params.stderr()), |
| 1335 | + exception); |
| 1336 | + throw exception; |
| 1337 | + } |
| 1338 | + |
| 1339 | + if (version != null) { |
| 1340 | + actualLocation = location.replace("latest", |
| 1341 | + String.format("download/%s/%s", version, getInstallerFileName(type))); |
| 1342 | + } |
| 1343 | + } |
| 1344 | + getLogger().info("The actual download location for {0} is {1}", type, actualLocation); |
| 1345 | + return actualLocation; |
| 1346 | + } |
| 1347 | + |
| 1348 | + private static boolean needToGetActualLocation( |
| 1349 | + String location, |
| 1350 | + String type) { |
| 1351 | + switch (type) { |
| 1352 | + case WDT: |
| 1353 | + return WDT_DOWNLOAD_URL_DEFAULT.equals(location); |
| 1354 | + case WIT: |
| 1355 | + return WIT_DOWNLOAD_URL_DEFAULT.equals(location); |
| 1356 | + case WLE: |
| 1357 | + return WLE_DOWNLOAD_URL_DEFAULT.equals(location); |
| 1358 | + case REMOTECONSOLE: |
| 1359 | + return REMOTECONSOLE_DOWNLOAD_URL_DEFAULT.equals(location); |
| 1360 | + default: |
| 1361 | + return false; |
| 1362 | + } |
| 1363 | + } |
| 1364 | + |
| 1365 | + /** |
| 1366 | + * Get the installer download filename. |
| 1367 | + * @return the download filename |
| 1368 | + */ |
| 1369 | + public static String getInstallerFileName( |
| 1370 | + String type) { |
| 1371 | + switch (type) { |
| 1372 | + case WDT: |
| 1373 | + return WDT_DOWNLOAD_FILENAME_DEFAULT; |
| 1374 | + case WIT: |
| 1375 | + return WIT_DOWNLOAD_FILENAME_DEFAULT; |
| 1376 | + case WLE: |
| 1377 | + return WLE_DOWNLOAD_FILENAME_DEFAULT; |
| 1378 | + case SNAKE: |
| 1379 | + return SNAKE_DOWNLOADED_FILENAME; |
| 1380 | + case REMOTECONSOLE: |
| 1381 | + return REMOTECONSOLE_DOWNLOAD_FILENAME_DEFAULT; |
| 1382 | + default: |
| 1383 | + return ""; |
| 1384 | + } |
| 1385 | + } |
1252 | 1386 | }
|
0 commit comments