package org.argeo.slc.server.client.impl;
-import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
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 {
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;
--- /dev/null
+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
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
--- /dev/null
+package org.argeo.slc.deploy;
+
+@SuppressWarnings("unchecked")
+public interface DynamicRuntime<M extends Module> extends
+ ModularDeployedSystem<M> {
+ public void shutdown();
+
+}
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();
}
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();
}
--- /dev/null
+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);
+ }
+ }
+
+}
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() {
}
public Distribution getDistribution() {
- // TODO Auto-generated method stub
- return null;
+ return distribution;
}
public TargetData getTargetData() {
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;
+ }
+
}
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;
}
}
--- /dev/null
+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;
+ }
+
+}
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
--- /dev/null
+<?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
--- /dev/null
+<?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
<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
<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