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; }
private HashMap<String, String> getBuildLocatorToAgentUUIDMap() { AgentInstances agents = agentService.agents(); HashMap<String, String> buildToAgentUUIDMap = new HashMap<>(); for (AgentInstance agent : agents) { if (agent.isBuilding()) { buildToAgentUUIDMap.put(agent.getBuildLocator(), agent.getUuid()); } } return buildToAgentUUIDMap; }
protected Collection<AgentMetadata> getAgentMetadataForPlugin(String pluginId) { LOGGER.debug("Listing agents for plugin {}", pluginId); List<ElasticAgentMetadata> elasticAgents = agentService.allElasticAgents().get(pluginId); Collection<AgentMetadata> metadata; if (elasticAgents == null) { metadata = new ArrayList<>(); } else { metadata = elasticAgents.stream().map(ElasticAgentPluginService::toAgentMetadata).collect(Collectors.toList()); } return metadata; }
@Override public AgentInstance doFetchEntityFromConfig(String uuid) { final AgentInstance agentInstance = agentService.findAgent(uuid); return agentInstance instanceof NullAgentInstance ? null : agentInstance; }
); HttpOperationResult result = new HttpOperationResult(); agentConfig = agentConfigService.updateAgent(compositeConfigCommand, uuid, result, agentService.agentUsername(uuid, ipAddress, preferredHostname)); if (!result.isSuccess()) { List<ConfigErrors> errors = ErrorCollector.getAllErrors(agentConfig); keyEntry = agentService.requestRegistration(agentService.agentUsername(uuid, ipAddress, preferredHostname), agentRuntimeInfo);
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); }
public String deleteAgent(Request request, Response response) throws IOException { final HttpOperationResult result = new HttpOperationResult(); agentService.deleteAgents(currentUsername(), result, singletonList(request.params("uuid"))); return renderHTTPOperationResult(result, request, response); }
public String getCookie(AgentIdentifier identifier, String location) { try { String cookie = agentService.assignCookie(identifier); LOGGER.info("[Agent Cookie] Agent [{}] at location [{}] asked for a new cookie, assigned [{}]", identifier, location, cookie); return cookie; } catch (Exception e) { LOGGER.error("[Agent Cookie] Agent [{}] at location [{}] could not get a cookie.", identifier, location, e); throw wrappedException(e); } }
public void setAgentViewModels(AgentService agentService) { this.agentViewModels = agentService.filter(environmentConfig.getLocalAgents().getUuids()); }
public String index(Request request, Response response) throws IOException { return writerForTopLevelObject(request, response, outputWriter -> AgentsRepresenter.toJSON(outputWriter, agentService.agentEnvironmentMap(), securityService, currentUsername())); }
AgentBuildingInfo buildingInfo = new AgentBuildingInfo(job.getIdentifier().buildLocatorForDisplay(), job.getIdentifier().buildLocator()); agentService.building(agent.getUuid(), buildingInfo); LOGGER.info("[Agent Assignment] Assigned job [{}] to agent [{}]", job.getIdentifier(), agent.agentConfig().getAgentIdentifier());
public String bulkUpdate(Request request, Response response) throws IOException { final AgentBulkUpdateRequest bulkUpdateRequest = AgentBulkUpdateRequestRepresenter.fromJSON(request.body()); final HttpLocalizedOperationResult result = new HttpLocalizedOperationResult(); agentService.bulkUpdateAgentAttributes(currentUsername(), result, bulkUpdateRequest.getUuids(), bulkUpdateRequest.getOperations().getResources().toAdd(), bulkUpdateRequest.getOperations().getResources().toRemove(), bulkUpdateRequest.getOperations().getEnvironments().toAdd(), bulkUpdateRequest.getOperations().getEnvironments().toRemove(), bulkUpdateRequest.getAgentConfigState() ); return renderHTTPOperationResult(result, request, response); }
@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 String bulkDeleteAgents(Request request, Response response) throws IOException { final JsonReader reader = GsonTransformer.getInstance().jsonReaderFrom(request.body()); final List<String> uuids = toList(reader.optJsonArray("uuids").orElse(new JsonArray())); final HttpOperationResult result = new HttpOperationResult(); agentService.deleteAgents(currentUsername(), result, uuids); return renderHTTPOperationResult(result, request, response); }
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()); } }
public void heartbeat() { LinkedMultiValueMap<String, ElasticAgentMetadata> elasticAgentsOfMissingPlugins = agentService.allElasticAgents(); // pingMessage TTL is set lesser than elasticPluginHeartBeatInterval to ensure there aren't multiple ping request for the same plugin long pingMessageTimeToLive = elasticPluginHeartBeatInterval - 10000L; for (PluginDescriptor descriptor : elasticAgentPluginRegistry.getPlugins()) { serverPingQueue.post(new ServerPingMessage(descriptor.id()), pingMessageTimeToLive); elasticAgentsOfMissingPlugins.remove(descriptor.id()); serverHealthService.removeByScope(scope(descriptor.id())); } if (!elasticAgentsOfMissingPlugins.isEmpty()) { for (String pluginId : elasticAgentsOfMissingPlugins.keySet()) { Collection<String> uuids = elasticAgentsOfMissingPlugins.get(pluginId).stream().map(ElasticAgentMetadata::uuid).collect(Collectors.toList()); String description = String.format("Elastic agent plugin with identifier %s has gone missing, but left behind %s agent(s) with UUIDs %s.", pluginId, elasticAgentsOfMissingPlugins.get(pluginId).size(), uuids); serverHealthService.update(ServerHealthState.warning("Elastic agents with no matching plugins", description, HealthStateType.general(scope(pluginId)))); LOGGER.warn(description); } } }