Search in sources :

Example 71 with AgentInstance

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

the class AgentStatusChangeNotifierTest method shouldNotifyIfAgentIsElastic.

@Test
public void shouldNotifyIfAgentIsElastic() throws Exception {
    ElasticAgentRuntimeInfo agentRuntimeInfo = new ElasticAgentRuntimeInfo(new AgentIdentifier("localhost", "127.0.0.1", "uuid"), AgentRuntimeStatus.Idle, "/foo/one", null, "42", "go.cd.elastic-agent-plugin.docker");
    AgentConfig agentConfig = new AgentConfig();
    agentConfig.setElasticAgentId("42");
    agentConfig.setElasticPluginId("go.cd.elastic-agent-plugin.docker");
    agentConfig.setIpAddress("127.0.0.1");
    AgentInstance agentInstance = AgentInstance.createFromConfig(agentConfig, new SystemEnvironment(), mock(AgentStatusChangeListener.class));
    agentInstance.update(agentRuntimeInfo);
    when(notificationPluginRegistry.isAnyPluginInterestedIn("agent-status")).thenReturn(true);
    agentStatusChangeNotifier.onAgentStatusChange(agentInstance);
    verify(pluginNotificationQueue).post(captor.capture());
    assertThat(captor.getValue().getData() instanceof AgentNotificationData, is(true));
    AgentNotificationData data = (AgentNotificationData) captor.getValue().getData();
    assertTrue(data.isElastic());
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) AgentConfig(com.thoughtworks.go.config.AgentConfig) AgentNotificationData(com.thoughtworks.go.domain.notificationdata.AgentNotificationData) ElasticAgentRuntimeInfo(com.thoughtworks.go.server.service.ElasticAgentRuntimeInfo) AgentIdentifier(com.thoughtworks.go.remote.AgentIdentifier) AgentStatusChangeListener(com.thoughtworks.go.listener.AgentStatusChangeListener) Test(org.junit.Test)

Example 72 with AgentInstance

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

the class AgentInstancesTest method shouldReturnFirstMatchedAgentsWhenHostNameHasMoreThanOneMatch.

@Test
public void shouldReturnFirstMatchedAgentsWhenHostNameHasMoreThanOneMatch() throws Exception {
    AgentInstance agent = AgentInstance.createFromConfig(new AgentConfig("uuid20", "CCeDev01", "10.18.5.20"), systemEnvironment, null);
    AgentInstance duplicatedAgent = AgentInstance.createFromConfig(new AgentConfig("uuid21", "CCeDev01", "10.18.5.20"), systemEnvironment, null);
    AgentInstances agentInstances = new AgentInstances(systemEnvironment, agentStatusChangeListener, agent, duplicatedAgent);
    AgentInstance byHostname = agentInstances.findFirstByHostname("CCeDev01");
    assertThat(byHostname, is(agent));
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) NullAgentInstance(com.thoughtworks.go.domain.NullAgentInstance) AgentConfig(com.thoughtworks.go.config.AgentConfig) Test(org.junit.Test)

Example 73 with AgentInstance

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

the class AgentConfigService method deleteAgents.

public void deleteAgents(Username currentUser, AgentInstance... agentInstances) {
    GoConfigDao.CompositeConfigCommand commandForDeletingAgents = commandForDeletingAgents(agentInstances);
    ArrayList<String> uuids = new ArrayList<>();
    for (AgentInstance agentInstance : agentInstances) {
        uuids.add(agentInstance.getUuid());
    }
    updateAgentWithoutValidations(commandForDeletingAgents, currentUser);
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) ArrayList(java.util.ArrayList)

Example 74 with AgentInstance

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

the class AgentConfigService method updateAgentAttributes.

public AgentConfig updateAgentAttributes(final String uuid, Username username, String hostname, String resources, String environments, TriState enable, AgentInstances agentInstances, HttpOperationResult result) {
    final GoConfigDao.CompositeConfigCommand command = new GoConfigDao.CompositeConfigCommand();
    if (!goConfigService.hasAgent(uuid) && enable.isTrue()) {
        AgentInstance agentInstance = agentInstances.findAgent(uuid);
        AgentConfig agentConfig = agentInstance.agentConfig();
        command.addCommand(new AddAgentCommand(agentConfig));
    }
    if (enable.isTrue()) {
        command.addCommand(new UpdateAgentApprovalStatus(uuid, false));
    }
    if (enable.isFalse()) {
        command.addCommand(new UpdateAgentApprovalStatus(uuid, true));
    }
    if (hostname != null) {
        command.addCommand(new UpdateAgentHostname(uuid, hostname, username.getUsername().toString()));
    }
    if (resources != null) {
        command.addCommand(new UpdateResourcesCommand(uuid, new ResourceConfigs(resources)));
    }
    if (environments != null) {
        Set<String> existingEnvironments = goConfigService.getCurrentConfig().getEnvironments().environmentsForAgent(uuid);
        Set<String> newEnvironments = new HashSet<>(asList(environments.split(",")));
        Set<String> environmentsToRemove = Sets.difference(existingEnvironments, newEnvironments);
        Set<String> environmentsToAdd = Sets.difference(newEnvironments, existingEnvironments);
        for (String environmentToRemove : environmentsToRemove) {
            command.addCommand(new ModifyEnvironmentCommand(uuid, environmentToRemove, TriStateSelection.Action.remove));
        }
        for (String environmentToAdd : environmentsToAdd) {
            command.addCommand(new ModifyEnvironmentCommand(uuid, environmentToAdd, TriStateSelection.Action.add));
        }
    }
    return updateAgent(command, uuid, result, username);
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) ModifyEnvironmentCommand(com.thoughtworks.go.config.update.ModifyEnvironmentCommand) HashSet(java.util.HashSet)

Example 75 with AgentInstance

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

the class AgentService method populateAgentInstancesForUUIDs.

private boolean populateAgentInstancesForUUIDs(OperationResult operationResult, List<String> uuids, List<AgentInstance> agents) {
    for (String uuid : uuids) {
        AgentInstance agentInstance = findAgentAndRefreshStatus(uuid);
        if (isUnknownAgent(agentInstance, operationResult)) {
            return false;
        }
        agents.add(agentInstance);
    }
    return true;
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance)

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