Search in sources :

Example 16 with Agents

use of com.thoughtworks.go.config.Agents in project gocd by gocd.

the class AgentsTest method shouldValidateDuplicateElasticAgentId.

@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]"));
}
Also used : AgentConfig(com.thoughtworks.go.config.AgentConfig) ConfigSaveValidationContext(com.thoughtworks.go.config.ConfigSaveValidationContext) Agents(com.thoughtworks.go.config.Agents) Test(org.junit.Test)

Example 17 with Agents

use of com.thoughtworks.go.config.Agents in project gocd by gocd.

the class AgentsTest method shouldFindAgentByUuid.

@Test
public void shouldFindAgentByUuid() {
    Agents agents = new Agents();
    agents.add(new AgentConfig("1", "localhost", "2"));
    assertThat(agents.getAgentByUuid("1").getHostname(), is("localhost"));
}
Also used : AgentConfig(com.thoughtworks.go.config.AgentConfig) Agents(com.thoughtworks.go.config.Agents) Test(org.junit.Test)

Example 18 with Agents

use of com.thoughtworks.go.config.Agents in project gocd by gocd.

the class AgentsTest method shouldGiveAListOfUuids.

@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"));
}
Also used : AgentConfig(com.thoughtworks.go.config.AgentConfig) Agents(com.thoughtworks.go.config.Agents) Test(org.junit.Test)

Example 19 with Agents

use of com.thoughtworks.go.config.Agents in project gocd by gocd.

the class DefaultSchedulingContext method overrideEnvironmentVariables.

public SchedulingContext overrideEnvironmentVariables(EnvironmentVariablesConfig environmentVariablesConfig) {
    DefaultSchedulingContext context = new DefaultSchedulingContext(approvedBy, new Agents(agents), profiles);
    context.variables = variables.overrideWith(environmentVariablesConfig);
    context.rerun = rerun;
    return context;
}
Also used : Agents(com.thoughtworks.go.config.Agents)

Example 20 with Agents

use of com.thoughtworks.go.config.Agents in project gocd by gocd.

the class RestfulServiceTest method shouldFindOriginalWhenJobCopiedForRerun.

@Test
public void shouldFindOriginalWhenJobCopiedForRerun() throws Exception {
    Pipeline pipeline = fixture.createdPipelineWithAllStagesPassed();
    Stage stage = pipeline.getStages().byName(fixture.devStage);
    JobInstance job = stage.findJob(PipelineWithTwoStages.JOB_FOR_DEV_STAGE);
    Stage rerunStage = instanceFactory.createStageForRerunOfJobs(stage, a(PipelineWithTwoStages.DEV_STAGE_SECOND_JOB), new DefaultSchedulingContext("loser", new Agents()), fixture.pipelineConfig().getStage(new CaseInsensitiveString(fixture.devStage)), new TimeProvider(), "md5");
    stageDao.saveWithJobs(pipeline, rerunStage);
    dbHelper.passStage(rerunStage);
    JobIdentifier result = restfulService.findJob(pipeline.getName(), String.valueOf(pipeline.getCounter()), stage.getName(), String.valueOf(rerunStage.getCounter()), job.getName());
    JobIdentifier expect = new JobIdentifier(pipeline, stage, job);
    assertThat(result, is(expect));
    long copiedJobId = rerunStage.getJobInstances().getByName(job.getName()).getId();
    // sanity check(its a copy, not the same)
    assertThat(copiedJobId, is(not(job.getId())));
    result = restfulService.findJob(pipeline.getName(), String.valueOf(pipeline.getCounter()), stage.getName(), String.valueOf(rerunStage.getCounter()), job.getName());
    // still, the job identifier returned should be the same(because other one was a copy)
    assertThat(result, is(expect));
    result = restfulService.findJob(pipeline.getName(), String.valueOf(pipeline.getCounter()), stage.getName(), String.valueOf(rerunStage.getCounter()), job.getName(), copiedJobId);
    // since caller knows the buildId, honor it(caller knows what she is doing)
    assertThat(result, is(not(expect)));
    assertThat(result, is(new JobIdentifier(rerunStage.getIdentifier(), job.getName(), copiedJobId)));
}
Also used : TimeProvider(com.thoughtworks.go.util.TimeProvider) Agents(com.thoughtworks.go.config.Agents) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.Test)

Aggregations

Agents (com.thoughtworks.go.config.Agents)21 Test (org.junit.Test)16 AgentConfig (com.thoughtworks.go.config.AgentConfig)13 EnvironmentVariablesConfig (com.thoughtworks.go.config.EnvironmentVariablesConfig)3 TimeProvider (com.thoughtworks.go.util.TimeProvider)3 EnvironmentVariableConfig (com.thoughtworks.go.config.EnvironmentVariableConfig)2 Resources (com.thoughtworks.go.config.Resources)2 StageConfig (com.thoughtworks.go.config.StageConfig)2 Before (org.junit.Before)2 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)1 ConfigSaveValidationContext (com.thoughtworks.go.config.ConfigSaveValidationContext)1 ResourceConfig (com.thoughtworks.go.config.ResourceConfig)1 ElasticProfile (com.thoughtworks.go.config.elastic.ElasticProfile)1 DefaultSchedulingContext (com.thoughtworks.go.domain.DefaultSchedulingContext)1 NullAgentInstance (com.thoughtworks.go.domain.NullAgentInstance)1 Pipeline (com.thoughtworks.go.domain.Pipeline)1 AgentStatusChangeListener (com.thoughtworks.go.listener.AgentStatusChangeListener)1 SystemEnvironment (com.thoughtworks.go.util.SystemEnvironment)1 HashMap (java.util.HashMap)1 TransactionStatus (org.springframework.transaction.TransactionStatus)1