@Test public void shouldTellIfHasCookie() throws Exception { assertThat(new AgentRuntimeInfo(new AgentIdentifier("localhost", "127.0.0.1", "uuid"), AgentRuntimeStatus.Idle, currentWorkingDirectory(), "cookie", false).hasDuplicateCookie("cookie"), is(false)); assertThat(new AgentRuntimeInfo(new AgentIdentifier("localhost", "127.0.0.1", "uuid"), AgentRuntimeStatus.Idle, currentWorkingDirectory(), "cookie", false).hasDuplicateCookie("different"), is(true)); assertThat(new AgentRuntimeInfo(new AgentIdentifier("localhost", "127.0.0.1", "uuid"), AgentRuntimeStatus.Idle, currentWorkingDirectory(), null, false).hasDuplicateCookie("cookie"), is(false)); assertThat(new AgentRuntimeInfo(new AgentIdentifier("localhost", "127.0.0.1", "uuid"), AgentRuntimeStatus.Idle, currentWorkingDirectory(), "cookie", false).hasDuplicateCookie(null), is(false)); }
public void updateRuntimeInfo(AgentRuntimeInfo info) { if (!info.hasCookie()) { LOGGER.warn("Agent [{}] has no cookie set", info.agentInfoDebugString()); throw new AgentNoCookieSetException(format("Agent [%s] has no cookie set", info.agentInfoDebugString())); } if (info.hasDuplicateCookie(agentDao.cookieFor(info.getIdentifier()))) { LOGGER.warn("Found agent [{}] with duplicate uuid. Please check the agent installation.", info.agentInfoDebugString()); serverHealthService.update( ServerHealthState.warning(format("[%s] has duplicate unique identifier which conflicts with [%s]", info.agentInfoForDisplay(), findAgentAndRefreshStatus(info.getUUId()).agentInfoForDisplay()), "Please check the agent installation. Click <a href='" + docsUrl("/faq/agent_guid_issue.html") + "' target='_blank'>here</a> for more info.", HealthStateType.duplicateAgent(HealthStateScope.forAgent(info.getCookie())), Timeout.THIRTY_SECONDS)); throw new AgentWithDuplicateUUIDException(format("Agent [%s] has invalid cookie", info.agentInfoDebugString())); } AgentInstance agentInstance = findAgentAndRefreshStatus(info.getUUId()); if (agentInstance.isIpChangeRequired(info.getIpAdress())) { AgentConfig agentConfig = agentInstance.agentConfig(); Username userName = agentUsername(info.getUUId(), info.getIpAdress(), agentConfig.getHostNameForDisplay()); LOGGER.warn("Agent with UUID [{}] changed IP Address from [{}] to [{}]", info.getUUId(), agentConfig.getIpAddress(), info.getIpAdress()); agentConfigService.updateAgentIpByUuid(agentConfig.getUuid(), info.getIpAdress(), userName); } agentInstances.updateAgentRuntimeInfo(info); }