exo-jcr SVN: r4577 - kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/naming.
by do-not-reply@jboss.org
Author: tolusha
Date: 2011-07-01 08:28:11 -0400 (Fri, 01 Jul 2011)
New Revision: 4577
Modified:
kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/naming/InitialContextBinder.java
Log:
EXOJCR-1397: Fix java doc
Modified: kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/naming/InitialContextBinder.java
===================================================================
--- kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/naming/InitialContextBinder.java 2011-07-01 12:24:54 UTC (rev 4576)
+++ kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/naming/InitialContextBinder.java 2011-07-01 12:28:11 UTC (rev 4577)
@@ -156,7 +156,7 @@
}
/**
- * Returns reference associated with bindName.
+ * Returns reference associated with defined name.
*
* @param bindName the name on which the reference was binded.
*/
12 years, 10 months
exo-jcr SVN: r4576 - jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/repository/creation.
by do-not-reply@jboss.org
Author: tolusha
Date: 2011-07-01 08:24:54 -0400 (Fri, 01 Jul 2011)
New Revision: 4576
Modified:
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/repository/creation/RepositoryCreationServiceImpl.java
Log:
EXOJCR-1397: Create method which will return db configuration of repository
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 12:23:41 UTC (rev 4575)
+++ jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/repository/creation/RepositoryCreationServiceImpl.java 2011-07-01 12:24:54 UTC (rev 4576)
@@ -505,7 +505,7 @@
// bind data-source
try
{
- initialContextInitializer.bind(dataSource, "javax.sql.DataSource",
+ initialContextInitializer.getInitialContextBinder().bind(dataSource, "javax.sql.DataSource",
"org.apache.commons.dbcp.BasicDataSourceFactory", null, refAddr);
}
catch (NamingException e)
@@ -604,7 +604,7 @@
// bind data-source
try
{
- initialContextInitializer.bind(dataSource, "javax.sql.DataSource",
+ initialContextInitializer.getInitialContextBinder().bind(dataSource, "javax.sql.DataSource",
"org.apache.commons.dbcp.BasicDataSourceFactory", null, refAddr);
}
catch (NamingException e)
12 years, 10 months
exo-jcr SVN: r4575 - kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/naming.
by do-not-reply@jboss.org
Author: tolusha
Date: 2011-07-01 08:23:41 -0400 (Fri, 01 Jul 2011)
New Revision: 4575
Modified:
kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/naming/InitialContextBinder.java
kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/naming/InitialContextInitializer.java
Log:
EXOJCR-1397: Create method which will return db configuration of repository
Modified: kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/naming/InitialContextBinder.java
===================================================================
--- kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/naming/InitialContextBinder.java 2011-07-01 11:39:42 UTC (rev 4574)
+++ kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/naming/InitialContextBinder.java 2011-07-01 12:23:41 UTC (rev 4575)
@@ -155,6 +155,16 @@
saveBindings();
}
+ /**
+ * Returns reference associated with bindName.
+ *
+ * @param bindName the name on which the reference was binded.
+ */
+ public Reference getReference(String bindName)
+ {
+ return bindings.get(bindName);
+ }
+
private void bind(String bindName, Reference reference) throws NamingException
{
try
Modified: kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/naming/InitialContextInitializer.java
===================================================================
--- kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/naming/InitialContextInitializer.java 2011-07-01 11:39:42 UTC (rev 4574)
+++ kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/naming/InitialContextInitializer.java 2011-07-01 12:23:41 UTC (rev 4575)
@@ -34,8 +34,6 @@
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
-import java.util.Map;
-import java.util.Set;
import javax.naming.Context;
import javax.naming.InitialContext;
@@ -233,50 +231,10 @@
}
/**
- * Constructs references from params, binds in initial contexts and persists list of all binded
- * references into file.
- *
- * @param bindName
- * bind name
- * @param className
- * class name
- * @param factory
- * factory name
- * @param factoryLocation
- * factory location
- * @param refAddr
- * map of references's properties
- *
- * @throws NamingException
- * if error occurs due to binding
- * @throws XMLStreamException
- * @throws FileNotFoundException
+ * Returns InitialContextBinder.
*/
- public void bind(String bindName, String className, String factory, String factoryLocation,
- Map<String, String> refAddr) throws NamingException, FileNotFoundException, XMLStreamException
+ public InitialContextBinder getInitialContextBinder()
{
- if (LOG.isDebugEnabled())
- {
- StringBuilder refAddrString = new StringBuilder();
- refAddrString.append('{');
- Set<Map.Entry<String, String>> refs = refAddr.entrySet();
- int i = 1;
- for (Map.Entry<String, String> ent : refs)
- {
- refAddrString.append(ent.getKey());
- refAddrString.append('=');
- refAddrString.append(ent.getValue());
- if (i < refs.size())
- {
- refAddrString.append(' ');
- }
- i++;
- }
- refAddrString.append('}');
- LOG.debug("Bind: " + bindName + " class-name:" + className + " factory:" + factory + " factoryLocation:"
- + factoryLocation + " refAddr:" + refAddrString);
- }
-
- binder.bind(bindName, className, factory, factoryLocation, refAddr);
+ return binder;
}
}
12 years, 10 months
exo-jcr SVN: r4574 - in kernel/trunk/exo.kernel.container/src: test/java/org/exoplatform/container and 1 other directory.
by do-not-reply@jboss.org
Author: nzamosenchuk
Date: 2011-07-01 07:39:42 -0400 (Fri, 01 Jul 2011)
New Revision: 4574
Modified:
kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/management/ManageableContainer.java
kernel/trunk/exo.kernel.container/src/test/java/org/exoplatform/container/TestExoContainer.java
Log:
EXOJCR-1068 : fixing the test
Modified: kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/management/ManageableContainer.java
===================================================================
--- kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/management/ManageableContainer.java 2011-07-01 09:50:10 UTC (rev 4573)
+++ kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/management/ManageableContainer.java 2011-07-01 11:39:42 UTC (rev 4574)
@@ -234,11 +234,11 @@
@Override
public ComponentAdapter unregisterComponent(Object componentKey)
{
- ComponentAdapter adapter = getComponentAdapter(componentKey);
+ Object componentInstance = getComponentInstance(componentKey);
- if (managementContext != null && adapter != null)
+ if (managementContext != null && componentInstance != null)
{
- managementContext.unregister(adapter.getComponentInstance(this));
+ managementContext.unregister(componentInstance);
}
return super.unregisterComponent(componentKey);
}
Modified: kernel/trunk/exo.kernel.container/src/test/java/org/exoplatform/container/TestExoContainer.java
===================================================================
--- kernel/trunk/exo.kernel.container/src/test/java/org/exoplatform/container/TestExoContainer.java 2011-07-01 09:50:10 UTC (rev 4573)
+++ kernel/trunk/exo.kernel.container/src/test/java/org/exoplatform/container/TestExoContainer.java 2011-07-01 11:39:42 UTC (rev 4574)
@@ -491,28 +491,40 @@
public void destroyContainer(ExoContainer container) throws Exception
{
MyCounter counter = (MyCounter)container.getComponentInstanceOfType(MyCounter.class);
- if (counter != null) counter.destroy.add(this);
+ if (counter != null)
+ {
+ counter.destroy.add(this);
+ }
}
@Override
public void initContainer(ExoContainer container) throws Exception
{
MyCounter counter = (MyCounter)container.getComponentInstanceOfType(MyCounter.class);
- if (counter != null) counter.init.add(this);
+ if (counter != null)
+ {
+ counter.init.add(this);
+ }
}
@Override
public void startContainer(ExoContainer container) throws Exception
{
MyCounter counter = (MyCounter)container.getComponentInstanceOfType(MyCounter.class);
- if (counter != null) counter.start.add(this);
+ if (counter != null)
+ {
+ counter.start.add(this);
+ }
}
@Override
public void stopContainer(ExoContainer container) throws Exception
{
MyCounter counter = (MyCounter)container.getComponentInstanceOfType(MyCounter.class);
- if (counter != null) counter.stop.add(this);
+ if (counter != null)
+ {
+ counter.stop.add(this);
+ }
}
}
@@ -530,28 +542,40 @@
public void destroyContainer(ExoContainer container) throws Exception
{
MyCounter counter = (MyCounter)container.getComponentInstanceOfType(MyCounter.class);
- if (counter != null) counter.destroy.add(this);
+ if (counter != null)
+ {
+ counter.destroy.add(this);
+ }
}
@Override
public void initContainer(ExoContainer container) throws Exception
{
MyCounter counter = (MyCounter)container.getComponentInstanceOfType(MyCounter.class);
- if (counter != null) counter.init.add(this);
+ if (counter != null)
+ {
+ counter.init.add(this);
+ }
}
@Override
public void startContainer(ExoContainer container) throws Exception
{
MyCounter counter = (MyCounter)container.getComponentInstanceOfType(MyCounter.class);
- if (counter != null) counter.start.add(this);
+ if (counter != null)
+ {
+ counter.start.add(this);
+ }
}
@Override
public void stopContainer(ExoContainer container) throws Exception
{
MyCounter counter = (MyCounter)container.getComponentInstanceOfType(MyCounter.class);
- if (counter != null) counter.stop.add(this);
+ if (counter != null)
+ {
+ counter.stop.add(this);
+ }
}
}
@@ -567,28 +591,40 @@
public void destroyContainer(ExoContainer container) throws Exception
{
MyCounter counter = (MyCounter)container.getComponentInstanceOfType(MyCounter.class);
- if (counter != null) counter.destroy.add(this);
+ if (counter != null)
+ {
+ counter.destroy.add(this);
+ }
}
@Override
public void initContainer(ExoContainer container) throws Exception
{
MyCounter counter = (MyCounter)container.getComponentInstanceOfType(MyCounter.class);
- if (counter != null) counter.init.add(this);
+ if (counter != null)
+ {
+ counter.init.add(this);
+ }
}
@Override
public void startContainer(ExoContainer container) throws Exception
{
MyCounter counter = (MyCounter)container.getComponentInstanceOfType(MyCounter.class);
- if (counter != null) counter.start.add(this);
+ if (counter != null)
+ {
+ counter.start.add(this);
+ }
}
@Override
public void stopContainer(ExoContainer container) throws Exception
{
MyCounter counter = (MyCounter)container.getComponentInstanceOfType(MyCounter.class);
- if (counter != null) counter.stop.add(this);
+ if (counter != null)
+ {
+ counter.stop.add(this);
+ }
}
}
@@ -636,7 +672,7 @@
public Object getComponentInstance(PicoContainer arg0) throws PicoInitializationException,
PicoIntrospectionException
{
- throw (PicoInitializationException)new Exception();
+ return "testKey";
}
public Class getComponentImplementation()
@@ -722,7 +758,9 @@
public void init()
{
if (!c2.started)
+ {
throw new IllegalStateException("C2 should be started");
+ }
}
}
12 years, 10 months
exo-jcr SVN: r4573 - jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/repository/creation/cluster.
by do-not-reply@jboss.org
Author: tolusha
Date: 2011-07-01 05:50:10 -0400 (Fri, 01 Jul 2011)
New Revision: 4573
Added:
jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/repository/creation/cluster/TestRepositoryCreationServiceInClusterNode1.java
jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/repository/creation/cluster/TestRepositoryCreationServiceInClusterNode2.java
Log:
EXOJCR-1398: Add cluster tests
Added: jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/repository/creation/cluster/TestRepositoryCreationServiceInClusterNode1.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/repository/creation/cluster/TestRepositoryCreationServiceInClusterNode1.java (rev 0)
+++ jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/repository/creation/cluster/TestRepositoryCreationServiceInClusterNode1.java 2011-07-01 09:50:10 UTC (rev 4573)
@@ -0,0 +1,117 @@
+/*
+ * Copyright (C) 2003-2010 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see<http://www.gnu.org/licenses/>.
+ */
+package org.exoplatform.services.jcr.ext.repository.creation.cluster;
+
+import org.exoplatform.services.jcr.RepositoryService;
+import org.exoplatform.services.jcr.config.RepositoryEntry;
+import org.exoplatform.services.jcr.config.WorkspaceEntry;
+import org.exoplatform.services.jcr.core.ManageableRepository;
+import org.exoplatform.services.jcr.ext.backup.AbstractBackupTestCase;
+import org.exoplatform.services.jcr.ext.backup.BackupManager;
+import org.exoplatform.services.jcr.ext.backup.ExtendedBackupManager;
+import org.exoplatform.services.jcr.ext.backup.RepositoryBackupChain;
+import org.exoplatform.services.jcr.ext.backup.RepositoryBackupConfig;
+import org.exoplatform.services.jcr.ext.repository.creation.DBCreationProperties;
+import org.exoplatform.services.jcr.ext.repository.creation.RepositoryCreationService;
+
+import java.io.File;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Created by The eXo Platform SAS.
+ *
+ * <br/>Date:
+ *
+ * @author <a href="karpenko.sergiy(a)gmail.com">Karpenko Sergiy</a>
+ * @version $Id: TestRepositoryCreationService.java 111 2008-11-11 11:11:11Z serg $
+ */
+public class TestRepositoryCreationServiceInClusterNode1 extends AbstractBackupTestCase
+{
+ public void testCreateRepositorySingleDBWithSpecificCreationProps() throws Exception
+ {
+ log.info("Node1: Waits the second node");
+ Thread.sleep(60000);
+
+ Map<String, String> connProps = new HashMap<String, String>();
+ connProps.put("driverClassName", "com.mysql.jdbc.Driver");
+ connProps.put("username", "root");
+ connProps.put("password", "24635457");
+
+ DBCreationProperties creationProps =
+ new DBCreationProperties("jdbc:mysql://localhost/", connProps,
+ "src/test/resources/test-mysql.sql", "user1", "pass1");
+
+ // 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 = "tenant_2";
+ String repoToken = creatorService.reserveRepositoryName(tenantName);
+
+ // restore
+ RepositoryEntry newRE =
+ helper.createRepositoryEntry(false, repository.getConfiguration().getSystemWorkspaceName(), tenantName);
+ newRE.setName(tenantName);
+
+ WorkspaceEntry newWSEntry = helper.createWorkspaceEntry(false, tenantName);
+ 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));
+
+ log.info("Node1: Repository has been created");
+ Thread.sleep(100000);
+ }
+
+ @Override
+ protected ExtendedBackupManager getBackupManager()
+ {
+ return getRDBMSBackupManager();
+ }
+}
Added: jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/repository/creation/cluster/TestRepositoryCreationServiceInClusterNode2.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/repository/creation/cluster/TestRepositoryCreationServiceInClusterNode2.java (rev 0)
+++ jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/repository/creation/cluster/TestRepositoryCreationServiceInClusterNode2.java 2011-07-01 09:50:10 UTC (rev 4573)
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2003-2010 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see<http://www.gnu.org/licenses/>.
+ */
+package org.exoplatform.services.jcr.ext.repository.creation.cluster;
+
+import org.exoplatform.services.jcr.core.ManageableRepository;
+import org.exoplatform.services.jcr.ext.backup.AbstractBackupTestCase;
+import org.exoplatform.services.jcr.ext.backup.ExtendedBackupManager;
+import org.exoplatform.services.jcr.impl.core.SessionImpl;
+
+/**
+ * Created by The eXo Platform SAS.
+ *
+ * <br/>Date:
+ *
+ * @author <a href="karpenko.sergiy(a)gmail.com">Karpenko Sergiy</a>
+ * @version $Id: TestRepositoryCreationService.java 111 2008-11-11 11:11:11Z serg $
+ */
+public class TestRepositoryCreationServiceInClusterNode2 extends AbstractBackupTestCase
+{
+ public void testCreateRepositorySingleDBWithSpecificCreationProps() throws Exception
+ {
+ log.info("Node2: Waits for the repository creation");
+ Thread.sleep(60000);
+
+ String tenantName = "tenant_2";
+
+ // check
+ ManageableRepository restoredRepository = repositoryService.getRepository(tenantName);
+ assertNotNull(restoredRepository);
+
+ SessionImpl session =
+ (SessionImpl)restoredRepository.login(credentials, restoredRepository.getConfiguration()
+ .getSystemWorkspaceName());
+ session.getRootNode();
+
+ log.info("Node2: test passed. I have root node");
+ Thread.sleep(100000);
+ }
+
+ @Override
+ protected ExtendedBackupManager getBackupManager()
+ {
+ return getRDBMSBackupManager();
+ }
+}
12 years, 10 months
exo-jcr SVN: r4572 - in jcr/trunk: exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/repository/creation and 5 other directories.
by do-not-reply@jboss.org
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>
12 years, 10 months
exo-jcr SVN: r4571 - in core/trunk/exo.core.component.database/src: test/java/org/exoplatform/services/database and 1 other directory.
by do-not-reply@jboss.org
Author: tolusha
Date: 2011-07-01 04:57:52 -0400 (Fri, 01 Jul 2011)
New Revision: 4571
Modified:
core/trunk/exo.core.component.database/src/main/java/org/exoplatform/services/database/creator/DBConnectionInfo.java
core/trunk/exo.core.component.database/src/main/java/org/exoplatform/services/database/creator/DBCreator.java
core/trunk/exo.core.component.database/src/test/java/org/exoplatform/services/database/TestDBCreator.java
Log:
EXOJCR-1398: Allow to initialize DBCreator with custome set of parameters
Modified: core/trunk/exo.core.component.database/src/main/java/org/exoplatform/services/database/creator/DBConnectionInfo.java
===================================================================
--- core/trunk/exo.core.component.database/src/main/java/org/exoplatform/services/database/creator/DBConnectionInfo.java 2011-07-01 08:50:58 UTC (rev 4570)
+++ core/trunk/exo.core.component.database/src/main/java/org/exoplatform/services/database/creator/DBConnectionInfo.java 2011-07-01 08:57:52 UTC (rev 4571)
@@ -30,13 +30,16 @@
{
private final Map<String, String> connectionProperties;
+ private final String dbName;
+
/**
* DBConnectionInfo constructor.
* @param connectionProperties
* connection properties
*/
- public DBConnectionInfo(Map<String, String> connectionProperties)
+ public DBConnectionInfo(String dbName, Map<String, String> connectionProperties)
{
+ this.dbName = dbName;
this.connectionProperties = connectionProperties;
}
@@ -44,4 +47,9 @@
{
return connectionProperties;
}
+
+ public String getDBName()
+ {
+ return dbName;
+ }
}
Modified: core/trunk/exo.core.component.database/src/main/java/org/exoplatform/services/database/creator/DBCreator.java
===================================================================
--- core/trunk/exo.core.component.database/src/main/java/org/exoplatform/services/database/creator/DBCreator.java 2011-07-01 08:50:58 UTC (rev 4570)
+++ core/trunk/exo.core.component.database/src/main/java/org/exoplatform/services/database/creator/DBCreator.java 2011-07-01 08:57:52 UTC (rev 4571)
@@ -46,22 +46,24 @@
public class DBCreator
{
- private final static String DB_CONNECTION = "db-connection";
+ private final static String CONNECTION_PROPERTIES = "db-connection";
- private final static String DB_DRIVER = "driverClassName";
+ private final static String DRIVER_NAME = "driverClassName";
- private final static String DB_URL = "url";
+ private final static String SERVER_URL = "url";
- private final static String DB_USERNAME = "username";
+ private final static String USERNAME = "username";
- private final static String DB_PASSWORD = "password";
+ private final static String PASSWORD = "password";
- private final static String DB_ORCL_INTERNAL_LOGON = "internal_logon";
+ private final static String DB_CREATION_PROPERTIES = "db-creation";
- private final static String DB_CREATION = "db-creation";
-
private final static String DB_SCRIPT_PATH = "scriptPath";
+ private final static String DB_USERNAME = "username";
+
+ private final static String DB_PASSWORD = "password";
+
/**
* Database template.
*/
@@ -110,34 +112,52 @@
* @configurationManager
* configuration manager instance
*/
- public DBCreator(InitParams params, ConfigurationManager configurationManager) throws ConfigurationException
+ public DBCreator(String serverUrl, Map<String, String> connectionProperties, String scriptPath, String dbUserName,
+ String dbPassword, ConfigurationManager cm) throws ConfigurationException
{
+ this.serverUrl = serverUrl;
+ this.connectionProperties = connectionProperties;
+ this.dbUserName = dbUserName;
+ this.dbPassword = dbPassword;
+ this.dbScript = findScriptResource(scriptPath, cm);
+ }
+
+ /**
+ * DBCreator constructor.
+ *
+ * @param params
+ * Initializations parameters
+ * @configurationManager
+ * configuration manager instance
+ */
+ public DBCreator(InitParams params, ConfigurationManager cm) throws ConfigurationException
+ {
if (params == null)
{
throw new ConfigurationException("Initializations parameters expected");
}
- PropertiesParam prop = params.getPropertiesParam(DB_CONNECTION);
+ PropertiesParam prop = params.getPropertiesParam(CONNECTION_PROPERTIES);
if (prop != null)
{
- if (prop.getProperty(DB_DRIVER) == null)
+ if (prop.getProperty(DRIVER_NAME) == null)
{
throw new ConfigurationException("driverClassName expected in db-connection properties section");
}
- serverUrl = prop.getProperty(DB_URL);
+ serverUrl = prop.getProperty(SERVER_URL);
if (serverUrl == null)
{
throw new ConfigurationException("url expected in db-connection properties section");
}
- if (prop.getProperty(DB_USERNAME) == null)
+ if (prop.getProperty(USERNAME) == null)
{
throw new ConfigurationException("username expected in db-connection properties section");
}
- if (prop.getProperty(DB_PASSWORD) == null)
+ if (prop.getProperty(PASSWORD) == null)
{
throw new ConfigurationException("password expected in db-connection properties section");
}
@@ -148,7 +168,7 @@
while (pit.hasNext())
{
Property p = pit.next();
- if (!p.getName().equalsIgnoreCase(DB_URL))
+ if (!p.getName().equalsIgnoreCase(SERVER_URL))
{
connectionProperties.put(p.getName(), p.getValue());
}
@@ -159,29 +179,13 @@
throw new ConfigurationException("db-connection properties expected in initializations parameters");
}
- prop = params.getPropertiesParam(DB_CREATION);
+ prop = params.getPropertiesParam(DB_CREATION_PROPERTIES);
if (prop != null)
{
String scriptPath = prop.getProperty(DB_SCRIPT_PATH);
if (scriptPath != null)
{
- String dbScript;
- try
- {
- dbScript = readScriptResource(configurationManager.getInputStream(scriptPath));
- }
- catch (Exception e)
- {
- try
- {
- dbScript = readScriptResource(PrivilegedFileHelper.fileInputStream(scriptPath));
- }
- catch (IOException ioe)
- {
- throw new ConfigurationException("Can't read script resource " + scriptPath, e);
- }
- }
- this.dbScript = dbScript;
+ this.dbScript = findScriptResource(scriptPath, cm);
}
else
{
@@ -217,43 +221,13 @@
* @throws DBCreatorException
* if any error occurs
*/
- public DBConnectionInfo createDatabase(String dbName) throws DBCreatorException
+ public DBConnectionInfo createDatabase(final String dbName) throws DBCreatorException
{
- Connection conn = null;
+ Connection conn = openConnection();
try
{
- Class.forName(connectionProperties.get(DB_DRIVER));
+ String dbProductName = getDBProductName(conn);
- conn = SecurityHelper.doPrivilegedSQLExceptionAction(new PrivilegedExceptionAction<Connection>()
- {
- public Connection run() throws Exception
- {
- return DriverManager.getConnection(serverUrl, connectionProperties.get(DB_USERNAME),
- connectionProperties.get(DB_PASSWORD));
- }
- });
- }
- catch (SQLException e)
- {
- throw new DBCreatorException("Can't establish the JDBC connection to database " + serverUrl, e);
- }
- catch (ClassNotFoundException e)
- {
- throw new DBCreatorException("Can't load the JDBC driver " + connectionProperties.get(DB_DRIVER), e);
- }
-
- String dbProductName;
- try
- {
- final Connection connection = conn;
- dbProductName = SecurityHelper.doPrivilegedSQLExceptionAction(new PrivilegedExceptionAction<String>()
- {
- public String run() throws Exception
- {
- return connection.getMetaData().getDatabaseProductName();
- }
- });
-
if (dbProductName.startsWith("Microsoft SQL Server") || dbProductName.startsWith("Adaptive Server Anywhere")
|| dbProductName.equals("Sybase SQL Server") || dbProductName.equals("Adaptive Server Enterprise"))
{
@@ -263,6 +237,8 @@
{
executeBatchMode(conn, dbName);
}
+
+ return constructDBConnectionInfo(dbName, dbProductName);
}
catch (SQLException e)
{
@@ -286,8 +262,6 @@
throw new DBCreatorException("Can't close connection", e);
}
}
-
- return constructDBConnectionInfo(dbName, dbProductName);
}
/**
@@ -296,49 +270,15 @@
* @param dbName
* new database name
* @throws DBCreatorException
- * if any error occurs
+ * if any error occurs or database is not available
*/
public DBConnectionInfo getDBConnectionInfo(String dbName) throws DBCreatorException
{
- Connection conn = null;
+ Connection conn = openConnection();
try
{
- Class.forName(connectionProperties.get(DB_DRIVER));
-
- conn = SecurityHelper.doPrivilegedSQLExceptionAction(new PrivilegedExceptionAction<Connection>()
- {
- public Connection run() throws Exception
- {
- return DriverManager.getConnection(serverUrl, connectionProperties.get(DB_USERNAME),
- connectionProperties.get(DB_PASSWORD));
- }
- });
+ return constructDBConnectionInfo(dbName, getDBProductName(conn));
}
- catch (SQLException e)
- {
- throw new DBCreatorException("Can't establish the JDBC connection to database " + serverUrl, e);
- }
- catch (ClassNotFoundException e)
- {
- throw new DBCreatorException("Can't load the JDBC driver " + connectionProperties.get(DB_DRIVER), e);
- }
-
- String dbProductName;
- try
- {
- final Connection connection = conn;
- dbProductName = SecurityHelper.doPrivilegedSQLExceptionAction(new PrivilegedExceptionAction<String>()
- {
- public String run() throws Exception
- {
- return connection.getMetaData().getDatabaseProductName();
- }
- });
- }
- catch (SQLException e)
- {
- throw new DBCreatorException("Can't resolve database product name ", e);
- }
finally
{
try
@@ -350,8 +290,6 @@
throw new DBCreatorException("Can't close connection", e);
}
}
-
- return constructDBConnectionInfo(dbName, dbProductName);
}
/**
@@ -389,6 +327,10 @@
* database name
* @param dbProductName
* database product name
+ * @param serverUrl
+ * url to DB server
+ * @param connectionProperties
+ * connection properties
* @return DBConnectionInfo
*/
private DBConnectionInfo constructDBConnectionInfo(String dbName, String dbProductName)
@@ -410,14 +352,15 @@
// clone connection properties
Map<String, String> connProperties = new HashMap<String, String>();
- for (Entry<String, String> entry : this.connectionProperties.entrySet())
+ for (Entry<String, String> entry : connectionProperties.entrySet())
{
connProperties.put(entry.getKey(), entry.getValue());
}
- connProperties.put(DB_URL, dbUrl);
+ // add url to database
+ connProperties.put(SERVER_URL, dbUrl);
- return new DBConnectionInfo(connProperties);
+ return new DBConnectionInfo(dbName, connProperties);
}
/**
@@ -452,7 +395,7 @@
/**
* Read SQL script from {@link InputStream}.
*/
- protected String readScriptResource(InputStream is) throws IOException
+ private String readResource(InputStream is) throws IOException
{
InputStreamReader isr = new InputStreamReader(is);
try
@@ -474,6 +417,37 @@
}
/**
+ * Find script resource.
+ *
+ * @param scriptPath
+ * path to the script
+ * @param cm
+ * the configuration manager will help to find script in jars
+ * @return
+ * script content
+ * @throws ConfigurationException
+ * if script not found
+ */
+ private String findScriptResource(String scriptPath, ConfigurationManager cm) throws ConfigurationException
+ {
+ try
+ {
+ return readResource(cm.getInputStream(scriptPath));
+ }
+ catch (Exception e)
+ {
+ try
+ {
+ return readResource(PrivilegedFileHelper.fileInputStream(scriptPath));
+ }
+ catch (IOException ioe)
+ {
+ throw new ConfigurationException("Can't read script resource " + scriptPath, e);
+ }
+ }
+ }
+
+ /**
* Clean whitespace.
*/
private String cleanWhitespaces(String string)
@@ -492,4 +466,68 @@
}
return string;
}
+
+ /**
+ * Open connection to the DB.
+ *
+ * @param connectionProperties
+ * connection properties
+ * @return connection
+ * @throws DBCreatorException
+ * if can't establish connection to DB
+ */
+ private Connection openConnection() throws DBCreatorException
+ {
+ Connection conn = null;
+ try
+ {
+ Class.forName(connectionProperties.get(DRIVER_NAME));
+
+ conn = SecurityHelper.doPrivilegedSQLExceptionAction(new PrivilegedExceptionAction<Connection>()
+ {
+ public Connection run() throws Exception
+ {
+ return DriverManager.getConnection(serverUrl, connectionProperties.get(USERNAME),
+ connectionProperties.get(PASSWORD));
+ }
+ });
+
+ return conn;
+ }
+ catch (SQLException e)
+ {
+ throw new DBCreatorException("Can't establish the JDBC connection to database " + serverUrl, e);
+ }
+ catch (ClassNotFoundException e)
+ {
+ throw new DBCreatorException("Can't load the JDBC driver " + connectionProperties.get(DRIVER_NAME), e);
+ }
+ }
+
+ /**
+ * Get database product name.
+ *
+ * @param conn
+ * connection to database
+ * @return product name
+ * @throws DBCreatorException
+ * if can't resolve database product name
+ */
+ private String getDBProductName(final Connection conn) throws DBCreatorException
+ {
+ try
+ {
+ return SecurityHelper.doPrivilegedSQLExceptionAction(new PrivilegedExceptionAction<String>()
+ {
+ public String run() throws Exception
+ {
+ return conn.getMetaData().getDatabaseProductName();
+ }
+ });
+ }
+ catch (SQLException e)
+ {
+ throw new DBCreatorException("Can't resolve database product name ", e);
+ }
+ }
}
Modified: core/trunk/exo.core.component.database/src/test/java/org/exoplatform/services/database/TestDBCreator.java
===================================================================
--- core/trunk/exo.core.component.database/src/test/java/org/exoplatform/services/database/TestDBCreator.java 2011-07-01 08:50:58 UTC (rev 4570)
+++ core/trunk/exo.core.component.database/src/test/java/org/exoplatform/services/database/TestDBCreator.java 2011-07-01 08:57:52 UTC (rev 4571)
@@ -21,11 +21,13 @@
import junit.framework.TestCase;
import org.exoplatform.container.PortalContainer;
+import org.exoplatform.container.configuration.ConfigurationManager;
import org.exoplatform.services.database.creator.DBConnectionInfo;
import org.exoplatform.services.database.creator.DBCreator;
import org.exoplatform.services.naming.InitialContextInitializer;
import java.sql.Connection;
+import java.util.HashMap;
import java.util.Map;
import javax.sql.DataSource;
@@ -41,11 +43,12 @@
private InitialContextInitializer initContext;
+ private PortalContainer container;
+
@Override
public void setUp() throws Exception
{
- PortalContainer container = PortalContainer.getInstance();
-
+ container = PortalContainer.getInstance();
dbCreator = (DBCreator)container.getComponentInstanceOfType(DBCreator.class);
initContext = (InitialContextInitializer)container.getComponentInstanceOfType(InitialContextInitializer.class);
}
@@ -61,9 +64,9 @@
Map<String, String> connProps1 = dbInfo1.getProperties();
assertEquals(connProps.get("driverClassName"), connProps1.get("driverClassName"));
+ assertEquals(connProps.get("username"), connProps1.get("username"));
+ assertEquals(connProps.get("url"), connProps1.get("url"));
assertEquals(connProps.get("password"), connProps1.get("password"));
- assertEquals(connProps.get("url"), connProps1.get("url"));
- assertEquals(connProps.get("username"), connProps1.get("username"));
Map<String, String> refAddr = dbInfo.getProperties();
@@ -77,6 +80,43 @@
assertNotNull(conn);
}
+ public void testDBCreateWithSpecificProperties() throws Exception
+ {
+ assertNotNull(dbCreator);
+
+ String serverUrl = "jdbc:hsqldb:file:target/temp/data/dbcreator_test";
+ Map<String, String> connectionProperties = new HashMap<String, String>();
+ connectionProperties.put("driverClassName", "org.hsqldb.jdbcDriver");
+ connectionProperties.put("username", "sa");
+ connectionProperties.put("password", "");
+
+ ConfigurationManager cm = (ConfigurationManager)container.getComponentInstanceOfType(ConfigurationManager.class);
+ DBCreator dbCreator =
+ new DBCreator(serverUrl, connectionProperties, "classpath:/dbcreator/test.sql", "sa", "", cm);
+
+ DBConnectionInfo dbInfo = dbCreator.createDatabase("testdb");
+ DBConnectionInfo dbInfo1 = dbCreator.getDBConnectionInfo("testdb");
+
+ Map<String, String> connProps = dbInfo.getProperties();
+ Map<String, String> connProps1 = dbInfo1.getProperties();
+
+ assertEquals(connProps.get("driverClassName"), connProps1.get("driverClassName"));
+ assertEquals(connProps.get("username"), connProps1.get("username"));
+ assertEquals(connProps.get("url"), connProps1.get("url"));
+ assertEquals(connProps.get("password"), connProps1.get("password"));
+
+ Map<String, String> refAddr = dbInfo.getProperties();
+
+ initContext.bind("testjdbcjcr2", "javax.sql.DataSource", "org.apache.commons.dbcp.BasicDataSourceFactory", null,
+ refAddr);
+
+ DataSource ds = (DataSource)initContext.getInitialContext().lookup("testjdbcjcr2");
+ assertNotNull(ds);
+
+ Connection conn = ds.getConnection();
+ assertNotNull(conn);
+ }
+
public void testDBCreateMultiThread() throws Exception
{
DBCreateThread[] queue = new DBCreateThread[100];
12 years, 10 months
exo-jcr SVN: r4570 - kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/management.
by do-not-reply@jboss.org
Author: nzamosenchuk
Date: 2011-07-01 04:50:58 -0400 (Fri, 01 Jul 2011)
New Revision: 4570
Modified:
kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/management/ManageableContainer.java
kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/management/ManagementContextImpl.java
Log:
EXOJCR-1068 : Unregister all MBeans on container stop.
Modified: kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/management/ManageableContainer.java
===================================================================
--- kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/management/ManageableContainer.java 2011-06-30 14:54:37 UTC (rev 4569)
+++ kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/management/ManageableContainer.java 2011-07-01 08:50:58 UTC (rev 4570)
@@ -52,8 +52,7 @@
* @author <a href="mailto:julien.viet@exoplatform.com">Julien Viet</a>
* @version $Revision$
*/
-public class ManageableContainer
- extends CachingContainer
+public class ManageableContainer extends CachingContainer
{
/**
@@ -69,7 +68,7 @@
/** . */
private static final ThreadLocal<ManageableComponentAdapterFactory> hack =
- new ThreadLocal<ManageableComponentAdapterFactory>();
+ new ThreadLocal<ManageableComponentAdapterFactory>();
/** . */
final ManagementContextImpl managementContext;
@@ -78,8 +77,9 @@
private MBeanServer server;
private volatile boolean objectNameSet;
+
private ObjectName objectName;
-
+
/** . */
private final Set<ManagementProvider> providers;
@@ -88,7 +88,7 @@
public ManageableContainer()
{
- this((PicoContainer) null);
+ this((PicoContainer)null);
}
public ManageableContainer(PicoContainer parent)
@@ -113,12 +113,12 @@
ManagementContextImpl parentCtx = null;
if (parent instanceof ManageableContainer)
{
- ManageableContainer manageableParent = (ManageableContainer) parent;
+ ManageableContainer manageableParent = (ManageableContainer)parent;
parentCtx = manageableParent.managementContext;
}
//
- this.parent = parent instanceof ManageableContainer ? (ManageableContainer) parent : null;
+ this.parent = parent instanceof ManageableContainer ? (ManageableContainer)parent : null;
//
if (parentCtx != null)
@@ -156,7 +156,7 @@
}
private static ManageableComponentAdapterFactory getComponentAdapterFactory(
- ComponentAdapterFactory componentAdapterFactory)
+ ComponentAdapterFactory componentAdapterFactory)
{
ManageableComponentAdapterFactory factory = new ManageableComponentAdapterFactory(componentAdapterFactory);
hack.set(factory);
@@ -196,7 +196,7 @@
{
MBeanScopingData scopingData = list.get(i - 1);
props.putAll(scopingData);
- }
+ }
try
{
this.objectName = JMX.createObjectName("exo", props);
@@ -204,7 +204,7 @@
catch (Exception e)
{
LOG.error("Could not create the object name", e);
- }
+ }
}
this.objectNameSet = true;
}
@@ -212,9 +212,9 @@
}
return objectName;
}
-
+
public ComponentAdapter registerComponentInstance(Object componentKey, Object componentInstance)
- throws PicoRegistrationException
+ throws PicoRegistrationException
{
ComponentAdapter adapter = super.registerComponentInstance(componentKey, componentInstance);
if (managementContext != null)
@@ -224,13 +224,36 @@
// Register if it is a management provider
if (componentInstance instanceof ManagementProvider)
{
- ManagementProvider provider = (ManagementProvider) componentInstance;
+ ManagementProvider provider = (ManagementProvider)componentInstance;
addProvider(provider);
}
}
return adapter;
}
+ @Override
+ public ComponentAdapter unregisterComponent(Object componentKey)
+ {
+ ComponentAdapter adapter = getComponentAdapter(componentKey);
+
+ if (managementContext != null && adapter != null)
+ {
+ managementContext.unregister(adapter.getComponentInstance(this));
+ }
+ return super.unregisterComponent(componentKey);
+ }
+
+ @Override
+ public void stop()
+ {
+ if (managementContext != null)
+ {
+ // un-manage all registered MBeans
+ managementContext.unregisterAll();
+ }
+ super.stop();
+ };
+
/**
* Returns the list of the providers which are relevant for this container.
*
Modified: kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/management/ManagementContextImpl.java
===================================================================
--- kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/management/ManagementContextImpl.java 2011-06-30 14:54:37 UTC (rev 4569)
+++ kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/management/ManagementContextImpl.java 2011-07-01 08:50:58 UTC (rev 4570)
@@ -33,8 +33,10 @@
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.Map.Entry;
/**
* @author <a href="mailto:julien.viet@exoplatform.com">Julien Viet</a>
@@ -237,6 +239,10 @@
}
}
+ /**
+ *
+ * {@inheritDoc}
+ */
public void unregister(Object o)
{
ManagementContextImpl context = registrations.remove(o);
@@ -247,6 +253,26 @@
}
}
}
+
+ /**
+ * Unmanages (unregisters) all early registered MBeans in ManagementProviders
+ */
+ public void unregisterAll()
+ {
+ Iterator<Entry<Object, ManagementContextImpl>> iterator = registrations.entrySet().iterator();
+ while (iterator.hasNext())
+ {
+ Entry<Object, ManagementContextImpl> contextEntry = iterator.next();
+ iterator.remove();
+ if (contextEntry.getValue() != null)
+ {
+ for (Map.Entry<ManagementProvider, Object> provider : contextEntry.getValue().managedSet.entrySet())
+ {
+ provider.getKey().unmanage(provider.getValue());
+ }
+ }
+ }
+ }
public <S> List<S> getScopingData(Class<S> scopeType)
{
12 years, 10 months