use of org.jenkinsci.plugins.cloudstats.ProvisioningActivity in project azure-vm-agents-plugin by jenkinsci.
the class AzureVMAgentCleanUpTask method cleanCloudStatistics.
public void cleanCloudStatistics() {
Jenkins jenkins = Jenkins.get();
LOGGER.log(getNormalLoggingLevel(), "Beginning");
Set<ProvisioningActivity.Id> plannedNodesSet = new HashSet<>();
for (NodeProvisioner.PlannedNode node : jenkins.unlabeledNodeProvisioner.getPendingLaunches()) {
if (node instanceof TrackedItem) {
plannedNodesSet.add(((TrackedItem) node).getId());
}
}
for (Label l : jenkins.getLabels()) {
for (NodeProvisioner.PlannedNode node : l.nodeProvisioner.getPendingLaunches()) {
if (node instanceof TrackedItem) {
plannedNodesSet.add(((TrackedItem) node).getId());
}
}
}
for (Node node : jenkins.getNodes()) {
if (node instanceof TrackedItem) {
plannedNodesSet.add(((TrackedItem) node).getId());
}
}
Collection<ProvisioningActivity> activities = CloudStatistics.get().getNotCompletedActivities();
for (ProvisioningActivity activity : activities) {
if (activity.getCurrentPhase().equals(ProvisioningActivity.Phase.PROVISIONING) && !plannedNodesSet.contains(activity.getId())) {
Exception e = new Exception(String.format("Node %s has lost. Mark as failure", activity.getId()));
CloudStatistics.ProvisioningListener.get().onFailure(activity.getId(), e);
}
}
LOGGER.log(getNormalLoggingLevel(), "Completed");
}
use of org.jenkinsci.plugins.cloudstats.ProvisioningActivity in project azure-vm-agents-plugin by jenkinsci.
the class AzureVMAgent method _terminate.
@Override
protected void _terminate(TaskListener arg0) throws IOException, InterruptedException {
// TODO: Check when this method is getting called and code accordingly
LOGGER.log(Level.INFO, "Terminate called for agent {0}", getNodeName());
ProvisioningActivity activity = CloudStatistics.get().getActivityFor(this);
if (activity != null) {
activity.enterIfNotAlready(ProvisioningActivity.Phase.COMPLETED);
}
}
Aggregations