Search in sources :

Example 1 with TriStateSelection

use of com.thoughtworks.go.presentation.TriStateSelection in project gocd by gocd.

the class GoConfigService method modifyEnvironments.

public void modifyEnvironments(List<AgentInstance> agents, List<TriStateSelection> selections) {
    GoConfigDao.CompositeConfigCommand command = new GoConfigDao.CompositeConfigCommand();
    for (AgentInstance agentInstance : agents) {
        String uuid = agentInstance.getUuid();
        if (hasAgent(uuid)) {
            for (TriStateSelection selection : selections) {
                command.addCommand(new ModifyEnvironmentCommand(uuid, selection.getValue(), selection.getAction()));
            }
        }
    }
    updateConfig(command);
}
Also used : TriStateSelection(com.thoughtworks.go.presentation.TriStateSelection)

Example 2 with TriStateSelection

use of com.thoughtworks.go.presentation.TriStateSelection in project gocd by gocd.

the class AgentServiceIntegrationTest method shouldRespondToAgentEnvironmentModificationRequestWith406WhenErrors.

@Test
public void shouldRespondToAgentEnvironmentModificationRequestWith406WhenErrors() throws Exception {
    createEnabledAgent(UUID);
    HttpOperationResult operationResult = new HttpOperationResult();
    agentService.modifyEnvironments(USERNAME, operationResult, Arrays.asList(UUID), Arrays.asList(new TriStateSelection("unknown_env", TriStateSelection.Action.add)));
    assertThat(operationResult.httpCode(), is(406));
    assertThat(operationResult.message(), containsString("Could not modify environments:"));
}
Also used : HttpOperationResult(com.thoughtworks.go.server.service.result.HttpOperationResult) TriStateSelection(com.thoughtworks.go.presentation.TriStateSelection) Test(org.junit.Test)

Example 3 with TriStateSelection

use of com.thoughtworks.go.presentation.TriStateSelection in project gocd by gocd.

the class AgentServiceIntegrationTest method shouldNotAllowAddingResourcesWhenNotAdmin.

@Test
public void shouldNotAllowAddingResourcesWhenNotAdmin() throws IOException {
    String agentId = "agent-id";
    CONFIG_HELPER.enableSecurity();
    HttpOperationResult operationResult = new HttpOperationResult();
    CONFIG_HELPER.addAdmins("admin1");
    agentService.modifyResources(new Username(new CaseInsensitiveString("not-admin")), operationResult, Arrays.asList(agentId), Arrays.asList(new TriStateSelection("dont-care", TriStateSelection.Action.add)));
    assertThat(operationResult.httpCode(), is(401));
    assertThat(operationResult.message(), is("Unauthorized to operate on agent"));
}
Also used : HttpOperationResult(com.thoughtworks.go.server.service.result.HttpOperationResult) Username(com.thoughtworks.go.server.domain.Username) TriStateSelection(com.thoughtworks.go.presentation.TriStateSelection) Test(org.junit.Test)

Example 4 with TriStateSelection

use of com.thoughtworks.go.presentation.TriStateSelection in project gocd by gocd.

the class AgentServiceIntegrationTest method shouldNotChangeEnvironmentsOtherThanTheOneRemoveIsRequestedFor.

@Test
public void shouldNotChangeEnvironmentsOtherThanTheOneRemoveIsRequestedFor() throws Exception {
    createEnvironment("uat", "prod");
    createEnabledAgent(UUID);
    addAgentToEnv("uat", UUID);
    addAgentToEnv("prod", UUID);
    HttpOperationResult operationResult = new HttpOperationResult();
    agentService.modifyEnvironments(USERNAME, operationResult, Arrays.asList(UUID), Arrays.asList(new TriStateSelection("uat", TriStateSelection.Action.remove)));
    assertThat(operationResult.httpCode(), is(200));
    assertThat(operationResult.message(), is("Environment(s) modified on 1 agent(s)"));
    assertThat(environmentConfigService.environmentsFor(UUID), not(containsSet("uat")));
    assertThat(environmentConfigService.environmentsFor(UUID), containsSet("prod"));
}
Also used : HttpOperationResult(com.thoughtworks.go.server.service.result.HttpOperationResult) TriStateSelection(com.thoughtworks.go.presentation.TriStateSelection) Test(org.junit.Test)

Example 5 with TriStateSelection

use of com.thoughtworks.go.presentation.TriStateSelection in project gocd by gocd.

the class AgentServiceIntegrationTest method shouldAddEnvironmentsToMultipleAgents.

@Test
public void shouldAddEnvironmentsToMultipleAgents() throws Exception {
    createEnvironment("uat", "prod");
    createEnabledAgent(UUID);
    createEnabledAgent(UUID2);
    HttpOperationResult operationResult = new HttpOperationResult();
    agentService.modifyEnvironments(USERNAME, operationResult, Arrays.asList(UUID, UUID2), Arrays.asList(new TriStateSelection("uat", TriStateSelection.Action.add), new TriStateSelection("prod", TriStateSelection.Action.add)));
    assertThat(operationResult.httpCode(), is(200));
    assertThat(operationResult.message(), is("Environment(s) modified on 2 agent(s)"));
    assertThat(environmentConfigService.environmentsFor(UUID), containsSet("uat", "prod"));
    assertThat(environmentConfigService.environmentsFor(UUID2), containsSet("uat", "prod"));
}
Also used : HttpOperationResult(com.thoughtworks.go.server.service.result.HttpOperationResult) TriStateSelection(com.thoughtworks.go.presentation.TriStateSelection) Test(org.junit.Test)

Aggregations

TriStateSelection (com.thoughtworks.go.presentation.TriStateSelection)32 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)14 Test (org.junit.jupiter.api.Test)13 HttpOperationResult (com.thoughtworks.go.server.service.result.HttpOperationResult)12 Test (org.junit.Test)12 Username (com.thoughtworks.go.server.domain.Username)6 BeforeEach (org.junit.jupiter.api.BeforeEach)4 GoConfigFileHelper (com.thoughtworks.go.util.GoConfigFileHelper)3 UpdateConfigCommand (com.thoughtworks.go.config.UpdateConfigCommand)2 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)1 PartialConfig (com.thoughtworks.go.config.remote.PartialConfig)1 RepoConfigOrigin (com.thoughtworks.go.config.remote.RepoConfigOrigin)1 AgentInstance (com.thoughtworks.go.domain.AgentInstance)1 MaterialConfig (com.thoughtworks.go.domain.materials.MaterialConfig)1 PackageRepositories (com.thoughtworks.go.domain.packagerepository.PackageRepositories)1 PackageRepository (com.thoughtworks.go.domain.packagerepository.PackageRepository)1 GoCipher (com.thoughtworks.go.security.GoCipher)1 AgentConfigsUpdateValidator (com.thoughtworks.go.validation.AgentConfigsUpdateValidator)1 ArrayList (java.util.ArrayList)1 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)1