hudson.slaves.NodeProvisioner Java Examples
The following examples show how to use
hudson.slaves.NodeProvisioner.
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: EC2FleetCloudTest.java From ec2-spot-jenkins-plugin with Apache License 2.0 | 6 votes |
@Test public void provision_shouldProvisionNoneIfNotYetUpdated() { // given when(ec2Api.connect(any(String.class), any(String.class), anyString())).thenReturn(amazonEC2); PowerMockito.when(FleetStateStats.readClusterState(any(AmazonEC2.class), anyString(), anyString())) .thenReturn(new FleetStateStats("", 0, "active", Collections.<String>emptySet(), Collections.<String, Double>emptyMap())); EC2FleetCloud fleetCloud = new EC2FleetCloud(null, null, "credId", null, "region", "", "", "", null, null, false, false, 0, 0, 1, 1, false, false, false, 0, 0, false, 10, false); // when Collection<NodeProvisioner.PlannedNode> r = fleetCloud.provision(null, 1); // then assertEquals(0, r.size()); assertEquals(0, fleetCloud.getToAdd()); }
Example #2
Source File: EC2FleetCloudTest.java From ec2-spot-jenkins-plugin with Apache License 2.0 | 6 votes |
@Test public void provision_shouldProvisionNoneWhenMaxReached() { // given when(ec2Api.connect(any(String.class), any(String.class), anyString())).thenReturn(amazonEC2); PowerMockito.when(FleetStateStats.readClusterState(any(AmazonEC2.class), anyString(), anyString())) .thenReturn(new FleetStateStats("", 0, "active", Collections.<String>emptySet(), Collections.<String, Double>emptyMap())); EC2FleetCloud fleetCloud = new EC2FleetCloud(null, null, "credId", null, "region", "", "", "", null, null, false, false, 0, 0, 10, 1, false, false, false, 0, 0, false, 10, false); fleetCloud.setStats(new FleetStateStats("", 10, "active", Collections.<String>emptySet(), Collections.<String, Double>emptyMap())); // when Collection<NodeProvisioner.PlannedNode> r = fleetCloud.provision(null, 1); // then assertEquals(0, r.size()); assertEquals(0, fleetCloud.getToAdd()); }
Example #3
Source File: EC2FleetCloudTest.java From ec2-spot-jenkins-plugin with Apache License 2.0 | 6 votes |
@Test public void provision_shouldProvisionNoneWhenExceedMax() { // given when(ec2Api.connect(any(String.class), any(String.class), anyString())).thenReturn(amazonEC2); PowerMockito.when(FleetStateStats.readClusterState(any(AmazonEC2.class), anyString(), anyString())) .thenReturn(new FleetStateStats("", 0, "active", Collections.<String>emptySet(), Collections.<String, Double>emptyMap())); EC2FleetCloud fleetCloud = new EC2FleetCloud(null, null, "credId", null, "region", "", "", "", null, null, false, false, 0, 0, 9, 1, false, false, false, 0, 0, false, 10, false); fleetCloud.setStats(new FleetStateStats("", 10, "active", Collections.<String>emptySet(), Collections.<String, Double>emptyMap())); // when Collection<NodeProvisioner.PlannedNode> r = fleetCloud.provision(null, 1); // then assertEquals(0, r.size()); assertEquals(0, fleetCloud.getToAdd()); }
Example #4
Source File: NoDelayProvisionStrategyTest.java From ec2-spot-jenkins-plugin with Apache License 2.0 | 6 votes |
@Test public void givenEC2Clouds_shouldDoScalingAndReduceForNextOne() { when(snapshot.getQueueLength()).thenReturn(5); 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.CONSULT_REMAINING_STRATEGIES, strategy.apply(state)); verify(ec2FleetCloud1, times(1)).provision(label, 5); verify(ec2FleetCloud2, times(1)).provision(label, 3); }
Example #5
Source File: NoDelayProvisionStrategyTest.java From ec2-spot-jenkins-plugin with Apache License 2.0 | 6 votes |
@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 #6
Source File: NoDelayProvisionStrategyTest.java From ec2-spot-jenkins-plugin with Apache License 2.0 | 6 votes |
@Test public void givenEC2CloudsWithEnabledNoDelayAndWithout_shouldDoScalingForOne() { when(snapshot.getQueueLength()).thenReturn(10); 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(false); Assert.assertEquals( NodeProvisioner.StrategyDecision.CONSULT_REMAINING_STRATEGIES, strategy.apply(state)); verify(ec2FleetCloud1, times(1)).provision(label, 10); verify(ec2FleetCloud2, never()).provision(any(Label.class), anyInt()); }
Example #7
Source File: EC2FleetCloudTest.java From ec2-spot-jenkins-plugin with Apache License 2.0 | 6 votes |
@Test public void provision_shouldProvisionIfBelowMax() { // given when(ec2Api.connect(any(String.class), any(String.class), anyString())).thenReturn(amazonEC2); PowerMockito.when(FleetStateStats.readClusterState(any(AmazonEC2.class), anyString(), anyString())) .thenReturn(new FleetStateStats("", 0, "active", Collections.<String>emptySet(), Collections.<String, Double>emptyMap())); EC2FleetCloud fleetCloud = new EC2FleetCloud(null, null, "credId", null, "region", "", "", "", null, null, false, false, 0, 0, 10, 1, false, false, false, 0, 0, false, 10, false); fleetCloud.setStats(new FleetStateStats("", 5, "active", Collections.<String>emptySet(), Collections.<String, Double>emptyMap())); // when Collection<NodeProvisioner.PlannedNode> r = fleetCloud.provision(null, 1); // then assertEquals(1, r.size()); assertEquals(1, fleetCloud.getToAdd()); }
Example #8
Source File: EC2FleetCloudTest.java From ec2-spot-jenkins-plugin with Apache License 2.0 | 6 votes |
@Test public void provision_shouldProvisionNoMoreMax() { // given when(ec2Api.connect(any(String.class), any(String.class), anyString())).thenReturn(amazonEC2); PowerMockito.when(FleetStateStats.readClusterState(any(AmazonEC2.class), anyString(), anyString())) .thenReturn(new FleetStateStats("", 0, "active", Collections.<String>emptySet(), Collections.<String, Double>emptyMap())); EC2FleetCloud fleetCloud = new EC2FleetCloud(null, null, "credId", null, "region", "", "", "", null, null, false, false, 0, 0, 10, 1, false, false, false, 0, 0, false, 10, false); fleetCloud.setStats(new FleetStateStats("", 5, "active", Collections.<String>emptySet(), Collections.<String, Double>emptyMap())); // when Collection<NodeProvisioner.PlannedNode> r = fleetCloud.provision(null, 10); // then assertEquals(5, r.size()); assertEquals(5, fleetCloud.getToAdd()); }
Example #9
Source File: StandardPlannedNodeBuilder.java From kubernetes-plugin with Apache License 2.0 | 6 votes |
@Override public NodeProvisioner.PlannedNode build() { KubernetesCloud cloud = getCloud(); PodTemplate t = getTemplate(); Future f; String displayName; try { KubernetesSlave agent = KubernetesSlave .builder() .podTemplate(cloud.getUnwrappedTemplate(t)) .cloud(cloud) .build(); displayName = agent.getDisplayName(); f = Futures.immediateFuture(agent); } catch (IOException | Descriptor.FormException e) { displayName = null; f = Futures.immediateFailedFuture(e); } return new NodeProvisioner.PlannedNode(Util.fixNull(displayName), f, getNumExecutors()); }
Example #10
Source File: DockerProvisioningStrategy.java From yet-another-docker-plugin with MIT License | 6 votes |
/** * For groovy. */ public void setEnabled(boolean enabled) { final ExtensionList<NodeProvisioner.Strategy> strategies = lookup(NodeProvisioner.Strategy.class); DockerProvisioningStrategy strategy = strategies.get(DockerProvisioningStrategy.class); if (isNull(strategy)) { LOG.debug("YAD strategy was null, creating new."); strategy = new DockerProvisioningStrategy(); } else { LOG.debug("Removing YAD strategy."); strategies.remove(strategy); } LOG.debug("Inserting YAD strategy at position 0"); strategies.add(0, strategy); }
Example #11
Source File: FastNodeProvisionerStrategy.java From docker-plugin with MIT License | 6 votes |
@Nonnull @Override public StrategyDecision apply(@Nonnull NodeProvisioner.StrategyState state) { if (Jenkins.getInstance().isQuietingDown()) { return CONSULT_REMAINING_STRATEGIES; } for (Cloud cloud : Jenkins.getInstance().clouds) { if (cloud instanceof DockerCloud) { final StrategyDecision decision = applyFoCloud(state, (DockerCloud) cloud); if (decision == PROVISIONING_COMPLETED) return decision; } } return CONSULT_REMAINING_STRATEGIES; }
Example #12
Source File: ParallelsDesktopCloud.java From jenkins-parallels with MIT License | 5 votes |
@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 #13
Source File: FastNodeProvisionerStrategy.java From docker-plugin with MIT License | 5 votes |
@Override public void onEnterBuildable(Queue.BuildableItem item) { final Jenkins jenkins = Jenkins.getInstance(); final Label label = item.getAssignedLabel(); for (Cloud cloud : Jenkins.getInstance().clouds) { if (cloud instanceof DockerCloud && cloud.canProvision(label)) { final NodeProvisioner provisioner = (label == null ? jenkins.unlabeledNodeProvisioner : label.nodeProvisioner); provisioner.suggestReviewNow(); } } }
Example #14
Source File: EC2FleetCloudTest.java From ec2-spot-jenkins-plugin with Apache License 2.0 | 5 votes |
@Test public void provision_shouldProvisionNoMoreMaxWhenMultipleCallBeforeUpdate() { // given when(ec2Api.connect(any(String.class), any(String.class), anyString())).thenReturn(amazonEC2); PowerMockito.when(FleetStateStats.readClusterState(any(AmazonEC2.class), anyString(), anyString())) .thenReturn(new FleetStateStats("", 0, "active", Collections.<String>emptySet(), Collections.<String, Double>emptyMap())); EC2FleetCloud fleetCloud = new EC2FleetCloud(null, null, "credId", null, "region", "", "", "", null, null, false, false, 0, 0, 10, 1, false, false, false, 0, 0, false, 10, false); fleetCloud.setStats(new FleetStateStats("", 5, "active", Collections.<String>emptySet(), Collections.<String, Double>emptyMap())); // when Collection<NodeProvisioner.PlannedNode> r1 = fleetCloud.provision(null, 2); Collection<NodeProvisioner.PlannedNode> r2 = fleetCloud.provision(null, 2); Collection<NodeProvisioner.PlannedNode> r3 = fleetCloud.provision(null, 5); // then assertEquals(2, r1.size()); assertEquals(2, r2.size()); assertEquals(1, r3.size()); assertEquals(5, fleetCloud.getToAdd()); }
Example #15
Source File: KubernetesCloudTest.java From kubernetes-plugin with Apache License 2.0 | 5 votes |
@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 #16
Source File: KubernetesCloudTest.java From kubernetes-plugin with Apache License 2.0 | 5 votes |
@Test public void testContainerCap() { 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()); cloud.setContainerCapStr("10"); podTemplate.setInstanceCap(20); plannedNodes = cloud.provision(test, 200); assertEquals(10, plannedNodes.size()); }
Example #17
Source File: ECSCloud.java From amazon-ecs-plugin with MIT License | 5 votes |
@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 #18
Source File: FastNodeProvisionerStrategy.java From docker-plugin with MIT License | 5 votes |
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 #19
Source File: EC2FleetCloudWithHistory.java From ec2-spot-jenkins-plugin with Apache License 2.0 | 5 votes |
@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 #20
Source File: NoDelayProvisionStrategyTest.java From ec2-spot-jenkins-plugin with Apache License 2.0 | 5 votes |
@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 #21
Source File: NoDelayProvisionStrategyTest.java From ec2-spot-jenkins-plugin with Apache License 2.0 | 5 votes |
@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 #22
Source File: NoDelayProvisionStrategyTest.java From ec2-spot-jenkins-plugin with Apache License 2.0 | 5 votes |
@Test public void givenNonEC2Cloud_shouldDoNotScale() { when(snapshot.getQueueLength()).thenReturn(10); clouds.add(mock(Cloud.class)); Assert.assertEquals( NodeProvisioner.StrategyDecision.CONSULT_REMAINING_STRATEGIES, strategy.apply(state)); }
Example #23
Source File: NoDelayProvisionStrategyTest.java From ec2-spot-jenkins-plugin with Apache License 2.0 | 5 votes |
@Test public void givenNoEC2Cloud_shouldDoNotScale() { when(snapshot.getQueueLength()).thenReturn(10); Assert.assertEquals( NodeProvisioner.StrategyDecision.CONSULT_REMAINING_STRATEGIES, strategy.apply(state)); }
Example #24
Source File: NoDelayProvisionStrategyTest.java From ec2-spot-jenkins-plugin with Apache License 2.0 | 5 votes |
@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 #25
Source File: EC2FleetCloudWithMeter.java From ec2-spot-jenkins-plugin with Apache License 2.0 | 5 votes |
@Override public Collection<NodeProvisioner.PlannedNode> provision( final Label label, final int excessWorkload) { try (Meter.Shot s = provisionMeter.start()) { return super.provision(label, excessWorkload); } }
Example #26
Source File: NoDelayProvisionStrategyPerformanceTest.java From ec2-spot-jenkins-plugin with Apache License 2.0 | 5 votes |
@BeforeClass public static void beforeClass() { // zero is unlimited timeout System.setProperty("jenkins.test.timeout", "0"); // set default MARGIN for Jenkins System.setProperty(NodeProvisioner.class.getName() + ".MARGIN", Integer.toString(10)); }
Example #27
Source File: KafkaKubernetesCloudTest.java From remoting-kafka-plugin with MIT License | 5 votes |
@Test public void testProvisionCreateThenTerminatePod() throws Exception { KafkaKubernetesCloud cloud = new KafkaKubernetesCloud("kafka-kubernetes"); cloud.setServerUrl(k.getMockServer().url("/").toString()); cloud.setSkipTlsVerify(true); j.jenkins.clouds.add(cloud); Collection<NodeProvisioner.PlannedNode> provisionedNodes = cloud.provision(new LabelAtom("test"), 1); assertThat(provisionedNodes, hasSize(1)); KafkaCloudSlave agent = (KafkaCloudSlave) provisionedNodes.iterator().next().future.get(); TaskListener listener = new LogTaskListener(Logger.getLogger(KafkaKubernetesCloudTest.class.getName()), Level.INFO); PodResource<Pod, DoneablePod> pod = k.getClient().pods().inNamespace(cloud.getNamespace()).withName(agent.getNodeName()); assertNull(pod.get()); // Poll for pod creation j.jenkins.addNode(agent); final int TIMEOUT = 30; for(int i = 0; i < TIMEOUT; i++) { if (pod.get() != null) break; TimeUnit.SECONDS.sleep(1); } assertNotNull(pod.get()); agent._terminate(listener); assertNull(pod.get()); }
Example #28
Source File: NomadCloudTest.java From jenkins-nomad with MIT License | 5 votes |
@Test public void testProvision() { int workload = 3; Collection<NodeProvisioner.PlannedNode> plannedNodes = nomadCloud.provision(label, workload); Assert.assertEquals(plannedNodes.size(), workload); }
Example #29
Source File: NoDelayProvisionStrategy.java From ec2-spot-jenkins-plugin with Apache License 2.0 | 5 votes |
@Override public NodeProvisioner.StrategyDecision apply(final NodeProvisioner.StrategyState strategyState) { final Label label = strategyState.getLabel(); final LoadStatistics.LoadStatisticsSnapshot snapshot = strategyState.getSnapshot(); final int availableCapacity = snapshot.getAvailableExecutors() // live executors + snapshot.getConnectingExecutors() // executors present but not yet connected + strategyState.getPlannedCapacitySnapshot() // capacity added by previous strategies from previous rounds + strategyState.getAdditionalPlannedCapacity(); // capacity added by previous strategies _this round_ int currentDemand = snapshot.getQueueLength() - availableCapacity; LOGGER.log(Level.INFO, "Available capacity={0}, currentDemand={1}", new Object[]{availableCapacity, currentDemand}); for (final Cloud cloud : getClouds()) { if (currentDemand < 1) break; if (!(cloud instanceof EC2FleetCloud)) continue; if (!cloud.canProvision(label)) continue; final EC2FleetCloud ec2 = (EC2FleetCloud) cloud; if (!ec2.isNoDelayProvision()) continue; final Collection<NodeProvisioner.PlannedNode> plannedNodes = cloud.provision(label, currentDemand); currentDemand -= plannedNodes.size(); LOGGER.log(Level.FINE, "Planned {0} new nodes", plannedNodes.size()); strategyState.recordPendingLaunches(plannedNodes); LOGGER.log(Level.FINE, "After provisioning, available capacity={0}, currentDemand={1}", new Object[]{availableCapacity, currentDemand}); } if (currentDemand < 1) { LOGGER.log(Level.FINE, "Provisioning completed"); return NodeProvisioner.StrategyDecision.PROVISIONING_COMPLETED; } else { LOGGER.log(Level.FINE, "Provisioning not complete, consulting remaining strategies"); return NodeProvisioner.StrategyDecision.CONSULT_REMAINING_STRATEGIES; } }
Example #30
Source File: DockerSwarmCloud.java From docker-swarm-plugin with MIT License | 4 votes |
@Override public Collection<NodeProvisioner.PlannedNode> provision(final Label label, final int excessWorkload) { return new ArrayList<>(); }