Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
3cba76c
Add a method isConnected to IComputer and provide implementation in C…
gbhat618 Apr 28, 2025
d4143af
update the tests add sufficient delays after #connect and #disconnect
gbhat618 Apr 29, 2025
b908361
Merge branch 'master' into add-a-isconnected-method
gbhat618 Apr 29, 2025
1fa88d1
add a default implementation in the IComputer for isConnected to keep…
gbhat618 Apr 29, 2025
b3f9dce
Merge branch 'master' into add-a-isconnected-method
gbhat618 Apr 29, 2025
da4af69
Trigger CI: empty commit
gbhat618 Apr 30, 2025
481a261
Merge branch 'master' into add-a-isconnected-method
MarkEWaite May 16, 2025
c075364
Merge branch 'master' into add-a-isconnected-method
timja May 17, 2025
5e9d3be
Merge branch 'master' into add-a-isconnected-method
gbhat618 May 21, 2025
1b5cd55
Merge branch 'master' into add-a-isconnected-method
MarkEWaite May 30, 2025
0570f83
Merge branch 'master' into add-a-isconnected-method
gbhat618 Jun 23, 2025
0917ac6
Merge branch 'master' into add-a-isconnected-method
gbhat618 Jun 23, 2025
65ab6aa
Merge branch 'master' of github.com:jenkinsci/jenkins into add-a-isco…
gbhat618 Jun 26, 2025
9cb3364
add the import of org.hamcrest.Matchers.is
gbhat618 Jun 26, 2025
dd7a177
Merge branch 'master' into add-a-isconnected-method
gbhat618 Jun 30, 2025
9ab6ea6
Merge branch 'master' into add-a-isconnected-method
Vlatombe Jul 21, 2025
88eb0e1
Merge branch 'master' into add-a-isconnected-method
gbhat618 Jul 22, 2025
4ddbcae
Fix the javadocs of interface and inherited methods
gbhat618 Jul 22, 2025
d143222
Merge branch 'master' into add-a-isconnected-method
gbhat618 Jul 22, 2025
b8b31c3
Merge branch 'master' into add-a-isconnected-method
gbhat618 Jul 23, 2025
f7ffe9a
Merge branch 'master' into add-a-isconnected-method
gbhat618 Jul 24, 2025
fb7c01f
Merge branch 'master' into add-a-isconnected-method
gbhat618 Aug 6, 2025
febf944
Merge branch 'master' into add-a-isconnected-method
gbhat618 Aug 12, 2025
fe240d4
Merge branch 'master' into add-a-isconnected-method
gbhat618 Aug 13, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions core/src/main/java/hudson/model/Computer.java
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,10 @@ public final boolean isOnline() {
return !isOffline();
}

public boolean isConnected() {
return getChannel() != null;
}

/**
* This method is called to determine whether manual launching of the agent is allowed at this point in time.
* @return {@code true} if manual launching of the agent is allowed at this point in time.
Expand Down
16 changes: 14 additions & 2 deletions core/src/main/java/jenkins/model/IComputer.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ public interface IComputer extends AccessControlled, IconSpec {
List<? extends IDisplayExecutor> getDisplayExecutors();

/**
* @return {@code true} if the node is offline. {@code false} if it is online.
* Returns whether the agent is offline for scheduling new tasks.
* Even if {@code true}, the agent may still be connected to the controller and executing a task,
* but is considered offline for scheduling.
* @return {@code true} if the agent is offline; {@code false} if online.
* @see #isConnected()
*/
boolean isOffline();

Expand Down Expand Up @@ -192,10 +196,18 @@ default String getIconClassName() {
int countExecutors();

/**
* @return true if the computer is online.
* Indicates whether the agent can accept a new task when it becomes idle.
* {@code false} does not necessarily mean the agent is disconnected.
* @return {@code true} if the agent is online.
* @see #isConnected()
*/
boolean isOnline();

/**
* @return {@code true} if the agent is connected to the controller.
*/
boolean isConnected();

/**
* @return the number of {@link IExecutor}s that are idle right now.
*/
Expand Down
33 changes: 33 additions & 0 deletions test/src/test/java/hudson/model/ComputerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -311,4 +311,37 @@ public void computersCollected() throws Exception {
MemoryAssert.assertGC(channelRef, false);
}

@Test
public void isConnectedTest() throws Exception {
var agent = j.createSlave();
var computer = agent.toComputer();

// Verify initial state: computer is not connected
assertThat(computer.isOnline(), is(false));
assertThat(computer.isConnected(), is(false));

// Connect the computer
computer.connect(false);
await("computer should be online after connect").until(() -> computer.isOnline(), is(true));
assertThat(computer.isConnected(), is(true));
assertThat(computer.isOffline(), is(false));

// Mark computer temporary offline
computer.doToggleOffline(null);
assertThat("temporary offline agent is still connected", computer.isConnected(), is(true));
assertThat("temporary offline agent is not available for scheduling", computer.isOnline(), is(false));
assertThat(computer.isOffline(), is(true));

// Bring it back online
computer.doToggleOffline(null);
assertThat(computer.isOnline(), is(true));
assertThat(computer.isConnected(), is(true)); // channel is still there.

// Disconnect the computer
computer.disconnect(new OfflineCause.UserCause(null, null));
// wait for the slave process to be killed
await("disconnected agent is not available for scheduling").until(() -> computer.isOnline(), is(false));
assertThat(computer.isConnected(), is(false));
assertThat(computer.isOffline(), is(true));
}
}
Loading