@Test public void noAgents() { assertEquals(0, service.getKnownAgents().size()); }
@Override public Map<String, Agent> getKnownAgents() { agentCache.cleanUp(); EntityManager em = null; User user = securityService.getUser(); Organization org = securityService.getOrganization(); String orgAdmin = org.getAdminRole(); Set<Role> roles = user.getRoles(); try { em = emf.createEntityManager(); Query q = em.createNamedQuery("Agent.byOrganization"); q.setParameter("org", securityService.getOrganization().getId()); List<AgentImpl> agents = q.getResultList(); if (!user.hasRole(SecurityConstants.GLOBAL_ADMIN_ROLE) && !user.hasRole(orgAdmin)) { for (Iterator<AgentImpl> iter = agents.iterator(); iter.hasNext();) { AgentImpl agent = iter.next(); Set<String> schedulerRoles = agent.getSchedulerRoles(); if (schedulerRoles == null || schedulerRoles.isEmpty()) { continue; } boolean hasSchedulerRole = false; for (Role role : roles) { if (schedulerRoles.contains(role.getName())) { hasSchedulerRole = true; break; } } if (!hasSchedulerRole) { iter.remove(); } } } Map<String, Agent> map = new TreeMap<>(); for (AgentImpl agent : agents) { map.put(agent.getName(), updateCachedLastHeardFrom(agent, org.getId())); } return map; } finally { if (em != null) em.close(); } }
CaptureAgentStateServiceImpl implements CaptureAgentStateService, ManagedServiceFactory { @Override public Map<String, Agent> getKnownAgents() { agentCache.cleanUp(); EntityManager em = null; User user = securityService.getUser(); Organization org = securityService.getOrganization(); String orgAdmin = org.getAdminRole(); Set<Role> roles = user.getRoles(); try { em = emf.createEntityManager(); Query q = em.createNamedQuery("Agent.byOrganization"); q.setParameter("org", securityService.getOrganization().getId()); List<AgentImpl> agents = q.getResultList(); if (!user.hasRole(SecurityConstants.GLOBAL_ADMIN_ROLE) && !user.hasRole(orgAdmin)) { for (Iterator<AgentImpl> iter = agents.iterator(); iter.hasNext();) { AgentImpl agent = iter.next(); Set<String> schedulerRoles = agent.getSchedulerRoles(); if (schedulerRoles == null || schedulerRoles.isEmpty()) { continue; } boolean hasSchedulerRole = false; for (Role role : roles) { if (schedulerRoles.contains(role.getName())) { hasSchedulerRole = true; break; } } if (!hasSchedulerRole) { iter.remove(); } } } Map<String, Agent> map = new TreeMap<>(); for (AgentImpl agent : agents) { map.put(agent.getName(), updateCachedLastHeardFrom(agent, org.getId())); } return map; } finally { if (em != null) em.close(); } } }
CaptureAgentStateServiceImpl implements CaptureAgentStateService, ManagedServiceFactory { @Override public Map<String, Agent> getKnownAgents() { agentCache.cleanUp(); EntityManager em = null; User user = securityService.getUser(); Organization org = securityService.getOrganization(); String orgAdmin = org.getAdminRole(); Set<Role> roles = user.getRoles(); try { em = emf.createEntityManager(); Query q = em.createNamedQuery("Agent.byOrganization"); q.setParameter("org", securityService.getOrganization().getId()); List<AgentImpl> agents = q.getResultList(); if (!user.hasRole(SecurityConstants.GLOBAL_ADMIN_ROLE) && !user.hasRole(orgAdmin)) { for (Iterator<AgentImpl> iter = agents.iterator(); iter.hasNext();) { AgentImpl agent = iter.next(); Set<String> schedulerRoles = agent.getSchedulerRoles(); if (schedulerRoles == null || schedulerRoles.isEmpty()) { continue; } boolean hasSchedulerRole = false; for (Role role : roles) { if (schedulerRoles.contains(role.getName())) { hasSchedulerRole = true; break; } } if (!hasSchedulerRole) { iter.remove(); } } } Map<String, Agent> map = new TreeMap<>(); for (AgentImpl agent : agents) { map.put(agent.getName(), updateCachedLastHeardFrom(agent, org.getId())); } return map; } finally { if (em != null) em.close(); } } CaptureAgentStateServiceImpl(); }
CaptureAgentStateServiceImpl implements CaptureAgentStateService, ManagedServiceFactory { @Override public Map<String, Agent> getKnownAgents() { agentCache.cleanUp(); EntityManager em = null; User user = securityService.getUser(); Organization org = securityService.getOrganization(); String orgAdmin = org.getAdminRole(); Set<Role> roles = user.getRoles(); try { em = emf.createEntityManager(); Query q = em.createNamedQuery("Agent.byOrganization"); q.setParameter("org", securityService.getOrganization().getId()); List<AgentImpl> agents = q.getResultList(); if (!user.hasRole(SecurityConstants.GLOBAL_ADMIN_ROLE) && !user.hasRole(orgAdmin)) { for (Iterator<AgentImpl> iter = agents.iterator(); iter.hasNext();) { AgentImpl agent = iter.next(); Set<String> schedulerRoles = agent.getSchedulerRoles(); if (schedulerRoles == null || schedulerRoles.isEmpty()) { continue; } boolean hasSchedulerRole = false; for (Role role : roles) { if (schedulerRoles.contains(role.getName())) { hasSchedulerRole = true; break; } } if (!hasSchedulerRole) { iter.remove(); } } } Map<String, Agent> map = new TreeMap<>(); for (AgentImpl agent : agents) { map.put(agent.getName(), updateCachedLastHeardFrom(agent, org.getId())); } return map; } finally { if (em != null) em.close(); } } CaptureAgentStateServiceImpl(); @Reference(name = "security-service") void setSecurityService(SecurityService securityService); @Activate void activate(ComponentContext cc); @Deactivate void deactivate(); @Override Agent getAgent(String name); @Override String getAgentState(String agentName); @Override boolean setAgentState(String agentName, String state); @Override boolean setAgentUrl(String agentName, String agentUrl); @Override void removeAgent(String agentName); @Override Map<String, Agent> getKnownAgents(); @Override Properties getAgentCapabilities(String agentName); @Override Properties getAgentConfiguration(String agentName); @Override boolean setAgentConfiguration(String agentName, Properties configuration); @Override String getName(); @Override void updated(String pid, Dictionary<String, ?> properties); @Override void deleted(String pid); }
CaptureAgentStateServiceImpl implements CaptureAgentStateService, ManagedServiceFactory { @Override public Map<String, Agent> getKnownAgents() { agentCache.cleanUp(); EntityManager em = null; User user = securityService.getUser(); Organization org = securityService.getOrganization(); String orgAdmin = org.getAdminRole(); Set<Role> roles = user.getRoles(); try { em = emf.createEntityManager(); Query q = em.createNamedQuery("Agent.byOrganization"); q.setParameter("org", securityService.getOrganization().getId()); List<AgentImpl> agents = q.getResultList(); if (!user.hasRole(SecurityConstants.GLOBAL_ADMIN_ROLE) && !user.hasRole(orgAdmin)) { for (Iterator<AgentImpl> iter = agents.iterator(); iter.hasNext();) { AgentImpl agent = iter.next(); Set<String> schedulerRoles = agent.getSchedulerRoles(); if (schedulerRoles == null || schedulerRoles.isEmpty()) { continue; } boolean hasSchedulerRole = false; for (Role role : roles) { if (schedulerRoles.contains(role.getName())) { hasSchedulerRole = true; break; } } if (!hasSchedulerRole) { iter.remove(); } } } Map<String, Agent> map = new TreeMap<>(); for (AgentImpl agent : agents) { map.put(agent.getName(), updateCachedLastHeardFrom(agent, org.getId())); } return map; } finally { if (em != null) em.close(); } } CaptureAgentStateServiceImpl(); @Reference(name = "security-service") void setSecurityService(SecurityService securityService); @Activate void activate(ComponentContext cc); @Deactivate void deactivate(); @Override Agent getAgent(String name); @Override String getAgentState(String agentName); @Override boolean setAgentState(String agentName, String state); @Override boolean setAgentUrl(String agentName, String agentUrl); @Override void removeAgent(String agentName); @Override Map<String, Agent> getKnownAgents(); @Override Properties getAgentCapabilities(String agentName); @Override Properties getAgentConfiguration(String agentName); @Override boolean setAgentConfiguration(String agentName, Properties configuration); @Override String getName(); @Override void updated(String pid, Dictionary<String, ?> properties); @Override void deleted(String pid); static final String PERSISTENCE_UNIT; static final String CAPTURE_AGENT_TIMEOUT_KEY; }