Various fiddlings with Stress test.

Cleaned up AVMRevertListActions. 
Added AVMRevertToVersionActions which reverts to a single node to a given previous version
of that node.  See class for use syntax.


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@4748 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Britt Park
2007-01-08 01:41:21 +00:00
parent d5f62da5e3
commit 4dca69be7a
8 changed files with 182 additions and 55 deletions

View File

@@ -457,6 +457,18 @@
</property> </property>
</bean> </bean>
<bean id="avm-revert-to-version" class="org.alfresco.repo.avm.actions.AVMRevertToVersionAction" parent = "action-executer">
<property name="avmSyncService">
<ref bean="avmSyncService"/>
</property>
<property name="avmService">
<ref bean="avmService"/>
</property>
<property name="publicAction">
<value>false</value>
</property>
</bean>
<bean id="avm-undo-list" class="org.alfresco.repo.avm.actions.AVMUndoSandboxListAction" parent="action-executer"> <bean id="avm-undo-list" class="org.alfresco.repo.avm.actions.AVMUndoSandboxListAction" parent="action-executer">
<property name="avmService"> <property name="avmService">
<ref bean="avmService"/> <ref bean="avmService"/>

View File

@@ -107,6 +107,10 @@ avm-revert-list.store.display-label=The name of the store being reverted, only n
avm-revert-list.staging.display-label=The name of the staging store to flatten to. avm-revert-list.staging.display-label=The name of the staging store to flatten to.
avm-revert-list.flatten-path.display-label=The store relative path that should be flattened. avm-revert-list.flatten-path.display-label=The store relative path that should be flattened.
avm-revert-to-version.title=Revert a Node to a particular version.
avm-revert-to-version.description=This reverts a Node to a particular version of that node.
avm-revert-to-version.to-revert.display-label=The AVM Node Descriptor of the version to revert to.
avm-undo-list.title=Make a list of Nodes in a store transparent to staging. avm-undo-list.title=Make a list of Nodes in a store transparent to staging.
avm-undo-list.description=This acts as a mistake eraser for a user's sandbox. avm-undo-list.description=This acts as a mistake eraser for a user's sandbox.
avm-undo-list.node-list.display-label=The string encoded list of nodes to revert. avm-undo-list.node-list.display-label=The string encoded list of nodes to revert.

View File

@@ -36,8 +36,8 @@ public class AVMCrawlTestP extends AVMServiceTestBase
public void testCrawl() public void testCrawl()
{ {
int n = 4; // Number of Threads. int n = 4; // Number of Threads.
int m = 12; // How many multiples of content to start with. int m = 192; // How many multiples of content to start with.
long runTime = 36000000; // 6 hours. long runTime = 3600000; // 6 hours.
fService.purgeStore("main"); fService.purgeStore("main");
BulkLoader loader = new BulkLoader(); BulkLoader loader = new BulkLoader();
loader.setAvmService(fService); loader.setAvmService(fService);

View File

@@ -120,7 +120,7 @@ class AVMCrawler implements Runnable
{ {
List<AVMStoreDescriptor> reps = fService.getStores(); List<AVMStoreDescriptor> reps = fService.getStores();
fOpCount++; fOpCount++;
AVMStoreDescriptor repDesc = reps.get(fRandom.nextInt(reps.size())); AVMStoreDescriptor repDesc = reps.get(fRandom.nextInt(12));
Map<String, AVMNodeDescriptor> rootListing = fService.getDirectoryListing(-1, repDesc.getName() + ":/"); Map<String, AVMNodeDescriptor> rootListing = fService.getDirectoryListing(-1, repDesc.getName() + ":/");
fOpCount++; fOpCount++;
// Get all the directories in the root. // Get all the directories in the root.

View File

@@ -36,6 +36,7 @@ import org.alfresco.model.ContentModel;
import org.alfresco.model.WCMModel; import org.alfresco.model.WCMModel;
import org.alfresco.repo.action.ActionImpl; import org.alfresco.repo.action.ActionImpl;
import org.alfresco.repo.avm.actions.AVMRevertListAction; import org.alfresco.repo.avm.actions.AVMRevertListAction;
import org.alfresco.repo.avm.actions.AVMRevertToVersionAction;
import org.alfresco.repo.avm.actions.AVMUndoSandboxListAction; import org.alfresco.repo.avm.actions.AVMUndoSandboxListAction;
import org.alfresco.repo.avm.actions.SimpleAVMPromoteAction; import org.alfresco.repo.avm.actions.SimpleAVMPromoteAction;
import org.alfresco.repo.avm.actions.SimpleAVMSubmitAction; import org.alfresco.repo.avm.actions.SimpleAVMSubmitAction;
@@ -71,6 +72,52 @@ import org.alfresco.util.Pair;
*/ */
public class AVMServiceTest extends AVMServiceTestBase public class AVMServiceTest extends AVMServiceTestBase
{ {
/**
* Test the revert to version action.
*/
public void testRevertToVersionAction()
{
try
{
setupBasicTree();
fService.getFileOutputStream("main:/a/b/c/foo").close();
fService.createSnapshot("main", "v1", null);
fService.getFileOutputStream("main:/a/b/c/foo").close();
fService.createSnapshot("main", "v2", null);
fService.getFileOutputStream("main:/a/b/c/foo").close();
fService.createSnapshot("main", "v3", null);
fService.getFileOutputStream("main:/a/b/c/foo").close();
fService.createSnapshot("main", "v4", null);
fService.getFileOutputStream("main:/a/b/c/foo").close();
fService.createSnapshot("main", "v5", null);
fService.getFileOutputStream("main:/a/b/c/foo").close();
AVMNodeDescriptor desc = fService.lookup(-1, "main:/a/b/c/foo");
List<AVMNodeDescriptor> history = fService.getHistory(desc, 100);
AVMNodeDescriptor toRevert = history.get(3);
final ActionImpl action = new ActionImpl(null,
GUID.generate(),
AVMRevertToVersionAction.NAME);
action.setParameterValue(AVMRevertToVersionAction.TOREVERT, toRevert);
final AVMRevertToVersionAction revert = (AVMRevertToVersionAction)fContext.getBean("avm-revert-to-version");
class TxnWork implements TransactionUtil.TransactionWork<Object>
{
public Object doWork() throws Exception
{
revert.execute(action, AVMNodeConverter.ToNodeRef(-1, "main:/a/b/c/foo"));
return null;
}
};
TransactionUtil.executeInUserTransaction((TransactionService)fContext.getBean("transactionComponent"),
new TxnWork());
assertEquals(toRevert.getId(), fService.lookup(-1, "main:/a/b/c/foo").getId());
}
catch (Exception e)
{
e.printStackTrace();
fail();
}
}
/** /**
* Test version numbering. * Test version numbering.
*/ */
@@ -333,15 +380,11 @@ public class AVMServiceTest extends AVMServiceTestBase
final ActionImpl action = new ActionImpl(null, final ActionImpl action = new ActionImpl(null,
GUID.generate(), GUID.generate(),
AVMRevertListAction.NAME); AVMRevertListAction.NAME);
List<Pair<Integer, String>> versionPaths = List<String> paths =
new ArrayList<Pair<Integer, String>>(); new ArrayList<String>();
versionPaths.add(new Pair<Integer, String>(-1, "area:/a/b")); paths.add("area:/a/b");
action.setParameterValue(AVMRevertListAction.PARAM_VERSION, fService.getLatestSnapshotID("area")); action.setParameterValue(AVMRevertListAction.PARAM_VERSION, fService.getLatestSnapshotID("area"));
action.setParameterValue(AVMRevertListAction.PARAM_NODE_LIST, (Serializable)versionPaths); action.setParameterValue(AVMRevertListAction.PARAM_NODE_LIST, (Serializable)paths);
action.setParameterValue(AVMRevertListAction.PARAM_FLATTEN, true);
action.setParameterValue(AVMRevertListAction.PARAM_STORE, "area");
action.setParameterValue(AVMRevertListAction.PARAM_STAGING, "main");
action.setParameterValue(AVMRevertListAction.PARAM_FLATTEN_PATH, "/a");
final AVMRevertListAction revert = (AVMRevertListAction)fContext.getBean("avm-revert-list"); final AVMRevertListAction revert = (AVMRevertListAction)fContext.getBean("avm-revert-list");
class TxnWork implements TransactionUtil.TransactionWork<Object> class TxnWork implements TransactionUtil.TransactionWork<Object>
{ {

View File

@@ -484,7 +484,8 @@ public class AVMStoreImpl implements AVMStore, Serializable
SortedMap<String, AVMNodeDescriptor> results = new TreeMap<String, AVMNodeDescriptor>(); SortedMap<String, AVMNodeDescriptor> results = new TreeMap<String, AVMNodeDescriptor>();
for (String name : listing.keySet()) for (String name : listing.keySet())
{ {
AVMNode child = listing.get(name); // TODO consider doing this at a lower level.
AVMNode child = AVMNodeUnwrapper.Unwrap(listing.get(name));
AVMNodeDescriptor desc = child.getDescriptor(lPath, name); AVMNodeDescriptor desc = child.getDescriptor(lPath, name);
results.put(name, desc); results.put(name, desc);
} }

View File

@@ -14,12 +14,10 @@ import org.alfresco.service.cmr.avmsync.AVMDifference;
import org.alfresco.service.cmr.avmsync.AVMSyncService; import org.alfresco.service.cmr.avmsync.AVMSyncService;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition; import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.util.Pair;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
/** /**
* This action handles reverting a selected set of nodes to a particular version. * This action handles reverting a selected set of nodes to a particular version.
* The set of of nodes is passed in as a packed string (Obtained by VersionPathStuffer).
* The actionedUponNodeRef is a dummy and can be null. * The actionedUponNodeRef is a dummy and can be null.
* @author britt * @author britt
*/ */
@@ -33,13 +31,6 @@ public class AVMRevertListAction extends ActionExecuterAbstractBase
// The encoded list of nodes. // The encoded list of nodes.
public static final String PARAM_NODE_LIST = "node-list"; public static final String PARAM_NODE_LIST = "node-list";
// Flag for whether we should flatten after revert. // Flag for whether we should flatten after revert.
public static final String PARAM_FLATTEN = "flatten";
// If we are flattening, then this holds the staging store name.
public static final String PARAM_STAGING = "staging";
// If we are flattening, then this holds the reverted store's name
public static final String PARAM_STORE = "store";
// If we are flattening, then this holds the path "/foo/bar/baz" to flatten.
public static final String PARAM_FLATTEN_PATH = "flatten-path";
/** /**
* The sync service. * The sync service.
@@ -61,27 +52,18 @@ public class AVMRevertListAction extends ActionExecuterAbstractBase
protected void executeImpl(Action action, NodeRef actionedUponNodeRef) protected void executeImpl(Action action, NodeRef actionedUponNodeRef)
{ {
int revertVersion = (Integer)action.getParameterValue(PARAM_VERSION); int revertVersion = (Integer)action.getParameterValue(PARAM_VERSION);
List<Pair<Integer, String>> versionPaths = List<String> paths =
(List<Pair<Integer, String>>)action.getParameterValue(PARAM_NODE_LIST); (List<String>)action.getParameterValue(PARAM_NODE_LIST);
List<AVMDifference> diffs = new ArrayList<AVMDifference>(); List<AVMDifference> diffs = new ArrayList<AVMDifference>();
for (Pair<Integer, String> item : versionPaths) for (String path : paths)
{ {
List<AVMDifference> diffSet = List<AVMDifference> diffSet =
fSyncService.compare(revertVersion, item.getSecond(), fSyncService.compare(revertVersion, path,
-1, item.getSecond(), null); -1, path, null);
diffs.addAll(diffSet); diffs.addAll(diffSet);
} }
String message = "Reverted to version " + revertVersion; String message = "Reverted to version " + revertVersion;
fSyncService.update(diffs, null, false, false, true, true, message, message); fSyncService.update(diffs, null, false, false, true, true, message, message);
if (!(Boolean)action.getParameterValue(PARAM_FLATTEN))
{
return;
}
String storeName = (String)action.getParameterValue(PARAM_STORE);
String flattenPath = (String)action.getParameterValue(PARAM_FLATTEN_PATH);
String stagingName = (String)action.getParameterValue(PARAM_STAGING);
fSyncService.flatten(storeName + ":" + flattenPath,
stagingName + ":" + flattenPath);
} }
/* (non-Javadoc) /* (non-Javadoc)
@@ -100,25 +82,5 @@ public class AVMRevertListAction extends ActionExecuterAbstractBase
DataTypeDefinition.ANY, DataTypeDefinition.ANY,
true, true,
getParamDisplayLabel(PARAM_NODE_LIST))); getParamDisplayLabel(PARAM_NODE_LIST)));
paramList.add(
new ParameterDefinitionImpl(PARAM_FLATTEN,
DataTypeDefinition.BOOLEAN,
false,
getParamDisplayLabel(PARAM_FLATTEN)));
paramList.add(
new ParameterDefinitionImpl(PARAM_STAGING,
DataTypeDefinition.TEXT,
false,
getParamDisplayLabel(PARAM_STAGING)));
paramList.add(
new ParameterDefinitionImpl(PARAM_STORE,
DataTypeDefinition.TEXT,
false,
getParamDisplayLabel(PARAM_STORE)));
paramList.add(
new ParameterDefinitionImpl(PARAM_FLATTEN_PATH,
DataTypeDefinition.TEXT,
false,
getParamDisplayLabel(PARAM_FLATTEN_PATH)));
} }
} }

View File

@@ -0,0 +1,105 @@
/**
*
*/
package org.alfresco.repo.avm.actions;
import java.util.ArrayList;
import java.util.List;
import org.alfresco.repo.action.ParameterDefinitionImpl;
import org.alfresco.repo.action.executer.ActionExecuterAbstractBase;
import org.alfresco.repo.avm.AVMNodeConverter;
import org.alfresco.service.cmr.action.Action;
import org.alfresco.service.cmr.action.ParameterDefinition;
import org.alfresco.service.cmr.avm.AVMNodeDescriptor;
import org.alfresco.service.cmr.avm.AVMService;
import org.alfresco.service.cmr.avmsync.AVMDifference;
import org.alfresco.service.cmr.avmsync.AVMSyncService;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.util.Pair;
import org.apache.log4j.Logger;
/**
* Revert a single path to a specified node. The path in head is passed
* as actionedUponNodeRef. The node to revert to is passed as an AVMNodeDescriptor
* parameter.
* @author britt
*/
public class AVMRevertToVersionAction extends ActionExecuterAbstractBase
{
private static Logger fgLogger = Logger.getLogger(AVMRevertToVersionAction.class);
public static final String NAME = "avm-revert-to-version";
// The node to revert to. Passed as an AVMNodeDescriptor.
public static final String TOREVERT = "to-revert";
private AVMService fAVMService;
private AVMSyncService fAVMSyncService;
/**
* Set the AVMService.
*/
public void setAvmService(AVMService service)
{
fAVMService = service;
}
/**
* Set the AVMSyncService.
*/
public void setAvmSyncService(AVMSyncService service)
{
fAVMSyncService = service;
}
/* (non-Javadoc)
* @see org.alfresco.repo.action.executer.ActionExecuterAbstractBase#executeImpl(org.alfresco.service.cmr.action.Action, org.alfresco.service.cmr.repository.NodeRef)
*/
@Override
protected void executeImpl(Action action, NodeRef actionedUponNodeRef)
{
Pair<Integer, String> versionPath =
AVMNodeConverter.ToAVMVersionPath(actionedUponNodeRef);
String [] storePath = versionPath.getSecond().split(":");
String store = storePath[0];
AVMNodeDescriptor toRevert =
(AVMNodeDescriptor)action.getParameterValue(TOREVERT);
List<Pair<Integer, String>> paths = fAVMService.getPaths(toRevert);
Pair<Integer, String> found = new Pair<Integer, String>(Integer.MAX_VALUE, "");
for (Pair<Integer, String> path : paths)
{
if (!path.getSecond().startsWith(store + ':'))
{
continue;
}
if (path.getFirst() < found.getFirst())
{
found = path;
}
}
// TODO I believe that this should always have found not
// the initial found. Must confirm.
AVMDifference diff = new AVMDifference(found.getFirst(), found.getSecond(),
-1, versionPath.getSecond(),
AVMDifference.NEWER);
List<AVMDifference> diffs = new ArrayList<AVMDifference>(1);
diffs.add(diff);
String message = "Reverted " + versionPath.getSecond() + " to version in snapshot " + found.getFirst() + ".";
fAVMSyncService.update(diffs, null, false, false, true, true, "Reverted", message);
}
/* (non-Javadoc)
* @see org.alfresco.repo.action.ParameterizedItemAbstractBase#addParameterDefinitions(java.util.List)
*/
@Override
protected void addParameterDefinitions(List<ParameterDefinition> paramList)
{
paramList.add(
new ParameterDefinitionImpl(TOREVERT,
DataTypeDefinition.ANY,
true,
getParamDisplayLabel(TOREVERT)));
}
}