From: Mathieu Baudier Date: Wed, 17 Jun 2009 07:08:38 +0000 (+0000) Subject: Remote shutdown X-Git-Tag: argeo-slc-2.1.7~1778 X-Git-Url: http://git.argeo.org/?a=commitdiff_plain;h=c013d066971b9ac23b7b488bd1cc6193c83b6227;p=gpl%2Fargeo-slc.git Remote shutdown git-svn-id: https://svn.argeo.org/slc/trunk@2557 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- diff --git a/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/server/client/impl/SlcServerHttpClientImpl.java b/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/server/client/impl/SlcServerHttpClientImpl.java index 666e7b7bc..99f0a80a3 100644 --- a/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/server/client/impl/SlcServerHttpClientImpl.java +++ b/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/server/client/impl/SlcServerHttpClientImpl.java @@ -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 index 000000000..3b792e47b --- /dev/null +++ b/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/web/mvc/management/ShutdownRuntime.java @@ -0,0 +1,38 @@ +package org.argeo.slc.web.mvc.management; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.argeo.slc.deploy.DynamicRuntime; +import org.argeo.slc.msg.ExecutionAnswer; +import org.argeo.slc.web.mvc.AbstractServiceController; +import org.springframework.web.servlet.ModelAndView; + +/** . */ +public class ShutdownRuntime extends AbstractServiceController { + private DynamicRuntime dynamicRuntime; + + @Override + protected void handleServiceRequest(HttpServletRequest request, + HttpServletResponse response, ModelAndView modelAndView) + throws Exception { + new Thread() { + public void run() { + // wait in order to let call return + try { + Thread.sleep(3000); + } catch (InterruptedException e) { + // silent + } + dynamicRuntime.shutdown(); + } + }.start(); + ExecutionAnswer answer = ExecutionAnswer.ok("Server shutting down..."); + modelAndView.addObject(answer); + } + + public void setDynamicRuntime(DynamicRuntime dynamicRuntime) { + this.dynamicRuntime = dynamicRuntime; + } + +} diff --git a/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/deploy/DeployedSystem.java b/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/deploy/DeployedSystem.java index be28154fe..cd2e95eb9 100644 --- a/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/deploy/DeployedSystem.java +++ b/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/deploy/DeployedSystem.java @@ -3,7 +3,7 @@ package org.argeo.slc.deploy; import org.argeo.slc.build.Distribution; /** An instance of a software system. */ -public interface DeployedSystem extends TargetData { +public interface DeployedSystem extends TargetData { /** Unique ID for this system instance. */ public String getDeployedSystemId(); 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 index 000000000..16d727a2c --- /dev/null +++ b/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/deploy/DynamicRuntime.java @@ -0,0 +1,8 @@ +package org.argeo.slc.deploy; + +@SuppressWarnings("unchecked") +public interface DynamicRuntime extends + ModularDeployedSystem { + public void shutdown(); + +} diff --git a/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/deploy/ModularDeployedSystem.java b/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/deploy/ModularDeployedSystem.java index 346d2bcaa..177fac83d 100644 --- a/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/deploy/ModularDeployedSystem.java +++ b/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/deploy/ModularDeployedSystem.java @@ -2,7 +2,8 @@ package org.argeo.slc.deploy; import java.util.List; -public interface ModularDeployedSystem extends DeployedSystem { +@SuppressWarnings("unchecked") +public interface ModularDeployedSystem extends DeployedSystem { /** List the underlying deployed modules (in real time) */ - public List listModules(); + public List listModules(); } diff --git a/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/deploy/Module.java b/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/deploy/Module.java index 897358e0c..57e387924 100644 --- a/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/deploy/Module.java +++ b/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/deploy/Module.java @@ -2,8 +2,8 @@ package org.argeo.slc.deploy; import org.argeo.slc.build.Distribution; -public interface Module { +public interface Module extends DeployedSystem { 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 index 000000000..60d36280c --- /dev/null +++ b/runtime/org.argeo.slc.support.equinox/src/main/java/org/argeo/slc/equinox/EquinoxRuntime.java @@ -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 { + + public void shutdown() { + try { + EclipseStarter.shutdown(); + } catch (Exception e) { + throw new SlcException("Cannot shutdown Equinox runtime.", e); + } + } + +} diff --git a/runtime/org.argeo.slc.support.equinox/src/main/java/org/argeo/slc/osgi/OsgiBundle.java b/runtime/org.argeo.slc.support.equinox/src/main/java/org/argeo/slc/osgi/OsgiBundle.java index 42663cc6d..47ca2ea72 100644 --- a/runtime/org.argeo.slc.support.equinox/src/main/java/org/argeo/slc/osgi/OsgiBundle.java +++ b/runtime/org.argeo.slc.support.equinox/src/main/java/org/argeo/slc/osgi/OsgiBundle.java @@ -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 { + 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; + } + } diff --git a/runtime/org.argeo.slc.support.equinox/src/main/java/org/argeo/slc/osgi/OsgiRuntime.java b/runtime/org.argeo.slc.support.equinox/src/main/java/org/argeo/slc/osgi/OsgiRuntime.java index 364854605..bd6c63034 100644 --- a/runtime/org.argeo.slc.support.equinox/src/main/java/org/argeo/slc/osgi/OsgiRuntime.java +++ b/runtime/org.argeo.slc.support.equinox/src/main/java/org/argeo/slc/osgi/OsgiRuntime.java @@ -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, + BundleContextAware, ResourceLoaderAware { + private String uuid = UUID.randomUUID().toString(); + private BundleContext bundleContext; + private ResourceLoader resourceLoader; - public List listModules() { - // TODO Auto-generated method stub - return null; + public List listModules() { + List modules = new ArrayList(); + 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 index 000000000..bef859fcc --- /dev/null +++ b/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/deploy/ResourceDistribution.java @@ -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; + } + +} diff --git a/server/org.argeo.slc.siteserver/bundles/org.argeo.slc.server.main/META-INF/MANIFEST.MF b/server/org.argeo.slc.siteserver/bundles/org.argeo.slc.server.main/META-INF/MANIFEST.MF index d3ec3e14e..dda0d6862 100644 --- a/server/org.argeo.slc.siteserver/bundles/org.argeo.slc.server.main/META-INF/MANIFEST.MF +++ b/server/org.argeo.slc.siteserver/bundles/org.argeo.slc.server.main/META-INF/MANIFEST.MF @@ -4,4 +4,5 @@ Bundle-Version: 0.11.4.SNAPSHOT Bundle-Name: SLC Server Main Require-Bundle: org.argeo.slc.server, org.argeo.slc.specs, - org.argeo.slc.support.simple + org.argeo.slc.support.simple, + org.argeo.slc.support.equinox 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 index 000000000..eccb3544a --- /dev/null +++ b/server/org.argeo.slc.siteserver/bundles/org.argeo.slc.server.main/META-INF/spring/manager.xml @@ -0,0 +1,8 @@ + + + + + \ 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 index 000000000..43818e343 --- /dev/null +++ b/server/org.argeo.slc.siteserver/bundles/org.argeo.slc.server.main/META-INF/spring/osgi.xml @@ -0,0 +1,10 @@ + + + + + \ No newline at end of file diff --git a/server/org.argeo.slc.siteserver/bundles/org.argeo.slc.webapp.war/WEB-INF/osgi.xml b/server/org.argeo.slc.siteserver/bundles/org.argeo.slc.webapp.war/WEB-INF/osgi.xml index 1c9aea4c2..a75bac77a 100644 --- a/server/org.argeo.slc.siteserver/bundles/org.argeo.slc.webapp.war/WEB-INF/osgi.xml +++ b/server/org.argeo.slc.siteserver/bundles/org.argeo.slc.webapp.war/WEB-INF/osgi.xml @@ -40,4 +40,8 @@ + + + + \ No newline at end of file diff --git a/server/org.argeo.slc.siteserver/bundles/org.argeo.slc.webapp.war/WEB-INF/slc-service-servlet.xml b/server/org.argeo.slc.siteserver/bundles/org.argeo.slc.webapp.war/WEB-INF/slc-service-servlet.xml index a3e22d198..1e335c886 100644 --- a/server/org.argeo.slc.siteserver/bundles/org.argeo.slc.webapp.war/WEB-INF/slc-service-servlet.xml +++ b/server/org.argeo.slc.siteserver/bundles/org.argeo.slc.webapp.war/WEB-INF/slc-service-servlet.xml @@ -100,6 +100,12 @@ + + + + + + @@ -113,5 +119,4 @@ - \ No newline at end of file