@Override public AgentInstance doFetchEntityFromConfig(String uuid) { final AgentInstance agentInstance = agentService.findAgent(uuid); return agentInstance instanceof NullAgentInstance ? null : agentInstance; }
@RequestMapping(value = "/admin/agent/token", method = RequestMethod.GET) public ResponseEntity getToken(@RequestParam("uuid") String uuid) { if (StringUtils.isBlank(uuid)) { String message = "UUID cannot be blank."; LOG.error("Rejecting request for token. Error: HttpCode=[{}] Message=[{}] UUID=[{}]", CONFLICT, message, uuid); return new ResponseEntity<>(message, CONFLICT); } final AgentInstance agentInstance = agentService.findAgent(uuid); if ((!agentInstance.isNullAgent() && agentInstance.isPending()) || goConfigService.hasAgent(uuid)) { String message = "A token has already been issued for this agent."; LOG.error("Rejecting request for token. Error: HttpCode=[{}] Message=[{}] Pending=[{}] UUID=[{}]", CONFLICT, message, agentInstance.isPending(), uuid); return new ResponseEntity<>(message, CONFLICT); } return new ResponseEntity<>(encodeBase64String(hmac().doFinal(uuid.getBytes())), OK); }
public AgentInstance updateAgentAttributes(Username username, HttpOperationResult result, String uuid, String newHostname, String resources, String environments, TriState enable) { if (!hasOperatePermission(username, result)) { return null; } AgentInstance agentInstance = findAgent(uuid); if (isUnknownAgent(agentInstance, result)) { return null; } AgentConfig agentConfig = agentConfigService.updateAgentAttributes(uuid, username, newHostname, resources, environments, enable, agentInstances, result); if (agentConfig != null) { return AgentInstance.createFromConfig(agentConfig, systemEnvironment, agentStatusChangeNotifier); } return null; }
public void jobCompleted(JobInstance job) { AgentInstance agentInstance = agentService.findAgent(job.getAgentUuid()); if (!agentInstance.isElastic()) { LOGGER.debug("Agent {} is not elastic. Skipping further execution.", agentInstance.getUuid()); return; } if (job.isAssignedToAgent()) { jobCreationTimeMap.remove(job.getId()); } String pluginId = agentInstance.elasticAgentMetadata().elasticPluginId(); String elasticAgentId = agentInstance.elasticAgentMetadata().elasticAgentId(); elasticAgentPluginRegistry.reportJobCompletion(pluginId, elasticAgentId, job.getIdentifier()); } }