Experiment with runtime manager
authorMathieu Baudier <mbaudier@argeo.org>
Mon, 4 Mar 2024 18:23:49 +0000 (19:23 +0100)
committerMathieu Baudier <mbaudier@argeo.org>
Mon, 4 Mar 2024 18:23:49 +0000 (19:23 +0100)
org.argeo.slc.cms/bnd.bnd
org.argeo.slc.cms/src/org/argeo/slc/cms/deploy/CmsTargetData.java
org.argeo.slc.cms/src/org/argeo/slc/cms/deploy/SimpleCmsTargetData.java
org.argeo.slc.cms/src/org/argeo/slc/cms/deploy/osgi/OsgiCmsDeployedSystem.java
org.argeo.slc.cms/src/org/argeo/slc/cms/deploy/osgi/OsgiCmsDeployment.java
org.argeo.slc.cms/src/org/argeo/slc/cms/deploy/osgi/OsgiCmsTargetData.java
org.argeo.slc.cms/src/org/argeo/slc/init/osgi/SlcInitActivator.java [new file with mode: 0644]

index 93725b673fded250407533f480088a884ac0706f..1c0334fb0e121e0e8aa3f264c6a74446ecf9643b 100644 (file)
@@ -1,6 +1,9 @@
+
+Bundle-Activator: org.argeo.slc.init.osgi.SlcInitActivator
+
 Import-Package: \
 org.apache.commons.logging,\
 org.postgresql;version="[42,43)";resolution:=optional,\
-org.apache.commons.vfs2.*resolution:=optional,\
+org.apache.commons.vfs2.*;resolution:=optional,\
 org.osgi.*;version="0.0.0",\
 *
\ No newline at end of file
index 4616b202934032dcaaf9ad283f1f9ba540e9d9ac..8e8d147ce244cdab6e0ffa1c0165c80df5644834 100644 (file)
@@ -7,6 +7,8 @@ import org.argeo.slc.deploy.TargetData;
 public interface CmsTargetData extends TargetData {
        Path getInstanceData();
 
+       String getHost();
+
        Integer getHttpPort();
 
 }
index ecf17d684233c53d515baa06a7a686d5555b1409..081fb899e92b5679fdcef823b8029450127ceae8 100644 (file)
@@ -4,13 +4,23 @@ import java.nio.file.Path;
 
 public class SimpleCmsTargetData implements CmsTargetData {
        private Path instanceData;
+       private String host;
        private Integer httpPort;
 
-       public SimpleCmsTargetData(Path instanceData, Integer httpPort) {
+       public SimpleCmsTargetData(Path instanceData, String host, Integer httpPort) {
                this.instanceData = instanceData;
+               this.host = host;
                this.httpPort = httpPort;
        }
 
+       public String getHost() {
+               return host;
+       }
+
+       public void setHost(String hostname) {
+               this.host = hostname;
+       }
+
        public Integer getHttpPort() {
                return httpPort;
        }
index c925a544b4ad3ab8aba8665248a5dc72f4a38e6d..25d57b897955f03a194f4d45d514272f97afaebc 100644 (file)
@@ -15,11 +15,11 @@ public class OsgiCmsDeployedSystem implements CmsDeployedSystem {
        private CmsTargetData targetData;
        private CmsDeploymentData deploymentData;
 
-       private BundleContext systemBundleContext;
+       // private BundleContext systemBundleContext;
 
        public OsgiCmsDeployedSystem(BundleContext systemBundleContext, ModularDistribution distribution,
                        CmsTargetData targetData, CmsDeploymentData deploymentData) {
-               this.systemBundleContext = systemBundleContext;
+               // this.systemBundleContext = systemBundleContext;
 
                this.distribution = distribution;
                this.targetData = targetData;
index 91aba29459a8b7cd652f0f1bed05d966fb624ab0..b385609d788d2b6bdd7bdb7ed69a540d7567954a 100644 (file)
@@ -56,6 +56,11 @@ public class OsgiCmsDeployment implements Deployment {
                        // target
                        config.put(WellKnownConstants.OSGI_INSTANCE_AREA,
                                        targetData.getInstanceData().toRealPath().toUri().toString());
+
+                       if (targetData.getHost() != null) {
+                               config.put(CmsDeployProperty.HOST.getProperty(), targetData.getHost().toString());
+                       }
+
                        if (targetData.getHttpPort() != null) {
                                config.put(CmsDeployProperty.HTTP_PORT.getProperty(), targetData.getHttpPort().toString());
                        }
@@ -77,11 +82,19 @@ public class OsgiCmsDeployment implements Deployment {
                                        "sun.security.util,sun.security.internal.spec,sun.security.provider,com.sun.net.httpserver,com.sun.jndi.ldap,com.sun.jndi.ldap.sasl,com.sun.jndi.dns,com.sun.security.jgss,com.sun.nio.file,com.sun.nio.sctp");
                        config.put("eclipse.ignoreApp", "true");
                        config.put("osgi.noShutdown", "true");
-                       
+                       config.put("osgi.clean", "true");
+                       config.put("osgi.framework.useSystemProperties", "false");
+
                        config.put("argeo.directory", "dc=example,dc=com.ldif");
 
-                       if (targetData instanceof OsgiCmsTargetData osgiCmsTargetData && osgiCmsTargetData.getTelnetPort() != null)
-                               config.put("osgi.console", osgiCmsTargetData.getTelnetPort().toString());
+                       if (targetData instanceof OsgiCmsTargetData osgiCmsTargetData
+                                       && osgiCmsTargetData.getTelnetPort() != null) {
+                               String hostStr = "";
+                               if (targetData.getHost() != null) {
+                                       hostStr = targetData.getHost().toString() + ":";
+                               }
+                               config.put("osgi.console", hostStr + osgiCmsTargetData.getTelnetPort().toString());
+                       }
 
                        // initialise
                        for (String key : config.keySet()) {
@@ -137,12 +150,12 @@ public class OsgiCmsDeployment implements Deployment {
                        xOr.put("swt", "rap");
                        xOr.put("log", "syslogger");
                        xOr.put("crypto", "fips");
-                       distribution.getA2Sources().add(new FsA2Source(a2Base, xOr, true));
+                       distribution.getA2Sources().add(new FsA2Source(a2Base, xOr, true, null, null));
 
                        // target data
                        Path instanceData = userHome.resolve("dev/git/unstable/argeo-slc/sdk/exec/cms-deployment/data");
                        Files.createDirectories(instanceData);
-                       OsgiCmsTargetData targetData = new OsgiCmsTargetData(instanceData, 7070, 2323);
+                       OsgiCmsTargetData targetData = new OsgiCmsTargetData(instanceData, "host1", 7070, 2323);
 
                        // deployment data
                        SimpleCmsDeploymentData deploymentData = new SimpleCmsDeploymentData();
@@ -184,7 +197,7 @@ public class OsgiCmsDeployment implements Deployment {
 
                                Path instanceData2 = userHome.resolve("dev/git/unstable/argeo-slc/sdk/exec/cms-deployment2/data");
                                Files.createDirectories(instanceData2);
-                               OsgiCmsTargetData targetData2 = new OsgiCmsTargetData(instanceData2, 7071, 2324);
+                               OsgiCmsTargetData targetData2 = new OsgiCmsTargetData(instanceData2, "host2", 7070, 2323);
 
                                OsgiCmsDeployment deployment2 = new OsgiCmsDeployment();
                                deployment2.setDistribution(distribution);
index 9edc5247ca5bc588d85f090f718a808b4039ce30..dc4bf3b1dad7fb516d48a3f71a81ecc88698a3f8 100644 (file)
@@ -7,8 +7,8 @@ import org.argeo.slc.cms.deploy.SimpleCmsTargetData;
 public class OsgiCmsTargetData extends SimpleCmsTargetData {
        private Integer telnetPort;
 
-       public OsgiCmsTargetData(Path instanceData, Integer httpPort, Integer telnetPort) {
-               super(instanceData, httpPort);
+       public OsgiCmsTargetData(Path instanceData, String host, Integer httpPort, Integer telnetPort) {
+               super(instanceData, host, httpPort);
                this.telnetPort = telnetPort;
        }
 
diff --git a/org.argeo.slc.cms/src/org/argeo/slc/init/osgi/SlcInitActivator.java b/org.argeo.slc.cms/src/org/argeo/slc/init/osgi/SlcInitActivator.java
new file mode 100644 (file)
index 0000000..e8b43e7
--- /dev/null
@@ -0,0 +1,70 @@
+package org.argeo.slc.init.osgi;
+
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+import org.argeo.api.cms.CmsLog;
+import org.argeo.cms.CmsDeployProperty;
+import org.argeo.init.RuntimeManager;
+import org.argeo.init.osgi.OsgiBoot;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.osgi.util.tracker.ServiceTracker;
+
+public class SlcInitActivator implements BundleActivator {
+       private final static CmsLog log = CmsLog.getLog(SlcInitActivator.class);
+
+       private ServiceTracker<RuntimeManager, RuntimeManager> runtimeManagerSt;
+
+       @Override
+       public void start(BundleContext context) throws Exception {
+               Path userHome = Paths.get(System.getProperty("user.home"));
+//             OsgiCmsDeployment.main(new String[0]);
+               runtimeManagerSt = new ServiceTracker<>(context, RuntimeManager.class, null) {
+
+                       @Override
+                       public RuntimeManager addingService(ServiceReference<RuntimeManager> reference) {
+                               RuntimeManager runtimeManager = super.addingService(reference);
+                               log.debug("Found runtime manager " + runtimeManager);
+                               new Thread() {
+                                       public void run() {
+                                               try {
+                                                       Thread.sleep(5000);
+                                               } catch (InterruptedException e) {
+                                                       return;
+                                               }
+
+                                               runtimeManager.startRuntime("cms/test", (config) -> {
+                                                       config.put("osgi.clean", "true");
+                                                       // config.put("argeo.osgi.sources", "a2+reference:///?osgi=equinox");
+                                                       config.put("osgi.console", "2024");
+                                                       config.put(CmsDeployProperty.SSHD_PORT.getProperty(), "2222");
+//                                                     config.put(CmsDeployProperty.HTTP_PORT.getProperty(), "7070");
+//                                                     config.put(CmsDeployProperty.HOST.getProperty(),
+//                                                                     "localhost");
+                                                       Path instanceData = userHome
+                                                                       .resolve("dev/git/unstable/argeo-slc/sdk/exec/cms-deployment/data");
+                                                       config.put(OsgiBoot.PROP_OSGI_INSTANCE_AREA, instanceData.toUri().toString());
+                                                       config.put("argeo.directory", "dc=example,dc=com.ldif");
+
+//                                                     for (String key : config.keySet()) {
+//                                                             System.out.println(key + "=" + config.get(key));
+////                                                           log.debug(() -> key + "=" + config.get(key));
+//                                                     }
+                                               });
+                                       }
+                               }.start();
+
+                               return runtimeManager;
+                       }
+
+               };
+               runtimeManagerSt.open(true);
+       }
+
+       @Override
+       public void stop(BundleContext context) throws Exception {
+       }
+
+}