Skip to content

Commit

Permalink
Rename terminology on JenkinsRule and deprecated methods
Browse files Browse the repository at this point in the history
  • Loading branch information
jonesbusy committed Dec 28, 2023
1 parent c4d3d55 commit c83930a
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 20 deletions.
4 changes: 2 additions & 2 deletions src/main/java/hudson/slaves/DummyCloudImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ public Node call() throws Exception {
// since it's normally some async operation.
Thread.sleep(time);

System.out.println("launching slave");
final DumbSlave slave = rule.createSlave(label);
System.out.println("launching agent");
final DumbSlave slave = rule.createAgent(label);
for (NodeProperty nodeProperty : nodeProperties) {
slave.getNodeProperties().add(updateWithNode(nodeProperty, slave));
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jvnet/hudson/test/InboundAgentRule.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
* </pre>
*
* @see JenkinsRule#createComputerLauncher
* @see JenkinsRule#createSlave()
* @see JenkinsRule#createAgent()
*/
public final class InboundAgentRule extends ExternalResource {

Expand Down
142 changes: 126 additions & 16 deletions src/main/java/org/jvnet/hudson/test/JenkinsRule.java
Original file line number Diff line number Diff line change
Expand Up @@ -976,9 +976,18 @@ public File createTmpDir() throws IOException {
return env.temporaryDirectoryAllocator.allocate();
}

/**
* @deprecated Use {@link createAgent} instead.
*/
@NonNull
@Deprecated
public DumbSlave createSlave(boolean waitForChannelConnect) throws Exception {
DumbSlave slave = createSlave();
return createAgent(waitForChannelConnect);
}

@NonNull
public DumbSlave createAgent(boolean waitForChannelConnect) throws Exception {
DumbSlave slave = createAgent();
if (waitForChannelConnect) {
long start = System.currentTimeMillis();
while (slave.getChannel() == null) {
Expand All @@ -991,10 +1000,17 @@ public DumbSlave createSlave(boolean waitForChannelConnect) throws Exception {
return slave;
}

/**
* @deprecated Use {@link disconnectAgent} instead.
*/
public void disconnectSlave(DumbSlave slave) throws Exception {

Check warning on line 1006 in src/main/java/org/jvnet/hudson/test/JenkinsRule.java

View check run for this annotation

ci.jenkins.io / Java Compiler

gplus:execute

NORMAL: deprecated item is not annotated with @deprecated

Check warning on line 1006 in src/main/java/org/jvnet/hudson/test/JenkinsRule.java

View check run for this annotation

ci.jenkins.io / Java Compiler

compiler:compile

NORMAL: deprecated item is not annotated with @deprecated
slave.getComputer().disconnect(new OfflineCause.ChannelTermination(new Exception("terminate")));
disconnectAgent(slave);
}

public void disconnectAgent(DumbSlave agent) throws Exception {
agent.getComputer().disconnect(new OfflineCause.ChannelTermination(new Exception("terminate")));
long start = System.currentTimeMillis();
while (slave.getChannel() != null) {
while (agent.getChannel() != null) {
if (System.currentTimeMillis() > (start + 10000)) {
throw new IllegalStateException("Timed out waiting on DumbSlave channel to disconnect.");
}
Expand All @@ -1007,16 +1023,33 @@ public void disconnectSlave(DumbSlave slave) throws Exception {
* @see InboundAgentRule
*/
@NonNull
public DumbSlave createAgent() throws Exception {
return createAgent("",null);
}

/**
* @deprecated Use {@link createAgent} instead.
*/
@NonNull
public DumbSlave createSlave() throws Exception {

Check warning on line 1034 in src/main/java/org/jvnet/hudson/test/JenkinsRule.java

View check run for this annotation

ci.jenkins.io / Java Compiler

gplus:execute

NORMAL: deprecated item is not annotated with @deprecated

Check warning on line 1034 in src/main/java/org/jvnet/hudson/test/JenkinsRule.java

View check run for this annotation

ci.jenkins.io / Java Compiler

compiler:compile

NORMAL: deprecated item is not annotated with @deprecated
return createSlave("",null);
return createAgent();
}

/**
* Creates and launches a new slave on the local host.
* @deprecated Use {@link createAgent} instead.
*/
@Deprecated
@NonNull
public DumbSlave createSlave(@CheckForNull Label l) throws Exception {
return createSlave(l, null);
return createAgent(l, null);
}

/**
* Creates and launches a new slave on the local host.
*/
@NonNull
public DumbSlave createAgent(@CheckForNull Label l) throws Exception {
return createAgent(l, null);
}

/**
Expand Down Expand Up @@ -1086,29 +1119,65 @@ public URL getURL() throws IOException {
return new URL("http://localhost:"+localPort+contextPath+"/");
}

/**
* @deprecated Use {@link createAgent} instead.
*/
@Deprecated
@NonNull
public DumbSlave createSlave(@CheckForNull EnvVars env) throws Exception {
return createSlave("",env);
return createAgent(env);
}

@NonNull
public DumbSlave createAgent(@CheckForNull EnvVars env) throws Exception {
return createAgent("",env);
}

/**
* @deprecated Use {@link createAgent} instead.
*/
@Deprecated
@NonNull
public DumbSlave createSlave(@CheckForNull Label l, @CheckForNull EnvVars env) throws Exception {
return createSlave(l==null ? null : l.getExpression(), env);
return createAgent(l, env);
}

@NonNull
public DumbSlave createAgent(@CheckForNull Label l, @CheckForNull EnvVars env) throws Exception {
return createAgent(l==null ? null : l.getExpression(), env);
}

/**
* Creates a slave with certain additional environment variables
* @deprecated Use {@link createAgent} instead.
*/
@Deprecated
@NonNull
public DumbSlave createSlave(@CheckForNull String labels, @CheckForNull EnvVars env) throws Exception {
return createAgent(labels, env);
}

/**
* Creates an agent with certain additional environment variables
*/
@NonNull
public DumbSlave createAgent(@CheckForNull String labels, @CheckForNull EnvVars env) throws Exception {
synchronized (jenkins) {
int sz = jenkins.getNodes().size();
return createSlave("slave" + sz,labels,env);
return createAgent("slave" + sz,labels,env);
}
}

/**
* @deprecated Use {@link createAgent} instead.
*/
@Deprecated
@NonNull
public DumbSlave createSlave(@NonNull String nodeName, @CheckForNull String labels, @CheckForNull EnvVars env) throws Exception {
return createAgent(nodeName, labels, env);
}

@NonNull
public DumbSlave createAgent(@NonNull String nodeName, @CheckForNull String labels, @CheckForNull EnvVars env) throws Exception {
synchronized (jenkins) {
DumbSlave slave = new DumbSlave(nodeName, new File(jenkins.getRootDir(), "agent-work-dirs/" + nodeName).getAbsolutePath(), createComputerLauncher(env));
if (labels != null) {
Expand All @@ -1120,7 +1189,15 @@ public DumbSlave createSlave(@NonNull String nodeName, @CheckForNull String labe
}
}

/**
* @deprecated Use {@link createPretendAgent} instead.
*/
@Deprecated
public PretendSlave createPretendSlave(FakeLauncher faker) throws Exception {
return createPretendAgent(faker);
}

public PretendSlave createPretendAgent(FakeLauncher faker) throws Exception {
synchronized (jenkins) {
int sz = jenkins.getNodes().size();
String nodeName = "slave" + sz;
Expand Down Expand Up @@ -1152,30 +1229,63 @@ public ComputerLauncher createComputerLauncher(@CheckForNull EnvVars env) throws
/**
* Create a new slave on the local host and wait for it to come online
* before returning.
* @deprecated Use {@link #createOnlineAgent} instead.
*/
@Deprecated
@NonNull
public DumbSlave createOnlineSlave() throws Exception {
return createOnlineSlave(null);
return createOnlineAgent();
}

/**
* Create a new agent on the local host and wait for it to come online
* before returning.
*/
@NonNull
public DumbSlave createOnlineAgent() throws Exception {
return createOnlineAgent(null);
}

/**
* Create a new slave on the local host and wait for it to come online
* before returning.
* @deprecated Use {@link #createOnlineAgent} instead.
*/
@NonNull
@Deprecated
public DumbSlave createOnlineSlave(@CheckForNull Label l) throws Exception {
return createOnlineSlave(l, null);
return createOnlineAgent(l, null);
}

/**
* Create a new slave on the local host and wait for it to come online
* before returning.
*/
@NonNull
public DumbSlave createOnlineAgent(@CheckForNull Label l) throws Exception {
return createOnlineAgent(l, null);
}

/**
* Create a new slave on the local host and wait for it to come online
* before returning
* @deprecated Use {@link #createOnlineAgent} instead.
* @see #waitOnline
*/
@NonNull
@SuppressWarnings({"deprecation"})
@Deprecated
public DumbSlave createOnlineSlave(@CheckForNull Label l, @CheckForNull EnvVars env) throws Exception {
DumbSlave s = createSlave(l, env);
return createOnlineAgent(l, env);
}

/**
* Create a new agent on the local host and wait for it to come online
* before returning
* @see #waitOnline
*/
@NonNull
public DumbSlave createOnlineAgent(@CheckForNull Label l, @CheckForNull EnvVars env) throws Exception {
DumbSlave s = createAgent(l, env);
waitOnline(s);
return s;
}
Expand All @@ -1198,8 +1308,8 @@ public DumbSlave createOnlineSlave(@CheckForNull Label l, @CheckForNull EnvVars
}

/**
* Waits for a newly created slave to come online.
* @see #createSlave()
* Waits for a newly created agent to come online.
* @see #createAgent()
*/
public void waitOnline(Slave s) throws Exception {
Computer computer = s.toComputer();
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/org/jvnet/hudson/test/JenkinsRuleTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ public String getSetterParam() {

@Test
public void serialization() throws Exception {
j.createSlave("agent", "agent", new EnvVars());
j.createAgent("agent", "agent", new EnvVars());
j.jenkins.save();
}

Expand Down

0 comments on commit c83930a

Please sign in to comment.