Skip to content
Permalink
Browse files

Check if agent is disabled before job assignment

* Fix for #3747
* BuildAssignmentService#assignWorkToAgent has a check to verify if an
  agent is disabled. The actual assignment happens in a synchronized
  block, by the time a thread enters the block the agent could be
  disabled. This commit ensures that an agent is not disabled within the
  synchronized block.
* Disabled agents are refreshed now, this ensures if a disabled agent is
  running a job and loses contact the job can be reschuduled.
  • Loading branch information...
maheshp committed Aug 14, 2017
1 parent 9bf0823 commit e538ba0032fcdd6cc8c95d202267deeb6c46a979
@@ -168,7 +168,7 @@ public boolean canApprove() {
}

public void refresh(final AgentRuntimeStatus.ChangeListener changeListener) {
if (agentConfigStatus == AgentConfigStatus.Pending || agentConfigStatus == AgentConfigStatus.Disabled) {
if (agentConfigStatus == AgentConfigStatus.Pending) {
return;
}
if (lastHeardTime == null) {
@@ -322,16 +322,19 @@ public int getAgentConnectionTimeout() {
}

@Test
public void shouldNotRefreshDeniedAgent() throws Exception {
public void shouldRefreshDisabledAgent() throws Exception {
agentConfig.disable();
AgentInstance instance = AgentInstance.createFromConfig(agentConfig, new SystemEnvironment() {
public int getAgentConnectionTimeout() {
return -1;
}
});
instance.update(new AgentRuntimeInfo(agentConfig.getAgentIdentifier(), AgentRuntimeStatus.Idle, currentWorkingDirectory(), "cookie", false));
instance.update(new AgentRuntimeInfo(agentConfig.getAgentIdentifier(), AgentRuntimeStatus.Building, currentWorkingDirectory(), "cookie", false));

instance.refresh(null);
assertThat(instance.getStatus().getRuntimeStatus(), is(not(AgentRuntimeStatus.LostContact)));

assertThat(instance.getRuntimeStatus(), is(AgentRuntimeStatus.LostContact));
assertThat(instance.getStatus(), is(AgentStatus.Disabled));
}

@Test
@@ -143,6 +143,10 @@ Work assignWorkToAgent(final AgentInstance agent) {
}

synchronized (this) {
// check to ensure agent is not disabled after entering the synchronized block
if (agent.isDisabled()) {
return new DeniedAgentWork(agent.getUuid());
}
//check if agent already has assigned build, if so, reschedule it
scheduleService.rescheduleAbandonedBuildIfNecessary(agent.getAgentIdentifier());
final JobPlan job = findMatchingJob(agent);

0 comments on commit e538ba0

Please sign in to comment.
You can’t perform that action at this time.