hudson.model.Node.Mode Java Examples

The following examples show how to use hudson.model.Node.Mode. 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: MesosTest.java    From configuration-as-code-plugin with MIT License 5 votes vote down vote up
@Test
@ConfiguredWithReadme("mesos/README.md")
public void configure_mesos_cloud() throws Exception {
    final MesosCloud cloud = Jenkins.get().clouds.get(MesosCloud.class);
    assertNotNull(cloud);

    assertFalse(cloud.isCheckpoint());
    assertThat(cloud.getCloudID(), is("mesos-name"));
    assertThat(cloud.getCredentialsId(), is("MESOS_CREDENTIALS"));
    assertThat(cloud.getDeclineOfferDuration(), is("600"));
    assertThat(cloud.getDescription(), is("My Mesos Cloud"));
    assertThat(cloud.getFrameworkName(), is("Jenkins Framework"));
    assertThat(cloud.getJenkinsURL(), is("https://jenkins.mesos.cloud"));
    assertThat(cloud.getMaster(), is("1.2.3.4:8000"));
    assertThat(cloud.getRole(), is("*"));
    assertThat(cloud.getSlavesUser(), is("jenkins"));
    assertThat(cloud.getSlavesUser(), is("jenkins"));

    final List<MesosSlaveInfo> slaves = cloud.getSlaveInfos();
    assertThat(slaves, hasSize(1));

    final MesosSlaveInfo slaveInfo = slaves.get(0);
    assertThat(slaveInfo.getLabelString(), is("docker"));
    assertThat(slaveInfo.getContainerInfo().getType(), is("DOCKER"));
    assertThat(slaveInfo.getContainerInfo().getDockerImage(), is("cloudbees/java-with-docker-client:latest"));
    assertThat(slaveInfo.getContainerInfo().getVolumes(), hasSize(2));
    assertThat(slaveInfo.getMinExecutors(), is(1));
    assertThat(slaveInfo.getMaxExecutors(), is(2));
    assertThat(slaveInfo.getMode(), is(Mode.NORMAL));
    assertThat(slaveInfo.getSlaveCpus(), is(0.1));
    assertThat(slaveInfo.getSlaveMem(), is(512));
    assertThat(slaveInfo.getRemoteFSRoot(), is("jenkins"));
    assertThat(slaveInfo.getJnlpArgs(), is(""));
    assertThat(slaveInfo.getSlaveAttributes().toString(), containsString("\"rack\":\"jenkins-build-agents\""));
    assertTrue(slaveInfo.isDefaultSlave());
}
 
Example #2
Source File: JenkinsReadmeDemoTest.java    From configuration-as-code-plugin with MIT License 5 votes vote down vote up
@Test
@ConfiguredWithReadme("jenkins/README.md#0")
public void configure_demo_first_code_block() throws Exception {
    final Jenkins jenkins = Jenkins.get();
    assertEquals("Jenkins configured automatically by Jenkins Configuration as Code plugin\n\n", jenkins.getSystemMessage());
    assertEquals(5, jenkins.getNumExecutors());
    assertEquals(2, jenkins.getScmCheckoutRetryCount());
    assertEquals(Mode.NORMAL, jenkins.getMode());
}
 
Example #3
Source File: HudsonTestCase.java    From jenkins-test-harness with MIT License 5 votes vote down vote up
public DumbSlave createSlave(String nodeName, String labels, EnvVars env) throws Exception {
    synchronized (jenkins) {
        DumbSlave slave = new DumbSlave(nodeName, "dummy",
				createTmpDir().getPath(), "1", Mode.NORMAL, labels==null?"":labels, createComputerLauncher(env),
       RetentionStrategy.NOOP, Collections.emptyList());
		jenkins.addNode(slave);
		return slave;
	}
}
 
Example #4
Source File: ParallelsDesktopVMSlave.java    From jenkins-parallels with MIT License 5 votes vote down vote up
@DataBoundConstructor
public ParallelsDesktopVMSlave(ParallelsDesktopVM vm, ParallelsDesktopConnectorSlaveComputer connector)
		throws IOException, Descriptor.FormException
{
	super(vm.getSlaveName(), "", vm.getRemoteFS(), 1, Mode.NORMAL, vm.getLabels(), vm.getLauncher(),
			new ParallelsDesktopCloudRetentionStrategy(), new ArrayList<NodeProperty<?>>());
	this.connector = connector;
	this.vm = vm;
}
 
Example #5
Source File: ParallelsDesktopConnectorSlave.java    From jenkins-parallels with MIT License 5 votes vote down vote up
@DataBoundConstructor
public ParallelsDesktopConnectorSlave(ParallelsDesktopCloud owner, String name, String remoteFS, 
		ComputerLauncher launcher, boolean useAsBuilder)
		throws IOException, Descriptor.FormException
{
	super(name, "", remoteFS, 1, Mode.NORMAL, "", launcher,
			useAsBuilder ? new RetentionStrategy.Always() : new RetentionStrategy.Demand(1, 1),
			new ArrayList<NodeProperty<?>>());
	this.owner = owner;
	this.useAsBuilder = useAsBuilder;
}
 
Example #6
Source File: JenkinsDemoTest.java    From configuration-as-code-plugin with MIT License 4 votes vote down vote up
@Test
@ConfiguredWithCode("jenkins/jenkins.yaml")
public void configure_demo_yaml() throws Exception {
    final Jenkins jenkins = Jenkins.get();
    assertEquals("Jenkins configured automatically by Jenkins Configuration as Code plugin\n\n", jenkins.getSystemMessage());
    assertEquals(5, jenkins.getNumExecutors());
    assertEquals(2, jenkins.getScmCheckoutRetryCount());
    assertEquals(Mode.NORMAL, jenkins.getMode());
    assertEquals("https://ci.example.com/", jenkins.getRootUrl());

    final FullControlOnceLoggedInAuthorizationStrategy strategy = (FullControlOnceLoggedInAuthorizationStrategy) jenkins.getAuthorizationStrategy();
    assertFalse(strategy.isAllowAnonymousRead());

    final DockerCloud docker = DockerCloud.getCloudByName("docker");
    assertNotNull(docker);
    assertNotNull(docker.getDockerApi());
    assertNotNull(docker.getDockerApi().getDockerHost());
    assertEquals("unix:///var/run/docker.sock", docker.getDockerApi().getDockerHost().getUri());

    final GitTool.DescriptorImpl gitTool = (GitTool.DescriptorImpl) jenkins.getDescriptor(GitTool.class);
    assertEquals(1, gitTool.getInstallations().length);

    assertEquals(1, GlobalLibraries.get().getLibraries().size());
    final LibraryConfiguration library = GlobalLibraries.get().getLibraries().get(0);
    assertEquals("awesome-lib", library.getName());

    final Mailer.DescriptorImpl descriptor = (Mailer.DescriptorImpl) jenkins.getDescriptor(Mailer.class);
    assertEquals("4441", descriptor.getSmtpPort());
    assertEquals("[email protected]", descriptor.getReplyToAddress());
    assertEquals("smtp.acme.org", descriptor.getSmtpHost() );

    final ArtifactoryBuilder.DescriptorImpl artifactory = (ArtifactoryBuilder.DescriptorImpl) jenkins.getDescriptor(ArtifactoryBuilder.class);
    assertTrue(artifactory.getUseCredentialsPlugin());

    final List<ArtifactoryServer> actifactoryServers = artifactory.getArtifactoryServers();
    assertThat(actifactoryServers, hasSize(1));
    assertThat(actifactoryServers.get(0).getName(), is(equalTo("artifactory")));
    assertThat(actifactoryServers.get(0).getUrl(), is(equalTo("http://acme.com/artifactory")));
    assertThat(actifactoryServers.get(0).getResolverCredentialsConfig().getUsername(), is(equalTo("artifactory_user")));
    assertThat(actifactoryServers.get(0).getResolverCredentialsConfig().getPassword(), is(equalTo("password123")));
}
 
Example #7
Source File: KubernetesCloudTest.java    From configuration-as-code-plugin with MIT License 4 votes vote down vote up
@Test
@ConfiguredWithReadme("kubernetes/README.md")
public void configure_kubernetes_cloud() throws Exception {
    final KubernetesCloud cloud = j.jenkins.clouds.get(KubernetesCloud.class);
    assertNotNull(cloud);
    assertEquals("advanced-k8s-config", cloud.name);
    assertEquals("https://avanced-k8s-config:443", cloud.getServerUrl());
    assertEquals("serverCertificate", cloud.getServerCertificate());
    assertTrue(cloud.isSkipTlsVerify());
    assertEquals("default", cloud.getNamespace());
    assertEquals("http://jenkins/", cloud.getJenkinsUrl());
    assertEquals("advanced-k8s-credentials", cloud.getCredentialsId());
    assertEquals("jenkinsTunnel", cloud.getJenkinsTunnel());
    assertEquals(42, cloud.getContainerCap());
    assertEquals(5, cloud.getRetentionTimeout());
    assertEquals(10, cloud.getConnectTimeout());
    assertEquals(20, cloud.getReadTimeout());
    assertEquals("64", cloud.getMaxRequestsPerHostStr());

    final List<PodTemplate> templates = cloud.getTemplates();
    assertEquals(2, templates.size());
    final PodTemplate template = templates.get(0);
    assertEquals("test", template.getName());
    assertEquals("serviceAccount", template.getServiceAccount());
    assertEquals(1234, template.getInstanceCap());
    assertEquals("label", template.getLabel());

    final List<PodVolume> volumes = template.getVolumes();
    assertEquals(1, volumes.size());
    final PodVolume volume = volumes.get(0);
    assertTrue(volume instanceof HostPathVolume);
    assertEquals("mountPath", volume.getMountPath());
    assertEquals("hostPath", ((HostPathVolume)volume).getHostPath());

    final List<TemplateEnvVar> envVars = template.getEnvVars();
    assertEquals(1, envVars.size());
    final KeyValueEnvVar envVar = (KeyValueEnvVar) envVars.get(0);
    assertEquals("FOO", envVar.getKey());
    assertEquals("BAR", envVar.getValue());

    final PodTemplate template1 = templates.get(1);
    assertEquals("k8s-slave", template1.getName());
    assertEquals("default", template1.getNamespace());
    assertEquals(Mode.EXCLUSIVE, template1.getNodeUsageMode());
}
 
Example #8
Source File: ParallelsDesktopConnectorSlave.java    From jenkins-parallels with MIT License 4 votes vote down vote up
@Override
public Node.Mode getMode()
{
	return useAsBuilder ? Node.Mode.NORMAL : Node.Mode.EXCLUSIVE;
}