public static AgentConfig elasticAgent() { AgentConfig agentConfig = new AgentConfig(UUID.randomUUID().toString(), UUID.randomUUID().toString(), "127.0.0.1"); agentConfig.setElasticAgentId(UUID.randomUUID().toString()); agentConfig.setElasticPluginId(UUID.randomUUID().toString()); return agentConfig; }
public static AgentInstance updateElasticAgentId(AgentInstance agentInstance, String elasticAgentId) { AgentConfig agentConfig = agentInstance.agentConfig(); agentConfig.setElasticAgentId(elasticAgentId); agentInstance.syncConfig(agentConfig); return agentInstance; }
agentConfig.setElasticAgentId(elasticAgentId); agentConfig.setElasticPluginId(elasticPluginId);
@Test public void shouldNotMatchJobPlanIfTheAgentWasLaunchedByADifferentPluginFromThatConfiguredForTheJob() { AgentConfig agentConfig = new AgentConfig("uuid"); agentConfig.setElasticAgentId("elastic-agent-id-1"); String elasticPluginId = "elastic-plugin-id-1"; agentConfig.setElasticPluginId(elasticPluginId); AgentInstance agentInstance = new AgentInstance(agentConfig, REMOTE, mock(SystemEnvironment.class), null); DefaultJobPlan jobPlan1 = new DefaultJobPlan(); jobPlan1.setElasticProfile(new ElasticProfile("foo", "elastic-plugin-id-2")); List<JobPlan> jobPlans = asList(jobPlan1, new DefaultJobPlan()); assertThat(agentInstance.firstMatching(jobPlans), is(nullValue())); }
@Test public void shouldNotMatchJobPlanIfJobRequiresElasticAgent_MatchingIsManagedByBuildAssignmentService() { AgentConfig agentConfig = new AgentConfig("uuid"); agentConfig.setElasticAgentId("elastic-agent-id-1"); String elasticPluginId = "elastic-plugin-id-1"; agentConfig.setElasticPluginId(elasticPluginId); AgentInstance agentInstance = new AgentInstance(agentConfig, REMOTE, mock(SystemEnvironment.class), null); DefaultJobPlan jobPlan1 = new DefaultJobPlan(); jobPlan1.setElasticProfile(new ElasticProfile("foo", elasticPluginId)); List<JobPlan> jobPlans = asList(jobPlan1, new DefaultJobPlan()); assertThat(agentInstance.firstMatching(jobPlans), is(nullValue())); }
@Test public void shouldNotMatchJobPlanIfTheAgentIsElasticAndJobHasResourcesDefined() { AgentConfig agentConfig = new AgentConfig("uuid", "hostname", "11.1.1.1", new ResourceConfigs(new ResourceConfig("r1"))); agentConfig.setElasticAgentId("elastic-agent-id-1"); String elasticPluginId = "elastic-plugin-id-1"; agentConfig.setElasticPluginId(elasticPluginId); AgentInstance agentInstance = new AgentInstance(agentConfig, REMOTE, mock(SystemEnvironment.class), null); DefaultJobPlan jobPlan1 = new DefaultJobPlan(); jobPlan1.setResources(asList(new Resource("r1"))); List<JobPlan> jobPlans = asList(jobPlan1, new DefaultJobPlan()); assertThat(agentInstance.firstMatching(jobPlans), is(nullValue())); }
@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 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.")); }
@Test public void syncConfigShouldUpdateElasticAgentRuntimeInfo() { AgentInstance agent = AgentInstanceMother.idle(); AgentConfig agentConfig = new AgentConfig(agent.getUuid(), agent.getHostname(), agent.getIpAddress()); agentConfig.setElasticAgentId("i-123456"); agentConfig.setElasticPluginId("com.example.aws"); assertFalse(agent.isElastic()); agent.syncConfig(agentConfig); assertTrue(agent.isElastic()); assertEquals("i-123456", agent.elasticAgentMetadata().elasticAgentId()); assertEquals("com.example.aws", agent.elasticAgentMetadata().elasticPluginId()); }