public static void externalizeJobValues(JobDataMap jobDataMap, String key, Collection<Agent> agents) { if (agents != null && agents.size() > 0) { StringBuilder valuesCommaSeparated = new StringBuilder(); String comma = ""; for (Agent agent : agents) { valuesCommaSeparated.append(comma).append(agent.getId()); comma = ","; } jobDataMap.put(key, valuesCommaSeparated.toString()); } }
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) public void updateByAgent(int agentId) { log.debug("About to mark status by agent"); Query updateAgentQuery = entityManager.createNamedQuery(Agent.QUERY_UPDATE_STATUS_BY_AGENT); updateAgentQuery.setParameter("agentId", agentId); updateAgentQuery.executeUpdate(); /* * this is informational debugging only - do NOT change the status bits here */ if (log.isDebugEnabled()) { Agent agent = entityManager.find(Agent.class, agentId); log.debug("Marking status, agent[id=" + agent.getId() + ", status=" + agent.getStatus() + "]"); } }
@ExcludeDefaultInterceptors public void deleteAgent(Agent agent) { agent = entityManager.find(Agent.class, agent.getId()); failoverListManager.deleteServerListsForAgent(agent); entityManager.remove(agent); Query q = entityManager.createNamedQuery(AgentInstall.QUERY_DELETE_BY_NAME); q.setParameter("agentName", agent.getName()); q.executeUpdate(); destroyAgentClient(agent); LOG.info("Removed agent: " + agent); }
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) public void updateByAutoBaselineCalculationJob() { log.debug("About to mark status by autoBaselineCalculationJob"); // baselines refer to measurement-based alert conditions, thus only agent statuses need to be set Query updateAgentQuery = entityManager.createNamedQuery(Agent.QUERY_UPDATE_STATUS_FOR_ALL); updateAgentQuery.executeUpdate(); /* * this is informational debugging only - do NOT change the status bits here */ if (log.isDebugEnabled()) { List<Agent> agents = agentManager.getAllAgents(); for (Agent agent : agents) { log.debug("Marking status, agent[id=" + agent.getId() + ", status=" + agent.getStatus() + "] for AutoBaselineCalculationJob"); } } } }
private boolean sendUpdatedSchedulesToAgent(Agent agent, Set<ResourceMeasurementScheduleRequest> resourceMeasurementScheduleRequest) { try { AgentClient agentClient = LookupUtil.getAgentManager().getAgentClient(agent); if (!agentClient.pingService(2000)) { if (log.isDebugEnabled()) { log.debug("Won't send MeasurementSchedules to offline Agent[id=" + agent.getId() + "]"); } return false; } agentClient.getMeasurementAgentService().updateCollection(resourceMeasurementScheduleRequest); return true; // successfully sync'ed schedules down to the agent } catch (Throwable t) { log.error("Error updating MeasurementSchedules for Agent[id=" + agent.getId() + "]: ", t); } return false; // catch all and presume the live sync failed }
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) public void updateByMeasurementBaseline(int baselineId) { log.debug("About to mark status by measurement baseline"); // baselines refer to measurement-based alert conditions, thus only agent statuses need to be set Query updateAgentQuery = entityManager.createNamedQuery(Agent.QUERY_UPDATE_STATUS_BY_MEASUREMENT_BASELINE); updateAgentQuery.setParameter("baselineId", baselineId); updateAgentQuery.executeUpdate(); /* * this is informational debugging only - do NOT change the status bits here */ if (log.isDebugEnabled()) { MeasurementBaseline baseline = entityManager.find(MeasurementBaseline.class, baselineId); Agent agent = baseline.getSchedule().getResource().getAgent(); log.debug("Marking status, agent[id=" + agent.getId() + ", status=" + agent.getStatus() + "] for measurementBaseline[id=" + baselineId + "]"); } }
public void reloadAllCaches() { reloadGlobalCache(); List<Agent> agents = serverManager.getAgents(); for (Agent agent : agents) { reloadCachesForAgent(agent.getId()); } }
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) public void updateByResource(Subject subject, int resourceId) { log.debug("About to mark status by resource"); /* * the old alert definition is needed to know which caches to remove stale entries from; the updated / new * alert definition is needed to know which caches need to be reloaded to get the new conditions; by the time * this method is called, we only have the updated alert definition, thus it's not possible to intelligently * know which of the two caches to reload; so, we need to reload them both to be sure the system is consistent */ markGlobalCache(); // use local references to execute in the same transaction Query updateAgentQuery = entityManager.createNamedQuery(Agent.QUERY_UPDATE_STATUS_BY_RESOURCE); updateAgentQuery.setParameter("resourceId", resourceId); int agentsUpdated = updateAgentQuery.executeUpdate(); /* * this is informational debugging only - do NOT change the status bits here */ if (log.isDebugEnabled()) { Agent agent = agentManager.getAgentByResourceId(LookupUtil.getSubjectManager().getOverlord(), resourceId); log.debug("Marking status, agent[id=" + agent.getId() + ", status=" + agent.getStatus() + "] for resource[id=" + resourceId + "]"); log.debug("Agents updated: " + agentsUpdated); } }
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) public void updateByAlertDefinition(Subject subject, int alertDefinitionId) { log.debug("About to mark status by alert definition"); // alert templates and group alert definitions do not represent cache-ready entries if (alertDefinitionManager.isResourceAlertDefinition(alertDefinitionId) == false) { return; } /* * the old alert definition is needed to know which caches to remove stale entries from; the updated / new * alert definition is needed to know which caches need to be reloaded to get the new conditions; by the time * this method is called, we only have the updated alert definition, thus it's not possible to intelligently * know which of the two caches to reload; so, we need to reload them both to be sure the system is consistent */ markGlobalCache(); // use local references to execute in the same transaction Query updateAgentQuery = entityManager.createNamedQuery(Agent.QUERY_UPDATE_STATUS_BY_ALERT_DEFINITION); updateAgentQuery.setParameter("alertDefinitionId", alertDefinitionId); int agentsUpdated = updateAgentQuery.executeUpdate(); /* * this is informational debugging only - do NOT change the status bits here */ if (log.isDebugEnabled()) { AlertDefinition definition = entityManager.find(AlertDefinition.class, alertDefinitionId); Agent agent = agentManager.getAgentByResourceId(LookupUtil.getSubjectManager().getOverlord(), definition .getResource().getId()); log.debug("Marking status, agent[id=" + agent.getId() + ", status=" + agent.getStatus() + "] for alertDefinition[id=" + alertDefinitionId + "]"); log.debug("Agents updated: " + agentsUpdated); } }
int agentId = agentEntry.getKey().getId(); setAgentSynchronizationNeededByDefinitionsForAgent(agentId, idsAsList);
@Asynchronous @ExcludeDefaultInterceptors public void agentIsShuttingDown(String agentName) { Agent downedAgent = getAgentByName(agentName); ServerCommunicationsServiceMBean server_bootstrap = ServerCommunicationsServiceUtil.getService(); server_bootstrap.removeDownedAgent(downedAgent.getRemoteEndpoint()); LOG.info("Agent with name [" + agentName + "] just went down"); agentManager.backfillAgentInNewTransaction(subjectManager.getOverlord(), agentName, downedAgent.getId()); return; }
/** * @see CoreServerService#connectAgent(ConnectAgentRequest) */ @Override public ConnectAgentResults connectAgent(ConnectAgentRequest request) throws AgentRegistrationException, AgentNotSupportedException { String agentName = request.getAgentName(); AgentVersion agentVersion = request.getAgentVersion(); log.info("Agent [" + agentName + "][" + agentVersion + "] would like to connect to this server"); AgentVersionCheckResults agentVersionCheckResults = getAgentManager().isAgentVersionSupported(agentVersion); if (!agentVersionCheckResults.isSupported()) { log.warn("Agent [" + agentName + "][" + agentVersion + "] would like to connect to this server but it is not supported"); throw new AgentNotSupportedException("Agent [" + agentName + "] is an unsupported agent: " + agentVersion); } Agent agent = getAgentManager().getAgentByName(agentName); if (agent == null) { throw new AgentRegistrationException("Agent [" + agentName + "] is not registered"); } Server server = getServerManager().getServer(); agent.setServer(server); agent.setLastAvailabilityPing(Long.valueOf(System.currentTimeMillis())); getAgentManager().updateAgent(agent); getAlertConditionCacheManager().reloadCachesForAgent(agent.getId()); getPartitionEventManager().auditPartitionEvent(getSubjectManager().getOverlord(), PartitionEventType.AGENT_CONNECT, agentName + " - " + server.getName()); log.info("Agent [" + agentName + "] has connected to this server at " + new Date()); return new ConnectAgentResults(System.currentTimeMillis(), agent.isBackFilled(), agentVersionCheckResults.getLatestAgentVersion()); }