/** * Check if a configuration is allowed. * * @param group the cluster group. * @param category the configuration category constant. * @param pid the configuration PID. * @param type the cluster event type. * @return true if the cluster event type is allowed, false else. */ public boolean isAllowed(Group group, String category, String pid, EventType type) { CellarSupport support = new CellarSupport(); support.setClusterManager(this.clusterManager); support.setGroupManager(this.groupManager); support.setConfigurationAdmin(this.configurationAdmin); return support.isAllowed(group, category, pid, type); }
CellarSupport support = new CellarSupport(); support.setClusterManager(clusterManager); support.setGroupManager(groupManager); support.setConfigurationAdmin(configurationAdmin); if (whitelist) { System.out.print("\twhitelist: "); Set<String> list = support.getListEntries(Configurations.WHITELIST, groupName, Constants.CATEGORY, EventType.INBOUND); System.out.println(list.toString()); Set<String> list = support.getListEntries(Configurations.BLACKLIST, groupName, Constants.CATEGORY, EventType.INBOUND); System.out.println(list.toString()); if (whitelist) { System.out.print("\twhitelist: "); Set<String> list = support.getListEntries(Configurations.WHITELIST, groupName, Constants.CATEGORY, EventType.OUTBOUND); System.out.println(list.toString()); Set<String> list = support.getListEntries(Configurations.BLACKLIST, groupName, Constants.CATEGORY, EventType.OUTBOUND); System.out.println(list.toString()); if (whitelist) { System.out.println("\tinbound whitelist ..."); support.switchListEntry(Configurations.WHITELIST, groupName, Constants.CATEGORY, EventType.INBOUND, featurePattern); support.switchListEntry(Configurations.BLACKLIST, groupName, Constants.CATEGORY, EventType.INBOUND, featurePattern); if (whitelist) { System.out.println("\toutbound whitelist ...");
@Override public void block(String groupName, String pid, boolean whitelist, boolean blacklist, boolean in, boolean out) throws Exception { CellarSupport support = new CellarSupport(); support.setClusterManager(clusterManager); support.setGroupManager(groupManager); support.setConfigurationAdmin(configurationAdmin); if (in) { if (whitelist) support.switchListEntry(Configurations.WHITELIST, groupName, Constants.CATEGORY, EventType.INBOUND, pid); if (blacklist) support.switchListEntry(Configurations.BLACKLIST, groupName, Constants.CATEGORY, EventType.INBOUND, pid); } if (out) { if (whitelist) support.switchListEntry(Configurations.WHITELIST, groupName, Constants.CATEGORY, EventType.OUTBOUND, pid); if (blacklist) support.switchListEntry(Configurations.BLACKLIST, groupName, Constants.CATEGORY, EventType.OUTBOUND, pid); } }
Set<String> whiteList = getListEntries(Configurations.WHITELIST, group, category, type); Set<String> blackList = getListEntries(Configurations.BLACKLIST, group, category, type); result = false; for (String whiteListItem : whiteList) { if (wildCardMatch(event, whiteListItem)) result = true; if (wildCardMatch(event, blackListItem)) { return false;
/** * Get the resources in the Cellar cluster groups configuration. * * @param listType the comma separated string of resources. * @param groups the cluster groups names. * @param category the resource category name. * @param type the event type (inbound, outbound). * @return the set of resources. */ public Set<String> getListEntries(String listType, Collection<String> groups, String category, EventType type) { Set<String> result = null; if (groups != null && !groups.isEmpty()) { for (String group : groups) { Set<String> items = getListEntries(listType, group, category, type); if (items != null && !items.isEmpty()) { if (result == null) result = new HashSet<String>(); result.addAll(items); } } } return result; }
/** * Get the resources in the Cellar cluster groups configuration. * * @param listType the comma separated string of resources. * @param groups the cluster groups names. * @param category the resource category name. * @param type the event type (inbound, outbound). * @return the set of resources. */ public Set<String> getListEntries(String listType, Collection<String> groups, String category, EventType type) { Set<String> result = null; if (groups != null && !groups.isEmpty()) { for (String group : groups) { Set<String> items = getListEntries(listType, group, category, type); if (items != null && !items.isEmpty()) { if (result == null) result = new HashSet<String>(); result.addAll(items); } } } return result; }
Set<String> whiteList = getListEntries(Configurations.WHITELIST, group, category, type); Set<String> blackList = getListEntries(Configurations.BLACKLIST, group, category, type); result = false; for (String whiteListItem : whiteList) { if (wildCardMatch(event, whiteListItem)) result = true; if (wildCardMatch(event, blackListItem)) { return false;
/** * Check if a configuration is allowed. * * @param group the cluster group. * @param category the configuration category constant. * @param pid the configuration PID. * @param type the cluster event type. * @return true if the cluster event type is allowed, false else. */ public boolean isClusterConfigPIDAllowed(Group group, String category, String pid, EventType type) { CellarSupport support = new CellarSupport(); support.setClusterManager(this.karafCellarClusterManager); support.setGroupManager(this.karafCellarGroupManager); support.setConfigurationAdmin(this.osgiConfigurationAdmin); return support.isAllowed(group, category, pid, type); }
@Override public void block(String groupName, String pid, boolean whitelist, boolean blacklist, boolean in, boolean out) throws Exception { CellarSupport support = new CellarSupport(); support.setClusterManager(clusterManager); support.setGroupManager(groupManager); support.setConfigurationAdmin(configurationAdmin); if (in) { if (whitelist) support.switchListEntry(Configurations.WHITELIST, groupName, Constants.CATEGORY, EventType.INBOUND, pid); if (blacklist) support.switchListEntry(Configurations.BLACKLIST, groupName, Constants.CATEGORY, EventType.INBOUND, pid); } if (out) { if (whitelist) support.switchListEntry(Configurations.WHITELIST, groupName, Constants.CATEGORY, EventType.OUTBOUND, pid); if (blacklist) support.switchListEntry(Configurations.BLACKLIST, groupName, Constants.CATEGORY, EventType.OUTBOUND, pid); } }
/** * Get a set of resources in the Cellar cluster groups configuration. * * @param listType a comma separated string of resources. * @param group the cluster group. * @param category the resource category name. * @param type the event type (inbound, outbound). * @return the set of resources. */ public Set<String> getListEntries(String listType, Group group, String category, EventType type) { Set<String> result = null; if (group != null) { String groupName = group.getName(); Set<String> items = getListEntries(listType, groupName, category, type); if (items != null && !items.isEmpty()) { if (result == null) result = new HashSet<String>(); result.addAll(items); } } return result; }
/** * Check if a configuration is allowed. * * @param group the cluster group. * @param category the configuration category constant. * @param pid the configuration PID. * @param type the cluster event type. * @return true if the cluster event type is allowed, false else. */ public boolean isAllowed(Group group, String category, String pid, EventType type) { CellarSupport support = new CellarSupport(); support.setClusterManager(this.clusterManager); support.setGroupManager(this.groupManager); support.setConfigurationAdmin(this.configurationAdmin); return support.isAllowed(group, category, pid, type); }
@Override public void block(String groupName, String featurePattern, boolean whitelist, boolean blacklist, boolean in, boolean out) throws Exception { Group group = groupManager.findGroupByName(groupName); if (group == null) { throw new IllegalArgumentException("Cluster group " + groupName + " doesn't exist"); } CellarSupport support = new CellarSupport(); support.setClusterManager(clusterManager); support.setGroupManager(groupManager); support.setConfigurationAdmin(configurationAdmin); if (in) { if (whitelist) support.switchListEntry(Configurations.WHITELIST, groupName, Constants.CATEGORY, EventType.INBOUND, featurePattern); if (blacklist) support.switchListEntry(Configurations.BLACKLIST, groupName, Constants.CATEGORY, EventType.INBOUND, featurePattern); } if (out) { if (whitelist) support.switchListEntry(Configurations.WHITELIST, groupName, Constants.CATEGORY, EventType.OUTBOUND, featurePattern); if (blacklist) support.switchListEntry(Configurations.BLACKLIST, groupName, Constants.CATEGORY, EventType.OUTBOUND, featurePattern); } }
/** * Get a set of resources in the Cellar cluster groups configuration. * * @param listType a comma separated string of resources. * @param group the cluster group. * @param category the resource category name. * @param type the event type (inbound, outbound). * @return the set of resources. */ public Set<String> getListEntries(String listType, Group group, String category, EventType type) { Set<String> result = null; if (group != null) { String groupName = group.getName(); Set<String> items = getListEntries(listType, groupName, category, type); if (items != null && !items.isEmpty()) { if (result == null) result = new HashSet<String>(); result.addAll(items); } } return result; }
/** * Check if a configuration is allowed. * * @param group the cluster group. * @param category the configuration category constant. * @param pid the configuration PID. * @param type the cluster event type. * @return true if the cluster event type is allowed, false else. */ public boolean isClusterConfigPIDAllowed(Group group, String category, String pid, EventType type) { CellarSupport support = new CellarSupport(); support.setClusterManager(this.karafCellarClusterManager); support.setGroupManager(this.karafCellarGroupManager); support.setConfigurationAdmin(this.osgiConfigurationAdmin); return support.isAllowed(group, category, pid, type); }
@Override public void block(String groupName, String featurePattern, boolean whitelist, boolean blacklist, boolean in, boolean out) throws Exception { Group group = groupManager.findGroupByName(groupName); if (group == null) { throw new IllegalArgumentException("Cluster group " + groupName + " doesn't exist"); } CellarSupport support = new CellarSupport(); support.setClusterManager(clusterManager); support.setGroupManager(groupManager); support.setConfigurationAdmin(configurationAdmin); if (in) { if (whitelist) support.switchListEntry(Configurations.WHITELIST, groupName, Constants.CATEGORY, EventType.INBOUND, featurePattern); if (blacklist) support.switchListEntry(Configurations.BLACKLIST, groupName, Constants.CATEGORY, EventType.INBOUND, featurePattern); } if (out) { if (whitelist) support.switchListEntry(Configurations.WHITELIST, groupName, Constants.CATEGORY, EventType.OUTBOUND, featurePattern); if (blacklist) support.switchListEntry(Configurations.BLACKLIST, groupName, Constants.CATEGORY, EventType.OUTBOUND, featurePattern); } }
String parent = (String) dictionary.get(group + Configurations.SEPARATOR + Configurations.PARENT); if (parent != null) { result = getListEntries(listType, parent, category, type);
/** * Check if an OBR cluster event is allowed. * * @param group the cluster group. * @param category the OBR category name. * @param id the event ID. * @param type the event type (inbound, outbound). * @return in case of check failure. */ public boolean isAllowed(Group group, String category, String id, EventType type) { CellarSupport support = new CellarSupport(); support.setClusterManager(this.clusterManager); support.setGroupManager(this.groupManager); support.setConfigurationAdmin(this.configurationAdmin); return support.isAllowed(group, category, id, type); }
@Override public void block(String groupName, String bundlePattern, boolean whitelist, boolean blacklist, boolean in, boolean out) throws Exception { List<String> patterns = new ArrayList<String>(); Map<String, ExtendedBundleState> bundles = gatherBundles(groupName); List<String> selectedBundles = selector(bundlePattern, bundles); for (String selectedBundle : selectedBundles) { patterns.add(bundles.get(selectedBundle).getLocation()); } if (patterns.isEmpty()) { patterns.add(bundlePattern); } CellarSupport support = new CellarSupport(); support.setClusterManager(clusterManager); support.setGroupManager(groupManager); support.setConfigurationAdmin(configurationAdmin); for (String pattern : patterns) { if (in) { if (whitelist) support.switchListEntry(Configurations.WHITELIST, groupName, Constants.CATEGORY, EventType.INBOUND, pattern); if (blacklist) support.switchListEntry(Configurations.BLACKLIST, groupName, Constants.CATEGORY, EventType.INBOUND, pattern); } if (out) { if (whitelist) support.switchListEntry(Configurations.WHITELIST, groupName, Constants.CATEGORY, EventType.OUTBOUND, pattern); if (blacklist) support.switchListEntry(Configurations.BLACKLIST, groupName, Constants.CATEGORY, EventType.OUTBOUND, pattern); } } }
String parent = (String) dictionary.get(group + Configurations.SEPARATOR + Configurations.PARENT); if (parent != null) { result = getListEntries(listType, parent, category, type);
@Override protected Object doExecute() throws Exception { // check if the group exists Group group = groupManager.findGroupByName(groupName); if (group == null) { System.err.println("Cluster group " + groupName + " doesn't exist"); return null; } // check if the producer is ON if (eventProducer.getSwitch().getStatus().equals(SwitchStatus.OFF)) { System.err.println("Cluster event producer is OFF"); return null; } CellarSupport support = new CellarSupport(); support.setConfigurationAdmin(configurationAdmin); support.setGroupManager(groupManager); support.setClusterManager(clusterManager); // check if the kar is allowed if (support.isAllowed(group, Constants.CATEGORY, url, EventType.OUTBOUND)) { // broadcast cluster event ClusterKarEvent clusterEvent = new ClusterKarEvent(url, true); clusterEvent.setSourceGroup(group); clusterEvent.setInstall(true); eventProducer.produce(clusterEvent); } else { System.err.println("KAR " + url + " is blocked outbound for cluster group " + groupName); } return null; }