private String getServerName() { CloudStatistics cs = CloudStatistics.get(); next_number: for (;;) { // Using static counter to ensure colliding template names (between clouds) will not cause a clash String nameCandidate = name + "-" + nodeCounter.getAndIncrement(); // Collide with existing node - quite likely from this cloud if (Jenkins.getInstance().getNode(nameCandidate) != null) continue; // Collide with node being provisioned (at this point this plugin does not assign final name before launch // is completed) or recently used name (just to avoid confusion). for (ProvisioningActivity provisioningActivity : cs.getActivities()) { if (nameCandidate.equals(provisioningActivity.getId().getNodeName())) { continue next_number; } } return nameCandidate; } }
@Override public boolean isOutOfScope(@Nonnull Server server) { if (Jenkins.getActiveInstance().getNode(specifier) != null) return false; // The node may be provisioned or deleted at the moment - do not interfere for (ProvisioningActivity pa : CloudStatistics.get().getActivities()) { if (specifier.equals(pa.getName())) { switch (pa.getCurrentPhase()) { case PROVISIONING: return false; // Node not yet created case LAUNCHING: case OPERATING: LOGGER.warning("Node does not exist for " + pa.getCurrentPhase() + " " + specifier); return false; case COMPLETED: return true; } assert false: "Unreachable"; } } Date created = server.getCreated(); if (created != null) { long now = System.currentTimeMillis(); long ageHours = (now - created.getTime()) / (1000 * 60 * 60); if (ageHours < 1) return false; // Make sure not to throw it away during launching } // Resolving activity by name is not reliable as they may not be assigned yet or the activity might already // be rotated when in completed state. In the latter case it should be treated as out of scope. return true; } }