public void disable() { disable(Boolean.TRUE); }
public void enable() { disable(Boolean.FALSE); }
public void deny() { if (!canDisable()) { throw new RuntimeException("Should not deny agent when is building."); } agentConfig().disable(); updateConfigStatus(AgentConfigStatus.Disabled); }
public static AgentConfig deniedAgent() { AgentConfig agentConfig = new AgentConfig("uuid", "deniedAgent", "192.168.0.1"); agentConfig.disable(); return agentConfig; }
private void disableAgents(boolean disabled, Username currentUser, AgentInstance... instances) { GoConfigDao.CompositeConfigCommand command = new GoConfigDao.CompositeConfigCommand(); ArrayList<String> uuids = new ArrayList<>(); for (AgentInstance agentInstance : instances) { String uuid = agentInstance.getUuid(); uuids.add(uuid); if (goConfigService.hasAgent(uuid)) { command.addCommand(new UpdateAgentApprovalStatus(uuid, disabled)); } else { AgentConfig agentConfig = agentInstance.agentConfig(); agentConfig.disable(disabled); command.addCommand(new AddAgentCommand(agentConfig)); } } updateAgentWithoutValidations(command, currentUser); }
@Test public void deniedAgentshouldBeRegistered() throws Exception { agentConfig.disable(); AgentInstance instance = AgentInstance.createFromConfig(agentConfig, systemEnvironment, mock(AgentStatusChangeListener.class)); assertThat(instance.isRegistered(), is(true)); }
@Test public void shouldRefreshDisabledAgent() throws Exception { agentConfig.disable(); AgentInstance instance = AgentInstance.createFromConfig(agentConfig, new SystemEnvironment() { public int getAgentConnectionTimeout() { return -1; } }, mock(AgentStatusChangeListener.class)); instance.update(new AgentRuntimeInfo(agentConfig.getAgentIdentifier(), AgentRuntimeStatus.Building, currentWorkingDirectory(), "cookie", false)); instance.refresh(); assertThat(instance.getRuntimeStatus(), is(AgentRuntimeStatus.LostContact)); assertThat(instance.getStatus(), is(AgentStatus.Disabled)); }
@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 shouldNotMatchDeniedAgents() throws Exception { AgentConfig linux = agent("uuid1", "linux"); AgentConfig windows = agent("uuid2", "windows"); windows.disable(); Agents matchingAgents = new Agents(linux, windows); DefaultSchedulingContext context = new DefaultSchedulingContext("approved", matchingAgents); assertThat(context.findAgentsMatching(resources()), is(new Agents(linux))); }
@Test public void shouldCreateRerunSchedulingContextCorrectly() throws Exception { AgentConfig linux = agent("uuid1", "linux"); AgentConfig windows = agent("uuid2", "windows"); windows.disable(); Agents matchingAgents = new Agents(linux, windows); EnvironmentVariablesConfig existing = new EnvironmentVariablesConfig(); existing.add("firstVar", "firstVal"); existing.add("overriddenVar", "originalVal"); SchedulingContext schedulingContext = new DefaultSchedulingContext("approver", matchingAgents); schedulingContext = schedulingContext.overrideEnvironmentVariables(existing); EnvironmentVariablesConfig stageLevel = new EnvironmentVariablesConfig(); stageLevel.add("stageVar", "stageVal"); stageLevel.add("overriddenVar", "overriddenVal"); StageConfig config = StageConfigMother.custom("test", Approval.automaticApproval()); config.setVariables(stageLevel); SchedulingContext context = schedulingContext.overrideEnvironmentVariables(config.getVariables()); SchedulingContext rerunContext = context.rerunContext(); assertThat(rerunContext.isRerun(), is(true)); assertThat(rerunContext.getApprovedBy(), is("approver")); Agents agents = (Agents) ReflectionUtil.getField(rerunContext, "agents"); assertThat(agents, is(matchingAgents)); EnvironmentVariablesConfig environmentVariablesUsed = rerunContext.getEnvironmentVariablesConfig(); assertThat(environmentVariablesUsed.size(), is(3)); assertThat(environmentVariablesUsed, hasItem(new EnvironmentVariableConfig("firstVar", "firstVal"))); assertThat(environmentVariablesUsed, hasItem(new EnvironmentVariableConfig("overriddenVar", "overriddenVal"))); assertThat(environmentVariablesUsed, hasItem(new EnvironmentVariableConfig("stageVar", "stageVal"))); }
@Test public void shouldCreatePermittedAgentContextCorrectly() throws Exception { AgentConfig linux = agent("uuid1", "linux"); AgentConfig windows = agent("uuid2", "windows"); windows.disable(); Agents matchingAgents = new Agents(linux, windows); EnvironmentVariablesConfig existing = new EnvironmentVariablesConfig(); existing.add("firstVar", "firstVal"); existing.add("overriddenVar", "originalVal"); SchedulingContext schedulingContext = new DefaultSchedulingContext("approver", matchingAgents); schedulingContext = schedulingContext.overrideEnvironmentVariables(existing); EnvironmentVariablesConfig stageLevel = new EnvironmentVariablesConfig(); stageLevel.add("stageVar", "stageVal"); stageLevel.add("overriddenVar", "overriddenVal"); StageConfig config = StageConfigMother.custom("test", Approval.automaticApproval()); config.setVariables(stageLevel); SchedulingContext context = schedulingContext.overrideEnvironmentVariables(config.getVariables()); ReflectionUtil.setField(context, "rerun", true); SchedulingContext permittedAgentContext = context.permittedAgent("uuid1"); Agents agents = (Agents) ReflectionUtil.getField(permittedAgentContext, "agents"); assertThat(agents.size(), is(1)); assertThat(agents.get(0).getAgentIdentifier().getUuid(), is("uuid1")); assertThat(permittedAgentContext.isRerun(), is(true)); assertThat(permittedAgentContext.getApprovedBy(), is("approver")); EnvironmentVariablesConfig environmentVariablesUsed = permittedAgentContext.getEnvironmentVariablesConfig(); assertThat(environmentVariablesUsed.size(), is(3)); assertThat(environmentVariablesUsed, hasItem(new EnvironmentVariableConfig("firstVar", "firstVal"))); assertThat(environmentVariablesUsed, hasItem(new EnvironmentVariableConfig("overriddenVar", "overriddenVal"))); assertThat(environmentVariablesUsed, hasItem(new EnvironmentVariableConfig("stageVar", "stageVal"))); }
for (AgentConfig agentConfig : agents) { if (state.isFalse()) { agentConfig.disable();