Search in sources :

Example 41 with AgentInstance

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

the class AgentViewModelTest method shouldDisplayTheRightStatusMessage.

@Test
public void shouldDisplayTheRightStatusMessage() {
    AgentInstance building = AgentInstanceMother.building();
    assertThat(new AgentViewModel(updateRuntimeStatus(building, AgentRuntimeStatus.Idle)).getStatusForDisplay(), is("Idle"));
    assertThat(new AgentViewModel(updateRuntimeStatus(building, AgentRuntimeStatus.Building)).getStatusForDisplay(), is("Building"));
    assertThat(new AgentViewModel(updateRuntimeStatus(building, AgentRuntimeStatus.Cancelled)).getStatusForDisplay(), is("Building (Cancelled)"));
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) Test(org.junit.Test)

Example 42 with AgentInstance

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

the class AgentsViewModelTest method agentsViewModel.

private AgentsViewModel agentsViewModel() {
    AgentsViewModel agents = new AgentsViewModel();
    AgentInstance idle = AgentInstanceMother.idle(new Date(), "CCeDev01");
    AgentInstanceMother.updateOS(idle, "macos");
    idle.getResources().add(new Resource("foo"));
    idle.getResources().add(new Resource("bar"));
    agents.add(new AgentViewModel(idle, "uat"));
    AgentInstance building = AgentInstanceMother.building();
    building.getResources().add(new Resource("goofooboo"));
    agents.add(new AgentViewModel(building, "dev", "uat"));
    agents.add(new AgentViewModel(AgentInstanceMother.pending()));
    agents.add(new AgentViewModel(AgentInstanceMother.disabled(), "prod"));
    return agents;
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) Resource(com.thoughtworks.go.config.Resource) Date(java.util.Date)

Example 43 with AgentInstance

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

the class ElasticAgentRequestProcessorTest method shouldProcessDisableAgentRequest.

@Test
public void shouldProcessDisableAgentRequest() throws Exception {
    AgentMetadata agent = new AgentMetadata("foo", null, null, null);
    DefaultGoApiRequest goPluginApiRequest = new DefaultGoApiRequest(PROCESS_DISABLE_AGENTS, "1.0", pluginIdentifier);
    goPluginApiRequest.setRequestBody(extension.getElasticAgentMessageConverter(goPluginApiRequest.apiVersion()).listAgentsResponseBody(Arrays.asList(agent)));
    AgentInstance agentInstance = AgentInstance.createFromConfig(new AgentConfig("uuid"), null);
    when(agentService.findElasticAgent("foo", "docker")).thenReturn(agentInstance);
    processor.process(pluginDescriptor, goPluginApiRequest);
    verify(agentConfigService).disableAgents(processor.usernameFor(pluginDescriptor), agentInstance);
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) AgentConfig(com.thoughtworks.go.config.AgentConfig) ElasticAgentMetadata(com.thoughtworks.go.server.domain.ElasticAgentMetadata) AgentMetadata(com.thoughtworks.go.plugin.access.elastic.models.AgentMetadata) DefaultGoApiRequest(com.thoughtworks.go.plugin.api.request.DefaultGoApiRequest) Test(org.junit.Test)

Example 44 with AgentInstance

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

the class AgentConfigServiceTest method shouldEnableMultipleAgents.

@Test
public void shouldEnableMultipleAgents() {
    AgentRuntimeInfo agentRuntimeInfo = AgentRuntimeInfo.fromAgent(new AgentIdentifier("remote-host", "50.40.30.20", "abc"), AgentRuntimeStatus.Unknown, "cookie", false);
    AgentInstance pending = AgentInstance.createFromLiveAgent(agentRuntimeInfo, new SystemEnvironment());
    AgentConfig agentConfig = new AgentConfig("UUID2", "remote-host", "50.40.30.20");
    agentConfig.disable();
    AgentInstance fromConfigFile = AgentInstance.createFromConfig(agentConfig, new SystemEnvironment());
    when(goConfigService.hasAgent(fromConfigFile.getUuid())).thenReturn(true);
    when(goConfigService.hasAgent(pending.getUuid())).thenReturn(false);
    agentConfigService.enableAgents(Username.ANONYMOUS, pending, fromConfigFile);
    GoConfigDao.CompositeConfigCommand command = new GoConfigDao.CompositeConfigCommand(new AgentConfigService.AddAgentCommand(pending.agentConfig()), new AgentConfigService.UpdateAgentApprovalStatus("UUID2", false));
    ArgumentCaptor<AgentsUpdateCommand> captor = ArgumentCaptor.forClass(AgentsUpdateCommand.class);
    verify(goConfigService).updateConfig(captor.capture(), eq(Username.ANONYMOUS));
    AgentsUpdateCommand updateCommand = captor.getValue();
    assertThat(ReflectionUtil.getField(updateCommand, "command"), is(command));
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) GoConfigDao(com.thoughtworks.go.config.GoConfigDao) SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) AgentConfig(com.thoughtworks.go.config.AgentConfig) AgentIdentifier(com.thoughtworks.go.remote.AgentIdentifier) AgentsUpdateCommand(com.thoughtworks.go.config.update.AgentsUpdateCommand) Test(org.junit.Test)

Example 45 with AgentInstance

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

the class AgentServiceTest method shouldFailWhenDeleteIsNotSuccessful.

@Test
public void shouldFailWhenDeleteIsNotSuccessful() throws Exception {
    SecurityService securityService = mock(SecurityService.class);
    AgentConfigService agentConfigService = mock(AgentConfigService.class);
    AgentInstance agentInstance = mock(AgentInstance.class);
    String uuid = "1234";
    Username username = new Username(new CaseInsensitiveString("test"));
    HttpOperationResult operationResult = mock(HttpOperationResult.class);
    when(securityService.hasOperatePermissionForAgents(username)).thenReturn(true);
    when(agentInstance.canBeDeleted()).thenReturn(true);
    doThrow(new RuntimeException()).when(agentConfigService).deleteAgents(username, agentInstance);
    when(agentInstances.findAgentAndRefreshStatus(uuid)).thenReturn(agentInstance);
    AgentService agentService = new AgentService(agentConfigService, new SystemEnvironment(), agentInstances, mock(EnvironmentConfigService.class), mock(GoConfigService.class), securityService, agentDao, uuidGenerator, serverHealthService = mock(ServerHealthService.class));
    agentService.deleteAgents(username, operationResult, Arrays.asList(uuid));
    verify(operationResult).internalServerError(any(String.class), any(HealthStateType.class));
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) HttpOperationResult(com.thoughtworks.go.server.service.result.HttpOperationResult) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) HealthStateType(com.thoughtworks.go.serverhealth.HealthStateType) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) Username(com.thoughtworks.go.server.domain.Username) Test(org.junit.Test)

Aggregations

AgentInstance (com.thoughtworks.go.domain.AgentInstance)85 Test (org.junit.Test)58 SystemEnvironment (com.thoughtworks.go.util.SystemEnvironment)26 ArrayList (java.util.ArrayList)21 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)17 AgentConfig (com.thoughtworks.go.config.AgentConfig)15 NullAgentInstance (com.thoughtworks.go.domain.NullAgentInstance)9 AgentInstances (com.thoughtworks.go.server.domain.AgentInstances)7 Username (com.thoughtworks.go.server.domain.Username)6 AgentRuntimeInfo (com.thoughtworks.go.server.service.AgentRuntimeInfo)6 AgentIdentifier (com.thoughtworks.go.remote.AgentIdentifier)4 GoConfigDao (com.thoughtworks.go.config.GoConfigDao)3 Resource (com.thoughtworks.go.config.Resource)3 BuildWork (com.thoughtworks.go.remote.work.BuildWork)3 NoWork (com.thoughtworks.go.remote.work.NoWork)3 Work (com.thoughtworks.go.remote.work.Work)3 HttpOperationResult (com.thoughtworks.go.server.service.result.HttpOperationResult)3 AgentViewModel (com.thoughtworks.go.server.ui.AgentViewModel)3 AgentsViewModel (com.thoughtworks.go.server.ui.AgentsViewModel)3 UuidGenerator (com.thoughtworks.go.server.util.UuidGenerator)3