@Test(expected = IOException.class) public void testAllGroupsFail() throws Exception { ServiceElement service = new ServiceElement(); ServiceBeanConfig serviceBeanConfig = new ServiceBeanConfig(); serviceBeanConfig.setGroups("all"); service.setServiceBeanConfig(serviceBeanConfig); deploymentVerifier.ensureGroups(service); }
void ensureGroups(final ServiceElement serviceElement) throws IOException { if (serviceElement.getServiceBeanConfig().getGroups()==DiscoveryGroupManagement.ALL_GROUPS) { throw new IOException(String.format("Service %s has been declared for ALL_GROUPS", serviceElement.getName())); } for(ServiceRegistrar registrar : discoveryManagement.getRegistrars()) { try { List<String> toAdd = new ArrayList<>(); DiscoveryAdmin admin = (DiscoveryAdmin) ((Administrable)registrar).getAdmin(); String[] knownGroups = admin.getMemberGroups(); for(String serviceGroup : serviceElement.getServiceBeanConfig().getGroups()) { boolean found = false; for(String known : knownGroups) { if (serviceGroup.equals(known)) { found = true; break; } } if (!found) { toAdd.add(serviceGroup); } } if (!toAdd.isEmpty()) { admin.addMemberGroups(toAdd.toArray(new String[0])); if (logger.isDebugEnabled()) { logger.debug("Added {} to ServiceRegistrar at {}:{}", toAdd, registrar.getLocator().getHost(), registrar.getLocator().getPort()); } } } catch (RemoteException e) { logger.warn("While trying to ensure groups", e); } } }
DeploymentVerifier { void ensureGroups(final ServiceElement serviceElement) throws IOException { if (serviceElement.getServiceBeanConfig().getGroups()==DiscoveryGroupManagement.ALL_GROUPS) { throw new IOException(String.format("Service %s has been declared for ALL_GROUPS", serviceElement.getName())); } for(ServiceRegistrar registrar : discoveryManagement.getRegistrars()) { try { List<String> toAdd = new ArrayList<>(); DiscoveryAdmin admin = (DiscoveryAdmin) ((Administrable)registrar).getAdmin(); String[] knownGroups = admin.getMemberGroups(); for(String serviceGroup : serviceElement.getServiceBeanConfig().getGroups()) { boolean found = false; for(String known : knownGroups) { if (serviceGroup.equals(known)) { found = true; break; } } if (!found) { toAdd.add(serviceGroup); } } if (!toAdd.isEmpty()) { admin.addMemberGroups(toAdd.toArray(new String[0])); if (logger.isDebugEnabled()) { logger.debug("Added {} to ServiceRegistrar at {}:{}", toAdd, registrar.getLocator().getHost(), registrar.getLocator().getPort()); } } } catch (RemoteException e) { logger.warn("While trying to ensure groups", e); } } } }
DeploymentVerifier { void ensureGroups(final ServiceElement serviceElement) throws IOException { if (serviceElement.getServiceBeanConfig().getGroups()==DiscoveryGroupManagement.ALL_GROUPS) { throw new IOException(String.format("Service %s has been declared for ALL_GROUPS", serviceElement.getName())); } for(ServiceRegistrar registrar : discoveryManagement.getRegistrars()) { try { List<String> toAdd = new ArrayList<>(); DiscoveryAdmin admin = (DiscoveryAdmin) ((Administrable)registrar).getAdmin(); String[] knownGroups = admin.getMemberGroups(); for(String serviceGroup : serviceElement.getServiceBeanConfig().getGroups()) { boolean found = false; for(String known : knownGroups) { if (serviceGroup.equals(known)) { found = true; break; } } if (!found) { toAdd.add(serviceGroup); } } if (!toAdd.isEmpty()) { admin.addMemberGroups(toAdd.toArray(new String[0])); if (logger.isDebugEnabled()) { logger.debug("Added {} to ServiceRegistrar at {}:{}", toAdd, registrar.getLocator().getHost(), registrar.getLocator().getPort()); } } } catch (RemoteException e) { logger.warn("While trying to ensure groups", e); } } } DeploymentVerifier(final Configuration config, final DiscoveryManagement discoveryManagement); }
DeploymentVerifier { void ensureGroups(final ServiceElement serviceElement) throws IOException { if (serviceElement.getServiceBeanConfig().getGroups()==DiscoveryGroupManagement.ALL_GROUPS) { throw new IOException(String.format("Service %s has been declared for ALL_GROUPS", serviceElement.getName())); } for(ServiceRegistrar registrar : discoveryManagement.getRegistrars()) { try { List<String> toAdd = new ArrayList<>(); DiscoveryAdmin admin = (DiscoveryAdmin) ((Administrable)registrar).getAdmin(); String[] knownGroups = admin.getMemberGroups(); for(String serviceGroup : serviceElement.getServiceBeanConfig().getGroups()) { boolean found = false; for(String known : knownGroups) { if (serviceGroup.equals(known)) { found = true; break; } } if (!found) { toAdd.add(serviceGroup); } } if (!toAdd.isEmpty()) { admin.addMemberGroups(toAdd.toArray(new String[0])); if (logger.isDebugEnabled()) { logger.debug("Added {} to ServiceRegistrar at {}:{}", toAdd, registrar.getLocator().getHost(), registrar.getLocator().getPort()); } } } catch (RemoteException e) { logger.warn("While trying to ensure groups", e); } } } DeploymentVerifier(final Configuration config, final DiscoveryManagement discoveryManagement); void verifyDeploymentRequest(final DeployRequest request); void verifyOperationalString(final OperationalString opString, final RemoteRepository[] repositories); void verifyOperationalStringService(final ServiceElement service,
                                               final Resolver resolver,
                                               final RemoteRepository[] repositories); }
DeploymentVerifier { void ensureGroups(final ServiceElement serviceElement) throws IOException { if (serviceElement.getServiceBeanConfig().getGroups()==DiscoveryGroupManagement.ALL_GROUPS) { throw new IOException(String.format("Service %s has been declared for ALL_GROUPS", serviceElement.getName())); } for(ServiceRegistrar registrar : discoveryManagement.getRegistrars()) { try { List<String> toAdd = new ArrayList<>(); DiscoveryAdmin admin = (DiscoveryAdmin) ((Administrable)registrar).getAdmin(); String[] knownGroups = admin.getMemberGroups(); for(String serviceGroup : serviceElement.getServiceBeanConfig().getGroups()) { boolean found = false; for(String known : knownGroups) { if (serviceGroup.equals(known)) { found = true; break; } } if (!found) { toAdd.add(serviceGroup); } } if (!toAdd.isEmpty()) { admin.addMemberGroups(toAdd.toArray(new String[0])); if (logger.isDebugEnabled()) { logger.debug("Added {} to ServiceRegistrar at {}:{}", toAdd, registrar.getLocator().getHost(), registrar.getLocator().getPort()); } } } catch (RemoteException e) { logger.warn("While trying to ensure groups", e); } } } DeploymentVerifier(final Configuration config, final DiscoveryManagement discoveryManagement); void verifyDeploymentRequest(final DeployRequest request); void verifyOperationalString(final OperationalString opString, final RemoteRepository[] repositories); void verifyOperationalStringService(final ServiceElement service,
                                               final Resolver resolver,
                                               final RemoteRepository[] repositories);  }