public void execute(TaskListener arg0) throws IOException, InterruptedException {
    for (Computer computer : Hudson.getInstance().getComputers()) {
      if (computer instanceof AzureComputer) {
        AzureComputer azureComputer = (AzureComputer) computer;
        AzureSlave slaveNode = azureComputer.getNode();

        try {
          if (azureComputer.isOffline()) {
            if (!slaveNode.isDeleteSlave()) {
              // Find out if node exists in azure , if not continue with delete else do not delete
              // node
              // although it is offline. May be JNLP or SSH launch is in progress
              if (AzureManagementServiceDelegate.isVirtualMachineExists(slaveNode)) {
                LOGGER.info(
                    "AzureSlaveCleanUpTask: execute: VM "
                        + slaveNode.getDisplayName()
                        + " exists in cloud");
                continue;
              }
            }

            int retryCount = 0;
            boolean successful = false;

            // Retrying for 30 times with 30 seconds wait time between each retry
            while (retryCount < 30 && !successful) {
              try {
                slaveNode.idleTimeout();
                successful = true;
              } catch (Exception e) {
                retryCount++;
                LOGGER.info(
                    "AzureSlaveCleanUpTask: execute: Exception occured while calling timeout on node , \n"
                        + "Will retry again after 30 seconds. Current retry count "
                        + retryCount
                        + "\n"
                        + "Error code "
                        + e.getMessage());
                // We won't get exception for RNF , so for other exception types we can retry
                try {
                  Thread.sleep(30 * 1000);
                } catch (InterruptedException e1) {
                  e1.printStackTrace();
                }
              }
            }

            Hudson.getInstance().removeNode(slaveNode);
          }
        } catch (Exception e) {
          LOGGER.severe("AzureSlaveCleanUpTask: execute: failed to remove node " + e);
        }
      }
    }
  }
  /** Checks if node configuration matches with template definition. */
  private static boolean isNodeEligibleForReuse(
      AzureSlave slaveNode, AzureSlaveTemplate slaveTemplate) {

    // Do not reuse slave if it is marked for deletion.
    if (slaveNode.isDeleteSlave()) {
      return false;
    }

    // Check for null label and mode.
    if (AzureUtil.isNull(slaveNode.getLabelString()) && (slaveNode.getMode() == Node.Mode.NORMAL)) {
      return true;
    }

    if (AzureUtil.isNotNull(slaveNode.getLabelString())
        && slaveNode.getLabelString().equalsIgnoreCase(slaveTemplate.getLabels())) {
      return true;
    }

    return false;
  }