Search in sources :

Example 1 with AgentConfig

use of com.thoughtworks.go.config.AgentConfig 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 AgentConfig

use of com.thoughtworks.go.config.AgentConfig 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 AgentConfig

use of com.thoughtworks.go.config.AgentConfig 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 4 with AgentConfig

use of com.thoughtworks.go.config.AgentConfig 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)

Example 5 with AgentConfig

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

the class AgentConfigsUpdateValidator method isValid.

@Override
public boolean isValid(CruiseConfig preprocessedConfig) {
    boolean isValid = true;
    for (String uuid : agentsUuids) {
        AgentConfig agentConfig = preprocessedConfig.agents().getAgentByUuid(uuid);
        isValid = agentConfig.validateTree(ConfigSaveValidationContext.forChain(preprocessedConfig)) && isValid;
        validatedAgents.add(agentConfig);
    }
    return isValid;
}
Also used : AgentConfig(com.thoughtworks.go.config.AgentConfig)

Aggregations

AgentConfig (com.thoughtworks.go.config.AgentConfig)65 Test (org.junit.Test)45 AgentInstance (com.thoughtworks.go.domain.AgentInstance)15 Agents (com.thoughtworks.go.config.Agents)13 Username (com.thoughtworks.go.server.domain.Username)7 SystemEnvironment (com.thoughtworks.go.util.SystemEnvironment)6 Resource (com.thoughtworks.go.config.Resource)5 Resources (com.thoughtworks.go.config.Resources)5 GoConfigDao (com.thoughtworks.go.config.GoConfigDao)4 SecurityConfig (com.thoughtworks.go.config.SecurityConfig)4 ServerConfig (com.thoughtworks.go.config.ServerConfig)4 UpdateConfigCommand (com.thoughtworks.go.config.UpdateConfigCommand)4 JobInstance (com.thoughtworks.go.domain.JobInstance)4 EnvironmentVariablesConfig (com.thoughtworks.go.config.EnvironmentVariablesConfig)3 NullAgentInstance (com.thoughtworks.go.domain.NullAgentInstance)3 AgentIdentifier (com.thoughtworks.go.remote.AgentIdentifier)3 HttpOperationResult (com.thoughtworks.go.server.service.result.HttpOperationResult)3 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)2 EnvironmentVariableConfig (com.thoughtworks.go.config.EnvironmentVariableConfig)2 StageConfig (com.thoughtworks.go.config.StageConfig)2