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;
}
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"));
}
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)"));
}
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));
}
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"))));
}
Aggregations