本文整理汇总了Java中hudson.model.Slave类的典型用法代码示例。如果您正苦于以下问题:Java Slave类的具体用法?Java Slave怎么用?Java Slave使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Slave类属于hudson.model包,在下文中一共展示了Slave类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: copySlaveJarUsingSCP
import hudson.model.Slave; //导入依赖的package包/类
/**
* Method copies the slave jar to the remote system using scp.
*
* @param listener The listener.
* @param workingDirectory The directory into which the slave jar will be copied.
* @throws IOException If something goes wrong.
* @throws InterruptedException If something goes wrong.
*/
private void copySlaveJarUsingSCP(TaskListener listener, String workingDirectory) throws IOException, InterruptedException {
SCPClient scp = new SCPClient(connection);
try {
// check if the working directory exists
if (connection.exec("test -d " + workingDirectory, listener.getLogger()) != 0) {
listener.getLogger().println("Remote filesystem doesn't exist");
// working directory doesn't exist, lets make it.
if (connection.exec("mkdir -p " + workingDirectory, listener.getLogger()) != 0) {
listener.getLogger().println("Failed to create " + workingDirectory);
}
}
// delete the slave jar as we do with SFTP
connection.exec("rm " + workingDirectory + "/slave.jar", new NullStream());
// SCP it to the slave. hudson.Util.ByteArrayOutputStream2 doesn't work for this. It pads the byte array.
listener.getLogger().println("Copying slave jar");
scp.put(new Slave.JnlpJar("slave.jar").readFully(), "slave.jar", workingDirectory, "0644");
} catch (IOException e) {
throw new IOException2("Error copying slave jar", e);
}
}
示例2: getFakeSlave
import hudson.model.Slave; //导入依赖的package包/类
protected Slave getFakeSlave(JenkinsRule r) throws Exception {
PretendSlave slave = r.createPretendSlave(p -> {
if (p.cmds().get(0).equals(KUBECTL_BINARY)) {
String[] maskedCmd = getMaskedCmd(p.cmds(), p.masks());
PrintStream ps = new PrintStream(p.stdout());
ps.println("Call stubbed for: " + String.join(", ", maskedCmd));
return new FakeLauncher.FinishedProc(0);
}
return r.createLocalLauncher().launch(p);
});
slave.setLabelString("mocked-kubectl");
return slave;
}
示例3: createSpecialEnvSlave
import hudson.model.Slave; //导入依赖的package包/类
/**
* Akin to {@link JenkinsRule#createSlave(String, String, EnvVars)} but allows {@link Computer#getEnvironment} to be controlled rather than directly modifying launchers.
* @param env variables to override in {@link Computer#getEnvironment}; null values will get unset even if defined in the test environment
* @see <a href="https://github.com/jenkinsci/jenkins/pull/1553/files#r23784822">explanation in core PR 1553</a>
*/
public static Slave createSpecialEnvSlave(JenkinsRule rule, String nodeName, @CheckForNull String labels, Map<String,String> env) throws Exception {
@SuppressWarnings("deprecation") // keep consistency with original signature rather than force the caller to pass in a TemporaryFolder rule
File remoteFS = rule.createTmpDir();
SpecialEnvSlave slave = new SpecialEnvSlave(remoteFS, rule.createComputerLauncher(/* yes null */null), nodeName, labels != null ? labels : "", env);
rule.jenkins.addNode(slave);
return slave;
}
示例4: executeCheck
import hudson.model.Slave; //导入依赖的package包/类
public boolean executeCheck(Node item) {
try {
LOG.log(Level.INFO, "slave " + item.getDisplayName() + " service " + ( (Slave) item).getComputer().getLauncher().toString());
return ((Slave) item).getComputer().getLauncher().toString().contains("ManagedWindowsServiceLauncher");
} catch (NullPointerException npe) {
return false;
}
}
示例5: afterContainerCreate
import hudson.model.Slave; //导入依赖的package包/类
@Override
public void afterContainerCreate(DockerClient client, String containerId) throws IOException {
// upload archive
try (ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
TarArchiveOutputStream tarOut = new TarArchiveOutputStream(byteArrayOutputStream)) {
// @see hudson.model.Slave.JnlpJar.getURL()
// byte[] slavejar = IOUtils.toByteArray(Jenkins.getInstance().servletContext.getResourceAsStream("/WEB-INF/slave.jar"));
// if (isNull(null)) {
// // during the development this path doesn't have the files.
// slavejar = Files.readAllBytes(Paths.get("./target/jenkins/WEB-INF/slave.jar"));
// }
byte[] slaveJar = new Slave.JnlpJar("slave.jar").readFully();
TarArchiveEntry entry = new TarArchiveEntry("slave.jar");
entry.setSize(slaveJar.length);
entry.setMode(0664);
tarOut.putArchiveEntry(entry);
tarOut.write(slaveJar);
tarOut.closeArchiveEntry();
tarOut.close();
try (InputStream is = new ByteArrayInputStream(byteArrayOutputStream.toByteArray())) {
client.copyArchiveToContainerCmd(containerId)
.withTarInputStream(is)
.withRemotePath("/tmp")
.exec();
}
}
}
示例6: check
import hudson.model.Slave; //导入依赖的package包/类
@Override
public synchronized long check(final DeployNowComputer c) {
if (!c.isIdle()) {
return 1;
}
final Jenkins jenkins = Jenkins.getInstance();
if (jenkins != null) {
for (Queue.Item t : jenkins.getQueue().getItems()) {
if (t.task instanceof DeployNowTask) {
return 1;
}
}
}
if (!c.offline) {
c.offline = true;
try {
if (jenkins != null) {
Slave node = c.getNode();
if (node != null) {
jenkins.removeNode(node);
}
}
} catch (IOException e) {
// ignore
}
}
return 1;
}
示例7: getSepFor
import hudson.model.Slave; //导入依赖的package包/类
/**
* Returns the separator for that node -- if possible to be retrieved.
* <p>
* Guaranteed to always be either "/", "\\" or null.
* <p>
* The result is cached, so that repeated lookups are sped-up and
* random node offlining does not affect the separator calculation as much.
*
* @param n the node to check.
* @return the separator, one of "/", "\\" or null.
*/
public String getSepFor(Node n) {
if (n == null) { return null; }
//Check if a value is cached
String c = nodeLookup.getIfPresent(n);
if (c != null) { return c; }
try {
//Check if the node is online and we can determine the separator via
//a system property
c = this.getRawSepFor(n.toComputer());
if (c != null) { return c; }
//Check if the remote root path can tell us something
if (n instanceof Slave) {
c = this.getRawSepFor((Slave)n);
if (c != null) { return c; }
}
//Last fallback, try to determine based on full file path
c = this.getRawSepFor(n.getRootPath());
if (c != null) { return c; }
} finally {
if (c != null) {
nodeLookup.put(n, c);
}
}
//If this point is reached, no path could be found
return null;
}
示例8: FleetNodeComputer
import hudson.model.Slave; //导入依赖的package包/类
public FleetNodeComputer(final Slave slave) {
super(slave);
}
示例9: testDefaultSlave
import hudson.model.Slave; //导入依赖的package包/类
@Test public void testDefaultSlave() throws Exception {
Slave slave = createLinuxSlave("default", "", "");
assertFalse(checker.executeCheck(slave));
}
示例10: testWindowsSlave
import hudson.model.Slave; //导入依赖的package包/类
@Test public void testWindowsSlave() throws Exception {
Slave slave = createWindowsSlave("default", "", "somelabel");
assertFalse(checker.executeCheck(slave));
}
示例11: testControlComment
import hudson.model.Slave; //导入依赖的package包/类
@Test public void testControlComment() throws Exception {
Slave slave = createLinuxSlave("default", "", "");
assertFalse(checker.isIgnored(slave.getNodeDescription()));
slave = createLinuxSlave("default", "#lint:ignore:" + checker.getClass().getSimpleName(), "");
assertTrue(checker.isIgnored(slave.getNodeDescription()));
}
示例12: createLinuxSlave
import hudson.model.Slave; //导入依赖的package包/类
private Slave createLinuxSlave(String name, String description, String label) throws Exception {
return new DumbSlave(name, description, "/wherever", "1", Node.Mode.NORMAL, label, new JNLPLauncher(), RetentionStrategy.NOOP, Collections.<NodeProperty<?>>emptyList());
}
示例13: createWindowsSlave
import hudson.model.Slave; //导入依赖的package包/类
private Slave createWindowsSlave(String name, String description, String label) throws Exception {
return new DumbSlave(name, description, "/wherever", "1", Node.Mode.NORMAL, label, new ManagedWindowsServiceLauncher("user", "pass"), RetentionStrategy.NOOP, Collections.<NodeProperty<?>>emptyList());
}
示例14: testDefaultSlave
import hudson.model.Slave; //导入依赖的package包/类
@Test public void testDefaultSlave() throws Exception {
Slave slave = createSlave("default", "", "");
assertFalse(checker.executeCheck(slave));
}
示例15: testControlComment
import hudson.model.Slave; //导入依赖的package包/类
@Test public void testControlComment() throws Exception {
Slave slave = createSlave("default", "", "");
assertFalse(checker.isIgnored(slave.getNodeDescription()));
slave = createSlave("default", "#lint:ignore:" + checker.getClass().getSimpleName(), "");
assertTrue(checker.isIgnored(slave.getNodeDescription()));
}