public Registration requestRegistration(Username username, AgentRuntimeInfo agentRuntimeInfo) { LOGGER.debug("Agent is requesting registration {}", agentRuntimeInfo); AgentInstance agentInstance = agentInstances.register(agentRuntimeInfo); Registration registration = agentInstance.assignCertification(); if (agentInstance.isRegistered()) { agentConfigService.saveOrUpdateAgent(agentInstance, username); LOGGER.debug("New Agent approved {}", agentRuntimeInfo); } return registration; }
public void run() { int count = 0; while (!stop) { AgentConfig agentConfig = new AgentConfig("uuid" + count, "CCeDev_" + count, "10.18.5." + count); agentInstances.register(AgentRuntimeInfo.fromServer(agentConfig, false, "/var/lib", Long.MAX_VALUE, "linux", false)); count++; } }
@Test public void agentHostnameShouldBeUnique() { AgentConfig agentConfig = new AgentConfig("uuid2", "CCeDev01", "10.18.5.1"); AgentInstances agentInstances = new AgentInstances(mock(AgentStatusChangeListener.class)); agentInstances.register(AgentRuntimeInfo.fromServer(agentConfig, false, "/var/lib", 0L, "linux", false)); agentInstances.register(AgentRuntimeInfo.fromServer(agentConfig, false, "/var/lib", 0L, "linux", false)); }
@Test(expected = MaxPendingAgentsLimitReachedException.class) public void registerShouldErrorOutIfMaxPendingAgentsLimitIsReached() { AgentConfig agentConfig = new AgentConfig("uuid2", "CCeDev01", "10.18.5.1"); AgentInstances agentInstances = new AgentInstances(systemEnvironment, agentStatusChangeListener, AgentInstanceMother.pending()); when(systemEnvironment.get(SystemEnvironment.MAX_PENDING_AGENTS_ALLOWED)).thenReturn(1); agentInstances.register(AgentRuntimeInfo.fromServer(agentConfig, false, "/var/lib", 0L, "linux", false)); }
@Test public void shouldSupportConcurrentOperations() throws Exception { final AgentInstances agentInstances = new AgentInstances(mock(AgentStatusChangeListener.class)); // register 100 agents for (int i = 0; i < 100; i++) { AgentConfig agentConfig = new AgentConfig("uuid" + i, "CCeDev_" + i, "10.18.5." + i); agentInstances.register(AgentRuntimeInfo.fromServer(agentConfig, false, "/var/lib", Long.MAX_VALUE, "linux", false)); } thrown.expect(MaxPendingAgentsLimitReachedException.class); thrown.expectMessage("Max pending agents allowed 100, limit reached"); AgentConfig agentConfig = new AgentConfig("uuid" + 200, "CCeDev_" + 200, "10.18.5." + 200); agentInstances.register(AgentRuntimeInfo.fromServer(agentConfig, false, "/var/lib", Long.MAX_VALUE, "linux", false)); }