Sfoglia il codice sorgente

filter servers/images based on installType

cobbzilla/introduce_packer
Jonathan Cobb 4 anni fa
parent
commit
e955fb8af1
3 ha cambiato i file con 9 aggiunte e 8 eliminazioni
  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 Vedi File

@@ -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<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 Vedi File

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

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")
|| !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<BubbleNode> 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);


+ 1
- 1
bubble-server/src/main/java/bubble/service/packer/PackerJob.java Vedi 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()));

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


Caricamento…
Annulla
Salva