in features/src/main/java/org/apache/karaf/cellar/features/shell/UninstallFeatureCommand.java [58:137]
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 for this node");
return null;
}
ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
try {
// get cluster features
Map<String, FeatureState> clusterFeatures = clusterManager.getMap(Constants.FEATURES_MAP + Configurations.SEPARATOR + groupName);
CellarSupport support = new CellarSupport();
support.setGroupManager(groupManager);
support.setClusterManager(clusterManager);
support.setConfigurationAdmin(configurationAdmin);
for (String feature : features) {
String[] split = feature.split("/");
String name = split[0];
String version = null;
if (split.length == 2) {
version = split[1];
}
FeatureState found = null;
String foundKey = null;
for (String k : clusterFeatures.keySet()) {
FeatureState f = clusterFeatures.get(k);
foundKey = k;
if (version == null) {
if (f.getName().equals(name)) {
found = f;
break;
}
} else {
if (f.getName().equals(name) && f.getVersion().equals(version)) {
found = f;
break;
}
}
}
if (found == null) {
if (version == null)
throw new IllegalArgumentException("Feature " + name + " doesn't exist in cluster group " + groupName);
else
throw new IllegalArgumentException("Feature " + name + "/" + version + " doesn't exist in cluster group " + groupName);
}
// check if the feature is allowed (outbound)
if (!support.isAllowed(group, Constants.CATEGORY, found.getName(), EventType.OUTBOUND)) {
System.err.println("Feature " + found.getName() + " is blocked outbound for cluster group " + groupName);
continue;
}
// update the cluster state
found.setInstalled(false);
clusterFeatures.put(foundKey, found);
// broadcast the cluster event
ClusterFeaturesEvent event = new ClusterFeaturesEvent(found.getName(), found.getVersion(), noRefresh, false, false, false, FeatureEvent.EventType.FeatureUninstalled);
event.setSourceGroup(group);
eventProducer.produce(event);
}
} finally {
Thread.currentThread().setContextClassLoader(originalClassLoader);
}
return null;
}