private AgentRuntimeInfo idleRuntimeInfo() { AgentRuntimeInfo agentRuntimeInfo = new AgentRuntimeInfo(agentConfig.getAgentIdentifier(), AgentRuntimeStatus.Idle, currentWorkingDirectory(), "cookie", false); agentRuntimeInfo.idle(); return agentRuntimeInfo; }
private AgentRuntimeInfo buildingRuntimeInfo(AgentConfig agentConfig) { AgentRuntimeInfo runtimeInfo = new AgentRuntimeInfo(agentConfig.getAgentIdentifier(), AgentRuntimeStatus.Idle, currentWorkingDirectory(), "cookie", false); runtimeInfo.busy(defaultBuildingInfo); return runtimeInfo; } }
public static AgentRuntimeInfo initialState(AgentConfig agentConfig) { AgentRuntimeInfo agentRuntimeInfo = new AgentRuntimeInfo(agentConfig.getAgentIdentifier(), AgentStatus.fromRuntime(AgentRuntimeStatus.Missing).getRuntimeStatus(), "", null, false); if (agentConfig.isElastic()) { agentRuntimeInfo = ElasticAgentRuntimeInfo.fromServer(agentRuntimeInfo, agentConfig.getElasticAgentId(), agentConfig.getElasticPluginId()); } return agentRuntimeInfo; }
@Test public void shouldInitializeTheLastHeardTimeWhenFirstPing() throws Exception { AgentInstance agentInstance = AgentInstance.createFromConfig(agentConfig, systemEnvironment, mock(AgentStatusChangeListener.class)); Date time = agentInstance.getLastHeardTime(); assertThat(time, is(nullValue())); agentInstance.update(new AgentRuntimeInfo(agentConfig.getAgentIdentifier(), AgentRuntimeStatus.Idle, currentWorkingDirectory(), "cookie", false)); time = agentInstance.getLastHeardTime(); assertThat(time, is(not(nullValue()))); }
@Test public void shouldUpdateTheLastHeardTime() throws Exception { AgentInstance agentInstance = AgentInstance.createFromConfig(agentConfig, systemEnvironment, mock(AgentStatusChangeListener.class)); agentInstance.update(new AgentRuntimeInfo(agentConfig.getAgentIdentifier(), AgentRuntimeStatus.Idle, currentWorkingDirectory(), "cookie", false)); Date time = agentInstance.getLastHeardTime(); Thread.sleep(1000); agentInstance.update(new AgentRuntimeInfo(agentConfig.getAgentIdentifier(), AgentRuntimeStatus.Idle, currentWorkingDirectory(), "cookie", false)); Date newtime = agentInstance.getLastHeardTime(); assertThat(newtime.after(time), is(true)); }
@Test public void shouldBecomeIdleAfterApprove() throws Exception { AgentInstance instance = AgentInstance.createFromLiveAgent(new AgentRuntimeInfo(agentConfig.getAgentIdentifier(), AgentRuntimeStatus.Idle, currentWorkingDirectory(), "cookie", false), systemEnvironment, mock(AgentStatusChangeListener.class)); instance.enable(); instance.update(new AgentRuntimeInfo(agentConfig.getAgentIdentifier(), AgentRuntimeStatus.Idle, currentWorkingDirectory(), "cookie", false)); assertThat(instance.getStatus(), is(AgentStatus.Idle)); }
@Test public void pendingAgentshouldNotBeRegistered() throws Exception { AgentRuntimeInfo agentRuntimeInfo = new AgentRuntimeInfo(agentConfig.getAgentIdentifier(), AgentRuntimeStatus.Idle, currentWorkingDirectory(), "cookie", false); AgentInstance instance = AgentInstance.createFromLiveAgent(agentRuntimeInfo, systemEnvironment, mock(AgentStatusChangeListener.class)); assertThat(instance.isRegistered(), is(false)); }
@Test public void shouldInitializeTheFreeSpaceAtAgentSide() { AgentIdentifier id = new AgentConfig("uuid", "localhost", "176.19.4.1").getAgentIdentifier(); AgentRuntimeInfo agentRuntimeInfo = new AgentRuntimeInfo(id, AgentRuntimeStatus.Idle, currentWorkingDirectory(), "cookie", false); assertThat(agentRuntimeInfo.getUsableSpace(), is(not(0L))); }
@Test public void shouldAssignCertificateToApprovedAgent() { AgentInstance agentInstance = AgentInstance.createFromConfig(agentConfig, systemEnvironment, mock(AgentStatusChangeListener.class)); agentInstance.update(new AgentRuntimeInfo(agentConfig.getAgentIdentifier(), AgentRuntimeStatus.Idle, currentWorkingDirectory(), "cookie", false)); Registration entry = agentInstance.assignCertification(); assertThat(entry.getChain().length, is(not(0))); }
private AgentRuntimeInfo cancelRuntimeInfo() { AgentRuntimeInfo agentRuntimeInfo = new AgentRuntimeInfo(agentConfig.getAgentIdentifier(), AgentRuntimeStatus.Idle, currentWorkingDirectory(), "cookie", false); agentRuntimeInfo.busy(defaultBuildingInfo); agentRuntimeInfo.cancel(); return agentRuntimeInfo; }
@Test public void shouldUpdateSupportBuildCommandProtocolFlag() throws Exception { AgentInstance agentInstance = AgentInstance.createFromConfig(agentConfig, systemEnvironment, mock(AgentStatusChangeListener.class)); assertThat(agentInstance.getSupportsBuildCommandProtocol(), is(false)); agentInstance.update(new AgentRuntimeInfo(agentConfig.getAgentIdentifier(), AgentRuntimeStatus.Idle, currentWorkingDirectory(), "cookie", false)); assertThat(agentInstance.getSupportsBuildCommandProtocol(), is(false)); agentInstance.update(new AgentRuntimeInfo(agentConfig.getAgentIdentifier(), AgentRuntimeStatus.Idle, currentWorkingDirectory(), "cookie", true)); assertThat(agentInstance.getSupportsBuildCommandProtocol(), is(true)); }
@Test public void shouldDenyPendingAgent() throws Exception { AgentRuntimeInfo agentRuntimeInfo = new AgentRuntimeInfo(agentConfig.getAgentIdentifier(), AgentRuntimeStatus.Idle, currentWorkingDirectory(), "cookie", false); AgentInstance instance = AgentInstance.createFromLiveAgent(agentRuntimeInfo, systemEnvironment, mock(AgentStatusChangeListener.class)); instance.deny(); assertThat(instance.getStatus(), is(AgentStatus.Disabled)); }
@Test public void shouldUpdateTheInstallLocation() throws Exception { AgentInstance agentInstance = AgentInstance.createFromConfig(agentConfig, systemEnvironment, mock(AgentStatusChangeListener.class)); String installPath = "/var/lib/GoServer"; AgentRuntimeInfo newRuntimeInfo = new AgentRuntimeInfo(agentConfig.getAgentIdentifier(), AgentRuntimeStatus.Idle, currentWorkingDirectory(), "cookie", false); newRuntimeInfo.setLocation(installPath); agentInstance.update(newRuntimeInfo); assertThat(agentInstance.getLocation(), is(installPath)); }
@Test public void shouldBeLostContactWhenLastHeardTimeExeedTimeOut() { AgentInstance instance = AgentInstance.createFromConfig(agentConfig, new SystemEnvironment() { public int getAgentConnectionTimeout() { return -1; } }, mock(AgentStatusChangeListener.class)); assertThat(instance.getStatus(), is(AgentStatus.Missing)); instance.update(new AgentRuntimeInfo(agentConfig.getAgentIdentifier(), AgentRuntimeStatus.Idle, currentWorkingDirectory(), "cookie", false)); instance.refresh(); assertThat(instance.getStatus(), is(AgentStatus.LostContact)); }
@Test public void shouldUpdateTheUsableSpace() throws Exception { AgentInstance agentInstance = AgentInstance.createFromConfig(agentConfig, systemEnvironment, mock(AgentStatusChangeListener.class)); AgentRuntimeInfo newRuntimeInfo = new AgentRuntimeInfo(agentConfig.getAgentIdentifier(), AgentRuntimeStatus.Idle, currentWorkingDirectory(), "cookie", false); newRuntimeInfo.setUsableSpace(1000L); assertThat(agentInstance.getUsableSpace(), is(not(newRuntimeInfo.getUsableSpace()))); agentInstance.update(newRuntimeInfo); assertThat(agentInstance.getUsableSpace(), is(newRuntimeInfo.getUsableSpace())); }
@Test public void shouldUpdateBuildingInfoWhenAgentIsBuilding() throws Exception { AgentInstance agentInstance = AgentInstance.createFromConfig(agentConfig, systemEnvironment, mock(AgentStatusChangeListener.class)); AgentRuntimeInfo agentRuntimeInfo = new AgentRuntimeInfo(agentConfig.getAgentIdentifier(), AgentRuntimeStatus.Idle, currentWorkingDirectory(), "cookie", false); AgentBuildingInfo buildingInfo = new AgentBuildingInfo("running pipeline/stage/build", "buildLocator"); agentRuntimeInfo.busy(buildingInfo); agentInstance.update(agentRuntimeInfo); assertThat(agentInstance.getBuildingInfo(), is(buildingInfo)); }
@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)); }
public static AgentInstance building(String buildLocator, SystemEnvironment systemEnvironment) { AgentConfig buildingAgentConfig = new AgentConfig("uuid3", "CCeDev01", "10.18.5.1", new ResourceConfigs("java")); AgentRuntimeInfo agentRuntimeInfo = new AgentRuntimeInfo(buildingAgentConfig.getAgentIdentifier(), AgentRuntimeStatus.Idle, currentWorkingDirectory(), "cookie", false); agentRuntimeInfo.busy(new AgentBuildingInfo("pipeline", buildLocator)); AgentInstance building = AgentInstance.createFromConfig(buildingAgentConfig, systemEnvironment, mock(AgentStatusChangeListener.class)); building.update(agentRuntimeInfo); return building; }
@Test public void shouldUpdateAgentBackToIdleAfterCancelledTaskFinishes() throws Exception { AgentInstance cancelled = AgentInstanceMother.cancelled(); AgentRuntimeInfo fromAgent = new AgentRuntimeInfo(cancelled.agentConfig().getAgentIdentifier(), AgentRuntimeStatus.Idle, currentWorkingDirectory(), "cookie", false); fromAgent.idle(); cancelled.update(fromAgent); assertThat(cancelled.getStatus(), is(AgentStatus.Idle)); }
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; }