]> git.argeo.org Git - lgpl/argeo-commons.git/blobdiff - org.argeo.cms/src/org/argeo/cms/internal/runtime/CmsStateImpl.java
Clarify CMS initialisation
[lgpl/argeo-commons.git] / org.argeo.cms / src / org / argeo / cms / internal / runtime / CmsStateImpl.java
index cb07f43eb17eea2af0bf290c3445916fbb3198f8..d335b48b191b111ce428ac2bab5dc19beff228e8 100644 (file)
@@ -4,9 +4,7 @@ import java.io.File;
 import java.io.FileFilter;
 import java.io.IOException;
 import java.io.Reader;
-import java.net.InetAddress;
 import java.net.URL;
-import java.net.UnknownHostException;
 import java.nio.charset.StandardCharsets;
 import java.nio.file.Files;
 import java.nio.file.Path;
@@ -44,7 +42,7 @@ public class CmsStateImpl implements CmsState {
 
        private UUID uuid;
 //     private final boolean cleanState;
-       private String hostname;
+//     private String hostname;
 
        private UuidFactory uuidFactory;
 
@@ -83,11 +81,11 @@ public class CmsStateImpl implements CmsState {
 //                     this.uuid = UUID.fromString(stateUuidStr);
                        this.uuid = uuidFactory.timeUUID();
 //             this.cleanState = stateUuid.equals(frameworkUuid);
-                       try {
-                               this.hostname = InetAddress.getLocalHost().getHostName();
-                       } catch (UnknownHostException e) {
-                               log.error("Cannot set hostname: " + e);
-                       }
+//                     try {
+//                             this.hostname = InetAddress.getLocalHost().getHostName();
+//                     } catch (UnknownHostException e) {
+//                             log.error("Cannot set hostname: " + e);
+//                     }
 
                        availableSince = System.currentTimeMillis();
                        if (log.isDebugEnabled()) {
@@ -119,7 +117,7 @@ public class CmsStateImpl implements CmsState {
                        }
 
                } catch (RuntimeException | IOException e) {
-                       log.error("## FATAL: CMS activator failed", e);
+                       log.error("## FATAL: CMS state failed", e);
                }
        }
 
@@ -156,6 +154,7 @@ public class CmsStateImpl implements CmsState {
                        try (Reader key = Files.newBufferedReader(pemKeyPath, StandardCharsets.US_ASCII);
                                        Reader cert = Files.newBufferedReader(pemCertPath, StandardCharsets.US_ASCII);) {
                                PkiUtils.loadPem(keyStore, key, keyStorePassword, cert);
+                               Files.createDirectories(keyStorePath.getParent());
                                PkiUtils.saveKeyStore(keyStorePath, keyStorePassword, keyStore);
                                if (log.isDebugEnabled())
                                        log.debug("PEM certificate stored in " + keyStorePath);
@@ -175,6 +174,7 @@ public class CmsStateImpl implements CmsState {
                                        getDeployProperty(CmsDeployProperty.SSL_TRUSTSTORETYPE));
                        try (Reader cert = Files.newBufferedReader(ipaCaCertPath, StandardCharsets.US_ASCII);) {
                                PkiUtils.loadPem(trustStore, null, trustStorePassword, cert);
+                               Files.createDirectories(keyStorePath.getParent());
                                PkiUtils.saveKeyStore(trustStorePath, trustStorePassword, trustStore);
                                if (log.isDebugEnabled())
                                        log.debug("IPA CA certificate stored in " + trustStorePath);
@@ -335,10 +335,6 @@ public class CmsStateImpl implements CmsState {
        /*
         * ACCESSORS
         */
-       public String getHostname() {
-               return hostname;
-       }
-
        @Override
        public UUID getUuid() {
                return uuid;
@@ -355,6 +351,8 @@ public class CmsStateImpl implements CmsState {
        public static void prepareFirstInitInstanceArea(List<String> nodeInits) {
 
                for (String nodeInit : nodeInits) {
+                       if(nodeInit==null)
+                               continue;
 
                        if (nodeInit.startsWith("http")) {
                                // TODO reconnect it