in bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/InstallBundleCommand.java [62:144]
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.setClusterManager(this.clusterManager);
support.setGroupManager(this.groupManager);
support.setConfigurationAdmin(this.configurationAdmin);
for (String url : urls) {
// check if the bundle is allowed
if (support.isAllowed(group, Constants.CATEGORY, url, EventType.OUTBOUND)) {
// get the name and version in the location MANIFEST
JarInputStream jarInputStream = new JarInputStream(new URL(url).openStream());
Manifest manifest = jarInputStream.getManifest();
if (manifest == null) {
System.err.println("Bundle location " + url + " doesn't seem correct");
continue;
}
String name = manifest.getMainAttributes().getValue("Bundle-Name");
String symbolicName = manifest.getMainAttributes().getValue("Bundle-SymbolicName");
if (name == null) {
name = symbolicName;
}
if (name == null) {
name = url;
}
String version = manifest.getMainAttributes().getValue("Bundle-Version");
jarInputStream.close();
ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
try {
// update the cluster group
Map<String, BundleState> clusterBundles = clusterManager.getMap(Constants.BUNDLE_MAP + Configurations.SEPARATOR + groupName);
BundleState state = new BundleState();
state.setName(name);
state.setSymbolicName(symbolicName);
state.setVersion(version);
state.setStartLevel(level);
state.setId(clusterBundles.size());
state.setLocation(url);
if (start) {
state.setStatus(Bundle.ACTIVE);
} else {
state.setStatus(Bundle.INSTALLED);
}
clusterBundles.put(symbolicName + "/" + version, state);
} finally {
Thread.currentThread().setContextClassLoader(originalClassLoader);
}
// broadcast the cluster event
ClusterBundleEvent event;
if (start) {
event = new ClusterBundleEvent(symbolicName, version, url, level, Bundle.ACTIVE);
event.setSourceGroup(group);
event.setSourceNode(clusterManager.getNode());
} else {
event = new ClusterBundleEvent(symbolicName, version, url, level, Bundle.INSTALLED);
event.setSourceGroup(group);
event.setSourceNode(clusterManager.getNode());
}
eventProducer.produce(event);
} else {
System.err.println("Bundle location " + url + " is blocked outbound for cluster group " + groupName);
}
}
return null;
}