Search in sources :

Example 96 with HttpLocalizedOperationResult

use of com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult in project gocd by gocd.

the class AgentConfigServiceIntegrationTest method shouldDisableTheProvidedAgents.

@Test
public void shouldDisableTheProvidedAgents() throws Exception {
    AgentConfig agentConfig1 = new AgentConfig(UUID.randomUUID().toString(), "remote-host1", "50.40.30.21");
    AgentConfig agentConfig2 = new AgentConfig(UUID.randomUUID().toString(), "remote-host2", "50.40.30.22");
    AgentInstance agentInstance1 = AgentInstance.createFromConfig(agentConfig1, new SystemEnvironment());
    AgentInstance agentInstance2 = AgentInstance.createFromConfig(agentConfig2, new SystemEnvironment());
    agentInstances.add(agentInstance1);
    agentInstances.add(agentInstance2);
    agentConfigService.addAgent(agentConfig1, Username.ANONYMOUS);
    agentConfigService.addAgent(agentConfig2, Username.ANONYMOUS);
    CruiseConfig cruiseConfig = goConfigDao.load();
    assertThat(cruiseConfig.agents().getAgentByUuid(agentConfig1.getUuid()).isDisabled(), is(false));
    assertThat(cruiseConfig.agents().getAgentByUuid(agentConfig2.getUuid()).isDisabled(), is(false));
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    ArrayList<String> uuids = new ArrayList<>();
    uuids.add(agentConfig1.getUuid());
    uuids.add(agentConfig2.getUuid());
    agentConfigService.bulkUpdateAgentAttributes(agentInstances, Username.ANONYMOUS, result, uuids, new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), TriState.FALSE);
    cruiseConfig = goConfigDao.load();
    assertTrue(result.isSuccessful());
    assertTrue(result.toString(), result.toString().contains("BULK_AGENT_UPDATE_SUCESSFUL"));
    assertTrue(cruiseConfig.agents().getAgentByUuid(agentConfig1.getUuid()).isDisabled());
    assertTrue(cruiseConfig.agents().getAgentByUuid(agentConfig2.getUuid()).isDisabled());
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 97 with HttpLocalizedOperationResult

use of com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult in project gocd by gocd.

the class AgentConfigServiceIntegrationTest method shouldNotEnableAgentsWhenInvalidAgentUUIDIsprovided.

@Test
public void shouldNotEnableAgentsWhenInvalidAgentUUIDIsprovided() throws Exception {
    AgentConfig agentConfig1 = new AgentConfig(UUID.randomUUID().toString(), "remote-host1", "50.40.30.21");
    AgentConfig agentConfig2 = new AgentConfig(UUID.randomUUID().toString(), "remote-host2", "50.40.30.22");
    AgentInstance agentInstance1 = AgentInstance.createFromConfig(agentConfig1, new SystemEnvironment());
    AgentInstance agentInstance2 = AgentInstance.createFromConfig(agentConfig2, new SystemEnvironment());
    agentInstances.add(agentInstance1);
    agentInstances.add(agentInstance2);
    agentConfigService.addAgent(agentConfig1, Username.ANONYMOUS);
    agentConfigService.addAgent(agentConfig2, Username.ANONYMOUS);
    CruiseConfig cruiseConfig = goConfigDao.load();
    assertFalse(cruiseConfig.agents().getAgentByUuid(agentConfig1.getUuid()).isDisabled());
    assertFalse(cruiseConfig.agents().getAgentByUuid(agentConfig2.getUuid()).isDisabled());
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    ArrayList<String> uuids = new ArrayList<>();
    uuids.add(agentConfig1.getUuid());
    uuids.add(agentConfig2.getUuid());
    uuids.add("invalid-uuid");
    agentConfigService.bulkUpdateAgentAttributes(agentInstances, Username.ANONYMOUS, result, uuids, new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), TriState.TRUE);
    cruiseConfig = goConfigDao.load();
    assertThat(cruiseConfig.agents().getAgentByUuid(agentConfig1.getUuid()).isDisabled(), is(false));
    assertThat(cruiseConfig.agents().getAgentByUuid(agentConfig2.getUuid()).isDisabled(), is(false));
    assertFalse(result.isSuccessful());
    assertThat(result.toString(), result.httpCode(), is(400));
    assertTrue(result.toString(), result.toString().contains("RESOURCE_NOT_FOUND"));
    assertTrue(result.toString(), result.toString().contains("invalid-uuid"));
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 98 with HttpLocalizedOperationResult

use of com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult in project gocd by gocd.

the class AgentConfigServiceIntegrationTest method shouldNotDisableAgentsWhenInvalidAgentUUIDIsprovided.

@Test
public void shouldNotDisableAgentsWhenInvalidAgentUUIDIsprovided() throws Exception {
    AgentConfig agentConfig1 = new AgentConfig(UUID.randomUUID().toString(), "remote-host1", "50.40.30.21");
    AgentConfig agentConfig2 = new AgentConfig(UUID.randomUUID().toString(), "remote-host2", "50.40.30.22");
    AgentInstance agentInstance1 = AgentInstance.createFromConfig(agentConfig1, new SystemEnvironment());
    AgentInstance agentInstance2 = AgentInstance.createFromConfig(agentConfig2, new SystemEnvironment());
    agentInstances.add(agentInstance1);
    agentInstances.add(agentInstance2);
    agentConfigService.addAgent(agentConfig1, Username.ANONYMOUS);
    agentConfigService.addAgent(agentConfig2, Username.ANONYMOUS);
    CruiseConfig cruiseConfig = goConfigDao.load();
    assertFalse(cruiseConfig.agents().getAgentByUuid(agentConfig1.getUuid()).isDisabled());
    assertFalse(cruiseConfig.agents().getAgentByUuid(agentConfig1.getUuid()).isDisabled());
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    ArrayList<String> uuids = new ArrayList<>();
    uuids.add(agentConfig1.getUuid());
    uuids.add(agentConfig2.getUuid());
    uuids.add("invalid-uuid");
    agentConfigService.bulkUpdateAgentAttributes(agentInstances, Username.ANONYMOUS, result, uuids, new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), TriState.FALSE);
    cruiseConfig = goConfigDao.load();
    assertFalse(cruiseConfig.agents().getAgentByUuid(agentConfig1.getUuid()).isDisabled());
    assertFalse(cruiseConfig.agents().getAgentByUuid(agentConfig2.getUuid()).isDisabled());
    assertFalse(result.isSuccessful());
    assertThat(result.toString(), result.httpCode(), is(400));
    assertTrue(result.toString(), result.toString().contains("RESOURCE_NOT_FOUND"));
    assertTrue(result.toString(), result.toString().contains("invalid-uuid"));
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 99 with HttpLocalizedOperationResult

use of com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult in project gocd by gocd.

the class AgentConfigServiceIntegrationTest method shouldAddProvidedAgentsToTheSpecifiedEnvironments.

@Test
public void shouldAddProvidedAgentsToTheSpecifiedEnvironments() throws Exception {
    AgentConfig agentConfig1 = new AgentConfig(UUID.randomUUID().toString(), "remote-host1", "50.40.30.21");
    AgentConfig agentConfig2 = new AgentConfig(UUID.randomUUID().toString(), "remote-host2", "50.40.30.22");
    AgentInstance agentInstance1 = AgentInstance.createFromConfig(agentConfig1, new SystemEnvironment());
    AgentInstance agentInstance2 = AgentInstance.createFromConfig(agentConfig2, new SystemEnvironment());
    agentInstances.add(agentInstance1);
    agentInstances.add(agentInstance2);
    agentConfigService.addAgent(agentConfig1, Username.ANONYMOUS);
    agentConfigService.addAgent(agentConfig2, Username.ANONYMOUS);
    BasicEnvironmentConfig environment = new BasicEnvironmentConfig(new CaseInsensitiveString("Dev"));
    goConfigDao.addEnvironment(environment);
    assertFalse(environment.hasAgent(agentConfig1.getUuid()));
    assertFalse(environment.hasAgent(agentConfig2.getUuid()));
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    ArrayList<String> uuids = new ArrayList<>();
    uuids.add(agentConfig1.getUuid());
    uuids.add(agentConfig2.getUuid());
    ArrayList<String> environmentsToAdd = new ArrayList<>();
    environmentsToAdd.add("Dev");
    agentConfigService.bulkUpdateAgentAttributes(agentInstances, Username.ANONYMOUS, result, uuids, new ArrayList<>(), new ArrayList<>(), environmentsToAdd, new ArrayList<>(), TriState.TRUE);
    assertTrue(result.isSuccessful());
    assertThat(result.toString(), containsString("BULK_AGENT_UPDATE_SUCESSFUL"));
    assertThat(goConfigDao.load().getEnvironments().find(new CaseInsensitiveString("Dev")).getAgents().getUuids(), containsInAnyOrder(agentConfig1.getUuid(), agentConfig2.getUuid()));
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 100 with HttpLocalizedOperationResult

use of com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult in project gocd by gocd.

the class AgentConfigServiceIntegrationTest method shouldAllowEnablingThePendingAndDisabledAgentsTogether.

@Test
public void shouldAllowEnablingThePendingAndDisabledAgentsTogether() throws Exception {
    AgentInstance pendingAgent = AgentInstanceMother.pending();
    agentInstances.add(pendingAgent);
    assertThat(pendingAgent.isRegistered(), is(false));
    AgentConfig agentConfig = new AgentConfig(UUID.randomUUID().toString(), "remote-host1", "50.40.30.21");
    agentConfig.disable();
    AgentInstance agentInstance = AgentInstance.createFromConfig(agentConfig, new SystemEnvironment());
    agentInstances.add(agentInstance);
    agentConfigService.addAgent(agentConfig, Username.ANONYMOUS);
    CruiseConfig cruiseConfig = goConfigDao.load();
    assertThat(cruiseConfig.agents().getAgentByUuid(agentConfig.getUuid()).isDisabled(), is(true));
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    ArrayList<String> uuids = new ArrayList<>();
    uuids.add(pendingAgent.getUuid());
    uuids.add(agentConfig.getUuid());
    agentConfigService.bulkUpdateAgentAttributes(agentInstances, Username.ANONYMOUS, result, uuids, new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), TriState.TRUE);
    assertTrue(result.isSuccessful());
    assertTrue(result.toString(), result.toString().contains("BULK_AGENT_UPDATE_SUCESSFUL"));
    cruiseConfig = goConfigDao.load();
    assertThat(cruiseConfig.agents().getAgentByUuid(pendingAgent.getUuid()).isEnabled(), is(true));
    assertThat(cruiseConfig.agents().getAgentByUuid(agentConfig.getUuid()).isEnabled(), is(true));
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)361 Test (org.junit.Test)329 Username (com.thoughtworks.go.server.domain.Username)131 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)36 Pipeline (com.thoughtworks.go.domain.Pipeline)27 ArrayList (java.util.ArrayList)27 Before (org.junit.Before)22 MaterialRevision (com.thoughtworks.go.domain.MaterialRevision)20 PipelineMaterialRevision (com.thoughtworks.go.domain.PipelineMaterialRevision)20 PackageRepository (com.thoughtworks.go.domain.packagerepository.PackageRepository)19 SecurityAuthConfig (com.thoughtworks.go.config.SecurityAuthConfig)17 ConfigUpdateResponse (com.thoughtworks.go.config.update.ConfigUpdateResponse)17 AgentInstance (com.thoughtworks.go.domain.AgentInstance)17 UserSearchModel (com.thoughtworks.go.presentation.UserSearchModel)16 Matchers.containsString (org.hamcrest.Matchers.containsString)16 GoConfigMother (com.thoughtworks.go.helper.GoConfigMother)15 GoCipher (com.thoughtworks.go.security.GoCipher)14 SystemEnvironment (com.thoughtworks.go.util.SystemEnvironment)14 DependencyMaterial (com.thoughtworks.go.config.materials.dependency.DependencyMaterial)13 PackageRepositories (com.thoughtworks.go.domain.packagerepository.PackageRepositories)12