use of hudson.model.labels.LabelAtom in project support-core-plugin by jenkinsci.
the class CheckFilterTest method createObjectsWithNames.
private QueueTaskFuture<FreeStyleBuild> createObjectsWithNames() throws Exception {
// For an environment variable
if (ENV_VAR != null) {
User.getOrCreateByIdOrFullName(ENV_VAR);
}
// For JVMProcessSytemMetricsContents
User.getOrCreateByIdOrFullName("kb");
User.getOrCreateByIdOrFullName("mb");
User.getOrCreateByIdOrFullName("max");
User.getOrCreateByIdOrFullName("mounted");
// ThreadDumps
User.getOrCreateByIdOrFullName("runnable");
// For SystemProperties
User.getOrCreateByIdOrFullName("encoding");
// For ConfigFileComponent --> config.xml
j.jenkins.getView("all").rename(VIEW_ALL_NEW_NAME);
j.jenkins.save();
// Create the agent agent0 for some components and wait until it's online
j.waitOnline(j.createSlave(AGENT_NAME, AGENT_NAME, new EnvVars()));
// Create a job to have something pending in the queue for the BuilQueue component
FreeStyleProject project = j.createFreeStyleProject(JOB_NAME);
// it's mandatory
project.setAssignedLabel(new LabelAtom("foo"));
// project.getBuildersList().add(new SimpleBuilder());
return project.scheduleBuild2(0);
}
use of hudson.model.labels.LabelAtom in project configuration-as-code-plugin by jenkinsci.
the class EC2CloudTest method configure_ec2_cloud.
@Test
@ConfiguredWithReadme("ec2/README.md")
public void configure_ec2_cloud() {
final AmazonEC2Cloud ec2Cloud = (AmazonEC2Cloud) Jenkins.get().getCloud("ec2-ec2");
assertNotNull(ec2Cloud);
assertTrue(ec2Cloud.isUseInstanceProfileForCredentials());
assertThat(ec2Cloud.getSshKeysCredentialsId(), is("ssh-key-credential-id"));
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.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.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"));
}
use of hudson.model.labels.LabelAtom in project configuration-as-code-plugin by jenkinsci.
the class JenkinsConfiguratorTest method shouldImportLabelAtoms.
@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);
}
use of hudson.model.labels.LabelAtom in project hudson-2.x by hudson.
the class Hudson method getLabelAtom.
/**
* Returns the label atom of the given name.
*/
public LabelAtom getLabelAtom(String name) {
if (name == null) {
return null;
}
while (true) {
Label l = labels.get(name);
if (l != null) {
return (LabelAtom) l;
}
// non-existent
LabelAtom la = new LabelAtom(name);
if (labels.putIfAbsent(name, la) == null) {
la.load();
}
}
}
use of hudson.model.labels.LabelAtom in project support-core-plugin by jenkinsci.
the class BuildQueueTest method verifyMinimumBuildQueue.
@Ignore("Unit test fails when performing a release. The queue has a race condition" + "which is resolved in 1.607+ (TODO).")
@Test
public void verifyMinimumBuildQueue() throws Exception {
// Given
QueueTaskFuture<FreeStyleBuild> build;
String assignedLabel = "foo";
FreeStyleProject p = j.createFreeStyleProject("bar");
p.setAssignedLabel(new LabelAtom(assignedLabel));
BuildQueue queue = new BuildQueue();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
// When
build = p.scheduleBuild2(0);
queue.addContents(createContainer(baos));
// Then
build.cancel(true);
List<String> output = new ArrayList<>(Arrays.asList(baos.toString().split("\n")));
assertContains(output, "1 item");
assertContains(output, p.getDisplayName());
assertContains(output, "Waiting for next available executor");
}
Aggregations