Introduce CMS deployment
authorMathieu Baudier <mbaudier@argeo.org>
Sat, 28 May 2022 09:31:00 +0000 (11:31 +0200)
committerMathieu Baudier <mbaudier@argeo.org>
Sat, 28 May 2022 09:31:00 +0000 (11:31 +0200)
cms/org.argeo.slc.cms/build.properties
cms/org.argeo.slc.cms/src/org/argeo/slc/cms/deploy/CmsDeployedSystem.java [new file with mode: 0644]
cms/org.argeo.slc.cms/src/org/argeo/slc/cms/deploy/CmsDeploymentData.java [new file with mode: 0644]
cms/org.argeo.slc.cms/src/org/argeo/slc/cms/deploy/CmsTargetData.java [new file with mode: 0644]
cms/org.argeo.slc.cms/src/org/argeo/slc/cms/deploy/SimpleCmsTargetData.java
cms/org.argeo.slc.cms/src/org/argeo/slc/cms/deploy/osgi/CmsOsgiDeployedSystem.java [new file with mode: 0644]
cms/org.argeo.slc.cms/src/org/argeo/slc/cms/deploy/osgi/CmsOsgiDeployment.java [new file with mode: 0644]
cms/org.argeo.slc.cms/src/org/argeo/slc/cms/distribution/A2Distribution.java [new file with mode: 0644]
cms/org.argeo.slc.cms/src/org/argeo/slc/cms/distribution/A2ModuleDistribution.java [new file with mode: 0644]
org.argeo.slc.api/src/org/argeo/slc/WellKnownConstants.java [new file with mode: 0644]

index 34d2e4d2dad529ceaeb953bfcdb63c51d69ffed2..5d082eaf6b26b7e5312bb461f335d96028189808 100644 (file)
@@ -2,3 +2,4 @@ source.. = src/
 output.. = bin/
 bin.includes = META-INF/,\
                .
+additional.bundles = org.argeo.init
diff --git a/cms/org.argeo.slc.cms/src/org/argeo/slc/cms/deploy/CmsDeployedSystem.java b/cms/org.argeo.slc.cms/src/org/argeo/slc/cms/deploy/CmsDeployedSystem.java
new file mode 100644 (file)
index 0000000..feec64f
--- /dev/null
@@ -0,0 +1,7 @@
+package org.argeo.slc.cms.deploy;
+
+import org.argeo.slc.deploy.DeployedSystem;
+
+public interface CmsDeployedSystem extends DeployedSystem {
+
+}
diff --git a/cms/org.argeo.slc.cms/src/org/argeo/slc/cms/deploy/CmsDeploymentData.java b/cms/org.argeo.slc.cms/src/org/argeo/slc/cms/deploy/CmsDeploymentData.java
new file mode 100644 (file)
index 0000000..62de7f1
--- /dev/null
@@ -0,0 +1,7 @@
+package org.argeo.slc.cms.deploy;
+
+import org.argeo.slc.deploy.DeploymentData;
+
+public interface CmsDeploymentData extends DeploymentData {
+
+}
diff --git a/cms/org.argeo.slc.cms/src/org/argeo/slc/cms/deploy/CmsTargetData.java b/cms/org.argeo.slc.cms/src/org/argeo/slc/cms/deploy/CmsTargetData.java
new file mode 100644 (file)
index 0000000..4616b20
--- /dev/null
@@ -0,0 +1,12 @@
+package org.argeo.slc.cms.deploy;
+
+import java.nio.file.Path;
+
+import org.argeo.slc.deploy.TargetData;
+
+public interface CmsTargetData extends TargetData {
+       Path getInstanceData();
+
+       Integer getHttpPort();
+
+}
index 9ba955a546d3ae99f1ab9b79c2266fd0af4ff386..ecf17d684233c53d515baa06a7a686d5555b1409 100644 (file)
@@ -2,9 +2,29 @@ package org.argeo.slc.cms.deploy;
 
 import java.nio.file.Path;
 
-import org.argeo.slc.deploy.TargetData;
-
-public class SimpleCmsTargetData implements TargetData {
-       private Integer httpPort;
+public class SimpleCmsTargetData implements CmsTargetData {
        private Path instanceData;
+       private Integer httpPort;
+
+       public SimpleCmsTargetData(Path instanceData, Integer httpPort) {
+               this.instanceData = instanceData;
+               this.httpPort = httpPort;
+       }
+
+       public Integer getHttpPort() {
+               return httpPort;
+       }
+
+       public void setHttpPort(Integer httpPort) {
+               this.httpPort = httpPort;
+       }
+
+       public Path getInstanceData() {
+               return instanceData;
+       }
+
+       public void setInstanceData(Path instanceData) {
+               this.instanceData = instanceData;
+       }
+
 }
diff --git a/cms/org.argeo.slc.cms/src/org/argeo/slc/cms/deploy/osgi/CmsOsgiDeployedSystem.java b/cms/org.argeo.slc.cms/src/org/argeo/slc/cms/deploy/osgi/CmsOsgiDeployedSystem.java
new file mode 100644 (file)
index 0000000..8de4354
--- /dev/null
@@ -0,0 +1,49 @@
+package org.argeo.slc.cms.deploy.osgi;
+
+import org.argeo.slc.build.Distribution;
+import org.argeo.slc.build.ModularDistribution;
+import org.argeo.slc.cms.deploy.CmsDeployedSystem;
+import org.argeo.slc.cms.deploy.CmsDeploymentData;
+import org.argeo.slc.cms.deploy.CmsTargetData;
+import org.argeo.slc.deploy.DeploymentData;
+import org.argeo.slc.deploy.TargetData;
+import org.osgi.framework.BundleContext;
+
+public class CmsOsgiDeployedSystem implements CmsDeployedSystem {
+       private ModularDistribution distribution;
+       private CmsTargetData targetData;
+       private CmsDeploymentData deploymentData;
+
+       private BundleContext systemBundleContext;
+
+       public CmsOsgiDeployedSystem(BundleContext systemBundleContext, ModularDistribution distribution,
+                       CmsTargetData targetData, CmsDeploymentData deploymentData) {
+               this.systemBundleContext = systemBundleContext;
+
+               this.distribution = distribution;
+               this.targetData = targetData;
+               this.deploymentData = deploymentData;
+       }
+
+       @Override
+       public String getDeployedSystemId() {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       @Override
+       public Distribution getDistribution() {
+               return distribution;
+       }
+
+       @Override
+       public DeploymentData getDeploymentData() {
+               return deploymentData;
+       }
+
+       @Override
+       public TargetData getTargetData() {
+               return targetData;
+       }
+
+}
diff --git a/cms/org.argeo.slc.cms/src/org/argeo/slc/cms/deploy/osgi/CmsOsgiDeployment.java b/cms/org.argeo.slc.cms/src/org/argeo/slc/cms/deploy/osgi/CmsOsgiDeployment.java
new file mode 100644 (file)
index 0000000..4e9849f
--- /dev/null
@@ -0,0 +1,109 @@
+package org.argeo.slc.cms.deploy.osgi;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Map;
+import java.util.StringJoiner;
+import java.util.TreeMap;
+
+import org.argeo.init.a2.A2Source;
+import org.argeo.init.a2.FsA2Source;
+import org.argeo.init.osgi.OsgiBoot;
+import org.argeo.init.osgi.OsgiRuntimeContext;
+import org.argeo.slc.WellKnownConstants;
+import org.argeo.slc.build.Distribution;
+import org.argeo.slc.cms.deploy.CmsDeployedSystem;
+import org.argeo.slc.cms.deploy.CmsTargetData;
+import org.argeo.slc.cms.deploy.SimpleCmsTargetData;
+import org.argeo.slc.cms.distribution.A2Distribution;
+import org.argeo.slc.deploy.DeployedSystem;
+import org.argeo.slc.deploy.Deployment;
+import org.argeo.slc.deploy.DeploymentData;
+import org.argeo.slc.deploy.TargetData;
+
+public class CmsOsgiDeployment implements Deployment {
+
+       private A2Distribution distribution;
+       private CmsTargetData targetData;
+
+       private CmsDeployedSystem deployedSystem;
+
+       @Override
+       public void run() {
+               try {
+                       Map<String, String> config = new TreeMap<>();
+
+                       // sources
+                       StringJoiner sourcesProperty = new StringJoiner(",");
+                       for (A2Source a2Source : distribution.getA2Sources()) {
+                               sourcesProperty.add(a2Source.getUri().toString());
+                       }
+                       config.put(OsgiBoot.PROP_ARGEO_OSGI_SOURCES, sourcesProperty.toString());
+
+                       // target
+                       config.put(WellKnownConstants.OSGI_INSTANCE_AREA, targetData.getInstanceData().toUri().toString());
+                       if (targetData.getHttpPort() != null) {
+                               config.put(WellKnownConstants.OSGI_HTTP_PORT, targetData.getHttpPort().toString());
+                       }
+
+                       Path configurationArea = Files.createTempDirectory("slc-cms-test");
+                       config.put(WellKnownConstants.OSGI_CONFIGURATION_AREA, configurationArea.toString());
+
+                       // initialise
+                       OsgiRuntimeContext runtimeContext = new OsgiRuntimeContext(config);
+                       runtimeContext.run();
+
+                       deployedSystem = new CmsOsgiDeployedSystem(runtimeContext.getFramework().getBundleContext(), distribution,
+                                       targetData, null);
+
+                       runtimeContext.waitForStop(0);
+               } catch (IOException | InterruptedException e) {
+                       throw new IllegalStateException("Cannot run OSGi deployment", e);
+               }
+
+       }
+
+       @Override
+       public DeployedSystem getDeployedSystem() {
+               return deployedSystem;
+       }
+
+       @Override
+       public void setTargetData(TargetData targetData) {
+               this.targetData = (CmsTargetData) targetData;
+       }
+
+       @Override
+       public void setDeploymentData(DeploymentData deploymentData) {
+               // TODO Auto-generated method stub
+
+       }
+
+       @Override
+       public void setDistribution(Distribution distribution) {
+               this.distribution = (A2Distribution) distribution;
+       }
+
+       public static void main(String[] args) throws IOException {
+               Path userHome = Paths.get(System.getProperty("user.home"));
+
+               // distribution
+               Path a2Base = userHome.resolve("dev/git/unstable/output/a2");
+               A2Distribution distribution = new A2Distribution();
+               distribution.getA2Sources().add(new FsA2Source(a2Base));
+
+               // target data
+               Path instanceData = userHome.resolve("dev/git/unstable/argeo-slc/sdk/exec/cms-deployment/data");
+               Files.createDirectories(instanceData);
+               Integer httpPort = 7070;
+               SimpleCmsTargetData targetData = new SimpleCmsTargetData(instanceData, httpPort);
+
+               CmsOsgiDeployment deployment = new CmsOsgiDeployment();
+               deployment.setDistribution(distribution);
+               deployment.setTargetData(targetData);
+               deployment.run();
+       }
+
+}
diff --git a/cms/org.argeo.slc.cms/src/org/argeo/slc/cms/distribution/A2Distribution.java b/cms/org.argeo.slc.cms/src/org/argeo/slc/cms/distribution/A2Distribution.java
new file mode 100644 (file)
index 0000000..6c8bbe7
--- /dev/null
@@ -0,0 +1,75 @@
+package org.argeo.slc.cms.distribution;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.argeo.init.a2.A2Branch;
+import org.argeo.init.a2.A2Component;
+import org.argeo.init.a2.A2Contribution;
+import org.argeo.init.a2.A2Module;
+import org.argeo.init.a2.A2Source;
+import org.argeo.slc.CategoryNameVersion;
+import org.argeo.slc.DefaultCategoryNameVersion;
+import org.argeo.slc.NameVersion;
+import org.argeo.slc.build.Distribution;
+import org.argeo.slc.build.ModularDistribution;
+
+public class A2Distribution implements ModularDistribution {
+       private List<A2Source> a2Sources = new ArrayList<>();
+
+       @Override
+       public String getDistributionId() {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       @Override
+       public String getName() {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       @Override
+       public String getVersion() {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       @Override
+       public Iterator<? extends NameVersion> nameVersions() {
+               List<CategoryNameVersion> nameVersions = new ArrayList<>();
+               for (A2Source a2Source : a2Sources) {
+                       for (A2Contribution a2Contribution : a2Source.listContributions(null)) {
+                               for (A2Component a2Component : a2Contribution.listComponents(null)) {
+                                       for (A2Branch a2Branch : a2Component.listBranches(null)) {
+                                               for (A2Module a2Module : a2Branch.listModules(null)) {
+                                                       CategoryNameVersion nameVersion = new DefaultCategoryNameVersion(a2Contribution.getId(),
+                                                                       a2Component.getId(), a2Module.getVersion().toString());
+                                                       nameVersions.add(nameVersion);
+                                               }
+                                       }
+                               }
+                       }
+               }
+               return nameVersions.iterator();
+       }
+
+       @Override
+       public Distribution getModuleDistribution(String moduleName, String moduleVersion) {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       @Override
+       public Object getModulesDescriptor(String descriptorType) {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       public List<A2Source> getA2Sources() {
+               return a2Sources;
+       }
+
+       
+}
diff --git a/cms/org.argeo.slc.cms/src/org/argeo/slc/cms/distribution/A2ModuleDistribution.java b/cms/org.argeo.slc.cms/src/org/argeo/slc/cms/distribution/A2ModuleDistribution.java
new file mode 100644 (file)
index 0000000..cc7e681
--- /dev/null
@@ -0,0 +1,14 @@
+package org.argeo.slc.cms.distribution;
+
+import org.argeo.init.a2.A2Module;
+import org.argeo.slc.build.Distribution;
+
+public class A2ModuleDistribution implements Distribution {
+       private A2Module a2Module;
+
+       @Override
+       public String getDistributionId() {
+               return a2Module.getCoordinates();
+       }
+
+}
diff --git a/org.argeo.slc.api/src/org/argeo/slc/WellKnownConstants.java b/org.argeo.slc.api/src/org/argeo/slc/WellKnownConstants.java
new file mode 100644 (file)
index 0000000..c71f243
--- /dev/null
@@ -0,0 +1,17 @@
+package org.argeo.slc;
+
+/**
+ * Centralises constant values related to software systems, which are well
+ * defined and not expected to change within a major version cycle of SLC, but
+ * which are not necessarily defined in core Java.
+ */
+public interface WellKnownConstants {
+
+       /*
+        * OSGi
+        */
+       final static String OSGI_INSTANCE_AREA = "osgi.instance.area";
+       final static String OSGI_CONFIGURATION_AREA = "osgi.configuration.area";
+
+       final static String OSGI_HTTP_PORT = "org.osgi.service.http.port";
+}