From e955fb8af1d10d51e5ce60baec011d7a3d9c087e Mon Sep 17 00:00:00 2001 From: Jonathan Cobb Date: Sat, 6 Jun 2020 01:41:37 -0400 Subject: [PATCH] filter servers/images based on installType --- .../bubble/cloud/compute/ComputeServiceDriver.java | 3 ++- .../java/bubble/cloud/compute/vultr/VultrDriver.java | 12 ++++++------ .../main/java/bubble/service/packer/PackerJob.java | 2 +- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/bubble-server/src/main/java/bubble/cloud/compute/ComputeServiceDriver.java b/bubble-server/src/main/java/bubble/cloud/compute/ComputeServiceDriver.java index a5c508f0..c9eec8dd 100644 --- a/bubble-server/src/main/java/bubble/cloud/compute/ComputeServiceDriver.java +++ b/bubble-server/src/main/java/bubble/cloud/compute/ComputeServiceDriver.java @@ -6,6 +6,7 @@ package bubble.cloud.compute; import bubble.cloud.CloudServiceDriver; import bubble.cloud.CloudServiceType; +import bubble.model.cloud.AnsibleInstallType; import bubble.model.cloud.BubbleNode; import bubble.model.cloud.RegionalServiceDriver; import org.cobbzilla.util.system.CommandResult; @@ -35,6 +36,6 @@ public interface ComputeServiceDriver extends CloudServiceDriver, RegionalServic @Override default boolean test () { return true; } List getPackerImages(); - default List finalizeIncompletePackerRun(CommandResult commandResult, String jarSha) { return null; } + default List finalizeIncompletePackerRun(CommandResult commandResult, AnsibleInstallType installType, String jarSha) { return null; } } diff --git a/bubble-server/src/main/java/bubble/cloud/compute/vultr/VultrDriver.java b/bubble-server/src/main/java/bubble/cloud/compute/vultr/VultrDriver.java index c0e8d1b7..23e04a2a 100644 --- a/bubble-server/src/main/java/bubble/cloud/compute/vultr/VultrDriver.java +++ b/bubble-server/src/main/java/bubble/cloud/compute/vultr/VultrDriver.java @@ -411,11 +411,11 @@ public class VultrDriver extends ComputeServiceDriverBase { } public static final long SNAPSHOT_TIMEOUT = MINUTES.toMillis(60); - @Override public List finalizeIncompletePackerRun(CommandResult commandResult, String jarSha) { + @Override public List finalizeIncompletePackerRun(CommandResult commandResult, AnsibleInstallType installType, String jarSha) { if (!commandResult.getStdout().contains("Waiting 300s for snapshot") || !commandResult.getStdout().contains("Error waiting for snapshot") || !commandResult.getStdout().contains("Unable to destroy server: Unable to remove VM: Server is currently locked")) { - stopImageServer(jarSha); + stopImageServer(installType, jarSha); return null; } @@ -424,7 +424,7 @@ public class VultrDriver extends ComputeServiceDriverBase { PackerImage snapshot = null; while (now() - start < SNAPSHOT_TIMEOUT) { snapshot = getPackerImages().stream() - .filter(i -> i.getName().endsWith(jarSha)) + .filter(i -> i.getName().contains("_"+installType.name()+"_") && i.getName().endsWith(jarSha)) .findFirst() .orElse(null); if (snapshot != null) break; @@ -434,19 +434,19 @@ public class VultrDriver extends ComputeServiceDriverBase { log.error("finalizeIncompletePackerRun: timeout waiting for snapshot"); } - if (!stopImageServer(jarSha)) return null; + if (!stopImageServer(installType, jarSha)) return null; if (snapshot == null) return null; return new SingletonList<>(snapshot); } - public boolean stopImageServer(String jarSha) { + public boolean stopImageServer(AnsibleInstallType installType, String jarSha) { // find the server final List servers; try { servers = listNodes(server -> { final String tag = server.has("tag") ? server.get("tag").textValue() : null; - return tag != null && tag.endsWith(jarSha); + return tag != null && tag.contains("_"+installType.name()+"_") && tag.endsWith(jarSha); }); } catch (IOException e) { log.error("finalizeIncompletePackerRun: error listing servers: "+shortError(e), e); diff --git a/bubble-server/src/main/java/bubble/service/packer/PackerJob.java b/bubble-server/src/main/java/bubble/service/packer/PackerJob.java index 06a728fb..64e40444 100644 --- a/bubble-server/src/main/java/bubble/service/packer/PackerJob.java +++ b/bubble-server/src/main/java/bubble/service/packer/PackerJob.java @@ -217,7 +217,7 @@ public class PackerJob implements Callable> { images.addAll(Arrays.stream(builds).map(b -> b.toPackerImage(imageName)).collect(Collectors.toList())); } else { - final List finalizedImages = computeDriver.finalizeIncompletePackerRun(commandResult, jarSha); + final List finalizedImages = computeDriver.finalizeIncompletePackerRun(commandResult, installType, jarSha); if (empty(finalizedImages)) { return die("Error executing packer: exit status " + commandResult.getExitStatus()); }