hudson.slaves.ComputerConnector Java Examples
The following examples show how to use
hudson.slaves.ComputerConnector.
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: ProvisionIntegrationTest.java From ec2-spot-jenkins-plugin with Apache License 2.0 | 6 votes |
@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 #2
Source File: EC2FleetCloudTest.java From ec2-spot-jenkins-plugin with Apache License 2.0 | 5 votes |
@Test public void update_shouldAddNodeWithScaledNumExecutors_whenWeightPresentAndEnabled() throws IOException { // given when(ec2Api.connect(any(String.class), any(String.class), anyString())).thenReturn(amazonEC2); final String instanceType = "t"; final String instanceId = "i-0"; final Instance instance = new Instance() .withPublicIpAddress("p-ip") .withInstanceType(instanceType) .withInstanceId(instanceId); when(ec2Api.describeInstances(any(AmazonEC2.class), any(Set.class))).thenReturn( ImmutableMap.of(instanceId, instance)); PowerMockito.when(FleetStateStats.readClusterState(any(AmazonEC2.class), anyString(), anyString())) .thenReturn(new FleetStateStats("fleetId", 0, "active", ImmutableSet.of(instanceId), ImmutableMap.of(instanceType, 2.0))); mockNodeCreatingPart(); EC2FleetCloud fleetCloud = new EC2FleetCloud(null, null, "credId", null, "region", "", "fleetId", "", null, PowerMockito.mock(ComputerConnector.class), false, false, 0, 0, 1, 1, false, true, false, 0, 0, true, 10, false); ArgumentCaptor<Node> nodeCaptor = ArgumentCaptor.forClass(Node.class); doNothing().when(jenkins).addNode(nodeCaptor.capture()); // when fleetCloud.update(); // then Node actualFleetNode = nodeCaptor.getValue(); assertEquals(2, actualFleetNode.getNumExecutors()); }
Example #3
Source File: EC2FleetCloudTest.java From ec2-spot-jenkins-plugin with Apache License 2.0 | 5 votes |
@Test public void update_shouldAddNodeWithNumExecutors_whenWeightProvidedButNotEnabled() throws IOException { // given when(ec2Api.connect(any(String.class), any(String.class), anyString())).thenReturn(amazonEC2); final String instanceType = "t"; final Instance instance = new Instance() .withPublicIpAddress("p-ip") .withInstanceType(instanceType) .withInstanceId("i-0"); when(ec2Api.describeInstances(any(AmazonEC2.class), any(Set.class))).thenReturn( ImmutableMap.of("i-0", instance)); PowerMockito.when(FleetStateStats.readClusterState(any(AmazonEC2.class), anyString(), anyString())) .thenReturn(new FleetStateStats("fleetId", 0, "active", ImmutableSet.of("i-0"), ImmutableMap.of(instanceType, 1.1))); mockNodeCreatingPart(); EC2FleetCloud fleetCloud = new EC2FleetCloud(null, null, "credId", null, "region", "", "fleetId", "", null, PowerMockito.mock(ComputerConnector.class), false, false, 0, 0, 1, 1, false, true, false, 0, 0, false, 10, false); ArgumentCaptor<Node> nodeCaptor = ArgumentCaptor.forClass(Node.class); doNothing().when(jenkins).addNode(nodeCaptor.capture()); // when fleetCloud.update(); // then Node actualFleetNode = nodeCaptor.getValue(); assertEquals(1, actualFleetNode.getNumExecutors()); }
Example #4
Source File: EC2FleetCloudTest.java From ec2-spot-jenkins-plugin with Apache License 2.0 | 5 votes |
@Test public void update_shouldAddNodeIfAnyNewDescribed_restrictUsage() throws IOException { // 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("fleetId", 0, "active", ImmutableSet.of("i-0"), Collections.<String, Double>emptyMap())); final Instance instance = new Instance() .withPublicIpAddress("p-ip") .withInstanceId("i-0"); when(ec2Api.describeInstances(any(AmazonEC2.class), any(Set.class))).thenReturn( ImmutableMap.of("i-0", instance)); mockNodeCreatingPart(); EC2FleetCloud fleetCloud = new EC2FleetCloud(null, null, "credId", null, "region", "", "fleetId", "", null, PowerMockito.mock(ComputerConnector.class), false, false, 0, 0, 1, 1, false, true, false, 0, 0, false, 10, false); ArgumentCaptor<Node> nodeCaptor = ArgumentCaptor.forClass(Node.class); doNothing().when(jenkins).addNode(nodeCaptor.capture()); // when FleetStateStats stats = fleetCloud.update(); // then assertEquals(0, stats.getNumDesired()); assertEquals(1, stats.getNumActive()); assertEquals("fleetId", stats.getFleetId()); // and Node actualFleetNode = nodeCaptor.getValue(); assertEquals(Node.Mode.EXCLUSIVE, actualFleetNode.getMode()); }
Example #5
Source File: EC2FleetCloudTest.java From ec2-spot-jenkins-plugin with Apache License 2.0 | 5 votes |
@Test public void update_shouldAddNodeIfAnyNewDescribed() throws IOException { // given when(ec2Api.connect(any(String.class), any(String.class), anyString())).thenReturn(amazonEC2); final Instance instance = new Instance() .withPublicIpAddress("p-ip") .withInstanceId("i-0"); when(ec2Api.describeInstances(any(AmazonEC2.class), any(Set.class))).thenReturn( ImmutableMap.of("i-0", instance)); PowerMockito.when(FleetStateStats.readClusterState(any(AmazonEC2.class), anyString(), anyString())) .thenReturn(new FleetStateStats("fleetId", 0, "active", ImmutableSet.of("i-0"), Collections.<String, Double>emptyMap())); mockNodeCreatingPart(); EC2FleetCloud fleetCloud = new EC2FleetCloud(null, null, "credId", null, "region", "", "fleetId", "", null, PowerMockito.mock(ComputerConnector.class), false, false, 0, 0, 1, 1, false, false, false, 0, 0, false, 10, false); ArgumentCaptor<Node> nodeCaptor = ArgumentCaptor.forClass(Node.class); doNothing().when(jenkins).addNode(nodeCaptor.capture()); // when FleetStateStats stats = fleetCloud.update(); // then assertEquals(0, stats.getNumDesired()); assertEquals(1, stats.getNumActive()); assertEquals("fleetId", stats.getFleetId()); // and Node actualFleetNode = nodeCaptor.getValue(); assertEquals(Node.Mode.NORMAL, actualFleetNode.getMode()); }
Example #6
Source File: EC2FleetCloudTest.java From ec2-spot-jenkins-plugin with Apache License 2.0 | 5 votes |
@Test public void update_shouldAddNodeWithNumExecutors_whenWeightPresentAndEnabledButForDiffType() throws IOException { // given when(ec2Api.connect(any(String.class), any(String.class), anyString())).thenReturn(amazonEC2); final String instanceType = "t"; final String instanceId = "i-0"; final Instance instance = new Instance() .withPublicIpAddress("p-ip") .withInstanceType(instanceType) .withInstanceId(instanceId); when(ec2Api.describeInstances(any(AmazonEC2.class), any(Set.class))).thenReturn( ImmutableMap.of(instanceId, instance)); PowerMockito.when(FleetStateStats.readClusterState(any(AmazonEC2.class), anyString(), anyString())) .thenReturn(new FleetStateStats("fleetId", 0, "active", ImmutableSet.of(instanceId), ImmutableMap.of("diff-t", 2.0))); mockNodeCreatingPart(); EC2FleetCloud fleetCloud = new EC2FleetCloud(null, null, "credId", null, "region", "", "fleetId", "", null, PowerMockito.mock(ComputerConnector.class), false, false, 0, 0, 1, 1, false, true, false, 0, 0, true, 10, false); ArgumentCaptor<Node> nodeCaptor = ArgumentCaptor.forClass(Node.class); doNothing().when(jenkins).addNode(nodeCaptor.capture()); // when fleetCloud.update(); // then Node actualFleetNode = nodeCaptor.getValue(); assertEquals(1, actualFleetNode.getNumExecutors()); }
Example #7
Source File: EC2FleetCloudTest.java From ec2-spot-jenkins-plugin with Apache License 2.0 | 5 votes |
@Test public void update_shouldAddNodeWithRoundToLowScaledNumExecutors_whenWeightPresentAndEnabled() throws IOException { // given when(ec2Api.connect(any(String.class), any(String.class), anyString())).thenReturn(amazonEC2); final String instanceType = "t"; final String instanceId = "i-0"; final Instance instance = new Instance() .withPublicIpAddress("p-ip") .withInstanceType(instanceType) .withInstanceId(instanceId); when(ec2Api.describeInstances(any(AmazonEC2.class), any(Set.class))).thenReturn( ImmutableMap.of(instanceId, instance)); PowerMockito.when(FleetStateStats.readClusterState(any(AmazonEC2.class), anyString(), anyString())) .thenReturn(new FleetStateStats("fleetId", 0, "active", ImmutableSet.of(instanceId), ImmutableMap.of(instanceType, 1.44))); mockNodeCreatingPart(); EC2FleetCloud fleetCloud = new EC2FleetCloud(null, null, "credId", null, "region", "", "fleetId", "", null, PowerMockito.mock(ComputerConnector.class), false, false, 0, 0, 1, 1, false, true, false, 0, 0, true, 10, false); ArgumentCaptor<Node> nodeCaptor = ArgumentCaptor.forClass(Node.class); doNothing().when(jenkins).addNode(nodeCaptor.capture()); // when fleetCloud.update(); // then Node actualFleetNode = nodeCaptor.getValue(); assertEquals(1, actualFleetNode.getNumExecutors()); }
Example #8
Source File: ProvisionIntegrationTest.java From ec2-spot-jenkins-plugin with Apache License 2.0 | 5 votes |
@Test public void should_not_convert_planned_to_node_if_state_is_not_running_and_check_state_enabled() throws Exception { ComputerLauncher computerLauncher = mock(ComputerLauncher.class); ComputerConnector computerConnector = mock(ComputerConnector.class); when(computerConnector.launch(anyString(), any(TaskListener.class))).thenReturn(computerLauncher); EC2FleetCloud cloud = new EC2FleetCloud(null, null, "credId", null, "region", null, "fId", "momo", null, computerConnector, false, false, 0, 0, 10, 1, true, false, false, 0, 0, false, 2, false); j.jenkins.clouds.add(cloud); mockEc2ApiToDescribeInstancesWhenModified(InstanceStateName.Pending); List<QueueTaskFuture> rs = getQueueTaskFutures(1); triggerSuggestReviewNow("momo"); Assert.assertEquals(0, j.jenkins.getNodes().size()); tryUntil(new Runnable() { @Override public void run() { Assert.assertEquals(ImmutableSet.of("master", "momo"), labelsToNames(j.jenkins.getLabels())); Assert.assertEquals(1, j.jenkins.getLabelAtom("momo").nodeProvisioner.getPendingLaunches().size()); Assert.assertEquals(0, j.jenkins.getNodes().size()); } }); cancelTasks(rs); }
Example #9
Source File: EC2FleetCloudTest.java From ec2-spot-jenkins-plugin with Apache License 2.0 | 5 votes |
@Test public void update_shouldAddNodeWithRoundToLowScaledNumExecutors_whenWeightPresentAndEnabled1() throws IOException { // given when(ec2Api.connect(any(String.class), any(String.class), anyString())).thenReturn(amazonEC2); final String instanceType = "t"; final String instanceId = "i-0"; final Instance instance = new Instance() .withPublicIpAddress("p-ip") .withInstanceType(instanceType) .withInstanceId(instanceId); when(ec2Api.describeInstances(any(AmazonEC2.class), any(Set.class))).thenReturn( ImmutableMap.of(instanceId, instance)); PowerMockito.when(FleetStateStats.readClusterState(any(AmazonEC2.class), anyString(), anyString())) .thenReturn(new FleetStateStats("fleetId", 0, "active", ImmutableSet.of(instanceId), ImmutableMap.of(instanceType, 1.5))); mockNodeCreatingPart(); EC2FleetCloud fleetCloud = new EC2FleetCloud(null, null, "credId", null, "region", "", "fleetId", "", null, PowerMockito.mock(ComputerConnector.class), false, false, 0, 0, 1, 1, false, true, false, 0, 0, true, 10, false); ArgumentCaptor<Node> nodeCaptor = ArgumentCaptor.forClass(Node.class); doNothing().when(jenkins).addNode(nodeCaptor.capture()); // when fleetCloud.update(); // then Node actualFleetNode = nodeCaptor.getValue(); assertEquals(2, actualFleetNode.getNumExecutors()); }
Example #10
Source File: ProvisionIntegrationTest.java From ec2-spot-jenkins-plugin with Apache License 2.0 | 5 votes |
@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 #11
Source File: ProvisionIntegrationTest.java From ec2-spot-jenkins-plugin with Apache License 2.0 | 5 votes |
@Test public void should_add_planned_if_capacity_required_but_not_described_yet() throws Exception { ComputerLauncher computerLauncher = mock(ComputerLauncher.class); ComputerConnector computerConnector = mock(ComputerConnector.class); when(computerConnector.launch(anyString(), any(TaskListener.class))).thenReturn(computerLauncher); mockEc2ApiToDescribeFleetNotInstanceWhenModified(); EC2FleetCloud cloud = new EC2FleetCloud(null, null, "credId", null, "region", null, "fId", "momo", null, computerConnector, false, false, 0, 0, 10, 1, false, false, false, 0, 0, false, 2, false); j.jenkins.clouds.add(cloud); List<QueueTaskFuture> rs = getQueueTaskFutures(1); triggerSuggestReviewNow("momo"); Assert.assertEquals(0, j.jenkins.getNodes().size()); tryUntil(new Runnable() { @Override public void run() { Assert.assertEquals(0, j.jenkins.getNodes().size()); Assert.assertEquals(2, j.jenkins.getLabels().size()); Assert.assertEquals(1, j.jenkins.getLabelAtom("momo").nodeProvisioner.getPendingLaunches().size()); } }); cancelTasks(rs); }
Example #12
Source File: EC2FleetCloudTest.java From ec2-spot-jenkins-plugin with Apache License 2.0 | 5 votes |
@Test public void update_shouldAddNodeWithScaledToOneNumExecutors_whenWeightPresentButLessOneAndEnabled() throws IOException { // given when(ec2Api.connect(any(String.class), any(String.class), anyString())).thenReturn(amazonEC2); final String instanceType = "t"; final String instanceId = "i-0"; final Instance instance = new Instance() .withPublicIpAddress("p-ip") .withInstanceType(instanceType) .withInstanceId(instanceId); when(ec2Api.describeInstances(any(AmazonEC2.class), any(Set.class))).thenReturn( ImmutableMap.of(instanceId, instance)); PowerMockito.when(FleetStateStats.readClusterState(any(AmazonEC2.class), anyString(), anyString())) .thenReturn(new FleetStateStats("fleetId", 0, "active", ImmutableSet.of(instanceId), ImmutableMap.of(instanceType, .1))); mockNodeCreatingPart(); EC2FleetCloud fleetCloud = new EC2FleetCloud(null, null, "credId", null, "region", "", "fleetId", "", null, PowerMockito.mock(ComputerConnector.class), false, false, 0, 0, 1, 1, false, true, false, 0, 0, true, 10, false); ArgumentCaptor<Node> nodeCaptor = ArgumentCaptor.forClass(Node.class); doNothing().when(jenkins).addNode(nodeCaptor.capture()); // when fleetCloud.update(); // then Node actualFleetNode = nodeCaptor.getValue(); assertEquals(1, actualFleetNode.getNumExecutors()); }
Example #13
Source File: ComputerConnectorTester.java From jenkins-test-harness with MIT License | 4 votes |
public void doConfigSubmit(StaplerRequest req) throws IOException, ServletException { connector = req.bindJSON(ComputerConnector.class, req.getSubmittedForm().getJSONObject("connector")); }
Example #14
Source File: JenkinsRule.java From jenkins-test-harness with MIT License | 4 votes |
public <C extends ComputerConnector> C configRoundtrip(C before) throws Exception { computerConnectorTester.connector = before; submit(createWebClient().goTo("self/computerConnectorTester/configure").getFormByName("config")); return (C)computerConnectorTester.connector; }
Example #15
Source File: JenkinsComputerConnectorTester.java From jenkins-test-harness with MIT License | 4 votes |
public void doConfigSubmit(StaplerRequest req) throws IOException, ServletException { connector = req.bindJSON(ComputerConnector.class, req.getSubmittedForm().getJSONObject("connector")); }
Example #16
Source File: HudsonTestCase.java From jenkins-test-harness with MIT License | 4 votes |
@SuppressWarnings("unchecked") protected <C extends ComputerConnector> C configRoundtrip(C before) throws Exception { computerConnectorTester.connector = before; submit(createWebClient().goTo("self/computerConnectorTester/configure").getFormByName("config")); return (C)computerConnectorTester.connector; }
Example #17
Source File: EC2FleetCloudWithMeter.java From ec2-spot-jenkins-plugin with Apache License 2.0 | 4 votes |
public EC2FleetCloudWithMeter(String name, String oldId, String awsCredentialsId, String credentialsId, String region, String endpoint, String fleet, String labelString, String fsRoot, ComputerConnector computerConnector, boolean privateIpUsed, boolean alwaysReconnect, Integer idleMinutes, Integer minSize, Integer maxSize, Integer numExecutors, boolean addNodeOnlyIfRunning, boolean restrictUsage, boolean disableTaskResubmit, Integer initOnlineTimeoutSec, Integer initOnlineCheckIntervalSec, boolean scaleExecutorsByWeight, Integer cloudStatusIntervalSec, boolean immediatelyProvision) { super(name, oldId, awsCredentialsId, credentialsId, region, endpoint, fleet, labelString, fsRoot, computerConnector, privateIpUsed, alwaysReconnect, idleMinutes, minSize, maxSize, numExecutors, addNodeOnlyIfRunning, restrictUsage, disableTaskResubmit, initOnlineTimeoutSec, initOnlineCheckIntervalSec, scaleExecutorsByWeight, cloudStatusIntervalSec, immediatelyProvision); }
Example #18
Source File: EC2FleetCloud.java From ec2-spot-jenkins-plugin with Apache License 2.0 | 4 votes |
@DataBoundConstructor public EC2FleetCloud(final String name, final String oldId, final String awsCredentialsId, final @Deprecated String credentialsId, final String region, final String endpoint, final String fleet, final String labelString, final String fsRoot, final ComputerConnector computerConnector, final boolean privateIpUsed, final boolean alwaysReconnect, final Integer idleMinutes, final Integer minSize, final Integer maxSize, final Integer numExecutors, final boolean addNodeOnlyIfRunning, final boolean restrictUsage, final boolean disableTaskResubmit, final Integer initOnlineTimeoutSec, final Integer initOnlineCheckIntervalSec, final boolean scaleExecutorsByWeight, final Integer cloudStatusIntervalSec, final boolean noDelayProvision) { super(StringUtils.isBlank(name) ? FLEET_CLOUD_ID : name); init(); this.credentialsId = credentialsId; this.awsCredentialsId = awsCredentialsId; this.region = region; this.endpoint = endpoint; this.fleet = fleet; this.fsRoot = fsRoot; this.computerConnector = computerConnector; this.labelString = labelString; this.idleMinutes = idleMinutes; this.privateIpUsed = privateIpUsed; this.alwaysReconnect = alwaysReconnect; this.minSize = minSize; this.maxSize = maxSize; this.numExecutors = numExecutors; this.addNodeOnlyIfRunning = addNodeOnlyIfRunning; this.restrictUsage = restrictUsage; this.scaleExecutorsByWeight = scaleExecutorsByWeight; this.disableTaskResubmit = disableTaskResubmit; this.initOnlineTimeoutSec = initOnlineTimeoutSec; this.initOnlineCheckIntervalSec = initOnlineCheckIntervalSec; this.cloudStatusIntervalSec = cloudStatusIntervalSec; this.noDelayProvision = noDelayProvision; if (StringUtils.isNotEmpty(oldId)) { // existent cloud was modified, let's re-assign all dependencies of old cloud instance // to new one EC2FleetCloudAwareUtils.reassign(oldId, this); } }
Example #19
Source File: ProvisionIntegrationTest.java From ec2-spot-jenkins-plugin with Apache License 2.0 | 4 votes |
@Test public void should_continue_update_after_termination() throws IOException { mockEc2ApiToDescribeInstancesWhenModified(InstanceStateName.Running, 5); final ComputerConnector computerConnector = new LocalComputerConnector(j); final EC2FleetCloud cloud = new EC2FleetCloud(null, null, "credId", null, "region", null, "fId", "momo", null, computerConnector, false, false, 1, 0, 5, 1, true, false, false, 0, 0, false, 10, false); j.jenkins.clouds.add(cloud); // wait while all nodes will be ok // tryUntil(new Runnable() { // @Override // public void run() { // for (Node node : j.jenkins.getNodes()) { // final Computer computer = node.toComputer(); // Assert.assertNotNull(computer); // Assert.assertTrue(computer.isOnline()); // } // } // }); final List<QueueTaskFuture<FreeStyleBuild>> tasks = new ArrayList<>(); tasks.addAll((List) getQueueTaskFutures(5)); System.out.println("tasks submitted"); // wait full execution for (final QueueTaskFuture<FreeStyleBuild> task : tasks) { try { Assert.assertEquals(task.get().getResult(), Result.SUCCESS); } catch (InterruptedException | ExecutionException e) { throw new RuntimeException(e); } } // wait until downscale happens tryUntil(new Runnable() { @Override public void run() { // defect in termination logic, that why 1 Assert.assertThat(j.jenkins.getLabel("momo").getNodes().size(), Matchers.lessThanOrEqualTo(1)); } }, TimeUnit.MINUTES.toMillis(3)); final FleetStateStats oldStats = cloud.getStats(); tryUntil(new Runnable() { @Override public void run() { System.out.println("stats should be updated"); Assert.assertNotSame(oldStats, cloud.getStats()); } }); }
Example #20
Source File: ProvisionIntegrationTest.java From ec2-spot-jenkins-plugin with Apache License 2.0 | 4 votes |
@Test public void should_not_allow_jenkins_to_provision_if_address_not_available() 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, 0, 0, false, 10, false)); cloud.setStats(new FleetStateStats("", 0, "active", Collections.<String>emptySet(), Collections.<String, Double>emptyMap())); j.jenkins.clouds.add(cloud); EC2Api ec2Api = spy(EC2Api.class); Registry.setEc2Api(ec2Api); AmazonEC2 amazonEC2 = mock(AmazonEC2.class); when(ec2Api.connect(anyString(), anyString(), Mockito.nullable(String.class))).thenReturn(amazonEC2); when(amazonEC2.describeInstances(any(DescribeInstancesRequest.class))).thenReturn( new DescribeInstancesResult().withReservations( new Reservation().withInstances( new Instance() .withState(new InstanceState().withName(InstanceStateName.Running)) // .withPublicIpAddress("public-io") .withInstanceId("i-1") ))); when(amazonEC2.describeSpotFleetInstances(any(DescribeSpotFleetInstancesRequest.class))).thenReturn( new DescribeSpotFleetInstancesResult().withActiveInstances(new ActiveInstance().withInstanceId("i-1"))); DescribeSpotFleetRequestsResult describeSpotFleetRequestsResult = new DescribeSpotFleetRequestsResult(); describeSpotFleetRequestsResult.setSpotFleetRequestConfigs(Arrays.asList( new SpotFleetRequestConfig() .withSpotFleetRequestState("active") .withSpotFleetRequestConfig( new SpotFleetRequestConfigData().withTargetCapacity(1)))); when(amazonEC2.describeSpotFleetRequests(any(DescribeSpotFleetRequestsRequest.class))) .thenReturn(describeSpotFleetRequestsResult); List<QueueTaskFuture> rs = getQueueTaskFutures(1); j.jenkins.getLabelAtom("momo").nodeProvisioner.suggestReviewNow(); Assert.assertEquals(0, j.jenkins.getNodes().size()); Thread.sleep(TimeUnit.MINUTES.toMillis(2)); cancelTasks(rs); verify(cloud, times(1)).provision(any(Label.class), anyInt()); }
Example #21
Source File: ProvisionIntegrationTest.java From ec2-spot-jenkins-plugin with Apache License 2.0 | 4 votes |
@Test public void dont_provide_any_planned_if_empty_and_reached_max_capacity() throws Exception { ComputerLauncher computerLauncher = mock(ComputerLauncher.class); ComputerConnector computerConnector = mock(ComputerConnector.class); when(computerConnector.launch(anyString(), any(TaskListener.class))).thenReturn(computerLauncher); EC2FleetCloud cloud = new EC2FleetCloud(null, null, "credId", null, "region", null, "fId", "momo", null, computerConnector, false, false, 0, 0, 0, 1, false, false, false, 0, 0, false, 2, false); j.jenkins.clouds.add(cloud); EC2Api ec2Api = spy(EC2Api.class); Registry.setEc2Api(ec2Api); AmazonEC2 amazonEC2 = mock(AmazonEC2.class); when(ec2Api.connect(anyString(), anyString(), Mockito.nullable(String.class))).thenReturn(amazonEC2); when(amazonEC2.describeSpotFleetInstances(any(DescribeSpotFleetInstancesRequest.class))) .thenReturn(new DescribeSpotFleetInstancesResult()); DescribeSpotFleetRequestsResult describeSpotFleetRequestsResult = new DescribeSpotFleetRequestsResult(); describeSpotFleetRequestsResult.setSpotFleetRequestConfigs(Arrays.asList( new SpotFleetRequestConfig() .withSpotFleetRequestState("active") .withSpotFleetRequestConfig( new SpotFleetRequestConfigData().withTargetCapacity(0)))); when(amazonEC2.describeSpotFleetRequests(any(DescribeSpotFleetRequestsRequest.class))) .thenReturn(describeSpotFleetRequestsResult); List<QueueTaskFuture> rs = getQueueTaskFutures(5); Assert.assertEquals(0, j.jenkins.getNodes().size()); triggerSuggestReviewNow("momo"); Thread.sleep(TimeUnit.SECONDS.toMillis(30)); Assert.assertEquals(0, j.jenkins.getNodes().size()); cancelTasks(rs); }
Example #22
Source File: EC2FleetCloudWithHistory.java From ec2-spot-jenkins-plugin with Apache License 2.0 | 4 votes |
public EC2FleetCloudWithHistory(String name, String oldId, String awsCredentialsId, String credentialsId, String region, String endpoint, String fleet, String labelString, String fsRoot, ComputerConnector computerConnector, boolean privateIpUsed, boolean alwaysReconnect, Integer idleMinutes, Integer minSize, Integer maxSize, Integer numExecutors, boolean addNodeOnlyIfRunning, boolean restrictUsage, boolean disableTaskResubmit, Integer initOnlineTimeoutSec, Integer initOnlineCheckIntervalSec, boolean scaleExecutorsByWeight, Integer cloudStatusIntervalSec, boolean immediatelyProvision) { super(name, oldId, awsCredentialsId, credentialsId, region, endpoint, fleet, labelString, fsRoot, computerConnector, privateIpUsed, alwaysReconnect, idleMinutes, minSize, maxSize, numExecutors, addNodeOnlyIfRunning, restrictUsage, disableTaskResubmit, initOnlineTimeoutSec, initOnlineCheckIntervalSec, scaleExecutorsByWeight, cloudStatusIntervalSec, immediatelyProvision); }
Example #23
Source File: ProvisionPerformanceTest.java From ec2-spot-jenkins-plugin with Apache License 2.0 | 4 votes |
private void test(int workers, int maxTasks) throws IOException, InterruptedException { mockEc2ApiToDescribeInstancesWhenModifiedWithDelay(InstanceStateName.Running, 500); final ComputerConnector computerConnector = new LocalComputerConnector(j); final EC2FleetCloudWithMeter cloud = new EC2FleetCloudWithMeter(null, null, "credId", null, "region", null, "fId", "momo", null, computerConnector, false, false, 1, 0, workers, 1, true, false, false, 0, 0, false, 2, false); j.jenkins.clouds.add(cloud); // updated plugin requires some init time to get first update // so wait this event to be really correct with perf comparison as old version is not require init time tryUntil(new Runnable() { @Override public void run() { Assert.assertNotNull(cloud.getStats()); } }); System.out.println("start test"); final long start = System.currentTimeMillis(); final List<QueueTaskFuture<FreeStyleBuild>> tasks = new ArrayList<>(); final int taskBatch = 5; while (tasks.size() < maxTasks) { tasks.addAll((List) getQueueTaskFutures(taskBatch)); triggerSuggestReviewNow("momo"); System.out.println(taskBatch + " added into queue, " + (maxTasks - tasks.size()) + " remain"); } for (final QueueTaskFuture<FreeStyleBuild> task : tasks) { try { Assert.assertEquals(task.get().getResult(), Result.SUCCESS); } catch (InterruptedException | ExecutionException e) { throw new RuntimeException(e); } } System.out.println("downscale"); final long finish = System.currentTimeMillis(); // wait until downscale happens tryUntil(new Runnable() { @Override public void run() { // defect in termination logic, that why 1 Assert.assertThat(j.jenkins.getLabel("momo").getNodes().size(), Matchers.lessThanOrEqualTo(1)); } }, TimeUnit.MINUTES.toMillis(3)); final long upTime = TimeUnit.MILLISECONDS.toSeconds(finish - start); final long downTime = TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis() - finish); final long totalTime = upTime + downTime; final long ideaUpTime = (maxTasks / workers) * JOB_SLEEP_TIME; final int idealDownTime = 60; final long ideaTime = ideaUpTime + idealDownTime; System.out.println(maxTasks + " up in " + upTime + " sec, ideal time is " + ideaUpTime + " sec, overhead is " + (upTime - ideaUpTime) + " sec"); System.out.println(maxTasks + " down in " + downTime + " sec, ideal time is " + idealDownTime + " sec, overhead is " + (downTime - idealDownTime) + " sec"); System.out.println(maxTasks + " completed in " + totalTime + " sec, ideal time is " + ideaTime + " sec, overhead is " + (totalTime - ideaTime) + " sec"); System.out.println(cloud.provisionMeter); System.out.println(cloud.removeMeter); System.out.println(cloud.updateMeter); }
Example #24
Source File: EC2FleetCloud.java From ec2-spot-jenkins-plugin with Apache License 2.0 | 4 votes |
public List getComputerConnectorDescriptors() { return Jenkins.getInstance().getDescriptorList(ComputerConnector.class); }
Example #25
Source File: EC2FleetCloud.java From ec2-spot-jenkins-plugin with Apache License 2.0 | 4 votes |
public ComputerConnector getComputerConnector() { return computerConnector; }