Search in sources :

Example 86 with AgentConfig

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

the class AgentRegistrationControllerIntegrationTest method shouldRejectGenerateTokenRequestIfAgentIsInConfig.

@Test
public void shouldRejectGenerateTokenRequestIfAgentIsInConfig() throws Exception {
    System.setProperty(SystemEnvironment.AUTO_REGISTER_LOCAL_AGENT_ENABLED.propertyName(), "false");
    final String uuid = UUID.randomUUID().toString();
    agentConfigService.addAgent(new AgentConfig(uuid, "hostname", "127.0.01"), Username.ANONYMOUS);
    assertTrue(agentService.findAgent(uuid).getAgentConfigStatus().equals(AgentConfigStatus.Enabled));
    final ResponseEntity responseEntity = controller.getToken(uuid);
    assertThat(responseEntity.getStatusCode(), Matchers.is(CONFLICT));
    assertThat(responseEntity.getBody(), Matchers.is("A token has already been issued for this agent."));
}
Also used : AgentConfig(com.thoughtworks.go.config.AgentConfig) ResponseEntity(org.springframework.http.ResponseEntity) Test(org.junit.Test)

Example 87 with AgentConfig

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

the class AgentRegistrationControllerIntegrationTest method shouldRegisterLocalAgent.

@Test
public void shouldRegisterLocalAgent() throws Exception {
    System.setProperty(SystemEnvironment.AUTO_REGISTER_LOCAL_AGENT_ENABLED.propertyName(), "true");
    String uuid = UUID.randomUUID().toString();
    MockHttpServletRequest request = new MockHttpServletRequest();
    final ResponseEntity responseEntity = controller.agentRequest("hostname", uuid, "sandbox", "100", null, null, null, null, null, null, null, false, token(uuid, goConfigService.serverConfig().getTokenGenerationKey()), request);
    AgentConfig agentConfig = goConfigService.agentByUuid(uuid);
    assertThat(agentConfig.getHostname(), is("hostname"));
    assertThat(responseEntity.getStatusCode(), is(HttpStatus.OK));
    assertThat(responseEntity.getHeaders().getContentType(), is(MediaType.APPLICATION_JSON));
    assertTrue(RegistrationJSONizer.fromJson(responseEntity.getBody().toString()).isValid());
}
Also used : AgentConfig(com.thoughtworks.go.config.AgentConfig) ResponseEntity(org.springframework.http.ResponseEntity) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Test(org.junit.Test)

Example 88 with AgentConfig

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

the class AgentRegistrationControllerIntegrationTest method shouldRejectGenerateTokenRequestIfAgentIsInPendingState.

@Test
public void shouldRejectGenerateTokenRequestIfAgentIsInPendingState() throws Exception {
    System.setProperty(SystemEnvironment.AUTO_REGISTER_LOCAL_AGENT_ENABLED.propertyName(), "false");
    final String uuid = UUID.randomUUID().toString();
    final AgentRuntimeInfo agentRuntimeInfo = AgentRuntimeInfo.fromServer(new AgentConfig(uuid, "hostname", "127.0.01"), false, "sandbox", 0l, "linux", false);
    agentService.requestRegistration(agentService.agentUsername(uuid, "127.0.0.1", "hostname"), agentRuntimeInfo);
    final AgentInstance agentInstance = agentService.findAgent(uuid);
    assertTrue(agentInstance.isPending());
    final ResponseEntity responseEntity = controller.getToken(uuid);
    assertThat(responseEntity.getStatusCode(), Matchers.is(CONFLICT));
    assertThat(responseEntity.getBody(), Matchers.is("A token has already been issued for this agent."));
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) AgentRuntimeInfo(com.thoughtworks.go.server.service.AgentRuntimeInfo) AgentConfig(com.thoughtworks.go.config.AgentConfig) ResponseEntity(org.springframework.http.ResponseEntity) Test(org.junit.Test)

Example 89 with AgentConfig

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

the class ElasticAgentRequestProcessorV1Test method shouldProcessDeleteAgentRequest.

@Test
public void shouldProcessDeleteAgentRequest() {
    AgentInstance agentInstance = AgentInstance.createFromConfig(new AgentConfig("uuid"), null, null);
    when(request.api()).thenReturn(REQUEST_DELETE_AGENTS);
    when(request.requestBody()).thenReturn("[{\"agent_id\":\"foo\"}]");
    when(agentService.findElasticAgent("foo", "cd.go.example.plugin")).thenReturn(agentInstance);
    processor.process(pluginDescriptor, request);
    verify(agentConfigService).deleteAgents(processor.usernameFor(pluginDescriptor.id()), agentInstance);
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) AgentConfig(com.thoughtworks.go.config.AgentConfig) Test(org.junit.Test)

Example 90 with AgentConfig

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

the class ElasticAgentRequestProcessorV1Test method shouldProcessDisableAgentRequest.

@Test
public void shouldProcessDisableAgentRequest() {
    AgentInstance agentInstance = AgentInstance.createFromConfig(new AgentConfig("uuid"), null, null);
    when(request.api()).thenReturn(REQUEST_DISABLE_AGENTS);
    when(request.requestBody()).thenReturn("[{\"agent_id\":\"foo\"}]");
    when(agentService.findElasticAgent("foo", "cd.go.example.plugin")).thenReturn(agentInstance);
    processor.process(pluginDescriptor, request);
    verify(agentConfigService).disableAgents(processor.usernameFor(pluginDescriptor.id()), agentInstance);
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) AgentConfig(com.thoughtworks.go.config.AgentConfig) 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