private static String getIpAddress(Computer computer) throws RequestUnsuccessfulException, DigitalOceanException { Droplet instance = computer.updateInstanceDescription(); for (final Network network : instance.getNetworks().getVersion4Networks()) { String host = network.getIpAddress(); if (host != null) { return host; } } return null; }
private static boolean isDropletStarting(final Droplet droplet) { switch (droplet.getStatus()) { case NEW: return true; case ACTIVE: return false; default: throw new IllegalStateException("Droplet has unexpected status: " + droplet.getStatus()); } }
public boolean isInstanceCapReachedRemote(List<Droplet> droplets, String cloudName) throws DigitalOceanException { LOGGER.log(Level.INFO, "slave limit check"); int count = 0; for (Droplet droplet : droplets) { if ((droplet.isActive() || droplet.isNew())) { if (DropletName.isDropletInstanceOfSlave(droplet.getName(), cloudName, name)) { count++; } } } return count >= instanceCap; }
/** * Create a new {@link Slave} from the given {@link Droplet} * * @param droplet the droplet being created * @param privateKey the RSA private key being used * @return the provisioned {@link Slave} * @throws IOException * @throws Descriptor.FormException */ private Slave newSlave(String cloudName, Droplet droplet, String privateKey) throws IOException, Descriptor.FormException { LOGGER.log(Level.INFO, "Creating new slave..."); return new Slave( cloudName, droplet.getName(), "Computer running on DigitalOcean with name: " + droplet.getName(), droplet.getId(), privateKey, username, workspacePath, sshPort, numExecutors, idleTerminationInMinutes, Node.Mode.NORMAL, labels, new ComputerLauncher(), new RetentionStrategy(), Collections.<NodeProperty<?>>emptyList(), Util.fixNull(initScript), ""); }
public Slave provision( String dropletName, String cloudName, String authToken, String privateKey, Integer sshKeyId, List<Droplet> droplets) throws IOException, RequestUnsuccessfulException, Descriptor.FormException { LOGGER.log(Level.INFO, "Provisioning slave..."); try { LOGGER.log( Level.INFO, "Starting to provision digital ocean droplet using image: " + imageId + " region: " + regionId + ", sizeId: " + sizeId); if (isInstanceCapReachedLocal(cloudName) || isInstanceCapReachedRemote(droplets, cloudName)) { throw new AssertionError(); } // create a new droplet Droplet droplet = new Droplet(); droplet.setName(dropletName); droplet.setSize(sizeId); droplet.setRegion(new Region(regionId)); droplet.setImage(DigitalOcean.newImage(imageId)); droplet.setKeys(newArrayList(new Key(sshKeyId))); if (!(userData == null || userData.trim().isEmpty())) { droplet.setUserData(userData); } LOGGER.log(Level.INFO, "Creating slave with new droplet " + dropletName); DigitalOceanClient apiClient = new DigitalOceanClient(authToken); Droplet createdDroplet = apiClient.createDroplet(droplet); return newSlave(cloudName, createdDroplet, privateKey); } catch (Exception e) { LOGGER.log(Level.WARNING, e.getMessage(), e); throw new AssertionError(); } }