|
10 | 10 | import java.util.Collection;
|
11 | 11 | import java.util.Collections;
|
12 | 12 | import java.util.HashMap;
|
| 13 | +import java.util.Iterator; |
13 | 14 | import java.util.List;
|
14 | 15 | import java.util.Map;
|
15 | 16 | import java.util.concurrent.CountDownLatch;
|
16 | 17 | import java.util.concurrent.atomic.AtomicBoolean;
|
17 | 18 |
|
| 19 | +import com.fasterxml.jackson.core.JsonProcessingException; |
| 20 | +import com.fasterxml.jackson.databind.JsonNode; |
| 21 | +import com.fasterxml.jackson.databind.ObjectMapper; |
18 | 22 | import oracle.weblogic.kubernetes.TestConstants;
|
19 | 23 | import oracle.weblogic.kubernetes.actions.impl.Operator;
|
20 | 24 | import oracle.weblogic.kubernetes.utils.ExecCommand;
|
@@ -243,7 +247,65 @@ private void deleteImageOcir(String token, String imageName) {
|
243 | 247 | }
|
244 | 248 | if (result != null) {
|
245 | 249 | logger.info("result.stdout: \n{0}", result.stdout());
|
| 250 | + String stdout = result.stdout(); |
| 251 | + logger.info("result.stdout: \n{0}", stdout); |
246 | 252 | logger.info("result.stderr: \n{0}", result.stderr());
|
| 253 | + |
| 254 | + // check if delete was successful and respond if tag couldn't be deleted because there is only one image |
| 255 | + if (!stdout.isEmpty()) { |
| 256 | + ObjectMapper mapper = new ObjectMapper(); |
| 257 | + try { |
| 258 | + JsonNode root = mapper.readTree(stdout); |
| 259 | + JsonNode errors = root.path("errors"); |
| 260 | + if (errors != null) { |
| 261 | + Iterator<JsonNode> it = errors.elements(); |
| 262 | + while (it.hasNext()) { |
| 263 | + JsonNode entry = it.next(); |
| 264 | + if (entry != null) { |
| 265 | + JsonNode code = entry.path("code"); |
| 266 | + if (code != null) { |
| 267 | + if ("SEMANTIC_VALIDATION_ERROR".equals(code.asText())) { |
| 268 | + // The delete of the tag failed because there is only one tag remaining in the |
| 269 | + // repository |
| 270 | + // Note: there are probably other semantic validation errors, but I don't think |
| 271 | + // it's worth |
| 272 | + // checking now because our use cases are fairly simple |
| 273 | + |
| 274 | + int colonIdx = imageAndTag.indexOf(':'); |
| 275 | + String repo = imageAndTag.substring(0, colonIdx); |
| 276 | + |
| 277 | + // Delete the repository |
| 278 | + curlCmd = |
| 279 | + "curl -skL -X \"DELETE\" -H \"Authorization: Bearer " |
| 280 | + + token |
| 281 | + + "\" \"https://" |
| 282 | + + registry |
| 283 | + + "/20180419/docker/repos/" |
| 284 | + + tenancy |
| 285 | + + "/" |
| 286 | + + repo |
| 287 | + + "\""; |
| 288 | + logger.info("About to invoke: " + curlCmd); |
| 289 | + result = null; |
| 290 | + try { |
| 291 | + result = ExecCommand.exec(curlCmd, true); |
| 292 | + } catch (Exception e) { |
| 293 | + logger.info("Got exception while running command: {0}", curlCmd); |
| 294 | + logger.info(e.toString()); |
| 295 | + } |
| 296 | + if (result != null) { |
| 297 | + logger.info("result.stdout: \n{0}", result.stdout()); |
| 298 | + logger.info("result.stderr: \n{0}", result.stderr()); |
| 299 | + } |
| 300 | + } |
| 301 | + } |
| 302 | + } |
| 303 | + } |
| 304 | + } |
| 305 | + } catch (JsonProcessingException e) { |
| 306 | + logger.info("Got exception, parsing failed with errors " + e.getMessage()); |
| 307 | + } |
| 308 | + } |
247 | 309 | }
|
248 | 310 | }
|
249 | 311 |
|
|
0 commit comments