public DefaultSchedulingContext(String approvedBy) { this(approvedBy, new Agents()); }
public Agents filter(List<String> uuids) { Agents agents = new Agents(); for (String uuid : uuids) { agents.add(getAgentByUuid(uuid)); } return agents; }
public CruiseConfig update(CruiseConfig cruiseConfig) { AgentConfig agentConfig = cruiseConfig.agents().getAgentByUuid(uuid); if (agentConfig.isNull()) { bomb("Unable to delete agent; Agent [" + uuid + "] not found."); } cruiseConfig.getEnvironments().removeAgentFromAllEnvironments(uuid); cruiseConfig.agents().remove(agentConfig); return cruiseConfig; }
public CruiseConfig update(CruiseConfig cruiseConfig) { cruiseConfig.agents().add(agentConfig); return cruiseConfig; }
@Test public void shouldGiveAListOfUuids() throws Exception { Agents agents = new Agents(); agents.add(new AgentConfig("1", "localhost", "2")); AgentConfig denied = new AgentConfig("2", "localhost", "2"); denied.setDisabled(true); agents.add(denied); Set<String> uuids = agents.acceptedUuids(); assertThat(uuids.size(), is(2)); assertThat(uuids, hasItem("1")); assertThat(uuids, hasItem("2")); }
public AgentConfig agentByUuid(String uuid) { return agents().getAgentByUuid(uuid); }
@Test public void shouldValidateDuplicateElasticAgentId() throws Exception { Agents agents = new Agents(); AgentConfig elasticAgent1 = new AgentConfig("1", "localhost", "1"); elasticAgent1.setElasticAgentId("elastic-agent-id"); elasticAgent1.setElasticPluginId("awesome-elastic-agent"); AgentConfig elasticAgent2 = new AgentConfig("2", "localhost", "2"); elasticAgent2.setElasticAgentId("elastic-agent-id"); elasticAgent2.setElasticPluginId("awesome-elastic-agent"); agents.add(elasticAgent1); agents.add(elasticAgent2); agents.validate(new ConfigSaveValidationContext(agents)); assertThat(elasticAgent1.errors().size(), is(1)); assertThat(elasticAgent1.errors().getAllOn("elasticAgentId").get(0), is("Duplicate ElasticAgentId found for agents [1, 2]")); assertThat(elasticAgent2.errors().size(), is(1)); assertThat(elasticAgent2.errors().getAllOn("elasticAgentId").get(0), is("Duplicate ElasticAgentId found for agents [1, 2]")); } }
@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"))); }
@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()))); }
@Override public Map<String, Object> asJson() { LinkedHashMap<String, Object> json = new LinkedHashMap<>(); CruiseConfig currentConfig = goConfigService.getCurrentConfig(); LinkedHashMap<String, Object> validConfig = new LinkedHashMap<>(); validConfig.put("Number of pipelines", goConfigService.getAllPipelineConfigs().size()); validConfig.put("Number of agents", goConfigService.agents().size()); validConfig.put("Number of environments", currentConfig.getEnvironments().size()); validConfig.put("Number of unique materials", currentConfig.getAllUniqueMaterials().size()); validConfig.put("Number of schedulable materials", goConfigService.getSchedulableMaterials().size()); json.put("Valid Config", validConfig); json.put("Security", securityInformation()); return json; }
public Agents(List<AgentConfig> agentConfigs) { if (agentConfigs != null) { this.addAll(agentConfigs); } }
public List<ConfigErrors> validateConfig(CruiseConfig cruiseConfig) { List<ConfigErrors> errors = new ArrayList<>(); Set<String> uuids = cruiseConfig.agents().acceptedUuids(); if (!cruiseConfig.getEnvironments().validateContainOnlyUuids(uuids)) { for (EnvironmentConfig environmentConfig : cruiseConfig.getEnvironments()) { for (EnvironmentAgentConfig environmentAgentConfig : environmentConfig.getAgents()) { if (!environmentAgentConfig.errors().isEmpty()) { errors.add(environmentAgentConfig.errors()); } } } } return errors; } }
@Override public int hashCode() { int result = approvedBy != null ? approvedBy.hashCode() : 0; result = 31 * result + (agents != null ? agents.hashCode() : 0); result = 31 * result + (variables != null ? variables.hashCode() : 0); return result; } }
public boolean hasAgent(String uuid) { return agents().hasAgent(uuid); }
@Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } DefaultSchedulingContext that = (DefaultSchedulingContext) o; if (agents != null ? !agents.equals(that.agents) : that.agents != null) { return false; } if (approvedBy != null ? !approvedBy.equals(that.approvedBy) : that.approvedBy != null) { return false; } if (variables != null ? !variables.equals(that.variables) : that.variables != null) { return false; } return true; }
@Test public void agentWithNoIpAddressShouldBeValid() throws Exception { CruiseConfig cruiseConfig = new BasicCruiseConfig(); AgentConfig agent = new AgentConfig("uuid", null, null); cruiseConfig.agents().add(agent); assertThat(cruiseConfig.validateAfterPreprocess().isEmpty(), is(true)); }
public boolean hasAgent(String uuid) { return !getAgentByUuid(uuid).isNull(); }
public Agents(Collection<AgentConfig> agentConfigs) { this.addAll(agentConfigs); }