Author: tolusha
Date: 2011-09-28 03:02:50 -0400 (Wed, 28 Sep 2011)
New Revision: 4990
Modified:
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/distribution/DataDistributionType.java
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/distribution/impl/AbstractDataDistributionType.java
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/distribution/impl/DataDistributionByName.java
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/hierarchy/impl/NodeHierarchyCreatorImpl.java
jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/distribution/TestDataDistributionManager.java
jcr/trunk/exo.jcr.component.ext/src/test/resources/conf/standalone/test-configuration.xml
Log:
EXOJCR-1498: Migration tool and guideline for migration from 1.12.10-GA to
1.14.0.CR4-CP01
Modified:
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/distribution/DataDistributionType.java
===================================================================
---
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/distribution/DataDistributionType.java 2011-09-28
06:59:57 UTC (rev 4989)
+++
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/distribution/DataDistributionType.java 2011-09-28
07:02:50 UTC (rev 4990)
@@ -100,4 +100,12 @@
* @throws RepositoryException if an error occurred while trying to remove the
expected data
*/
void removeDataNode(Node rootNode, String dataId) throws RepositoryException;
+
+ /**
+ * Migrate from old structure to new one.
+ *
+ * @param rootNode the root node under which the data to migrate is stored
+ * @throws RepositoryException if an error occurred during migration
+ */
+ void migrate(Node rootNode) throws RepositoryException;
}
Modified:
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/distribution/impl/AbstractDataDistributionType.java
===================================================================
---
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/distribution/impl/AbstractDataDistributionType.java 2011-09-28
06:59:57 UTC (rev 4989)
+++
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/distribution/impl/AbstractDataDistributionType.java 2011-09-28
07:02:50 UTC (rev 4990)
@@ -43,7 +43,7 @@
/**
* The default node type to use when we create a new node
*/
- private static final String DEFAULT_NODE_TYPE = "nt:unstructured".intern();
+ protected static final String DEFAULT_NODE_TYPE =
"nt:unstructured".intern();
/**
* The map defining all the locks available
@@ -141,8 +141,16 @@
lock.unlock();
}
}
-
+
/**
+ * {@inheritDoc}
+ */
+ public void migrate(Node rootNode) throws RepositoryException
+ {
+ throw new UnsupportedOperationException("The method is not supported");
+ }
+
+ /**
* Creates the node of the given node type with the given node name directly under
* the given parent node, using the given mixin types and permissions
* @param parentNode the parent node
Modified:
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/distribution/impl/DataDistributionByName.java
===================================================================
---
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/distribution/impl/DataDistributionByName.java 2011-09-28
06:59:57 UTC (rev 4989)
+++
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/distribution/impl/DataDistributionByName.java 2011-09-28
07:02:50 UTC (rev 4990)
@@ -18,9 +18,15 @@
*/
package org.exoplatform.services.jcr.ext.distribution.impl;
+import org.exoplatform.services.jcr.impl.core.NodeImpl;
+
import java.util.ArrayList;
import java.util.List;
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+import javax.jcr.PathNotFoundException;
+import javax.jcr.RepositoryException;
/**
* This data distribution will distribute the data in a understandable way for a human
being.
@@ -76,4 +82,44 @@
{
return true;
}
+
+ /**
+ * {@inheritDoc}
+ */
+ public void migrate(Node rootNode) throws RepositoryException
+ {
+ NodeIterator iter = ((NodeImpl)rootNode).getNodesLazily(1);
+ if (iter.hasNext() && !iter.nextNode().getPath().endsWith(suffix))
+ {
+ iter = ((NodeImpl)rootNode).getNodesLazily();
+ while (iter.hasNext())
+ {
+ Node userNode = iter.nextNode();
+ List<String> ancestors = getAncestors(userNode.getName());
+
+ Node node = rootNode;
+
+ for (int i = 0, length = ancestors.size() - 1; i < length; i++)
+ {
+ String nodeName = ancestors.get(i);
+ try
+ {
+ node = node.getNode(nodeName);
+ continue;
+ }
+ catch (PathNotFoundException e)
+ {
+ // ignore me
+ }
+
+ // The node doesn't exist we need to create it
+ node = node.addNode(nodeName, DEFAULT_NODE_TYPE);
+ }
+
+ userNode.getSession().move(userNode.getPath(), node.getPath() + "/"
+ ancestors.get(ancestors.size() - 1));
+ }
+ }
+
+ rootNode.getSession().save();
+ }
}
Modified:
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/hierarchy/impl/NodeHierarchyCreatorImpl.java
===================================================================
---
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/hierarchy/impl/NodeHierarchyCreatorImpl.java 2011-09-28
06:59:57 UTC (rev 4989)
+++
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/hierarchy/impl/NodeHierarchyCreatorImpl.java 2011-09-28
07:02:50 UTC (rev 4990)
@@ -75,6 +75,8 @@
private final boolean oldDistribution;
+ private final boolean autoMigrate;
+
public NodeHierarchyCreatorImpl(RepositoryService jcrService, InitParams params)
{
this(jcrService, null, params);
@@ -91,9 +93,9 @@
}
jcrService_ = jcrService;
dataDistributionManager_ = dataDistributionManager;
- oldDistribution =
- params != null &&
params.getValueParam("old-user-distribution") != null
- &&
Boolean.valueOf(params.getValueParam("old-user-distribution").getValue());
+ oldDistribution = params != null &&
Boolean.valueOf(params.getValueParam("old-user-distribution").getValue());
+ autoMigrate = params != null &&
Boolean.valueOf(params.getValueParam("auto-migrate").getValue());
+
if (PropertyManager.isDevelopping() && !oldDistribution)
{
log.info("The NodeHierarchyCreator is configured to use the new
distribution mechanism for the"
@@ -115,6 +117,15 @@
{
log.error("An error occurs while processing the plugins", e);
}
+
+ try
+ {
+ checkForUpgrade();
+ }
+ catch (RepositoryException e)
+ {
+ log.error("An error occurs while upgrading JCR structure", e);
+ }
}
/**
@@ -359,4 +370,29 @@
}
}
}
+
+ private void checkForUpgrade() throws RepositoryException
+ {
+ if (!oldDistribution && autoMigrate)
+ {
+
+ ManageableRepository repo = jcrService_.getCurrentRepository();
+ Session session = repo.login();
+
+ try
+ {
+ String userPath = getJcrPath(USERS_PATH);
+ Node usersNode = (Node)session.getItem(userPath);
+
+
dataDistributionManager_.getDataDistributionType(DataDistributionMode.READABLE).migrate(usersNode);
+ }
+ finally
+ {
+ if (session != null)
+ {
+ session.logout();
+ }
+ }
+ }
+ }
}
Modified:
jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/distribution/TestDataDistributionManager.java
===================================================================
---
jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/distribution/TestDataDistributionManager.java 2011-09-28
06:59:57 UTC (rev 4989)
+++
jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/distribution/TestDataDistributionManager.java 2011-09-28
07:02:50 UTC (rev 4990)
@@ -21,7 +21,6 @@
import org.exoplatform.services.jcr.access.PermissionType;
import org.exoplatform.services.jcr.core.ExtendedNode;
import org.exoplatform.services.jcr.ext.BaseStandaloneTest;
-import org.exoplatform.services.jcr.impl.core.SessionImpl;
import java.util.ArrayList;
import java.util.Collections;
@@ -487,7 +486,7 @@
startSignalWriter.await();
for (int j = 0; j < totalTimes; j++)
{
- session = (SessionImpl)repository.login(credentials, WS_NAME);
+ session = repository.login(credentials, WS_NAME);
Node node = (Node)session.getItem(parentNode.getPath());
for (int i = 0; i < totalElement; i++)
{
@@ -533,7 +532,7 @@
startSignalOthers.await();
for (int j = 0; j < totalTimes; j++)
{
- session = (SessionImpl)repository.login(credentials, WS_NAME);
+ session = repository.login(credentials, WS_NAME);
Node node = (Node)session.getItem(parentNode.getPath());
for (int i = 0; i < totalElement; i++)
{
@@ -579,7 +578,7 @@
startSignalOthers.await();
for (int j = 0; j < totalTimes; j++)
{
- session = (SessionImpl)repository.login(credentials, WS_NAME);
+ session = repository.login(credentials, WS_NAME);
Node node = (Node)session.getItem(parentNode.getPath());
for (int i = 0; i < totalElement; i++)
{
@@ -621,4 +620,56 @@
}
System.out.println("Total Time for '" +
type.getClass().getSimpleName() + "' = " + (System.currentTimeMillis() -
time));
}
+
+ public void testMigration() throws Exception
+ {
+ Node rootNode = session.getRootNode().addNode("testRoot");
+ rootNode.addNode("bob").setProperty("bob", "bob");
+ rootNode.addNode("john.smith").setProperty("john.smith",
"john.smith");
+ rootNode.addNode("joiv").setProperty("joiv",
"joiv");
+ rootNode.addNode("bonjov").setProperty("bonjov",
"bonjov");
+
rootNode.addNode("anatoliy.bazko").setProperty("anatoliy.bazko",
"anatoliy.bazko");
+ rootNode.getSession().save();
+
+ manager.getDataDistributionType(DataDistributionMode.READABLE).migrate(rootNode);
+
+ assertFalse(rootNode.hasNode("bob"));
+ assertFalse(rootNode.hasNode("john.smith"));
+ assertFalse(rootNode.hasNode("joiv"));
+ assertFalse(rootNode.hasNode("bonjov"));
+ assertFalse(rootNode.hasNode("anatoliy.bazko"));
+
+ assertTrue(rootNode.hasNode("b___/bo___/bob"));
+ assertTrue(rootNode.hasNode("j___/jo___/joh___/john.smith"));
+ assertTrue(rootNode.hasNode("j___/jo___/joi___/joiv"));
+ assertTrue(rootNode.hasNode("b___/bo___/bon___/bonjov"));
+ assertTrue(rootNode.hasNode("a___/an___/ana___/anatoliy.bazko"));
+
+
assertTrue(rootNode.getNode("b___/bo___/bob").hasProperty("bob"));
+
assertTrue(rootNode.getNode("j___/jo___/joh___/john.smith").hasProperty("john.smith"));
+
assertTrue(rootNode.getNode("j___/jo___/joi___/joiv").hasProperty("joiv"));
+
assertTrue(rootNode.getNode("b___/bo___/bon___/bonjov").hasProperty("bonjov"));
+
assertTrue(rootNode.getNode("a___/an___/ana___/anatoliy.bazko").hasProperty("anatoliy.bazko"));
+
+ // shoud not be any changes
+ manager.getDataDistributionType(DataDistributionMode.READABLE).migrate(rootNode);
+
+ assertFalse(rootNode.hasNode("bob"));
+ assertFalse(rootNode.hasNode("john.smith"));
+ assertFalse(rootNode.hasNode("joiv"));
+ assertFalse(rootNode.hasNode("bonjov"));
+ assertFalse(rootNode.hasNode("anatoliy.bazko"));
+
+ assertTrue(rootNode.hasNode("b___/bo___/bob"));
+ assertTrue(rootNode.hasNode("j___/jo___/joh___/john.smith"));
+ assertTrue(rootNode.hasNode("j___/jo___/joi___/joiv"));
+ assertTrue(rootNode.hasNode("b___/bo___/bon___/bonjov"));
+ assertTrue(rootNode.hasNode("a___/an___/ana___/anatoliy.bazko"));
+
+
assertTrue(rootNode.getNode("b___/bo___/bob").hasProperty("bob"));
+
assertTrue(rootNode.getNode("j___/jo___/joh___/john.smith").hasProperty("john.smith"));
+
assertTrue(rootNode.getNode("j___/jo___/joi___/joiv").hasProperty("joiv"));
+
assertTrue(rootNode.getNode("b___/bo___/bon___/bonjov").hasProperty("bonjov"));
+
assertTrue(rootNode.getNode("a___/an___/ana___/anatoliy.bazko").hasProperty("anatoliy.bazko"));
+ }
}
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-09-28
06:59:57 UTC (rev 4989)
+++
jcr/trunk/exo.jcr.component.ext/src/test/resources/conf/standalone/test-configuration.xml 2011-09-28
07:02:50 UTC (rev 4990)
@@ -467,11 +467,19 @@
</init-params>
</component-plugin>
</component-plugins>
- </component>
+ </component>
+
<component>
<key>org.exoplatform.services.jcr.ext.hierarchy.NodeHierarchyCreator</key>
-
<type>org.exoplatform.services.jcr.ext.hierarchy.impl.NodeHierarchyCreatorImpl</type>
- </component>
+
<type>org.exoplatform.services.jcr.ext.hierarchy.impl.NodeHierarchyCreatorImpl</type>
+ <init-params>
+ <value-param>
+ <name>auto-migrate</name>
+ <value>false</value>
+ </value-param>
+ </init-params>
+ </component>
+
<component>
<type>org.exoplatform.services.jcr.ext.hierarchy.impl.NewUserListener</type>
<init-params>