public Set<String> acceptedUuids() { HashSet<String> uuids = new HashSet<>(); for (AgentConfig agentConfig : this) { uuids.add(agentConfig.getUuid()); } return uuids; }
private List<String> getPendingAgentUuids(List<AgentConfig> pendingAgents) { List<String> pendingAgentUuids = new ArrayList<>(); for (AgentConfig pendingAgent : pendingAgents) { pendingAgentUuids.add(pendingAgent.getUuid()); } return pendingAgentUuids; }
public AgentConfig getAgentByUuid(String uuid) { for (AgentConfig agentConfig : this) { if (StringUtils.equals(agentConfig.getUuid(), uuid)) { return agentConfig; } } return NullAgent.createNullAgent(uuid); }
public String getUuid() { return agentConfig().getUuid(); }
public void add(AgentInstance agent) { agentInstances.put(agent.agentConfig().getUuid(), agent); }
private List<String> getLiveAgentUuids(AgentInstances knownAgents) { List<String> agents = new ArrayList<>(); for (AgentInstance agent : knownAgents) { if (agent.getStatus() != AgentStatus.LostContact) { agents.add(agent.agentConfig().getUuid()); } } return agents; }
public void addAgent(AgentConfig agentConfig, Username currentUser) { updateAgent(new AddAgentCommand(agentConfig), agentConfig.getUuid(), currentUser); }
public void saveOrUpdateAgent(AgentInstance agentInstance, Username currentUser) { AgentConfig agentConfig = agentInstance.agentConfig(); if (goConfigService.hasAgent(agentConfig.getUuid())) { this.updateAgentApprovalStatus(agentConfig.getUuid(), agentConfig.isDisabled(), currentUser); } else { this.addAgent(agentConfig, currentUser); } }
public static Agent fromConfig(AgentConfig config) { return new Agent(config.getUuid(), "None", config.getHostNameForDisplay(), config.getIpAddress()); }
public JobPlan firstMatching(List<JobPlan> jobPlans) { for (JobPlan jobPlan : jobPlans) { if (jobPlan.requiresElasticAgent()) { continue; } if (jobPlan.assignedToAgent() && isNotElasticAndResourcesMatchForNonElasticAgents(jobPlan)) { return jobPlan; } else { if (agentConfig.getUuid().equals(jobPlan.getAgentUuid())) { return jobPlan; } } } return null; }
public AgentIdentifier getAgentIdentifier() { return new AgentIdentifier(this.getHostname(), getIpAddress(), getUuid()); }
public SchedulingContext permittedAgent(String permittedAgentUuid) { Agents permitted = new Agents(); for (AgentConfig agent : agents) { if (agent.getUuid().equals(permittedAgentUuid)) { permitted.add(agent); } } DefaultSchedulingContext context = new DefaultSchedulingContext(approvedBy, permitted, profiles); context.variables = variables.overrideWith(new EnvironmentVariablesConfig()); context.rerun = rerun; return context; }
public void createJobInstances(JobInstances jobs, SchedulingContext context, JobConfig config, String stageName, final JobNameGenerator nameGenerator, final Clock clock, InstanceFactory instanceFactory) { Collection<AgentConfig> agents = context.findAgentsMatching(config.resourceConfigs()); int counter = 0; for (AgentConfig agent : agents) { instanceFactory.reallyCreateJobInstance(config, jobs, agent.getUuid(), nameGenerator.generateName(++counter), true, false, context, clock); } if (counter == 0) { throw new CannotScheduleException(String.format("Could not find matching agents to run job [%s] of stage [%s].", config.name(), stageName), stageName); } }
public void refresh() { for (AgentInstance instance : currentInstances()) { instance.refresh(); } for (AgentInstance agentInstance : agentsToRemove()) { removeAgent(agentInstance.agentConfig().getUuid()); } }
@Test public void shouldNotReturnAJobWithMismatchedUuid() throws Exception { AgentConfig config = agentConfig("linux, mercurial"); AgentInstance agentInstance = new AgentInstance(config, LOCAL, systemEnvironment, null); final JobPlan job = jobPlan("pipeline-name", "job-name", "linux", config.getUuid() + "-ensure-doesn't-match"); JobPlan matchingJob = agentInstance.firstMatching(new ArrayList<JobPlan>() {{ add(job); }}); assertThat(matchingJob, is(nullValue())); }
public static AgentInstance updateHostname(AgentInstance agentInstance, String hostname) { AgentConfig original = agentInstance.agentConfig(); agentInstance.syncConfig(new AgentConfig(original.getUuid(), hostname, original.getIpAddress(), original.getResourceConfigs())); return agentInstance; }
@Test public void shouldReturnAJobPlanWithMatchingUuidSet() throws Exception { AgentConfig config = agentConfig("linux, mercurial"); AgentInstance agentInstance = new AgentInstance(config, LOCAL, systemEnvironment, null); final JobPlan job = jobPlan("pipeline-name", "job-name", "resource", config.getUuid()); JobPlan matchingJob = agentInstance.firstMatching(new ArrayList<JobPlan>() {{ add(job); }}); assertThat(matchingJob, is(job)); }
public Agents agentsForPipeline(final CaseInsensitiveString pipelineName) { Agents configs = new Agents(); if (environments.isPipelineAssociatedWithAnyEnvironment(pipelineName)) { EnvironmentConfig forPipeline = environments.findEnvironmentForPipeline(pipelineName); for (EnvironmentAgentConfig environmentAgentConfig : forPipeline.getAgents()) { configs.add(goConfigService.agentByUuid(environmentAgentConfig.getUuid())); } } else { for (AgentConfig agentConfig : goConfigService.agents()) { if (!environments.isAgentUnderEnvironment(agentConfig.getUuid())) { configs.add(agentConfig); } } } return configs; }
@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()))); }
@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)); }