hudson.model.labels.LabelAtom Java Examples
The following examples show how to use
hudson.model.labels.LabelAtom.
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: FreestyleTest.java From yet-another-docker-plugin with MIT License | 6 votes |
@Override public Boolean call() throws Throwable { final Jenkins jenkins = Jenkins.getInstance(); // prepare job final FreeStyleProject project = jenkins.createProject(FreeStyleProject.class, "freestyle-project"); final Shell env = new Shell("env"); project.getBuildersList().add(env); project.setAssignedLabel(new LabelAtom(DOCKER_CLOUD_LABEL)); project.save(); LOG.trace("trace test."); project.scheduleBuild(new TestCause()); // image pull may take time waitUntilNoActivityUpTo(jenkins, 10 * 60 * 1000); final FreeStyleBuild lastBuild = project.getLastBuild(); assertThat(lastBuild, not(nullValue())); assertThat(lastBuild.getResult(), is(Result.SUCCESS)); assertThat(getLog(lastBuild), Matchers.containsString(TEST_VALUE)); assertThat(getLog(lastBuild), Matchers.containsString(CLOUD_ID + "=" + DOCKER_CLOUD_NAME)); return true; }
Example #2
Source File: ECSCloudTest.java From amazon-ecs-plugin with MIT License | 6 votes |
@Test public void provision_oneagent() throws Exception { List<ECSTaskTemplate> templates = new ArrayList<>(); templates.add(getTaskTemplate("my-template","label")); ECSCloud sut = new ECSCloud("mycloud", "", "mycluster"); sut.setTemplates(templates); sut.setRegionName("eu-west-1"); sut.setJenkinsUrl("http://jenkins.local"); sut.setSlaveTimeoutInSeconds(5); sut.setRetentionTimeout(5); Collection<PlannedNode> plannedNodes = sut.provision(new LabelAtom("label"), 1); Assert.assertEquals(1, plannedNodes.size()); }
Example #3
Source File: ECSCloudTest.java From amazon-ecs-plugin with MIT License | 6 votes |
@Test public void canProvision_unknownLabel_returnsFalse() throws Exception { List<ECSTaskTemplate> templates = new ArrayList<>(); ECSCloud sut = new ECSCloud("mycloud", "", "mycluster"); sut.setTemplates(templates); sut.setRegionName("eu-west-1"); sut.setJenkinsUrl("http://jenkins.local"); sut.setSlaveTimeoutInSeconds(5); sut.setRetentionTimeout(5); boolean canProvision = sut.canProvision(new LabelAtom("unknownLabel")); Assert.assertFalse(canProvision); }
Example #4
Source File: LabelAtomConfigurator.java From configuration-as-code-plugin with MIT License | 5 votes |
@NonNull @Override public Set<Attribute<LabelAtom, ?>> describe() { return new HashSet<>(Arrays.asList( new Attribute<LabelAtom, String>("name", String.class) .getter(Label::getName), new MultivaluedAttribute<LabelAtom, LabelAtomProperty>("properties", LabelAtomProperty.class) .getter(labelAtom -> labelAtom.getProperties()) .setter((labelAtom, properties) -> labelAtom.getProperties().addAll(properties)) )); }
Example #5
Source File: EC2FleetCloudTest.java From ec2-spot-jenkins-plugin with Apache License 2.0 | 5 votes |
private void mockNodeCreatingPart() { when(jenkins.getNodesObject()).thenReturn(mock(Nodes.class)); ExtensionList labelFinder = mock(ExtensionList.class); when(labelFinder.iterator()).thenReturn(Collections.emptyIterator()); PowerMockito.when(LabelFinder.all()).thenReturn(labelFinder); // mocking part of node creation process Jenkins.getInstance().getLabelAtom(l) when(jenkins.getLabelAtom(anyString())).thenReturn(new LabelAtom("mock-label")); }
Example #6
Source File: IntegrationTest.java From ec2-spot-jenkins-plugin with Apache License 2.0 | 5 votes |
protected List<QueueTaskFuture> getQueueTaskFutures(int count) throws IOException { final LabelAtom label = new LabelAtom("momo"); final List<QueueTaskFuture> rs = new ArrayList<>(); for (int i = 0; i < count; i++) { final FreeStyleProject project = j.createFreeStyleProject(); project.setAssignedLabel(label); project.getBuildersList().add(Functions.isWindows() ? new BatchFile("Ping -n " + JOB_SLEEP_TIME + " 127.0.0.1 > nul") : new Shell("sleep " + JOB_SLEEP_TIME)); rs.add(project.scheduleBuild2(0)); } return rs; }
Example #7
Source File: NomadCloudTest.java From jenkins-nomad with MIT License | 5 votes |
@Before public void setup() { Set<LabelAtom> labels = Collections.singleton(label); Mockito.when(label.matches(Mockito.anyCollectionOf(LabelAtom.class))).thenReturn(true); Mockito.when(slaveTemplate.createSlaveName()).thenReturn("slave-1", "slave-2", "slave-3"); Mockito.when(slaveTemplate.getNumExecutors()).thenReturn(1); Mockito.when(slaveTemplate.getLabelSet()).thenReturn(labels); }
Example #8
Source File: JenkinsConfiguratorTest.java From configuration-as-code-plugin with MIT License | 5 votes |
@Test @ConfiguredWithCode("ConfigureLabels.yml") public void shouldImportLabelAtoms() { LabelAtom label1 = Jenkins.get().getLabelAtom("label1"); assertNotNull(label1); assertThat(label1.getProperties(), hasSize(2)); assertEquals(2, label1.getProperties().get(TestProperty.class).value); assertEquals(4, label1.getProperties().get(AnotherTestProperty.class).otherProperty); LabelAtom label2 = Jenkins.get().getLabelAtom("label2"); assertNotNull(label2); assertThat(label2.getProperties(), hasSize(1)); assertEquals(3, label2.getProperties().get(TestProperty.class).value); }
Example #9
Source File: KafkaKubernetesCloudTest.java From remoting-kafka-plugin with MIT License | 5 votes |
@Test public void testCanProvisionMultipleLabels() { KafkaKubernetesCloud cloud = new KafkaKubernetesCloud("kafka-kubernetes"); cloud.setLabel("label1 label2"); assertThat(cloud.canProvision(new LabelAtom("label1")), is(true)); assertThat(cloud.canProvision(new LabelAtom("label3")), is(false)); }
Example #10
Source File: KafkaKubernetesCloudTest.java From remoting-kafka-plugin with MIT License | 5 votes |
@Test public void testCanProvisionSingleLabel() { KafkaKubernetesCloud cloud = new KafkaKubernetesCloud("kafka-kubernetes"); cloud.setLabel("test"); assertThat(cloud.canProvision(null), is(false)); assertThat(cloud.canProvision(new LabelAtom("test")), is(true)); assertThat(cloud.canProvision(new LabelAtom("wrong")), is(false)); }
Example #11
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 #12
Source File: IntegrationTest.java From warnings-ng-plugin with MIT License | 5 votes |
/** * Creates an {@link DumbSlave agent} with the specified label. * * @param label * the label of the agent * * @return the agent */ @SuppressWarnings("illegalcatch") protected Slave createAgent(final String label) { try { return getJenkins().createOnlineSlave(new LabelAtom(label)); } catch (Exception e) { throw new AssertionError(e); } }
Example #13
Source File: DockerTemplate.java From docker-plugin with MIT License | 4 votes |
@Nonnull public Set<LabelAtom> getLabelSet() { return labelSet; }
Example #14
Source File: ECSTaskTemplate.java From amazon-ecs-plugin with MIT License | 4 votes |
public Set<LabelAtom> getLabelSet() { return Label.parse(label); }
Example #15
Source File: DockerSlaveTemplate.java From yet-another-docker-plugin with MIT License | 4 votes |
@Nonnull public Set<LabelAtom> getLabelSet() { return labelSet != null ? labelSet : Collections.emptySet(); }
Example #16
Source File: DockerQueueListener.java From docker-plugin with MIT License | 4 votes |
@Override public Label getAssignedLabel(@Nonnull SubTask task) { return new LabelAtom(uuid); }
Example #17
Source File: DockerSwarmAgent.java From docker-swarm-plugin with MIT License | 4 votes |
@Override public Set<LabelAtom> getAssignedLabels() { final TreeSet<LabelAtom> labels = new TreeSet<>(); labels.add(new LabelAtom(getLabelString())); return labels; }
Example #18
Source File: PodTemplate.java From kubernetes-plugin with Apache License 2.0 | 4 votes |
public Set<LabelAtom> getLabelSet() { return Label.parse(label); }
Example #19
Source File: AutoResubmitIntegrationTest.java From ec2-spot-jenkins-plugin with Apache License 2.0 | 4 votes |
@Test public void should_successfully_resubmit_parametrized_task() throws Exception { EC2FleetCloud cloud = new EC2FleetCloud(null, null, "credId", null, "region", null, "fId", "momo", null, new LocalComputerConnector(j), false, false, 0, 0, 10, 1, false, false, false, 0, 0, false, 10, false); j.jenkins.clouds.add(cloud); List<QueueTaskFuture> rs = new ArrayList<>(); final FreeStyleProject project = j.createFreeStyleProject(); project.setAssignedLabel(new LabelAtom("momo")); project.addProperty(new ParametersDefinitionProperty(new StringParameterDefinition("number", "opa"))); /* example of actions for project actions = {CopyOnWriteArrayList@14845} size = 2 0 = {ParametersAction@14853} safeParameters = {TreeSet@14855} size = 0 parameters = {ArrayList@14856} size = 1 0 = {StringParameterValue@14862} "(StringParameterValue) number='1'" value = "1" name = "number" description = "" parameterDefinitionNames = {ArrayList@14857} size = 1 0 = "number" build = null run = {FreeStyleBuild@14834} "parameter #14" */ project.getBuildersList().add(Functions.isWindows() ? new BatchFile("Ping -n %number% 127.0.0.1 > nul") : new Shell("sleep ${number}")); rs.add(project.scheduleBuild2(0, new ParametersAction(new StringParameterValue("number", "30")))); System.out.println("check if zero nodes!"); Assert.assertEquals(0, j.jenkins.getNodes().size()); assertAtLeastOneNode(); final Node node = j.jenkins.getNodes().get(0); assertQueueIsEmpty(); System.out.println("disconnect node"); node.toComputer().disconnect(new OfflineCause.ChannelTermination(new UnsupportedOperationException("Test"))); assertLastBuildResult(Result.FAILURE, Result.ABORTED); node.toComputer().connect(true); assertNodeIsOnline(node); assertQueueAndNodesIdle(node); Assert.assertEquals(1, j.jenkins.getProjects().size()); Assert.assertEquals(Result.SUCCESS, j.jenkins.getProjects().get(0).getLastBuild().getResult()); Assert.assertEquals(2, j.jenkins.getProjects().get(0).getBuilds().size()); cancelTasks(rs); }
Example #20
Source File: NomadSlaveTemplate.java From jenkins-nomad with MIT License | 4 votes |
public Set<LabelAtom> getLabelSet() { return labelSet; }
Example #21
Source File: EC2CloudTest.java From configuration-as-code-plugin with MIT License | 4 votes |
@Test @ConfiguredWithReadme("ec2/README.md") public void configure_ec2_cloud() throws Exception { final AmazonEC2Cloud ec2Cloud = (AmazonEC2Cloud) Jenkins.get().getCloud("ec2-ec2"); assertNotNull(ec2Cloud); assertTrue(ec2Cloud.isUseInstanceProfileForCredentials()); assertThat(ec2Cloud.getPrivateKey().getPrivateKey(), is("ADMIN123")); final List<SlaveTemplate> templates = ec2Cloud.getTemplates(); assertThat(templates, hasSize(2)); SlaveTemplate slaveTemplate = templates.get(0); assertThat(slaveTemplate.getDisplayName(), containsString("Auto configured EC2 Agent Small")); assertFalse(slaveTemplate.getAssociatePublicIp()); assertFalse(slaveTemplate.isConnectBySSHProcess()); assertFalse(slaveTemplate.deleteRootOnTermination); assertFalse(slaveTemplate.ebsOptimized); assertFalse(slaveTemplate.monitoring); assertFalse(slaveTemplate.stopOnTerminate); assertFalse(slaveTemplate.getUseDedicatedTenancy()); assertFalse(slaveTemplate.useEphemeralDevices); assertThat(slaveTemplate.type, is(InstanceType.T2Small)); assertThat(slaveTemplate.getAmi(), equalTo("ami-0c6bb742864ffa3f3")); assertThat(slaveTemplate.getLabelString(), containsString("Small")); assertThat(slaveTemplate.getLabelSet(), is(notNullValue())); assertThat(slaveTemplate.remoteFS, equalTo("/home/ec2-user")); assertThat(slaveTemplate.getRemoteAdmin(), equalTo("ec2-user")); assertThat(slaveTemplate.zone, equalTo("us-east-1")); assertThat(slaveTemplate.getSecurityGroupString(), equalTo("some-group")); // fails here without mode specified assertTrue(ec2Cloud.canProvision(new LabelAtom("Small"))); // Checks that the AMI type is Unix and configured AMITypeData amiType = slaveTemplate.getAmiType(); assertTrue(amiType.isUnix()); assertTrue(amiType instanceof UnixData); UnixData unixData = (UnixData) amiType; assertThat(unixData.getRootCommandPrefix(), equalTo("sudo")); assertThat(unixData.getSlaveCommandPrefix(), equalTo("sudo -u jenkins")); assertThat(unixData.getSshPort(), equalTo("61120")); slaveTemplate = templates.get(1); assertThat(slaveTemplate.getDisplayName(), containsString("Auto configured EC2 Agent Large")); assertFalse(slaveTemplate.getAssociatePublicIp()); assertFalse(slaveTemplate.isConnectBySSHProcess()); assertFalse(slaveTemplate.deleteRootOnTermination); assertFalse(slaveTemplate.ebsOptimized); assertFalse(slaveTemplate.monitoring); assertFalse(slaveTemplate.stopOnTerminate); assertFalse(slaveTemplate.getUseDedicatedTenancy()); assertFalse(slaveTemplate.useEphemeralDevices); assertThat(slaveTemplate.type, is(InstanceType.T2Xlarge)); assertThat(slaveTemplate.getAmi(), equalTo("ami-0c6bb742864ffa3f3")); assertThat(slaveTemplate.getLabelString(), containsString("Large")); assertThat(slaveTemplate.getLabelSet(), is(notNullValue())); assertThat(slaveTemplate.remoteFS, equalTo("/home/ec2-user")); assertThat(slaveTemplate.getRemoteAdmin(), equalTo("ec2-user")); assertThat(slaveTemplate.zone, equalTo("us-east-1")); assertThat(slaveTemplate.getSecurityGroupString(), equalTo("some-group")); // fails here without mode specified assertTrue(ec2Cloud.canProvision(new LabelAtom("Large"))); // Checks that the AMI type is Unix and configured amiType = slaveTemplate.getAmiType(); assertTrue(amiType.isUnix()); assertTrue(amiType instanceof UnixData); unixData = (UnixData) amiType; assertThat(unixData.getRootCommandPrefix(), equalTo("sudo")); assertThat(unixData.getSlaveCommandPrefix(), equalTo("sudo -u jenkins")); assertThat(unixData.getSshPort(), equalTo("61120")); }
Example #22
Source File: JenkinsConfigurator.java From configuration-as-code-plugin with MIT License | 4 votes |
@NonNull @Override public Set<Attribute<Jenkins,?>> describe() { final Set<Attribute<Jenkins,?>> attributes = super.describe(); // Add remoting security, all legwork will be done by a configurator attributes.add(new Attribute<Jenkins, AdminWhitelistRule>("remotingSecurity", AdminWhitelistRule.class) .getter( j -> j.getInjector().getInstance(AdminWhitelistRule.class) ) .setter( noop() )); // Override "nodes" getter so we don't export Nodes registered by Cloud plugins Attribute.<Jenkins, List<Node>>get(attributes, "nodes").ifPresent(attribute -> attribute .getter(jenkins -> jenkins.getNodes().stream() .filter(node -> !isCloudNode(node)) .collect(Collectors.toList())) .setter((jenkins, configuredNodes) -> { List<String> configuredNodesNames = configuredNodes.stream() .map(Node::getNodeName) .collect(Collectors.toList()); List<Node> nodesToKeep = jenkins.getNodes().stream() .filter(node -> !configuredNodesNames.contains(node.getNodeName())) .filter(this::isCloudNode) .collect(Collectors.toList()); nodesToKeep.addAll(configuredNodes); jenkins.setNodes(nodesToKeep); }) ); // Add updateCenter, all legwork will be done by a configurator attributes.add(new Attribute<Jenkins, UpdateCenter>("updateCenter", UpdateCenter.class) .getter(Jenkins::getUpdateCenter) .setter( noop() )); attributes.add(new MultivaluedAttribute<Jenkins, LabelAtom>("labelAtoms", LabelAtom.class) .getter(jenkins -> jenkins.getLabelAtoms()) .setter((jenkins, labelAtoms) -> { for (LabelAtom labelAtom : labelAtoms) { // Get or create a LabelAtom instance LabelAtom atom = jenkins.getLabelAtom(labelAtom.getName()); if (atom != null) { atom.getProperties().clear(); atom.getProperties().addAll(labelAtom.getProperties()); } } }) ); attributes.add(new Attribute<Jenkins, ProxyConfiguration>("proxy", ProxyConfiguration.class) .getter( j -> j.proxy) .setter((o, v) -> o.proxy = v)); return attributes; }
Example #23
Source File: LabelAtomConfigurator.java From configuration-as-code-plugin with MIT License | 4 votes |
@Override protected LabelAtom instance(Mapping mapping, ConfigurationContext context) throws ConfiguratorException { return new LabelAtom(mapping.getScalarValue("name")); }
Example #24
Source File: LabelAtomConfigurator.java From configuration-as-code-plugin with MIT License | 4 votes |
@Override public Class<LabelAtom> getTarget() { return LabelAtom.class; }
Example #25
Source File: KafkaKubernetesCloudTest.java From remoting-kafka-plugin with MIT License | 4 votes |
@Test public void testProvisionWorkloadSize() { KafkaKubernetesCloud cloud = new KafkaKubernetesCloud("kafka-kubernetes"); Collection<NodeProvisioner.PlannedNode> nodes = cloud.provision(new LabelAtom("test"), 200); assertThat(nodes, hasSize(200)); }
Example #26
Source File: KafkaKubernetesCloud.java From remoting-kafka-plugin with MIT License | 4 votes |
public Set<LabelAtom> getLabelSet() { return Label.parse(label); }