本文整理汇总了Java中hudson.model.Node类的典型用法代码示例。如果您正苦于以下问题:Java Node类的具体用法?Java Node怎么用?Java Node使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Node类属于hudson.model包,在下文中一共展示了Node类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getPollingEnvVars
import hudson.model.Node; //导入依赖的package包/类
@Nonnull
public static Map<String, String> getPollingEnvVars(@Nonnull Job<?, ?> job, @CheckForNull Node node) throws EnvInjectException {
final Run<?, ?> lastBuild = job.getLastBuild();
if (lastBuild != null) {
if (EnvInjectPluginHelper.isEnvInjectPluginInstalled()) {
return getEnVars(lastBuild);
}
}
if (node == null) {
return getFallBackMasterNode(job);
}
if (node.getRootPath() == null) {
return getFallBackMasterNode(job);
}
return getDefaultEnvVarsJob(job, node);
}
示例2: getEnVars
import hudson.model.Node; //导入依赖的package包/类
@Nonnull
public static Map<String, String> getEnVars(@Nonnull Run<?, ?> run) throws EnvInjectException {
Action envInjectAction = EnvInjectActionRetriever.getEnvInjectAction(run);
if (envInjectAction != null) {
try {
Method method = envInjectAction.getClass().getMethod("getEnvMap");
return (Map<String, String>) method.invoke(envInjectAction);
} catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException | ClassCastException e) {
throw new EnvInjectException(e);
}
}
// Retrieve node used for this build
Node builtOn = (run instanceof AbstractBuild) ? ((AbstractBuild)run).getBuiltOn() : null;
// Check if node is always on. Otherwise, gather master env vars
if (builtOn == null) {
return getFallBackMasterNode(run.getParent());
}
if (builtOn.getRootPath() == null) {
return getFallBackMasterNode(run.getParent());
}
// Get envVars from the node of the last build
return getDefaultEnvVarsJob(run.getParent(), builtOn);
}
示例3: findNodeProperty
import hudson.model.Node; //导入依赖的package包/类
/**
* Finds the {@link NodeProperty} for the external workspace definition.
*
* @param node the current node
* @return the node property for the external workspace manager
* @throws IOException if node property was not found
*/
@Nonnull
private static ExternalWorkspaceProperty findNodeProperty(Node node) throws IOException {
DescribableList<NodeProperty<?>, NodePropertyDescriptor> nodeProperties = node.getNodeProperties();
ExternalWorkspaceProperty exwsNodeProperty = null;
for (NodeProperty<?> nodeProperty : nodeProperties) {
if (nodeProperty instanceof ExternalWorkspaceProperty) {
exwsNodeProperty = (ExternalWorkspaceProperty) nodeProperty;
break;
}
}
if (exwsNodeProperty == null) {
String message = format("There is no External Workspace config defined in Node '%s' config", node.getDisplayName());
throw new AbortException(message);
}
return exwsNodeProperty;
}
示例4: localRootPathToNodeMountPoint
import hudson.model.Node; //导入依赖的package包/类
@LocalData
@Test
public void localRootPathToNodeMountPoint() throws Exception {
// The node configuration version 1.0.0 contains a localRootPath field.
// This tests that future versions load this field as nodeMountPoint,
// in other words it tests NodeDisk.readResolve()
Computer computer = jr.getInstance().getComputer("node1");
Node node = computer.getNode();
DescribableList<NodeProperty<?>,NodePropertyDescriptor> props = node.getNodeProperties();
ExternalWorkspaceProperty exwsProp = props.get(ExternalWorkspaceProperty.class);
List<NodeDiskPool> diskPools = exwsProp.getNodeDiskPools();
assertThat(diskPools.size(), is(1));
NodeDiskPool diskPool = diskPools.get(0);
assertThat(diskPool.getDiskPoolRefId(), is ("dp1"));
List<NodeDisk> disks = diskPool.getNodeDisks();
assertThat(disks.size(), is(1));
NodeDisk disk = disks.get(0);
assertThat(disk.getDiskRefId(), is("d1"));
assertThat(disk.getNodeMountPoint(), is("/tmp/dp1/d1"));
}
示例5: removeNode
import hudson.model.Node; //导入依赖的package包/类
private synchronized void removeNode(String instanceId) {
final Jenkins jenkins=Jenkins.getInstance();
//noinspection SynchronizationOnLocalVariableOrMethodParameter
synchronized (jenkins) {
// If this node is dying, remove it from Jenkins
final Node n = jenkins.getNode(instanceId);
if (n != null) {
try {
jenkins.removeNode(n);
} catch(final Exception ex) {
LOGGER.log(Level.WARNING, "Error removing node " + instanceId);
throw new IllegalStateException(ex);
}
}
}
}
示例6: execute
import hudson.model.Node; //导入依赖的package包/类
public static void execute(Run<?, ?> run, FilePath ws, Launcher launcher, String installation, Node node, TaskListener listener, EnvVars envVars, String cliScriptContent) throws IOException, InterruptedException{
String exe = AppScanSourceInstallation.getExecutable(installation, AppScanSourceCommand.AppScanSourceCLI, node, listener, envVars);
//Create a temp file with our script commands
FilePath tempFile = ws.createTextTempFile("temp_cli_script_", ".txt", cliScriptContent);
//Build the command line commands with necessary parameters
JenkinsExecutor runner = new JenkinsExecutor(run, ws, launcher, listener);
AppScanSourceInvocation invocation = new AppScanSourceInvocation(exe, run, ws, listener);
invocation.addScriptFile(tempFile);
//Execute command line
if (!invocation.execute(runner)) {
throw new AbortException("AppScan Source execution failed");
}
//Delete the temp file after we use it
tempFile.delete();
}
示例7: createSlaveOnVM
import hudson.model.Node; //导入依赖的package包/类
public Node createSlaveOnVM(ParallelsDesktopVM vm) throws Exception
{
String vmId = vm.getVmid();
String slaveName = vm.getSlaveName();
LOGGER.log(Level.SEVERE, "Starting slave '" + slaveName+ "'");
LOGGER.log(Level.SEVERE, "Starting virtual machine '" + vmId + "'");
RunVmCallable command = new RunVmCallable("start", vmId);
try
{
forceGetChannel().call(command);
LOGGER.log(Level.SEVERE, "Waiting for IP...");
String ip = getVmIPAddress(vmId);
LOGGER.log(Level.SEVERE, "Got IP address for VM " + vmId + ": " + ip);
vm.setLauncherIP(ip);
}
catch (Exception ex)
{
LOGGER.log(Level.SEVERE, ex.toString());
}
return new ParallelsDesktopVMSlave(vm, this);
}
示例8: getAllAvailableNodes
import hudson.model.Node; //导入依赖的package包/类
/**
* Used to get all available {@link Nodes}s in the {@link Label} that are
* not the Master node.
*
* @param build
* the current build
* @param set
* the {@link Label} assigned to the {@link DTJob}.
* @return a {@link Set} of all available nodes
* @throws Exception
* @since 1.0
*/
public static Set<Node> getAllAvailableNodes(AbstractBuild<?, ?> build)
throws Exception {
Set<Node> nodes = new HashSet<Node>();
checkNodes(build);
for (Node node : getAssignedNodes(build)) {
if (node.toComputer().isOnline()) {
if (node.equals(build.getBuiltOn())) {
nodes.add(node);
} else {
if (node.toComputer().isIdle()) {
nodes.add(node);
}
}
}
}
if (nodes.size() < 2) {
throw PrintMessages.throwNotEnoughSlaves(nodes.size());
}
return nodes;
}
示例9: createEnvVarsForNode
import hudson.model.Node; //导入依赖的package包/类
/**
* Used define additional environment variable for a particular {@link Node}
* .
*
* @param node
* the {@link Node}
* @param build
* the current build
* @return a new Entry of a node and it's additional environment variables
* @throws IOException
* @throws Exception
* @since 1.0
*/
public static GenericEntry<Node, EnvVars> createEnvVarsForNode(Node node,
AbstractBuild<?, ?> build, String listFile) throws IOException,
Exception {
if (node != null) {
String nodeTestEnv = ((DTBuild) build).getTestJob()
.getSlaveTestEnv();
String projectName = ((DTBuild) build).getTestJob()
.getDisplayName();
EnvVars additionalEnvironment = new EnvVars();
additionalEnvironment.put("$TEST_ENV", nodeTestEnv + "/");
additionalEnvironment.put("$TEST_LIST", projectName + "/"
+ listFile);
additionalEnvironment.put("$TARGET_SCRIPT", projectName + "/"
+ FilePathUtils.getPathToTargetScript(build).getName());
additionalEnvironment.put("$TEST_WS", FilePathUtils
.getPathToRootProjectWorkspaceOnNode(node, build)
.getRemote()
+ "/");
return new GenericEntry<Node, EnvVars>(node, additionalEnvironment);
} else {
return null;
}
}
示例10: testUnixConfigRoundTrip
import hudson.model.Node; //导入依赖的package包/类
public void testUnixConfigRoundTrip() throws Exception {
String ami = "ami1";
String description = "foo ami";
EC2Tag tag1 = new EC2Tag( "name1", "value1" );
EC2Tag tag2 = new EC2Tag( "name2", "value2" );
List<EC2Tag> tags = new ArrayList<EC2Tag>();
tags.add( tag1 );
tags.add( tag2 );
SlaveTemplate orig = new SlaveTemplate(ami, EC2AbstractSlave.TEST_ZONE, null, "default", "foo", InstanceType.M1Large, "ttt", Node.Mode.NORMAL, description, "bar", "bbb", "aaa", "10", "rrr", new UnixData("sudo", "22"), "-Xmx1g", false, "subnet 456", tags, null, false, null, "", true, false, "", false, "");
List<SlaveTemplate> templates = new ArrayList<SlaveTemplate>();
templates.add(orig);
AmazonEC2Cloud ac = new AmazonEC2Cloud("us-east-1", false, "abc", "def", "us-east-1", "ghi", "3", templates);
hudson.clouds.add(ac);
submit(createWebClient().goTo("configure").getFormByName("config"));
SlaveTemplate received = ((EC2Cloud)hudson.clouds.iterator().next()).getTemplate(description);
assertEqualBeans(orig, received, "amiType");
}
示例11: printPreBuildInfoSuccess
import hudson.model.Node; //导入依赖的package包/类
/**
* Used to print a success message indicating that the test case suite
* generation and the copying of relevant files was successful.
*
* @param printStream
* the print stream
* @param pair
* containing the {@link Node} and it's assigned test cases
* @param path
* the path to the remote location where files have been copied
* @since 1.0
*/
public static void printPreBuildInfoSuccess(PrintStream printStream,
Entry<Node, List<String>> pair, String path) {
printStream
.printf("[PREBUILD-INFO] The test case list for %s Slave Node was successfully generated!%n",
pair.getKey().getDisplayName());
printStream.printf(
"%-15s The %slist.lst contains %d test cases in total.%n", " ",
pair.getKey().getDisplayName(), pair.getValue().size());
printStream
.printf("%-15s The test cases specified in %slist.lst were successfully copied.%n",
" ", pair.getKey().getDisplayName());
printStream
.printf("[PREBUILD-INFO]%n Copying list, target script and test cases files ->%n [TO] %s%n",
pair.getKey().getDisplayName() + " -> " + path);
}
示例12: executeTest
import hudson.model.Node; //导入依赖的package包/类
/**
* Used to execute/start a remote process that initializes the testing
* process.
*
* @param build
* the current build
* @param listener
* the build's listener
* @param entry
* containing the {@link Node} and its {@link EnvVars}
* @return the started process
* @throws InterruptedException
* @throws IOException
* @since 1.0
*/
private Proc executeTest(AbstractBuild<?, ?> build, BuildListener listener,
Entry<Node, EnvVars> entry) throws InterruptedException,
IOException {
final EnvVars vars = NodeUtils.getEnvironment(entry.getKey(),
entry.getValue());
final Node node = entry.getKey();
// Get testing environment on the specific node
FilePath testEnv = FilePathUtils.getPathToTestEnvOnNode(node, build);
// Create a remote launcher
RemoteLauncher remoteLaucher = new RemoteLauncher(listener,
node.getChannel(), true);
// Create process starter
ProcStarter starter = remoteLaucher.launch()
.cmds(buildShellCmds(vars, node, build)).stdout(listener)
.stderr(listener.getLogger()).pwd(testEnv.getParent());
// Launch the process
Proc proc = remoteLaucher.launch(starter);
return proc;
}
示例13: getZAPProgramNameWithSeparator
import hudson.model.Node; //导入依赖的package包/类
/**
* Return the ZAProxy program name with separator prefix (\zap.bat or /zap.sh) depending of the build node and the OS.
*
* @param build
* @return the ZAProxy program name with separator prefix (\zap.bat or /zap.sh)
* @throws IOException
* @throws InterruptedException
*/
private String getZAPProgramNameWithSeparator(AbstractBuild<?, ?> build) throws IOException, InterruptedException {
Node node = build.getBuiltOn();
String zapProgramName = "";
// Append zap program following Master/Slave and Windows/Unix
if( "".equals(node.getNodeName())) { // Master
if( File.pathSeparatorChar == ':' ) { // UNIX
zapProgramName = "/" + ZAP_PROG_NAME_SH;
} else { // Windows (pathSeparatorChar == ';')
zapProgramName = "\\" + ZAP_PROG_NAME_BAT;
}
}
else { // Slave
if( "Unix".equals(((SlaveComputer)node.toComputer()).getOSDescription()) ) {
zapProgramName = "/" + ZAP_PROG_NAME_SH;
} else {
zapProgramName = "\\" + ZAP_PROG_NAME_BAT;
}
}
return zapProgramName;
}
示例14: getTemplates
import hudson.model.Node; //导入依赖的package包/类
/**
* Multiple templates may have the same label.
*
* @return Templates matched to requested label assuming slave Mode
*/
@Nonnull
public List<DockerSlaveTemplate> getTemplates(Label label) {
List<DockerSlaveTemplate> dockerSlaveTemplates = new ArrayList<>();
for (DockerSlaveTemplate t : templates) {
if (isNull(label) && t.getMode() == Node.Mode.NORMAL) {
dockerSlaveTemplates.add(t);
}
if (nonNull(label) && label.matches(t.getLabelSet())) {
dockerSlaveTemplates.add(t);
}
}
return dockerSlaveTemplates;
}
示例15: tearDown
import hudson.model.Node; //导入依赖的package包/类
@Override
public void tearDown(Run<?, ?> run, FilePath workspace, Launcher launcher, TaskListener listener)
throws IOException, InterruptedException {
LOG.info("Shutting down slave");
listener.getLogger().println("Shutting down slave '" + slaveName + "'.");
final Node slaveNode = Jenkins.getInstance().getNode(slaveName);
if (isNull(slaveNode)) {
throw new IllegalStateException("Can't get node " + slaveName);
}
final DockerSlaveSingle node = (DockerSlaveSingle) slaveNode;
try {
node.terminate();
} catch (Throwable e) {
LOG.error("Can't terminate node", e);
CloudStatistics.ProvisioningListener.get().onFailure(node.getId(), e);
}
}