private ElasticAgentRuntimeInfo(AgentRuntimeInfo runtimeInfo, String elasticAgentId, String elasticPluginId) { this(runtimeInfo.getIdentifier(), runtimeInfo.getRuntimeStatus(), runtimeInfo.getLocation(), runtimeInfo.getCookie(), elasticAgentId, elasticPluginId); this.setOperatingSystem(runtimeInfo.getOperatingSystem()); this.setUsableSpace(runtimeInfo.getUsableSpace()); }
private AgentRuntimeInfo cancelRuntimeInfo() { AgentRuntimeInfo agentRuntimeInfo = new AgentRuntimeInfo(agentConfig.getAgentIdentifier(), AgentRuntimeStatus.Idle, currentWorkingDirectory(), "cookie", false); agentRuntimeInfo.busy(defaultBuildingInfo); agentRuntimeInfo.cancel(); return agentRuntimeInfo; }
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); }
public void updateSelf(AgentRuntimeInfo newRuntimeInfo) { this.buildingInfo = newRuntimeInfo.getBuildingInfo(); if (newRuntimeInfo.isCancelled()) { this.setRuntimeStatus(AgentRuntimeStatus.Cancelled); } this.location = newRuntimeInfo.getLocation(); this.usableSpace = newRuntimeInfo.getUsableSpace(); this.operatingSystemName = newRuntimeInfo.getOperatingSystem(); this.supportsBuildCommandProtocol = newRuntimeInfo.getSupportsBuildCommandProtocol(); }
public String agentInfoForDisplay() { return format("Agent located at [%s, %s, %s]", getHostName(), getIpAdress(), getLocation()); }
public String agentInfoDebugString() { return format("Agent [%s, %s, %s, %s]", getHostName(), getIpAdress(), getUUId(), cookie); }
@Test public void shouldUpdateSelfForAnIdleAgent() { AgentRuntimeInfo agentRuntimeInfo = new AgentRuntimeInfo(new AgentIdentifier("localhost", "127.0.0.1", "uuid"), AgentRuntimeStatus.Idle, currentWorkingDirectory(), null, false); AgentRuntimeInfo newRuntimeInfo = new AgentRuntimeInfo(new AgentIdentifier("go02", "10.10.10.1", "uuid"), AgentRuntimeStatus.Idle, currentWorkingDirectory(), "cookie", false); newRuntimeInfo.setBuildingInfo(new AgentBuildingInfo("Idle", "")); newRuntimeInfo.setLocation("home"); newRuntimeInfo.setUsableSpace(10L); newRuntimeInfo.setOperatingSystem("Linux"); agentRuntimeInfo.updateSelf(newRuntimeInfo); assertThat(agentRuntimeInfo.getBuildingInfo(), is(newRuntimeInfo.getBuildingInfo())); assertThat(agentRuntimeInfo.getLocation(), is(newRuntimeInfo.getLocation())); assertThat(agentRuntimeInfo.getUsableSpace(), is(newRuntimeInfo.getUsableSpace())); assertThat(agentRuntimeInfo.getOperatingSystem(), is(newRuntimeInfo.getOperatingSystem())); }
@Before public void setup() { AgentIdentifier agentIdentifier = new AgentIdentifier("duloc", "127.0.0.1", "uuid"); AgentRuntimeInfo runtimeInfo = new AgentRuntimeInfo(agentIdentifier, AgentRuntimeStatus.Idle, "/home/lord-farquaad/builds", "cookie", false); bvs = new BuildVariables(runtimeInfo, new TestingClock(new Date(0))); }
AgentRuntimeInfo info = MessageEncoding.decodeData(msg.getData(), AgentRuntimeInfo.class); if (!sessionIds.containsKey(agent)) { LOGGER.info("{} is connected with websocket {}", info.getIdentifier(), agent); sessionIds.put(agent, info.getUUId()); this.agentSessions.put(info.getUUId(), agent); if (info.getCookie() == null) { String cookie = agentCookie.get(agent); if (cookie == null) { cookie = buildRepositoryRemote.getCookie(info.getIdentifier(), info.getLocation()); agentCookie.put(agent, cookie); info.setCookie(cookie); agent.send(new Message(Action.setCookie, MessageEncoding.encodeData(cookie)));
agentController.getAgentRuntimeInfo().setSupportsBuildCommandProtocol(true); final BuildSettings build = new BuildSettings(); build.setBuildId("b001"); agentRuntimeInfo.busy(new AgentBuildingInfo("build1ForDisplay", "build1")); agentRuntimeInfo.cancel(); assertThat(agentController.getAgentRuntimeInfo().getRuntimeStatus(), is(AgentRuntimeStatus.Idle));
private AgentRuntimeInfo buildingRuntimeInfo(AgentConfig agentConfig) { AgentRuntimeInfo runtimeInfo = new AgentRuntimeInfo(agentConfig.getAgentIdentifier(), AgentRuntimeStatus.Idle, currentWorkingDirectory(), "cookie", false); runtimeInfo.busy(defaultBuildingInfo); return runtimeInfo; } }
private void retrieveCookieIfNecessary() { if (!getAgentRuntimeInfo().hasCookie() && sslInfrastructureService.isRegistered()) { LOG.info("About to get cookie from the server."); String cookie = server.getCookie(agentIdentifier(), getAgentRuntimeInfo().getLocation()); getAgentRuntimeInfo().setCookie(cookie); LOG.info("Got cookie: {}", cookie); } }
BuildSession build = new BuildSession( buildSettings.getBuildId(), getAgentRuntimeInfo().getIdentifier(), buildStateReporter, buildConsole, getAgentRuntimeInfo().idle(); try { getAgentRuntimeInfo().busy(new AgentBuildingInfo(buildSettings.getBuildLocatorForDisplay(), buildSettings.getBuildLocator())); build.build(buildSettings.getBuildCommand()); } finally { buildConsole.stop(); } finally { getAgentRuntimeInfo().idle();
public boolean isIdle() { return agentRuntimeInfo.getRuntimeStatus() == AgentRuntimeStatus.Idle; }
assertThat(agentController.getAgentRuntimeInfo().getRuntimeStatus(), is(AgentRuntimeStatus.Idle)); agentRuntimeInfo.busy(new AgentBuildingInfo("build1ForDisplay", "build1"));
public AgentIdentifier getAgentIdentifier() { return agent.getIdentifier(); } }
public static AgentInstance idle(final Date lastHeardAt, final String hostname, SystemEnvironment systemEnvironment) { AgentConfig idleAgentConfig = new AgentConfig("uuid2", hostname, "10.18.5.1"); AgentRuntimeInfo agentRuntimeInfo = new AgentRuntimeInfo(idleAgentConfig.getAgentIdentifier(), AgentRuntimeStatus.Idle, currentWorkingDirectory(), "cookie", false); agentRuntimeInfo.setLocation("/var/lib/foo"); agentRuntimeInfo.idle(); agentRuntimeInfo.setUsableSpace(10 * 1024l); AgentInstance agentInstance = AgentInstance.createFromLiveAgent(agentRuntimeInfo, systemEnvironment, mock(AgentStatusChangeListener.class)); agentInstance.idle(); agentInstance.update(agentRuntimeInfo); ReflectionUtil.setField(agentInstance, "lastHeardTime", lastHeardAt); return agentInstance; }
@Test public void shouldBeUnknownWhenRegistrationRequestIsFromLocalAgent() { AgentRuntimeInfo agentRuntimeInfo = AgentRuntimeInfo.fromServer( new AgentConfig("uuid", "localhost", "176.19.4.1"), false, "/var/lib", 0L, "linux", false); assertThat(agentRuntimeInfo.getRuntimeStatus(), is(AgentRuntimeStatus.Unknown)); }
private AgentRuntimeInfo idleRuntimeInfo() { AgentRuntimeInfo agentRuntimeInfo = new AgentRuntimeInfo(agentConfig.getAgentIdentifier(), AgentRuntimeStatus.Idle, currentWorkingDirectory(), "cookie", false); agentRuntimeInfo.idle(); return agentRuntimeInfo; }
@Test public void shouldNotChangePendingAgentIpAddress() throws Exception { AgentInstance pending = AgentInstance.createFromLiveAgent(new AgentRuntimeInfo(agentConfig.getAgentIdentifier(), AgentRuntimeStatus.Idle, currentWorkingDirectory(), "cookie", false), systemEnvironment, mock(AgentStatusChangeListener.class)); AgentRuntimeInfo info = new AgentRuntimeInfo(new AgentIdentifier("ccedev01", "10.18.7.52", "uuid"), AgentRuntimeStatus.Idle, currentWorkingDirectory(), "cookie", false); assertThat(pending.isIpChangeRequired(info.getIpAdress()), is(false)); }