Search in sources :

Example 6 with AgentInstances

use of com.thoughtworks.go.server.domain.AgentInstances in project gocd by gocd.

the class ScheduleServiceRescheduleHungJobsTest method activities.

private AgentInstances activities() {
    final AgentInstances activities = new AgentInstances(null);
    SystemEnvironment systemEnvironment = new SystemEnvironment();
    activities.add(AgentInstance.createFromConfig(new AgentConfig("uuid1"), systemEnvironment));
    activities.add(AgentInstance.createFromConfig(new AgentConfig("uuid2"), systemEnvironment));
    return activities;
}
Also used : SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) AgentInstances(com.thoughtworks.go.server.domain.AgentInstances) AgentConfig(com.thoughtworks.go.config.AgentConfig)

Example 7 with AgentInstances

use of com.thoughtworks.go.server.domain.AgentInstances in project gocd by gocd.

the class AgentConfigServiceIntegrationTest method setup.

@Before
public void setup() throws Exception {
    agentInstances = new AgentInstances(new AgentRuntimeStatus.ChangeListener() {

        @Override
        public void statusUpdateRequested(AgentRuntimeInfo runtimeInfo, AgentRuntimeStatus newStatus) {
        }
    });
    configHelper = new GoConfigFileHelper();
    configHelper.usingCruiseConfigDao(goConfigDao).initializeConfigFile();
    configHelper.onSetUp();
    goConfigService.forceNotifyListeners();
}
Also used : AgentInstances(com.thoughtworks.go.server.domain.AgentInstances) AgentRuntimeStatus(com.thoughtworks.go.domain.AgentRuntimeStatus) GoConfigFileHelper(com.thoughtworks.go.util.GoConfigFileHelper) Before(org.junit.Before)

Example 8 with AgentInstances

use of com.thoughtworks.go.server.domain.AgentInstances in project gocd by gocd.

the class AgentServiceTest method setUp.

@Before
public void setUp() {
    agentInstances = mock(AgentInstances.class);
    AgentConfig config = new AgentConfig("uuid", "host", "192.168.1.1");
    when(agentInstances.findAgentAndRefreshStatus("uuid")).thenReturn(AgentInstance.createFromConfig(config, new SystemEnvironment()));
    agentDao = mock(AgentDao.class);
    uuidGenerator = mock(UuidGenerator.class);
    agentService = new AgentService(mock(AgentConfigService.class), new SystemEnvironment(), agentInstances, mock(EnvironmentConfigService.class), mock(GoConfigService.class), mock(SecurityService.class), agentDao, uuidGenerator, serverHealthService = mock(ServerHealthService.class));
    agentIdentifier = config.getAgentIdentifier();
    when(agentDao.cookieFor(agentIdentifier)).thenReturn("cookie");
}
Also used : SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) AgentInstances(com.thoughtworks.go.server.domain.AgentInstances) AgentConfig(com.thoughtworks.go.config.AgentConfig) UuidGenerator(com.thoughtworks.go.server.util.UuidGenerator) AgentDao(com.thoughtworks.go.server.persistence.AgentDao) ServerHealthService(com.thoughtworks.go.serverhealth.ServerHealthService) Before(org.junit.Before)

Example 9 with AgentInstances

use of com.thoughtworks.go.server.domain.AgentInstances in project gocd by gocd.

the class AgentsEntityConfigUpdateCommandTest method setUp.

@Before
public void setUp() throws Exception {
    result = new HttpLocalizedOperationResult();
    currentUser = new Username(new CaseInsensitiveString("user"));
    cruiseConfig = new GoConfigMother().defaultCruiseConfig();
    goConfigService = mock(GoConfigService.class);
    agentInstances = mock(AgentInstances.class);
    uuids = new ArrayList<>();
    environmentsToAdd = new ArrayList<>();
    environmentsToRemove = new ArrayList<>();
    resourcesToAdd = new ArrayList<>();
    resourcesToRemove = new ArrayList<>();
    triState = TriState.TRUE;
    when(goConfigService.getEnvironments()).thenReturn(cruiseConfig.getEnvironments());
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) AgentInstances(com.thoughtworks.go.server.domain.AgentInstances) Username(com.thoughtworks.go.server.domain.Username) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) GoConfigService(com.thoughtworks.go.server.service.GoConfigService) GoConfigMother(com.thoughtworks.go.helper.GoConfigMother) Before(org.junit.Before)

Example 10 with AgentInstances

use of com.thoughtworks.go.server.domain.AgentInstances in project gocd by gocd.

the class AgentServiceIntegrationTest method shouldThrowExceptionWhenADuplicateAgentTriesToUpdateStatus.

@Test
public void shouldThrowExceptionWhenADuplicateAgentTriesToUpdateStatus() throws Exception {
    AgentInstance instance = AgentInstanceMother.building();
    AgentService agentService = getAgentService(new AgentInstances(null, new SystemEnvironment(), instance));
    AgentInstances agents = agentService.findRegisteredAgents();
    String uuid = instance.agentConfig().getUuid();
    assertThat(agents.findAgentAndRefreshStatus(uuid).getStatus(), is(AgentStatus.Building));
    AgentIdentifier identifier = instance.agentConfig().getAgentIdentifier();
    agentDao.associateCookie(identifier, "new_cookie");
    AgentRuntimeInfo runtimeInfo = new AgentRuntimeInfo(identifier, AgentRuntimeStatus.Idle, currentWorkingDirectory(), "old_cookie", false);
    try {
        agentService.updateRuntimeInfo(runtimeInfo);
        fail("agent with bad cookie should not be able to update runtime info");
    } catch (AgentWithDuplicateUUIDException e) {
        assertThat(e.getMessage(), is(format("Agent [%s] has invalid cookie", runtimeInfo.agentInfoDebugString())));
    }
    agents = agentService.findRegisteredAgents();
    assertThat(agents.findAgentAndRefreshStatus(uuid).getStatus(), is(AgentStatus.Building));
    AgentIdentifier agentIdentifier = instance.agentConfig().getAgentIdentifier();
    String cookie = agentService.assignCookie(agentIdentifier);
    agentService.updateRuntimeInfo(new AgentRuntimeInfo(agentIdentifier, AgentRuntimeStatus.Idle, currentWorkingDirectory(), cookie, false));
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) AgentInstances(com.thoughtworks.go.server.domain.AgentInstances) AgentIdentifier(com.thoughtworks.go.remote.AgentIdentifier) Test(org.junit.Test)

Aggregations

AgentInstances (com.thoughtworks.go.server.domain.AgentInstances)14 Test (org.junit.Test)9 AgentInstance (com.thoughtworks.go.domain.AgentInstance)7 UuidGenerator (com.thoughtworks.go.server.util.UuidGenerator)4 Before (org.junit.Before)3 AgentConfig (com.thoughtworks.go.config.AgentConfig)2 AgentIdentifier (com.thoughtworks.go.remote.AgentIdentifier)2 SendEmailMessage (com.thoughtworks.go.server.messaging.SendEmailMessage)2 SystemEnvironment (com.thoughtworks.go.util.SystemEnvironment)2 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)1 AgentRuntimeStatus (com.thoughtworks.go.domain.AgentRuntimeStatus)1 GoConfigMother (com.thoughtworks.go.helper.GoConfigMother)1 InvalidAgentException (com.thoughtworks.go.remote.work.InvalidAgentException)1 GoUnauthorizedException (com.thoughtworks.go.server.GoUnauthorizedException)1 Username (com.thoughtworks.go.server.domain.Username)1 AgentDao (com.thoughtworks.go.server.persistence.AgentDao)1 GoConfigService (com.thoughtworks.go.server.service.GoConfigService)1 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)1 AgentViewModel (com.thoughtworks.go.server.ui.AgentViewModel)1 AgentsViewModel (com.thoughtworks.go.server.ui.AgentsViewModel)1