CaptureAgentStateServiceImpl implements CaptureAgentStateService, ManagedServiceFactory { @Override public void updated(String pid, Dictionary<String, ?> properties) throws ConfigurationException { String nameConfig = (String) properties.get("id"); if (isBlank(nameConfig)) throw new ConfigurationException("id", "must be specified"); nameConfig = nameConfig.trim(); String urlConfig = (String) properties.get("url"); if (isBlank(urlConfig)) throw new ConfigurationException("url", "must be specified"); urlConfig = urlConfig.trim(); String orgConfig = (String) properties.get("organization"); if (isBlank(orgConfig)) throw new ConfigurationException("organization", "must be specified"); orgConfig = orgConfig.trim(); String schedulerRolesConfig = (String) properties.get("schedulerRoles"); if (isBlank(schedulerRolesConfig)) throw new ConfigurationException("schedulerRoles", "must be specified"); String[] schedulerRoles = schedulerRolesConfig.trim().split(","); if (!pidMap.containsKey(pid)) { pidMap.put(pid, nameConfig); } AgentImpl agent; try { agent = getAgent(nameConfig, orgConfig); agent.setUrl(urlConfig); agent.setState(UNKNOWN); } catch (NotFoundException e) { agent = new AgentImpl(nameConfig, orgConfig, UNKNOWN, urlConfig, new Properties()); } for (String role : schedulerRoles) { agent.schedulerRoles.add(role.trim()); } logger.info("Roles '{}' may schedule '{}'", schedulerRolesConfig, agent.name); updateAgentInDatabase(agent); } 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; }
@Test public void testManagedServiceFactory() throws Exception { String pid = UUID.randomUUID().toString(); Dictionary<String, String> properties = new Hashtable<>(); properties.put("id", "agent1"); properties.put("organization", DefaultOrganization.DEFAULT_ORGANIZATION_ID); properties.put("url", "http: properties.put("schedulerRoles", DefaultOrganization.DEFAULT_ORGANIZATION_ADMIN + ", SOME_OTHER_ROLE"); service.updated(pid, properties); properties.remove("id"); try { service.updated(pid, properties); fail(); } catch (ConfigurationException e) { } }