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));
}
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;
}
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;
}
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);
}
}
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);
}
}
Aggregations