Java Code Examples for hudson.model.Node#Mode

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: PrimitiveConfiguratorTest.java    From configuration-as-code-plugin with MIT License 5 votes vote down vote up
@Test
public void _enum() throws Exception {
    // Jenkins do register a StaplerConverter for it.
    Configurator<Node.Mode> c = registry.lookupOrFail(Node.Mode.class);
    final Node.Mode value = c.configure(new Scalar("NORMAL"), context);
    assertEquals(Node.Mode.NORMAL, value);

}
 
Example 2
Source File: KafkaKubernetesCloud.java    From remoting-kafka-plugin with MIT License 4 votes vote down vote up
public Node.Mode getNodeUsageMode() {
    return nodeUsageMode;
}
 
Example 3
Source File: KafkaKubernetesCloud.java    From remoting-kafka-plugin with MIT License 4 votes vote down vote up
@DataBoundSetter
public void setNodeUsageMode(Node.Mode nodeUsageMode) {
    this.nodeUsageMode = nodeUsageMode;
}
 
Example 4
Source File: EC2FleetCloud.java    From ec2-spot-jenkins-plugin with Apache License 2.0 4 votes vote down vote up
/**
 * https://github.com/jenkinsci/ec2-plugin/blob/master/src/main/java/hudson/plugins/ec2/EC2Cloud.java#L640
 *
 * @param ec2      ec2 client
 * @param instance instance
 */
private void addNewSlave(final AmazonEC2 ec2, final Instance instance, FleetStateStats stats) throws Exception {
    final String instanceId = instance.getInstanceId();

    // instance state check enabled and not running, skip adding
    if (addNodeOnlyIfRunning && InstanceStateName.Running != InstanceStateName.fromValue(instance.getState().getName()))
        return;

    final String address = privateIpUsed ? instance.getPrivateIpAddress() : instance.getPublicIpAddress();
    // Check if we have the address to use. Nodes don't get it immediately.
    if (address == null) {
        if (!privateIpUsed) {
            info("%s instance public IP address not assigned, it could take some time or" +
                    " Spot Request is not configured to assign public IPs", instance.getInstanceId());
        }
        return; // wait more time, probably IP address not yet assigned
    }

    // Generate a random FS root if one isn't specified
    final String effectiveFsRoot;
    if (StringUtils.isBlank(fsRoot)) {
        effectiveFsRoot = "/tmp/jenkins-" + UUID.randomUUID().toString().substring(0, 8);
    } else {
        effectiveFsRoot = fsRoot;
    }

    final Double instanceTypeWeight = stats.getInstanceTypeWeights().get(instance.getInstanceType());
    final int effectiveNumExecutors;
    if (scaleExecutorsByWeight && instanceTypeWeight != null) {
        effectiveNumExecutors = (int) Math.max(Math.round(numExecutors * instanceTypeWeight), 1);
    } else {
        effectiveNumExecutors = numExecutors;
    }

    final EC2FleetAutoResubmitComputerLauncher computerLauncher = new EC2FleetAutoResubmitComputerLauncher(
            computerConnector.launch(address, TaskListener.NULL));
    final Node.Mode nodeMode = restrictUsage ? Node.Mode.EXCLUSIVE : Node.Mode.NORMAL;
    final EC2FleetNode node = new EC2FleetNode(instanceId, "Fleet slave for " + instanceId,
            effectiveFsRoot, effectiveNumExecutors, nodeMode, labelString, new ArrayList<NodeProperty<?>>(),
            this, computerLauncher);

    // Initialize our retention strategy
    node.setRetentionStrategy(new IdleRetentionStrategy());

    final Jenkins jenkins = Jenkins.getInstance();
    // jenkins automatically remove old node with same name if any
    jenkins.addNode(node);

    final SettableFuture<Node> future;
    if (plannedNodesCache.isEmpty()) {
        future = SettableFuture.create();
    } else {
        final NodeProvisioner.PlannedNode plannedNode = plannedNodesCache.iterator().next();
        plannedNodesCache.remove(plannedNode);
        future = ((SettableFuture<Node>) plannedNode.future);
    }

    // use getters for timeout and interval as they provide default value
    // when user just install new version and did't recreate fleet
    EC2FleetOnlineChecker.start(node, future,
            TimeUnit.SECONDS.toMillis(getInitOnlineTimeoutSec()),
            TimeUnit.SECONDS.toMillis(getInitOnlineCheckIntervalSec()));
}
 
Example 5
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;
}
 
Example 6
Source File: PodTemplateUtils.java    From kubernetes-plugin with Apache License 2.0 4 votes vote down vote up
/**
 * Combines a {@link PodTemplate} with its parent.
 * @param parent        The parent container template (nullable).
 * @param template      The actual container template
 * @return              The combined container template.
 */
public static PodTemplate combine(PodTemplate parent, PodTemplate template) {
    Preconditions.checkNotNull(template, "Pod template should not be null");
    if (parent == null) {
        return template;
    }

    LOGGER.log(Level.FINEST, "Combining pod templates, parent: {0}", parent);
    LOGGER.log(Level.FINEST, "Combining pod templates, template: {0}", template);

    String name = template.getName();
    String label = template.getLabel();
    String nodeSelector = Strings.isNullOrEmpty(template.getNodeSelector()) ? parent.getNodeSelector() : template.getNodeSelector();
    String serviceAccount = Strings.isNullOrEmpty(template.getServiceAccount()) ? parent.getServiceAccount() : template.getServiceAccount();
    Node.Mode nodeUsageMode = template.getNodeUsageMode() == null ? parent.getNodeUsageMode() : template.getNodeUsageMode();

    Set<PodAnnotation> podAnnotations = new LinkedHashSet<>();
    podAnnotations.addAll(template.getAnnotations());
    podAnnotations.addAll(parent.getAnnotations());

    Set<PodImagePullSecret> imagePullSecrets = new LinkedHashSet<>();
    imagePullSecrets.addAll(parent.getImagePullSecrets());
    imagePullSecrets.addAll(template.getImagePullSecrets());

    Map<String, ContainerTemplate> combinedContainers = new HashMap<>();
    Map<String, PodVolume> combinedVolumes = new HashMap<>();

    //Containers
    Map<String, ContainerTemplate> parentContainers = parent.getContainers().stream().collect(toMap(c -> c.getName(), c -> c));
    combinedContainers.putAll(parentContainers);
    combinedContainers.putAll(template.getContainers().stream().collect(toMap(c -> c.getName(), c -> combine(parentContainers.get(c.getName()), c))));

    //Volumes
    Map<String, PodVolume> parentVolumes = parent.getVolumes().stream().collect(toMap(v -> v.getMountPath(), v -> v));
    combinedVolumes.putAll(parentVolumes);
    combinedVolumes.putAll(template.getVolumes().stream().collect(toMap(v -> v.getMountPath(), v -> v)));

    WorkspaceVolume workspaceVolume = WorkspaceVolume.merge(parent.getWorkspaceVolume(), template.getWorkspaceVolume());

    //Tool location node properties
    PodTemplateToolLocation toolLocationNodeProperties = parent.getNodeProperties();
    toolLocationNodeProperties.addAll(template.getNodeProperties());

    PodTemplate podTemplate = new PodTemplate();
    podTemplate.setName(name);
    podTemplate.setNamespace(!Strings.isNullOrEmpty(template.getNamespace()) ? template.getNamespace() : parent.getNamespace());
    podTemplate.setLabel(label);
    podTemplate.setNodeSelector(nodeSelector);
    podTemplate.setServiceAccount(serviceAccount);
    podTemplate.setEnvVars(combineEnvVars(parent, template));
    podTemplate.setContainers(new ArrayList<>(combinedContainers.values()));
    podTemplate.setWorkspaceVolume(workspaceVolume);
    podTemplate.setVolumes(new ArrayList<>(combinedVolumes.values()));
    podTemplate.setImagePullSecrets(new ArrayList<>(imagePullSecrets));
    podTemplate.setAnnotations(new ArrayList<>(podAnnotations));
    podTemplate.setNodeProperties(toolLocationNodeProperties);
    podTemplate.setNodeUsageMode(nodeUsageMode);
    podTemplate.setYamlMergeStrategy(template.getYamlMergeStrategy());
    podTemplate.setInheritFrom(!Strings.isNullOrEmpty(template.getInheritFrom()) ?
                               template.getInheritFrom() : parent.getInheritFrom());

    podTemplate.setInstanceCap(template.getInstanceCap() != Integer.MAX_VALUE ?
                               template.getInstanceCap() : parent.getInstanceCap());

    podTemplate.setSlaveConnectTimeout(template.getSlaveConnectTimeout() != PodTemplate.DEFAULT_SLAVE_JENKINS_CONNECTION_TIMEOUT ?
                                       template.getSlaveConnectTimeout() : parent.getSlaveConnectTimeout());

    podTemplate.setIdleMinutes(template.getIdleMinutes() != 0 ?
                               template.getIdleMinutes() : parent.getIdleMinutes());

    podTemplate.setActiveDeadlineSeconds(template.getActiveDeadlineSeconds() != 0 ?
                                         template.getActiveDeadlineSeconds() : parent.getActiveDeadlineSeconds());


    podTemplate.setServiceAccount(!Strings.isNullOrEmpty(template.getServiceAccount()) ?
                                  template.getServiceAccount() : parent.getServiceAccount());

    podTemplate.setPodRetention(template.getPodRetention());
    podTemplate.setShowRawYaml(template.isShowRawYamlSet() ? template.isShowRawYaml() : parent.isShowRawYaml());

    podTemplate.setRunAsUser(template.getRunAsUser() != null ? template.getRunAsUser() : parent.getRunAsUser());
    podTemplate.setRunAsGroup(template.getRunAsGroup() != null ? template.getRunAsGroup() : parent.getRunAsGroup());

    podTemplate.setSupplementalGroups(template.getSupplementalGroups() != null ? template.getSupplementalGroups() : parent.getSupplementalGroups());

    podTemplate.setHostNetwork(template.isHostNetworkSet() ? template.isHostNetwork() : parent.isHostNetwork());

    List<String> yamls = new ArrayList<>(parent.getYamls());
    yamls.addAll(template.getYamls());
    podTemplate.setYamls(yamls);

    LOGGER.log(Level.FINEST, "Pod templates combined: {0}", podTemplate);
    return podTemplate;
}
 
Example 7
Source File: PodTemplateStep.java    From kubernetes-plugin with Apache License 2.0 4 votes vote down vote up
public Node.Mode getNodeUsageMode() {
    return nodeUsageMode;
}
 
Example 8
Source File: PodTemplateStep.java    From kubernetes-plugin with Apache License 2.0 4 votes vote down vote up
public void setNodeUsageMode(Node.Mode nodeUsageMode) {
    this.nodeUsageMode = nodeUsageMode;
}
 
Example 9
Source File: PodTemplate.java    From kubernetes-plugin with Apache License 2.0 4 votes vote down vote up
@DataBoundSetter
public void setNodeUsageMode(Node.Mode nodeUsageMode) {
    this.nodeUsageMode = nodeUsageMode;
}
 
Example 10
Source File: PodTemplate.java    From kubernetes-plugin with Apache License 2.0 4 votes vote down vote up
public Node.Mode getNodeUsageMode() {
    return nodeUsageMode;
}
 
Example 11
Source File: DockerSlaveConfig.java    From yet-another-docker-plugin with MIT License 4 votes vote down vote up
@DataBoundSetter
public void setMode(Node.Mode mode) {
    this.mode = mode;
}
 
Example 12
Source File: DockerSlaveConfig.java    From yet-another-docker-plugin with MIT License 4 votes vote down vote up
public Node.Mode getMode() {
    return mode;
}
 
Example 13
Source File: DockerTemplate.java    From docker-plugin with MIT License 4 votes vote down vote up
@DataBoundSetter
public void setMode(Node.Mode mode) {
    this.mode = mode;
}
 
Example 14
Source File: DockerTemplate.java    From docker-plugin with MIT License 4 votes vote down vote up
public Node.Mode getMode() {
    return mode;
}