JCloudsComputer computer = entry.getValue(); String id = entry.getKey(); String cloudName = computer.getId().getCloudName(); JCloudsCloud cloud; try {
public JCloudsSlave( @Nonnull ProvisioningActivity.Id id, @Nonnull Server metadata, @Nonnull String labelString, @Nonnull SlaveOptions slaveOptions ) throws IOException, Descriptor.FormException { super( metadata.getName(), null, slaveOptions.getFsRoot(), slaveOptions.getNumExecutors(), Mode.NORMAL, labelString, null, new JCloudsRetentionStrategy(), Collections.singletonList(new EnvironmentVariablesNodeProperty( new EnvironmentVariablesNodeProperty.Entry("OPENSTACK_PUBLIC_IP", Openstack.getPublicAddress(metadata)) )) ); this.cloudName = id.getCloudName(); // TODO deprecate field this.provisioningId = id; this.options = slaveOptions; this.nodeId = metadata.getId(); this.cache = makeCache(); setLauncher(new JCloudsLauncher(getLauncherFactory().createLauncher(this))); }
/** * Return the number of active nodes provisioned using this template. * * @param onlyNewComputers Whether or not to limit the count to unused machines. */ public int getActiveNodesTotal(boolean onlyNewComputers) { int totalServers = 0; for (Node node : Jenkins.getActiveInstance().getNodes()) { if (node instanceof JCloudsSlave) { JCloudsSlave slave = (JCloudsSlave) node; if (slave.getId().getCloudName().equals(cloud.name) && slave.getId().getTemplateName().equals(name)) { JCloudsComputer computer = slave.getComputer(); if (computer != null && !computer.isPendingDelete() && !(computer.getOfflineCause() instanceof OfflineCause.UserCause)) { if (onlyNewComputers) { if (!computer.isUsed()) { totalServers++; } } else { totalServers++; } } } } } return totalServers; }
/** * Should a slave be retained to meet the minimum instances constraint? */ public static boolean shouldSlaveBeRetained(JCloudsSlave slave) { String templateName = slave.getId().getTemplateName(); String cloudName = slave.getId().getCloudName(); if (templateName != null && cloudName != null) { JCloudsCloud cloud = JCloudsCloud.getByName(cloudName); if (cloud != null) { JCloudsSlaveTemplate template = cloud.getTemplate(templateName); if (template != null) { SlaveOptions slaveOptions = template.getEffectiveSlaveOptions(); Integer instancesMin = slaveOptions.getInstancesMin(); JCloudsComputer computer = slave.getComputer(); Integer retentionTime = slaveOptions.getRetentionTime(); if (instancesMin > 0 && computer != null) { if (retentionTime != 0 && (template.getActiveNodesTotal(false) - 1) < instancesMin) { return true; } if (retentionTime == 0 && !computer.isUsed() && (template.getActiveNodesTotal(true) - 1) < instancesMin) { return true; } } } } } return false; }