Search in sources :

Example 11 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.getResourceConfigs().add(new ResourceConfig("foo"));
    idle.getResourceConfigs().add(new ResourceConfig("bar"));
    agents.add(new AgentViewModel(idle, "uat"));
    AgentInstance building = AgentInstanceMother.building();
    building.getResourceConfigs().add(new ResourceConfig("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) ResourceConfig(com.thoughtworks.go.config.ResourceConfig) Date(java.util.Date)

Example 12 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(), null);
    AgentConfig agentConfig = new AgentConfig("UUID2", "remote-host", "50.40.30.20");
    agentConfig.disable();
    AgentInstance fromConfigFile = AgentInstance.createFromConfig(agentConfig, new SystemEnvironment(), null);
    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 13 with AgentInstance

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

the class AgentServiceTest method shouldThrowExceptionWhenADuplicateAgentTriesToUpdateStatus.

@Test
public void shouldThrowExceptionWhenADuplicateAgentTriesToUpdateStatus() throws Exception {
    AgentRuntimeInfo runtimeInfo = new AgentRuntimeInfo(agentIdentifier, AgentRuntimeStatus.Idle, currentWorkingDirectory(), null, false);
    runtimeInfo.setCookie("invalid_cookie");
    AgentInstance original = AgentInstance.createFromLiveAgent(new AgentRuntimeInfo(agentIdentifier, AgentRuntimeStatus.Idle, currentWorkingDirectory(), null, false), new SystemEnvironment(), null);
    try (LogFixture logFixture = logFixtureFor(AgentService.class, Level.DEBUG)) {
        try {
            when(agentService.findAgentAndRefreshStatus(runtimeInfo.getUUId())).thenReturn(original);
            agentService.updateRuntimeInfo(runtimeInfo);
            fail("should throw exception when cookie mismatched");
        } catch (Exception e) {
            assertThat(e.getMessage(), is(format("Agent [%s] has invalid cookie", runtimeInfo.agentInfoDebugString())));
            assertThat(logFixture.getRawMessages(), hasItem(format("Found agent [%s] with duplicate uuid. Please check the agent installation.", runtimeInfo.agentInfoDebugString())));
            verify(serverHealthService).update(ServerHealthState.warning(format("[%s] has duplicate unique identifier which conflicts with [%s]", runtimeInfo.agentInfoForDisplay(), original.agentInfoForDisplay()), "Please check the agent installation. Click <a href='https://docs.gocd.org/current/faq/agent_guid_issue.html' target='_blank'>here</a> for more info.", HealthStateType.duplicateAgent(HealthStateScope.forAgent(runtimeInfo.getCookie())), Timeout.THIRTY_SECONDS));
        }
    }
    verify(agentInstances).findAgentAndRefreshStatus(runtimeInfo.getUUId());
    verifyNoMoreInteractions(agentInstances);
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) LogFixture(com.thoughtworks.go.util.LogFixture) IOException(java.io.IOException) Test(org.junit.Test)

Example 14 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), securityService, agentDao, uuidGenerator, serverHealthService = mock(ServerHealthService.class), null);
    agentService.deleteAgents(username, operationResult, Arrays.asList(uuid));
    verify(operationResult).internalServerError(any(String.class), any(HealthStateType.class));
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) HttpOperationResult(com.thoughtworks.go.server.service.result.HttpOperationResult) Username(com.thoughtworks.go.server.domain.Username) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) HealthStateType(com.thoughtworks.go.serverhealth.HealthStateType) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.Test)

Example 15 with AgentInstance

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

the class AgentServiceTest method shouldUnderstandFilteringAgentListBasedOnUuid.

@Test
public void shouldUnderstandFilteringAgentListBasedOnUuid() {
    AgentInstance instance1 = AgentInstance.createFromLiveAgent(AgentRuntimeInfo.fromServer(new AgentConfig("uuid-1", "host-1", "192.168.1.2"), true, "/foo/bar", 100l, "linux", false), new SystemEnvironment(), null);
    AgentInstance instance3 = AgentInstance.createFromLiveAgent(AgentRuntimeInfo.fromServer(new AgentConfig("uuid-3", "host-3", "192.168.1.4"), true, "/baz/quux", 300l, "linux", false), new SystemEnvironment(), null);
    when(agentInstances.filter(Arrays.asList("uuid-1", "uuid-3"))).thenReturn(Arrays.asList(instance1, instance3));
    AgentsViewModel agents = agentService.filter(Arrays.asList("uuid-1", "uuid-3"));
    AgentViewModel view1 = new AgentViewModel(instance1);
    AgentViewModel view2 = new AgentViewModel(instance3);
    assertThat(agents, is(new AgentsViewModel(view1, view2)));
    verify(agentInstances).filter(Arrays.asList("uuid-1", "uuid-3"));
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) AgentConfig(com.thoughtworks.go.config.AgentConfig) AgentsViewModel(com.thoughtworks.go.server.ui.AgentsViewModel) AgentViewModel(com.thoughtworks.go.server.ui.AgentViewModel) Test(org.junit.Test)

Aggregations

AgentInstance (com.thoughtworks.go.domain.AgentInstance)95 Test (org.junit.Test)68 SystemEnvironment (com.thoughtworks.go.util.SystemEnvironment)27 ArrayList (java.util.ArrayList)21 AgentConfig (com.thoughtworks.go.config.AgentConfig)20 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)17 NullAgentInstance (com.thoughtworks.go.domain.NullAgentInstance)9 AgentStatusChangeListener (com.thoughtworks.go.listener.AgentStatusChangeListener)9 AgentInstances (com.thoughtworks.go.server.domain.AgentInstances)7 AgentRuntimeInfo (com.thoughtworks.go.server.service.AgentRuntimeInfo)7 Username (com.thoughtworks.go.server.domain.Username)6 AgentIdentifier (com.thoughtworks.go.remote.AgentIdentifier)5 ResponseEntity (org.springframework.http.ResponseEntity)4 GoConfigDao (com.thoughtworks.go.config.GoConfigDao)3 ResourceConfig (com.thoughtworks.go.config.ResourceConfig)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