public PartitionEventDetails(PartitionEvent partitionEvent, Agent agent, Server server) { this.partitionEvent = partitionEvent; this.agentName = agent.getName(); this.serverName = server.getName(); }
@SuppressWarnings("unused") private void logServerList(String debugTitle, Map<Agent, List<ServerBucket>> agentServerListMap) { //if (!log.isInfoEnabled()) // return; StringBuilder sb = new StringBuilder("\nServerList ("); sb.append(debugTitle); sb.append(") :"); for (Agent agent : agentServerListMap.keySet()) { sb.append("\n\n Agent: " + agent.getName()); for (ServerBucket bucket : agentServerListMap.get(agent)) { sb.append("\n "); sb.append(bucket.assignedLoad); sb.append(" : "); sb.append(bucket.server.getName()); } } sb.append("\n\n"); System.out.println(sb.toString()); log.info(sb.toString()); }
@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); }
/** * Returns a configuration that can be used for the the client command sender that will talk to the given agent. * * @param agent * * @return configuration for a {@link ClientCommandSender} that will talk to the given agent */ private ClientCommandSenderConfiguration getSenderConfiguration(Agent agent) { ServerConfiguration server_config = getConfiguration(); ClientCommandSenderConfiguration client_config = server_config.getClientCommandSenderConfiguration(); // make sure it uses a unique spool file. Senders cannot share spool files; each remote endpoint // must have its own spool file since the spool file contains command requests for a single, specific, agent. // (a null spool filename means we will never guarantee message delivery to agents) if (client_config.commandSpoolFileName != null) { File spool_file = new File(client_config.commandSpoolFileName); String file_name = spool_file.getName(); String parent_path = spool_file.getParent(); spool_file = new File(parent_path, agent.getName() + "_" + file_name); client_config.commandSpoolFileName = spool_file.getPath(); } return client_config; }
@Override public boolean pingService(long timeoutMillis) { try { // create our own factory so we can customize the timeout ClientRemotePojoFactory factory = sender.getClientRemotePojoFactory(); factory.setTimeout(timeoutMillis); PingAgentService pinger = factory.getRemotePojo(PingAgentService.class); long agentTime = pinger.ping(); long skew = Math.abs(System.currentTimeMillis() - agentTime); if (skew > 5 * 60 * 1000L) { LogFactory.getLog(this.getClass()).debug( "Agent [" + agent.getName() + "] either took a long time to process a ping (" + skew + "ms) or its clock is not synced: " + new Date(agentTime)); } return true; } catch (Exception e) { return false; } }
@RequiredPermissions({ @RequiredPermission(Permission.MANAGE_SETTINGS), @RequiredPermission(Permission.MANAGE_INVENTORY) }) public void removeAgentsFromGroup(Subject subject, Integer[] agentIds) { List<Integer> agentIdsList = Arrays.asList(agentIds); Query query = entityManager.createNamedQuery(AffinityGroup.QUERY_UPDATE_REMOVE_SPECIFIC_AGENTS); query.setParameter("agentIds", agentIdsList); query.executeUpdate(); // Audit each changed affinity group assignment (is this too verbose?) for (Integer agentId : agentIdsList) { Agent agent = entityManager.find(Agent.class, agentId); partitionEventManager.auditPartitionEvent(subject, PartitionEventType.AGENT_AFFINITY_GROUP_REMOVE, agent .getName()); } // Now, request a cloud repartitioning due to the affinity group changes partitionEventManager.cloudPartitionEventRequest(subject, PartitionEventType.AFFINITY_GROUP_CHANGE, PartitionEventType.AGENT_AFFINITY_GROUP_REMOVE.name()); }
@RequiredPermissions({ @RequiredPermission(Permission.MANAGE_SETTINGS), @RequiredPermission(Permission.MANAGE_INVENTORY) }) public void addAgentsToGroup(Subject subject, int affinityGroupId, Integer[] agentIds) { List<Integer> agentIdsList = Arrays.asList(agentIds); AffinityGroup group = entityManager.find(AffinityGroup.class, affinityGroupId); Query query = entityManager.createNamedQuery(AffinityGroup.QUERY_UPDATE_ADD_AGENTS); query.setParameter("affinityGroup", group); query.setParameter("agentIds", agentIdsList); query.executeUpdate(); // Audit each changed affinity group assignment (is this too verbose?) String auditString = group.getName() + " <-- "; for (Integer agentId : agentIdsList) { Agent agent = entityManager.find(Agent.class, agentId); partitionEventManager.auditPartitionEvent(subject, PartitionEventType.AGENT_AFFINITY_GROUP_ASSIGN, auditString + agent.getName()); } // Now, request a cloud repartitioning due to the affinity group changes partitionEventManager.cloudPartitionEventRequest(subject, PartitionEventType.AFFINITY_GROUP_CHANGE, group .getName()); }
if (agent.getName().startsWith(ResourceHandlerBean.DUMMY_AGENT_NAME_PREFIX) && agent.getAgentToken().startsWith(ResourceHandlerBean.DUMMY_AGENT_TOKEN_PREFIX)) { return Collections.<MeasurementData> emptySet();
} catch (Throwable t) { if (log.isDebugEnabled()) { log.debug("Tried to immediately sync agent[name=" + agent.getName() + "] with error-corrected schedules failed");
@Override @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED) public void setResourceAvailabilities(Map<Agent, int[]> map, AvailabilityType avail) { long now = System.currentTimeMillis(); for (Agent agent : map.keySet()) { AvailabilityReport report = new AvailabilityReport(true, null); report.setServerSideReport(true); for (int resourceId : map.get(agent)) { report.addAvailability(new Datum(resourceId, avail, now)); } AvailabilityReportSerializer.getSingleton().lock(agent.getName()); try { this.availabilityManager.mergeAvailabilityReport(report); } finally { AvailabilityReportSerializer.getSingleton().unlock(agent.getName()); } } return; }
@RequiredPermission(Permission.MANAGE_INVENTORY) public FailoverListComposite agentPartitionEvent(Subject subject, String agentName, PartitionEventType eventType, String eventDetail) { if (eventType.isCloudPartitionEvent() || (null == agentName)) { throw new IllegalArgumentException("Invalid agent partition event or no agent specified for event type: " + eventType); } Agent agent = agentManager.getAgentByName(agentName); if (null == agent) { throw new IllegalArgumentException("Can not perform partition event, agent not found with name: " + agentName); } PartitionEvent partitionEvent = new PartitionEvent(subject.getName(), eventType, eventDetail, PartitionEvent.ExecutionStatus.IMMEDIATE); partitionEventManager.createPartitionEvent(subject, partitionEvent); return failoverListManager.getForSingleAgent(partitionEvent, agent.getName()); }
if (resourceIdWithAgent.getAgent().getName().startsWith(ResourceHandlerBean.DUMMY_AGENT_NAME_PREFIX) && resourceIdWithAgent.getAgent().getAgentToken() .startsWith(ResourceHandlerBean.DUMMY_AGENT_TOKEN_PREFIX)) {
AvailabilityReport report = reports.get(agent); if (null == report) { report = new AvailabilityReport(agent.getName()); report.setEnablementReport(true); reports.put(agent, report);
AvailabilityReport report = reports.get(agent); if (null == report) { report = new AvailabilityReport(agent.getName()); report.setEnablementReport(true); reports.put(agent, report);
result.put("Agent " + agent.getName(), agent.toString());
@Override @NotNull public AvailabilityReport getCurrentAvailability(Resource resource, boolean changesOnly) { try { //make sure we have the full version of the resource ResourceContainer container = getResourceContainer(resource.getId()); if (container == null) { //don't bother doing anything return new AvailabilityReport(changesOnly, getAgent().getName()); } resource = container.getResource(); MeasurementScheduleRequest availSchedule = container.getAvailabilitySchedule(); boolean forceScanForRoot = availSchedule == null || availSchedule.isEnabled(); // force scan for root resource only if availability schedule is enabled AvailabilityExecutor availExec = new CustomScanRootAvailabilityExecutor(this, resource, forceScanForRoot); if (changesOnly) { availExec.sendChangesOnlyReportNextTime(); } else { availExec.sendFullReportNextTime(); } return availabilityThreadPoolExecutor.submit((Callable<AvailabilityReport>) availExec).get(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new RuntimeException("Availability scan execution was interrupted", e); } catch (ExecutionException e) { // Should never happen, reports are always generated, even if they're just to report the error throw new RuntimeException("Unexpected exception", e); } }
availabilityReport = new AvailabilityReport(changesOnly, inventoryManager.getAgent().getName());
@PUT @Path("/{id}/availability") @ApiOperation("Set the current availability of the passed resource") @TransactionAttribute(TransactionAttributeType.NEVER) public void reportAvailability(@ApiParam("Id of the resource to update") @PathParam("id") int resourceId, @ApiParam(value= "New Availability setting", required = true) AvailabilityRest avail) { if (avail.getResourceId() != resourceId) throw new IllegalArgumentException("Resource Ids do not match"); Resource resource = fetchResource(resourceId); AvailabilityType at; at = AvailabilityType.valueOf(avail.getType()); // According to jshaughn, plaforms must not be set to DISABLED, so catch this case here. if (resource.getResourceType().getCategory()==ResourceCategory.PLATFORM && at==AvailabilityType.DISABLED) { throw new BadArgumentException("Availability","Platforms must not be set to DISABLED"); } Agent agent = agentMgr.getAgentByResourceId(caller,resourceId); AvailabilityReport report = new AvailabilityReport(true, agent.getName()); Availability availability = new Availability(resource, avail.getSince(), at); report.addAvailability(availability); availMgr.mergeAvailabilityReport(report); }