Search in sources :

Example 46 with AgentConfig

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

the class AgentInstance method createFromLiveAgent.

public static AgentInstance createFromLiveAgent(AgentRuntimeInfo agentRuntimeInfo, SystemEnvironment systemEnvironment) {
    AgentConfig config = agentRuntimeInfo.agent();
    AgentType type = config.isFromLocalHost() ? AgentType.LOCAL : AgentType.REMOTE;
    AgentInstance instance;
    if (systemEnvironment.isAutoRegisterLocalAgentEnabled() && config.isFromLocalHost()) {
        instance = new AgentInstance(config, type, systemEnvironment);
        instance.agentConfigStatus = AgentConfigStatus.Enabled;
        instance.agentRuntimeInfo.idle();
        instance.update(agentRuntimeInfo);
        return instance;
    } else {
        instance = new AgentInstance(config, type, systemEnvironment);
        instance.update(agentRuntimeInfo);
    }
    return instance;
}
Also used : AgentConfig(com.thoughtworks.go.config.AgentConfig)

Example 47 with AgentConfig

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

the class AgentMother method deniedAgent.

public static AgentConfig deniedAgent() {
    AgentConfig agentConfig = new AgentConfig("uuid", "deniedAgent", "192.168.0.1");
    agentConfig.disable();
    return agentConfig;
}
Also used : AgentConfig(com.thoughtworks.go.config.AgentConfig)

Example 48 with AgentConfig

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

the class AgentMother method elasticAgent.

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;
}
Also used : AgentConfig(com.thoughtworks.go.config.AgentConfig)

Example 49 with AgentConfig

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

the class AgentConfigServiceTest method shouldEnableAgentWhenAlreadyInTheConfig.

@Test
public void shouldEnableAgentWhenAlreadyInTheConfig() {
    String agentId = DatabaseAccessHelper.AGENT_UUID;
    AgentConfig agentConfig = new AgentConfig(agentId, "remote-host", "50.40.30.20");
    agentConfig.disable();
    AgentInstance instance = AgentInstance.createFromConfig(agentConfig, new SystemEnvironment(), null);
    when(goConfigService.currentCruiseConfig()).thenReturn(mock(CruiseConfig.class));
    when(goConfigService.hasAgent(agentConfig.getUuid())).thenReturn(true);
    agentConfigService.enableAgents(Username.ANONYMOUS, instance);
    shouldPerformCommand(new GoConfigDao.CompositeConfigCommand((UpdateConfigCommand) new AgentConfigService.UpdateAgentApprovalStatus(agentId, false)));
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) AgentConfig(com.thoughtworks.go.config.AgentConfig) UpdateConfigCommand(com.thoughtworks.go.config.UpdateConfigCommand) GoConfigDao(com.thoughtworks.go.config.GoConfigDao) CruiseConfig(com.thoughtworks.go.config.CruiseConfig) Test(org.junit.Test)

Example 50 with AgentConfig

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

the class AgentConfigServiceTest method shouldEnableAgentWhenPending.

@Test
public void shouldEnableAgentWhenPending() {
    String agentId = DatabaseAccessHelper.AGENT_UUID;
    AgentConfig agentConfig = new AgentConfig(agentId, "remote-host", "50.40.30.20");
    AgentRuntimeInfo agentRuntimeInfo = AgentRuntimeInfo.fromAgent(new AgentIdentifier("remote-host", "50.40.30.20", agentId), AgentRuntimeStatus.Unknown, "cookie", false);
    AgentInstance instance = AgentInstance.createFromLiveAgent(agentRuntimeInfo, new SystemEnvironment(), null);
    agentConfigService.enableAgents(Username.ANONYMOUS, instance);
    shouldPerformCommand(new GoConfigDao.CompositeConfigCommand(new AgentConfigService.AddAgentCommand(agentConfig)));
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) AgentConfig(com.thoughtworks.go.config.AgentConfig) AgentIdentifier(com.thoughtworks.go.remote.AgentIdentifier) GoConfigDao(com.thoughtworks.go.config.GoConfigDao) Test(org.junit.Test)

Aggregations

AgentConfig (com.thoughtworks.go.config.AgentConfig)90 Test (org.junit.Test)68 AgentInstance (com.thoughtworks.go.domain.AgentInstance)20 Agents (com.thoughtworks.go.config.Agents)13 SystemEnvironment (com.thoughtworks.go.util.SystemEnvironment)11 AgentStatusChangeListener (com.thoughtworks.go.listener.AgentStatusChangeListener)10 Username (com.thoughtworks.go.server.domain.Username)7 ResponseEntity (org.springframework.http.ResponseEntity)7 ResourceConfig (com.thoughtworks.go.config.ResourceConfig)6 ResourceConfigs (com.thoughtworks.go.config.ResourceConfigs)5 AgentIdentifier (com.thoughtworks.go.remote.AgentIdentifier)5 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)5 GoConfigDao (com.thoughtworks.go.config.GoConfigDao)4 ServerConfig (com.thoughtworks.go.config.ServerConfig)4 UpdateConfigCommand (com.thoughtworks.go.config.UpdateConfigCommand)4 EnvironmentVariablesConfig (com.thoughtworks.go.config.EnvironmentVariablesConfig)3 ElasticProfile (com.thoughtworks.go.config.elastic.ElasticProfile)3 NullAgentInstance (com.thoughtworks.go.domain.NullAgentInstance)3 EnvironmentVariableConfig (com.thoughtworks.go.config.EnvironmentVariableConfig)2 StageConfig (com.thoughtworks.go.config.StageConfig)2