in bundle/src/main/java/org/apache/karaf/cellar/bundle/management/internal/CellarBundleMBeanImpl.java [104:174]
public void install(String groupName, String location, Integer level, boolean start) throws Exception {
// check if cluster group exists
Group group = groupManager.findGroupByName(groupName);
if (group == null) {
throw new IllegalArgumentException("Cluster group " + groupName + " doesn't exist");
}
// check if the producer is ON
if (eventProducer.getSwitch().getStatus().equals(SwitchStatus.OFF)) {
throw new IllegalStateException("Cluster event producer is OFF for this node");
}
// check if the bundle location is allowed
CellarSupport support = new CellarSupport();
support.setClusterManager(this.clusterManager);
support.setGroupManager(this.groupManager);
support.setConfigurationAdmin(this.configurationAdmin);
if (!support.isAllowed(group, Constants.CATEGORY, location, EventType.OUTBOUND)) {
throw new IllegalArgumentException("Bundle location " + location + " is blocked outbound for cluster group " + groupName);
}
// get the name and version in the location MANIFEST
JarInputStream jarInputStream = new JarInputStream(new URL(location).openStream());
Manifest manifest = jarInputStream.getManifest();
if (manifest == null) {
throw new IllegalArgumentException("Bundle location " + location + " doesn't seem correct");
}
String name = manifest.getMainAttributes().getValue("Bundle-Name");
String symbolicName = manifest.getMainAttributes().getValue("Bundle-SymbolicName");
if (name == null) {
name = symbolicName;
}
if (name == null) {
name = location;
}
String version = manifest.getMainAttributes().getValue("Bundle-Version");
jarInputStream.close();
ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
// 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.setId(clusterBundles.size());
state.setStartLevel(level);
state.setLocation(location);
if (start) {
state.setStatus(Bundle.ACTIVE);
} else {
state.setStatus(Bundle.INSTALLED);
}
clusterBundles.put(symbolicName + "/" + version, state);
} finally {
Thread.currentThread().setContextClassLoader(originalClassLoader);
}
// broadcast the event
ClusterBundleEvent event = new ClusterBundleEvent(symbolicName, version, location, level, Bundle.INSTALLED);
event.setSourceGroup(group);
event.setSourceNode(clusterManager.getNode());
if (start) {
event = new ClusterBundleEvent(symbolicName, version, location, level, Bundle.ACTIVE);
event.setSourceGroup(group);
event.setSourceNode(clusterManager.getNode());
}
eventProducer.produce(event);
}