Author: tolusha
Date: 2011-07-01 05:49:42 -0400 (Fri, 01 Jul 2011)
New Revision: 4572
Added:
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/repository/creation/DBCreationProperties.java
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/repository/creation/StorageCreationProperties.java
jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/repository/creation/cluster/
jcr/trunk/exo.jcr.component.ext/src/test/resources/test-mysql.sql
Modified:
jcr/trunk/exo.jcr.component.ext/pom.xml
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/repository/creation/RepositoryCreationService.java
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/repository/creation/RepositoryCreationServiceImpl.java
jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/BaseStandaloneTest.java
jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/repository/creation/TestRepositoryCreationService.java
jcr/trunk/exo.jcr.component.ext/src/test/resources/conf/standalone/test-configuration.xml
jcr/trunk/exo.jcr.docs/exo.jcr.docs.developer/en/src/main/docbook/en-US/modules/jcr/repository-creation-service.xml
Log:
EXOJCR-1398: Allow to create repository with custome set of DB connection
Modified: jcr/trunk/exo.jcr.component.ext/pom.xml
===================================================================
--- jcr/trunk/exo.jcr.component.ext/pom.xml 2011-07-01 08:57:52 UTC (rev 4571)
+++ jcr/trunk/exo.jcr.component.ext/pom.xml 2011-07-01 09:49:42 UTC (rev 4572)
@@ -139,7 +139,12 @@
<version>8.3-606.jdbc3</version>
<scope>test</scope>
</dependency>
-
+ <dependency>
+ <groupId>mysql</groupId>
+ <artifactId>mysql-connector-java</artifactId>
+ <version>5.1.14</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
@@ -199,6 +204,7 @@
<exclude>**/replication/external/BaseTestCaseChecker.java</exclude>
<exclude>**/access/*.java</exclude>
<exclude>**/LocalStorageMultithreadTest.java</exclude>
+ <include>**/repository/creation/cluster.java</include>
</excludes>
</configuration>
</plugin>
Added:
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/repository/creation/DBCreationProperties.java
===================================================================
---
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/repository/creation/DBCreationProperties.java
(rev 0)
+++
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/repository/creation/DBCreationProperties.java 2011-07-01
09:49:42 UTC (rev 4572)
@@ -0,0 +1,178 @@
+/*
+ * Copyright (C) 2011 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.services.jcr.ext.repository.creation;
+
+import org.exoplatform.services.jcr.impl.Constants;
+
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Map.Entry;
+
+/**
+ * @author <a href="abazko(a)exoplatform.com">Anatoliy Bazko</a>
+ * @version $Id: DBCreationProperties.java 34360 2009-07-22 23:58:59Z tolusha $
+ */
+public class DBCreationProperties implements StorageCreationProperties
+{
+ private String serverUrl;
+
+ private Map<String, String> connProps;
+
+ private String dbScriptPath;
+
+ private String dbUserName;
+
+ private String dbPassword;
+
+ /**
+ * Constructor DBCreationProperties.
+ */
+ public DBCreationProperties(String serverUrl, Map<String, String> connProps,
String dbScriptPath, String dbUserName,
+ String dbPassword)
+ {
+ this.serverUrl = serverUrl;
+ this.connProps = connProps;
+ this.dbScriptPath = dbScriptPath;
+ this.dbUserName = dbUserName;
+ this.dbPassword = dbPassword;
+ }
+
+ /**
+ * Constructor DBCreationProperties.
+ */
+ public DBCreationProperties()
+ {
+ }
+
+ /**
+ * Returns script path.
+ */
+ public String getDBScriptPath()
+ {
+ return dbScriptPath;
+ }
+
+ /**
+ * Returns return username for new database.
+ */
+ public String getDBUserName()
+ {
+ return dbUserName;
+ }
+
+ /**
+ * Returns new user's password.
+ */
+ public String getDBPassword()
+ {
+ return dbPassword;
+ }
+
+ /**
+ * Returns url to db server.
+ */
+ public String getServerUrl()
+ {
+ return serverUrl;
+ }
+
+ /**
+ * Returns connection properties.
+ */
+ public Map<String, String> getConnProps()
+ {
+ return Collections.unmodifiableMap(connProps);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void writeExternal(ObjectOutput out) throws IOException
+ {
+ byte[] buf = serverUrl.getBytes(Constants.DEFAULT_ENCODING);
+ out.writeInt(buf.length);
+ out.write(buf);
+
+ buf = dbScriptPath.getBytes(Constants.DEFAULT_ENCODING);
+ out.writeInt(buf.length);
+ out.write(buf);
+
+ buf = dbUserName.getBytes(Constants.DEFAULT_ENCODING);
+ out.writeInt(buf.length);
+ out.write(buf);
+
+ buf = dbPassword.getBytes(Constants.DEFAULT_ENCODING);
+ out.writeInt(buf.length);
+ out.write(buf);
+
+ out.writeInt(connProps.size());
+ for (Entry<String, String> entry : connProps.entrySet())
+ {
+ buf = entry.getKey().getBytes(Constants.DEFAULT_ENCODING);
+ out.writeInt(buf.length);
+ out.write(buf);
+
+ buf = entry.getValue().getBytes(Constants.DEFAULT_ENCODING);
+ out.writeInt(buf.length);
+ out.write(buf);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
+ {
+ byte[] buf = new byte[in.readInt()];
+ in.readFully(buf);
+ serverUrl = new String(buf, Constants.DEFAULT_ENCODING);
+
+ buf = new byte[in.readInt()];
+ in.readFully(buf);
+ dbScriptPath = new String(buf, Constants.DEFAULT_ENCODING);
+
+ buf = new byte[in.readInt()];
+ in.readFully(buf);
+ dbUserName = new String(buf, Constants.DEFAULT_ENCODING);
+
+ buf = new byte[in.readInt()];
+ in.readFully(buf);
+ dbPassword = new String(buf, Constants.DEFAULT_ENCODING);
+
+ int count = in.readInt();
+ connProps = new HashMap<String, String>(count);
+
+ for (int i = 0; i < count; i++)
+ {
+ buf = new byte[in.readInt()];
+ in.readFully(buf);
+ String key = new String(buf, Constants.DEFAULT_ENCODING);
+
+ buf = new byte[in.readInt()];
+ in.readFully(buf);
+ String value = new String(buf, Constants.DEFAULT_ENCODING);
+
+ connProps.put(key, value);
+ }
+ }
+}
Modified:
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/repository/creation/RepositoryCreationService.java
===================================================================
---
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/repository/creation/RepositoryCreationService.java 2011-07-01
08:57:52 UTC (rev 4571)
+++
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/repository/creation/RepositoryCreationService.java 2011-07-01
09:49:42 UTC (rev 4572)
@@ -30,6 +30,20 @@
public interface RepositoryCreationService
{
/**
+ * Reserves, validates and creates repository in a simplified form.
+ *
+ * @param rEntry - repository Entry - note that datasource must not exist.
+ * @param backupId - backup id
+ * @param creationProps - storage creation properties
+ * @throws RepositoryConfigurationException
+ * if some exception occurred during repository creation or repository name
is absent in reserved list
+ * @throws RepositoryCreationServiceException
+ * if some exception occurred during repository creation or repository name
is absent in reserved list
+ */
+ void createRepository(String backupId, RepositoryEntry rEntry,
StorageCreationProperties creationProps)
+ throws RepositoryConfigurationException, RepositoryCreationException;
+
+ /**
* Reserves, validates and creates repository in a simplified form.
*
* @param rEntry - repository Entry - note that datasource must not exist.
@@ -53,7 +67,23 @@
String reserveRepositoryName(String repositoryName) throws
RepositoryCreationException;
/**
- * Creates repository, using token of already reserved repository name. Good for
cases,
+ * Creates repository, using token of already reserved repository name.
+ * Good for cases, when repository creation should be delayed or made asynchronously
in dedicated thread.
+ *
+ * @param rEntry - repository entry - note, that datasource must not exist
+ * @param backupId - backup id
+ * @param rToken - token
+ * @param creationProps - storage creation properties
+ * @throws RepositoryConfigurationException
+ * if some exception occurred during repository creation or repository name
is absent in reserved list
+ * @throws RepositoryCreationServiceException
+ * if some exception occurred during repository creation or repository name
is absent in reserved list
+ */
+ void createRepository(String backupId, RepositoryEntry rEntry, String rToken,
StorageCreationProperties creationProps)
+ throws RepositoryConfigurationException, RepositoryCreationException;
+
+ /**
+ * Creates repository, using token of already reserved repository name. Good for
cases,
* when repository creation should be delayed or made asynchronously in dedicated
thread.
*
* @param rEntry - repository entry - note, that datasource must not exist
Modified:
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/repository/creation/RepositoryCreationServiceImpl.java
===================================================================
---
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/repository/creation/RepositoryCreationServiceImpl.java 2011-07-01
08:57:52 UTC (rev 4571)
+++
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/repository/creation/RepositoryCreationServiceImpl.java 2011-07-01
09:49:42 UTC (rev 4572)
@@ -17,6 +17,9 @@
package org.exoplatform.services.jcr.ext.repository.creation;
import org.exoplatform.commons.utils.PrivilegedFileHelper;
+import org.exoplatform.container.ExoContainerContext;
+import org.exoplatform.container.configuration.ConfigurationException;
+import org.exoplatform.container.configuration.ConfigurationManager;
import org.exoplatform.services.database.creator.DBConnectionInfo;
import org.exoplatform.services.database.creator.DBCreator;
import org.exoplatform.services.database.creator.DBCreatorException;
@@ -79,6 +82,9 @@
*/
private static final Log LOG =
ExoLogger.getLogger("exo.jcr.component.core.RepositoryCreationService");
+ /**
+ * The Repository service.
+ */
private final RepositoryService repositoryService;
/**
@@ -92,10 +98,11 @@
private final BackupManager backupManager;
/**
- * DBCreator used to create database. Only database not tables, indexes, etc.
+ * Exo container context;
*/
- private final DBCreator dbCreator;
+ private ExoContainerContext context;
+
/**
* InitalContextInitalizer used to bind new datasource.
*/
@@ -116,102 +123,104 @@
* Constructor RepositoryCreationServiceImpl.
*/
public RepositoryCreationServiceImpl(RepositoryService repositoryService,
BackupManager backupManager,
- DBCreator dbCreator, InitialContextInitializer initialContextInitializer)
+ ExoContainerContext context, InitialContextInitializer initialContextInitializer)
{
- this.repositoryService = repositoryService;
- this.backupManager = backupManager;
- this.rpcService = null;
- this.dbCreator = dbCreator;
- this.initialContextInitializer = initialContextInitializer;
-
- LOG.warn("RepositoryCreationService initialized without RPCService, so other
cluser nodes will"
- + " not be notified about new repositories.");
+ this(repositoryService, backupManager, context, initialContextInitializer, null);
}
/**
* Constructor RepositoryCreationServiceImpl.
*/
public RepositoryCreationServiceImpl(RepositoryService repositoryService,
BackupManager backupManager,
- DBCreator dbCreator, InitialContextInitializer initialContextInitializer, final
RPCService rpcService)
+ ExoContainerContext context, InitialContextInitializer initialContextInitializer,
final RPCService rpcService)
{
this.repositoryService = repositoryService;
this.backupManager = backupManager;
this.rpcService = rpcService;
- this.dbCreator = dbCreator;
+ this.context = context;
this.initialContextInitializer = initialContextInitializer;
- // register commands
- reserveRepositoryName = rpcService.registerCommand(new RemoteCommand()
+ if (rpcService != null)
{
-
- public String getId()
+ // register commands
+ reserveRepositoryName = rpcService.registerCommand(new RemoteCommand()
{
- return
"org.exoplatform.services.jcr.ext.repository.creation.RepositoryCreationServiceImpl-reserveRepositoryName";
- }
- public Serializable execute(Serializable[] args) throws Throwable
- {
- String repositoryName = (String)args[0];
- return reserveRepositoryNameLocally(repositoryName);
- }
- });
+ public String getId()
+ {
+ return
"org.exoplatform.services.jcr.ext.repository.creation.RepositoryCreationServiceImpl-reserveRepositoryName";
+ }
- createRepository = rpcService.registerCommand(new RemoteCommand()
- {
+ public Serializable execute(Serializable[] args) throws Throwable
+ {
+ String repositoryName = (String)args[0];
+ return reserveRepositoryNameLocally(repositoryName);
+ }
+ });
- public String getId()
+ createRepository = rpcService.registerCommand(new RemoteCommand()
{
- return
"org.exoplatform.services.jcr.ext.repository.creation.RepositoryCreationServiceImpl-createRepository";
- }
- public Serializable execute(Serializable[] args) throws Throwable
- {
- //String backupId, RepositoryEntry rEntry, String rToken
- String backupId = (String)args[0];
- String stringRepositoryEntry = (String)args[1];
- String rToken = (String)args[2];
+ public String getId()
+ {
+ return
"org.exoplatform.services.jcr.ext.repository.creation.RepositoryCreationServiceImpl-createRepository";
+ }
- try
+ public Serializable execute(Serializable[] args) throws Throwable
{
- RepositoryEntry rEntry =
- (RepositoryEntry)(getObject(RepositoryEntry.class,
stringRepositoryEntry
- .getBytes(Constants.DEFAULT_ENCODING)));
+ String backupId = (String)args[0];
+ String stringRepositoryEntry = (String)args[1];
+ String rToken = (String)args[2];
+ DBCreationProperties creationProps = (DBCreationProperties)args[3];
- createRepositoryLocally(backupId, rEntry, rToken);
- return null;
+ try
+ {
+ RepositoryEntry rEntry =
+ (RepositoryEntry)(getObject(RepositoryEntry.class,
+ stringRepositoryEntry.getBytes(Constants.DEFAULT_ENCODING)));
+
+ createRepositoryLocally(backupId, rEntry, rToken, creationProps);
+ return null;
+ }
+ finally
+ {
+ // release tokens
+ pendingRepositories.remove(rToken);
+ }
}
- finally
+ });
+
+ startRepository = rpcService.registerCommand(new RemoteCommand()
+ {
+ public String getId()
{
- // release tokens
- pendingRepositories.remove(rToken);
+ return
"org.exoplatform.services.jcr.ext.repository.creation.RepositoryCreationServiceImpl-startRepository";
}
- }
- });
- startRepository = rpcService.registerCommand(new RemoteCommand()
- {
- public String getId()
- {
- return
"org.exoplatform.services.jcr.ext.repository.creation.RepositoryCreationServiceImpl-startRepository";
- }
-
- public Serializable execute(Serializable[] args) throws Throwable
- {
- // must not be executed on coordinator node, since coordinator node already
created the repository
- if (!rpcService.isCoordinator())
+ public Serializable execute(Serializable[] args) throws Throwable
{
- //RepositoryEntry (as String) rEntry
- String stringRepositoryEntry = (String)args[0];
- RepositoryEntry rEntry =
- (RepositoryEntry)(getObject(RepositoryEntry.class,
stringRepositoryEntry
- .getBytes(Constants.DEFAULT_ENCODING)));
+ // must not be executed on coordinator node, since coordinator node
already created the repository
+ if (!rpcService.isCoordinator())
+ {
+ //RepositoryEntry (as String) rEntry
+ String stringRepositoryEntry = (String)args[0];
+ RepositoryEntry rEntry =
+ (RepositoryEntry)(getObject(RepositoryEntry.class,
+ stringRepositoryEntry.getBytes(Constants.DEFAULT_ENCODING)));
- startRepository(rEntry);
+ DBCreationProperties creationProps = (DBCreationProperties)args[1];
+
+ startRepository(rEntry, creationProps);
+ }
+ return null;
}
- return null;
- }
- });
-
+ });
+ }
+ else
+ {
+ LOG.warn("RepositoryCreationService initialized without RPCService, so
other cluser nodes will"
+ + " not be notified about new repositories.");
+ }
}
/**
@@ -221,15 +230,58 @@
RepositoryCreationException
{
String rToken = reserveRepositoryName(rEntry.getName());
- createRepository(backupId, rEntry, rToken);
+ createRepositoryInternally(backupId, rEntry, rToken, null);
}
/**
* {@inheritDoc}
*/
- public void createRepository(String backupId, RepositoryEntry rEntry, String rToken)
+ public void createRepository(String backupId, RepositoryEntry rEntry,
StorageCreationProperties creationProps)
throws RepositoryConfigurationException, RepositoryCreationException
{
+ String rToken = reserveRepositoryName(rEntry.getName());
+
+ if (creationProps instanceof DBCreationProperties)
+ {
+ createRepositoryInternally(backupId, rEntry, rToken,
(DBCreationProperties)creationProps);
+ }
+ else
+ {
+ throw new RepositoryCreationException("creationProps should be the instance
of DBCreationProperties");
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void createRepository(String backupId, RepositoryEntry rEntry, String rToken)
throws RepositoryConfigurationException, RepositoryCreationException
+ {
+ createRepositoryInternally(backupId, rEntry, rToken, null);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void createRepository(String backupId, RepositoryEntry rEntry, String rToken,
+ StorageCreationProperties creationProps) throws RepositoryConfigurationException,
RepositoryCreationException
+ {
+ if (creationProps instanceof DBCreationProperties)
+ {
+ createRepositoryInternally(backupId, rEntry, rToken,
(DBCreationProperties)creationProps);
+ }
+ else
+ {
+ throw new RepositoryCreationException("creationProps should be the instance
of DBCreationProperties");
+ }
+
+ }
+
+ /**
+ * Create repository internally. serverUrl and connProps contain specific properties
for db creation.
+ */
+ protected void createRepositoryInternally(String backupId, RepositoryEntry rEntry,
String rToken,
+ DBCreationProperties creationProps) throws RepositoryConfigurationException,
RepositoryCreationException
+ {
if (rpcService != null)
{
String stringRepositoryEntry = null;
@@ -248,7 +300,8 @@
try
{
Object result =
- rpcService.executeCommandOnCoordinator(createRepository, true, backupId,
stringRepositoryEntry, rToken);
+ rpcService.executeCommandOnCoordinator(createRepository, true, backupId,
stringRepositoryEntry, rToken,
+ creationProps);
if (result != null)
{
@@ -275,7 +328,8 @@
// execute startRepository at all cluster nodes (coordinator will ignore this
command)
try
{
- List<Object> results =
rpcService.executeCommandOnAllNodes(startRepository, true, stringRepositoryEntry);
+ List<Object> results =
+ rpcService.executeCommandOnAllNodes(startRepository, true,
stringRepositoryEntry, creationProps);
for (Object result : results)
{
@@ -307,7 +361,7 @@
{
try
{
- createRepositoryLocally(backupId, rEntry, rToken);
+ createRepositoryLocally(backupId, rEntry, rToken, creationProps);
}
finally
{
@@ -408,8 +462,8 @@
}
}
- protected void createRepositoryLocally(String backupId, RepositoryEntry rEntry, String
rToken)
- throws RepositoryConfigurationException, RepositoryCreationException
+ protected void createRepositoryLocally(String backupId, RepositoryEntry rEntry, String
rToken,
+ DBCreationProperties creationProps) throws RepositoryConfigurationException,
RepositoryCreationException
{
// check does token registered
if (!this.pendingRepositories.containsKey(rToken))
@@ -427,9 +481,15 @@
Map<String, String> refAddr = null;
try
{
- DBConnectionInfo dbConnectionInfo =
- dbCreator.createDatabase(rEntry.getName() + (dataSourceNames.size() == 1 ?
"" : "_" + dataSource));
+ // db name will be the same as repository name if only one datasource exists
+ String dbName = rEntry.getName() + (dataSourceNames.size() == 1 ?
"" : "_" + dataSource);
+ // get DBCreator
+ DBCreator dbCreator = getDBCreator(creationProps);
+
+ // create database
+ DBConnectionInfo dbConnectionInfo = dbCreator.createDatabase(dbName);
+
refAddr = dbConnectionInfo.getProperties();
}
catch (DBCreatorException e)
@@ -437,6 +497,10 @@
throw new RepositoryCreationException("Can not create new database for
" + rEntry.getName()
+ " repository.", e);
}
+ catch (ConfigurationException e)
+ {
+ throw new RepositoryCreationException("Can not get instance of
DBCreator", e);
+ }
// bind data-source
try
@@ -502,7 +566,8 @@
}
}
- protected void startRepository(RepositoryEntry repositoryEntry) throws
RepositoryCreationException
+ protected void startRepository(RepositoryEntry repositoryEntry, DBCreationProperties
creationProps)
+ throws RepositoryCreationException
{
try
{
@@ -515,8 +580,15 @@
Map<String, String> refAddr = null;
try
{
- DBConnectionInfo dbConnectionInfo =
- dbCreator.getDBConnectionInfo(repositoryEntry.getName() + "_"
+ dataSource);
+ // db name will be the same as repository name if only one datasource
exists
+ String dbName = repositoryEntry.getName() + (dataSourceNames.size() == 1 ?
"" : "_" + dataSource);
+
+ // get DBCreator
+ DBCreator dbCreator = getDBCreator(creationProps);
+
+ // get connection info
+ DBConnectionInfo dbConnectionInfo =
dbCreator.getDBConnectionInfo(dbName);
+
refAddr = dbConnectionInfo.getProperties();
}
catch (DBCreatorException e)
@@ -524,6 +596,11 @@
throw new RepositoryCreationException("Can not fetch database
information associated with "
+ repositoryEntry.getName() + " repository and " + dataSource
+ " datasource.", e);
}
+ catch (ConfigurationException e)
+ {
+ throw new RepositoryCreationException("Can't get instance of
DBCreator", e);
+ }
+
// bind data-source
try
{
@@ -626,7 +703,6 @@
*/
public void start()
{
- // do nothing
}
/**
@@ -641,4 +717,18 @@
this.rpcService.unregisterCommand(startRepository);
}
}
+
+ private DBCreator getDBCreator(DBCreationProperties creationProps) throws
ConfigurationException
+ {
+ if (creationProps == null)
+ {
+ return
(DBCreator)context.getContainer().getComponentInstanceOfType(DBCreator.class);
+ }
+
+ ConfigurationManager cm =
+
(ConfigurationManager)context.getContainer().getComponentInstanceOfType(ConfigurationManager.class);
+
+ return new DBCreator(creationProps.getServerUrl(), creationProps.getConnProps(),
creationProps.getDBScriptPath(),
+ creationProps.getDBUserName(), creationProps.getDBPassword(), cm);
+ }
}
Added:
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/repository/creation/StorageCreationProperties.java
===================================================================
---
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/repository/creation/StorageCreationProperties.java
(rev 0)
+++
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/repository/creation/StorageCreationProperties.java 2011-07-01
09:49:42 UTC (rev 4572)
@@ -0,0 +1,30 @@
+/*
+ * Copyright (C) 2011 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.services.jcr.ext.repository.creation;
+
+import java.io.Externalizable;
+
+/**
+ * @author <a href="abazko(a)exoplatform.com">Anatoliy Bazko</a>
+ * @version $Id: StorageCreationProperties.java 34360 2009-07-22 23:58:59Z tolusha $
+ */
+public interface StorageCreationProperties extends Externalizable
+{
+
+}
Modified:
jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/BaseStandaloneTest.java
===================================================================
---
jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/BaseStandaloneTest.java 2011-07-01
08:57:52 UTC (rev 4571)
+++
jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/BaseStandaloneTest.java 2011-07-01
09:49:42 UTC (rev 4572)
@@ -67,7 +67,7 @@
public abstract class BaseStandaloneTest extends TestCase
{
- private static final Log log =
ExoLogger.getLogger("exo.jcr.component.ext.BaseStandaloneTest");
+ protected static final Log log =
ExoLogger.getLogger("exo.jcr.component.ext.BaseStandaloneTest");
public static final String WS_NAME = "ws";
Modified:
jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/repository/creation/TestRepositoryCreationService.java
===================================================================
---
jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/repository/creation/TestRepositoryCreationService.java 2011-07-01
08:57:52 UTC (rev 4571)
+++
jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/repository/creation/TestRepositoryCreationService.java 2011-07-01
09:49:42 UTC (rev 4572)
@@ -29,6 +29,8 @@
import org.exoplatform.services.jcr.util.IdGenerator;
import java.io.File;
+import java.util.HashMap;
+import java.util.Map;
/**
* Created by The eXo Platform SAS.
@@ -147,6 +149,69 @@
assertNotNull(repoService.getConfig().getRepositoryConfiguration(tenantName));
}
+ public void testCreateRepositorySingleDBWithSpecificCreationProps() throws Exception
+ {
+ Map<String, String> connProps = new HashMap<String, String>();
+ connProps.put("driverClassName", "org.hsqldb.jdbcDriver");
+ connProps.put("username", "sa");
+ connProps.put("password", "");
+
+ DBCreationProperties creationProps =
+ new DBCreationProperties("jdbc:hsqldb:file:target/temp/data_2/",
connProps, "src/test/resources/test.sql",
+ "sa", "");
+
+ // prepare
+ String dsName = helper.createDatasource();
+ ManageableRepository repository = helper.createRepository(container, false,
dsName);
+ WorkspaceEntry wsEntry = helper.createWorkspaceEntry(false, dsName);
+ helper.addWorkspace(repository, wsEntry);
+ addConent(repository, wsEntry.getName());
+
+ // backup
+ File backDir = new File("target/backup");
+ backDir.mkdirs();
+
+ RepositoryBackupConfig config = new RepositoryBackupConfig();
+ config.setRepository(repository.getConfiguration().getName());
+ config.setBackupType(BackupManager.FULL_BACKUP_ONLY);
+ config.setBackupDir(backDir);
+
+ RepositoryBackupChain bch = backup.startBackup(config);
+ waitEndOfBackup(bch);
+ backup.stopBackup(bch);
+
+ // restore with RepositoryCreatorService
+ RepositoryCreationService creatorService =
+
(RepositoryCreationService)container.getComponentInstanceOfType(RepositoryCreationService.class);
+ assertNotNull(creatorService);
+
+ String tenantName = "new_repository_single-db-specific-props";
+ String repoToken = creatorService.reserveRepositoryName(tenantName);
+
+ // restore
+ String newDSName = IdGenerator.generate();
+
+ RepositoryEntry newRE =
+ helper.createRepositoryEntry(false,
repository.getConfiguration().getSystemWorkspaceName(), newDSName);
+ newRE.setName(tenantName);
+
+ WorkspaceEntry newWSEntry = helper.createWorkspaceEntry(false, newDSName);
+ newWSEntry.setName(wsEntry.getName());
+ newRE.addWorkspace(newWSEntry);
+
+ creatorService.createRepository(bch.getBackupId(), newRE, repoToken,
creationProps);
+
+ // check
+ ManageableRepository restoredRepository =
repositoryService.getRepository(tenantName);
+ assertNotNull(restoredRepository);
+
+ checkConent(restoredRepository, wsEntry.getName());
+
+ //check repositoryConfiguration
+ RepositoryService repoService =
(RepositoryService)this.container.getComponentInstance(RepositoryService.class);
+ assertNotNull(repoService.getConfig().getRepositoryConfiguration(tenantName));
+ }
+
public void testReserveRepositoryNameException() throws Exception
{
RepositoryCreationService creatorService =
Modified:
jcr/trunk/exo.jcr.component.ext/src/test/resources/conf/standalone/test-configuration.xml
===================================================================
---
jcr/trunk/exo.jcr.component.ext/src/test/resources/conf/standalone/test-configuration.xml 2011-07-01
08:57:52 UTC (rev 4571)
+++
jcr/trunk/exo.jcr.component.ext/src/test/resources/conf/standalone/test-configuration.xml 2011-07-01
09:49:42 UTC (rev 4572)
@@ -188,21 +188,6 @@
</init-params>
</component>
- <!-- component>
- <key>org.exoplatform.services.jcr.ext.audit.AuditService</key>
- <type>org.exoplatform.services.jcr.ext.audit.AuditServiceImpl</type>
- <init-params>
- <value-param>
- <name>adminIdentity</name>
- <value>root;john</value>
- </value-param>
- </init-params>
- </component -->
-
- <!--component>
-
<type>org.exoplatform.services.organization.impl.mock.DummyOrganizationService</type>
- </component-->
-
<component>
<key>org.exoplatform.services.security.Authenticator</key>
<type>org.exoplatform.services.organization.auth.OrganizationAuthenticatorImpl</type>
@@ -353,30 +338,6 @@
<type>org.exoplatform.services.jcr.impl.ext.action.SessionActionCatalog</type>
</component>
- <!-- component>
- <key>org.exoplatform.services.database.HibernateService</key>
- <jmx-name>database:type=HibernateService</jmx-name>
-
<type>org.exoplatform.services.database.impl.HibernateServiceImpl</type>
- <init-params>
- <properties-param>
- <name>hibernate.properties</name>
- <description>Default Hibernate Service</description>
- <property name="hibernate.show_sql" value="false"
/>
- <property name="hibernate.cglib.use_reflection_optimizer"
value="true" />
- <property name="hibernate.connection.url"
value="jdbc:hsqldb:file:../temp/data/exodb" />
- <property name="hibernate.connection.driver_class"
value="org.hsqldb.jdbcDriver" />
- <property name="hibernate.connection.autocommit"
value="true" />
- <property name="hibernate.connection.username"
value="sa" />
- <property name="hibernate.connection.password"
value="" />
- <property name="hibernate.dialect"
value="org.hibernate.dialect.HSQLDialect" />
- <property name="hibernate.c3p0.min_size" value="5"
/>
- <property name="hibernate.c3p0.max_size" value="20"
/>
- <property name="hibernate.c3p0.timeout" value="1800"
/>
- <property name="hibernate.c3p0.max_statements"
value="50" />
- </properties-param>
- </init-params>
- </component -->
-
<component>
<key>org.exoplatform.services.database.creator.DBCreator</key>
<type>org.exoplatform.services.database.creator.DBCreator</type>
@@ -428,478 +389,6 @@
<type>org.exoplatform.services.jcr.ext.distribution.impl.DataDistributionManagerImpl</type>
</component>
- <!-- component>
- <key>org.exoplatform.services.organization.OrganizationService</key>
-
<type>org.exoplatform.services.organization.hibernate.OrganizationServiceImpl</type>
- </component>
-
-
- <external-component-plugins>
-
<target-component>org.exoplatform.services.database.HibernateService</target-component>
- <component-plugin>
- <name>add.hibernate.mapping</name>
- <set-method>addPlugin</set-method>
-
<type>org.exoplatform.services.database.impl.AddHibernateMappingPlugin</type>
- <init-params>
- <values-param>
- <name>hibernate.mapping</name>
-
<value>org/exoplatform/services/organization/impl/UserImpl.hbm.xml</value>
-
<value>org/exoplatform/services/organization/impl/MembershipImpl.hbm.xml</value>
-
<value>org/exoplatform/services/organization/impl/GroupImpl.hbm.xml</value>
-
<value>org/exoplatform/services/organization/impl/MembershipTypeImpl.hbm.xml</value>
-
<value>org/exoplatform/services/organization/impl/UserProfileData.hbm.xml</value>
- </values-param>
- </init-params>
- </component-plugin>
- </external-component-plugins -->
-
- <!-- org service initializer, copied from ECM portal.war -->
- <!-- external-component-plugins>
-
<target-component>org.exoplatform.services.organization.OrganizationService</target-component>
- <component-plugin>
- <name>init.service.listener</name>
- <set-method>addListenerPlugin</set-method>
-
<type>org.exoplatform.services.organization.OrganizationDatabaseInitializer</type>
- <description>this listener populate organization data for the first
launch</description>
- <init-params>
- <value-param>
- <name>checkDatabaseAlgorithm</name>
- <description>check database</description>
- <value>entry</value>
- </value-param>
- <value-param>
- <name>printInformation</name>
- <description>Print information init database</description>
- <value>false</value>
- </value-param>
- <object-param>
- <name>configuration</name>
- <description>description</description>
- <object
type="org.exoplatform.services.organization.OrganizationConfig">
- <field name="membershipType">
- <collection type="java.util.ArrayList">
- <value>
- <object
type="org.exoplatform.services.organization.OrganizationConfig$MembershipType">
- <field name="type">
- <string>manager</string>
- </field>
- <field name="description">
- <string>manager membership type</string>
- </field>
- </object>
- </value>
- <value>
- <object
type="org.exoplatform.services.organization.OrganizationConfig$MembershipType">
- <field name="type">
- <string>member</string>
- </field>
- <field name="description">
- <string>member membership type</string>
- </field>
- </object>
- </value>
- <value>
- <object
type="org.exoplatform.services.organization.OrganizationConfig$MembershipType">
- <field name="type">
- <string>validator</string>
- </field>
- <field name="description">
- <string>validator membership type</string>
- </field>
- </object>
- </value>
- </collection>
- </field>
-
- <field name="group">
- <collection type="java.util.ArrayList">
- <value>
- <object
type="org.exoplatform.services.organization.OrganizationConfig$Group">
- <field name="name">
- <string>platform</string>
- </field>
- <field name="parentId">
- <string></string>
- </field>
- <field name="description">
- <string>the /platform group</string>
- </field>
- <field name="label">
- <string>Platform</string>
- </field>
- </object>
- </value>
- <value>
- <object
type="org.exoplatform.services.organization.OrganizationConfig$Group">
- <field name="name">
- <string>administrators</string>
- </field>
- <field name="parentId">
- <string>/platform</string>
- </field>
- <field name="description">
- <string>the /platform/administrators
group</string>
- </field>
- <field name="label">
- <string>Administrators</string>
- </field>
- </object>
- </value>
- <value>
- <object
type="org.exoplatform.services.organization.OrganizationConfig$Group">
- <field name="name">
- <string>users</string>
- </field>
- <field name="parentId">
- <string>/platform</string>
- </field>
- <field name="description">
- <string>the /platform/users group</string>
- </field>
- <field name="label">
- <string>Users</string>
- </field>
- </object>
- </value>
- <value>
- <object
type="org.exoplatform.services.organization.OrganizationConfig$Group">
- <field name="name">
- <string>guests</string>
- </field>
- <field name="parentId">
- <string>/platform</string>
- </field>
- <field name="description">
- <string>the /platform/guests group</string>
- </field>
- <field name="label">
- <string>Guests</string>
- </field>
- </object>
- </value>
- <value>
- <object
type="org.exoplatform.services.organization.OrganizationConfig$Group">
- <field name="name">
- <string>organization</string>
- </field>
- <field name="parentId">
- <string></string>
- </field>
- <field name="description">
- <string>the organization group</string>
- </field>
- <field name="label">
- <string>Organization</string>
- </field>
- </object>
- </value>
- <value>
- <object
type="org.exoplatform.services.organization.OrganizationConfig$Group">
- <field name="name">
- <string>management</string>
- </field>
- <field name="parentId">
- <string>/organization</string>
- </field>
- <field name="description">
- <string>the /organization/management
group</string>
- </field>
- <field name="label">
- <string>Management</string>
- </field>
- </object>
- </value>
- <value>
- <object
type="org.exoplatform.services.organization.OrganizationConfig$Group">
- <field name="name">
- <string>executive-board</string>
- </field>
- <field name="parentId">
- <string>/organization/management</string>
- </field>
- <field name="description">
- <string>the
/organization/management/executive-board group</string>
- </field>
- <field name="label">
- <string>Executive Board</string>
- </field>
- </object>
- </value>
- <value>
- <object
type="org.exoplatform.services.organization.OrganizationConfig$Group">
- <field name="name">
- <string>human-resources</string>
- </field>
- <field name="parentId">
- <string>/organization/management</string>
- </field>
- <field name="description">
- <string>the
/organization/management/human-resource group</string>
- </field>
- <field name="label">
- <string>Human Resources</string>
- </field>
- </object>
- </value>
- <value>
- <object
type="org.exoplatform.services.organization.OrganizationConfig$Group">
- <field name="name">
- <string>communication</string>
- </field>
- <field name="parentId">
- <string>/organization</string>
- </field>
- <field name="description">
- <string>the /organization/communication
group</string>
- </field>
- <field name="label">
- <string>Communication</string>
- </field>
- </object>
- </value>
- <value>
- <object
type="org.exoplatform.services.organization.OrganizationConfig$Group">
- <field name="name">
- <string>marketing</string>
- </field>
- <field name="parentId">
-
<string>/organization/communication</string>
- </field>
- <field name="description">
- <string>the /organization/communication/marketing
group</string>
- </field>
- <field name="label">
- <string>Marketing</string>
- </field>
- </object>
- </value>
- <value>
- <object
type="org.exoplatform.services.organization.OrganizationConfig$Group">
- <field name="name">
- <string>press-and-media</string>
- </field>
- <field name="parentId">
-
<string>/organization/communication</string>
- </field>
- <field name="description">
- <string>the
/organization/communication/press-and-media group</string>
- </field>
- <field name="label">
- <string>Press and Media</string>
- </field>
- </object>
- </value>
- <value>
- <object
type="org.exoplatform.services.organization.OrganizationConfig$Group">
- <field name="name">
- <string>operations</string>
- </field>
- <field name="parentId">
- <string>/organization</string>
- </field>
- <field name="description">
- <string>the /organization/operations and media
group</string>
- </field>
- <field name="label">
- <string>Operations</string>
- </field>
- </object>
- </value>
- <value>
- <object
type="org.exoplatform.services.organization.OrganizationConfig$Group">
- <field name="name">
- <string>sales</string>
- </field>
- <field name="parentId">
- <string>/organization/operations</string>
- </field>
- <field name="description">
- <string>the /organization/operations/sales
group</string>
- </field>
- <field name="label">
- <string>Sales</string>
- </field>
- </object>
- </value>
- <value>
- <object
type="org.exoplatform.services.organization.OrganizationConfig$Group">
- <field name="name">
- <string>finances</string>
- </field>
- <field name="parentId">
- <string>/organization/operations</string>
- </field>
- <field name="description">
- <string>the /organization/operations/finances
group</string>
- </field>
- <field name="label">
- <string>Finances</string>
- </field>
- </object>
- </value>
- <value>
- <object
type="org.exoplatform.services.organization.OrganizationConfig$Group">
- <field name="name">
- <string>customers</string>
- </field>
- <field name="parentId">
- <string></string>
- </field>
- <field name="description">
- <string>the /customers group</string>
- </field>
- <field name="label">
- <string>Customers</string>
- </field>
- </object>
- </value>
- <value>
- <object
type="org.exoplatform.services.organization.OrganizationConfig$Group">
- <field name="name">
- <string>partners</string>
- </field>
- <field name="parentId">
- <string></string>
- </field>
- <field name="description">
- <string>the /partners group</string>
- </field>
- <field name="label">
- <string>Partners</string>
- </field>
- </object>
- </value>
- </collection>
- </field>
-
- <field name="user">
- <collection type="java.util.ArrayList">
- <value>
- <object
type="org.exoplatform.services.organization.OrganizationConfig$User">
- <field name="userName">
- <string>root</string>
- </field>
- <field name="password">
- <string>exo</string>
- </field>
- <field name="firstName">
- <string>Root</string>
- </field>
- <field name="lastName">
- <string>Root</string>
- </field>
- <field name="email">
- <string>root@localhost</string>
- </field>
- <field name="groups">
- <string>
- *:/platform/administrators,*:/platform/users,
- member:/organization/management/executive-board
- </string>
- </field>
- </object>
- </value>
-
- <value>
- <object
type="org.exoplatform.services.organization.OrganizationConfig$User">
- <field name="userName">
- <string>john</string>
- </field>
- <field name="password">
- <string>exo</string>
- </field>
- <field name="firstName">
- <string>John</string>
- </field>
- <field name="lastName">
- <string>Anthony</string>
- </field>
- <field name="email">
- <string>john@localhost</string>
- </field>
- <field name="groups">
- <string>
-
validator:/platform/administrators,manager:/platform/users,
- *:/organization/management/executive-board,
- manager:/organization/management/executive-board,
validator:/organization/management/executive-board
- </string>
- </field>
- </object>
- </value>
- <value>
- <object
type="org.exoplatform.services.organization.OrganizationConfig$User">
- <field name="userName">
- <string>marry</string>
- </field>
- <field name="password">
- <string>exo</string>
- </field>
- <field name="firstName">
- <string>Marry</string>
- </field>
- <field name="lastName">
- <string>Kelly</string>
- </field>
- <field name="email">
- <string>marry@localhost</string>
- </field>
- <field name="groups">
- <string>member:/platform/users</string>
- </field>
- </object>
- </value>
- <value>
- <object
type="org.exoplatform.services.organization.OrganizationConfig$User">
- <field name="userName">
- <string>demo</string>
- </field>
- <field name="password">
- <string>exo</string>
- </field>
- <field name="firstName">
- <string>Demo</string>
- </field>
- <field name="lastName">
- <string>exo</string>
- </field>
- <field name="email">
- <string>demo@localhost</string>
- </field>
- <field name="groups">
- <string>member:/platform/users</string>
- </field>
- </object>
- </value>
- <value>
- <object
type="org.exoplatform.services.organization.OrganizationConfig$User">
- <field name="userName">
- <string>james</string>
- </field>
- <field name="password">
- <string>exo</string>
- </field>
- <field name="firstName">
- <string>James</string>
- </field>
- <field name="lastName">
- <string>Anderson</string>
- </field>
- <field name="email">
- <string>james@localhost</string>
- </field>
- <field name="groups">
-
<string>*:/organization/management/human-resources,member:/platform/users</string>
- </field>
- </object>
- </value>
- </collection>
- </field>
- </object>
- </object-param>
- </init-params>
- </component-plugin>
- </external-component-plugins -->
-
<component>
<type>org.exoplatform.services.jcr.impl.ext.action.SessionActionCatalog</type>
<component-plugins>
Added: jcr/trunk/exo.jcr.component.ext/src/test/resources/test-mysql.sql
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/test/resources/test-mysql.sql
(rev 0)
+++ jcr/trunk/exo.jcr.component.ext/src/test/resources/test-mysql.sql 2011-07-01 09:49:42
UTC (rev 4572)
@@ -0,0 +1,4 @@
+CREATE DATABASE ${database};
+USE ${database};
+CREATE USER '${username}' IDENTIFIED BY '${password}';
+GRANT SELECT,INSERT,UPDATE,DELETE ON ${database}.* TO '${username}';
\ No newline at end of file
Modified:
jcr/trunk/exo.jcr.docs/exo.jcr.docs.developer/en/src/main/docbook/en-US/modules/jcr/repository-creation-service.xml
===================================================================
---
jcr/trunk/exo.jcr.docs/exo.jcr.docs.developer/en/src/main/docbook/en-US/modules/jcr/repository-creation-service.xml 2011-07-01
08:57:52 UTC (rev 4571)
+++
jcr/trunk/exo.jcr.docs/exo.jcr.docs.developer/en/src/main/docbook/en-US/modules/jcr/repository-creation-service.xml 2011-07-01
09:49:42 UTC (rev 4572)
@@ -1,209 +1,239 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
-"http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
-<chapter id="JCR.RepositoryCreationService">
- <?dbhtml filename="ch-repository-creation-service.html"?>
-
- <title>RepositoryCreationService</title>
-
- <section>
- <title>Intro</title>
-
- <para>RepositoryCreationService is the service for creation repositories
- in runtime. The service can be used in standalone or cluster
- environment.</para>
- </section>
-
- <section>
- <title>Dependencies</title>
-
- <para>RepositoryConfigurationService depends to next components:</para>
-
- <itemizedlist>
- <listitem>
- <para><link
linkend="Core.DBCreatorService">DBCreator</link> -
- DBCreator used to create new database for each unbinded datasource.
- </para>
- </listitem>
-
- <listitem>
- <para><link
linkend="JCR.BackupService">BackupManager</link> -
- BackupManager used to created repository from backup.</para>
- </listitem>
-
- <listitem>
- <para><link
linkend="Kernel.RPCService">RPCService</link> - RPCService
- used for communication between cluster-nodes </para>
-
- <note>
- <para>RPCService may not be configured - in this case,
- RepositoryService will work as standalone service.</para>
- </note>
- </listitem>
- </itemizedlist>
- </section>
-
- <section>
- <title>How it works</title>
-
- <itemizedlist>
- <listitem>
- <para> User executes reserveRepositoryName(String repositoryName) -
- client-node calls coordinator-node to reserve repositoryName. If this
- name is already reserved or repository with this name exist,
- client-node will fetch RepositoryCreationException. If not Client will
- get token string. </para>
- </listitem>
-
- <listitem>
- <para>than user executes createRepository(String backupId,
- RepositoryEntry rEntry, String token). Coordinator-node checks the
- token, and creates Repository. </para>
- </listitem>
-
- <listitem>
- <para> whan repository become created - user-node broadcast message to
- all clusterNodes with RepositoryEntry, so each cluster node starts new
- Repository. </para>
- </listitem>
- </itemizedlist>
-
- <para>There is two ways to create repositry: make it in single step - just
- call createRepository(String backupId, RepositoryEntry); or reserve
- repositoryName at first (reserveRepositoryName(String repositoryName)),
- than create reserved repository (createRepository(String backupId,
- RepositoryEntry rEntry, String token)). </para>
- </section>
-
- <section>
- <title>Configuration</title>
-
- <para>RepositoryCreationService configuration</para>
-
- <programlisting language="xml"><component>
-
<key>org.exoplatform.services.jcr.ext.backup.BackupManager</key>
-
<type>org.exoplatform.services.jcr.ext.backup.impl.BackupManagerImpl</type>
- <init-params>
- <properties-param>
- <name>backup-properties</name>
- <property name="default-incremental-job-period"
value="3600" /><!-- set default incremental periond = 60 minutes
-->
- <property name="full-backup-type"
value="org.exoplatform.services.jcr.ext.backup.impl.fs.FullBackupJob" />
- <property name="incremental-backup-type"
value="org.exoplatform.services.jcr.ext.backup.impl.fs.IncrementalBackupJob"
/>
- <property name="backup-dir" value="target/backup"
/>
- </properties-param>
- </init-params>
-</component>
-
-<component>
-
<key>org.exoplatform.services.database.creator.DBCreator</key>
-
<type>org.exoplatform.services.database.creator.DBCreator</type>
- <init-params>
- <properties-param>
- <name>db-connection</name>
- <description>database connection
properties</description>
- <property name="driverClassName"
value="org.hsqldb.jdbcDriver" />
- <property name="url"
value="jdbc:hsqldb:file:target/temp/data/" />
- <property name="username" value="sa" />
- <property name="password" value="" />
- </properties-param>
- <properties-param>
- <name>db-creation</name>
- <description>database creation
properties</description>
- <property name="scriptPath"
value="src/test/resources/test.sql" />
- <property name="username" value="sa" />
- <property name="password" value="" />
- </properties-param>
- </init-params>
-</component>
-
-<component>
- <key>org.exoplatform.services.rpc.RPCService</key>
-
<type>org.exoplatform.services.rpc.impl.RPCServiceImpl</type>
- <init-params>
- <value-param>
- <name>jgroups-configuration</name>
- <value>jar:/conf/standalone/udp-mux.xml</value>
- </value-param>
- <value-param>
- <name>jgroups-cluster-name</name>
- <value>RPCService-Cluster</value>
- </value-param>
- <value-param>
- <name>jgroups-default-timeout</name>
- <value>0</value>
- </value-param>
- </init-params>
-</component>
-
-<component>
-
<key>org.exoplatform.services.jcr.ext.repository.creation.RepositoryCreationService</key>
- <type>
- org.exoplatform.services.jcr.ext.repository.creation.RepositoryCreationServiceImpl
- </type>
-</component></programlisting>
- </section>
-
- <section>
- <title>Repsitory Interface</title>
-
- <programlisting language="java">public interface
RepositoryCreationService
-{
- /**
- * Reserves, validates and creates repository in a simplified form.
- *
- * @param rEntry - repository Entry - note that datasource must not exist.
- * @param backupId - backup id
- * @throws RepositoryConfigurationException
- * if some exception occurred during repository creation or repository name
is absent in reserved list
- * @throws RepositoryCreationServiceException
- * if some exception occurred during repository creation or repository name
is absent in reserved list
- */
- void createRepository(String backupId, RepositoryEntry rEntry) throws
RepositoryConfigurationException,
- RepositoryCreationException;
-
- /**
- * Reserve repository name to prevent repository creation with same name from other
place in same time
- * via this service.
- *
- * @param repositoryName - repositoryName
- * @return repository token. Anyone obtaining a token can later create a repository of
reserved name.
- * @throws RepositoryCreationServiceException if can't reserve name
- */
- String reserveRepositoryName(String repositoryName) throws
RepositoryCreationException;
-
- /**
- * Creates repository, using token of already reserved repository name. Good for
cases, when repository creation should be delayed or
- * made asynchronously in dedicated thread.
- *
- * @param rEntry - repository entry - note, that datasource must not exist
- * @param backupId - backup id
- * @param rToken - token
- * @throws RepositoryConfigurationException
- * if some exception occurred during repository creation or repository name
is absent in reserved list
- * @throws RepositoryCreationServiceException
- * if some exception occurred during repository creation or repository name
is absent in reserved list
- */
- void createRepository(String backupId, RepositoryEntry rEntry, String rToken)
- throws RepositoryConfigurationException, RepositoryCreationException;
-}</programlisting>
- </section>
-
- <section>
- <title>Conclusions and restrictions</title>
-
- <itemizedlist>
- <listitem>
- <para>Each datasource in RepositoryEntry of new Repository must have
- unbinded datasources. Thats mean, such datasource must have not
- databases behind them. This restriction exists to avoid corruption of
- existing repositories data. </para>
- </listitem>
-
- <listitem>
- <para>RPCService is optional component, but without it,
- RepositoryCreatorService can not communicate with other cluster-nodes
- and works as standalone.</para>
- </listitem>
- </itemizedlist>
- </section>
-</chapter>
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
+"http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
+<chapter id="JCR.RepositoryCreationService">
+ <?dbhtml filename="ch-repository-creation-service.html"?>
+
+ <title>RepositoryCreationService</title>
+
+ <section>
+ <title>Intro</title>
+
+ <para>RepositoryCreationService is the service for creation repositories
+ in runtime. The service can be used in standalone or cluster
+ environment.</para>
+ </section>
+
+ <section>
+ <title>Dependencies</title>
+
+ <para>RepositoryConfigurationService depends to next components:</para>
+
+ <itemizedlist>
+ <listitem>
+ <para><link
linkend="Core.DBCreatorService">DBCreator</link> -
+ DBCreator used to create new database for each unbinded
+ datasource.</para>
+ </listitem>
+
+ <listitem>
+ <para><link
linkend="JCR.BackupService">BackupManager</link> -
+ BackupManager used to created repository from backup.</para>
+ </listitem>
+
+ <listitem>
+ <para><link
linkend="Kernel.RPCService">RPCService</link> - RPCService
+ used for communication between cluster-nodes</para>
+
+ <note>
+ <para>RPCService may not be configured - in this case,
+ RepositoryService will work as standalone service.</para>
+ </note>
+ </listitem>
+ </itemizedlist>
+ </section>
+
+ <section>
+ <title>How it works</title>
+
+ <itemizedlist>
+ <listitem>
+ <para>User executes reserveRepositoryName(String repositoryName) -
+ client-node calls coordinator-node to reserve repositoryName. If this
+ name is already reserved or repository with this name exist,
+ client-node will fetch RepositoryCreationException. If not Client will
+ get token string.</para>
+ </listitem>
+
+ <listitem>
+ <para>than user executes createRepository(String backupId,
+ RepositoryEntry rEntry, String token). Coordinator-node checks the
+ token, and creates Repository.</para>
+ </listitem>
+
+ <listitem>
+ <para>whan repository become created - user-node broadcast message to
+ all clusterNodes with RepositoryEntry, so each cluster node starts new
+ Repository.</para>
+ </listitem>
+ </itemizedlist>
+
+ <para>There is two ways to create repositry: make it in single step - just
+ call createRepository(String backupId, RepositoryEntry); or reserve
+ repositoryName at first (reserveRepositoryName(String repositoryName)),
+ than create reserved repository (createRepository(String backupId,
+ RepositoryEntry rEntry, String token)).</para>
+ </section>
+
+ <section>
+ <title>Configuration</title>
+
+ <para>RepositoryCreationService configuration</para>
+
+ <programlisting language="xml"><component>
+
<key>org.exoplatform.services.jcr.ext.backup.BackupManager</key>
+
<type>org.exoplatform.services.jcr.ext.backup.impl.BackupManagerImpl</type>
+ <init-params>
+ <properties-param>
+ <name>backup-properties</name>
+ <property name="default-incremental-job-period"
value="3600" /><!-- set default incremental periond = 60 minutes
-->
+ <property name="full-backup-type"
value="org.exoplatform.services.jcr.ext.backup.impl.fs.FullBackupJob" />
+ <property name="incremental-backup-type"
value="org.exoplatform.services.jcr.ext.backup.impl.fs.IncrementalBackupJob"
/>
+ <property name="backup-dir" value="target/backup"
/>
+ </properties-param>
+ </init-params>
+</component>
+
+<component>
+
<key>org.exoplatform.services.database.creator.DBCreator</key>
+
<type>org.exoplatform.services.database.creator.DBCreator</type>
+ <init-params>
+ <properties-param>
+ <name>db-connection</name>
+ <description>database connection
properties</description>
+ <property name="driverClassName"
value="org.hsqldb.jdbcDriver" />
+ <property name="url"
value="jdbc:hsqldb:file:target/temp/data/" />
+ <property name="username" value="sa" />
+ <property name="password" value="" />
+ </properties-param>
+ <properties-param>
+ <name>db-creation</name>
+ <description>database creation
properties</description>
+ <property name="scriptPath"
value="src/test/resources/test.sql" />
+ <property name="username" value="sa" />
+ <property name="password" value="" />
+ </properties-param>
+ </init-params>
+</component>
+
+<component>
+ <key>org.exoplatform.services.rpc.RPCService</key>
+
<type>org.exoplatform.services.rpc.impl.RPCServiceImpl</type>
+ <init-params>
+ <value-param>
+ <name>jgroups-configuration</name>
+ <value>jar:/conf/standalone/udp-mux.xml</value>
+ </value-param>
+ <value-param>
+ <name>jgroups-cluster-name</name>
+ <value>RPCService-Cluster</value>
+ </value-param>
+ <value-param>
+ <name>jgroups-default-timeout</name>
+ <value>0</value>
+ </value-param>
+ </init-params>
+</component>
+
+<component>
+
<key>org.exoplatform.services.jcr.ext.repository.creation.RepositoryCreationService</key>
+ <type>
+ org.exoplatform.services.jcr.ext.repository.creation.RepositoryCreationServiceImpl
+ </type>
+</component></programlisting>
+ </section>
+
+ <section>
+ <title>Repsitory Interface</title>
+
+ <programlisting language="java">public interface
RepositoryCreationService
+{
+ /**
+ * Reserves, validates and creates repository in a simplified form.
+ *
+ * @param rEntry - repository Entry - note that datasource must not exist.
+ * @param backupId - backup id
+ * @param creationProps - storage creation properties
+ * @throws RepositoryConfigurationException
+ * if some exception occurred during repository creation or repository name
is absent in reserved list
+ * @throws RepositoryCreationServiceException
+ * if some exception occurred during repository creation or repository name
is absent in reserved list
+ */
+ void createRepository(String backupId, RepositoryEntry rEntry,
StorageCreationProperties creationProps)
+ throws RepositoryConfigurationException, RepositoryCreationException;n
+
+ /**
+ * Reserves, validates and creates repository in a simplified form.
+ *
+ * @param rEntry - repository Entry - note that datasource must not exist.
+ * @param backupId - backup id
+ * @throws RepositoryConfigurationException
+ * if some exception occurred during repository creation or repository name
is absent in reserved list
+ * @throws RepositoryCreationServiceException
+ * if some exception occurred during repository creation or repository name
is absent in reserved list
+ */
+ void createRepository(String backupId, RepositoryEntry rEntry) throws
RepositoryConfigurationException,
+ RepositoryCreationException;
+
+ /**
+ * Reserve repository name to prevent repository creation with same name from other
place in same time
+ * via this service.
+ *
+ * @param repositoryName - repositoryName
+ * @return repository token. Anyone obtaining a token can later create a repository of
reserved name.
+ * @throws RepositoryCreationServiceException if can't reserve name
+ */
+ String reserveRepositoryName(String repositoryName) throws
RepositoryCreationException;
+
+ /**
+ * Creates repository, using token of already reserved repository name.
+ * Good for cases, when repository creation should be delayed or made asynchronously
in dedicated thread.
+ *
+ * @param rEntry - repository entry - note, that datasource must not exist
+ * @param backupId - backup id
+ * @param rToken - token
+ * @param creationProps - storage creation properties
+ * @throws RepositoryConfigurationException
+ * if some exception occurred during repository creation or repository name
is absent in reserved list
+ * @throws RepositoryCreationServiceException
+ * if some exception occurred during repository creation or repository name
is absent in reserved list
+ */
+ void createRepository(String backupId, RepositoryEntry rEntry, String rToken,
StorageCreationProperties creationProps)
+ throws RepositoryConfigurationException, RepositoryCreationException;
+
+ /**
+ * Creates repository, using token of already reserved repository name. Good for
cases, when repository creation should be delayed or
+ * made asynchronously in dedicated thread.
+ *
+ * @param rEntry - repository entry - note, that datasource must not exist
+ * @param backupId - backup id
+ * @param rToken - token
+ * @throws RepositoryConfigurationException
+ * if some exception occurred during repository creation or repository name
is absent in reserved list
+ * @throws RepositoryCreationServiceException
+ * if some exception occurred during repository creation or repository name
is absent in reserved list
+ */
+ void createRepository(String backupId, RepositoryEntry rEntry, String rToken)
+ throws RepositoryConfigurationException, RepositoryCreationException;
+}</programlisting>
+ </section>
+
+ <section>
+ <title>Conclusions and restrictions</title>
+
+ <itemizedlist>
+ <listitem>
+ <para>Each datasource in RepositoryEntry of new Repository must have
+ unbinded datasources. Thats mean, such datasource must have not
+ databases behind them. This restriction exists to avoid corruption of
+ existing repositories data.</para>
+ </listitem>
+
+ <listitem>
+ <para>RPCService is optional component, but without it,
+ RepositoryCreatorService can not communicate with other cluster-nodes
+ and works as standalone.</para>
+ </listitem>
+ </itemizedlist>
+ </section>
+</chapter>