Search in sources :

Example 1 with MaxPendingAgentsLimitReachedException

use of com.thoughtworks.go.domain.exception.MaxPendingAgentsLimitReachedException in project gocd by gocd.

the class AgentInstances method register.

public AgentInstance register(AgentRuntimeInfo runtimeInfo) {
    AgentInstance agentInstance = findAgentAndRefreshStatus(runtimeInfo.getUUId());
    if (!agentInstance.isRegistered()) {
        if (isMaxPendingAgentsLimitReached()) {
            throw new MaxPendingAgentsLimitReachedException(systemEnvironment.get(MAX_PENDING_AGENTS_ALLOWED));
        }
        agentInstance = AgentInstance.createFromLiveAgent(runtimeInfo, systemEnvironment, agentStatusChangeListener);
        this.add(agentInstance);
    }
    agentInstance.update(runtimeInfo);
    return agentInstance;
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) NullAgentInstance(com.thoughtworks.go.domain.NullAgentInstance) MaxPendingAgentsLimitReachedException(com.thoughtworks.go.domain.exception.MaxPendingAgentsLimitReachedException)

Example 2 with MaxPendingAgentsLimitReachedException

use of com.thoughtworks.go.domain.exception.MaxPendingAgentsLimitReachedException in project gocd by gocd.

the class AgentInstancesTest method registerShouldThrowExceptionWhenMaxPendingAgentsLimitIsReached.

@Test
void registerShouldThrowExceptionWhenMaxPendingAgentsLimitIsReached() {
    Agent agent = new Agent("uuid2", "CCeDev01", "10.18.5.1");
    AgentInstances agentInstances = new AgentInstances(systemEnvironment, listener, pending());
    when(systemEnvironment.get(MAX_PENDING_AGENTS_ALLOWED)).thenReturn(1);
    MaxPendingAgentsLimitReachedException e = assertThrows(MaxPendingAgentsLimitReachedException.class, () -> agentInstances.register(fromServer(agent, false, "/var/lib", 0L, "linux")));
    assertThat(e.getMessage(), is("Max pending agents allowed 1, limit reached"));
}
Also used : AgentInstance.createFromLiveAgent(com.thoughtworks.go.domain.AgentInstance.createFromLiveAgent) AgentInstance.createFromAgent(com.thoughtworks.go.domain.AgentInstance.createFromAgent) Agent(com.thoughtworks.go.config.Agent) MaxPendingAgentsLimitReachedException(com.thoughtworks.go.domain.exception.MaxPendingAgentsLimitReachedException) Test(org.junit.jupiter.api.Test)

Aggregations

MaxPendingAgentsLimitReachedException (com.thoughtworks.go.domain.exception.MaxPendingAgentsLimitReachedException)2 Agent (com.thoughtworks.go.config.Agent)1 AgentInstance (com.thoughtworks.go.domain.AgentInstance)1 AgentInstance.createFromAgent (com.thoughtworks.go.domain.AgentInstance.createFromAgent)1 AgentInstance.createFromLiveAgent (com.thoughtworks.go.domain.AgentInstance.createFromLiveAgent)1 NullAgentInstance (com.thoughtworks.go.domain.NullAgentInstance)1 Test (org.junit.jupiter.api.Test)1