public String getIpAddress() { return agentConfig.getIpAddress(); }
public boolean isIpChangeRequired(String newIpAdress) { return !StringUtils.equals(this.agentConfig.getIpAddress(), newIpAdress) && this.isRegistered(); }
private void syncIp(AgentRuntimeInfo info) { String ipAddress = (agentType == AgentType.LOCAL || agentType == AgentType.REMOTE) ? info.getIpAdress() : agentConfig.getIpAddress(); this.agentConfig.setIpAddress(ipAddress); }
private void validateIpAddress() { String address = getIpAddress(); if (address == null) { return; } if (StringUtils.isBlank(address)) { addError(IP_ADDRESS, "IpAddress cannot be empty if it is present."); return; } try { IpAddress.create(address); } catch (Exception e) { addError(IP_ADDRESS, String.format("'%s' is an invalid IP address.", address)); } }
public static Agent fromConfig(AgentConfig config) { return new Agent(config.getUuid(), "None", config.getHostNameForDisplay(), config.getIpAddress()); }
public static AgentRuntimeInfo fromServer(AgentConfig agentConfig, boolean registeredAlready, String location, Long usablespace, String operatingSystem, boolean supportsBuildCommandProtocol) { if (StringUtils.isEmpty(location)) { throw new RuntimeException("Agent should not register without installation path."); } AgentStatus status = AgentStatus.Pending; if (SystemUtil.isLocalIpAddress(agentConfig.getIpAddress()) || registeredAlready) { status = AgentStatus.Idle; } AgentRuntimeInfo agentRuntimeInfo = new AgentRuntimeInfo(agentConfig.getAgentIdentifier(), status.getRuntimeStatus(), location, null, supportsBuildCommandProtocol); agentRuntimeInfo.setUsableSpace(usablespace); agentRuntimeInfo.operatingSystemName = operatingSystem; return agentRuntimeInfo; }
public AgentIdentifier getAgentIdentifier() { return new AgentIdentifier(this.getHostname(), getIpAddress(), getUuid()); }
@Test public void shouldUpdateIPForPhysicalMachineWhenUpChanged() throws Exception { AgentInstance agentInstance = AgentInstance.createFromConfig(agentConfig, systemEnvironment, mock(AgentStatusChangeListener.class)); agentInstance.update(new AgentRuntimeInfo(new AgentIdentifier("ccedev01", "10.18.7.52", "uuid"), AgentRuntimeStatus.Idle, currentWorkingDirectory(), "cookie", false)); assertThat(agentInstance.agentConfig().getIpAddress(), is("10.18.7.52")); }
public static AgentInstance updateHostname(AgentInstance agentInstance, String hostname) { AgentConfig original = agentInstance.agentConfig(); agentInstance.syncConfig(new AgentConfig(original.getUuid(), hostname, original.getIpAddress(), original.getResourceConfigs())); return agentInstance; }
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); }
@Test public void shouldDenyAgentWhenAgentIsDeniedInConfigFile() throws Exception { AgentInstance original = AgentInstance.createFromConfig(agentConfig, systemEnvironment, mock(AgentStatusChangeListener.class)); original.update(buildingRuntimeInfo()); AgentConfig newAgentConfig = new AgentConfig(agentConfig.getUuid(), agentConfig.getHostname(), agentConfig.getIpAddress()); newAgentConfig.disable(); original.syncConfig(newAgentConfig); assertThat(original.getStatus(), is(AgentStatus.Disabled)); }
@Test public void shouldSupportMultipleAgentsFromSameBox() throws Exception { CruiseConfig cruiseConfig = xmlLoader.loadConfigHolder(ConfigMigrator.migrate(WITH_MULTIPLE_LOCAL_AGENT_CONFIG)).config; assertThat(cruiseConfig.agents().size(), is(2)); assertThat(cruiseConfig.agents().get(0).getHostname(), is(cruiseConfig.agents().get(1).getHostname())); assertThat(cruiseConfig.agents().get(0).getIpAddress(), is(cruiseConfig.agents().get(1).getIpAddress())); assertThat(cruiseConfig.agents().get(0).getUuid(), is(not(cruiseConfig.agents().get(1).getUuid()))); }