]> git.argeo.org Git - lgpl/argeo-commons.git/commitdiff
Improve runtime manager
authorMathieu Baudier <mbaudier@argeo.org>
Tue, 25 Jun 2024 10:12:49 +0000 (12:12 +0200)
committerMathieu Baudier <mbaudier@argeo.org>
Tue, 25 Jun 2024 10:12:49 +0000 (12:12 +0200)
Makefile
org.argeo.init/src/org/argeo/api/init/InitConstants.java
org.argeo.init/src/org/argeo/api/init/RuntimeManager.java
org.argeo.init/src/org/argeo/init/RuntimeManagerMain.java
org.argeo.init/src/org/argeo/init/osgi/OsgiBoot.java

index 497de15b0e1e2a03e0dc816b00669a25920a1fff..de809221af962a2a1688822a015aa8cac774b63c 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -28,6 +28,7 @@ crypto/fips/org.argeo.tp.crypto \
 org.argeo.tp \
 org.argeo.tp.httpd \
 org.argeo.tp.sshd \
+osgi/equinox/org.argeo.tp.osgi.framework \
 osgi/equinox/org.argeo.tp.osgi \
 osgi/equinox/org.argeo.tp.eclipse \
 swt/rap/org.argeo.tp.swt \
index 864749f600cc38b4dea835ea1a4566ad6b8789d2..fae934638dfce241233dda078e356f38b1017be4 100644 (file)
@@ -2,6 +2,12 @@ package org.argeo.api.init;
 
 /** Supported init constants. */
 public interface InitConstants {
+       /** Read-only configuration area */
+       String PROP_ARGEO_CONFIG_AREA = "argeo.configArea";
+       /** Read-write persistent data area */
+       String PROP_ARGEO_STATE_AREA = "argeo.stateArea";
+       /** Read-write cache area */
+       String PROP_ARGEO_CACHE_AREA = "argeo.cacheArea";
 
        String PROP_ARGEO_OSGI_SOURCES = "argeo.osgi.sources";
        String PROP_ARGEO_OSGI_START = "argeo.osgi.start";
@@ -22,12 +28,9 @@ public interface InitConstants {
         * nested runtime.
         */
        String PROP_ARGEO_OSGI_PARENT_UUID = "argeo.osgi.parent.uuid";
-       /**
-        * The A2 categories to load from the parent. If not specified, nested runtimes
-        * won't be used.
-        */
-       @Deprecated
-       String PROP_ARGEO_OSGI_PARENT_CATEGORIES = "argeo.osgi.parent.categories";
+//     @Deprecated
+//     String PROP_ARGEO_OSGI_PARENT_CATEGORIES = "argeo.osgi.parent.categories";
+       /** The A2 categories to export from the parent. */
        String PROP_ARGEO_OSGI_EXPORT_CATEGORIES = "argeo.osgi.export.categories";
        String PROP_ARGEO_OSGI_EXPORT_ENABLED = "argeo.osgi.export.enabled";
 
index 17c330c60045d998a93a1fc89c0bb267e81cd731..2344a86884fee44978dd2bc03aca3bd00db0223f 100644 (file)
@@ -15,6 +15,7 @@ import java.util.function.Consumer;
 public interface RuntimeManager {
        String JVM_ARGS = "jvm.args";
        String STATE = "state";
+       String OSGI_STORAGE_DIRNAME = "osgi";
        String DATA = "data";
        String SHARED = "shared";
 
index 1086be6d8a03955c2027f63934420f47ef4fd772..29ae5eb06541b1ccafd533062c3a19cd4684357f 100644 (file)
@@ -22,33 +22,25 @@ public class RuntimeManagerMain {
 
        private final static String ENV_STATE_DIRECTORY = "STATE_DIRECTORY";
        private final static String ENV_CONFIGURATION_DIRECTORY = "CONFIGURATION_DIRECTORY";
-//     private final static String ENV_CACHE_DIRECTORY = "CACHE_DIRECTORY";
+       private final static String ENV_CACHE_DIRECTORY = "CACHE_DIRECTORY";
 
        private final static long RUNTIME_SHUTDOWN_TIMEOUT = 60 * 1000;
 
        private Map<String, String> configuration = new HashMap<>();
 
-       RuntimeManagerMain(Path configArea, Path writableArea) {
-//             RuntimeManager.loadConfig(configArea, configuration);
-
-               // integration with OSGi runtime; this will be read by the init bundle
-//             configuration.put(ServiceMain.PROP_ARGEO_INIT_MAIN, "true");
+       RuntimeManagerMain(Path configArea, Path stateArea, Path cacheArea) {
                RuntimeManager.loadDefaults(configuration);
-               
+
                configuration.put(InitConstants.PROP_OSGI_SHARED_CONFIGURATION_AREA, configArea.toUri().toString());
                configuration.put(InitConstants.PROP_OSGI_SHARED_CONFIGURATION_AREA_RO, "true");
-               configuration.put(InitConstants.PROP_OSGI_USE_SYSTEM_PROPERTIES, "false");
+//             configuration.put(InitConstants.PROP_OSGI_USE_SYSTEM_PROPERTIES, "false");
 
                configuration.put(InitConstants.PROP_OSGI_CONFIGURATION_AREA,
-                               writableArea.resolve(RuntimeManager.STATE).toUri().toString());
-               // use config area if instance area is not set
-               if (!configuration.containsKey(InitConstants.PROP_OSGI_INSTANCE_AREA))
-                       configuration.put(InitConstants.PROP_OSGI_INSTANCE_AREA,
-                                       writableArea.resolve(RuntimeManager.DATA).toUri().toString());
+                               cacheArea.resolve(RuntimeManager.OSGI_STORAGE_DIRNAME).toUri().toString());
+               configuration.put(InitConstants.PROP_OSGI_INSTANCE_AREA,
+                               stateArea.resolve(RuntimeManager.DATA).toUri().toString());
 
                logger.log(Level.TRACE, () -> "Runtime manager configuration: " + configuration);
-
-//             System.out.println("java.library.path=" + System.getProperty("java.library.path"));
        }
 
        public void run() {
@@ -91,19 +83,23 @@ public class RuntimeManagerMain {
        public static void main(String[] args) {
                ThinLoggerFinder.reloadConfiguration();
                logger.log(Logger.Level.DEBUG, () -> "Argeo Init starting with PID " + ProcessHandle.current().pid());
-               Map<String, String> env = System.getenv();
 
-//             if (args.length < 1)
-//                     throw new IllegalArgumentException("A relative configuration directory must be specified");
-//             Path configArea = Paths.get(System.getProperty("user.dir"), args[0]);
-
-               // System.out.println("## Start with PID " + ProcessHandle.current().pid());
-               // System.out.println("user.dir=" + System.getProperty("user.dir"));
-
-               Path writableArea = Paths.get(env.get(ENV_STATE_DIRECTORY));
-               Path configArea = Paths.get(env.get(ENV_CONFIGURATION_DIRECTORY));
-               RuntimeManagerMain runtimeManager = new RuntimeManagerMain(configArea, writableArea);
+               Path writableArea = getLocalPath(InitConstants.PROP_ARGEO_STATE_AREA, ENV_STATE_DIRECTORY);
+               Path configArea =getLocalPath(InitConstants.PROP_ARGEO_CONFIG_AREA, ENV_CONFIGURATION_DIRECTORY);
+               Path cacheArea = getLocalPath(InitConstants.PROP_ARGEO_CACHE_AREA, ENV_CACHE_DIRECTORY);
+               RuntimeManagerMain runtimeManager = new RuntimeManagerMain(configArea, writableArea, cacheArea);
                runtimeManager.run();
        }
 
+       private static Path getLocalPath(String systemProperty, String environmentVariable) {
+               String prop = System.getProperty(systemProperty);
+               if (prop != null)
+                       return Paths.get(prop);
+               String env = System.getenv().get(environmentVariable);
+               if (env != null)
+                       return Paths.get(env);
+               throw new IllegalStateException("No local path set with system property " + systemProperty
+                               + " or environment variable " + environmentVariable);
+               // TODO allocate a temporary directory? or defaults based on working directory ?
+       }
 }
index c6c8471b0b336e4fdff09b91e6ac273799fb0a7a..9d8a207742ea5733de6f32eca9c73366cd7bc953 100644 (file)
@@ -99,19 +99,19 @@ public class OsgiBoot {
                                                provisioningManager.registerSource(
                                                                A2Source.SCHEME_A2 + "://" + homePath.toString() + "/.local/share/a2" + queryPart);
                                        provisioningManager.registerSource(A2Source.SCHEME_A2 + ":///usr/local/share/a2" + queryPart);
-//                                     provisioningManager.registerSource(A2Source.SCHEME_A2 + ":///usr/local/lib/a2" + queryPart);
+                                       provisioningManager.registerSource(A2Source.SCHEME_A2 + ":///usr/local/lib/a2" + queryPart);
                                        provisioningManager.registerSource(A2Source.SCHEME_A2 + ":///usr/share/a2" + queryPart);
-//                                     provisioningManager.registerSource(A2Source.SCHEME_A2 + ":///usr/lib/a2" + queryPart);
+                                       provisioningManager.registerSource(A2Source.SCHEME_A2 + ":///usr/lib/a2" + queryPart);
                                } else if (source.trim().equals(A2Source.DEFAULT_A2_REFERENCE_URI)) {
                                        if (Files.exists(homePath))
                                                provisioningManager.registerSource(A2Source.SCHEME_A2_REFERENCE + "://" + homePath.toString()
                                                                + "/.local/share/a2" + queryPart);
                                        provisioningManager
                                                        .registerSource(A2Source.SCHEME_A2_REFERENCE + ":///usr/local/share/a2" + queryPart);
-//                                     provisioningManager
-//                                                     .registerSource(A2Source.SCHEME_A2_REFERENCE + ":///usr/local/lib/a2" + queryPart);
+                                       provisioningManager
+                                                       .registerSource(A2Source.SCHEME_A2_REFERENCE + ":///usr/local/lib/a2" + queryPart);
                                        provisioningManager.registerSource(A2Source.SCHEME_A2_REFERENCE + ":///usr/share/a2" + queryPart);
-//                                     provisioningManager.registerSource(A2Source.SCHEME_A2_REFERENCE + ":///usr/lib/a2" + queryPart);
+                                       provisioningManager.registerSource(A2Source.SCHEME_A2_REFERENCE + ":///usr/lib/a2" + queryPart);
                                } else {
                                        provisioningManager.registerSource(source + queryPart);
                                }