Search in sources :

Example 91 with AgentInstance

use of com.thoughtworks.go.domain.AgentInstance in project gocd by gocd.

the class AgentConfigServiceIntegrationTest method shouldEnablePendingAgents.

@Test
public void shouldEnablePendingAgents() throws Exception {
    AgentInstance pendingAgent = AgentInstanceMother.pending();
    agentInstances.add(pendingAgent);
    assertThat(pendingAgent.isRegistered(), is(false));
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    ArrayList<String> uuids = new ArrayList<>();
    uuids.add(pendingAgent.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 cruiseConfig = goConfigDao.load();
    assertThat(cruiseConfig.agents().getAgentByUuid(pendingAgent.getUuid()).isEnabled(), is(true));
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 92 with AgentInstance

use of com.thoughtworks.go.domain.AgentInstance in project gocd by gocd.

the class AgentServiceIntegrationTest method testShouldThrowErrorOnUpdatingAgentOnInvalidInputs.

@Test
public void testShouldThrowErrorOnUpdatingAgentOnInvalidInputs() throws Exception {
    AgentConfig agent = createDisabledAndIdleAgent(UUID);
    String originalHostname = agent.getHostname();
    List<String> originalResourceNames = agent.getResourceConfigs().resourceNames();
    goConfigDao.load();
    assertThat(agentService.agents().size(), is(1));
    assertThat(getFirstAgent().getHostname(), is(not("some-hostname")));
    HttpOperationResult operationResult = new HttpOperationResult();
    AgentInstance agentInstance = agentService.updateAgentAttributes(USERNAME, operationResult, UUID, "some-hostname", "lin!ux", null, TriState.UNSET);
    assertThat(operationResult.httpCode(), is(422));
    assertThat(operationResult.message(), is("Updating agent failed:"));
    assertThat(agentInstance.agentConfig().getResourceConfigs().first().errors().on(JobConfig.RESOURCES), is("Resource name 'lin!ux' is not valid. Valid names much match '^[-\\w\\s|.]*$'"));
    assertThat(agentService.agents().size(), is(1));
    assertThat(getFirstAgent().getHostname(), is(originalHostname));
    assertThat(getFirstAgent().getResourceConfigs().resourceNames(), is(originalResourceNames));
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) HttpOperationResult(com.thoughtworks.go.server.service.result.HttpOperationResult) Test(org.junit.Test)

Example 93 with AgentInstance

use of com.thoughtworks.go.domain.AgentInstance in project gocd by gocd.

the class AgentServiceIntegrationTest method shouldApproveAgent.

@Test
public void shouldApproveAgent() throws Exception {
    AgentInstance pending = AgentInstanceMother.pending();
    agentService.requestRegistration(new Username("bob"), AgentRuntimeInfo.fromServer(pending.agentConfig(), false, "var/lib", 0L, "linux", false));
    agentService.approve(pending.getUuid());
    assertThat(agentService.findRegisteredAgents().size(), is(1));
    assertThat(agentService.findAgentAndRefreshStatus(pending.agentConfig().getUuid()).agentConfig().isDisabled(), is(false));
    CruiseConfig cruiseConfig = goConfigDao.load();
    assertThat(cruiseConfig.agents().get(0).isDisabled(), is(false));
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) Username(com.thoughtworks.go.server.domain.Username) Test(org.junit.Test)

Example 94 with AgentInstance

use of com.thoughtworks.go.domain.AgentInstance in project gocd by gocd.

the class AgentServiceIntegrationTest method shouldLoadAllAgents.

@Test
public void shouldLoadAllAgents() throws Exception {
    AgentInstance idle = AgentInstanceMother.idle(new Date(), "CCeDev01");
    AgentInstance pending = AgentInstanceMother.pending();
    AgentInstance building = AgentInstanceMother.building();
    AgentInstance denied = AgentInstanceMother.disabled();
    AgentService agentService = getAgentService(new AgentInstances(new SystemEnvironment(), agentStatusChangeListener(), idle, pending, building, denied));
    assertThat(agentService.agents().size(), is(4));
    assertThat(agentService.findAgentAndRefreshStatus(idle.agentConfig().getUuid()), is(idle));
    assertThat(agentService.findAgentAndRefreshStatus(pending.agentConfig().getUuid()), is(pending));
    assertThat(agentService.findAgentAndRefreshStatus(building.agentConfig().getUuid()), is(building));
    assertThat(agentService.findAgentAndRefreshStatus(denied.agentConfig().getUuid()), is(denied));
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) AgentInstances(com.thoughtworks.go.server.domain.AgentInstances) Test(org.junit.Test)

Example 95 with AgentInstance

use of com.thoughtworks.go.domain.AgentInstance in project gocd by gocd.

the class AgentServiceIntegrationTest method shouldDenyAgentWhenAgentChangedToDenyInConfigFile.

@Test
public void shouldDenyAgentWhenAgentChangedToDenyInConfigFile() throws Exception {
    disableAgent();
    AgentInstance instance = agentService.findAgentAndRefreshStatus("uuid1");
    assertThat(instance.getStatus(), is(AgentStatus.Disabled));
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) Test(org.junit.Test)

Aggregations

AgentInstance (com.thoughtworks.go.domain.AgentInstance)129 Test (org.junit.Test)61 NullAgentInstance (com.thoughtworks.go.domain.NullAgentInstance)32 SystemEnvironment (com.thoughtworks.go.util.SystemEnvironment)32 ArrayList (java.util.ArrayList)21 Agent (com.thoughtworks.go.config.Agent)20 Test (org.junit.jupiter.api.Test)20 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)17 AgentConfig (com.thoughtworks.go.config.AgentConfig)16 AgentStatusChangeListener (com.thoughtworks.go.listener.AgentStatusChangeListener)12 AgentInstance.createFromLiveAgent (com.thoughtworks.go.domain.AgentInstance.createFromLiveAgent)10 AgentInstances (com.thoughtworks.go.server.domain.AgentInstances)10 AgentIdentifier (com.thoughtworks.go.remote.AgentIdentifier)8 AgentRuntimeInfo (com.thoughtworks.go.server.service.AgentRuntimeInfo)8 AgentInstance.createFromAgent (com.thoughtworks.go.domain.AgentInstance.createFromAgent)7 ResponseEntity (org.springframework.http.ResponseEntity)7 BuildWork (com.thoughtworks.go.remote.work.BuildWork)6 NoWork (com.thoughtworks.go.remote.work.NoWork)6 Work (com.thoughtworks.go.remote.work.Work)6 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)6