Author: ffang
Date: Sun Feb  8 12:42:48 2009
New Revision: 742074

URL: http://svn.apache.org/viewvc?rev=742074&view=rev
Log:
[SMX4NMR]make MBean working for deploy/undeploy/stop/start/shutdown/list 
ServiceAssembly

Added:
    
servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/ServiceAssemblyInstaller.java
   (with props)
Modified:
    
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/impl/Deployer.java
    
servicemix/smx4/nmr/trunk/jbi/deployer/src/main/resources/META-INF/spring/servicemix-jbi-deployer.xml
    
servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/AdminCommandsService.java
    
servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/AdminService.java
    
servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/DeploymentService.java
    
servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/InstallationService.java
    
servicemix/smx4/nmr/trunk/jbi/management/src/main/resources/META-INF/spring/servicemix-jbi-management.xml

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=742074&r1=742073&r2=742074&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  8 12:42:48 2009
@@ -25,6 +25,7 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.servicemix.jbi.deployer.descriptor.DescriptorFactory;
+import org.apache.servicemix.jbi.deployer.impl.Deployer;
 import org.apache.servicemix.kernel.filemonitor.DeploymentListener;
 
 /**
@@ -35,6 +36,8 @@
 public class JBIDeploymentListener implements DeploymentListener {
        
        private static final Log Logger = 
LogFactory.getLog(JBIDeploymentListener.class);
+       
+       private Deployer deployer;
 
     /**
      * Check if the file is a recognized JBI artifact that needs to be
@@ -96,4 +99,15 @@
        }
 
 
+       public void setDeployer(Deployer deployer) {
+               this.deployer = deployer;
+       }
+
+
+       public Deployer getDeployer() {
+               return deployer;
+       }
+
+    
+
 }

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=742074&r1=742073&r2=742074&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  8 12:42:48 2009
@@ -28,6 +28,7 @@
 import java.util.Hashtable;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
 
 import javax.jbi.JBIException;
@@ -562,5 +563,17 @@
             LOGGER.error("Error unregistering deployed service assembly", e);
         }
     }
+    
+    public Set<String> getInstalledComponents() {
+       return this.components.keySet();
+    }
+    
+    public Set<String> getInstalledSharedLibararies() {
+       return this.sharedLibraries.keySet();
+    }
+    
+    public Set<String> getDeployServiceAssemblies() {
+       return this.serviceAssemblies.keySet();
+    }
 
 }

Modified: 
servicemix/smx4/nmr/trunk/jbi/deployer/src/main/resources/META-INF/spring/servicemix-jbi-deployer.xml
URL: 
http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/deployer/src/main/resources/META-INF/spring/servicemix-jbi-deployer.xml?rev=742074&r1=742073&r2=742074&view=diff
==============================================================================
--- 
servicemix/smx4/nmr/trunk/jbi/deployer/src/main/resources/META-INF/spring/servicemix-jbi-deployer.xml
 (original)
+++ 
servicemix/smx4/nmr/trunk/jbi/deployer/src/main/resources/META-INF/spring/servicemix-jbi-deployer.xml
 Sun Feb  8 12:42:48 2009
@@ -40,7 +40,9 @@
     <bean id="endpointListener" 
class="org.apache.servicemix.jbi.deployer.impl.AssemblyReferencesListener" />
 
     <!-- Deployment listener -->
-    <bean id="listener" 
class="org.apache.servicemix.jbi.deployer.handler.JBIDeploymentListener" />
+    <bean id="listener" 
class="org.apache.servicemix.jbi.deployer.handler.JBIDeploymentListener">
+        <property name="deployer" ref="deployer" />
+    </bean>
     
     <!-- JBI Handler -->
     <bean id="jbiHandler" 
class="org.apache.servicemix.jbi.deployer.handler.URLHandler" />

Modified: 
servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/AdminCommandsService.java
URL: 
http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/AdminCommandsService.java?rev=742074&r1=742073&r2=742074&view=diff
==============================================================================
--- 
servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/AdminCommandsService.java
 (original)
+++ 
servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/AdminCommandsService.java
 Sun Feb  8 12:42:48 2009
@@ -30,6 +30,8 @@
 
 
 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.descriptor.SharedLibraryList;
 import org.apache.servicemix.jbi.deployer.impl.ComponentImpl;
 import org.apache.servicemix.jbi.deployer.impl.Deployer;
@@ -38,6 +40,8 @@
 import org.osgi.framework.ServiceReference;
 import org.springframework.osgi.context.BundleContextAware;
 
+import com.sun.org.apache.bcel.internal.generic.GETSTATIC;
+
 public class AdminCommandsService implements AdminCommandsServiceMBean, 
BundleContextAware {
 
        
@@ -134,7 +138,11 @@
         * @return
         */
     public String installSharedLibrary(String file) throws Exception {
-       return installationService.installSharedLibrary(file);
+       try {
+               return installationService.installSharedLibrary(file);
+       } catch (Exception e) {
+            throw ManagementSupport.failure("installSharedLibrary", file, e);
+        }
     }
 
     /**
@@ -145,7 +153,7 @@
      */
     public String uninstallSharedLibrary(String name) throws Exception {
        //Check that the library is installed
-        boolean isInstalled = 
getInstallationService().containsSharedLibrary(name);
+        boolean isInstalled = 
getAdminService().getDeployer().getInstalledSharedLibararies().contains(name);
         if (!isInstalled) {
             throw ManagementSupport.failure("uninstallSharedLibrary", "Shared 
library '" + name + "' is not installed.");
         }
@@ -239,13 +247,12 @@
      * @return
      */
     public String deployServiceAssembly(String file) throws Exception {
-       return null;
-        /*if (deferException) {
-            container.updateExternalArchive(file);
-            return 
ManagementSupport.createSuccessMessage("deployServiceAssembly", file);
-        } else {
-            return deploymentService.deploy(file);
-        }*/
+       try {
+               return deploymentService.deploy(file);
+       } catch (Exception e) {
+            throw ManagementSupport.failure("deployServiceAssembly", file, e);
+        }
+
     }
 
     /**
@@ -396,7 +403,7 @@
     public String listSharedLibraries(String componentName, String 
sharedLibraryName) throws Exception {
        Set<String> libs = new HashSet<String>();
         if (sharedLibraryName != null && sharedLibraryName.length() > 0) {
-               if 
(getInstallationService().containsSharedLibrary(sharedLibraryName)) {
+               if 
(getAdminService().getDeployer().getInstalledSharedLibararies().contains(sharedLibraryName))
 {
                 libs.add(sharedLibraryName);
             }
         } else if (componentName != null && componentName.length() > 0) {
@@ -409,7 +416,7 @@
                libs.add(sl.getName());
             }
         } else {
-            libs = getInstallationService().getInstalledSharedLibs();
+            libs = 
getAdminService().getDeployer().getInstalledSharedLibararies();
         }
         StringBuffer buffer = new StringBuffer();
         buffer.append("<?xml version='1.0'?>\n");
@@ -431,7 +438,59 @@
      * @return
      */
     public String listServiceAssemblies(String state, String componentName, 
String serviceAssemblyName) throws Exception {
-       return ManagementSupport.createSuccessMessage("to be done");
+       String[] result = null;
+        if (null != serviceAssemblyName && serviceAssemblyName.length() > 0) {
+            result = new String[] {serviceAssemblyName };
+        } else if (null != componentName && componentName.length() > 0) {
+            result = getDeployedServiceAssembliesForComponent(componentName);
+        } else {
+               ServiceReference[] serviceRefs = 
getAdminService().getSAServiceReferences(null);
+               result = new String[serviceRefs.length];
+               int i = 0;
+               for (ServiceReference ref : serviceRefs) {
+               ServiceAssembly sa = (ServiceAssembly) 
getBundleContext().getService(ref);
+               result[i] = sa.getName();
+               i++;
+               }
+        }
+
+        List<ServiceAssemblyImpl> assemblies = new 
ArrayList<ServiceAssemblyImpl>();
+        for (int i = 0; i < result.length; i++) {
+               ServiceReference ref = 
getAdminService().getSAServiceReference("(" + Deployer.NAME + "=" + result[i] + 
")");
+               ServiceAssemblyImpl sa = (ServiceAssemblyImpl) 
getBundleContext().getService(ref);
+            if (sa != null) {
+                // Check status
+                if (state != null && state.length() > 0 && 
!state.equals(sa.getCurrentState())) {
+                    continue;
+                }
+                assemblies.add(sa);
+            }
+        }
+
+        StringBuffer buffer = new StringBuffer();
+        buffer.append("<?xml version='1.0'?>\n");
+        buffer.append("<service-assembly-info-list 
xmlns='http://java.sun.com/xml/ns/jbi/service-assembly-info-list' 
version='1.0'>\n");
+        for (Iterator<ServiceAssemblyImpl> iter = assemblies.iterator(); 
iter.hasNext();) {
+               ServiceAssemblyImpl sa = iter.next();
+            buffer.append("  <service-assembly-info");
+            buffer.append(" name='" + sa.getName() + "'");
+            buffer.append(" state='" + sa.getCurrentState() + "'>\n");
+            buffer.append("    <description>" + sa.getDescription() + 
"</description>\n");
+
+            ServiceUnit[] serviceUnitList = sa.getServiceUnits();
+            for (int i = 0; i < serviceUnitList.length; i++) {
+                buffer.append("    <service-unit-info");
+                buffer.append(" name='" + serviceUnitList[i].getName() + "'");
+                buffer.append(" deployed-on='" + 
serviceUnitList[i].getComponent().getName() + "'>\n");
+                buffer.append("      <description>" + 
serviceUnitList[i].getDescription() + "</description>\n");
+                buffer.append("    </service-unit-info>\n");
+            }
+
+            buffer.append("  </service-assembly-info>\n");
+        }
+        buffer.append("</service-assembly-info-list>");
+
+        return buffer.toString();
     }
 
        public void setBundleContext(BundleContext bundleContext) {
@@ -464,5 +523,31 @@
        public AdminService getAdminService() {
                return adminService;
        }
-
+       
+       /**
+     * Returns a list of Service Assemblies that contain SUs for the given 
component.
+     * 
+     * @param componentName name of the component.
+     * @return list of Service Assembly names.
+     */
+    public String[] getDeployedServiceAssembliesForComponent(String 
componentName) {
+        String[] result = null;
+        // iterate through the service assembiliessalc
+        Set<String> tmpList = new HashSet<String>();
+        ServiceReference[] serviceRefs = 
getAdminService().getSAServiceReferences(null);
+        for (ServiceReference ref : serviceRefs) {
+               ServiceAssembly sa = (ServiceAssembly) 
getBundleContext().getService(ref);
+            ServiceUnit[] sus = sa.getServiceUnits();
+            if (sus != null) {
+                for (int i = 0; i < sus.length; i++) {
+                    if (sus[i].getComponent().getName().equals(componentName)) 
{
+                        tmpList.add(sa.getName());
+                    }
+                }
+            }
+        }
+        result = new String[tmpList.size()];
+        tmpList.toArray(result);
+        return result;
+    }
 }

Modified: 
servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/AdminService.java
URL: 
http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/AdminService.java?rev=742074&r1=742073&r2=742074&view=diff
==============================================================================
--- 
servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/AdminService.java
 (original)
+++ 
servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/AdminService.java
 Sun Feb  8 12:42:48 2009
@@ -19,8 +19,10 @@
 import javax.jbi.management.AdminServiceMBean;
 import javax.management.ObjectName;
 
+import org.apache.servicemix.jbi.deployer.handler.JBIDeploymentListener;
 import org.apache.servicemix.jbi.deployer.impl.Deployer;
 import org.osgi.framework.BundleContext;
+import org.osgi.framework.InvalidSyntaxException;
 import org.osgi.framework.ServiceReference;
 import org.springframework.osgi.context.BundleContextAware;
 import org.springframework.osgi.util.OsgiServiceReferenceUtils;
@@ -60,7 +62,28 @@
                         
org.apache.servicemix.jbi.deployer.Component.class.getName(),
                         filter);
     }
+    
+    protected ServiceReference getSLServiceReference(String filter) {
+        return OsgiServiceReferenceUtils.getServiceReference(
+                        getBundleContext(),
+                        
org.apache.servicemix.jbi.deployer.SharedLibrary.class.getName(),
+                        filter);
+    }
 
+    protected ServiceReference getSAServiceReference(String filter) {
+        return OsgiServiceReferenceUtils.getServiceReference(
+                        getBundleContext(),
+                        
org.apache.servicemix.jbi.deployer.ServiceAssembly.class.getName(),
+                        filter);
+    }
+    
+    protected ServiceReference[] getSAServiceReferences(String filter) {
+        return OsgiServiceReferenceUtils.getServiceReferences(
+                        getBundleContext(),
+                        
org.apache.servicemix.jbi.deployer.ServiceAssembly.class.getName(),
+                        filter);
+    }
+    
     protected ServiceReference[] getComponentServiceReferences(String filter) {
         return OsgiServiceReferenceUtils.getServiceReferences(
                         getBundleContext(),
@@ -117,4 +140,12 @@
         ServiceReference ref = getComponentServiceReference(filter);
         return "service-engine".equals(ref.getProperty(Deployer.TYPE));
     }
+    
+    public Deployer getDeployer() throws InvalidSyntaxException {
+       ServiceReference ref = OsgiServiceReferenceUtils.getServiceReference(
+                getBundleContext(),
+                JBIDeploymentListener.class.getName(),
+                null);
+       return (Deployer) 
((JBIDeploymentListener)getBundleContext().getService(ref)).getDeployer();
+       }
 }

Modified: 
servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/DeploymentService.java
URL: 
http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/DeploymentService.java?rev=742074&r1=742073&r2=742074&view=diff
==============================================================================
--- 
servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/DeploymentService.java
 (original)
+++ 
servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/DeploymentService.java
 Sun Feb  8 12:42:48 2009
@@ -16,59 +16,256 @@
  */
 package org.apache.servicemix.jbi.management;
 
+import java.io.File;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import javax.jbi.JBIException;
 import javax.jbi.management.DeploymentServiceMBean;
+import javax.jbi.management.LifeCycleMBean;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.servicemix.jbi.deployer.Component;
+import org.apache.servicemix.jbi.deployer.descriptor.Descriptor;
+import org.apache.servicemix.jbi.deployer.descriptor.ServiceAssemblyDesc;
+import org.apache.servicemix.jbi.deployer.descriptor.ServiceUnitDesc;
+import org.apache.servicemix.jbi.deployer.handler.Transformer;
+import org.apache.servicemix.jbi.deployer.impl.ComponentImpl;
+import org.apache.servicemix.jbi.deployer.impl.Deployer;
+import org.apache.servicemix.jbi.deployer.impl.ServiceAssemblyImpl;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.ServiceReference;
 
 public class DeploymentService implements DeploymentServiceMBean {
+       
+       private static final Log LOG = 
LogFactory.getLog(DeploymentService.class);
+       private AdminService adminService;
+       
+       private Map<String, ServiceAssemblyInstaller> serviceAssemblyInstallers 
= new ConcurrentHashMap<String, ServiceAssemblyInstaller>();
 
     public String deploy(String saZipURL) throws Exception {
-        return null;  //To change body of implemented methods use File | 
Settings | File Templates.
-    }
-
-    public String undeploy(String saName) throws Exception {
-        return null;  //To change body of implemented methods use File | 
Settings | File Templates.
+       try {
+            if (saZipURL == null) {
+                throw ManagementSupport.failure("deploy", "saZipURL must not 
be null");
+            }
+            File jarfile = new File(saZipURL);
+            if (jarfile.exists()) {
+               Descriptor root = null;
+                try {
+                    root = Transformer.getDescriptor(jarfile);
+                } catch (Exception e) {
+                    throw ManagementSupport.failure("deploy", "Unable to build 
jbi descriptor: " + saZipURL, e);
+                }
+                if (root == null) {
+                    throw ManagementSupport.failure("deploy", "Unable to find 
jbi descriptor: " + saZipURL);
+                }
+                ServiceAssemblyDesc sa = root.getServiceAssembly();
+                if (sa == null) {
+                    throw ManagementSupport.failure("deploy", "JBI descriptor 
is not an assembly descriptor: " + saZipURL);
+                }
+                return deployServiceAssembly(saZipURL, sa);
+            } else {
+                throw new RuntimeException("location for deployment SA: " + 
saZipURL + " isn't valid");
+            }
+            
+       } catch (Exception e) {
+            LOG.error("Error deploying service assembly", e);
+            throw e;
+        }
+    }
+
+    private String deployServiceAssembly(String saZipURL, ServiceAssemblyDesc 
sa) throws Exception {
+       String assemblyName = sa.getIdentification().getName();
+               
+        // Check all SUs requirements
+        ServiceUnitDesc[] sus = sa.getServiceUnits();
+        if (sus != null) {
+            checkSus(sus);
+        }
+        LOG.info("Deploy ServiceAssembly " + assemblyName);
+        ServiceAssemblyInstaller saInstaller;
+        if (serviceAssemblyInstallers.containsKey(assemblyName)) {
+            saInstaller = serviceAssemblyInstallers.get(assemblyName);
+        } else {
+               saInstaller = new ServiceAssemblyInstaller(assemblyName, 
this.getAdminService());
+        }
+        saInstaller.deploy(saZipURL);
+        serviceAssemblyInstallers.put(assemblyName, saInstaller);
+        return ManagementSupport.createSuccessMessage("deploy SA", 
assemblyName);
+    }
+
+       private void checkSus(ServiceUnitDesc[] sus) throws Exception {
+               for (int i = 0; i < sus.length; i++) {
+            String suName = sus[i].getIdentification().getName();
+            String componentName = sus[i].getTarget().getComponentName();
+            ComponentImpl componentImpl = (ComponentImpl) 
getComponentByName(componentName);
+            if (componentImpl == null) {
+                throw ManagementSupport.failure("deploy", "Target component " 
+ componentName
+                                                            + " for service 
unit " + suName + " is not installed");
+            }
+            if 
(!componentImpl.getCurrentState().equals(LifeCycleMBean.STARTED)) {
+                throw ManagementSupport.failure("deploy", "Target component " 
+ componentName
+                                                            + " for service 
unit " + suName + " is not started");
+            }
+            if (componentImpl.getComponent().getServiceUnitManager() == null) {
+                throw ManagementSupport.failure("deploy", "Target component " 
+ componentName
+                                                            + " for service 
unit " + suName + " does not accept deployments");
+            }
+
+            if (isDeployedServiceUnit(componentName, suName)) {
+                throw ManagementSupport.failure("deploy", "Service unit " + 
suName
+                                                            + " is already 
deployed on component " + componentName);
+            }
+        }              
+       }
+
+       private Component getComponentByName(String name) throws Exception {
+               ServiceReference ref = 
getAdminService().getComponentServiceReference("(" + Deployer.NAME + "=" + name 
+ ")");
+        if (ref == null) {
+            throw new JBIException("Component '" + name + "' not found");
+        }
+        Component component = (Component) 
getAdminService().getBundleContext().getService(ref);
+        return component;
+       }
+       
+       public String undeploy(String saName) throws Exception {
+               if (saName == null) {
+            throw ManagementSupport.failure("undeploy", "SA name must not be 
null");
+        }
+               ServiceReference ref = 
getAdminService().getSAServiceReference("(" + Deployer.NAME + "=" + saName + 
")");
+               if (ref == null) {
+            throw ManagementSupport.failure("undeploy", "SA has not been 
deployed: " + saName);
+        }
+        Bundle bundle = ref.getBundle();
+        ServiceAssemblyImpl sa = (ServiceAssemblyImpl) 
getAdminService().getBundleContext().getService(ref);
+        
+        
+        String state = sa.getCurrentState();
+        if (!LifeCycleMBean.SHUTDOWN.equals(state)) {
+            throw ManagementSupport.failure("undeploy", "SA must be shut down: 
" + saName);
+        }
+        try {
+            if (bundle != null) {
+               bundle.stop();
+               bundle.uninstall();
+               return ManagementSupport.createSuccessMessage("undeploy service 
assembly successfully", saName);
+            }
+
+        } catch (Exception e) {
+            LOG.info("Unable to undeploy assembly", e);
+            throw e;
+        }
+        return "failed to undeploy service assembly" + saName;
     }
 
     public String[] getDeployedServiceUnitList(String componentName) throws 
Exception {
-        return new String[0];  //To change body of implemented methods use 
File | Settings | File Templates.
+        return new String[0]; 
     }
 
     public String[] getDeployedServiceAssemblies() throws Exception {
-        return new String[0];  //To change body of implemented methods use 
File | Settings | File Templates.
+        return new String[0];
     }
 
     public String getServiceAssemblyDescriptor(String saName) throws Exception 
{
-        return null;  //To change body of implemented methods use File | 
Settings | File Templates.
+        return null;
     }
 
     public String[] getDeployedServiceAssembliesForComponent(String 
componentName) throws Exception {
-        return new String[0];  //To change body of implemented methods use 
File | Settings | File Templates.
+        return new String[0];
     }
 
     public String[] getComponentsForDeployedServiceAssembly(String saName) 
throws Exception {
-        return new String[0];  //To change body of implemented methods use 
File | Settings | File Templates.
+        return new String[0];
     }
 
     public boolean isDeployedServiceUnit(String componentName, String suName) 
throws Exception {
-        return false;  //To change body of implemented methods use File | 
Settings | File Templates.
+        return false;
     }
 
     public boolean canDeployToComponent(String componentName) {
-        return false;  //To change body of implemented methods use File | 
Settings | File Templates.
+        return false;
     }
 
     public String start(String serviceAssemblyName) throws Exception {
-        return null;  //To change body of implemented methods use File | 
Settings | File Templates.
+       try {
+               if (serviceAssemblyName == null) {
+                throw ManagementSupport.failure("start", "SA name must not be 
null");
+            }
+               ServiceReference ref = 
getAdminService().getSAServiceReference("(" + Deployer.NAME + "=" + 
serviceAssemblyName + ")");
+               if (ref == null) {
+                throw ManagementSupport.failure("start", "SA has not exist: " 
+ serviceAssemblyName);
+            }
+               ServiceAssemblyImpl sa = (ServiceAssemblyImpl) 
getAdminService().getBundleContext().getService(ref);
+               sa.start();
+               return ManagementSupport.createSuccessMessage("start service 
assembly successfully", serviceAssemblyName);
+        } catch (Exception e) {
+            LOG.info("Error in start", e);
+            throw e;
+        }
     }
 
     public String stop(String serviceAssemblyName) throws Exception {
-        return null;  //To change body of implemented methods use File | 
Settings | File Templates.
+       try {
+               if (serviceAssemblyName == null) {
+                throw ManagementSupport.failure("stop", "SA name must not be 
null");
+            }
+               ServiceReference ref = 
getAdminService().getSAServiceReference("(" + Deployer.NAME + "=" + 
serviceAssemblyName + ")");
+               if (ref == null) {
+                throw ManagementSupport.failure("stop", "SA has not exist: " + 
serviceAssemblyName);
+            }
+               ServiceAssemblyImpl sa = (ServiceAssemblyImpl) 
getAdminService().getBundleContext().getService(ref);
+               sa.stop();
+               return ManagementSupport.createSuccessMessage("stop service 
assembly successfully", serviceAssemblyName);
+        } catch (Exception e) {
+            LOG.info("Error in stop", e);
+            throw e;
+        }
     }
 
     public String shutDown(String serviceAssemblyName) throws Exception {
-        return null;  //To change body of implemented methods use File | 
Settings | File Templates.
+       try {
+               if (serviceAssemblyName == null) {
+                throw ManagementSupport.failure("shutdown", "SA name must not 
be null");
+            }
+               ServiceReference ref = 
getAdminService().getSAServiceReference("(" + Deployer.NAME + "=" + 
serviceAssemblyName + ")");
+               if (ref == null) {
+                throw ManagementSupport.failure("shutdown", "SA has not exist: 
" + serviceAssemblyName);
+            }
+               ServiceAssemblyImpl sa = (ServiceAssemblyImpl) 
getAdminService().getBundleContext().getService(ref);
+               sa.shutDown();
+               return ManagementSupport.createSuccessMessage("shutdown service 
assembly successfully", serviceAssemblyName);
+        } catch (Exception e) {
+            LOG.info("Error in shutdown", e);
+            throw e;
+        }
     }
 
     public String getState(String serviceAssemblyName) throws Exception {
-        return null;  //To change body of implemented methods use File | 
Settings | File Templates.
-    }
+       try {
+               if (serviceAssemblyName == null) {
+                throw ManagementSupport.failure("getState", "SA name must not 
be null");
+            }
+               ServiceReference ref = 
getAdminService().getSAServiceReference("(" + Deployer.NAME + "=" + 
serviceAssemblyName + ")");
+               if (ref == null) {
+                throw ManagementSupport.failure("getState", "SA has not exist: 
" + serviceAssemblyName);
+            }
+               ServiceAssemblyImpl sa = (ServiceAssemblyImpl) 
getAdminService().getBundleContext().getService(ref);
+               sa.getState();
+               return ManagementSupport.createSuccessMessage("getState service 
assembly successfully", serviceAssemblyName);
+        } catch (Exception e) {
+            LOG.info("Error in getState", e);
+            throw e;
+        }
+    }
+
+       public void setAdminService(AdminService adminService) {
+               this.adminService = adminService;
+       }
+
+       public AdminService getAdminService() {
+               return adminService;
+       }
+       
+       
 }

Modified: 
servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/InstallationService.java
URL: 
http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/InstallationService.java?rev=742074&r1=742073&r2=742074&view=diff
==============================================================================
--- 
servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/InstallationService.java
 (original)
+++ 
servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/InstallationService.java
 Sun Feb  8 12:42:48 2009
@@ -35,6 +35,9 @@
 import org.apache.commons.logging.LogFactory;
 import org.apache.servicemix.jbi.deployer.descriptor.Descriptor;
 import org.apache.servicemix.jbi.deployer.handler.Transformer;
+import org.apache.servicemix.jbi.deployer.impl.Deployer;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.ServiceReference;
 
 public class InstallationService implements InstallationServiceMBean {
 
@@ -154,6 +157,17 @@
                 } else {
                     nonLoadedInstallers.put(componentName, installer);
                 }
+            } else {
+               //the component may not installed from Mbeans, so check the 
componet bundle directly
+               ServiceReference ref = 
getAdminService().getComponentServiceReference("(" + Deployer.NAME + "=" + 
componentName + ")");
+               if (ref != null) {
+                       Bundle bundle = ref.getBundle();
+                       if (bundle != null) {
+                               bundle.stop();
+                               bundle.uninstall();
+                               result = true;
+                       }
+               }
             }
         } catch (Exception e) {
             String errStr = "Problem shutting down Component: " + 
componentName;
@@ -221,8 +235,20 @@
                SharedLibInstaller installer = 
sharedLibinstallers.remove(aSharedLibName);
                result = installer != null;
             if (result) {
+               //the SL installed from Mbean
                installer.uninstall();
                 
+            } else {
+               //the SL not installed from Mbeans, so check the SL bundle 
directly
+               ServiceReference ref = 
getAdminService().getSLServiceReference("(" + Deployer.NAME + "=" + 
aSharedLibName + ")");
+               if (ref != null) {
+                       Bundle bundle = ref.getBundle();
+                       if (bundle != null) {
+                               bundle.stop();
+                               bundle.uninstall();
+                               result = true;
+                       }
+               }
             }
         } catch (Exception e) {
             String errStr = "Problem uninstall SL: " + aSharedLibName;

Added: 
servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/ServiceAssemblyInstaller.java
URL: 
http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/ServiceAssemblyInstaller.java?rev=742074&view=auto
==============================================================================
--- 
servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/ServiceAssemblyInstaller.java
 (added)
+++ 
servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/ServiceAssemblyInstaller.java
 Sun Feb  8 12:42:48 2009
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicemix.jbi.management;
+
+import javax.jbi.JBIException;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleException;
+
+public class ServiceAssemblyInstaller extends AbstractInstaller {
+
+private static final Log LOGGER = LogFactory.getLog(SharedLibInstaller.class);
+       
+       private String name;
+    private AdminService adminService;
+       
+       public ServiceAssemblyInstaller(String name, AdminService adminService) 
{
+               this.name = name;
+               this.adminService = adminService;
+               setBundleContext(adminService.getBundleContext());
+       }
+       
+       public void deploy(String filename) {
+               deployFile(filename);
+       }
+       
+       public void undeploy() throws javax.jbi.JBIException {
+               try {
+               Bundle bundle = getBundle();
+
+            if (bundle == null) {
+                LOGGER.warn("Could not find Bundle for Service Assembly: " + 
name);
+            }
+            else {
+                bundle.stop();
+                bundle.uninstall();
+            }
+        } catch (BundleException e) {
+               LOGGER.error("failed to uninstall Service Assembly: " + name, 
e);
+               throw new JBIException(e);
+               } 
+    }
+}

Propchange: 
servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/ServiceAssemblyInstaller.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/ServiceAssemblyInstaller.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: 
servicemix/smx4/nmr/trunk/jbi/management/src/main/resources/META-INF/spring/servicemix-jbi-management.xml
URL: 
http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/management/src/main/resources/META-INF/spring/servicemix-jbi-management.xml?rev=742074&r1=742073&r2=742074&view=diff
==============================================================================
--- 
servicemix/smx4/nmr/trunk/jbi/management/src/main/resources/META-INF/spring/servicemix-jbi-management.xml
 (original)
+++ 
servicemix/smx4/nmr/trunk/jbi/management/src/main/resources/META-INF/spring/servicemix-jbi-management.xml
 Sun Feb  8 12:42:48 2009
@@ -52,6 +52,7 @@
     <bean id="adminCommandsService" 
class="org.apache.servicemix.jbi.management.AdminCommandsService">
         <property name="installationService" ref="installationService" />
         <property name="adminService" ref="adminService" />
+        <property name="deploymentService" ref="deploymentService" />
     </bean>
     <bean id="installationService" 
class="org.apache.servicemix.jbi.management.InstallationService">
         <property name="namingStrategy" ref="namingStrategy" />
@@ -59,6 +60,9 @@
         <property name="adminService" ref="adminService" />
     </bean>
     
+   <bean id="deploymentService" 
class="org.apache.servicemix.jbi.management.DeploymentService">
+        <property name="adminService" ref="adminService" />
+   </bean>
 
    <bean id="managementAgent" 
class="org.apache.servicemix.jbi.management.ManagementAgent">
         <property name="mbeanServer" ref="mbeanServer" />


Reply via email to