未验证 提交 7b952de6 编写于 作者: O Oleg Nenashev 提交者: GitHub

Merge pull request #5010 from jeffret-b/jenkinsAgentJnlp

[JENKINS-35452] A step towards removing more 'slave' terminology.
......@@ -1874,7 +1874,7 @@ public class Functions {
/**
* Obtains the host name of the Hudson server that clients can use to talk back to.
* <p>
* This is primarily used in {@code slave-agent.jnlp.jelly} to specify the destination
* This is primarily used in {@code jenkins-agent.jnlp.jelly} to specify the destination
* that the agents talk to.
*/
public String getServerName() {
......
......@@ -814,13 +814,23 @@ public class SlaveComputer extends Computer {
@WebMethod(name="slave-agent.jnlp")
public HttpResponse doSlaveAgentJnlp(StaplerRequest req, StaplerResponse res) {
return new EncryptedSlaveAgentJnlpFile(this, "slave-agent.jnlp.jelly", getName(), CONNECT);
return doJenkinsAgentJnlp(req, res);
}
@WebMethod(name="jenkins-agent.jnlp")
public HttpResponse doJenkinsAgentJnlp(StaplerRequest req, StaplerResponse res) {
return new EncryptedSlaveAgentJnlpFile(this, "jenkins-agent.jnlp.jelly", getName(), CONNECT);
}
class LowPermissionResponse {
@WebMethod(name="jenkins-agent.jnlp")
public HttpResponse doJenkinsAgentJnlp(StaplerRequest req, StaplerResponse res) {
return SlaveComputer.this.doJenkinsAgentJnlp(req, res);
}
@WebMethod(name="slave-agent.jnlp")
public HttpResponse doSlaveAgentJnlp(StaplerRequest req, StaplerResponse res) {
return SlaveComputer.this.doSlaveAgentJnlp(req, res);
return SlaveComputer.this.doJenkinsAgentJnlp(req, res);
}
}
......
......@@ -4820,7 +4820,7 @@ public class Jenkins extends AbstractCIBase implements DirectlyModifiableTopLeve
}
// TODO SlaveComputer.doSlaveAgentJnlp; there should be an annotation to request unprotected access
if (restOfPath.matches("/computer/[^/]+/slave-agent[.]jnlp")
if ((isAgentJnlpPath(restOfPath, "jenkins") || (isAgentJnlpPath(restOfPath, "slave")))
&& "true".equals(Stapler.getCurrentRequest().getParameter("encrypt"))) {
return false;
}
......@@ -4828,6 +4828,10 @@ public class Jenkins extends AbstractCIBase implements DirectlyModifiableTopLeve
return true;
}
private boolean isAgentJnlpPath(String restOfPath, String prefix) {
return restOfPath.matches("/computer/[^/]+/" + prefix+ "-agent[.]jnlp");
}
/**
* Gets a list of unprotected root actions.
* These URL prefixes should be exempted from access control checks by container-managed security.
......
......@@ -41,7 +41,7 @@ THE SOFTWARE.
<j:when test="${it.launcher.javaWebStartSupported}">
<li>
<p>
<a href="slave-agent.jnlp" id="jnlp-link">
<a href="jenkins-agent.jnlp" id="jnlp-link">
<img src="${imagesURL}/webstart.gif" alt="${%launch agent}" />
</a>
${%Launch agent from browser}
......@@ -64,13 +64,13 @@ THE SOFTWARE.
<p>
${%Run from agent command line:}
</p>
<pre>javaws ${h.inferHudsonURL(request)}${it.url}slave-agent.jnlp</pre>
<pre>javaws ${h.inferHudsonURL(request)}${it.url}jenkins-agent.jnlp</pre>
</li>
<li>
<p>
${%Or if the agent is headless:}
</p>
<pre>java${it.launcher.vmargs == null ? '' : ' ' + it.launcher.vmargs} -jar <a href="${rootURL}/jnlpJars/agent.jar">agent.jar</a> -jnlpUrl ${h.inferHudsonURL(request)}${it.url}slave-agent.jnlp ${it.launcher.getWorkDirOptions(it)}</pre>
<pre>java${it.launcher.vmargs == null ? '' : ' ' + it.launcher.vmargs} -jar <a href="${rootURL}/jnlpJars/agent.jar">agent.jar</a> -jnlpUrl ${h.inferHudsonURL(request)}${it.url}jenkins-agent.jnlp ${it.launcher.getWorkDirOptions(it)}</pre>
</li>
</j:when>
<j:otherwise>
......@@ -79,12 +79,12 @@ THE SOFTWARE.
${%Run from agent command line:}
</p>
<!-- TODO conceal secret w/ JS if possible -->
<pre>java${it.launcher.vmargs == null ? '' : ' ' + it.launcher.vmargs} -jar <a href="${rootURL}/jnlpJars/agent.jar">agent.jar</a> -jnlpUrl ${h.inferHudsonURL(request)}${it.url}slave-agent.jnlp -secret ${it.jnlpMac} ${it.launcher.getWorkDirOptions(it)}</pre>
<pre>java${it.launcher.vmargs == null ? '' : ' ' + it.launcher.vmargs} -jar <a href="${rootURL}/jnlpJars/agent.jar">agent.jar</a> -jnlpUrl ${h.inferHudsonURL(request)}${it.url}jenkins-agent.jnlp -secret ${it.jnlpMac} ${it.launcher.getWorkDirOptions(it)}</pre>
<p>
${%Run from agent command line, with the secret stored in a file:}
</p>
<pre>echo ${it.jnlpMac} > secret-file
java${it.launcher.vmargs == null ? '' : ' ' + it.launcher.vmargs} -jar <a href="${rootURL}/jnlpJars/agent.jar">agent.jar</a> -jnlpUrl ${h.inferHudsonURL(request)}${it.url}slave-agent.jnlp -secret @secret-file ${it.launcher.getWorkDirOptions(it)}</pre>
java${it.launcher.vmargs == null ? '' : ' ' + it.launcher.vmargs} -jar <a href="${rootURL}/jnlpJars/agent.jar">agent.jar</a> -jnlpUrl ${h.inferHudsonURL(request)}${it.url}jenkins-agent.jnlp -secret @secret-file ${it.launcher.getWorkDirOptions(it)}</pre>
</li>
</j:otherwise>
</j:choose>
......
......@@ -23,6 +23,7 @@
*/
package hudson.slaves;
import com.gargoylesoftware.htmlunit.Page;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import hudson.Proc;
import hudson.Util;
......@@ -49,6 +50,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
......@@ -82,7 +84,7 @@ public class JNLPLauncherTest {
public void testLaunch() throws Exception {
Assume.assumeFalse("Skipping JNLPLauncherTest.testLaunch because we are running headless", GraphicsEnvironment.isHeadless());
Computer c = addTestSlave(false);
Computer c = addTestAgent(false);
launchJnlpAndVerify(c, buildJnlpArgs(c));
}
......@@ -95,7 +97,7 @@ public class JNLPLauncherTest {
Assume.assumeFalse("Skipping JNLPLauncherTest.testLaunch because we are running headless", GraphicsEnvironment.isHeadless());
File workDir = tmpDir.newFolder("workDir");
Computer c = addTestSlave(false);
Computer c = addTestAgent(false);
launchJnlpAndVerify(c, buildJnlpArgs(c).add("-workDir", workDir.getAbsolutePath()));
assertTrue("Remoting work dir should have been created", new File(workDir, "remoting").exists());
}
......@@ -106,7 +108,7 @@ public class JNLPLauncherTest {
*/
@Test
public void testHeadlessLaunch() throws Exception {
Computer c = addTestSlave(false);
Computer c = addTestAgent(false);
launchJnlpAndVerify(c, buildJnlpArgs(c).add("-arg","-headless"));
// make sure that onOffline gets called just the right number of times
assertEquals(1, ComputerListener.all().get(ListenerImpl.class).offlined);
......@@ -117,7 +119,7 @@ public class JNLPLauncherTest {
public void testHeadlessLaunchWithWorkDir() throws Exception {
Assume.assumeFalse("Skipping JNLPLauncherTest.testLaunch because we are running headless", GraphicsEnvironment.isHeadless());
Computer c = addTestSlave(true);
Computer c = addTestAgent(true);
launchJnlpAndVerify(c, buildJnlpArgs(c).add("-arg","-headless"));
assertEquals(1, ComputerListener.all().get(ListenerImpl.class).offlined);
}
......@@ -128,7 +130,7 @@ public class JNLPLauncherTest {
Assume.assumeFalse("Skipping JNLPLauncherTest.testLaunch because we are running headless", GraphicsEnvironment.isHeadless());
File workDir = tmpDir.newFolder("workDir");
Computer c = addTestSlave(false);
Computer c = addTestAgent(false);
launchJnlpAndVerify(c, buildJnlpArgs(c).add("-arg","-headless", "-workDir", workDir.getAbsolutePath()));
assertEquals(1, ComputerListener.all().get(ListenerImpl.class).offlined);
}
......@@ -165,7 +167,7 @@ public class JNLPLauncherTest {
ComputerLauncher launcher = new JNLPLauncher("", "", new RemotingWorkDirSettings(false, workDir.getAbsolutePath(), "internalDir", false));
launcher = new DelegatingComputerLauncherImpl(launcher);
Computer c = addTestSlave(launcher);
Computer c = addTestAgent(launcher);
launchJnlpAndVerify(c, buildJnlpArgs(c));
assertTrue("Remoting work dir should have been created", new File(workDir, "internalDir").exists());
}
......@@ -178,7 +180,7 @@ public class JNLPLauncherTest {
ComputerLauncher launcher = new JNLPLauncher("", "", new RemotingWorkDirSettings(false, workDir.getAbsolutePath(), "internalDir", false));
launcher = new ComputerLauncherFilterImpl(launcher);
Computer c = addTestSlave(launcher);
Computer c = addTestAgent(launcher);
launchJnlpAndVerify(c, buildJnlpArgs(c));
assertTrue("Remoting work dir should have been created", new File(workDir, "internalDir").exists());
}
......@@ -212,7 +214,7 @@ public class JNLPLauncherTest {
args.add(Which.jarFile(netx.jnlp.runtime.JNLPRuntime.class).getAbsolutePath());
args.add("-headless","-basedir");
args.add(j.createTmpDir());
args.add("-nosecurity","-jnlp", j.getURL() + "computer/"+c.getName()+"/slave-agent.jnlp");
args.add("-nosecurity","-jnlp", j.getURL() + "computer/"+c.getName()+"/jenkins-agent.jnlp");
if (c instanceof SlaveComputer) {
SlaveComputer sc = (SlaveComputer)c;
......@@ -226,7 +228,7 @@ public class JNLPLauncherTest {
}
/**
* Launches the JNLP slave agent and asserts its basic operations.
* Launches the Inbound TCP agent and asserts its basic operations.
*/
private void launchJnlpAndVerify(Computer c, ArgumentListBuilder args) throws Exception {
Proc proc = j.createLocalLauncher().launch().cmds(args).stdout(System.out).pwd(".").start();
......@@ -241,7 +243,7 @@ public class JNLPLauncherTest {
if (c.isOffline()) {
System.out.println(c.getLog());
fail("Slave failed to go online");
fail("Agent failed to go online");
}
// run some trivial thing
System.err.println("Calling task...");
......@@ -256,21 +258,21 @@ public class JNLPLauncherTest {
}
/**
* Adds a JNLP {@link Slave} to the system and returns it.
* Adds an Inbound TCP agent to the system and returns it.
*/
private Computer addTestSlave(boolean enableWorkDir) throws Exception {
return addTestSlave(new JNLPLauncher(enableWorkDir));
private Computer addTestAgent(boolean enableWorkDir) throws Exception {
return addTestAgent(new JNLPLauncher(enableWorkDir));
}
/**
* Adds a JNLP {@link Slave} to the system and returns it.
* Adds an Inbound TCP agent to the system and returns it.
*/
private Computer addTestSlave(ComputerLauncher launcher) throws Exception {
List<Node> slaves = new ArrayList<Node>(j.jenkins.getNodes());
private Computer addTestAgent(ComputerLauncher launcher) throws Exception {
List<Node> agents = new ArrayList<Node>(j.jenkins.getNodes());
File dir = Util.createTempDir();
slaves.add(new DumbSlave("test","dummy",dir.getAbsolutePath(),"1", Mode.NORMAL, "",
agents.add(new DumbSlave("test","dummy",dir.getAbsolutePath(),"1", Mode.NORMAL, "",
launcher, RetentionStrategy.INSTANCE, new ArrayList<NodeProperty<?>>()));
j.jenkins.setNodes(slaves);
j.jenkins.setNodes(agents);
Computer c = j.jenkins.getComputer("test");
assertNotNull(c);
return c;
......@@ -297,4 +299,21 @@ public class JNLPLauncherTest {
j.assertEqualBeans(original,s.getLauncher(),"tunnel,vmargs");
j.assertEqualDataBoundBeans(((JNLPLauncher) s.getLauncher()).getWorkDirSettings(), custom);
}
@Test
public void testJnlpFileDownload() throws Exception {
assertJnlpFileDownload("/jenkins-agent.jnlp");
}
@Test
public void testObsoletedJnlpFileDownload() throws Exception {
assertJnlpFileDownload("/slave-agent.jnlp");
}
private void assertJnlpFileDownload(String filename) throws Exception {
Computer c = addTestAgent(false);
Page p = j.createWebClient().getPage(j.getURL() + "computer/" + c.getName() + filename);
assertThat(p.getWebResponse().getStatusCode(), is(200));
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册