Search in sources :

Example 21 with HttpOperationResult

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

the class AgentServiceIntegrationTest method createDisabledAndIdleAgent.

private AgentConfig createDisabledAndIdleAgent(String uuid) {
    AgentConfig agentConfig = new AgentConfig(uuid, "agentName", "127.0.0.9");
    addAgent(agentConfig);
    AgentIdentifier agentIdentifier = agentConfig.getAgentIdentifier();
    String cookie = agentService.assignCookie(agentIdentifier);
    AgentRuntimeInfo agentRuntimeInfo = new AgentRuntimeInfo(agentIdentifier, AgentRuntimeStatus.Idle, currentWorkingDirectory(), cookie, false);
    agentRuntimeInfo.idle();
    agentService.updateRuntimeInfo(agentRuntimeInfo);
    assertTrue(agentService.findAgentAndRefreshStatus(uuid).isIdle());
    agentService.disableAgents(USERNAME, new HttpOperationResult(), Arrays.asList(agentConfig.getUuid()));
    AgentConfig updatedAgent = goConfigDao.load().agents().getAgentByUuid(agentConfig.getUuid());
    assertThat(isDisabled(updatedAgent), is(true));
    return updatedAgent;
}
Also used : HttpOperationResult(com.thoughtworks.go.server.service.result.HttpOperationResult) AgentIdentifier(com.thoughtworks.go.remote.AgentIdentifier)

Example 22 with HttpOperationResult

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

the class AgentServiceIntegrationTest method shouldRemoveEnvironmentsFromMultipleAgents.

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

Example 23 with HttpOperationResult

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

the class AgentServiceIntegrationTest method shouldAllowDisablingAgentWhenPending.

@Test
public void shouldAllowDisablingAgentWhenPending() {
    String agentName = "agentName";
    String agentId = DatabaseAccessHelper.AGENT_UUID;
    AgentConfig agentConfig = new AgentConfig(agentId, agentName, "50.40.30.9");
    AgentRuntimeInfo agentRuntimeInfo = new AgentRuntimeInfo(agentConfig.getAgentIdentifier(), AgentRuntimeStatus.Idle, currentWorkingDirectory(), "cookie", false);
    agentRuntimeInfo.busy(new AgentBuildingInfo("path", "buildLocator"));
    agentService.requestRegistration(new Username("bob"), agentRuntimeInfo);
    HttpOperationResult operationResult = new HttpOperationResult();
    agentService.disableAgents(USERNAME, operationResult, Arrays.asList(agentId));
    assertThat(operationResult.httpCode(), is(200));
    assertThat(operationResult.message(), is("Disabled 1 agent(s)"));
}
Also used : HttpOperationResult(com.thoughtworks.go.server.service.result.HttpOperationResult) Username(com.thoughtworks.go.server.domain.Username) Test(org.junit.Test)

Example 24 with HttpOperationResult

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

the class AgentServiceIntegrationTest method shouldDenyAgentFromPendingList.

@Test
public void shouldDenyAgentFromPendingList() throws Exception {
    AgentInstance pending = AgentInstanceMother.pending();
    agentService.requestRegistration(new Username("bob"), AgentRuntimeInfo.fromServer(pending.agentConfig(), false, "var/lib", 0L, "linux", false));
    String uuid = pending.getUuid();
    HttpOperationResult operationResult = new HttpOperationResult();
    agentService.disableAgents(USERNAME, operationResult, Arrays.asList(uuid));
    assertAgentDisablingSucceeded(operationResult, uuid);
    Agents agents = agentConfigService.agents();
    assertThat(agentService.agents().size(), is(1));
    assertThat(agents.size(), is(1));
    assertThat(agents.get(0).isDisabled(), is(true));
    assertThat(agentService.findAgentAndRefreshStatus(uuid).isDisabled(), is(true));
    assertThat(agentService.findAgentAndRefreshStatus(uuid).getStatus(), is(AgentStatus.Disabled));
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) HttpOperationResult(com.thoughtworks.go.server.service.result.HttpOperationResult) Username(com.thoughtworks.go.server.domain.Username) Test(org.junit.Test)

Example 25 with HttpOperationResult

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

the class AgentServiceIntegrationTest method shouldRemoveResourcesFromMultipleAgents.

@Test
public void shouldRemoveResourcesFromMultipleAgents() {
    createEnabledAgent(UUID);
    createEnabledAgent(UUID2);
    HttpOperationResult operationResult = new HttpOperationResult();
    agentService.modifyResources(USERNAME, operationResult, Arrays.asList(UUID, UUID2), Arrays.asList(new TriStateSelection("resource-1", TriStateSelection.Action.add), new TriStateSelection("resource-2", TriStateSelection.Action.add)));
    agentService.modifyResources(USERNAME, operationResult, Arrays.asList(UUID, UUID2), Arrays.asList(new TriStateSelection("resource-1", TriStateSelection.Action.remove)));
    assertThat(operationResult.httpCode(), is(200));
    assertThat(operationResult.message(), is("Resource(s) modified on 2 agent(s)"));
    assertThat(agentService.findAgentAndRefreshStatus(UUID).agentConfig().getResourceConfigs(), hasItem(new ResourceConfig("resource-2")));
    assertThat(agentService.findAgentAndRefreshStatus(UUID).agentConfig().getResourceConfigs(), not(hasItem(new ResourceConfig("resource-1"))));
    assertThat(agentService.findAgentAndRefreshStatus(UUID2).agentConfig().getResourceConfigs(), hasItem(new ResourceConfig("resource-2")));
    assertThat(agentService.findAgentAndRefreshStatus(UUID2).agentConfig().getResourceConfigs(), not(hasItem(new ResourceConfig("resource-1"))));
}
Also used : HttpOperationResult(com.thoughtworks.go.server.service.result.HttpOperationResult) TriStateSelection(com.thoughtworks.go.presentation.TriStateSelection) Test(org.junit.Test)

Aggregations

HttpOperationResult (com.thoughtworks.go.server.service.result.HttpOperationResult)146 Test (org.junit.jupiter.api.Test)64 Test (org.junit.Test)53 Username (com.thoughtworks.go.server.domain.Username)34 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)23 TriStateSelection (com.thoughtworks.go.presentation.TriStateSelection)12 Pagination (com.thoughtworks.go.server.util.Pagination)7 SvnMaterial (com.thoughtworks.go.config.materials.svn.SvnMaterial)6 StageStatusCache (com.thoughtworks.go.domain.activity.StageStatusCache)6 MaterialConfig (com.thoughtworks.go.domain.materials.MaterialConfig)6 StageStatusTopic (com.thoughtworks.go.server.messaging.StageStatusTopic)6 GitMaterialConfig (com.thoughtworks.go.config.materials.git.GitMaterialConfig)5 AgentInstance (com.thoughtworks.go.domain.AgentInstance)5 BeforeEach (org.junit.jupiter.api.BeforeEach)5 PipelineConfig (com.thoughtworks.go.config.PipelineConfig)4 MaterialConfigs (com.thoughtworks.go.config.materials.MaterialConfigs)4 NullStage (com.thoughtworks.go.domain.NullStage)4 BuildCause (com.thoughtworks.go.domain.buildcause.BuildCause)4 PipelineStatusModel (com.thoughtworks.go.presentation.PipelineStatusModel)4 Stage (com.thoughtworks.go.domain.Stage)3