X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=org.argeo.cms%2Fsrc%2Forg%2Fargeo%2Fcms%2Finternal%2Fjcr%2FRepositoryBuilder.java;h=86ce94bb40884b47c493c1c12e7dfa184c2980f8;hb=f29320f6e6aca6d3c1b1deca1276930189fd3a60;hp=ca5dfccb836924e33013c6913fe235cbcda2132d;hpb=5f71a84cb6ad1383c97f16a1aa6fd63f9464509a;p=lgpl%2Fargeo-commons.git diff --git a/org.argeo.cms/src/org/argeo/cms/internal/jcr/RepositoryBuilder.java b/org.argeo.cms/src/org/argeo/cms/internal/jcr/RepositoryBuilder.java index ca5dfccb8..86ce94bb4 100644 --- a/org.argeo.cms/src/org/argeo/cms/internal/jcr/RepositoryBuilder.java +++ b/org.argeo.cms/src/org/argeo/cms/internal/jcr/RepositoryBuilder.java @@ -1,6 +1,5 @@ package org.argeo.cms.internal.jcr; -import java.io.File; import java.io.IOException; import java.io.InputStream; import java.net.URI; @@ -76,31 +75,56 @@ public class RepositoryBuilder { props.put(key, properties.get(key)); } + // cluster id + // cf. https://wiki.apache.org/jackrabbit/Clustering + // TODO deal with multiple repos + String clusterId = System.getProperty("org.apache.jackrabbit.core.cluster.node_id"); + String clusterIdProp = props.getProperty(RepoConf.clusterId.name()); + if (clusterId != null) { + if (clusterIdProp != null) + throw new CmsException("Cluster id defined as System properties and in deploy config"); + props.put(RepoConf.clusterId.name(), clusterId); + } else { + clusterId = clusterIdProp; + } + // home String homeUri = props.getProperty(RepoConf.labeledUri.name()); Path homePath; if (homeUri == null) { String cn = props.getProperty(NodeConstants.CN); assert cn != null; - homePath = CmsPaths.getRepoDirPath(cn); + if (clusterId != null) { + homePath = CmsPaths.getRepoDirPath(cn + '/' + clusterId); + } else { + homePath = CmsPaths.getRepoDirPath(cn); + } } else { try { - homePath = Paths.get(new URI(homeUri)).toAbsolutePath(); + URI uri = new URI(homeUri); + String host = uri.getHost(); + if (host == null || host.trim().equals("")) { + homePath = Paths.get(uri).toAbsolutePath(); + } else { + // TODO remote at this stage? + throw new IllegalArgumentException("Cannot manage repository path for host " + host); + } } catch (URISyntaxException e) { throw new CmsException("Invalid repository home URI", e); } } + // TODO use Jackrabbit API (?) Path rootUuidPath = homePath.resolve("repository/meta/rootUUID"); - if (!Files.exists(rootUuidPath)) { - try { + try { + if (!Files.exists(rootUuidPath)) { Files.createDirectories(rootUuidPath.getParent()); Files.write(rootUuidPath, UUID.randomUUID().toString().getBytes()); - } catch (IOException e) { - log.error("Could not set rootUUID", e); } + // File homeDir = homePath.toFile(); + // homeDir.mkdirs(); + } catch (IOException e) { + throw new CmsException("Cannot set up repository home " + homePath, e); } - File homeDir = homePath.toFile(); - homeDir.mkdirs(); // home cannot be overridden props.put(RepositoryConfigurationParser.REPOSITORY_HOME_VARIABLE, homePath.toString()); @@ -119,7 +143,7 @@ public class RepositoryBuilder { String dburl; switch (type) { case h2: - dburl = "jdbc:h2:" + homeDir.getPath() + "/h2/repository"; + dburl = "jdbc:h2:" + homePath.toAbsolutePath() + "/h2/repository"; setProp(props, RepoConf.dburl, dburl); setProp(props, RepoConf.dbuser, "sa"); setProp(props, RepoConf.dbpassword, ""); @@ -127,6 +151,7 @@ public class RepositoryBuilder { case postgresql: case postgresql_ds: case postgresql_cluster: + case postgresql_cluster_ds: dburl = "jdbc:postgresql://localhost/demo"; setProp(props, RepoConf.dburl, dburl); setProp(props, RepoConf.dbuser, "argeo"); @@ -175,8 +200,8 @@ public class RepositoryBuilder { RepositoryContext repositoryContext = RepositoryContext.create(repositoryConfig); double duration = ((double) (System.currentTimeMillis() - begin)) / 1000; - if (log.isTraceEnabled()) - log.trace( + if (log.isDebugEnabled()) + log.debug( "Created Jackrabbit repository in " + duration + " s, home: " + repositoryConfig.getHomeDir()); return repositoryContext;