Search in sources :

Example 1 with ProvisioningActivity

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");
}
Also used : Jenkins(jenkins.model.Jenkins) ProvisioningActivity(org.jenkinsci.plugins.cloudstats.ProvisioningActivity) NodeProvisioner(hudson.slaves.NodeProvisioner) TrackedItem(org.jenkinsci.plugins.cloudstats.TrackedItem) Node(hudson.model.Node) Label(hudson.model.Label) TimeoutException(java.util.concurrent.TimeoutException) AzureCloudException(com.microsoft.azure.vmagent.exceptions.AzureCloudException) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) HashSet(java.util.HashSet)

Example 2 with ProvisioningActivity

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);
    }
}
Also used : ProvisioningActivity(org.jenkinsci.plugins.cloudstats.ProvisioningActivity)

Aggregations

ProvisioningActivity (org.jenkinsci.plugins.cloudstats.ProvisioningActivity)2 AzureCloudException (com.microsoft.azure.vmagent.exceptions.AzureCloudException)1 Label (hudson.model.Label)1 Node (hudson.model.Node)1 NodeProvisioner (hudson.slaves.NodeProvisioner)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 ExecutionException (java.util.concurrent.ExecutionException)1 TimeoutException (java.util.concurrent.TimeoutException)1 Jenkins (jenkins.model.Jenkins)1 TrackedItem (org.jenkinsci.plugins.cloudstats.TrackedItem)1