Search in sources :

Example 61 with AgentConfig

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

the class AgentRegistrationControllerTest method shouldNotAutoRegisterAgentIfKeysDoNotMatch.

@Test
public void shouldNotAutoRegisterAgentIfKeysDoNotMatch() throws Exception {
    String uuid = "uuid";
    when(goConfigService.hasAgent(uuid)).thenReturn(false);
    ServerConfig serverConfig = new ServerConfig("artifacts", new SecurityConfig(), 10, 20, "1", "");
    when(goConfigService.serverConfig()).thenReturn(serverConfig);
    when(agentService.agentUsername(uuid, request.getRemoteAddr(), "host")).thenReturn(new Username("some-agent-login-name"));
    controller.agentRequest("host", uuid, "location", "233232", "osx", "", "", "", "", "", "", false, request);
    verify(agentService).requestRegistration(new Username("some-agent-login-name"), AgentRuntimeInfo.fromServer(new AgentConfig(uuid, "host", request.getRemoteAddr()), false, "location", 233232L, "osx", false));
    verify(goConfigService, never()).updateConfig(any(UpdateConfigCommand.class));
}
Also used : ServerConfig(com.thoughtworks.go.config.ServerConfig) AgentConfig(com.thoughtworks.go.config.AgentConfig) UpdateConfigCommand(com.thoughtworks.go.config.UpdateConfigCommand) SecurityConfig(com.thoughtworks.go.config.SecurityConfig) Username(com.thoughtworks.go.server.domain.Username) Test(org.junit.Test)

Example 62 with AgentConfig

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

the class AgentRegistrationControllerTest method shouldRegisterWithProvidedAgentInformation.

@Test
public void shouldRegisterWithProvidedAgentInformation() throws Exception {
    when(goConfigService.hasAgent("blahAgent-uuid")).thenReturn(false);
    ServerConfig serverConfig = new ServerConfig("artifacts", new SecurityConfig(), 10, 20, "1", null);
    when(goConfigService.serverConfig()).thenReturn(serverConfig);
    when(agentService.agentUsername("blahAgent-uuid", request.getRemoteAddr(), "blahAgent-host")).thenReturn(new Username("some-agent-login-name"));
    ModelAndView modelAndView = controller.agentRequest("blahAgent-host", "blahAgent-uuid", "blah-location", "34567", "osx", "", "", "", "", "", "", false, request);
    assertThat(modelAndView.getView().getContentType(), is("application/json"));
    verify(agentService).requestRegistration(new Username("some-agent-login-name"), AgentRuntimeInfo.fromServer(new AgentConfig("blahAgent-uuid", "blahAgent-host", request.getRemoteAddr()), false, "blah-location", 34567L, "osx", false));
}
Also used : ServerConfig(com.thoughtworks.go.config.ServerConfig) AgentConfig(com.thoughtworks.go.config.AgentConfig) SecurityConfig(com.thoughtworks.go.config.SecurityConfig) Username(com.thoughtworks.go.server.domain.Username) ModelAndView(org.springframework.web.servlet.ModelAndView) Test(org.junit.Test)

Example 63 with AgentConfig

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

the class AgentRegistrationControllerTest method shouldAutoRegisterAgentWithHostnameFromAutoRegisterProperties.

@Test
public void shouldAutoRegisterAgentWithHostnameFromAutoRegisterProperties() throws Exception {
    String uuid = "uuid";
    when(goConfigService.hasAgent(uuid)).thenReturn(false);
    ServerConfig serverConfig = new ServerConfig("artifacts", new SecurityConfig(), 10, 20, "1", "someKey");
    when(goConfigService.serverConfig()).thenReturn(serverConfig);
    when(agentService.agentUsername(uuid, request.getRemoteAddr(), "autoregister-hostname")).thenReturn(new Username("some-agent-login-name"));
    when(agentConfigService.updateAgent(any(UpdateConfigCommand.class), eq(uuid), any(HttpOperationResult.class), eq(new Username("some-agent-login-name")))).thenReturn(new AgentConfig(uuid, "autoregister-hostname", request.getRemoteAddr()));
    controller.agentRequest("host", uuid, "location", "233232", "osx", "someKey", "", "", "autoregister-hostname", "", "", false, request);
    verify(agentService).requestRegistration(new Username("some-agent-login-name"), AgentRuntimeInfo.fromServer(new AgentConfig(uuid, "autoregister-hostname", request.getRemoteAddr()), false, "location", 233232L, "osx", false));
    verify(agentConfigService).updateAgent(any(UpdateConfigCommand.class), eq(uuid), any(HttpOperationResult.class), eq(new Username("some-agent-login-name")));
}
Also used : ServerConfig(com.thoughtworks.go.config.ServerConfig) HttpOperationResult(com.thoughtworks.go.server.service.result.HttpOperationResult) AgentConfig(com.thoughtworks.go.config.AgentConfig) UpdateConfigCommand(com.thoughtworks.go.config.UpdateConfigCommand) SecurityConfig(com.thoughtworks.go.config.SecurityConfig) Username(com.thoughtworks.go.server.domain.Username) Test(org.junit.Test)

Example 64 with AgentConfig

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

the class AgentRegistrationControllerTest method shouldAutoRegisterAgent.

@Test
public void shouldAutoRegisterAgent() throws Exception {
    String uuid = "uuid";
    when(goConfigService.hasAgent(uuid)).thenReturn(false);
    ServerConfig serverConfig = new ServerConfig("artifacts", new SecurityConfig(), 10, 20, "1", "someKey");
    when(goConfigService.serverConfig()).thenReturn(serverConfig);
    when(agentService.agentUsername(uuid, request.getRemoteAddr(), "host")).thenReturn(new Username("some-agent-login-name"));
    when(agentConfigService.updateAgent(any(UpdateConfigCommand.class), eq(uuid), any(HttpOperationResult.class), eq(new Username("some-agent-login-name")))).thenReturn(new AgentConfig(uuid, "host", request.getRemoteAddr()));
    controller.agentRequest("host", uuid, "location", "233232", "osx", "someKey", "", "", "", "", "", false, request);
    verify(agentService).requestRegistration(new Username("some-agent-login-name"), AgentRuntimeInfo.fromServer(new AgentConfig(uuid, "host", request.getRemoteAddr()), false, "location", 233232L, "osx", false));
    verify(agentConfigService).updateAgent(any(UpdateConfigCommand.class), eq(uuid), any(HttpOperationResult.class), eq(new Username("some-agent-login-name")));
}
Also used : ServerConfig(com.thoughtworks.go.config.ServerConfig) HttpOperationResult(com.thoughtworks.go.server.service.result.HttpOperationResult) AgentConfig(com.thoughtworks.go.config.AgentConfig) UpdateConfigCommand(com.thoughtworks.go.config.UpdateConfigCommand) SecurityConfig(com.thoughtworks.go.config.SecurityConfig) Username(com.thoughtworks.go.server.domain.Username) Test(org.junit.Test)

Example 65 with AgentConfig

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

the class ElasticAgentRequestProcessorTest method shouldProcessDeleteAgentRequest.

@Test
public void shouldProcessDeleteAgentRequest() throws Exception {
    AgentMetadata agent = new AgentMetadata("foo", null, null, null);
    DefaultGoApiRequest goPluginApiRequest = new DefaultGoApiRequest(PROCESS_DELETE_AGENTS, "1.0", pluginIdentifier);
    goPluginApiRequest.setRequestBody(extension.getElasticAgentMessageConverter(goPluginApiRequest.apiVersion()).listAgentsResponseBody(Arrays.asList(agent)));
    AgentInstance agentInstance = AgentInstance.createFromConfig(new AgentConfig("uuid"), null);
    when(agentService.findElasticAgent("foo", "docker")).thenReturn(agentInstance);
    processor.process(pluginDescriptor, goPluginApiRequest);
    verify(agentConfigService).deleteAgents(processor.usernameFor(pluginDescriptor), agentInstance);
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) AgentConfig(com.thoughtworks.go.config.AgentConfig) ElasticAgentMetadata(com.thoughtworks.go.server.domain.ElasticAgentMetadata) AgentMetadata(com.thoughtworks.go.plugin.access.elastic.models.AgentMetadata) DefaultGoApiRequest(com.thoughtworks.go.plugin.api.request.DefaultGoApiRequest) Test(org.junit.Test)

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