Search in sources :

Example 1 with Agents

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

the class DefaultSchedulingContextTest method shouldCreatePermittedAgentContextCorrectly.

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

Example 2 with Agents

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

the class DefaultSchedulingContextTest method shouldNotMatchDeniedAgents.

@Test
public void shouldNotMatchDeniedAgents() throws Exception {
    AgentConfig linux = agent("uuid1", "linux");
    AgentConfig windows = agent("uuid2", "windows");
    windows.disable();
    Agents matchingAgents = new Agents(linux, windows);
    DefaultSchedulingContext context = new DefaultSchedulingContext("approved", matchingAgents);
    assertThat(context.findAgentsMatching(resources()), is(new Agents(linux)));
}
Also used : AgentConfig(com.thoughtworks.go.config.AgentConfig) Agents(com.thoughtworks.go.config.Agents) Test(org.junit.Test)

Example 3 with Agents

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

the class DefaultSchedulingContextTest method shouldFindNoAgentsIfNoneExist.

@Test
public void shouldFindNoAgentsIfNoneExist() throws Exception {
    DefaultSchedulingContext context = new DefaultSchedulingContext("approved", new Agents());
    assertThat(context.findAgentsMatching(new Resources()), is(new Agents()));
}
Also used : Agents(com.thoughtworks.go.config.Agents) Resources(com.thoughtworks.go.config.Resources) Test(org.junit.Test)

Example 4 with Agents

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

the class DefaultSchedulingContextTest method shouldFindAllAgentsIfNoResourcesAreSpecified.

@Test
public void shouldFindAllAgentsIfNoResourcesAreSpecified() throws Exception {
    AgentConfig linux = agent("uuid1", "linux");
    AgentConfig windows = agent("uuid2", "windows");
    Agents matchingAgents = new Agents(linux, windows);
    DefaultSchedulingContext context = new DefaultSchedulingContext("approved", matchingAgents);
    assertThat(context.findAgentsMatching(new Resources()), is(matchingAgents));
}
Also used : AgentConfig(com.thoughtworks.go.config.AgentConfig) Agents(com.thoughtworks.go.config.Agents) Resources(com.thoughtworks.go.config.Resources) Test(org.junit.Test)

Example 5 with Agents

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

the class DefaultSchedulingContextTest method shouldCreateRerunSchedulingContextCorrectly.

@Test
public void shouldCreateRerunSchedulingContextCorrectly() 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());
    SchedulingContext rerunContext = context.rerunContext();
    assertThat(rerunContext.isRerun(), is(true));
    assertThat(rerunContext.getApprovedBy(), is("approver"));
    Agents agents = (Agents) ReflectionUtil.getField(rerunContext, "agents");
    assertThat(agents, is(matchingAgents));
    EnvironmentVariablesConfig environmentVariablesUsed = rerunContext.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")));
}
Also used : AgentConfig(com.thoughtworks.go.config.AgentConfig) EnvironmentVariableConfig(com.thoughtworks.go.config.EnvironmentVariableConfig) Agents(com.thoughtworks.go.config.Agents) EnvironmentVariablesConfig(com.thoughtworks.go.config.EnvironmentVariablesConfig) StageConfig(com.thoughtworks.go.config.StageConfig) Test(org.junit.Test)

Aggregations

Agents (com.thoughtworks.go.config.Agents)33 Test (org.junit.Test)28 AgentConfig (com.thoughtworks.go.config.AgentConfig)13 Map (java.util.Map)13 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)3 EnvironmentVariablesConfig (com.thoughtworks.go.config.EnvironmentVariablesConfig)3 StageConfig (com.thoughtworks.go.config.StageConfig)3 DefaultSchedulingContext (com.thoughtworks.go.domain.DefaultSchedulingContext)3 EnvironmentVariableConfig (com.thoughtworks.go.config.EnvironmentVariableConfig)2 Resources (com.thoughtworks.go.config.Resources)2 JobInstance (com.thoughtworks.go.domain.JobInstance)2 Pipeline (com.thoughtworks.go.domain.Pipeline)2 TimeProvider (com.thoughtworks.go.util.TimeProvider)2 Before (org.junit.Before)2 Resource (com.thoughtworks.go.config.Resource)1 TrackingTool (com.thoughtworks.go.config.TrackingTool)1 ElasticProfile (com.thoughtworks.go.config.elastic.ElasticProfile)1 JobIdentifier (com.thoughtworks.go.domain.JobIdentifier)1 NullAgentInstance (com.thoughtworks.go.domain.NullAgentInstance)1 Stage (com.thoughtworks.go.domain.Stage)1