Java Code Examples for hudson.model.labels.LabelAtom

The following examples show how to use hudson.model.labels.LabelAtom. These examples are extracted from open source projects. 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 Project: yet-another-docker-plugin   Source File: FreestyleTest.java    License: MIT License 6 votes vote down vote up
@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 Project: amazon-ecs-plugin   Source File: ECSCloudTest.java    License: MIT License 6 votes vote down vote up
@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 Project: amazon-ecs-plugin   Source File: ECSCloudTest.java    License: MIT License 6 votes vote down vote up
@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 Project: warnings-ng-plugin   Source File: IntegrationTest.java    License: MIT License 5 votes vote down vote up
/**
 * 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 5
Source Project: remoting-kafka-plugin   Source File: KafkaKubernetesCloudTest.java    License: MIT License 5 votes vote down vote up
@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 6
Source Project: remoting-kafka-plugin   Source File: KafkaKubernetesCloudTest.java    License: MIT License 5 votes vote down vote up
@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 7
Source Project: remoting-kafka-plugin   Source File: KafkaKubernetesCloudTest.java    License: MIT License 5 votes vote down vote up
@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 8
@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 9
@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 10
Source Project: jenkins-nomad   Source File: NomadCloudTest.java    License: MIT License 5 votes vote down vote up
@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 11
Source Project: ec2-spot-jenkins-plugin   Source File: IntegrationTest.java    License: Apache License 2.0 5 votes vote down vote up
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 12
Source Project: ec2-spot-jenkins-plugin   Source File: EC2FleetCloudTest.java    License: Apache License 2.0 5 votes vote down vote up
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 13
Source Project: docker-swarm-plugin   Source File: DockerSwarmAgent.java    License: MIT License 4 votes vote down vote up
@Override
public Set<LabelAtom> getAssignedLabels() {
    final TreeSet<LabelAtom> labels = new TreeSet<>();
    labels.add(new LabelAtom(getLabelString()));
    return labels;
}
 
Example 14
Source Project: remoting-kafka-plugin   Source File: KafkaKubernetesCloud.java    License: MIT License 4 votes vote down vote up
public Set<LabelAtom> getLabelSet() {
    return Label.parse(label);
}
 
Example 15
Source Project: remoting-kafka-plugin   Source File: KafkaKubernetesCloudTest.java    License: MIT License 4 votes vote down vote up
@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 16
@Override
public Class<LabelAtom> getTarget() {
    return LabelAtom.class;
}
 
Example 17
@Override
protected LabelAtom instance(Mapping mapping, ConfigurationContext context) throws ConfiguratorException {
    return new LabelAtom(mapping.getScalarValue("name"));
}
 
Example 18
Source Project: configuration-as-code-plugin   Source File: JenkinsConfigurator.java    License: MIT License 4 votes vote down vote up
@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 19
Source Project: configuration-as-code-plugin   Source File: EC2CloudTest.java    License: MIT License 4 votes vote down vote up
@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 20
Source Project: jenkins-nomad   Source File: NomadSlaveTemplate.java    License: MIT License 4 votes vote down vote up
public Set<LabelAtom> getLabelSet() {
    return labelSet;
}
 
Example 21
@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 = {[email protected]}  size = 2
        0 = {[email protected]}
        safeParameters = {[email protected]}  size = 0
        parameters = {[email protected]}  size = 1
        0 = {[email protected]} "(StringParameterValue) number='1'"
        value = "1"
        name = "number"
        description = ""
        parameterDefinitionNames = {[email protected]}  size = 1
        0 = "number"
        build = null
        run = {[email protected]} "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 22
Source Project: kubernetes-plugin   Source File: PodTemplate.java    License: Apache License 2.0 4 votes vote down vote up
public Set<LabelAtom> getLabelSet() {
    return Label.parse(label);
}
 
Example 23
Source Project: yet-another-docker-plugin   Source File: DockerSlaveTemplate.java    License: MIT License 4 votes vote down vote up
@Nonnull
public Set<LabelAtom> getLabelSet() {
    return labelSet != null ? labelSet : Collections.emptySet();
}
 
Example 24
Source Project: amazon-ecs-plugin   Source File: ECSTaskTemplate.java    License: MIT License 4 votes vote down vote up
public Set<LabelAtom> getLabelSet() {
    return Label.parse(label);
}
 
Example 25
Source Project: docker-plugin   Source File: DockerQueueListener.java    License: MIT License 4 votes vote down vote up
@Override
public Label getAssignedLabel(@Nonnull SubTask task) {
    return new LabelAtom(uuid);
}
 
Example 26
Source Project: docker-plugin   Source File: DockerTemplate.java    License: MIT License 4 votes vote down vote up
@Nonnull
public Set<LabelAtom> getLabelSet() {
    return labelSet;
}