mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
Added a semi intelligible toString to VersionDescriptor. Added an interactive
console program for debugging. Made it so you can't snapshot a version if there's nothing to snapshot. Fixed inactive to active transition in OrphanReaper. Other odds and ends. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/WCM-DEV2/root@3132 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
319
source/java/org/alfresco/repo/avm/AVMInteractiveConsole.java
Normal file
319
source/java/org/alfresco/repo/avm/AVMInteractiveConsole.java
Normal file
@@ -0,0 +1,319 @@
|
||||
/*
|
||||
* Copyright (C) 2006 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
|
||||
package org.alfresco.repo.avm;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.PrintStream;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.repo.avm.util.BulkLoader;
|
||||
|
||||
/**
|
||||
* An interactive console for the AVM repository.
|
||||
* @author britt
|
||||
*/
|
||||
public class AVMInteractiveConsole
|
||||
{
|
||||
/**
|
||||
* The service interface.
|
||||
*/
|
||||
private AVMService fService;
|
||||
|
||||
/**
|
||||
* The Orphan Cleaner Upper.
|
||||
*/
|
||||
private OrphanReaper fReaper;
|
||||
|
||||
/**
|
||||
* The reader for interaction.
|
||||
*/
|
||||
private BufferedReader fIn;
|
||||
|
||||
/**
|
||||
* The Bulk Loader.
|
||||
*/
|
||||
private BulkLoader fLoader;
|
||||
|
||||
/**
|
||||
* Main entry point.
|
||||
* Syntax: AVMInteractiveConsole storage (new|old).
|
||||
*/
|
||||
public static void main(String[] args)
|
||||
{
|
||||
if (args.length != 2)
|
||||
{
|
||||
System.err.println("Usage: AVMInteractiveConsole storage (new|old)");
|
||||
System.exit(1);
|
||||
}
|
||||
AVMInteractiveConsole console = new AVMInteractiveConsole(args[0], args[1].equals("new"));
|
||||
console.rep();
|
||||
}
|
||||
|
||||
/**
|
||||
* Make up a new console.
|
||||
* @param storage Where The backing store goes.
|
||||
* @param createNew Whether to create a new SuperRepository.
|
||||
*/
|
||||
public AVMInteractiveConsole(String storage, boolean createNew)
|
||||
{
|
||||
AVMServiceImpl service = new AVMServiceImpl();
|
||||
service.setStorage(storage);
|
||||
service.init(createNew);
|
||||
fService = service;
|
||||
fReaper = new OrphanReaper();
|
||||
fReaper.init();
|
||||
fLoader = new BulkLoader(fService);
|
||||
fIn = new BufferedReader(new InputStreamReader(System.in));
|
||||
}
|
||||
|
||||
/**
|
||||
* A Read-Eval-Print loop.
|
||||
*/
|
||||
public void rep()
|
||||
{
|
||||
boolean done = false;
|
||||
while (!done)
|
||||
{
|
||||
String command[] = null;
|
||||
try
|
||||
{
|
||||
String line = fIn.readLine();
|
||||
command = line.split("\\s+");
|
||||
if (command.length == 0)
|
||||
{
|
||||
command = new String[1];
|
||||
command[0] = line;
|
||||
}
|
||||
}
|
||||
catch (IOException ie)
|
||||
{
|
||||
ie.printStackTrace(System.err);
|
||||
System.exit(2);
|
||||
}
|
||||
if (command.length < 1)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
try
|
||||
{
|
||||
if (command[0].equals("ls"))
|
||||
{
|
||||
if (command.length != 3)
|
||||
{
|
||||
System.err.println("Syntax error.");
|
||||
continue;
|
||||
}
|
||||
AVMNodeDescriptor desc = fService.lookup(Integer.parseInt(command[2]),
|
||||
command[1]);
|
||||
Map<String, AVMNodeDescriptor> listing =
|
||||
fService.getDirectoryListing(desc);
|
||||
for (String name : listing.keySet())
|
||||
{
|
||||
System.out.println(name + " " + listing.get(name));
|
||||
}
|
||||
}
|
||||
else if (command[0].equals("lsrep"))
|
||||
{
|
||||
List<String> repos = fService.getRepositoryNames();
|
||||
for (String name : repos)
|
||||
{
|
||||
System.out.println(name);
|
||||
}
|
||||
}
|
||||
else if (command[0].equals("lsver"))
|
||||
{
|
||||
if (command.length != 2)
|
||||
{
|
||||
System.err.println("Syntax Error.");
|
||||
continue;
|
||||
}
|
||||
List<VersionDescriptor> listing = fService.getRepositoryVersions(command[1]);
|
||||
for (VersionDescriptor desc : listing)
|
||||
{
|
||||
System.out.println(desc);
|
||||
}
|
||||
}
|
||||
else if (command[0].equals("mkrep"))
|
||||
{
|
||||
if (command.length != 2)
|
||||
{
|
||||
System.err.println("Syntax error.");
|
||||
continue;
|
||||
}
|
||||
fService.createRepository(command[1]);
|
||||
}
|
||||
else if (command[0].equals("load"))
|
||||
{
|
||||
if (command.length != 3)
|
||||
{
|
||||
System.err.println("Syntax error.");
|
||||
continue;
|
||||
}
|
||||
fLoader.recursiveLoad(command[1], command[2]);
|
||||
}
|
||||
else if (command[0].equals("mkdir"))
|
||||
{
|
||||
if (command.length != 3)
|
||||
{
|
||||
System.err.println("Syntax error.");
|
||||
continue;
|
||||
}
|
||||
fService.createDirectory(command[1], command[2]);
|
||||
}
|
||||
else if (command[0].equals("mkldir"))
|
||||
{
|
||||
if (command.length != 4)
|
||||
{
|
||||
System.err.println("Syntax error.");
|
||||
continue;
|
||||
}
|
||||
fService.createLayeredDirectory(command[1], command[2], command[3]);
|
||||
}
|
||||
else if (command[0].equals("mklfile"))
|
||||
{
|
||||
if (command.length != 4)
|
||||
{
|
||||
System.err.println("Syntax error.");
|
||||
continue;
|
||||
}
|
||||
fService.createLayeredFile(command[1], command[2], command[3]);
|
||||
}
|
||||
else if (command[0].equals("snap"))
|
||||
{
|
||||
if (command.length != 2)
|
||||
{
|
||||
System.err.println("Syntax Error");
|
||||
continue;
|
||||
}
|
||||
fService.createSnapshot(command[1]);
|
||||
}
|
||||
else if (command[0].equals("cat"))
|
||||
{
|
||||
if (command.length != 3)
|
||||
{
|
||||
System.err.println("Syntax Error");
|
||||
continue;
|
||||
}
|
||||
BufferedReader reader =
|
||||
new BufferedReader(
|
||||
new InputStreamReader(fService.getFileInputStream(Integer.parseInt(command[2]),
|
||||
command[1])));
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null)
|
||||
{
|
||||
System.out.println(line);
|
||||
}
|
||||
reader.close();
|
||||
}
|
||||
else if (command[0].equals("rm"))
|
||||
{
|
||||
if (command.length != 3)
|
||||
{
|
||||
System.err.println("Syntax Error.");
|
||||
continue;
|
||||
}
|
||||
fService.removeNode(command[1], command[2]);
|
||||
}
|
||||
else if (command[0].equals("rmrep"))
|
||||
{
|
||||
if (command.length != 2)
|
||||
{
|
||||
System.err.println("Syntax error.");
|
||||
continue;
|
||||
}
|
||||
fService.purgeRepository(command[1]);
|
||||
}
|
||||
else if (command[0].equals("rmver"))
|
||||
{
|
||||
if (command.length != 3)
|
||||
{
|
||||
System.err.println("Syntax error.");
|
||||
continue;
|
||||
}
|
||||
fService.purgeVersion(Integer.parseInt(command[2]), command[1]);
|
||||
}
|
||||
else if (command[0].equals("write"))
|
||||
{
|
||||
if (command.length != 2)
|
||||
{
|
||||
System.err.println("Syntax error.");
|
||||
continue;
|
||||
}
|
||||
PrintStream out =
|
||||
new PrintStream(fService.getFileOutputStream(command[1]));
|
||||
String line;
|
||||
while (!(line = fIn.readLine()).equals(""))
|
||||
{
|
||||
out.println(line);
|
||||
}
|
||||
out.close();
|
||||
}
|
||||
else if (command[0].equals("create"))
|
||||
{
|
||||
if (command.length != 3)
|
||||
{
|
||||
System.err.println("Syntax error.");
|
||||
continue;
|
||||
}
|
||||
PrintStream out =
|
||||
new PrintStream(fService.createFile(command[1], command[2]));
|
||||
String line;
|
||||
while (!(line = fIn.readLine()).equals(""))
|
||||
{
|
||||
out.println(line);
|
||||
}
|
||||
out.close();
|
||||
}
|
||||
else if (command[0].equals("stat"))
|
||||
{
|
||||
if (command.length != 3)
|
||||
{
|
||||
System.err.println("Syntax error.");
|
||||
continue;
|
||||
}
|
||||
AVMNodeDescriptor desc = fService.lookup(Integer.parseInt(command[2]), command[1]);
|
||||
System.out.println(desc);
|
||||
System.out.println("Version: " + desc.getVersionID());
|
||||
System.out.println("Owner: " + desc.getOwner());
|
||||
System.out.println("Mod Time: " + new Date(desc.getModDate()));
|
||||
}
|
||||
else if (command[0].equals("exit"))
|
||||
{
|
||||
done = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
System.err.println("Syntax error.");
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace(System.err);
|
||||
}
|
||||
}
|
||||
fReaper.shutDown();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@@ -26,7 +26,7 @@ import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import org.alfresco.repo.avm.util.BulkLoad;
|
||||
import org.alfresco.repo.avm.util.BulkLoader;
|
||||
|
||||
/**
|
||||
* Big test of AVM behavior.
|
||||
@@ -1809,7 +1809,7 @@ public class AVMServiceTest extends AVMServiceTestBase
|
||||
try
|
||||
{
|
||||
ArrayList<Long> times = new ArrayList<Long>();
|
||||
BulkLoad loader = new BulkLoad(fService);
|
||||
BulkLoader loader = new BulkLoader(fService);
|
||||
loader.recursiveLoad("source/java/org/alfresco/repo", "main:/");
|
||||
times.add(System.currentTimeMillis());
|
||||
fService.createSnapshot("main");
|
||||
|
@@ -20,7 +20,7 @@ package org.alfresco.repo.avm;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.repo.avm.util.BulkLoad;
|
||||
import org.alfresco.repo.avm.util.BulkLoader;
|
||||
|
||||
/**
|
||||
* This is a stress test for the AVM repository.
|
||||
@@ -35,7 +35,7 @@ public class AVMStressTest extends AVMServiceTestBase
|
||||
{
|
||||
try
|
||||
{
|
||||
BulkLoad loader = new BulkLoad(fService);
|
||||
BulkLoader loader = new BulkLoader(fService);
|
||||
loader.recursiveLoad("source", "main:/");
|
||||
List<AVMTester> testers = new ArrayList<AVMTester>();
|
||||
List<Thread> threads = new ArrayList<Thread>();
|
||||
|
@@ -180,7 +180,6 @@ class OrphanReaper implements Runnable
|
||||
@SuppressWarnings("unchecked")
|
||||
public void doBatch()
|
||||
{
|
||||
long start = System.currentTimeMillis();
|
||||
class HTxnCallback implements HibernateTxnCallback
|
||||
{
|
||||
public void perform(Session session)
|
||||
@@ -193,6 +192,7 @@ class OrphanReaper implements Runnable
|
||||
fActive = false;
|
||||
return;
|
||||
}
|
||||
fActive = true;
|
||||
for (AVMNode node : nodes)
|
||||
{
|
||||
// Save away the ancestor and merged from fields from this node.
|
||||
@@ -267,6 +267,5 @@ class OrphanReaper implements Runnable
|
||||
e.printStackTrace(System.err);
|
||||
// TODO Log this properly.
|
||||
}
|
||||
System.err.println("Batch took: " + (System.currentTimeMillis() - start) + "ms");
|
||||
}
|
||||
}
|
||||
|
@@ -17,7 +17,7 @@
|
||||
|
||||
package org.alfresco.repo.avm;
|
||||
|
||||
import org.alfresco.repo.avm.util.BulkLoad;
|
||||
import org.alfresco.repo.avm.util.BulkLoader;
|
||||
|
||||
/**
|
||||
* Test the purge thread.
|
||||
@@ -35,7 +35,7 @@ public class PurgeTest extends AVMServiceTestBase
|
||||
OrphanReaper reaper = new OrphanReaper();
|
||||
reaper.init();
|
||||
setupBasicTree();
|
||||
BulkLoad loader = new BulkLoad(fService);
|
||||
BulkLoader loader = new BulkLoader(fService);
|
||||
long start = System.currentTimeMillis();
|
||||
loader.recursiveLoad("source", "main:/");
|
||||
System.err.println("Load time: " + (System.currentTimeMillis() - start) + "ms");
|
||||
@@ -73,7 +73,7 @@ public class PurgeTest extends AVMServiceTestBase
|
||||
OrphanReaper reaper = new OrphanReaper();
|
||||
reaper.init();
|
||||
setupBasicTree();
|
||||
BulkLoad loader = new BulkLoad(fService);
|
||||
BulkLoader loader = new BulkLoader(fService);
|
||||
long start = System.currentTimeMillis();
|
||||
loader.recursiveLoad("source", "main:/");
|
||||
System.err.println("Load time: " + (System.currentTimeMillis() - start) + "ms");
|
||||
@@ -113,7 +113,7 @@ public class PurgeTest extends AVMServiceTestBase
|
||||
OrphanReaper reaper = new OrphanReaper();
|
||||
reaper.init();
|
||||
setupBasicTree();
|
||||
BulkLoad loader = new BulkLoad(fService);
|
||||
BulkLoader loader = new BulkLoader(fService);
|
||||
long start = System.currentTimeMillis();
|
||||
loader.recursiveLoad("source", "main:/");
|
||||
System.err.println("Load time: " + (System.currentTimeMillis() - start) + "ms");
|
||||
|
@@ -115,6 +115,11 @@ class RepositoryImpl implements Repository, Serializable
|
||||
@SuppressWarnings("unchecked")
|
||||
public void createSnapshot()
|
||||
{
|
||||
// If the root isn't new, we can't take a snapshot since nothing has changed.
|
||||
if (!fRoot.getIsNew())
|
||||
{
|
||||
// TODO Silently return for now.
|
||||
}
|
||||
// Clear out the new nodes.
|
||||
Query query =
|
||||
fSuper.getSession().getNamedQuery("AVMNode.ByNewInRepo");
|
||||
@@ -393,7 +398,8 @@ class RepositoryImpl implements Repository, Serializable
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<VersionDescriptor> getVersions()
|
||||
{
|
||||
Query query = fSuper.getSession().createQuery("from VersionRootImpl v order by v.versionID");
|
||||
Query query = fSuper.getSession().createQuery("from VersionRootImpl v where v.repository = :rep order by v.versionID");
|
||||
query.setEntity("rep", this);
|
||||
List<VersionRoot> versions = (List<VersionRoot>)query.list();
|
||||
List<VersionDescriptor> descs = new ArrayList<VersionDescriptor>();
|
||||
for (VersionRoot vr : versions)
|
||||
|
@@ -17,6 +17,8 @@
|
||||
|
||||
package org.alfresco.repo.avm;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* All the information about a particular version.
|
||||
* @author britt
|
||||
@@ -96,4 +98,19 @@ public class VersionDescriptor
|
||||
{
|
||||
return fCreateDate;
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("[");
|
||||
builder.append(fRepositoryName);
|
||||
builder.append(":");
|
||||
builder.append("" + fVersionID);
|
||||
builder.append(":");
|
||||
builder.append(fCreator);
|
||||
builder.append(":");
|
||||
builder.append(new Date(fCreateDate).toString());
|
||||
builder.append("]");
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
||||
|
@@ -23,6 +23,7 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import org.alfresco.repo.avm.AVMException;
|
||||
import org.alfresco.repo.avm.AVMService;
|
||||
import org.alfresco.repo.avm.AVMServiceImpl;
|
||||
|
||||
@@ -31,7 +32,7 @@ import org.alfresco.repo.avm.AVMServiceImpl;
|
||||
* and bulk loads recursively from the filesystem.
|
||||
* @author britt
|
||||
*/
|
||||
public class BulkLoad
|
||||
public class BulkLoader
|
||||
{
|
||||
private AVMService fService;
|
||||
|
||||
@@ -50,7 +51,7 @@ public class BulkLoad
|
||||
AVMServiceImpl service = new AVMServiceImpl();
|
||||
service.setStorage(args[0]);
|
||||
service.init(args[1].equals("new"));
|
||||
BulkLoad loader = new BulkLoad(service);
|
||||
BulkLoader loader = new BulkLoader(service);
|
||||
loader.recursiveLoad(args[2], args[3]);
|
||||
service.createSnapshot("main");
|
||||
}
|
||||
@@ -59,7 +60,7 @@ public class BulkLoad
|
||||
* Create a new one.
|
||||
* @param service
|
||||
*/
|
||||
public BulkLoad(AVMService service)
|
||||
public BulkLoader(AVMService service)
|
||||
{
|
||||
fService = service;
|
||||
}
|
||||
@@ -102,7 +103,7 @@ public class BulkLoad
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace(System.err);
|
||||
System.exit(1);
|
||||
throw new AVMException("I/O Error");
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user