Search in sources :

Example 76 with AgentInstance

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

the class AgentsEntityConfigUpdateCommandTest method shouldThrowExceptionIfElasticAgentResourceIsUpdated.

@Test
public void shouldThrowExceptionIfElasticAgentResourceIsUpdated() throws Exception {
    resourcesToAdd.add("firefox");
    uuids.add("uuid-1");
    AgentInstance agentInstance = mock(AgentInstance.class);
    when(agentInstance.isNullAgent()).thenReturn(false);
    when(agentInstance.isElastic()).thenReturn(true);
    when(agentInstances.findAgent("uuid-1")).thenReturn(agentInstance);
    AgentsEntityConfigUpdateCommand command = new AgentsEntityConfigUpdateCommand(agentInstances, currentUser, result, uuids, environmentsToAdd, environmentsToRemove, triState, resourcesToAdd, resourcesToRemove, goConfigService);
    exception.expect(ElasticAgentsResourceUpdateException.class);
    exception.expectMessage("Can not update resources on Elastic Agents [uuid-1]");
    command.update(cruiseConfig);
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) Test(org.junit.Test)

Example 77 with AgentInstance

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

the class AgentsEntityConfigUpdateCommandTest method shouldThrowExceptionIfPendingAgentIsUpdatedWithoutChangingItsState.

@Test
public void shouldThrowExceptionIfPendingAgentIsUpdatedWithoutChangingItsState() throws Exception {
    resourcesToAdd.add("firefox");
    triState = TriState.UNSET;
    AgentInstance agentInstance = AgentInstanceMother.pendingInstance();
    AgentConfig agentConfig = agentInstance.agentConfig();
    uuids.add(agentConfig.getUuid());
    when(agentInstances.findAgent(agentConfig.getUuid())).thenReturn(agentInstance);
    AgentsEntityConfigUpdateCommand command = new AgentsEntityConfigUpdateCommand(agentInstances, currentUser, result, uuids, environmentsToAdd, environmentsToRemove, triState, resourcesToAdd, resourcesToRemove, goConfigService);
    exception.expect(InvalidPendingAgentOperationException.class);
    exception.expectMessage(String.format("Invalid operation performed on pending agents: [%s]", agentConfig.getUuid()));
    command.update(cruiseConfig);
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) AgentConfig(com.thoughtworks.go.config.AgentConfig) Test(org.junit.Test)

Example 78 with AgentInstance

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

the class AgentsEntityConfigUpdateCommandTest method shouldUpdateEnvironmentOfAgents.

@Test
public void shouldUpdateEnvironmentOfAgents() throws Exception {
    environmentsToAdd.add("prod");
    environmentsToRemove.add("dev");
    AgentInstance agentInstance = AgentInstanceMother.disabled();
    AgentConfig agentConfig = agentInstance.agentConfig();
    cruiseConfig.addEnvironment("dev");
    cruiseConfig.addEnvironment("prod");
    cruiseConfig.agents().add(agentConfig);
    cruiseConfig.getEnvironments().addAgentsToEnvironment("dev", agentConfig.getUuid());
    uuids.add(agentConfig.getUuid());
    List<String> emptyList = new ArrayList<>();
    assertThat(cruiseConfig.getEnvironments().find(new CaseInsensitiveString("dev")).getAgents().getUuids(), is(uuids));
    assertThat(cruiseConfig.getEnvironments().find(new CaseInsensitiveString("prod")).getAgents().getUuids(), is(emptyList));
    when(agentInstances.findAgent(agentConfig.getUuid())).thenReturn(agentInstance);
    AgentsEntityConfigUpdateCommand command = new AgentsEntityConfigUpdateCommand(agentInstances, currentUser, result, uuids, environmentsToAdd, environmentsToRemove, triState, resourcesToAdd, resourcesToRemove, goConfigService);
    command.update(cruiseConfig);
    assertThat(cruiseConfig.getEnvironments().find(new CaseInsensitiveString("dev")).getAgents().getUuids(), is(emptyList));
    assertThat(cruiseConfig.getEnvironments().find(new CaseInsensitiveString("prod")).getAgents().getUuids(), is(uuids));
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) AgentConfig(com.thoughtworks.go.config.AgentConfig) ArrayList(java.util.ArrayList) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.Test)

Example 79 with AgentInstance

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

the class AgentsEntityConfigUpdateCommandTest method shouldUpdateResourcesOfAgents.

@Test
public void shouldUpdateResourcesOfAgents() throws Exception {
    resourcesToAdd.add("firefox");
    resourcesToRemove.add("linux");
    AgentInstance agentInstance = AgentInstanceMother.disabled();
    AgentConfig agentConfig = agentInstance.agentConfig();
    agentConfig.addResourceConfig(new ResourceConfig("linux"));
    cruiseConfig.agents().add(agentConfig);
    assertThat(agentConfig.getResourceConfigs().resourceNames(), is(Arrays.asList("linux")));
    when(agentInstances.findAgent(agentConfig.getUuid())).thenReturn(agentInstance);
    uuids.add(agentConfig.getUuid());
    AgentsEntityConfigUpdateCommand command = new AgentsEntityConfigUpdateCommand(agentInstances, currentUser, result, uuids, environmentsToAdd, environmentsToRemove, triState, resourcesToAdd, resourcesToRemove, goConfigService);
    command.update(cruiseConfig);
    assertThat(agentConfig.getResourceConfigs().resourceNames(), is(Arrays.asList("firefox")));
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) AgentConfig(com.thoughtworks.go.config.AgentConfig) ResourceConfig(com.thoughtworks.go.config.ResourceConfig) Test(org.junit.Test)

Example 80 with AgentInstance

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

the class AgentInstances method allElasticAgentsGroupedByPluginId.

public LinkedMultiValueMap<String, ElasticAgentMetadata> allElasticAgentsGroupedByPluginId() {
    LinkedMultiValueMap<String, ElasticAgentMetadata> map = new LinkedMultiValueMap<>();
    for (Map.Entry<String, AgentInstance> entry : agentInstances.entrySet()) {
        AgentInstance agentInstance = entry.getValue();
        if (agentInstance.isElastic()) {
            ElasticAgentMetadata metadata = agentInstance.elasticAgentMetadata();
            map.add(metadata.elasticPluginId(), metadata);
        }
    }
    return map;
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) NullAgentInstance(com.thoughtworks.go.domain.NullAgentInstance) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap)

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