private static String jobLink(AgentBuildingInfo buildingInfo) { return format("/tab/build/detail/%s", buildingInfo.getBuildLocator()); }
private static String pipelineLink(AgentBuildingInfo buildingInfo) { return format("/tab/pipeline/history/%s", buildingInfo.getPipelineName()); }
public String getPipelineName() { if(isBuilding()) { return buildLocator.split("/")[0]; } return null; }
@Before public void setUp() { systemEnvironment = new SystemEnvironment(); agentConfig = new AgentConfig("uuid2", "CCeDev01", DEFAULT_IP_ADDRESS); defaultBuildingInfo = new AgentBuildingInfo("pipeline", "buildLocator"); agentStatusChangeListener = mock(AgentStatusChangeListener.class); }
@Test public void shouldReturnNullTheJobName() { AgentBuildingInfo agentBuildingInfo = new AgentBuildingInfo("buildInfo", "foo"); assertNull(agentBuildingInfo.getJobName()); }
@Test public void shouldReturnTheStageName() { AgentBuildingInfo agentBuildingInfo = new AgentBuildingInfo("buildInfo", "foo/1/bar"); assertThat(agentBuildingInfo.getStageName(), is("bar")); }
@Test public void shouldReturnThePipelineName() { AgentBuildingInfo agentBuildingInfo = new AgentBuildingInfo("buildInfo", "foo"); assertThat(agentBuildingInfo.getPipelineName(), is("foo")); }
public static void toJSON(OutputWriter outputWriter, AgentBuildingInfo buildingInfo) { outputWriter .addLinks(linksWriter -> { linksWriter.addLink("job", jobLink(buildingInfo)); linksWriter.addLink("stage", stageLink(buildingInfo)); linksWriter.addLink("pipeline", pipelineLink(buildingInfo)); }) .add("pipeline_name", buildingInfo.getPipelineName()) .add("stage_name", buildingInfo.getStageName()) .add("job_name", buildingInfo.getJobName()); }
@Test public void shouldNotifyAgentChangeListenerOnAgentBuilding() throws Exception { AgentInstance idleAgent = AgentInstance.createFromConfig(agentConfig("abc"), new SystemEnvironment(), agentStatusChangeListener); idleAgent.building(new AgentBuildingInfo("running pipeline/stage/build", "buildLocator")); verify(agentStatusChangeListener).onAgentStatusChange(idleAgent); }
@Test public void shouldReturnTheJobName() { AgentBuildingInfo agentBuildingInfo = new AgentBuildingInfo("buildInfo", "foo/1/bar/3/job"); assertThat(agentBuildingInfo.getJobName(), is("job")); }
@Test public void shouldReturnNullForStageName() { AgentBuildingInfo agentBuildingInfo = new AgentBuildingInfo("buildInfo", "foo"); assertNull(agentBuildingInfo.getStageName()); }
@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)); }
public String getJobName() { if (isBuilding()) { try { return buildLocator.split("/")[4]; } catch (ArrayIndexOutOfBoundsException e) { return null; } } return null; }
private static String stageLink(AgentBuildingInfo buildingInfo) { final String[] parts = buildingInfo.getBuildLocator().split("/"); final String stageLocator = join("/", copyOfRange(parts, 0, parts.length - 1)); return format("/pipelines/%s", stageLocator); } }
private static boolean hasViewOrOperatePermissionOnPipeline(AgentInstance agentInstance, SecurityService securityService, Username username) { return securityService.hasViewOrOperatePermissionForPipeline(username, agentInstance.getBuildingInfo().getPipelineName()); }
public static AgentInstance lostContact(String buildLocator) { AgentConfig agentConfig = new AgentConfig("1234", "localhost", "192.168.0.1"); AgentInstance instance = AgentInstance.createFromConfig(agentConfig, new SystemEnvironment(), mock(AgentStatusChangeListener.class)); AgentRuntimeInfo newRuntimeInfo = AgentRuntimeInfo.initialState(agentConfig); newRuntimeInfo.setStatus(AgentStatus.LostContact); newRuntimeInfo.setUsableSpace(1000L); newRuntimeInfo.setBuildingInfo(new AgentBuildingInfo("buildInfo", buildLocator)); instance.update(newRuntimeInfo); return instance; }
public String getStageName() { if(isBuilding()) { try { return buildLocator.split("/")[2]; } catch (ArrayIndexOutOfBoundsException e) { return null; } } return null; }
public String getBuildLocator() { return agentRuntimeInfo.getBuildingInfo().getBuildLocator(); }
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; }
private static boolean isBuilding(AgentInstance agentInstance) { return agentInstance.getBuildingInfo().isBuilding(); }