hudson.slaves.Cloud Java Examples
The following examples show how to use
hudson.slaves.Cloud.
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: DockerComputerConnectorTest.java From docker-plugin with MIT License | 6 votes |
private boolean dockerIsStillBusy() throws Exception { for( final Node n : j.jenkins.getNodes() ) { if( n instanceof DockerTransientNode ) { return true; } } for( final Cloud c : j.jenkins.clouds) { if( c instanceof DockerCloud) { DockerCloud cloud = (DockerCloud)c; for( final DockerTemplate t : cloud.getTemplates() ) { final int containersInProgress = cloud.countContainersInProgress(t); if( containersInProgress > 0 ) { return true; } } final int containersInDocker = cloud.countContainersInDocker(null); if( containersInDocker > 0 ) { return true; } } } return false; }
Example #2
Source File: DockerComputerSSHLauncherTest.java From yet-another-docker-plugin with MIT License | 6 votes |
@LocalData @Test public void migration() { Cloud cl = jenkinsRule.getInstance().getCloud("cloudName"); assertThat(cl, notNullValue()); DockerCloud cloud = (DockerCloud) cl; assertThat(cloud, notNullValue()); DockerSlaveTemplate template = cloud.getTemplateById("fb5f32a8-bfdd-4f00-8df8-fcf3cf14ab63"); assertThat(template, notNullValue()); DockerComputerLauncher l = template.getLauncher(); assertThat(l, instanceOf(DockerComputerSSHLauncher.class)); DockerComputerSSHLauncher sshLauncher = (DockerComputerSSHLauncher) l; DockerSSHConnector dockerSSHConnector = sshLauncher.getSshConnector(); assertThat(dockerSSHConnector, notNullValue()); assertThat(dockerSSHConnector.getSshHostKeyVerificationStrategy(), notNullValue()); assertThat(dockerSSHConnector.getSshHostKeyVerificationStrategy(), instanceOf(KnownHostsFileKeyVerificationStrategy.class)); assertThat(dockerSSHConnector.getSuffixStartSlaveCmd(), is("suffixStartSlave")); assertThat(dockerSSHConnector.getPrefixStartSlaveCmd(), is("prefixStartSlave")); }
Example #3
Source File: DockerCloudRetentionStrategyTest.java From yet-another-docker-plugin with MIT License | 6 votes |
@LocalData @Test public void testConfig() { final Cloud cloud = jenkinsRule.getInstance().getCloud("ff"); assertThat(cloud, instanceOf(DockerCloud.class)); final DockerCloud dockerCloud = (DockerCloud) cloud; final DockerSlaveTemplate template = dockerCloud.getTemplate("image"); assertThat(template, notNullValue()); final RetentionStrategy retentionStrategy = template.getRetentionStrategy(); assertThat(retentionStrategy, instanceOf(DockerCloudRetentionStrategy.class)); final DockerCloudRetentionStrategy strategy = (DockerCloudRetentionStrategy) retentionStrategy; assertThat(strategy.getIdleMinutes(), is(30)); }
Example #4
Source File: ECSTaskTemplateStepExecution.java From amazon-ecs-plugin with MIT License | 6 votes |
private Cloud findCloud(String parentLabel) { Cloud cloud = null; Jenkins.CloudList clouds = cloudSupplier.get(); if (parentLabel != null) { for (Cloud c: clouds) { if (c instanceof ECSCloud) { ECSCloud ecsCloud = (ECSCloud)c; if (ecsCloud.canProvision(parentLabel)){ cloud = c; break; } } } } else { cloud = clouds.getByName(this.cloudName); } return cloud; }
Example #5
Source File: ECSTaskTemplateStepExecution.java From amazon-ecs-plugin with MIT License | 6 votes |
@Override /* Remove the template after step is done */ protected void finished(StepContext context) throws Exception { Cloud c = Jenkins.get().getCloud(cloudName); if (c == null) { LOGGER.log(Level.WARNING, "Cloud {0} no longer exists, cannot delete task template {1}", new Object[] { cloudName, taskTemplate.getTemplateName() }); return; } if (c instanceof ECSCloud) { ECSCloud ecsCloud = (ECSCloud) c; LOGGER.log(Level.INFO, "Removing task template {1} from internal map and AWS cloud {0}", new Object[] { c.name, taskTemplate.getTemplateName() }); ecsCloud.removeDynamicTemplate(taskTemplate); } else { LOGGER.log(Level.WARNING, "Cloud is not an ECSCloud: {0} {1}", new String[] { c.name, c.getClass().getName() }); } }
Example #6
Source File: PodTemplateStepExecution.java From kubernetes-plugin with Apache License 2.0 | 6 votes |
@Override /** * Remove the template after step is done */ protected void finished(StepContext context) throws Exception { Cloud cloud = Jenkins.get().getCloud(cloudName); if (cloud == null) { LOGGER.log(Level.WARNING, "Cloud {0} no longer exists, cannot delete pod template {1}", new Object[] { cloudName, podTemplate.getName() }); return; } if (cloud instanceof KubernetesCloud) { LOGGER.log(Level.INFO, "Removing pod template {1} from cloud {0}", new Object[] { cloud.name, podTemplate.getName() }); KubernetesCloud kubernetesCloud = (KubernetesCloud) cloud; kubernetesCloud.removeDynamicTemplate(podTemplate); } else { LOGGER.log(Level.WARNING, "Cloud is not a KubernetesCloud: {0} {1}", new String[] { cloud.name, cloud.getClass().getName() }); } }
Example #7
Source File: AbstractStepExecution.java From kubernetes-pipeline-plugin with Apache License 2.0 | 6 votes |
/** * Obtains a {@link KubernetesClient} either from the configured {@link Cloud} or a default instance. * @return * @throws AbortException */ protected KubernetesClient getKubernetesClient() throws AbortException { Cloud cloud = Jenkins.getInstance().getCloud(getStep().getCloud()); if (cloud == null) { LOGGER.warning("Cloud does not exist: [" + getStep().getCloud() + "]. Falling back to default KubernetesClient."); } else if (!(cloud instanceof KubernetesCloud)) { LOGGER.warning("Cloud is not a Kubernetes cloud: [" + getStep().getCloud() + "]. Falling back to default KubernetesClient."); } else { KubernetesCloud kubernetesCloud = (KubernetesCloud) cloud; try { String json = Serialization.asJson(kubernetesCloud.connect().getConfiguration()); return DefaultKubernetesClient.fromConfig(json); } catch (Throwable t) { LOGGER.warning("Could not connect to cloud: [" + getStep().getCloud() + "]. Falling back to default KubernetesClient."); } } return new DefaultKubernetesClient(); }
Example #8
Source File: DockerBuilderNewTemplate.java From docker-plugin with MIT License | 6 votes |
@Override public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException { final PrintStream llogger = listener.getLogger(); final String dockerImage = dockerTemplate.getDockerTemplateBase().getImage(); // Job must run as Admin as we are changing global cloud configuration here. build.getACL().checkPermission(Jenkins.ADMINISTER); for (Cloud c : Jenkins.getInstance().clouds) { if (c instanceof DockerCloud && dockerImage != null) { DockerCloud dockerCloud = (DockerCloud) c; if (dockerCloud.getTemplate(dockerImage) == null) { LOGGER.info("Adding new template: '{}', to cloud: '{}'", dockerImage, dockerCloud.name); llogger.println("Adding new template: '" + dockerImage + "', to cloud: '" + dockerCloud.name + "'"); dockerCloud.addTemplate(dockerTemplate); } } } return true; }
Example #9
Source File: UiIntegrationTest.java From ec2-spot-jenkins-plugin with Apache License 2.0 | 6 votes |
@Test public void shouldShowMultipleCloudsWithDefaultName() throws IOException, SAXException { Cloud cloud1 = new EC2FleetCloud(null, null, null, null, null, null, null, null, null, null, false, false, 0, 0, 0, 0, false, false, false, 0, 0, false, 10, false); j.jenkins.clouds.add(cloud1); Cloud cloud2 = new EC2FleetCloud(null, null, null, null, null, null, null, null, null, null, false, false, 0, 0, 0, 0, false, false, false, 0, 0, false, 10, false); j.jenkins.clouds.add(cloud2); HtmlPage page = j.createWebClient().goTo("configure"); List<DomElement> elementsByName = getElementsByNameWithoutJdk(page, "_.name"); assertEquals(2, elementsByName.size()); assertEquals("FleetCloud", ((HtmlTextInput) elementsByName.get(0)).getText()); assertEquals("FleetCloud", ((HtmlTextInput) elementsByName.get(1)).getText()); }
Example #10
Source File: UiIntegrationTest.java From ec2-spot-jenkins-plugin with Apache License 2.0 | 6 votes |
@Test public void shouldShowMultipleClouds() throws IOException, SAXException { Cloud cloud1 = new EC2FleetCloud("a", null, null, null, null, null, null, null, null, null, false, false, 0, 0, 0, 0, false, false, false, 0, 0, false, 10, false); j.jenkins.clouds.add(cloud1); Cloud cloud2 = new EC2FleetCloud("b", null, null, null, null, null, null, null, null, null, false, false, 0, 0, 0, 0, false, false, false, 0, 0, false, 10, false); j.jenkins.clouds.add(cloud2); HtmlPage page = j.createWebClient().goTo("configure"); List<DomElement> elementsByName = getElementsByNameWithoutJdk(page, "_.name"); assertEquals(2, elementsByName.size()); assertEquals("a", ((HtmlTextInput) elementsByName.get(0)).getText()); assertEquals("b", ((HtmlTextInput) elementsByName.get(1)).getText()); }
Example #11
Source File: UiIntegrationTest.java From ec2-spot-jenkins-plugin with Apache License 2.0 | 6 votes |
@Test public void shouldReplaceCloudForNodesAfterConfigurationSave() throws Exception { EC2FleetCloud cloud = new EC2FleetCloud(null, null, null, null, null, null, null, null, null, null, false, false, 0, 0, 0, 0, false, false, false, 0, 0, false, 10, false); j.jenkins.clouds.add(cloud); j.jenkins.addNode(new EC2FleetNode("mock", "", "", 1, Node.Mode.EXCLUSIVE, "", new ArrayList<NodeProperty<?>>(), cloud, j.createComputerLauncher(null))); HtmlPage page = j.createWebClient().goTo("configure"); HtmlForm form = page.getFormByName("config"); ((HtmlTextInput) getElementsByNameWithoutJdk(page, "_.name").get(0)).setText("a"); HtmlFormUtil.submit(form); final Cloud newCloud = j.jenkins.clouds.get(0); assertNotSame(cloud, newCloud); assertSame(newCloud, ((EC2FleetNode) j.jenkins.getNode("mock")).getCloud()); }
Example #12
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 #13
Source File: DockerBuilderPublisher.java From docker-plugin with MIT License | 5 votes |
public ListBoxModel doFillCloudItems() { ListBoxModel model = new ListBoxModel(); model.add("Cloud this build is running on", ""); for (Cloud cloud : DockerCloud.instances()) { model.add(cloud.name); } return model; }
Example #14
Source File: DockerNodeStepExecution.java From docker-plugin with MIT License | 5 votes |
private static DockerAPI defaultApi() { for (Cloud cloud : Jenkins.getInstance().clouds) { if (cloud instanceof DockerCloud) { return ((DockerCloud) cloud).getDockerApi(); } } throw new IllegalStateException("Must either specify dockerHost/credentialsId, or define at least one Docker cloud"); }
Example #15
Source File: DockerBuilderControlOption.java From docker-plugin with MIT License | 5 votes |
public ListBoxModel doFillCloudNameItems() { ListBoxModel model = new ListBoxModel(); model.add("Cloud this build is running on", ""); for (Cloud cloud : DockerCloud.instances()) { model.add(cloud.name); } return model; }
Example #16
Source File: JenkinsUtils.java From docker-plugin with MIT License | 5 votes |
/** * Get the list of Docker servers. * * @return the list as a LinkedList of DockerCloud */ @Restricted(NoExternalUse.class) public static synchronized Collection<DockerCloud> getServers() { Collection clouds = Collections2.filter(Jenkins.getInstance().clouds, new Predicate<Cloud>() { @Override public boolean apply(Cloud input) { return input instanceof DockerCloud; } }); return clouds; }
Example #17
Source File: DockerJobTemplateProperty.java From docker-plugin with MIT License | 5 votes |
public ListBoxModel doFillCloudnameItems() { ListBoxModel model = new ListBoxModel(); for (Cloud cloud : DockerCloud.instances()) { model.add(cloud.name); } return model; }
Example #18
Source File: ECSTaskTemplateStepExecution.java From amazon-ecs-plugin with MIT License | 5 votes |
/** * Re-inject the dynamic template when resuming the pipeline */ @Override public void onResume() { super.onResume(); Cloud c = Jenkins.get().getCloud(cloudName); if (c == null) { throw new RuntimeException(String.format("Cloud does not exist: %s", cloudName)); } if (!(c instanceof ECSCloud)) { throw new RuntimeException(String.format("Cloud is not an ECS cloud: %s (%s)", cloudName, c.getClass().getName())); } ECSCloud ecsCloud = (ECSCloud) c; ecsCloud.addDynamicTemplate(newTemplate); }
Example #19
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 #20
Source File: ECSTaskTemplateStepExecution.java From amazon-ecs-plugin with MIT License | 5 votes |
private Cloud validateCloud(Cloud cloud) throws AbortException { if (cloud == null) { throw new AbortException(String.format( "Unable to determine cloud configuration using: Labels: [%s], inheritFrom: '%s', Cloud: '%s'", step.getLabel(), step.getInheritFrom(), cloudName )); } if (!(cloud instanceof ECSCloud)) { throw new AbortException(String.format("Cloud is not an ECS cloud: %s (%s)", cloudName, cloud.getClass().getName())); } return cloud; }
Example #21
Source File: DockerTransientNode.java From docker-plugin with MIT License | 5 votes |
public DockerCloud getCloud() { if (cloudId == null) return null; final Cloud cloud = Jenkins.getInstance().getCloud(cloudId); if (cloud == null) { throw new RuntimeException("Failed to retrieve Cloud " + cloudId); } if (!(cloud instanceof DockerCloud)) { throw new RuntimeException(cloudId + " is not a DockerCloud, it's a " + cloud.getClass().toString()); } return (DockerCloud) cloud; }
Example #22
Source File: DockerCloud.java From yet-another-docker-plugin with MIT License | 5 votes |
public static DockerCloud getCloudByName(String name) { final Cloud cloud = Jenkins.getInstance().getCloud(name); if (cloud instanceof DockerCloud) { return (DockerCloud) cloud; } if (isNull(cloud)) { throw new RuntimeException("Cloud " + name + "not found"); } return null; }
Example #23
Source File: DockerSlave.java From yet-another-docker-plugin with MIT License | 5 votes |
@Nonnull public DockerCloud getCloud() { final Cloud cloud = Jenkins.getInstance().getCloud(getCloudId()); if (cloud == null) { throw new RuntimeException("Docker template " + dockerSlaveTemplate + " has no assigned Cloud."); } if (!cloud.getClass().isAssignableFrom(DockerCloud.class)) { throw new RuntimeException("Assigned cloud is not DockerCloud"); } return (DockerCloud) cloud; }
Example #24
Source File: CloudNameDockerConnector.java From yet-another-docker-plugin with MIT License | 5 votes |
public FormValidation doCheckCloudName(@QueryParameter String cloudName) { try { final Cloud cloud = Jenkins.getInstance().getCloud(cloudName); if (cloud instanceof DockerCloud) { final DockerCloud dockerCloud = (DockerCloud) cloud; Version verResult = dockerCloud.getConnector().getClient().versionCmd().exec(); return ok(reflectionToString(verResult, MULTI_LINE_STYLE)); } else { return FormValidation.error("cloudId '" + cloudName + "' isn't DockerCloud"); } } catch (Throwable t) { return error(t, "error"); } }
Example #25
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 #26
Source File: CloudNanny.java From ec2-spot-jenkins-plugin with Apache License 2.0 | 5 votes |
/** * <h2>Exceptions</h2> * This method will be executed by {@link PeriodicWork} inside {@link java.util.concurrent.ScheduledExecutorService} * by default it stops execution if task throws exception, however {@link PeriodicWork} fix that * by catch any exception and just log it, so we safe to throw exception here. */ @Override protected void doRun() { final List<EC2FleetStatusInfo> info = new ArrayList<>(); for (final Cloud cloud : getClouds()) { if (!(cloud instanceof EC2FleetCloud)) continue; final EC2FleetCloud fleetCloud = (EC2FleetCloud) cloud; AtomicInteger recurrenceCounter = getRecurrenceCounter(fleetCloud); if (recurrenceCounter.decrementAndGet() > 0) { continue; } recurrenceCounter.set(fleetCloud.getCloudStatusIntervalSec()); try { // Update the cluster states final FleetStateStats stats = fleetCloud.update(); info.add(new EC2FleetStatusInfo( fleetCloud.getFleet(), stats.getState(), fleetCloud.getLabelString(), stats.getNumActive(), stats.getNumDesired())); } catch (Exception e) { // could bad configuration or real exception, we can't do too much here LOGGER.log(Level.INFO, String.format("Error during fleet %s stats update", fleetCloud.name), e); } } for (final Widget w : getWidgets()) { if (w instanceof EC2FleetStatusWidget) ((EC2FleetStatusWidget) w).setStatusList(info); } }
Example #27
Source File: UiIntegrationTest.java From ec2-spot-jenkins-plugin with Apache License 2.0 | 5 votes |
@Test public void shouldShowAsHiddenCloudIdAsOldId() throws IOException, SAXException { Cloud cloud = new EC2FleetCloud(null, null, null, null, null, null, null, null, null, null, false, false, 0, 0, 0, 0, false, false, false, 0, 0, false, 10, false); j.jenkins.clouds.add(cloud); HtmlPage page = j.createWebClient().goTo("configure"); assertTrue(StringUtils.isNotBlank(((HtmlTextInput) getElementsByNameWithoutJdk(page, "_.oldId").get(0)).getText())); }
Example #28
Source File: UiIntegrationTest.java From ec2-spot-jenkins-plugin with Apache License 2.0 | 5 votes |
@Test public void shouldShowInConfigurationClouds() throws IOException, SAXException { Cloud cloud = new EC2FleetCloud(null, null, null, null, null, null, null, null, null, null, false, false, 0, 0, 0, 0, false, false, false, 0, 0, false, 10, false); j.jenkins.clouds.add(cloud); HtmlPage page = j.createWebClient().goTo("configure"); assertEquals("ec2-fleet", ((HtmlTextInput) getElementsByNameWithoutJdk(page, "_.labelString").get(1)).getText()); }
Example #29
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 #30
Source File: CloudNannyTest.java From ec2-spot-jenkins-plugin with Apache License 2.0 | 5 votes |
@Test public void shouldIgnoreNonEC2FleetClouds() throws Exception { clouds.add(cloud1); Cloud nonEc2FleetCloud = mock(Cloud.class); clouds.add(nonEc2FleetCloud); widgets.add(widget2); getMockCloudNannyInstance().doRun(); verify(cloud1).update(); verifyZeroInteractions(nonEc2FleetCloud); }