Browse Source

filter servers/images based on installType

cobbzilla/introduce_packer
Jonathan Cobb 4 years ago
parent
commit
e955fb8af1
3 changed files with 9 additions and 8 deletions
  1. +2
    -1
      bubble-server/src/main/java/bubble/cloud/compute/ComputeServiceDriver.java
  2. +6
    -6
      bubble-server/src/main/java/bubble/cloud/compute/vultr/VultrDriver.java
  3. +1
    -1
      bubble-server/src/main/java/bubble/service/packer/PackerJob.java

+ 2
- 1
bubble-server/src/main/java/bubble/cloud/compute/ComputeServiceDriver.java View File

@@ -6,6 +6,7 @@ package bubble.cloud.compute;


import bubble.cloud.CloudServiceDriver; import bubble.cloud.CloudServiceDriver;
import bubble.cloud.CloudServiceType; import bubble.cloud.CloudServiceType;
import bubble.model.cloud.AnsibleInstallType;
import bubble.model.cloud.BubbleNode; import bubble.model.cloud.BubbleNode;
import bubble.model.cloud.RegionalServiceDriver; import bubble.model.cloud.RegionalServiceDriver;
import org.cobbzilla.util.system.CommandResult; import org.cobbzilla.util.system.CommandResult;
@@ -35,6 +36,6 @@ public interface ComputeServiceDriver extends CloudServiceDriver, RegionalServic
@Override default boolean test () { return true; } @Override default boolean test () { return true; }


List<PackerImage> getPackerImages(); List<PackerImage> getPackerImages();
default List<PackerImage> finalizeIncompletePackerRun(CommandResult commandResult, String jarSha) { return null; }
default List<PackerImage> finalizeIncompletePackerRun(CommandResult commandResult, AnsibleInstallType installType, String jarSha) { return null; }


} }

+ 6
- 6
bubble-server/src/main/java/bubble/cloud/compute/vultr/VultrDriver.java View File

@@ -411,11 +411,11 @@ public class VultrDriver extends ComputeServiceDriverBase {
} }


public static final long SNAPSHOT_TIMEOUT = MINUTES.toMillis(60); public static final long SNAPSHOT_TIMEOUT = MINUTES.toMillis(60);
@Override public List<PackerImage> finalizeIncompletePackerRun(CommandResult commandResult, String jarSha) {
@Override public List<PackerImage> finalizeIncompletePackerRun(CommandResult commandResult, AnsibleInstallType installType, String jarSha) {
if (!commandResult.getStdout().contains("Waiting 300s for snapshot") if (!commandResult.getStdout().contains("Waiting 300s for snapshot")
|| !commandResult.getStdout().contains("Error waiting for snapshot") || !commandResult.getStdout().contains("Error waiting for snapshot")
|| !commandResult.getStdout().contains("Unable to destroy server: Unable to remove VM: Server is currently locked")) { || !commandResult.getStdout().contains("Unable to destroy server: Unable to remove VM: Server is currently locked")) {
stopImageServer(jarSha);
stopImageServer(installType, jarSha);
return null; return null;
} }


@@ -424,7 +424,7 @@ public class VultrDriver extends ComputeServiceDriverBase {
PackerImage snapshot = null; PackerImage snapshot = null;
while (now() - start < SNAPSHOT_TIMEOUT) { while (now() - start < SNAPSHOT_TIMEOUT) {
snapshot = getPackerImages().stream() snapshot = getPackerImages().stream()
.filter(i -> i.getName().endsWith(jarSha))
.filter(i -> i.getName().contains("_"+installType.name()+"_") && i.getName().endsWith(jarSha))
.findFirst() .findFirst()
.orElse(null); .orElse(null);
if (snapshot != null) break; if (snapshot != null) break;
@@ -434,19 +434,19 @@ public class VultrDriver extends ComputeServiceDriverBase {
log.error("finalizeIncompletePackerRun: timeout waiting for snapshot"); log.error("finalizeIncompletePackerRun: timeout waiting for snapshot");
} }


if (!stopImageServer(jarSha)) return null;
if (!stopImageServer(installType, jarSha)) return null;
if (snapshot == null) return null; if (snapshot == null) return null;


return new SingletonList<>(snapshot); return new SingletonList<>(snapshot);
} }


public boolean stopImageServer(String jarSha) {
public boolean stopImageServer(AnsibleInstallType installType, String jarSha) {
// find the server // find the server
final List<BubbleNode> servers; final List<BubbleNode> servers;
try { try {
servers = listNodes(server -> { servers = listNodes(server -> {
final String tag = server.has("tag") ? server.get("tag").textValue() : null; 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) { } catch (IOException e) {
log.error("finalizeIncompletePackerRun: error listing servers: "+shortError(e), e); log.error("finalizeIncompletePackerRun: error listing servers: "+shortError(e), e);


+ 1
- 1
bubble-server/src/main/java/bubble/service/packer/PackerJob.java View File

@@ -217,7 +217,7 @@ public class PackerJob implements Callable<List<PackerImage>> {
images.addAll(Arrays.stream(builds).map(b -> b.toPackerImage(imageName)).collect(Collectors.toList())); images.addAll(Arrays.stream(builds).map(b -> b.toPackerImage(imageName)).collect(Collectors.toList()));


} else { } else {
final List<PackerImage> finalizedImages = computeDriver.finalizeIncompletePackerRun(commandResult, jarSha);
final List<PackerImage> finalizedImages = computeDriver.finalizeIncompletePackerRun(commandResult, installType, jarSha);
if (empty(finalizedImages)) { if (empty(finalizedImages)) {
return die("Error executing packer: exit status " + commandResult.getExitStatus()); return die("Error executing packer: exit status " + commandResult.getExitStatus());
} }


Loading…
Cancel
Save