Search in sources :

Example 36 with Agent

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

the class AgentInstanceMother method agentWithConfigErrors.

public static AgentInstance agentWithConfigErrors() {
    Agent agent = new Agent("uuid", "host", "IP", asList("foo%", "bar$"));
    agent.validate();
    return AgentInstance.createFromAgent(agent, new SystemEnvironment(), mock(AgentStatusChangeListener.class));
}
Also used : SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) AgentInstance.createFromLiveAgent(com.thoughtworks.go.domain.AgentInstance.createFromLiveAgent) Agent(com.thoughtworks.go.config.Agent) AgentStatusChangeListener(com.thoughtworks.go.listener.AgentStatusChangeListener)

Example 37 with Agent

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

the class AgentInstanceMother method idleWith.

public static AgentInstance idleWith(String uuid) {
    final AgentInstance agentInstance = idle();
    agentInstance.syncAgentFrom(new Agent(uuid, agentInstance.getHostname(), agentInstance.getIpAddress()));
    return agentInstance;
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) NullAgentInstance(com.thoughtworks.go.domain.NullAgentInstance) AgentInstance.createFromLiveAgent(com.thoughtworks.go.domain.AgentInstance.createFromLiveAgent) Agent(com.thoughtworks.go.config.Agent)

Example 38 with Agent

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

the class AgentInstanceMother method updateRuntimeStatus.

public static AgentInstance updateRuntimeStatus(AgentInstance agentInstance, AgentRuntimeStatus status) {
    Agent agent = agentInstance.getAgent();
    AgentRuntimeInfo newRuntimeInfo = fromServer(agent, true, agentInstance.getLocation(), agentInstance.getUsableSpace(), "linux");
    newRuntimeInfo.setRuntimeStatus(status);
    agentInstance.update(newRuntimeInfo);
    return agentInstance;
}
Also used : AgentInstance.createFromLiveAgent(com.thoughtworks.go.domain.AgentInstance.createFromLiveAgent) Agent(com.thoughtworks.go.config.Agent) AgentRuntimeInfo(com.thoughtworks.go.server.service.AgentRuntimeInfo)

Example 39 with Agent

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

the class AgentMutex method bulkUpdateAgents.

public void bulkUpdateAgents(List<Agent> agents) {
    List<String> uuids = agents.stream().map(agent -> agent.getUuid()).collect(toList());
    AgentMutex mutex = agentMutexes.acquire(uuids);
    synchronized (mutex) {
        transactionTemplate.execute(new TransactionCallbackWithoutResult() {

            @Override
            protected void doInTransactionWithoutResult(TransactionStatus status) {
                agents.forEach(agent -> sessionFactory.getCurrentSession().saveOrUpdate(Agent.class.getName(), agent));
                List<String> uuids = agents.stream().map(Agent::getUuid).collect(toList());
                registerAfterCommitCallback(() -> clearCacheAndNotifyBulkAgentEntityChangeListeners(uuids));
            }
        });
        agentMutexes.release(uuids, mutex);
    }
}
Also used : ExceptionUtils.bomb(com.thoughtworks.go.util.ExceptionUtils.bomb) Autowired(org.springframework.beans.factory.annotation.Autowired) TransactionSynchronizationAdapter(org.springframework.transaction.support.TransactionSynchronizationAdapter) Collections.singletonList(java.util.Collections.singletonList) HibernateDaoSupport(org.springframework.orm.hibernate3.support.HibernateDaoSupport) HashSet(java.util.HashSet) GoCache(com.thoughtworks.go.server.cache.GoCache) Map(java.util.Map) Query(org.hibernate.Query) UnregisteredAgentException(com.thoughtworks.go.domain.exception.UnregisteredAgentException) TransactionSynchronizationManager(com.thoughtworks.go.server.transaction.TransactionSynchronizationManager) TransactionTemplate(com.thoughtworks.go.server.transaction.TransactionTemplate) TransactionCallbackWithoutResult(org.springframework.transaction.support.TransactionCallbackWithoutResult) Collections.emptyList(java.util.Collections.emptyList) SessionFactory(org.hibernate.SessionFactory) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) lombok(lombok) String.format(java.lang.String.format) AgentIdentifier(com.thoughtworks.go.remote.AgentIdentifier) DatabaseEntityChangeListener(com.thoughtworks.go.listener.DatabaseEntityChangeListener) TestOnly(org.jetbrains.annotations.TestOnly) Component(org.springframework.stereotype.Component) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) TransactionStatus(org.springframework.transaction.TransactionStatus) UuidGenerator(com.thoughtworks.go.server.util.UuidGenerator) Agent(com.thoughtworks.go.config.Agent) TransactionCallback(org.springframework.transaction.support.TransactionCallback) Agent(com.thoughtworks.go.config.Agent) TransactionStatus(org.springframework.transaction.TransactionStatus) Collections.singletonList(java.util.Collections.singletonList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) TransactionCallbackWithoutResult(org.springframework.transaction.support.TransactionCallbackWithoutResult)

Example 40 with Agent

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

the class AgentMutex method associateCookie.

public void associateCookie(final AgentIdentifier agentIdentifier, final String cookie) {
    final String uuid = agentIdentifier.getUuid();
    final String key = agentCacheKey(uuid);
    List<String> uuids = singletonList(agentIdentifier.getUuid());
    AgentMutex mutex = agentMutexes.acquire(uuids);
    synchronized (mutex) {
        transactionTemplate.execute(new TransactionCallbackWithoutResult() {

            @Override
            protected void doInTransactionWithoutResult(TransactionStatus status) {
                Agent agent = fetchAgentFromDBByUUID(uuid);
                if (agent == null) {
                    throw new UnregisteredAgentException(format("Agent [%s] is not registered.", uuid), uuid);
                }
                agent.setCookie(cookie);
                getHibernateTemplate().saveOrUpdate(agent);
                final Agent updatedAgent = agent;
                registerAfterCommitCallback(() -> clearCacheAndNotifyAgentEntityChangeListeners(key, updatedAgent));
            }
        });
        agentMutexes.release(uuids, mutex);
    }
}
Also used : Agent(com.thoughtworks.go.config.Agent) UnregisteredAgentException(com.thoughtworks.go.domain.exception.UnregisteredAgentException) TransactionStatus(org.springframework.transaction.TransactionStatus) TransactionCallbackWithoutResult(org.springframework.transaction.support.TransactionCallbackWithoutResult)

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