public static AgentConfig localAgentWithResources(String... resources) { AgentConfig agentConfig = localAgent(); for (String resource : resources) { agentConfig.addResourceConfig(new ResourceConfig(resource)); } return agentConfig; } }
public CruiseConfig update(CruiseConfig cruiseConfig) { AgentConfig agentConfig = cruiseConfig.agents().getAgentByUuid(uuid); bombIfNull(agentConfig, "Unable to set agent resources; Agent [" + uuid + "] not found."); if (action.equals(TriStateSelection.Action.add)) { agentConfig.addResourceConfig(resourceConfig); } else if (action.equals(TriStateSelection.Action.remove)) { agentConfig.removeResource(resourceConfig); } else if (action.equals(TriStateSelection.Action.nochange)) { //do nothing } else { bomb(String.format("unsupported action '%s'", action)); } return cruiseConfig; } }
@Test public void shouldAllowResourcesOnNonElasticAgents() throws Exception { BasicCruiseConfig cruiseConfig = GoConfigMother.configWithPipelines("dev", "qa"); AgentConfig agentConfig = new AgentConfig("uuid", "hostname", "10.10.10.10"); cruiseConfig.agents().add(agentConfig); agentConfig.addResourceConfig(new ResourceConfig("foo")); assertThat(cruiseConfig.validateAfterPreprocess().isEmpty(), is(true)); }
@Test public void shouldNotAllowResourcesElasticAgents() throws Exception { BasicCruiseConfig cruiseConfig = GoConfigMother.configWithPipelines("dev", "qa"); AgentConfig agentConfig = new AgentConfig("uuid", "hostname", "10.10.10.10"); cruiseConfig.agents().add(agentConfig); agentConfig.setElasticPluginId("com.example.foo"); agentConfig.setElasticAgentId("foobar"); agentConfig.addResourceConfig(new ResourceConfig("foo")); assertThat(cruiseConfig.validateAfterPreprocess().isEmpty(), is(false)); assertEquals(1, agentConfig.errors().size()); assertThat(agentConfig.errors().on("elasticAgentId"), is("Elastic agents cannot have resources.")); }
agentConfig.addResourceConfig(new ResourceConfig(r));