hudson.model.Label Java Examples

The following examples show how to use hudson.model.Label. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DockerTemplate.java    From docker-plugin with MIT License 6 votes vote down vote up
@DataBoundConstructor
public DockerTemplate(@Nonnull DockerTemplateBase dockerTemplateBase,
                      @Nonnull DockerComputerConnector connector,
                      String labelString,
                      String instanceCapStr
) {
    this.dockerTemplateBase = dockerTemplateBase;
    this.connector = connector;
    this.labelString = Util.fixEmpty(labelString);

    if (Strings.isNullOrEmpty(instanceCapStr)) {
        this.instanceCap = Integer.MAX_VALUE;
    } else {
        this.instanceCap = Integer.parseInt(instanceCapStr);
    }

    labelSet = Label.parse(labelString);
}
 
Example #2
Source File: NoDelayProvisionStrategyTest.java    From ec2-spot-jenkins-plugin with Apache License 2.0 6 votes vote down vote up
@Test
public void givenEC2CloudsWhenOneCanCoverCapacity_shouldDoScalingForFirstOnly() {
    when(snapshot.getQueueLength()).thenReturn(2);
    when(state.getLabel()).thenReturn(label);

    final EC2FleetCloud ec2FleetCloud1 = mock(EC2FleetCloud.class);
    clouds.add(ec2FleetCloud1);
    final EC2FleetCloud ec2FleetCloud2 = mock(EC2FleetCloud.class);
    clouds.add(ec2FleetCloud2);
    when(ec2FleetCloud1.canProvision(any(Label.class))).thenReturn(true);
    when(ec2FleetCloud2.canProvision(any(Label.class))).thenReturn(true);
    when(ec2FleetCloud1.isNoDelayProvision()).thenReturn(true);
    when(ec2FleetCloud2.isNoDelayProvision()).thenReturn(true);
    when(ec2FleetCloud1.provision(any(Label.class), anyInt())).thenReturn(Arrays.asList(
            mock(NodeProvisioner.PlannedNode.class),
            mock(NodeProvisioner.PlannedNode.class)
    ));

    Assert.assertEquals(
            NodeProvisioner.StrategyDecision.PROVISIONING_COMPLETED,
            strategy.apply(state));
    verify(ec2FleetCloud1, times(1)).provision(label, 2);
    verify(ec2FleetCloud2, never()).provision(any(Label.class), anyInt());
}
 
Example #3
Source File: DockerComputerConnectorTest.java    From docker-plugin with MIT License 6 votes vote down vote up
protected void should_connect_agent(DockerTemplate template) throws IOException, ExecutionException, InterruptedException, TimeoutException {

        // FIXME on CI windows nodes don't have Docker4Windows
        Assume.assumeFalse(SystemUtils.IS_OS_WINDOWS);

        String dockerHost = SystemUtils.IS_OS_WINDOWS ? "tcp://localhost:2375" : "unix:///var/run/docker.sock";

        DockerCloud cloud = new DockerCloud(cloudName, new DockerAPI(new DockerServerEndpoint(dockerHost, null)),
                Collections.singletonList(template));

        j.jenkins.clouds.replaceBy(Collections.singleton(cloud));

        final FreeStyleProject project = j.createFreeStyleProject("test-docker-ssh");
        project.setAssignedLabel(Label.get(LABEL));
        project.getBuildersList().add(new Shell("whoami"));
        final QueueTaskFuture<FreeStyleBuild> scheduledBuild = project.scheduleBuild2(0);
        try {
            final FreeStyleBuild build = scheduledBuild.get(60L, TimeUnit.SECONDS);
            Assert.assertTrue(build.getResult() == Result.SUCCESS);
            Assert.assertTrue(build.getLog().contains("jenkins"));
        } finally {
            scheduledBuild.cancel(true);
        }
    }
 
Example #4
Source File: PodTemplateFilter.java    From kubernetes-plugin with Apache License 2.0 6 votes vote down vote up
/**
 * Pass the given pod templates list into all filters implementations.
 *
 * @param cloud The cloud instance the pod templates are getting considered for
 * @param podTemplates The initial list of pod templates
 * @param label The label that was requested for provisioning
 * @return The pod template list after filtering
 */
public static List<PodTemplate> applyAll(@Nonnull KubernetesCloud cloud, @Nonnull List<PodTemplate> podTemplates, @CheckForNull Label label) {
    List<PodTemplate> result = new ArrayList<>();
    for (PodTemplate t : podTemplates) {
        PodTemplate output = t;
        for (PodTemplateFilter f : all()) {
            output = f.transform(cloud, output, label);
            if (output == null) {
                break;
            }
        }
        if (output != null) {
            result.add(output);
        }
    }
    return result;
}
 
Example #5
Source File: ProvisionIntegrationTest.java    From ec2-spot-jenkins-plugin with Apache License 2.0 6 votes vote down vote up
@Test
public void should_not_keep_planned_node_if_configured_so_jenkins_will_overprovision() throws Exception {
    ComputerLauncher computerLauncher = mock(ComputerLauncher.class);
    ComputerConnector computerConnector = mock(ComputerConnector.class);
    when(computerConnector.launch(anyString(), any(TaskListener.class))).thenReturn(computerLauncher);

    final EC2FleetCloud cloud = spy(new EC2FleetCloud(null, null, "credId", null, "region",
            null, "fId", "momo", null, computerConnector, false, false,
            0, 0, 10, 1, false, false,
            false, 0, 0, false,
            10, false));
    j.jenkins.clouds.add(cloud);

    mockEc2ApiToDescribeInstancesWhenModified(InstanceStateName.Running);

    getQueueTaskFutures(1);

    tryUntil(new Runnable() {
        @Override
        public void run() {
            j.jenkins.getLabelAtom("momo").nodeProvisioner.suggestReviewNow();
            verify(cloud, atLeast(2)).provision(any(Label.class), anyInt());
        }
    });
}
 
Example #6
Source File: KubernetesPipelineTest.java    From kubernetes-plugin with Apache License 2.0 6 votes vote down vote up
@Test
public void podTemplateWithMultipleLabels() throws Exception {
    PodTemplate pt = new PodTemplate();
    pt.setName("podTemplate");
    pt.setLabel("label1 label2");
    ContainerTemplate jnlp = new ContainerTemplate("jnlp", "jenkins/jnlp-slave:3.35-5-alpine");
    pt.setContainers(Collections.singletonList(jnlp));
    cloud.addTemplate(pt);
    SemaphoreStep.waitForStart("pod/1", b);
    Map<String, String> labels = getLabels(cloud, this, name);
    labels.put("jenkins/label","label1_label2");
    KubernetesSlave node = r.jenkins.getNodes().stream()
            .filter(KubernetesSlave.class::isInstance)
            .map(KubernetesSlave.class::cast)
            .findAny().get();
    assertTrue(node.getAssignedLabels().containsAll(Label.parse("label1 label2")));
    PodList pods = cloud.connect().pods().withLabels(labels).list();
    assertThat(
            "Expected one pod with labels " + labels + " but got: "
                    + pods.getItems().stream().map(pod -> pod.getMetadata()).collect(Collectors.toList()),
            pods.getItems(), hasSize(1));
    SemaphoreStep.success("pod/1", null);
    r.assertBuildStatusSuccess(r.waitForCompletion(b));
}
 
Example #7
Source File: RandomLeastLoadedDockerCloudOrder.java    From yet-another-docker-plugin with MIT License 6 votes vote down vote up
@Nonnull
public List<DockerCloud> getDockerClouds(Label label) {
    List<DockerCloud> provisionClouds;

    //create a random list of docker clouds and prioritize idle clouds
    List<DockerCloud> availableClouds = getAvailableDockerClouds(label);
    if (availableClouds.size() > 0) {
        //select available clouds based on label which have potential capacity
        LOG.debug("Picking from available clouds.");
        provisionClouds = availableClouds;
    } else {
        //if there's no available clouds then fall back to original behavior
        LOG.debug("Falling back to getting all clouds regardless of availability.");
        provisionClouds = getAllDockerClouds();
    }

    //randomize the order of the DockerCloud list
    Collections.shuffle(provisionClouds);
    //sort by least loaded DockerCloud (i.e. fewest provisioned slaves)
    provisionClouds.sort(new DockerCloudLoadComparator());

    LOG.debug("Least loaded randomized DockerCloud: " +
            ((provisionClouds.size() > 0) ? provisionClouds.get(0).name : "none available"));

    return provisionClouds;
}
 
Example #8
Source File: NomadSlaveTemplate.java    From jenkins-nomad with MIT License 6 votes vote down vote up
@DataBoundConstructor
public NomadSlaveTemplate(
        String cpu,
        String memory,
        String disk,
        String labels,
        String remoteFs,
        String idleTerminationInMinutes,
        String region,
        String priority,
        String image
        ) {
    this.cpu = Integer.parseInt(cpu);
    this.memory = Integer.parseInt(memory);
    this.disk = Integer.parseInt(disk);
    this.priority = Integer.parseInt(priority);
    this.idleTerminationInMinutes = Integer.parseInt(idleTerminationInMinutes);
    this.remoteFs = remoteFs;
    this.labels = Util.fixNull(labels);
    this.labelSet = Label.parse(labels);
    this.region = region;
    this.image = image;

    readResolve();
}
 
Example #9
Source File: KafkaKubernetesCloud.java    From remoting-kafka-plugin with MIT License 6 votes vote down vote up
@Override
public Collection<PlannedNode> provision(Label label, int excessWorkload) {
    Set<String> allInProvisioning = getNodesInProvisioning(label);
    LOGGER.info("In provisioning : " + allInProvisioning);
    int toBeProvisioned = Math.max(0, excessWorkload - allInProvisioning.size());
    LOGGER.info("Excess workload after pending Kubernetes agents: " + toBeProvisioned);

    List<PlannedNode> provisionNodes = new ArrayList<>();
    for (int i = 0; i < toBeProvisioned; i++) {
        PlannedNode node = new PlannedNode(name,
                Computer.threadPoolForRemoting.submit(() -> new KafkaCloudSlave(this)),
                AGENT_NUM_EXECUTORS);
        provisionNodes.add(node);
    }
    return provisionNodes;
}
 
Example #10
Source File: DockerCloud.java    From docker-plugin with MIT License 6 votes vote down vote up
/**
 * Multiple amis can have the same label.
 *
 * @return Templates matched to requested label assuming slave Mode
 */
public List<DockerTemplate> getTemplates(Label label) {
    final List<DockerTemplate> dockerTemplates = new ArrayList<>();

    for (DockerTemplate t : getTemplates()) {
        if ( t.getDisabled().isDisabled() ) {
            continue; // pretend it doesn't exist
        }
        if (label == null && t.getMode() == Node.Mode.NORMAL) {
            dockerTemplates.add(t);
        }

        if (label != null && label.matches(t.getLabelSet())) {
            dockerTemplates.add(t);
        }
    }

    // add temporary templates matched to requested label
    for (DockerTemplate template : getJobTemplates().values()) {
        if (label != null && label.matches(template.getLabelSet())) {
            dockerTemplates.add(template);
        }
    }

    return dockerTemplates;
}
 
Example #11
Source File: ProvisionIntegrationTest.java    From ec2-spot-jenkins-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void should_keep_planned_node_until_node_will_not_be_online_so_jenkins_will_not_request_overprovision() throws Exception {
    ComputerLauncher computerLauncher = mock(ComputerLauncher.class);
    ComputerConnector computerConnector = mock(ComputerConnector.class);
    when(computerConnector.launch(anyString(), any(TaskListener.class))).thenReturn(computerLauncher);

    EC2FleetCloud cloud = spy(new EC2FleetCloud(null, null, "credId", null, "region",
            null, "fId", "momo", null, computerConnector, false, false,
            0, 0, 10, 1, false, false,
            false, 300, 15, false,
            2, false));

    // provide init state
    cloud.setStats(new FleetStateStats("", 0, "active",
            Collections.<String>emptySet(), Collections.<String, Double>emptyMap()));

    j.jenkins.clouds.add(cloud);

    mockEc2ApiToDescribeInstancesWhenModified(InstanceStateName.Running);

    List<QueueTaskFuture> rs = getQueueTaskFutures(1);

    final String labelString = "momo";
    triggerSuggestReviewNow(labelString);

    Thread.sleep(TimeUnit.MINUTES.toMillis(2));

    verify(cloud, times(1)).provision(any(Label.class), anyInt());

    cancelTasks(rs);
}
 
Example #12
Source File: RunImplTest.java    From blueocean-plugin with MIT License 5 votes vote down vote up
@Test @Ignore
public void replayRunTest() throws Exception {
    WorkflowJob job1 = j.jenkins.createProject(WorkflowJob.class, "pipeline1");
    j.createOnlineSlave(Label.get("remote"));
    job1.setDefinition(new CpsFlowDefinition(
        "node('remote') {\n" +
            "    ws {\n" +
            "        git($/" + sampleRepo + "/$)\n" +
            "    }\n" +
            "}"));


    WorkflowRun b1 = job1.scheduleBuild2(0).get();
    j.assertBuildStatusSuccess(b1);

    sampleRepo.write("file1", "");
    sampleRepo.git("add", "file1");
    sampleRepo.git("commit", "--message=init");

    WorkflowRun b2 = job1.scheduleBuild2(0).get();
    j.assertBuildStatusSuccess(b2);

    Assert.assertNotEquals(new PipelineRunImpl(b1, null, null).getCommitId(), new PipelineRunImpl(b2, null, null).getCommitId());

    request().post("/organizations/jenkins/pipelines/pipeline1/runs/1/replay").build(String.class);

    j.waitForCompletion(job1.getLastBuild());

    Map r = request().get("/organizations/jenkins/pipelines/pipeline1/runs/3/").build(Map.class);
    assertEquals(r.get("commitId"), new PipelineRunImpl(b2,null, null).getCommitId());
}
 
Example #13
Source File: NomadCloud.java    From jenkins-nomad with MIT License 5 votes vote down vote up
public NomadSlaveTemplate getTemplate(Label label) {
    for (NomadSlaveTemplate t : templates) {
        if (label == null && !t.getLabelSet().isEmpty()) {
            continue;
        }
        if ((label == null && t.getLabelSet().isEmpty()) || (label != null && label.matches(t.getLabelSet()))) {
            return t;
        }
    }
    return null;
}
 
Example #14
Source File: NoDelayProvisionStrategyTest.java    From ec2-spot-jenkins-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void givenEC2CloudWithDisabledNoDelay_shouldDoNotScale() {
    when(snapshot.getQueueLength()).thenReturn(10);
    when(state.getLabel()).thenReturn(label);

    final EC2FleetCloud ec2FleetCloud = mock(EC2FleetCloud.class);
    clouds.add(ec2FleetCloud);
    when(ec2FleetCloud.canProvision(any(Label.class))).thenReturn(true);
    when(ec2FleetCloud.isNoDelayProvision()).thenReturn(false);

    Assert.assertEquals(
            NodeProvisioner.StrategyDecision.CONSULT_REMAINING_STRATEGIES,
            strategy.apply(state));
    verify(ec2FleetCloud, never()).provision(any(Label.class), anyInt());
}
 
Example #15
Source File: KafkaKubernetesCloud.java    From remoting-kafka-plugin with MIT License 5 votes vote down vote up
public Set<String> getNodesInProvisioning(@CheckForNull Label label) {
    if (label == null) return Collections.emptySet();
    return label.getNodes().stream()
            .filter(KafkaCloudSlave.class::isInstance)
            .filter(node -> {
                Computer computer = node.toComputer();
                return computer != null && !computer.isOnline();
            })
            .map(Node::getNodeName)
            .collect(Collectors.toSet());
}
 
Example #16
Source File: NoDelayProvisionStrategyTest.java    From ec2-spot-jenkins-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void givenEC2CloudWhichCannotProvision_shouldDoNotScale() {
    when(snapshot.getQueueLength()).thenReturn(10);
    when(state.getLabel()).thenReturn(label);

    final EC2FleetCloud ec2FleetCloud = mock(EC2FleetCloud.class);
    clouds.add(ec2FleetCloud);
    when(ec2FleetCloud.canProvision(any(Label.class))).thenReturn(false);

    Assert.assertEquals(
            NodeProvisioner.StrategyDecision.CONSULT_REMAINING_STRATEGIES,
            strategy.apply(state));
    verify(ec2FleetCloud, never()).provision(any(Label.class), anyInt());
}
 
Example #17
Source File: NoDelayProvisionStrategyTest.java    From ec2-spot-jenkins-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void givenAvailableSameAsRequiredCapacity_shouldDoNotScale() {
    final EC2FleetCloud ec2FleetCloud = mock(EC2FleetCloud.class);
    clouds.add(ec2FleetCloud);
    when(snapshot.getQueueLength()).thenReturn(10);
    when(snapshot.getAvailableExecutors()).thenReturn(10);

    Assert.assertEquals(
            NodeProvisioner.StrategyDecision.PROVISIONING_COMPLETED,
            strategy.apply(state));

    verify(ec2FleetCloud, never()).canProvision(any(Label.class));
}
 
Example #18
Source File: KubernetesSlave.java    From kubernetes-plugin with Apache License 2.0 5 votes vote down vote up
@Nonnull
public PodTemplate getTemplate() {
    // Look up updated pod template after a restart
    if (template == null) {
        template = getKubernetesCloud().getTemplate(Label.get(getLabelString()));
        if (template == null) {
            throw new IllegalStateException("Not expecting pod template to be null at this point");
        }
    }
    return template;
}
 
Example #19
Source File: AsIsDockerCloudOrder.java    From yet-another-docker-plugin with MIT License 5 votes vote down vote up
@Nonnull
@Override
public List<DockerCloud> getDockerClouds(Label label) {
    return getInstance().clouds.stream()
            .filter(Objects::nonNull)
            .filter(DockerCloud.class::isInstance)
            .map(cloud -> (DockerCloud) cloud)
            .collect(Collectors.toList());
}
 
Example #20
Source File: EC2FleetCloudWithHistory.java    From ec2-spot-jenkins-plugin with Apache License 2.0 5 votes vote down vote up
@Override
public Collection<NodeProvisioner.PlannedNode> provision(
        final Label label, final int excessWorkload) {
    final Collection<NodeProvisioner.PlannedNode> r = super.provision(label, excessWorkload);
    for (NodeProvisioner.PlannedNode ignore : r) provisionTimes.add(System.currentTimeMillis());
    return r;
}
 
Example #21
Source File: ParallelsDesktopCloud.java    From jenkins-parallels with MIT License 5 votes vote down vote up
@Override
public Collection<NodeProvisioner.PlannedNode> provision(Label label, int excessWorkload)
{
	LOGGER.log(Level.SEVERE, "Going to provision " + excessWorkload + " executors");
	Collection<NodeProvisioner.PlannedNode> result = new ArrayList<NodeProvisioner.PlannedNode>();
	final ParallelsDesktopConnectorSlaveComputer connector = getConnector();
	for (int i = 0; (i < vms.size()) && (excessWorkload > 0); i++)
	{
		final ParallelsDesktopVM vm = vms.get(i);
		if (vm.isProvisioned())
			continue;
		if (!label.matches(Label.parse(vm.getLabels())))
			continue;
		final String vmId = vm.getVmid();
		final String slaveName = name + " " + vmId;
		vm.setSlaveName(slaveName);
		vm.setProvisioned(true);
		--excessWorkload;
		result.add(new NodeProvisioner.PlannedNode(slaveName,
			Computer.threadPoolForRemoting.submit(new Callable<Node>()
			{
				@Override
				public Node call() throws Exception
				{
					connector.checkVmExists(vmId);
					return connector.createSlaveOnVM(vm);
				}
			}), 1));
	}
	return result;
}
 
Example #22
Source File: InProvisioning.java    From kubernetes-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the agents names in provisioning according to all implementations of this extension point for the given label.
 *
 * @param label the {@link Label} being checked.
 * @return the agents names in provisioning according to all implementations of this extension point for the given label.
 */
@Nonnull
public static Set<String> getAllInProvisioning(@CheckForNull Label label) {
    return all().stream()
            .flatMap(c -> c.getInProvisioning(label).stream())
            .collect(toSet());
}
 
Example #23
Source File: DummyCloudImpl.java    From jenkins-test-harness with MIT License 5 votes vote down vote up
public Collection<PlannedNode> provision(Label label, int excessWorkload) {
    List<PlannedNode> r = new ArrayList<PlannedNode>();
    if(label!=this.label)   return r;   // provisioning impossible

    while(excessWorkload>0) {
        System.out.println("Provisioning");
        numProvisioned++;
        Future<Node> f = Computer.threadPoolForRemoting.submit(new Launcher(delay));
        r.add(new PlannedNode(name+" #"+numProvisioned,f,1));
        excessWorkload-=1;
    }
    return r;
}
 
Example #24
Source File: EC2FleetCloudWithMeter.java    From ec2-spot-jenkins-plugin with Apache License 2.0 5 votes vote down vote up
@Override
public Collection<NodeProvisioner.PlannedNode> provision(
        final Label label, final int excessWorkload) {
    try (Meter.Shot s = provisionMeter.start()) {
        return super.provision(label, excessWorkload);
    }
}
 
Example #25
Source File: NodesByLabelStep.java    From pipeline-utility-steps-plugin with MIT License 5 votes vote down vote up
@SuppressWarnings("unused") // used by stapler
public ComboBoxModel doFillLabelItems() {
    ComboBoxModel cbm = new ComboBoxModel();
    Set<Label> labels = Jenkins.get().getLabels();
    for (Label label : labels) {
        cbm.add(label.getDisplayName());
    }
    return cbm;
}
 
Example #26
Source File: ParallelsDesktopCloud.java    From jenkins-parallels with MIT License 5 votes vote down vote up
@Override
public boolean canProvision(Label label)
{
	if (label != null)
	{
		for (ParallelsDesktopVM vm : vms)
		{
			if (label.matches(Label.parse(vm.getLabels())))
				return true;
		}
	}
	return false;
}
 
Example #27
Source File: KubernetesCloudTest.java    From kubernetes-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void testInstanceCap() {
    KubernetesCloud cloud = new KubernetesCloud("name") {
        @Override
        public KubernetesClient connect() {
            KubernetesClient mockClient =  Mockito.mock(KubernetesClient.class);
            Mockito.when(mockClient.getNamespace()).thenReturn("default");
            MixedOperation<Pod, PodList, DoneablePod, PodResource<Pod, DoneablePod>> operation = Mockito.mock(MixedOperation.class);
            Mockito.when(operation.inNamespace(Mockito.anyString())).thenReturn(operation);
            Mockito.when(operation.withLabels(Mockito.anyMap())).thenReturn(operation);
            PodList podList = Mockito.mock(PodList.class);
            Mockito.when(podList.getItems()).thenReturn(new ArrayList<>());
            Mockito.when(operation.list()).thenReturn(podList);
            Mockito.when(mockClient.pods()).thenReturn(operation);
            return mockClient;
        }
    };

    PodTemplate podTemplate = new PodTemplate();
    podTemplate.setName("test");
    podTemplate.setLabel("test");

    cloud.addTemplate(podTemplate);

    Label test = Label.get("test");
    assertTrue(cloud.canProvision(test));

    Collection<NodeProvisioner.PlannedNode> plannedNodes = cloud.provision(test, 200);
    assertEquals(200, plannedNodes.size());

    podTemplate.setInstanceCap(5);
    plannedNodes = cloud.provision(test, 200);
    assertEquals(5, plannedNodes.size());
}
 
Example #28
Source File: ECSCloud.java    From amazon-ecs-plugin with MIT License 5 votes vote down vote up
@Override
public synchronized Collection<NodeProvisioner.PlannedNode> provision(Label label, int excessWorkload) {

    LOGGER.log(Level.INFO, "Asked to provision {0} agent(s) for: {1}", new Object[]{excessWorkload, label});

    List<NodeProvisioner.PlannedNode> result = new ArrayList<>();
    final ECSTaskTemplate template = getTemplate(label);
    if (template != null) {
        String parentLabel = template.getInheritFrom();
        final ECSTaskTemplate merged = template.merge(getTemplate(parentLabel));

        for (int i = 1; i <= excessWorkload; i++) {
            String agentName = name + "-" + label.getName() + "-" + RandomStringUtils.random(5, "bcdfghjklmnpqrstvwxz0123456789");
            LOGGER.log(Level.INFO, "Will provision {0}, for label: {1}", new Object[]{agentName, label} );
            result.add(
                    new NodeProvisioner.PlannedNode(
                            agentName,
                            Computer.threadPoolForRemoting.submit(
                                    new ProvisioningCallback(merged, agentName)
                            ),
                            1
                    )
            );
        }
    }
    return result.isEmpty() ? Collections.emptyList() : result;

}
 
Example #29
Source File: FastNodeProvisionerStrategy.java    From docker-plugin with MIT License 5 votes vote down vote up
private StrategyDecision applyFoCloud(@Nonnull NodeProvisioner.StrategyState state, DockerCloud cloud) {

        final Label label = state.getLabel();

        if (!cloud.canProvision(label)) {
            return CONSULT_REMAINING_STRATEGIES;
        }

        LoadStatistics.LoadStatisticsSnapshot snapshot = state.getSnapshot();
        LOGGER.log(FINEST, "Available executors={0}, connecting={1}, planned={2}",
                new Object[]{snapshot.getAvailableExecutors(), snapshot.getConnectingExecutors(), state.getPlannedCapacitySnapshot()});
        int availableCapacity =
              snapshot.getAvailableExecutors()
            + snapshot.getConnectingExecutors()
            + state.getPlannedCapacitySnapshot();

        int currentDemand = snapshot.getQueueLength();
        LOGGER.log(FINE, "Available capacity={0}, currentDemand={1}",
                new Object[]{availableCapacity, currentDemand});

        if (availableCapacity < currentDemand) {
            Collection<NodeProvisioner.PlannedNode> plannedNodes = cloud.provision(label, currentDemand - availableCapacity);
            LOGGER.log(FINE, "Planned {0} new nodes", plannedNodes.size());
            state.recordPendingLaunches(plannedNodes);
            availableCapacity += plannedNodes.size();
            LOGGER.log(FINE, "After provisioning, available capacity={0}, currentDemand={1}",
                    new Object[]{availableCapacity, currentDemand});
        }

        if (availableCapacity >= currentDemand) {
            LOGGER.log(FINE, "Provisioning completed");
            return PROVISIONING_COMPLETED;
        }
        LOGGER.log(FINE, "Provisioning not complete, consulting remaining strategies");
        return CONSULT_REMAINING_STRATEGIES;
    }
 
Example #30
Source File: RandomLeastLoadedDockerCloudOrder.java    From yet-another-docker-plugin with MIT License 5 votes vote down vote up
/**
 * Get a list of available DockerCloud clouds which are not at max
 * capacity.
 *
 * @param label A label expression of a Job Run requiring an executor.
 * @return A list of available DockerCloud clouds.
 */
protected List<DockerCloud> getAvailableDockerClouds(Label label) {
    return getAllDockerClouds().stream()
            .filter(cloud ->
                    cloud.canProvision(label) &&
                            (countCurrentDockerSlaves(cloud) >= 0) &&
                            (countCurrentDockerSlaves(cloud) < cloud.getContainerCap()))
            .collect(Collectors.toList());
}