]> git.argeo.org Git - gpl/argeo-slc.git/commitdiff
Remote shutdown
authorMathieu Baudier <mbaudier@argeo.org>
Wed, 17 Jun 2009 07:08:38 +0000 (07:08 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Wed, 17 Jun 2009 07:08:38 +0000 (07:08 +0000)
git-svn-id: https://svn.argeo.org/slc/trunk@2557 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

15 files changed:
runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/server/client/impl/SlcServerHttpClientImpl.java
runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/web/mvc/management/ShutdownRuntime.java [new file with mode: 0644]
runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/deploy/DeployedSystem.java
runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/deploy/DynamicRuntime.java [new file with mode: 0644]
runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/deploy/ModularDeployedSystem.java
runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/deploy/Module.java
runtime/org.argeo.slc.support.equinox/src/main/java/org/argeo/slc/equinox/EquinoxRuntime.java [new file with mode: 0644]
runtime/org.argeo.slc.support.equinox/src/main/java/org/argeo/slc/osgi/OsgiBundle.java
runtime/org.argeo.slc.support.equinox/src/main/java/org/argeo/slc/osgi/OsgiRuntime.java
runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/deploy/ResourceDistribution.java [new file with mode: 0644]
server/org.argeo.slc.siteserver/bundles/org.argeo.slc.server.main/META-INF/MANIFEST.MF
server/org.argeo.slc.siteserver/bundles/org.argeo.slc.server.main/META-INF/spring/manager.xml [new file with mode: 0644]
server/org.argeo.slc.siteserver/bundles/org.argeo.slc.server.main/META-INF/spring/osgi.xml [new file with mode: 0644]
server/org.argeo.slc.siteserver/bundles/org.argeo.slc.webapp.war/WEB-INF/osgi.xml
server/org.argeo.slc.siteserver/bundles/org.argeo.slc.webapp.war/WEB-INF/slc-service-servlet.xml

index 666e7b7bc2f8d07493de357b110dd6078b833ec2..99f0a80a3d7ee3e4faec0adb7e876793ef50a4d1 100644 (file)
@@ -1,6 +1,5 @@
 package org.argeo.slc.server.client.impl;
 
-import java.io.Serializable;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
@@ -21,7 +20,6 @@ import org.argeo.slc.process.RealizedFlow;
 import org.argeo.slc.process.SlcExecution;
 import org.argeo.slc.runtime.SlcAgentDescriptor;
 import org.argeo.slc.server.client.SlcServerHttpClient;
-import org.argeo.slc.services.EventPublisherAspect;
 
 public class SlcServerHttpClientImpl extends AbstractHttpServicesClient
                implements SlcServerHttpClient {
@@ -62,7 +60,7 @@ public class SlcServerHttpClientImpl extends AbstractHttpServicesClient
                                ExecutionAnswer answer = (ExecutionAnswer) obj;
                                if (answer.isError())
                                        throw new SlcException(
-                                                       "Unexpected exception when pollign event: "
+                                                       "Unexpected exception when polling event: "
                                                                        + answer.getMessage());
                        } else {
                                return (SlcEvent) obj;
diff --git a/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/web/mvc/management/ShutdownRuntime.java b/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/web/mvc/management/ShutdownRuntime.java
new file mode 100644 (file)
index 0000000..3b792e4
--- /dev/null
@@ -0,0 +1,38 @@
+package org.argeo.slc.web.mvc.management;\r
+\r
+import javax.servlet.http.HttpServletRequest;\r
+import javax.servlet.http.HttpServletResponse;\r
+\r
+import org.argeo.slc.deploy.DynamicRuntime;\r
+import org.argeo.slc.msg.ExecutionAnswer;\r
+import org.argeo.slc.web.mvc.AbstractServiceController;\r
+import org.springframework.web.servlet.ModelAndView;\r
+\r
+/** . */\r
+public class ShutdownRuntime extends AbstractServiceController {\r
+       private DynamicRuntime<?> dynamicRuntime;\r
+\r
+       @Override\r
+       protected void handleServiceRequest(HttpServletRequest request,\r
+                       HttpServletResponse response, ModelAndView modelAndView)\r
+                       throws Exception {\r
+               new Thread() {\r
+                       public void run() {\r
+                               // wait in order to let call return\r
+                               try {\r
+                                       Thread.sleep(3000);\r
+                               } catch (InterruptedException e) {\r
+                                       // silent\r
+                               }\r
+                               dynamicRuntime.shutdown();\r
+                       }\r
+               }.start();\r
+               ExecutionAnswer answer = ExecutionAnswer.ok("Server shutting down...");\r
+               modelAndView.addObject(answer);\r
+       }\r
+\r
+       public void setDynamicRuntime(DynamicRuntime<?> dynamicRuntime) {\r
+               this.dynamicRuntime = dynamicRuntime;\r
+       }\r
+\r
+}\r
index be28154fe1db2701ffdf239b363417f24eb88615..cd2e95eb992ab8d21a075d72c40865bf83ce3d24 100644 (file)
@@ -3,7 +3,7 @@ package org.argeo.slc.deploy;
 import org.argeo.slc.build.Distribution;\r
 \r
 /** An instance of a software system. */\r
-public interface DeployedSystem extends TargetData {\r
+public interface DeployedSystem<D extends Distribution> extends TargetData {\r
        /** Unique ID for this system instance. */\r
        public String getDeployedSystemId();\r
 \r
diff --git a/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/deploy/DynamicRuntime.java b/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/deploy/DynamicRuntime.java
new file mode 100644 (file)
index 0000000..16d727a
--- /dev/null
@@ -0,0 +1,8 @@
+package org.argeo.slc.deploy;
+
+@SuppressWarnings("unchecked")
+public interface DynamicRuntime<M extends Module> extends
+               ModularDeployedSystem<M> {
+       public void shutdown();
+
+}
index 346d2bcaac029027fb64c54e66072f55bc274431..177fac83dd67248dc220b668b474630f08ee7507 100644 (file)
@@ -2,7 +2,8 @@ package org.argeo.slc.deploy;
 
 import java.util.List;
 
-public interface ModularDeployedSystem extends DeployedSystem {
+@SuppressWarnings("unchecked")
+public interface ModularDeployedSystem<M extends Module> extends DeployedSystem {
        /** List the underlying deployed modules (in real time) */
-       public List<DeployedSystem> listModules();
+       public List<M> listModules();
 }
index 897358e0c92bd93fd3e34e55b47a2f6cf6b5cb84..57e38792421ed042381de62a54d598a1b9e6bec2 100644 (file)
@@ -2,8 +2,8 @@ package org.argeo.slc.deploy;
 
 import org.argeo.slc.build.Distribution;
 
-public interface Module {
+public interface Module<D extends Distribution> extends DeployedSystem<D> {
        public String getName();
+
        public String getVersion();
-       public Distribution getDistribution();
 }
diff --git a/runtime/org.argeo.slc.support.equinox/src/main/java/org/argeo/slc/equinox/EquinoxRuntime.java b/runtime/org.argeo.slc.support.equinox/src/main/java/org/argeo/slc/equinox/EquinoxRuntime.java
new file mode 100644 (file)
index 0000000..60d3628
--- /dev/null
@@ -0,0 +1,20 @@
+package org.argeo.slc.equinox;
+
+import org.argeo.slc.SlcException;
+import org.argeo.slc.deploy.DynamicRuntime;
+import org.argeo.slc.osgi.OsgiBundle;
+import org.argeo.slc.osgi.OsgiRuntime;
+import org.eclipse.core.runtime.adaptor.EclipseStarter;
+
+public class EquinoxRuntime extends OsgiRuntime implements
+               DynamicRuntime<OsgiBundle> {
+
+       public void shutdown() {
+               try {
+                       EclipseStarter.shutdown();
+               } catch (Exception e) {
+                       throw new SlcException("Cannot shutdown Equinox runtime.", e);
+               }
+       }
+
+}
index 42663cc6dfcb66ba82846a47ea5db1874fb2f69f..47ca2ea72fba8649cd64109c1df54aa940b342c3 100644 (file)
@@ -1,15 +1,28 @@
 package org.argeo.slc.osgi;
 
 import org.argeo.slc.build.Distribution;
-import org.argeo.slc.deploy.DeployedSystem;
+import org.argeo.slc.core.deploy.ResourceDistribution;
 import org.argeo.slc.deploy.DeploymentData;
+import org.argeo.slc.deploy.Module;
 import org.argeo.slc.deploy.TargetData;
+import org.osgi.framework.Bundle;
 
-public class OsgiBundle implements DeployedSystem {
+public class OsgiBundle implements Module<ResourceDistribution> {
+       private String name;
+       private String version;
+       private Distribution distribution;
+
+       public OsgiBundle() {
+
+       }
+
+       public OsgiBundle(Bundle bundle) {
+               name = bundle.getSymbolicName();
+               version = bundle.getHeaders().get("Bundle-Version").toString();
+       }
 
        public String getDeployedSystemId() {
-               // TODO Auto-generated method stub
-               return null;
+               return name + ":" + version;
        }
 
        public DeploymentData getDeploymentData() {
@@ -18,8 +31,7 @@ public class OsgiBundle implements DeployedSystem {
        }
 
        public Distribution getDistribution() {
-               // TODO Auto-generated method stub
-               return null;
+               return distribution;
        }
 
        public TargetData getTargetData() {
@@ -27,4 +39,24 @@ public class OsgiBundle implements DeployedSystem {
                return null;
        }
 
+       public String getName() {
+               return name;
+       }
+
+       public String getVersion() {
+               return version;
+       }
+
+       public void setName(String name) {
+               this.name = name;
+       }
+
+       public void setVersion(String version) {
+               this.version = version;
+       }
+
+       public void setDistribution(Distribution distribution) {
+               this.distribution = distribution;
+       }
+
 }
index 364854605ae47181cf36fd639325bad2ab3bc439..bd6c63034a8ca28395b4eb2d7c0ef434149d11e4 100644 (file)
@@ -1,38 +1,65 @@
 package org.argeo.slc.osgi;
 
+import java.util.ArrayList;
 import java.util.List;
+import java.util.UUID;
 
+import org.argeo.slc.UnsupportedException;
 import org.argeo.slc.build.Distribution;
-import org.argeo.slc.deploy.DeployedSystem;
+import org.argeo.slc.core.deploy.ResourceDistribution;
 import org.argeo.slc.deploy.DeploymentData;
 import org.argeo.slc.deploy.ModularDeployedSystem;
 import org.argeo.slc.deploy.TargetData;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.springframework.context.ResourceLoaderAware;
+import org.springframework.core.io.Resource;
+import org.springframework.core.io.ResourceLoader;
+import org.springframework.osgi.context.BundleContextAware;
 
-public class OsgiRuntime implements ModularDeployedSystem {
+public class OsgiRuntime implements ModularDeployedSystem<OsgiBundle>,
+               BundleContextAware, ResourceLoaderAware {
+       private String uuid = UUID.randomUUID().toString();
+       private BundleContext bundleContext;
+       private ResourceLoader resourceLoader;
 
-       public List<DeployedSystem> listModules() {
-               // TODO Auto-generated method stub
-               return null;
+       public List<OsgiBundle> listModules() {
+               List<OsgiBundle> modules = new ArrayList<OsgiBundle>();
+               Bundle[] bundles = bundleContext.getBundles();
+               for (Bundle bundle : bundles) {
+                       OsgiBundle osgiBundle = new OsgiBundle(bundle);
+                       modules.add(osgiBundle);
+                       String location = bundle.getLocation();
+                       if (location != null) {
+                               Resource resource = resourceLoader.getResource(location);
+                               osgiBundle.setDistribution(new ResourceDistribution(resource));
+                       }
+               }
+               return modules;
        }
 
        public String getDeployedSystemId() {
-               // TODO Auto-generated method stub
-               return null;
+               return uuid;
        }
 
        public DeploymentData getDeploymentData() {
-               // TODO Auto-generated method stub
-               return null;
+               throw new UnsupportedException();
        }
 
        public Distribution getDistribution() {
-               // TODO Auto-generated method stub
-               return null;
+               throw new UnsupportedException();
        }
 
        public TargetData getTargetData() {
-               // TODO Auto-generated method stub
-               return null;
+               throw new UnsupportedException();
+       }
+
+       public void setBundleContext(BundleContext bundleContext) {
+               this.bundleContext = bundleContext;
+       }
+
+       public void setResourceLoader(ResourceLoader resourceLoader) {
+               this.resourceLoader = resourceLoader;
        }
 
 }
diff --git a/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/deploy/ResourceDistribution.java b/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/deploy/ResourceDistribution.java
new file mode 100644 (file)
index 0000000..bef859f
--- /dev/null
@@ -0,0 +1,28 @@
+package org.argeo.slc.core.deploy;
+
+import org.argeo.slc.build.Distribution;
+import org.springframework.core.io.Resource;
+
+public class ResourceDistribution implements Distribution {
+       private Resource location;
+
+       public ResourceDistribution() {
+       }
+
+       public ResourceDistribution(Resource location) {
+               this.location = location;
+       }
+
+       public String getDistributionId() {
+               return location.toString();
+       }
+
+       public Resource getLocation() {
+               return location;
+       }
+
+       public void setLocation(Resource location) {
+               this.location = location;
+       }
+
+}
index d3ec3e14ea5498665519678ebb512c8156b54735..dda0d6862fa236d92ce2b052851ce091cd7a0a20 100644 (file)
@@ -4,4 +4,5 @@ Bundle-Version: 0.11.4.SNAPSHOT
 Bundle-Name: SLC Server Main\r
 Require-Bundle: org.argeo.slc.server,\r
  org.argeo.slc.specs,\r
- org.argeo.slc.support.simple\r
+ org.argeo.slc.support.simple,\r
+ org.argeo.slc.support.equinox\r
diff --git a/server/org.argeo.slc.siteserver/bundles/org.argeo.slc.server.main/META-INF/spring/manager.xml b/server/org.argeo.slc.siteserver/bundles/org.argeo.slc.server.main/META-INF/spring/manager.xml
new file mode 100644 (file)
index 0000000..eccb354
--- /dev/null
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="
+       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
+
+       <bean id="dynamicRuntime" class="org.argeo.slc.equinox.EquinoxRuntime" />
+</beans>
\ No newline at end of file
diff --git a/server/org.argeo.slc.siteserver/bundles/org.argeo.slc.server.main/META-INF/spring/osgi.xml b/server/org.argeo.slc.siteserver/bundles/org.argeo.slc.server.main/META-INF/spring/osgi.xml
new file mode 100644 (file)
index 0000000..43818e3
--- /dev/null
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans:beans xmlns="http://www.springframework.org/schema/osgi"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www.springframework.org/schema/beans"
+       xsi:schemaLocation="http://www.springframework.org/schema/osgi  
+       http://www.springframework.org/schema/osgi/spring-osgi-1.1.xsd
+       http://www.springframework.org/schema/beans   
+       http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
+
+       <service ref="dynamicRuntime" interface="org.argeo.slc.deploy.DynamicRuntime" />
+</beans:beans>
\ No newline at end of file
index 1c9aea4c2fd9ae3eb432c9daa40a22b9a90025be..a75bac77a67301a1c3c021a0ac73599b57482d4b 100644 (file)
@@ -40,4 +40,8 @@
        <reference id="attachmentsStorage"\r
                interface="org.argeo.slc.core.attachment.AttachmentsStorage" />\r
 \r
+       <!-- Runtime -->\r
+       <reference id="dynamicRuntime" interface="org.argeo.slc.deploy.DynamicRuntime" />\r
+\r
+\r
 </beans:beans>
\ No newline at end of file
index a3e22d1989b3be3c7c2711c0a88220b7c2b8817e..1e335c88679ffefdef639a4d6732b03fa6e392b0 100644 (file)
                <property name="attachmentsStorage" ref="attachmentsStorage" />
        </bean>
 
+       <!-- Management -->
+       <bean name="/shutdownRuntime.service" class="org.argeo.slc.web.mvc.management.ShutdownRuntime">
+               <property name="dynamicRuntime" ref="dynamicRuntime" />
+       </bean>
+
+       <!-- MVC -->
        <bean id="handlerMapping"
                class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping">
                <property name="interceptors">
                <constructor-arg ref="slcDefault.castor.marshaller" />
        </bean>
 
-
 </beans>
\ No newline at end of file