<commit_before>package org.jenkinsci.plugins.mesos.listener;

import hudson.Extension;
import hudson.model.Label;
import hudson.model.Node;
import hudson.model.Queue;
import hudson.model.queue.QueueListener;
import hudson.slaves.Cloud;
import hudson.slaves.CloudProvisioningListener;
import jenkins.model.Jenkins;
import org.jenkinsci.plugins.mesos.MesosCloud;
import org.jenkinsci.plugins.mesos.MesosSlaveInfo;
import java.util.logging.Logger;

@SuppressWarnings("rawtypes")
@Extension
public class MesosQueueListener extends QueueListener {

  private static final Logger LOGGER = Logger.getLogger(MesosQueueListener.class.getName());

  @SuppressWarnings("unchecked")
  public MesosQueueListener() {
    super();
  }

  @Override
  public void onEnterBuildable(Queue.BuildableItem bi) {
    forceProvisionInNewThreadIfPossible(bi.getAssignedLabel());
  }

  public void forceProvisionInNewThreadIfPossible(final Label label) {
    if(label != null) {
      Thread t = new Thread(new Runnable() {
        @Override
        public void run() {
          forceProvisionIfPossible(label);
        }
      }, "ForceNewMesosNode for " + label.getName());
      t.start();
    }
  }

  public void forceProvisionIfPossible(final Label label) {
    if(label != null) {
      Node future = null;
      CLOUD:
      for (Cloud c : Jenkins.getInstance().clouds) {
        if (c.canProvision(label)) {
          if (c instanceof MesosCloud) {
            MesosCloud mesosCloud = (MesosCloud) c;
            MesosSlaveInfo mesosSlaveInfo = mesosCloud.getSlaveInfo(mesosCloud.getSlaveInfos(), label);

            if (mesosSlaveInfo.isForceProvisioning()) {
              int numExecutors = 1;
              for (CloudProvisioningListener cl : CloudProvisioningListener.all()) {
                if (cl.canProvision(mesosCloud, label, numExecutors) != null) {
                  break CLOUD;
                }
              }
              mesosCloud.forceNewMesosNodes(label, numExecutors);
            }
          }
        }
      }
    }
  }
}
<commit_msg>implemented no force provisionig when MesosSingleUseSlave Buildwrapper is configured at Job config<commit_after>package org.jenkinsci.plugins.mesos.listener;

import hudson.Extension;
import hudson.model.*;
import hudson.model.queue.QueueListener;
import hudson.slaves.Cloud;
import hudson.slaves.CloudProvisioningListener;
import jenkins.model.Jenkins;
import org.jenkinsci.plugins.mesos.MesosCloud;
import org.jenkinsci.plugins.mesos.MesosSingleUseSlave;
import org.jenkinsci.plugins.mesos.MesosSlaveInfo;
import java.util.logging.Logger;

@SuppressWarnings("rawtypes")
@Extension
public class MesosQueueListener extends QueueListener {

  private static final Logger LOGGER = Logger.getLogger(MesosQueueListener.class.getName());

  @SuppressWarnings("unchecked")
  public MesosQueueListener() {
    super();
  }

  @Override
  public void onEnterBuildable(Queue.BuildableItem bi) {
    boolean containsMesosSingleUseSlaveClass = false;

    try {
      Project proj = (Project) bi.task;
      for (Object o : proj.getBuildWrappers().values()) {
        if (o.getClass().equals(MesosSingleUseSlave.class)) {
          containsMesosSingleUseSlaveClass = true;
          break;
        }
      }
    } catch (Exception e) {
      LOGGER.warning("Error while evaluating BuildWrappers, force provisioning will be ignored" + e.getMessage());
    }

    if(containsMesosSingleUseSlaveClass) {
      forceProvisionIfPossible(bi.getAssignedLabel());
    }
  }

  public void forceProvisionInNewThreadIfPossible(final Label label) {
    if(label != null) {
      Thread t = new Thread(new Runnable() {
        @Override
        public void run() {
          forceProvisionIfPossible(label);
        }
      }, "ForceNewMesosNode for " + label.getName());
      t.start();
    }
  }

  public void forceProvisionIfPossible(final Label label) {
    if(label != null) {
      Node future = null;
      CLOUD:
      for (Cloud c : Jenkins.getInstance().clouds) {
        if (c.canProvision(label)) {
          if (c instanceof MesosCloud) {
            MesosCloud mesosCloud = (MesosCloud) c;
            MesosSlaveInfo mesosSlaveInfo = mesosCloud.getSlaveInfo(mesosCloud.getSlaveInfos(), label);

            if (mesosSlaveInfo.isForceProvisioning()) {
              int numExecutors = 1;
              for (CloudProvisioningListener cl : CloudProvisioningListener.all()) {
                if (cl.canProvision(mesosCloud, label, numExecutors) != null) {
                  break CLOUD;
                }
              }
              mesosCloud.forceNewMesosNodes(label, numExecutors);
            }
          }
        }
      }
    }
  }
}

{'fraction_non_alphanumeric': 0.09852532592434281, 'fraction_numerical': 0.00042744176106005556, 'mean_word_length': 2.8935108153078204, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '420868', 'n_tokens_mistral': 1453, 'n_tokens_neox': 1415, 'n_words': 270}