Node.java 3.2 KB
Newer Older
K
kohsuke 已提交
1 2 3
package hudson.model;

import hudson.Launcher;
4
import hudson.FilePath;
K
kohsuke 已提交
5
import hudson.node_monitors.NodeMonitor;
K
kohsuke 已提交
6
import hudson.util.EnumConverter;
7
import hudson.util.ClockDifference;
K
kohsuke 已提交
8
import org.apache.commons.beanutils.ConvertUtils;
K
kohsuke 已提交
9

10
import java.util.Set;
K
kohsuke 已提交
11
import java.io.IOException;
12

K
kohsuke 已提交
13 14 15 16
/**
 * Commonality between {@link Slave} and master {@link Hudson}.
 *
 * @author Kohsuke Kawaguchi
K
kohsuke 已提交
17
 * @see NodeMonitor
K
kohsuke 已提交
18 19 20
 */
public interface Node {
    /**
K
kohsuke 已提交
21
     * Name of this node.
K
kohsuke 已提交
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
     *
     * @return
     *      "" if this is master
     */
    String getNodeName();

    /**
     * Human-readable description of this node.
     */
    String getNodeDescription();

    /**
     * Returns a {@link Launcher} for executing programs on this node.
     */
    Launcher createLauncher(TaskListener listener);

    /**
     * Returns the number of {@link Executor}s.
     *
     * This may be different from <code>getExecutors().size()</code>
     * because it takes time to adjust the number of executors.
     */
    int getNumExecutors();

    /**
47
     * Returns {@link Mode#EXCLUSIVE} if this node is only available
K
kohsuke 已提交
48 49 50 51 52
     * for those jobs that exclusively specifies this node
     * as the assigned node.
     */
    Mode getMode();

K
kohsuke 已提交
53 54
    Computer createComputer();

55 56 57 58 59 60
    /**
     * Returns the possibly empty set of labels that are assigned to this node,
     * including the automatic {@link #getSelfLabel() self label}.
     */
    Set<Label> getAssignedLabels();

61 62 63 64 65 66
    /**
     * Returns the possibly empty set of labels that it has been determined as supported by this node.
     * @see hudson.tasks.LabelFinder
     */
    Set<Label> getDynamicLabels();

67 68 69 70 71
    /**
     * Gets the special label that represents this node itself.
     */
    Label getSelfLabel();

72 73 74 75 76 77
    /**
     * Returns a "workspace" directory for the given {@link TopLevelItem}.
     *
     * <p>
     * Workspace directory is usually used for keeping out the checked out
     * source code, but it can be used for anything.
K
kohsuke 已提交
78 79 80
     *
     * @return
     *      null if this node is not connected hence the path is not available
81 82 83
     */
    FilePath getWorkspaceFor(TopLevelItem item);

K
kohsuke 已提交
84 85 86 87 88 89 90 91 92 93 94 95 96
    /**
     * Gets the root directory of this node.
     *
     * <p>
     * Hudson always owns a directory on every node. This method
     * returns that.
     *
     * @return
     *      null if the node is offline and hence the {@link FilePath}
     *      object is not available.
     */
    FilePath getRootPath();

K
kohsuke 已提交
97 98 99 100
    /**
     * Estimates the clock difference with this slave.
     *
     * @return
101
     *      always non-null.
K
kohsuke 已提交
102 103 104
     * @throws InterruptedException
     *      if the operation is aborted.
     */
105
    ClockDifference getClockDifference() throws IOException, InterruptedException;
K
kohsuke 已提交
106

K
kohsuke 已提交
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
    public enum Mode {
        NORMAL("Utilize this slave as much as possible"),
        EXCLUSIVE("Leave this machine for tied jobs only");

        private final String description;

        public String getDescription() {
            return description;
        }

        public String getName() {
            return name();
        }

        Mode(String description) {
            this.description = description;
        }
K
kohsuke 已提交
124 125 126 127

        static {
            ConvertUtils.register(new EnumConverter(),Mode.class);
        }
K
kohsuke 已提交
128 129
    }
}