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; }
@Deprecated public void approve(String uuid) { AgentInstance agentInstance = findAgentAndRefreshStatus(uuid); agentConfigService.approvePendingAgent(agentInstance); }
public AgentViewModel findAgentViewModel(String uuid) { return toAgentViewModel(findAgentAndRefreshStatus(uuid)); }
public Work assignWorkToAgent(AgentIdentifier agent) { return assignWorkToAgent(agentService.findAgentAndRefreshStatus(agent.getUuid())); }
public AgentInstruction ping(AgentRuntimeInfo info) { LOGGER.trace("{} ping received.", info); try { agentService.updateRuntimeInfo(info); return new AgentInstruction(agentService.findAgentAndRefreshStatus(info.getUUId()).isCancelled()); } catch (AgentWithDuplicateUUIDException agentException) { throw wrappedException(agentException); } catch (Exception e) { LOGGER.error("Error occurred in {} ping.", info, e); throw wrappedException(e); } }
public List<JobInstanceModel> jobInstanceModelFor(JobInstances jobInstances) { ArrayList<JobInstanceModel> models = new ArrayList<>(); for (JobInstance jobInstance : jobInstances) { AgentInstance agentInstance = jobInstance.isAssignedToAgent() ? agentService.findAgentAndRefreshStatus(jobInstance.getAgentUuid()) : null; JobInstanceModel model; if (null != agentInstance && !agentInstance.isNullAgent()) { model = new JobInstanceModel(jobInstance, jobDurationStrategy, agentInstance); } else if (jobInstance.getAgentUuid() != null) { Agent agent = agentService.findAgentObjectByUuid(jobInstance.getAgentUuid()); model = new JobInstanceModel(jobInstance, jobDurationStrategy, agent); } else { model = new JobInstanceModel(jobInstance, jobDurationStrategy); } models.add(model); } models.sort(JobInstanceModel.JOB_MODEL_COMPARATOR); return models; } }
private void matchingJobForRegisteredAgents() { Map<String, Agent> agents = agentRemoteHandler.connectedAgents(); if (agents.isEmpty()) { return; } Long start = System.currentTimeMillis(); for (Map.Entry<String, Agent> entry : agents.entrySet()) { String agentUUId = entry.getKey(); Agent agent = entry.getValue(); AgentInstance agentInstance = agentService.findAgentAndRefreshStatus(agentUUId); if (!agentInstance.isRegistered()) { agent.send(new Message(Action.reregister)); continue; } if (agentInstance.isDisabled() || !agentInstance.isIdle()) { LOGGER.debug("Ignore agent [{}] that is {} and {}", agentInstance.getAgentIdentifier(), agentInstance.getRuntimeStatus(), agentInstance.getAgentConfigStatus()); continue; } Work work = assignWorkToAgent(agentInstance); if (work != NO_WORK) { if (agentInstance.getSupportsBuildCommandProtocol()) { BuildSettings buildSettings = createBuildSettings(((BuildWork) work).getAssignment()); agent.send(new Message(Action.build, MessageEncoding.encodeData(buildSettings))); } else { agent.send(new Message(Action.assignWork, MessageEncoding.encodeWork(work))); } } } LOGGER.debug("Matching {} agents with {} jobs took: {}ms", agents.size(), jobPlans.size(), System.currentTimeMillis() - start); }
public void updateRuntimeInfo(AgentRuntimeInfo info) { if (!info.hasCookie()) { LOGGER.warn("Agent [{}] has no cookie set", info.agentInfoDebugString()); throw new AgentNoCookieSetException(format("Agent [%s] has no cookie set", info.agentInfoDebugString())); } if (info.hasDuplicateCookie(agentDao.cookieFor(info.getIdentifier()))) { LOGGER.warn("Found agent [{}] with duplicate uuid. Please check the agent installation.", info.agentInfoDebugString()); serverHealthService.update( ServerHealthState.warning(format("[%s] has duplicate unique identifier which conflicts with [%s]", info.agentInfoForDisplay(), findAgentAndRefreshStatus(info.getUUId()).agentInfoForDisplay()), "Please check the agent installation. Click <a href='" + docsUrl("/faq/agent_guid_issue.html") + "' target='_blank'>here</a> for more info.", HealthStateType.duplicateAgent(HealthStateScope.forAgent(info.getCookie())), Timeout.THIRTY_SECONDS)); throw new AgentWithDuplicateUUIDException(format("Agent [%s] has invalid cookie", info.agentInfoDebugString())); } AgentInstance agentInstance = findAgentAndRefreshStatus(info.getUUId()); if (agentInstance.isIpChangeRequired(info.getIpAdress())) { AgentConfig agentConfig = agentInstance.agentConfig(); Username userName = agentUsername(info.getUUId(), info.getIpAdress(), agentConfig.getHostNameForDisplay()); LOGGER.warn("Agent with UUID [{}] changed IP Address from [{}] to [{}]", info.getUUId(), agentConfig.getIpAddress(), info.getIpAdress()); agentConfigService.updateAgentIpByUuid(agentConfig.getUuid(), info.getIpAdress(), userName); } agentInstances.updateAgentRuntimeInfo(info); }