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