Search in sources :

Example 51 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 = mockedServerConfig("token-generation-key", "someKey");
    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, token(uuid, serverConfig.getTokenGenerationKey()), 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) Username(com.thoughtworks.go.server.domain.Username) Test(org.junit.Test)

Example 52 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 = mockedServerConfig("token-generation-key", "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, token(uuid, serverConfig.getTokenGenerationKey()), 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) Username(com.thoughtworks.go.server.domain.Username) Test(org.junit.Test)

Example 53 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 = mockedServerConfig("token-generation-key", "someKey");
    when(goConfigService.serverConfig()).thenReturn(serverConfig);
    when(agentService.agentUsername("blahAgent-uuid", request.getRemoteAddr(), "blahAgent-host")).thenReturn(new Username("some-agent-login-name"));
    controller.agentRequest("blahAgent-host", "blahAgent-uuid", "blah-location", "34567", "osx", "", "", "", "", "", "", false, token("blahAgent-uuid", serverConfig.getTokenGenerationKey()), request);
    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) Username(com.thoughtworks.go.server.domain.Username) Test(org.junit.Test)

Example 54 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";
    final ServerConfig serverConfig = mockedServerConfig("token-generation-key", "someKey");
    final String token = token(uuid, serverConfig.getTokenGenerationKey());
    when(goConfigService.hasAgent(uuid)).thenReturn(false);
    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, token, 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) Username(com.thoughtworks.go.server.domain.Username) Test(org.junit.Test)

Example 55 with AgentConfig

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

the class AgentStatusChangeNotifierTest method shouldNotifyIfAgentIsElastic.

@Test
public void shouldNotifyIfAgentIsElastic() throws Exception {
    ElasticAgentRuntimeInfo agentRuntimeInfo = new ElasticAgentRuntimeInfo(new AgentIdentifier("localhost", "127.0.0.1", "uuid"), AgentRuntimeStatus.Idle, "/foo/one", null, "42", "go.cd.elastic-agent-plugin.docker");
    AgentConfig agentConfig = new AgentConfig();
    agentConfig.setElasticAgentId("42");
    agentConfig.setElasticPluginId("go.cd.elastic-agent-plugin.docker");
    agentConfig.setIpAddress("127.0.0.1");
    AgentInstance agentInstance = AgentInstance.createFromConfig(agentConfig, new SystemEnvironment(), mock(AgentStatusChangeListener.class));
    agentInstance.update(agentRuntimeInfo);
    when(notificationPluginRegistry.isAnyPluginInterestedIn("agent-status")).thenReturn(true);
    agentStatusChangeNotifier.onAgentStatusChange(agentInstance);
    verify(pluginNotificationQueue).post(captor.capture());
    assertThat(captor.getValue().getData() instanceof AgentNotificationData, is(true));
    AgentNotificationData data = (AgentNotificationData) captor.getValue().getData();
    assertTrue(data.isElastic());
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) AgentConfig(com.thoughtworks.go.config.AgentConfig) AgentNotificationData(com.thoughtworks.go.domain.notificationdata.AgentNotificationData) ElasticAgentRuntimeInfo(com.thoughtworks.go.server.service.ElasticAgentRuntimeInfo) AgentIdentifier(com.thoughtworks.go.remote.AgentIdentifier) AgentStatusChangeListener(com.thoughtworks.go.listener.AgentStatusChangeListener) 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