package org.argeo.cms.internal.runtime;
+import java.io.IOException;
+import java.io.InputStream;
import java.net.InetAddress;
import java.net.URL;
import java.net.UnknownHostException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.TreeMap;
+import java.util.UUID;
import javax.security.auth.login.Configuration;
+import org.argeo.api.cms.CmsConstants;
import org.argeo.api.cms.CmsLog;
import org.argeo.api.cms.CmsState;
+import org.argeo.api.uuid.UuidFactory;
import org.argeo.cms.auth.ident.IdentClient;
-import org.osgi.framework.Constants;
+import org.argeo.util.directory.ldap.LdifParser;
/**
* Implementation of a {@link CmsState}, initialising the required services.
// REFERENCES
private Long availableSince;
- private String stateUuid;
+ private UUID uuid;
// private final boolean cleanState;
private String hostname;
+ private UuidFactory uuidFactory;
+
public void start() {
// Runtime.getRuntime().addShutdownHook(new CmsShutdown());
if (log.isTraceEnabled())
log.trace("CMS State started");
- this.stateUuid = KernelUtils.getFrameworkProp(Constants.FRAMEWORK_UUID);
+// String stateUuidStr = KernelUtils.getFrameworkProp(Constants.FRAMEWORK_UUID);
+// this.uuid = UUID.fromString(stateUuidStr);
+ this.uuid = uuidFactory.timeUUID();
// this.cleanState = stateUuid.equals(frameworkUuid);
try {
this.hostname = InetAddress.getLocalHost().getHostName();
if (log.isDebugEnabled())
// log.debug("## CMS starting... stateUuid=" + this.stateUuid + (cleanState ? "
// (clean state) " : " "));
- log.debug("## CMS starting... (" + stateUuid + ")");
+ log.debug("## CMS starting... (" + uuid + ")");
+
// initI18n();
// initServices();
+ if (!Files.exists(getDataPath(CmsConstants.NODE))) {// first init
+ firstInit();
+ }
- } catch (RuntimeException e) {
+ } catch (RuntimeException | IOException e) {
log.error("## FATAL: CMS activator failed", e);
}
}
public void stop() {
if (log.isDebugEnabled())
- log.debug("CMS stopping... (" + this.stateUuid + ")");
+ log.debug("CMS stopping... (" + this.uuid + ")");
long duration = ((System.currentTimeMillis() - availableSince) / 1000) / 60;
log.info("## ARGEO CMS STOPPED after " + (duration / 60) + "h " + (duration % 60) + "min uptime ##");
}
+ private void firstInit() throws IOException {
+ log.info("## FIRST INIT ##");
+ // FirstInit firstInit = new FirstInit();
+ InitUtils.prepareFirstInitInstanceArea();
+ }
+
+ @Override
+ public String getDeployProperty(String key) {
+ return KernelUtils.getFrameworkProp(key);
+ }
+
+ @Override
+ public Path getDataPath(String relativePath) {
+ return KernelUtils.getOsgiInstancePath(relativePath);
+ }
@Override
public Long getAvailableSince() {
return hostname;
}
+ @Override
+ public UUID getUuid() {
+ return uuid;
+ }
+
+ public void setUuidFactory(UuidFactory uuidFactory) {
+ this.uuidFactory = uuidFactory;
+ }
+
/*
* STATIC
*/