当前位置: 首页>>代码示例>>Java>>正文


Java Node.toComputer方法代码示例

本文整理汇总了Java中hudson.model.Node.toComputer方法的典型用法代码示例。如果您正苦于以下问题:Java Node.toComputer方法的具体用法?Java Node.toComputer怎么用?Java Node.toComputer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在hudson.model.Node的用法示例。


在下文中一共展示了Node.toComputer方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: startZAP

import hudson.model.Node; //导入方法依赖的package包/类
/**
 * Start ZAProxy using command line. It uses host and port configured in Jenkins admin mode and
 * ZAProxy program is launched in daemon mode (i.e without UI).
 * ZAProxy is started on the build's machine (so master machine ou slave machine) thanks to 
 * {@link FilePath} object and {@link Launcher} object.
 * 
 * @param build
 * @param listener the listener to display log during the job execution in jenkins
 * @param launcher the object to launch a process locally or remotely
 * @throws InterruptedException 
 * @throws IOException 
 * @throws IllegalArgumentException 
 */
public void startZAP(AbstractBuild<?, ?> build, BuildListener listener, Launcher launcher) 
		throws IllegalArgumentException, IOException, InterruptedException {
	checkParams(build, listener);
	
	FilePath ws = build.getWorkspace();
	if (ws == null) {
		Node node = build.getBuiltOn();
		if (node == null) {
			throw new NullPointerException("no such build node: " + build.getBuiltOnStr());
		}
		throw new NullPointerException("no workspace from node " + node + " which is computer " + node.toComputer() + " and has channel " + node.getChannel());
	}
	
	// Contains the absolute path to ZAP program
	FilePath zapPathWithProgName = new FilePath(ws.getChannel(), zapProgram + getZAPProgramNameWithSeparator(build));
	listener.getLogger().println("Start ZAProxy [" + zapPathWithProgName.getRemote() + "]");
	
	// Command to start ZAProxy with parameters
	List<String> cmd = new ArrayList<String>();
	cmd.add(zapPathWithProgName.getRemote());
	cmd.add(CMD_LINE_DAEMON);
	cmd.add(CMD_LINE_HOST);
	cmd.add(zapProxyHost);
	cmd.add(CMD_LINE_PORT);
	cmd.add(String.valueOf(zapProxyPort));
	cmd.add(CMD_LINE_CONFIG);
	cmd.add(CMD_LINE_API_KEY + "=" + API_KEY);
	
	// Set the default directory used by ZAP if it's defined and if a scan is provided
	if(scanURL && zapDefaultDir != null && !zapDefaultDir.isEmpty()) {
		cmd.add(CMD_LINE_DIR);
		cmd.add(zapDefaultDir);
	}
	
	// Adds command line arguments if it's provided
	if(!cmdLinesZAP.isEmpty()) {
		addZapCmdLine(cmd);
	}
		
	EnvVars envVars = build.getEnvironment(listener);
	// on Windows environment variables are converted to all upper case,
	// but no such conversions are done on Unix, so to make this cross-platform,
	// convert variables to all upper cases.
	for(Map.Entry<String,String> e : build.getBuildVariables().entrySet())
		envVars.put(e.getKey(),e.getValue());
	
	FilePath workDir = new FilePath(ws.getChannel(), zapProgram);
	
	// JDK choice
	computeJdkToUse(build, listener, envVars);
	
	// Launch ZAP process on remote machine (on master if no remote machine)
	launcher.launch().cmds(cmd).envs(envVars).stdout(listener).pwd(workDir).start();
	
	// Call waitForSuccessfulConnectionToZap(int, BuildListener) remotely
	build.getWorkspace().act(new WaitZAProxyInitCallable(this, listener));
}
 
开发者ID:jenkinsci,项目名称:zaproxy-plugin,代码行数:71,代码来源:ZAProxy.java

示例2: lockSlaveExecutors

import hudson.model.Node; //导入方法依赖的package包/类
/**
 * Used to lock the executors for each available slave assigned to this
 * build. <br />
 * <br />
 * <b>(Can be modified to get the auto-generated projects and their
 * builds)</b>
 * 
 * @param availableNodes
 *            the available nodes
 * @param build
 *            the current build
 * @param stream
 *            the printing stream
 * @return the locked set of nodes
 * @throws Exception
 */
private Set<Node> lockSlaveExecutors(Set<Node> availableNodes,
		AbstractBuild<?, ?> build, PrintStream stream) throws Exception {
	ArrayList<Future<FreeStyleBuild>> futureBuildList = new ArrayList<Future<FreeStyleBuild>>();

	ArrayList<FreeStyleProject> projectList = new ArrayList<FreeStyleProject>();

	Set<Node> nodeSet = new HashSet<Node>();

	Computer c = null;

	for (Node n : availableNodes) {

		c = n.toComputer();

		nodeSet.add(n);

		for (Executor e : c.getExecutors()) {

			if (e.isIdle()) {
				String lockProjectName = NodeUtils.getLockedProjectName(
						build.getProject().getName(), n, e);

				Jenkins jenkins = Jenkins.getInstance();

				NodeUtils.deleteLockingProject(lockProjectName, stream);

				FreeStyleProject project = jenkins.createProject(
						FreeStyleProject.class, lockProjectName);

				final String projectName = build.getProject().getName();

				project.getBuildersList().add(
						new DTDumbBuilder(projectName));

				project.setAssignedNode(n);

				QueueTaskFuture<FreeStyleBuild> buildFuture = project
						.scheduleBuild2(0);

				futureBuildList.add(buildFuture);
				projectList.add(project);

			}
		}
	}

	return nodeSet;
}
 
开发者ID:bombardier-transportation,项目名称:distributed-test-job,代码行数:65,代码来源:DTBuilder.java


注:本文中的hudson.model.Node.toComputer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。