Search in sources :

Example 41 with Agent

use of com.thoughtworks.go.config.Agent in project gocd by gocd.

the class AgentMutex method fetchAgentFromDBByUUID.

public Agent fetchAgentFromDBByUUID(final String uuid) {
    List<String> uuids = singletonList(uuid);
    AgentMutex mutex = agentMutexes.acquire(uuids);
    synchronized (mutex) {
        Agent agent = (Agent) transactionTemplate.execute((TransactionCallback) transactionStatus -> {
            Query query = sessionFactory.getCurrentSession().createQuery("FROM Agent where uuid = :uuid and deleted = false");
            query.setCacheable(true);
            query.setParameter("uuid", uuid);
            return query.uniqueResult();
        });
        agentMutexes.release(uuids, mutex);
        return agent;
    }
}
Also used : Agent(com.thoughtworks.go.config.Agent) TransactionCallback(org.springframework.transaction.support.TransactionCallback) Query(org.hibernate.Query)

Example 42 with Agent

use of com.thoughtworks.go.config.Agent in project gocd by gocd.

the class AgentRegistrationControllerTest method shouldNotRelyOnAutoRegisterKeyForRegisteringElasticAgents.

@Test
public void shouldNotRelyOnAutoRegisterKeyForRegisteringElasticAgents() {
    String uuid = "elastic-uuid";
    String autoRegisterKey = "auto_register_key";
    final ServerConfig serverConfig = mockedServerConfig("token-generation-key", autoRegisterKey);
    final String token = token(uuid, serverConfig.getTokenGenerationKey());
    when(agentService.isRegistered(uuid)).thenReturn(false);
    when(goConfigService.serverConfig()).thenReturn(serverConfig);
    when(agentService.createAgentUsername(uuid, request.getRemoteAddr(), "host")).thenReturn(new Username("some-agent-login-name"));
    when(ephemeralAutoRegisterKeyService.validateAndRevoke(any())).thenReturn(false);
    controller.agentRequest("host", uuid, "location", "233232", "osx", autoRegisterKey, "", "e1", "", "elastic-agent-id", "elastic-plugin-id", token, request);
    verify(agentService, never()).register(any(Agent.class));
}
Also used : ServerConfig(com.thoughtworks.go.config.ServerConfig) Agent(com.thoughtworks.go.config.Agent) Username(com.thoughtworks.go.server.domain.Username) Test(org.junit.jupiter.api.Test)

Example 43 with Agent

use of com.thoughtworks.go.config.Agent in project gocd by gocd.

the class AgentInstance method createFromLiveAgent.

public static AgentInstance createFromLiveAgent(AgentRuntimeInfo agentRuntimeInfo, SystemEnvironment sysEnv, AgentStatusChangeListener agentStatusChangeListener) {
    Agent agent = agentRuntimeInfo.agent();
    AgentType type = agent.isFromLocalHost() ? AgentType.LOCAL : AgentType.REMOTE;
    AgentInstance instance;
    if (sysEnv.isAutoRegisterLocalAgentEnabled() && agent.isFromLocalHost()) {
        instance = new AgentInstance(agent, type, sysEnv, agentStatusChangeListener, agentRuntimeInfo);
        instance.agentConfigStatus = Enabled;
        instance.agentRuntimeInfo.idle();
        instance.update(agentRuntimeInfo);
        return instance;
    } else {
        instance = new AgentInstance(agent, type, sysEnv, agentStatusChangeListener);
        instance.update(agentRuntimeInfo);
    }
    return instance;
}
Also used : Agent(com.thoughtworks.go.config.Agent)

Example 44 with Agent

use of com.thoughtworks.go.config.Agent in project gocd by gocd.

the class AgentMother method localAgentWithResources.

public static Agent localAgentWithResources(String... resources) {
    Agent agent = localAgent();
    agent.setResourcesFromList(asList(resources));
    return agent;
}
Also used : Agent(com.thoughtworks.go.config.Agent)

Example 45 with Agent

use of com.thoughtworks.go.config.Agent in project gocd by gocd.

the class ScheduleServiceRescheduleHungJobsTest method activities.

private AgentInstances activities() {
    AgentStatusChangeListener agentStatusChangeListener = mock(AgentStatusChangeListener.class);
    final AgentInstances activities = new AgentInstances(agentStatusChangeListener);
    SystemEnvironment systemEnvironment = new SystemEnvironment();
    activities.add(AgentInstance.createFromAgent(new Agent("uuid1"), systemEnvironment, agentStatusChangeListener));
    activities.add(AgentInstance.createFromAgent(new Agent("uuid2"), systemEnvironment, agentStatusChangeListener));
    return activities;
}
Also used : SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) AgentInstances(com.thoughtworks.go.server.domain.AgentInstances) Agent(com.thoughtworks.go.config.Agent) AgentStatusChangeListener(com.thoughtworks.go.listener.AgentStatusChangeListener)

Aggregations

Agent (com.thoughtworks.go.config.Agent)100 Test (org.junit.jupiter.api.Test)52 AgentInstance.createFromLiveAgent (com.thoughtworks.go.domain.AgentInstance.createFromLiveAgent)36 AgentInstance (com.thoughtworks.go.domain.AgentInstance)20 AgentStatusChangeListener (com.thoughtworks.go.listener.AgentStatusChangeListener)19 SystemEnvironment (com.thoughtworks.go.util.SystemEnvironment)16 AgentRuntimeInfo (com.thoughtworks.go.server.service.AgentRuntimeInfo)13 NullAgentInstance (com.thoughtworks.go.domain.NullAgentInstance)11 JobInstance (com.thoughtworks.go.domain.JobInstance)8 ResponseEntity (org.springframework.http.ResponseEntity)8 ServerConfig (com.thoughtworks.go.config.ServerConfig)6 AgentIdentifier (com.thoughtworks.go.remote.AgentIdentifier)6 Username (com.thoughtworks.go.server.domain.Username)5 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)5 AgentInstance.createFromAgent (com.thoughtworks.go.domain.AgentInstance.createFromAgent)4 AgentBuildingInfo (com.thoughtworks.go.server.service.AgentBuildingInfo)4 Query (org.hibernate.Query)4 TransactionCallback (org.springframework.transaction.support.TransactionCallback)4 Gson (com.google.gson.Gson)3 ResourceConfig (com.thoughtworks.go.config.ResourceConfig)3