You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by gn...@apache.org on 2008/02/25 00:29:37 UTC
svn commit: r630705 - in /servicemix/smx4/nmr/trunk/jbi: deployer/
deployer/src/main/java/org/apache/servicemix/jbi/deployer/handler/
deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/
runtime/src/main/java/org/apache/servicemix/jbi/runtim...
Author: gnodet
Date: Sun Feb 24 15:29:34 2008
New Revision: 630705
URL: http://svn.apache.org/viewvc?rev=630705&view=rev
Log:
SMX4NMR-9: Reduce dynamicly imported packages
+ fix problems when deploying zips with no manifest at all
Modified:
servicemix/smx4/nmr/trunk/jbi/deployer/pom.xml
servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/handler/JBIDeploymentListener.java
servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/handler/Transformer.java
servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/Deployer.java
servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/ServiceAssemblyImpl.java
servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/ComponentContextImpl.java
Modified: servicemix/smx4/nmr/trunk/jbi/deployer/pom.xml
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/deployer/pom.xml?rev=630705&r1=630704&r2=630705&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/deployer/pom.xml (original)
+++ servicemix/smx4/nmr/trunk/jbi/deployer/pom.xml Sun Feb 24 15:29:34 2008
@@ -89,7 +89,6 @@
<Bundle-SymbolicName>${pom.artifactId}</Bundle-SymbolicName>
<Private-Package>org.apache.xbean*</Private-Package>
<Export-Package>${pom.artifactId}*</Export-Package>
- <DynamicImport-Package>*</DynamicImport-Package>
<Spring-Context>*;publish-context:=false;create-asynchronously:=false</Spring-Context>
</instructions>
</configuration>
Modified: servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/handler/JBIDeploymentListener.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/handler/JBIDeploymentListener.java?rev=630705&r1=630704&r2=630705&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/handler/JBIDeploymentListener.java (original)
+++ servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/handler/JBIDeploymentListener.java Sun Feb 24 15:29:34 2008
@@ -46,7 +46,8 @@
}
// Only handle non OSGi bundles
Manifest m = jar.getManifest();
- if (m.getMainAttributes().getValue(new Attributes.Name("Bundle-SymbolicName")) != null &&
+ if (m != null &&
+ m.getMainAttributes().getValue(new Attributes.Name("Bundle-SymbolicName")) != null &&
m.getMainAttributes().getValue(new Attributes.Name("Bundle-Version")) != null) {
return false;
}
Modified: servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/handler/Transformer.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/handler/Transformer.java?rev=630705&r1=630704&r2=630705&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/handler/Transformer.java (original)
+++ servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/handler/Transformer.java Sun Feb 24 15:29:34 2008
@@ -38,6 +38,10 @@
public static void transformToOSGiBundle(File jbiArtifact, File jbiBundle) throws Exception {
JarFile jar = new JarFile(jbiArtifact);
Manifest m = jar.getManifest();
+ if (m == null) {
+ m = new Manifest();
+ m.getMainAttributes().putValue("Manifest-Version", "1.0");
+ }
JarEntry jarEntry = jar.getJarEntry("META-INF/jbi.xml");
InputStream is = jar.getInputStream(jarEntry);
Descriptor desc = DescriptorFactory.buildDescriptor(is);
@@ -55,6 +59,7 @@
m.getMainAttributes().putValue("Bundle-SymbolicName", name);
m.getMainAttributes().putValue("Bundle-Version", version);
+ m.getMainAttributes().putValue("DynamicImport-Package", "javax.*,org.xml.*,org.w3c.*");
JarInputStream jis = new JarInputStream(new FileInputStream(jbiArtifact));
JarOutputStream jos = new JarOutputStream(new FileOutputStream(jbiBundle), m);
Modified: servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/Deployer.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/Deployer.java?rev=630705&r1=630704&r2=630705&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/Deployer.java (original)
+++ servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/Deployer.java Sun Feb 24 15:29:34 2008
@@ -17,9 +17,14 @@
package org.apache.servicemix.jbi.deployer.impl;
import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.Dictionary;
+import java.util.Enumeration;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
@@ -32,6 +37,7 @@
import org.apache.commons.logging.LogFactory;
import org.apache.servicemix.jbi.deployer.Component;
import org.apache.servicemix.jbi.deployer.ServiceAssembly;
+import org.apache.servicemix.jbi.deployer.ServiceUnit;
import org.apache.servicemix.jbi.deployer.SharedLibrary;
import org.apache.servicemix.jbi.deployer.descriptor.ComponentDesc;
import org.apache.servicemix.jbi.deployer.descriptor.Descriptor;
@@ -136,7 +142,7 @@
pendingBundles.add(e.getBundle());
LOGGER.warn("JBI artifact requirements not met. Installation pending.");
} catch (Exception e) {
- LOGGER.error("Error handling bundle event", e);
+ LOGGER.error("Error handling bundle start event", e);
} finally {
Thread.currentThread().setContextClassLoader(cl);
}
@@ -155,6 +161,19 @@
}
}
}
+ try {
+ URL url = bundle.getResource(JBI_DESCRIPTOR);
+ Descriptor descriptor = DescriptorFactory.buildDescriptor(url);
+ if (descriptor.getComponent() != null) {
+ uninstallComponent(descriptor.getComponent(), bundle);
+ } else if (descriptor.getServiceAssembly() != null) {
+ undeployServiceAssembly(descriptor.getServiceAssembly(), bundle);
+ } else if (descriptor.getSharedLibrary() != null) {
+ uninstallSharedLibrary(descriptor.getSharedLibrary(), bundle);
+ }
+ } catch (Exception e) {
+ LOGGER.error("Error handling bundle stop event", e);
+ }
}
protected void installComponent(ComponentDesc componentDesc, Bundle bundle) throws Exception {
@@ -167,17 +186,23 @@
}
}
}
+ String name = componentDesc.getIdentification().getName();
// Create component class loader
ClassLoader classLoader = createComponentClassLoader(componentDesc, bundle);
Thread.currentThread().setContextClassLoader(classLoader);
+ // Extract component (needed to feed the installRoot)
+ // Few components actually use this, but Ode is one of them
+ File installRoot = new File(System.getProperty("servicemix.base"), "data/jbi/" + name + "/install");
+ installRoot.mkdirs();
+ extractBundle(installRoot, bundle, "/");
// Instanciate component
- Preferences prefs = preferencesService.getUserPreferences(componentDesc.getIdentification().getName());
+ Preferences prefs = preferencesService.getUserPreferences(name);
Class clazz = classLoader.loadClass(componentDesc.getComponentClassName());
javax.jbi.component.Component innerComponent = (javax.jbi.component.Component) clazz.newInstance();
ComponentImpl component = new ComponentImpl(componentDesc, innerComponent, prefs, autoStart, this);
// populate props from the component meta-data
Dictionary<String, String> props = new Hashtable<String, String>();
- props.put(NAME, componentDesc.getIdentification().getName());
+ props.put(NAME, name);
props.put(TYPE, componentDesc.getType());
// register the component in the OSGi registry
LOGGER.debug("Registering JBI component");
@@ -185,6 +210,26 @@
registerService(bundle, javax.jbi.component.Component.class.getName(), component.getComponent(), props);
}
+ private void extractBundle(File installRoot, Bundle bundle, String path) throws IOException {
+ for (Enumeration e = bundle.getEntryPaths(path); e.hasMoreElements(); ) {
+ String entry = (String) e.nextElement();
+ File fout = new File(installRoot, entry);
+ if (entry.endsWith("/")) {
+ fout.mkdirs();
+ extractBundle(installRoot, bundle, entry);
+ } else {
+ InputStream in = bundle.getEntry(entry).openStream();
+ OutputStream out = new FileOutputStream(fout);
+ try {
+ FileUtil.copyInputStream(in, out);
+ } finally {
+ in.close();
+ out.close();
+ }
+ }
+ }
+ }
+
protected void deployServiceAssembly(ServiceAssemblyDesc serviceAssembyDesc, Bundle bundle) throws Exception {
LOGGER.debug("Bundle '" + OsgiStringUtils.nullSafeNameAndSymName(bundle) + "' is a JBI service assembly");
// Check requirements
@@ -204,6 +249,7 @@
FileUtil.buildDirectory(saDir);
// Iterate each SU and deploy it
List<ServiceUnitImpl> sus = new ArrayList<ServiceUnitImpl>();
+ boolean failure = false;
for (ServiceUnitDesc sud : serviceAssembyDesc.getServiceUnits()) {
// Create directory for this SU
File suRootDir = new File(saDir, sud.getIdentification().getName());
@@ -217,14 +263,34 @@
Component component = getComponent(componentName);
// Create service unit object
ServiceUnitImpl su = new ServiceUnitImpl(sud, suRootDir, component);
- su.deploy();
- // Add it to the list
- sus.add(su);
+ try {
+ LOGGER.debug("Deploying SU " + su.getName());
+ su.deploy();
+ // Add it to the list
+ sus.add(su);
+ } catch (Exception e) {
+ LOGGER.error("Error deploying SU " + su.getName(), e);
+ failure = true;
+ break;
+ }
+ }
+ // If failure, undeploy SU and exit
+ if (failure) {
+ for (ServiceUnitImpl su : sus) {
+ try {
+ LOGGER.debug("Undeploying SU " + su.getName());
+ su.undeploy();
+ } catch (Exception e) {
+ LOGGER.warn("Error undeploying SU " + su.getName(), e);
+ }
+ }
+ return;
}
// Now create the SA and initialize it
Preferences prefs = preferencesService.getUserPreferences(serviceAssembyDesc.getIdentification().getName());
ServiceAssemblyImpl sa = new ServiceAssemblyImpl(serviceAssembyDesc, sus, prefs, autoStart);
sa.init();
+ serviceAssemblies.put(sa.getName(), sa);
// populate props from the component meta-data
Dictionary<String, String> props = new Hashtable<String, String>();
props.put(NAME, serviceAssembyDesc.getIdentification().getName());
@@ -246,6 +312,28 @@
checkPendingBundles();
}
+ protected void uninstallComponent(ComponentDesc componentDesc, Bundle bundle) throws Exception {
+ String name = componentDesc.getIdentification().getName();
+ File file = new File(System.getProperty("servicemix.base"), "data/jbi/" + name);
+ FileUtil.deleteFile(file);
+ }
+ protected void undeployServiceAssembly(ServiceAssemblyDesc serviceAssembyDesc, Bundle bundle) throws Exception {
+ ServiceAssemblyImpl sa = serviceAssemblies.remove(serviceAssembyDesc.getIdentification().getName());
+ if (sa != null) {
+ if (sa.getState() == ServiceAssemblyImpl.State.Started) {
+ sa.stop();
+ }
+ if (sa.getState() == ServiceAssemblyImpl.State.Stopped) {
+ sa.shutDown();
+ }
+ for (ServiceUnit su : sa.getServiceUnits()) {
+ ((ServiceUnitImpl) su).undeploy();
+ }
+ }
+ }
+ protected void uninstallSharedLibrary(SharedLibraryDesc sharedLibraryDesc, Bundle bundle) throws JBIException {
+ }
+
protected synchronized void checkPendingBundles() {
if (!pendingBundles.isEmpty()) {
final List<Bundle> pending = pendingBundles;
@@ -277,7 +365,10 @@
String filter = "(" + NAME + "=" + name + ")";
BundleContext context = getBundleContext();
ServiceReference reference = OsgiServiceReferenceUtils.getServiceReference(context, Component.class.getName(), filter);
- return (Component) context.getService(reference);
+ if (reference != null) {
+ return (Component) context.getService(reference);
+ }
+ return null;
}
protected ClassLoader createComponentClassLoader(ComponentDesc component, Bundle bundle) {
Modified: servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/ServiceAssemblyImpl.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/ServiceAssemblyImpl.java?rev=630705&r1=630704&r2=630705&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/ServiceAssemblyImpl.java (original)
+++ servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/ServiceAssemblyImpl.java Sun Feb 24 15:29:34 2008
@@ -79,6 +79,10 @@
return serviceUnits.toArray(new ServiceUnit[serviceUnits.size()]);
}
+ public State getState() {
+ return state;
+ }
+
public String getCurrentState() {
switch (state) {
case Started:
Modified: servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/ComponentContextImpl.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/ComponentContextImpl.java?rev=630705&r1=630704&r2=630705&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/ComponentContextImpl.java (original)
+++ servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/ComponentContextImpl.java Sun Feb 24 15:29:34 2008
@@ -16,6 +16,7 @@
*/
package org.apache.servicemix.jbi.runtime.impl;
+import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
@@ -81,11 +82,12 @@
private Map<String,?> properties;
private BlockingQueue<Exchange> queue;
private DeliveryChannel dc;
- private List<EndpointImpl> endpoints;
private EndpointImpl componentEndpoint;
private String name;
private Environment environment;
private ManagementContext managementContext;
+ private File workspaceRoot;
+ private File installRoot;
public ComponentContextImpl(ComponentRegistryImpl componentRegistry,
Environment environment,
@@ -99,13 +101,16 @@
this.documentRepository = componentRegistry.getDocumentRepository();
this.component = component;
this.properties = properties;
- this.endpoints = new ArrayList<EndpointImpl>();
this.queue = new ArrayBlockingQueue<Exchange>(DEFAULT_QUEUE_CAPACITY);
this.componentEndpoint = new EndpointImpl();
this.componentEndpoint.setQueue(queue);
this.nmr.getEndpointRegistry().register(componentEndpoint, properties);
this.dc = new DeliveryChannelImpl(this, componentEndpoint.getChannel(), queue);
this.name = (String) properties.get(ComponentRegistry.NAME);
+ this.workspaceRoot = new File(System.getProperty("servicemix.base"), "data/jbi/" + name + "/workspace");
+ this.workspaceRoot.mkdirs();
+ this.installRoot = new File(System.getProperty("servicemix.base"), "data/jbi/" + name + "/install");
+ this.installRoot.mkdirs();
}
public NMR getNmr() {
@@ -136,9 +141,15 @@
}
public synchronized void deactivateEndpoint(ServiceEndpoint endpoint) throws JBIException {
- EndpointImpl ep = (EndpointImpl) endpoint;
+ EndpointImpl ep;
+ if (endpoint instanceof EndpointImpl) {
+ ep = (EndpointImpl) endpoint;
+ } else if (endpoint instanceof SimpleServiceEndpoint) {
+ ep = ((SimpleServiceEndpoint) endpoint).getEndpoint();
+ } else {
+ throw new IllegalArgumentException("Unrecognized endpoint");
+ }
nmr.getEndpointRegistry().unregister(ep, null);
- endpoints.remove(ep);
}
public void registerExternalEndpoint(ServiceEndpoint externalEndpoint) throws JBIException {
@@ -241,7 +252,7 @@
}
public String getInstallRoot() {
- return null; // TODO
+ return installRoot.getAbsolutePath();
}
public Logger getLogger(String suffix, String resourceBundleName) throws MissingResourceException, JBIException {
@@ -279,7 +290,7 @@
}
public String getWorkspaceRoot() {
- return null; // TODO
+ return workspaceRoot.getAbsolutePath();
}
public ObjectName createCustomComponentMBeanName(String customName) {