Search in sources :

Example 81 with Agent

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

the class AgentMother method deniedAgent.

public static Agent deniedAgent() {
    Agent agent = new Agent("uuid", "deniedAgent", "192.168.0.1", UUID.randomUUID().toString());
    agent.disable();
    return agent;
}
Also used : Agent(com.thoughtworks.go.config.Agent)

Example 82 with Agent

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

the class JobController method addElasticAgentInfo.

private void addElasticAgentInfo(JobInstance jobInstance, Map data) {
    if (!jobInstance.currentStatus().isActive()) {
        return;
    }
    final JobAgentMetadata jobAgentMetadata = jobAgentMetadataDao.load(jobInstance.getId());
    if (jobAgentMetadata == null) {
        return;
    }
    ClusterProfile clusterProfile = jobAgentMetadata.clusterProfile();
    if (clusterProfile == null) {
        return;
    }
    final String pluginId = clusterProfile.getPluginId();
    final ElasticAgentPluginInfo pluginInfo = elasticAgentMetadataStore.getPluginInfo(pluginId);
    if (pluginInfo != null && pluginInfo.getCapabilities().supportsAgentStatusReport()) {
        String clusterProfileId = jobAgentMetadata.clusterProfile().getId();
        String elasticProfileId = jobAgentMetadata.elasticProfile().getId();
        data.put("clusterProfileId", clusterProfileId);
        data.put("elasticAgentProfileId", elasticProfileId);
        data.put("elasticAgentPluginId", pluginId);
        data.put("doesUserHaveViewAccessToStatusReportPage", securityService.doesUserHasPermissions(SessionUtils.currentUsername(), SupportedAction.VIEW, SupportedEntity.ELASTIC_AGENT_PROFILE, elasticProfileId, clusterProfileId));
        final Agent agent = agentService.getAgentByUUID(jobInstance.getAgentUuid());
        if (agent != null && agent.isElastic()) {
            data.put("elasticAgentPluginId", agent.getElasticPluginId());
            data.put("elasticAgentId", agent.getElasticAgentId());
            return;
        }
    }
}
Also used : Agent(com.thoughtworks.go.config.Agent) ElasticAgentPluginInfo(com.thoughtworks.go.plugin.domain.elastic.ElasticAgentPluginInfo) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) ClusterProfile(com.thoughtworks.go.config.elastic.ClusterProfile)

Example 83 with Agent

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

the class AgentMutex method getAgentsByUUIDs.

public List<Agent> getAgentsByUUIDs(List<String> uuids) {
    AgentMutex mutex = agentMutexes.acquire(uuids);
    synchronized (mutex) {
        List<Agent> agents = (List<Agent>) transactionTemplate.execute((TransactionCallback) transactionStatus -> {
            Query query = sessionFactory.getCurrentSession().createQuery("FROM Agent where uuid in :uuids and deleted = false");
            query.setCacheable(true);
            query.setParameterList("uuids", uuids);
            return query.list();
        });
        agentMutexes.release(uuids, mutex);
        return agents;
    }
}
Also used : Agent(com.thoughtworks.go.config.Agent) TransactionCallback(org.springframework.transaction.support.TransactionCallback) Query(org.hibernate.Query) Collections.singletonList(java.util.Collections.singletonList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList)

Example 84 with Agent

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

the class AgentMutex method fetchAgentFromDBByUUIDIncludingDeleted.

public Agent fetchAgentFromDBByUUIDIncludingDeleted(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");
            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 85 with Agent

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

the class AgentMutex method getAgentByUUIDFromCacheOrDB.

public Agent getAgentByUUIDFromCacheOrDB(String uuid) {
    String key = agentCacheKey(uuid);
    Agent agent = (Agent) cache.get(key);
    if (agent == null) {
        List<String> uuids = singletonList(uuid);
        AgentMutex mutex = agentMutexes.acquire(uuids);
        synchronized (mutex) {
            agent = (Agent) cache.get(key);
            if (agent != null) {
                return agent;
            }
            agent = fetchAgentFromDBByUUID(uuid);
            cache.put(key, agent);
            agentMutexes.release(uuids, mutex);
        }
    }
    return agent;
}
Also used : Agent(com.thoughtworks.go.config.Agent)

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