[exo-jcr-commits] exo-jcr SVN: r2119 - in jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup: server and 2 other directories.
do-not-reply at jboss.org
do-not-reply at jboss.org
Thu Mar 25 07:52:37 EDT 2010
Author: tolusha
Date: 2010-03-25 07:52:37 -0400 (Thu, 25 Mar 2010)
New Revision: 2119
Modified:
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/BackupManagerImpl.java
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/JobRepositoryRestore.java
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/server/HTTPBackupAgent.java
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/server/bean/BackupConfigBean.java
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/server/bean/response/DetailedInfo.java
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/server/bean/response/DetailedInfoEx.java
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/server/bean/response/ShortInfo.java
Log:
EXOJCR-549: HTTPBackupAgent impl
Modified: jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/BackupManagerImpl.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/BackupManagerImpl.java 2010-03-25 11:28:12 UTC (rev 2118)
+++ jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/BackupManagerImpl.java 2010-03-25 11:52:37 UTC (rev 2119)
@@ -98,8 +98,7 @@
* @version $Id: $
*/
-public class BackupManagerImpl
- implements BackupManager, Startable
+public class BackupManagerImpl implements BackupManager, Startable
{
protected static Log log = ExoLogger.getLogger("ext.BackupManagerImpl");
@@ -131,14 +130,14 @@
private String incrementalBackupType;
private final Set<BackupChain> currentBackups;
-
+
private final Set<RepositoryBackupChain> currentRepositoryBackups;
/**
* The list of workspace restore job.
*/
private List<JobWorkspaceRestore> restoreJobs;
-
+
/**
* The list of repository restore job.
*/
@@ -161,11 +160,10 @@
private final MessagesListener messagesListener;
private final WorkspaceBackupAutoStopper workspaceBackupStopper;
-
+
private final RepositoryBackupAutoStopper repositoryBackupStopper;
- class MessagesListener
- implements BackupJobListener
+ class MessagesListener implements BackupJobListener
{
public void onError(BackupJob job, String message, Throwable error)
@@ -248,8 +246,7 @@
}
}
- class LogsFilter
- implements FileFilter
+ class LogsFilter implements FileFilter
{
public boolean accept(File pathname)
@@ -258,8 +255,7 @@
}
}
- class TaskFilter
- implements FileFilter
+ class TaskFilter implements FileFilter
{
public boolean accept(File pathname)
@@ -268,8 +264,7 @@
}
}
- class WorkspaceBackupAutoStopper
- extends Thread
+ class WorkspaceBackupAutoStopper extends Thread
{
/**
@@ -315,50 +310,49 @@
}
}
}
-
- class RepositoryBackupAutoStopper
- extends Thread
-{
- /**
- * {@inheritDoc}
- */
- public void run()
+ class RepositoryBackupAutoStopper extends Thread
{
- while (true)
+
+ /**
+ * {@inheritDoc}
+ */
+ public void run()
{
- try
+ while (true)
{
- Thread.sleep(AUTO_STOPPER_TIMEOUT);
+ try
+ {
+ Thread.sleep(AUTO_STOPPER_TIMEOUT);
- Iterator<RepositoryBackupChain> it = currentRepositoryBackups.iterator();
- List<RepositoryBackupChain> stopedList = new ArrayList<RepositoryBackupChain>();
+ Iterator<RepositoryBackupChain> it = currentRepositoryBackups.iterator();
+ List<RepositoryBackupChain> stopedList = new ArrayList<RepositoryBackupChain>();
- while (it.hasNext())
- {
- RepositoryBackupChain chain = it.next();
+ while (it.hasNext())
+ {
+ RepositoryBackupChain chain = it.next();
- if (chain.isFinished())
- {
- stopedList.add(chain);
+ if (chain.isFinished())
+ {
+ stopedList.add(chain);
+ }
}
+
+ // STOP backups
+ for (RepositoryBackupChain chain : stopedList)
+ stopBackup(chain);
}
-
- // STOP backups
- for (RepositoryBackupChain chain : stopedList)
- stopBackup(chain);
+ catch (InterruptedException e)
+ {
+ log.error("The interapted this thread.", e);
+ }
+ catch (Throwable e)
+ {
+ log.error("The unknown error", e);
+ }
}
- catch (InterruptedException e)
- {
- log.error("The interapted this thread.", e);
- }
- catch (Throwable e)
- {
- log.error("The unknown error", e);
- }
}
}
-}
/**
* BackupManagerImpl constructor.
@@ -391,7 +385,7 @@
this.initParams = initParams;
currentBackups = Collections.synchronizedSet(new HashSet<BackupChain>());
-
+
currentRepositoryBackups = Collections.synchronizedSet(new HashSet<RepositoryBackupChain>());
fileCleaner = new FileCleaner(10000);
@@ -402,10 +396,10 @@
this.restoreJobs = new ArrayList<JobWorkspaceRestore>();
this.restoreRepositoryJobs = new ArrayList<JobRepositoryRestore>();
-
+
this.workspaceBackupStopper = new WorkspaceBackupAutoStopper();
this.workspaceBackupStopper.start();
-
+
this.repositoryBackupStopper = new RepositoryBackupAutoStopper();
this.repositoryBackupStopper.start();
}
@@ -473,8 +467,8 @@
*/
@Deprecated
public void restore(BackupChainLog log, String repositoryName, WorkspaceEntry workspaceEntry)
- throws BackupOperationException, RepositoryException, RepositoryConfigurationException,
- BackupConfigurationException
+ throws BackupOperationException, RepositoryException, RepositoryConfigurationException,
+ BackupConfigurationException
{
List<JobEntryInfo> list = log.getJobEntryInfos();
BackupConfig config = log.getBackupConfig();
@@ -531,8 +525,8 @@
}
protected void restoreOverInitializer(BackupChainLog log, String repositoryName, WorkspaceEntry workspaceEntry)
- throws BackupOperationException, RepositoryException, RepositoryConfigurationException,
- BackupConfigurationException
+ throws BackupOperationException, RepositoryException, RepositoryConfigurationException,
+ BackupConfigurationException
{
List<JobEntryInfo> list = log.getJobEntryInfos();
@@ -561,7 +555,7 @@
{
throw new BackupOperationException("Restore of full backup file I/O error " + e, e);
}
-
+
repoService.getConfig().retain(); // save configuration to persistence (file or persister)
}
else
@@ -592,7 +586,7 @@
}
private boolean workspaceAlreadyExist(String repository, String workspace) throws RepositoryException,
- RepositoryConfigurationException
+ RepositoryConfigurationException
{
String[] ws = repoService.getRepository(repository).getWorkspaceNames();
@@ -606,7 +600,7 @@
* {@inheritDoc}
*/
public BackupChain startBackup(BackupConfig config) throws BackupOperationException, BackupConfigurationException,
- RepositoryException, RepositoryConfigurationException
+ RepositoryException, RepositoryConfigurationException
{
return startBackup(config, null);
@@ -624,14 +618,14 @@
* @throws RepositoryConfigurationException
*/
BackupChain startBackup(BackupConfig config, BackupJobListener jobListener) throws BackupOperationException,
- BackupConfigurationException, RepositoryException, RepositoryConfigurationException
+ BackupConfigurationException, RepositoryException, RepositoryConfigurationException
{
validateBackupConfig(config);
BackupChain bchain =
- new BackupChainImpl(config, logsDirectory, repoService.getRepository(config.getRepository()),
- fullBackupType, incrementalBackupType, IdGenerator.generate());
-
+ new BackupChainImpl(config, logsDirectory, repoService.getRepository(config.getRepository()), fullBackupType,
+ incrementalBackupType, IdGenerator.generate());
+
bchain.addListener(messagesListener);
bchain.addListener(jobListener);
@@ -640,7 +634,7 @@
return bchain;
}
-
+
/**
* Initialize backup chain to workspace backup.
*
@@ -756,22 +750,22 @@
@Deprecated
private void fullRestore(String pathBackupFile, String repositoryName, String workspaceName,
- WorkspaceEntry workspaceEntry) throws FileNotFoundException, IOException, RepositoryException,
- RepositoryConfigurationException
+ WorkspaceEntry workspaceEntry) throws FileNotFoundException, IOException, RepositoryException,
+ RepositoryConfigurationException
{
- RepositoryImpl defRep = (RepositoryImpl) repoService.getRepository(repositoryName);
+ RepositoryImpl defRep = (RepositoryImpl)repoService.getRepository(repositoryName);
defRep.importWorkspace(workspaceEntry.getName(), new FileInputStream(pathBackupFile));
}
private void fullRestoreOverInitializer(String pathBackupFile, String repositoryName, WorkspaceEntry workspaceEntry)
- throws FileNotFoundException, IOException, RepositoryException, RepositoryConfigurationException
+ throws FileNotFoundException, IOException, RepositoryException, RepositoryConfigurationException
{
WorkspaceInitializerEntry wieOriginal = workspaceEntry.getInitializer();
-
- RepositoryImpl defRep = (RepositoryImpl) repoService.getRepository(repositoryName);
+ RepositoryImpl defRep = (RepositoryImpl)repoService.getRepository(repositoryName);
+
// set the initializer SysViewWorkspaceInitializer
WorkspaceInitializerEntry wiEntry = new WorkspaceInitializerEntry();
wiEntry.setType(SysViewWorkspaceInitializer.class.getCanonicalName());
@@ -786,21 +780,21 @@
//restore
defRep.configWorkspace(workspaceEntry);
defRep.createWorkspace(workspaceEntry.getName());
-
+
//set original workspace initializer
WorkspaceContainerFacade wcf = defRep.getWorkspaceContainer(workspaceEntry.getName());
- WorkspaceEntry createdWorkspaceEntry = (WorkspaceEntry) wcf.getComponent(WorkspaceEntry.class);
+ WorkspaceEntry createdWorkspaceEntry = (WorkspaceEntry)wcf.getComponent(WorkspaceEntry.class);
createdWorkspaceEntry.setInitializer(wieOriginal);
}
private void incrementalRestore(String pathBackupFile, String repositoryName, String workspaceName)
- throws RepositoryException, RepositoryConfigurationException, BackupOperationException,
- FileNotFoundException, IOException, ClassNotFoundException
+ throws RepositoryException, RepositoryConfigurationException, BackupOperationException, FileNotFoundException,
+ IOException, ClassNotFoundException
{
- SessionImpl sesion = (SessionImpl) repoService.getRepository(repositoryName).getSystemSession(workspaceName);
+ SessionImpl sesion = (SessionImpl)repoService.getRepository(repositoryName).getSystemSession(workspaceName);
WorkspacePersistentDataManager dataManager =
- (WorkspacePersistentDataManager) sesion.getContainer().getComponentInstanceOfType(
- WorkspacePersistentDataManager.class);
+ (WorkspacePersistentDataManager)sesion.getContainer().getComponentInstanceOfType(
+ WorkspacePersistentDataManager.class);
ObjectInputStream ois = null;
File backupFile = null;
@@ -835,7 +829,7 @@
}
private void saveChangesLog(WorkspacePersistentDataManager dataManager, TransactionChangesLog changesLog)
- throws RepositoryException, BackupOperationException
+ throws RepositoryException, BackupOperationException
{
try
{
@@ -844,24 +838,24 @@
catch (JCRInvalidItemStateException e)
{
TransactionChangesLog normalizeChangesLog =
- getNormalizedChangesLog(e.getIdentifier(), e.getState(), changesLog);
+ getNormalizedChangesLog(e.getIdentifier(), e.getState(), changesLog);
if (normalizeChangesLog != null)
saveChangesLog(dataManager, normalizeChangesLog);
else
throw new BackupOperationException(
- "Collisions found during save of restore changes log, but caused item is not found by ID "
- + e.getIdentifier() + ". " + e, e);
+ "Collisions found during save of restore changes log, but caused item is not found by ID "
+ + e.getIdentifier() + ". " + e, e);
}
catch (JCRItemExistsException e)
{
TransactionChangesLog normalizeChangesLog =
- getNormalizedChangesLog(e.getIdentifier(), e.getState(), changesLog);
+ getNormalizedChangesLog(e.getIdentifier(), e.getState(), changesLog);
if (normalizeChangesLog != null)
saveChangesLog(dataManager, normalizeChangesLog);
else
throw new RepositoryException(
- "Collisions found during save of restore changes log, but caused item is not found by ID "
- + e.getIdentifier() + ". " + e, e);
+ "Collisions found during save of restore changes log, but caused item is not found by ID "
+ + e.getIdentifier() + ". " + e, e);
}
}
@@ -891,7 +885,7 @@
{
// Node... by ID and desc path
if (!item.getIdentifier().equals(collisionID)
- && !item.getQPath().isDescendantOf(citem.getData().getQPath()))
+ && !item.getQPath().isDescendantOf(citem.getData().getQPath()))
normalized.add(change);
}
else if (!item.getIdentifier().equals(collisionID))
@@ -925,7 +919,7 @@
{
// read ChangesLog
- transactionChangesLog = (TransactionChangesLog) in.readObject();
+ transactionChangesLog = (TransactionChangesLog)in.readObject();
// read FixupStream count
int iFixupStream = in.readInt();
@@ -956,7 +950,7 @@
}
PendingChangesLog pendingChangesLog =
- new PendingChangesLog(transactionChangesLog, listFixupStreams, listFiles, fileCleaner);
+ new PendingChangesLog(transactionChangesLog, listFixupStreams, listFiles, fileCleaner);
pendingChangesLog.restore();
@@ -965,7 +959,7 @@
}
else if (changesLogType == PendingChangesLog.Type.CHANGESLOG_WITHOUT_STREAM)
{
- transactionChangesLog = (TransactionChangesLog) in.readObject();
+ transactionChangesLog = (TransactionChangesLog)in.readObject();
}
return transactionChangesLog;
@@ -990,8 +984,8 @@
}
else if (readBytes < bufferSize)
{
- ois.readFully(buf, 0, (int) readBytes);
- fos.write(buf, 0, (int) readBytes);
+ ois.readFully(buf, 0, (int)readBytes);
+ fos.write(buf, 0, (int)readBytes);
}
readBytes -= bufferSize;
}
@@ -1013,7 +1007,7 @@
* @throws RepositoryException
*/
private void writeParamsToRegistryService(SessionProvider sessionProvider) throws IOException, SAXException,
- ParserConfigurationException, RepositoryException
+ ParserConfigurationException, RepositoryException
{
Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
Element root = doc.createElement(SERVICE_NAME);
@@ -1039,7 +1033,7 @@
* @throws PathNotFoundException
*/
private void readParamsFromRegistryService(SessionProvider sessionProvider) throws PathNotFoundException,
- RepositoryException
+ RepositoryException
{
String entryPath = RegistryService.EXO_SERVICES + "/" + SERVICE_NAME + "/" + BACKUP_PROPERTIES;
RegistryEntry registryEntry = registryService.getEntry(sessionProvider, entryPath);
@@ -1151,7 +1145,7 @@
{
BackupChain chain = it.next();
if (repository.equals(chain.getBackupConfig().getRepository())
- && workspace.equals(chain.getBackupConfig().getWorkspace()))
+ && workspace.equals(chain.getBackupConfig().getWorkspace()))
return chain;
}
return null;
@@ -1249,13 +1243,13 @@
return null;
}
-
+
/**
* {@inheritDoc}
*/
public JobRepositoryRestore getLastRepositoryRestore(String repositoryName)
{
-
+
for (int i = restoreRepositoryJobs.size() - 1; i >= 0; i--)
{
JobRepositoryRestore job = restoreRepositoryJobs.get(i);
@@ -1279,13 +1273,13 @@
* {@inheritDoc}
*/
public void restore(BackupChainLog log, String repositoryName, WorkspaceEntry workspaceEntry, boolean asynchronous)
- throws BackupOperationException, BackupConfigurationException, RepositoryException,
- RepositoryConfigurationException
+ throws BackupOperationException, BackupConfigurationException, RepositoryException,
+ RepositoryConfigurationException
{
if (asynchronous)
{
JobWorkspaceRestore jobRestore =
- new JobWorkspaceRestore(repoService, this, repositoryName, log, workspaceEntry);
+ new JobWorkspaceRestore(repoService, this, repositoryName, log, workspaceEntry);
restoreJobs.add(jobRestore);
jobRestore.start();
}
@@ -1294,51 +1288,56 @@
this.restoreOverInitializer(log, repositoryName, workspaceEntry);
}
}
-
+
/**
* {@inheritDoc}
*/
public void restore(RepositoryBackupChainLog log, RepositoryEntry repositoryEntry, boolean asynchronous)
- throws BackupOperationException, BackupConfigurationException, RepositoryException,
- RepositoryConfigurationException
+ throws BackupOperationException, BackupConfigurationException, RepositoryException,
+ RepositoryConfigurationException
{
this.restore(log, repositoryEntry, null, asynchronous);
}
-
+
/**
* {@inheritDoc}
*/
public void restore(RepositoryBackupChainLog rblog, RepositoryEntry repositoryEntry,
- Map<String, String> workspaceNamesCorrespondMap, boolean asynchronous) throws BackupOperationException,
- BackupConfigurationException, RepositoryException, RepositoryConfigurationException
+ Map<String, String> workspaceNamesCorrespondMap, boolean asynchronous) throws BackupOperationException,
+ BackupConfigurationException, RepositoryException, RepositoryConfigurationException
{
Map<String, BackupChainLog> workspacesMapping = new HashedMap();
Map<String, BackupChainLog> backups = new HashedMap();
-
- if (workspaceNamesCorrespondMap == null)
+
+ if (workspaceNamesCorrespondMap == null)
{
for (String path : rblog.getWorkspaceBackupsInfo())
{
BackupChainLog bLog = new BackupChainLog(new File(path));
backups.put(bLog.getBackupConfig().getWorkspace(), bLog);
}
-
- if (!rblog.getSystemWorkspace().equals(repositoryEntry.getSystemWorkspaceName()))
+
+ if (!rblog.getSystemWorkspace().equals(repositoryEntry.getSystemWorkspaceName()))
{
- throw new BackupConfigurationException("The backup to system workspace is not system workspace in repository entry: " + rblog.getSystemWorkspace() + " is not equal " + repositoryEntry.getSystemWorkspaceName());
+ throw new BackupConfigurationException(
+ "The backup to system workspace is not system workspace in repository entry: "
+ + rblog.getSystemWorkspace() + " is not equal " + repositoryEntry.getSystemWorkspaceName());
}
-
- if (backups.size() != repositoryEntry.getWorkspaceEntries().size())
+
+ if (backups.size() != repositoryEntry.getWorkspaceEntries().size())
{
- throw new BackupConfigurationException("The repository entry is contains more or less workspace entry than backups of workspace in " + rblog.getLogFilePath());
+ throw new BackupConfigurationException(
+ "The repository entry is contains more or less workspace entry than backups of workspace in "
+ + rblog.getLogFilePath());
}
-
+
for (WorkspaceEntry wsEntry : repositoryEntry.getWorkspaceEntries())
{
- if (!backups.containsKey(wsEntry.getName()))
+ if (!backups.containsKey(wsEntry.getName()))
{
- throw new BackupConfigurationException("The workspace '" + wsEntry.getName() + "' is not found in backup " + rblog.getLogFilePath());
+ throw new BackupConfigurationException("The workspace '" + wsEntry.getName()
+ + "' is not found in backup " + rblog.getLogFilePath());
}
else
{
@@ -1348,41 +1347,49 @@
}
else
{
- // Crate map [new_ws_name : backupLog to that workspace].
+ // Create map [new_ws_name : backupLog to that workspace].
for (String path : rblog.getWorkspaceBackupsInfo())
{
BackupChainLog bLog = new BackupChainLog(new File(path));
-
- if (!workspaceNamesCorrespondMap.containsKey(bLog.getBackupConfig().getWorkspace()))
+
+ if (!workspaceNamesCorrespondMap.containsKey(bLog.getBackupConfig().getWorkspace()))
{
- throw new BackupConfigurationException("Can not found coresptonding workspace name to workspace '"
- + bLog.getBackupConfig().getWorkspace() + "' in " + workspaceNamesCorrespondMap .keySet());
+ throw new BackupConfigurationException("Can not found coresptonding workspace name to workspace '"
+ + bLog.getBackupConfig().getWorkspace() + "' in " + workspaceNamesCorrespondMap.keySet());
}
-
+
backups.put(workspaceNamesCorrespondMap.get(bLog.getBackupConfig().getWorkspace()), bLog);
}
-
+
// Checking system workspace.
- if (!repositoryEntry.getSystemWorkspaceName().equals(workspaceNamesCorrespondMap.get(rblog.getSystemWorkspace())))
+ if (!repositoryEntry.getSystemWorkspaceName().equals(
+ workspaceNamesCorrespondMap.get(rblog.getSystemWorkspace())))
{
- throw new BackupConfigurationException("The backup to system workspace is not system workspace in repository entry: " + repositoryEntry.getSystemWorkspaceName() + " is not equal " + workspaceNamesCorrespondMap.get(rblog.getSystemWorkspace()));
+ throw new BackupConfigurationException(
+ "The backup to system workspace is not system workspace in repository entry: "
+ + repositoryEntry.getSystemWorkspaceName() + " is not equal "
+ + workspaceNamesCorrespondMap.get(rblog.getSystemWorkspace()));
}
-
+
// Checking count of corresponding workspaces.
- if (workspaceNamesCorrespondMap.size() != repositoryEntry.getWorkspaceEntries().size())
+ if (workspaceNamesCorrespondMap.size() != repositoryEntry.getWorkspaceEntries().size())
{
- throw new BackupConfigurationException("The repository entry is contains more or less workspace entry than backups of workspace in " + rblog.getLogFilePath());
+ throw new BackupConfigurationException(
+ "The repository entry is contains more or less workspace entry than backups of workspace in "
+ + rblog.getLogFilePath());
}
-
+
for (WorkspaceEntry wsEntry : repositoryEntry.getWorkspaceEntries())
{
- if (!workspaceNamesCorrespondMap.containsValue(wsEntry.getName()))
+ if (!workspaceNamesCorrespondMap.containsValue(wsEntry.getName()))
{
- throw new BackupConfigurationException("The workspace '" + wsEntry.getName() + "' is not found workspaceNamesCorrespondMap : " + workspaceNamesCorrespondMap.values());
+ throw new BackupConfigurationException("The workspace '" + wsEntry.getName()
+ + "' is not found workspaceNamesCorrespondMap : " + workspaceNamesCorrespondMap.values());
}
else if (!backups.containsKey(wsEntry.getName()))
{
- throw new BackupConfigurationException("The workspace '" + wsEntry.getName() + "' is not found in backup " + rblog.getLogFilePath());
+ throw new BackupConfigurationException("The workspace '" + wsEntry.getName()
+ + "' is not found in backup " + rblog.getLogFilePath());
}
else
{
@@ -1390,10 +1397,11 @@
}
}
}
-
+
JobRepositoryRestore jobRepositoryRestore =
- new JobRepositoryRestore(repoService, this, repositoryEntry, workspacesMapping);
-
+ new JobRepositoryRestore(repoService, this, repositoryEntry, workspacesMapping, new RepositoryBackupChainLog(
+ new File(rblog.getLogFilePath()))); // TODO
+
if (asynchronous)
{
restoreRepositoryJobs.add(jobRepositoryRestore);
@@ -1409,24 +1417,24 @@
* {@inheritDoc}
*/
public RepositoryBackupChain startBackup(RepositoryBackupConfig config) throws BackupOperationException,
- BackupConfigurationException, RepositoryException, RepositoryConfigurationException
+ BackupConfigurationException, RepositoryException, RepositoryConfigurationException
{
validateBackupConfig(config);
ManageableRepository repository = repoService.getRepository(config.getRepository());
File dir =
- new File(config.getBackupDir() + File.separator + "repository_" + config.getRepository() + "_backup_"
- + System.currentTimeMillis());
+ new File(config.getBackupDir() + File.separator + "repository_" + config.getRepository() + "_backup_"
+ + System.currentTimeMillis());
dir.mkdir();
config.setBackupDir(dir);
RepositoryBackupChain repositoryBackupChain =
- new RepositoryBackupChainImpl(config, logsDirectory, repository, fullBackupType, incrementalBackupType,
- IdGenerator.generate());
-
+ new RepositoryBackupChainImpl(config, logsDirectory, repository, fullBackupType, incrementalBackupType,
+ IdGenerator.generate());
+
repositoryBackupChain.startBackup();
-
+
currentRepositoryBackups.add(repositoryBackupChain);
return repositoryBackupChain;
Modified: jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/JobRepositoryRestore.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/JobRepositoryRestore.java 2010-03-25 11:28:12 UTC (rev 2118)
+++ jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/JobRepositoryRestore.java 2010-03-25 11:52:37 UTC (rev 2119)
@@ -34,6 +34,7 @@
import org.exoplatform.services.jcr.core.ManageableRepository;
import org.exoplatform.services.jcr.core.WorkspaceContainerFacade;
import org.exoplatform.services.jcr.ext.backup.BackupChainLog;
+import org.exoplatform.services.jcr.ext.backup.RepositoryBackupChainLog;
import org.exoplatform.services.jcr.ext.backup.RepositoryRestoreExeption;
import org.exoplatform.services.jcr.ext.backup.server.WorkspaceRestoreExeption;
import org.exoplatform.services.jcr.impl.core.BackupWorkspaceInitializer;
@@ -57,7 +58,7 @@
* The apache logger.
*/
private static Log log = ExoLogger.getLogger("ext.JobRepositoryRestore");
-
+
/**
* REPOSITORY_RESTORE_STARTED. The state of start restore.
*/
@@ -82,7 +83,7 @@
* The state of restore.
*/
private int stateRestore;
-
+
/**
* The start time of restore.
*/
@@ -92,27 +93,31 @@
* The end time of restore.
*/
private Calendar endTime;
-
+
/**
* The exception on restore.
*/
private Throwable restoreException = null;
-
+
private RepositoryService repositoryService;
-
+
private BackupManagerImpl backupManager;
-
+
private RepositoryEntry repositoryEntry;
-
+
private Map<String, BackupChainLog> workspacesMapping;
+ private RepositoryBackupChainLog repositoryBackupChainLog;
+
public JobRepositoryRestore(RepositoryService repoService, BackupManagerImpl backupManagerImpl,
- RepositoryEntry repositoryEntry, Map<String, BackupChainLog> workspacesMapping)
+ RepositoryEntry repositoryEntry, Map<String, BackupChainLog> workspacesMapping,
+ RepositoryBackupChainLog backupChainLog)
{
this.repositoryService = repoService;
this.backupManager = backupManagerImpl;
this.repositoryEntry = repositoryEntry;
this.workspacesMapping = workspacesMapping;
+ this.repositoryBackupChainLog = backupChainLog;
}
/**
@@ -122,82 +127,86 @@
* @throws Throwable
* will be generated the Throwable
*/
- protected void restore() throws RepositoryRestoreExeption
+ protected void restore() throws RepositoryRestoreExeption
{
List<WorkspaceEntry> originalWorkspaceEntrys = repositoryEntry.getWorkspaceEntries();
-
+
//Getting system workspace entry
WorkspaceEntry systemWorkspaceEntry = null;
-
+
for (WorkspaceEntry wsEntry : originalWorkspaceEntrys)
{
- if (wsEntry.getName().equals(repositoryEntry.getSystemWorkspaceName()))
+ if (wsEntry.getName().equals(repositoryEntry.getSystemWorkspaceName()))
{
systemWorkspaceEntry = wsEntry;
break;
}
}
-
+
WorkspaceInitializerEntry wieOriginal = systemWorkspaceEntry.getInitializer();
-
- //getting backup cahil log to system workspace.
+
+ //getting backup chail log to system workspace.
BackupChainLog systemBackupChainLog = workspacesMapping.get(systemWorkspaceEntry.getName());
File fullBackupFile = new File(systemBackupChainLog.getJobEntryInfos().get(0).getURL().getPath());
-
+
// set the initializer SysViewWorkspaceInitializer
WorkspaceInitializerEntry wiEntry = new WorkspaceInitializerEntry();
wiEntry.setType(BackupWorkspaceInitializer.class.getCanonicalName());
List<SimpleParameterEntry> wieParams = new ArrayList<SimpleParameterEntry>();
- wieParams.add(new SimpleParameterEntry(BackupWorkspaceInitializer.RESTORE_PATH_PARAMETER, fullBackupFile.getParent()));
+ wieParams.add(new SimpleParameterEntry(BackupWorkspaceInitializer.RESTORE_PATH_PARAMETER, fullBackupFile
+ .getParent()));
wiEntry.setParameters(wieParams);
// set initializer
systemWorkspaceEntry.setInitializer(wiEntry);
-
+
ArrayList<WorkspaceEntry> newEntries = new ArrayList<WorkspaceEntry>();
newEntries.add(systemWorkspaceEntry);
-
+
repositoryEntry.setWorkspaceEntries(newEntries);
-
+
String currennWorkspaceName = repositoryEntry.getSystemWorkspaceName();
-
+
boolean restored = true;
try
{
repositoryService.createRepository(repositoryEntry);
-
+
//set original initializer to created workspace.
- RepositoryImpl defRep = (RepositoryImpl) repositoryService.getRepository(repositoryEntry.getName());
+ RepositoryImpl defRep = (RepositoryImpl)repositoryService.getRepository(repositoryEntry.getName());
WorkspaceContainerFacade wcf = defRep.getWorkspaceContainer(systemWorkspaceEntry.getName());
- WorkspaceEntry createdWorkspaceEntry = (WorkspaceEntry) wcf.getComponent(WorkspaceEntry.class);
+ WorkspaceEntry createdWorkspaceEntry = (WorkspaceEntry)wcf.getComponent(WorkspaceEntry.class);
createdWorkspaceEntry.setInitializer(wieOriginal);
-
+
// save configuration to persistence (file or persister)
- repositoryService.getConfig().retain();
-
- for (WorkspaceEntry wsEntry : originalWorkspaceEntrys)
- {
- if (!(wsEntry.getName().equals(repositoryEntry.getSystemWorkspaceName())))
- {
- currennWorkspaceName = wsEntry.getName();
- backupManager.restore(workspacesMapping.get(wsEntry.getName()), repositoryEntry.getName(), wsEntry, false);
- }
- }
+ repositoryService.getConfig().retain();
+ backupManager.restore(repositoryBackupChainLog, repositoryEntry, false);
+
+ // TODO
+ // for (WorkspaceEntry wsEntry : originalWorkspaceEntrys)
+ // {
+ // if (!(wsEntry.getName().equals(repositoryEntry.getSystemWorkspaceName())))
+ // {
+ // currennWorkspaceName = wsEntry.getName();
+ // backupManager.restore(workspacesMapping.get(wsEntry.getName()), repositoryEntry.getName(), wsEntry,
+ // false);
+ // }
+ // }
}
catch (InvalidItemStateException e)
{
restored = false;
- throw new RepositoryRestoreExeption("Workspace '" + "/" + repositoryEntry.getName() + "/" + currennWorkspaceName
- + "' can not be restored! There was database error!", e);
+ throw new RepositoryRestoreExeption("Workspace '" + "/" + repositoryEntry.getName() + "/"
+ + currennWorkspaceName + "' can not be restored! There was database error!", e);
}
catch (Throwable t)
{
restored = false;
- throw new RepositoryRestoreExeption("Workspace '" + "/" + repositoryEntry.getName() + "/" + currennWorkspaceName
- + "' can not be restored!", t);
+ throw new RepositoryRestoreExeption("Workspace '" + "/" + repositoryEntry.getName() + "/"
+ + currennWorkspaceName + "' can not be restored!", t);
}
finally
@@ -207,16 +216,16 @@
try
{
ManageableRepository mr = null;
-
- try
+
+ try
{
mr = repositoryService.getRepository(repositoryEntry.getName());
- }
+ }
catch (RepositoryException e)
{
// The repository not exist.
}
-
+
if (mr != null)
{
closeAllSession(mr);
@@ -226,13 +235,13 @@
}
catch (Throwable thr)
{
- throw new RepositoryRestoreExeption("Reprository '" + "/" + repositoryEntry.getName() +
- "' can not be restored!", thr);
+ throw new RepositoryRestoreExeption("Reprository '" + "/" + repositoryEntry.getName()
+ + "' can not be restored!", thr);
}
}
}
}
-
+
/**
* Close all open session in repository
*
@@ -247,7 +256,7 @@
if (!mr.canRemoveWorkspace(wsName))
{
WorkspaceContainerFacade wc = mr.getWorkspaceContainer(wsName);
- SessionRegistry sessionRegistry = (SessionRegistry) wc.getComponent(SessionRegistry.class);
+ SessionRegistry sessionRegistry = (SessionRegistry)wc.getComponent(SessionRegistry.class);
sessionRegistry.closeSessions(wsName);
}
}
@@ -258,7 +267,7 @@
*/
public void run()
{
-
+
try
{
stateRestore = REPOSITORY_RESTORE_STARTED;
@@ -287,7 +296,7 @@
{
return restoreException;
}
-
+
/**
* getStateRestore.
*
@@ -317,7 +326,7 @@
{
return endTime;
}
-
+
/**
* getRepositoryName.
*
@@ -328,4 +337,25 @@
{
return repositoryEntry.getName();
}
+
+ /**
+ * GetRepositoryBackupChainLog.
+ *
+ * @return repositoryBackupChainLog
+ */
+ public RepositoryBackupChainLog getRepositoryBackupChainLog()
+ {
+ return repositoryBackupChainLog;
+ }
+
+ /**
+ * getRepositoryEntry.
+ *
+ * @return repositoryBackupChainLog
+ */
+ public RepositoryEntry getRepositoryEntry()
+ {
+ return repositoryEntry;
+ }
+
}
Modified: jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/server/HTTPBackupAgent.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/server/HTTPBackupAgent.java 2010-03-25 11:28:12 UTC (rev 2118)
+++ jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/server/HTTPBackupAgent.java 2010-03-25 11:52:37 UTC (rev 2119)
@@ -40,6 +40,7 @@
import org.exoplatform.services.jcr.RepositoryService;
import org.exoplatform.services.jcr.config.RepositoryConfigurationException;
+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.core.WorkspaceContainerFacade;
@@ -50,6 +51,10 @@
import org.exoplatform.services.jcr.ext.backup.BackupConfigurationException;
import org.exoplatform.services.jcr.ext.backup.BackupManager;
import org.exoplatform.services.jcr.ext.backup.BackupOperationException;
+import org.exoplatform.services.jcr.ext.backup.RepositoryBackupChain;
+import org.exoplatform.services.jcr.ext.backup.RepositoryBackupChainLog;
+import org.exoplatform.services.jcr.ext.backup.RepositoryBackupConfig;
+import org.exoplatform.services.jcr.ext.backup.impl.JobRepositoryRestore;
import org.exoplatform.services.jcr.ext.backup.impl.JobWorkspaceRestore;
import org.exoplatform.services.jcr.ext.backup.server.bean.BackupConfigBean;
import org.exoplatform.services.jcr.ext.backup.server.bean.response.BackupServiceInfoBean;
@@ -74,8 +79,7 @@
*/
@Path("/jcr-backup/")
-public class HTTPBackupAgent
- implements ResourceContainer
+public class HTTPBackupAgent implements ResourceContainer
{
/**
@@ -223,7 +227,7 @@
* the ThreadLocalSessionProviderService
*/
public HTTPBackupAgent(RepositoryService repoService, BackupManager backupManager,
- ThreadLocalSessionProviderService sessionProviderService)
+ ThreadLocalSessionProviderService sessionProviderService)
{
this.repositoryService = repoService;
this.backupManager = backupManager;
@@ -249,7 +253,7 @@
@RolesAllowed("administrators")
@Path("/start/{repo}/{ws}")
public Response start(BackupConfigBean bConfigBeen, @PathParam("repo") String repository,
- @PathParam("ws") String workspace)
+ @PathParam("ws") String workspace)
{
String failMessage;
Response.Status status;
@@ -331,10 +335,96 @@
log.error("Can not start backup", exception);
return Response.status(status).entity("Can not start backup : " + failMessage).type(MediaType.TEXT_PLAIN)
- .cacheControl(noCache).build();
+ .cacheControl(noCache).build();
}
/**
+ * The start repository backup.
+ *
+ * @param bConfigBeen
+ * BackupConfigBeen, the been with backup configuration.
+ * @param repository
+ * String, the repository name
+ * @return Response return the response
+ */
+ @POST
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @RolesAllowed("administrators")
+ @Path("/start/{repo}}")
+ public Response start(BackupConfigBean bConfigBeen, @PathParam("repo") String repository)
+ {
+ String failMessage;
+ Response.Status status;
+ Throwable exception;
+
+ try
+ {
+ File backupDir = new File(bConfigBeen.getBackupDir());
+ if (!backupDir.exists())
+ {
+ throw new BackupDirNotFoundException("The backup folder not exists : " + backupDir.getAbsolutePath());
+ }
+
+ RepositoryBackupConfig config = new RepositoryBackupConfig();
+ config.setBackupType(bConfigBeen.getBackupType());
+ config.setRepository(repository);
+ config.setBackupDir(backupDir);
+ config.setIncrementalJobPeriod(bConfigBeen.getIncrementalJobPeriod());
+ config.setIncrementalJobNumber(bConfigBeen.getIncrementalRepetitionNumber());
+
+ validateRepositoryName(repository);
+
+ RepositoryBackupChain chain = backupManager.startBackup(config);
+
+ ShortInfo shortInfo = new ShortInfo(ShortInfo.CURRENT, chain);
+
+ return Response.ok(shortInfo).cacheControl(noCache).build();
+ }
+ catch (LoginException e)
+ {
+ exception = e;
+ status = Response.Status.UNAUTHORIZED;
+ failMessage = e.getMessage();
+ }
+ catch (RepositoryException e)
+ {
+ exception = e;
+ status = Response.Status.INTERNAL_SERVER_ERROR;
+ failMessage = e.getMessage();
+ }
+ catch (RepositoryConfigurationException e)
+ {
+ exception = e;
+ status = Response.Status.NOT_FOUND;
+ failMessage = e.getMessage();
+ }
+ catch (BackupOperationException e)
+ {
+ exception = e;
+ status = Response.Status.INTERNAL_SERVER_ERROR;
+ failMessage = e.getMessage();
+ }
+ catch (BackupConfigurationException e)
+ {
+ exception = e;
+ status = Response.Status.NOT_FOUND;
+ failMessage = e.getMessage();
+ }
+ catch (Throwable e)
+ {
+ exception = e;
+ status = Response.Status.INTERNAL_SERVER_ERROR;
+ failMessage = e.getMessage();
+ }
+
+ log.error("Can not start backup", exception);
+
+ return Response.status(status).entity("Can not start backup : " + failMessage).type(MediaType.TEXT_PLAIN)
+ .cacheControl(noCache).build();
+ }
+
+ /**
* The delete workspace.
*
* @param repository
@@ -349,7 +439,7 @@
@RolesAllowed("administrators")
@Path("/drop-workspace/{repo}/{ws}/{force-session-close}")
public Response dropWorkspace(@PathParam("repo") String repository, @PathParam("ws") String workspace,
- @PathParam("force-session-close") Boolean forceSessionClose)
+ @PathParam("force-session-close") Boolean forceSessionClose)
{
String failMessage;
@@ -364,7 +454,7 @@
if (forceSessionClose)
forceCloseSession(repository, workspace);
- RepositoryImpl repositoryImpl = (RepositoryImpl) repositoryService.getRepository(repository);
+ RepositoryImpl repositoryImpl = (RepositoryImpl)repositoryService.getRepository(repository);
repositoryImpl.removeWorkspace(workspace);
repositoryService.getConfig().retain(); // save configuration to persistence (file or persister)
@@ -393,8 +483,8 @@
log.error("Can not drop the workspace '" + "/" + repository + "/" + workspace + "'", exception);
return Response.status(status).entity(
- "Can not drop the workspace '" + "/" + repository + "/" + workspace + "' : " + failMessage).type(
- MediaType.TEXT_PLAIN).cacheControl(noCache).build();
+ "Can not drop the workspace '" + "/" + repository + "/" + workspace + "' : " + failMessage).type(
+ MediaType.TEXT_PLAIN).cacheControl(noCache).build();
}
@@ -443,31 +533,34 @@
* Sleeping
* Restore must be initialized by job thread
*/
-
+
Thread.sleep(100);
-
+
/*
* search necessary restore
*/
List<JobWorkspaceRestore> restoreJobs = backupManager.getRestores();
JobWorkspaceRestore restore = null;
- for (JobWorkspaceRestore curRestore : restoreJobs) {
- if (curRestore.getRepositoryName().equals(repository) &&
- curRestore.getWorkspaceName().equals(wEntry.getName())) {
+ for (JobWorkspaceRestore curRestore : restoreJobs)
+ {
+ if (curRestore.getRepositoryName().equals(repository)
+ && curRestore.getWorkspaceName().equals(wEntry.getName()))
+ {
restore = curRestore;
break;
}
}
-
- if (restore != null) {
+
+ if (restore != null)
+ {
ShortInfo info =
- new ShortInfo(ShortInfo.RESTORE, restore.getBackupChainLog(), restore.getStartTime(), restore.getEndTime(),
- restore.getStateRestore(), restore.getRepositoryName(), restore.getWorkspaceName());
+ new ShortInfo(ShortInfo.RESTORE, restore.getBackupChainLog(), restore.getStartTime(), restore
+ .getEndTime(), restore.getStateRestore(), restore.getRepositoryName(), restore.getWorkspaceName());
return Response.ok(info).cacheControl(noCache).build();
}
-
- return Response.ok().cacheControl(noCache).build();
+
+ return Response.ok().cacheControl(noCache).build();
}
catch (WorkspaceRestoreExeption e)
{
@@ -501,15 +594,125 @@
}
log.error("Can not start restore the workspace '" + "/" + repository + "/" + wEntry.getName()
- + "' from backup log with id '" + backupId + "'", exception);
+ + "' from backup log with id '" + backupId + "'", exception);
return Response.status(status).entity(
- "Can not start restore the workspace '" + "/" + repository + "/" + wEntry.getName()
- + "' from backup log with id '" + backupId + "' : " + failMessage).type(MediaType.TEXT_PLAIN)
- .cacheControl(noCache).build();
+ "Can not start restore the workspace '" + "/" + repository + "/" + wEntry.getName()
+ + "' from backup log with id '" + backupId + "' : " + failMessage).type(MediaType.TEXT_PLAIN).cacheControl(
+ noCache).build();
}
/**
+ * Restore the repository.
+ *
+ * @param rEntry
+ * RepositoryEntry, the configuration to restored repository
+ * @param repository
+ * String, the repository name
+ * @param backupId
+ * String, the identifier of backup
+ * @return Response return the response
+ */
+ @POST
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @RolesAllowed("administrators")
+ @Path("/restore/{repo}/{id}")
+ public Response restore(RepositoryEntry rEntry, @PathParam("repo") String repository,
+ @PathParam("id") String backupId)
+ {
+ String failMessage;
+ Response.Status status;
+ Throwable exception;
+
+ try
+ {
+ validateOneRestoreInstants(repository);
+
+ File backupLog = getBackupLogbyId(backupId);
+
+ // validate backup log file
+ if (backupLog == null)
+ {
+ throw new BackupLogNotFoundException("The backup log file with id " + backupId + " not exists.");
+ }
+
+ validateRepositoryName(repository);
+
+ if (isRepositoryExist(repository))
+ {
+ throw new Exception("Repository " + rEntry.getName() + " already exist!");
+ }
+
+ RepositoryBackupChainLog backupChainLog = new RepositoryBackupChainLog(backupLog);
+
+ backupManager.restore(backupChainLog, rEntry, true);
+
+ // Sleeping. Restore should be initialized by job thread
+ Thread.sleep(100);
+
+ // search necessary restore
+ List<JobRepositoryRestore> restoreJobs = backupManager.getRepositoryRestores();
+ JobRepositoryRestore restore = null;
+ for (JobRepositoryRestore curRestore : restoreJobs)
+ {
+ if (curRestore.getRepositoryName().equals(repository))
+ {
+ restore = curRestore;
+ break;
+ }
+ }
+
+ if (restore != null)
+ {
+ ShortInfo info =
+ new ShortInfo(ShortInfo.RESTORE, restore.getRepositoryBackupChainLog(), restore.getStartTime(), restore
+ .getEndTime(), restore.getStateRestore(), restore.getRepositoryName());
+ return Response.ok(info).cacheControl(noCache).build();
+ }
+
+ return Response.ok().cacheControl(noCache).build();
+ }
+ catch (WorkspaceRestoreExeption e)
+ {
+ exception = e;
+ status = Response.Status.FORBIDDEN;
+ failMessage = e.getMessage();
+ }
+ catch (RepositoryException e)
+ {
+ exception = e;
+ status = Response.Status.NOT_FOUND;
+ failMessage = e.getMessage();
+ }
+ catch (RepositoryConfigurationException e)
+ {
+ exception = e;
+ status = Response.Status.NOT_FOUND;
+ failMessage = e.getMessage();
+ }
+ catch (BackupLogNotFoundException e)
+ {
+ exception = e;
+ status = Response.Status.NOT_FOUND;
+ failMessage = e.getMessage();
+ }
+ catch (Throwable e)
+ {
+ exception = e;
+ status = Response.Status.INTERNAL_SERVER_ERROR;
+ failMessage = e.getMessage();
+ }
+
+ log.error("Can not start restore the repository '" + "/" + repository + "' from backup log with id '" + backupId
+ + "'", exception);
+
+ return Response.status(status).entity(
+ "Can not start restore the repository '" + "/" + repository + "' from backup log with id '" + backupId
+ + "' : " + failMessage).type(MediaType.TEXT_PLAIN).cacheControl(noCache).build();
+ }
+
+ /**
* The backup stop by 'id'.
*
* @param backupId
@@ -565,7 +768,7 @@
log.error("Can not stop backup", exception);
return Response.status(status).entity("Can not stop backup : " + failMessage).type(MediaType.TEXT_PLAIN)
- .cacheControl(noCache).build();
+ .cacheControl(noCache).build();
}
/**
@@ -582,9 +785,8 @@
try
{
BackupServiceInfoBean infoBeen =
- new BackupServiceInfoBean(backupManager.getFullBackupType(),
- backupManager.getIncrementalBackupType(), backupManager.getBackupDirectory()
- .getAbsolutePath(), backupManager.getDefaultIncrementalJobPeriod());
+ new BackupServiceInfoBean(backupManager.getFullBackupType(), backupManager.getIncrementalBackupType(),
+ backupManager.getBackupDirectory().getAbsolutePath(), backupManager.getDefaultIncrementalJobPeriod());
return Response.ok(infoBeen).cacheControl(noCache).build();
}
@@ -593,8 +795,8 @@
log.error("Can not get information about backup service", e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(
- "Can not get information about backup service : " + e.getMessage()).type(MediaType.TEXT_PLAIN)
- .cacheControl(noCache).build();
+ "Can not get information about backup service : " + e.getMessage()).type(MediaType.TEXT_PLAIN)
+ .cacheControl(noCache).build();
}
}
@@ -629,8 +831,8 @@
log.error("Can not get information about current or completed backups", e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(
- "Can not get information about current or completed backups" + e.getMessage()).type(
- MediaType.TEXT_PLAIN).cacheControl(noCache).build();
+ "Can not get information about current or completed backups" + e.getMessage()).type(MediaType.TEXT_PLAIN)
+ .cacheControl(noCache).build();
}
}
@@ -670,15 +872,15 @@
}
return Response.status(Response.Status.NOT_FOUND).entity("No current or completed backup with 'id' " + id)
- .type(MediaType.TEXT_PLAIN).cacheControl(noCache).build();
+ .type(MediaType.TEXT_PLAIN).cacheControl(noCache).build();
}
catch (Throwable e)
{
log.error("Can not get information about current or completed backup with 'id' " + id, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(
- "Can not get information about current or completed backup with 'id' " + id + " : " + e.getMessage())
- .type(MediaType.TEXT_PLAIN).cacheControl(noCache).build();
+ "Can not get information about current or completed backup with 'id' " + id + " : " + e.getMessage()).type(
+ MediaType.TEXT_PLAIN).cacheControl(noCache).build();
}
}
@@ -709,8 +911,8 @@
log.error("Can not get information about current backups", e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(
- "Can not get information about current backups" + e.getMessage()).type(MediaType.TEXT_PLAIN)
- .cacheControl(noCache).build();
+ "Can not get information about current backups" + e.getMessage()).type(MediaType.TEXT_PLAIN).cacheControl(
+ noCache).build();
}
}
@@ -742,8 +944,8 @@
log.error("Can not get information about completed backups", e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(
- "Can not get information about completed backups" + e.getMessage()).type(MediaType.TEXT_PLAIN)
- .cacheControl(noCache).build();
+ "Can not get information about completed backups" + e.getMessage()).type(MediaType.TEXT_PLAIN)
+ .cacheControl(noCache).build();
}
}
@@ -771,7 +973,7 @@
for (BackupChain chain : backupManager.getCurrentBackups())
{
if (repository.equals(chain.getBackupConfig().getRepository())
- && workspace.equals(chain.getBackupConfig().getWorkspace()))
+ && workspace.equals(chain.getBackupConfig().getWorkspace()))
{
list.add(new ShortInfo(ShortInfo.CURRENT, chain));
}
@@ -780,8 +982,8 @@
for (BackupChainLog chainLog : backupManager.getBackupsLogs())
{
if (backupManager.findBackup(chainLog.getBackupId()) == null
- && repository.equals(chainLog.getBackupConfig().getRepository())
- && workspace.equals(chainLog.getBackupConfig().getWorkspace()))
+ && repository.equals(chainLog.getBackupConfig().getRepository())
+ && workspace.equals(chainLog.getBackupConfig().getWorkspace()))
{
list.add(new ShortInfo(ShortInfo.COMPLETED, chainLog));
}
@@ -796,8 +998,8 @@
log.error("Can not get information about current or completed backups", e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(
- "Can not get information about current or completed backups" + e.getMessage()).type(
- MediaType.TEXT_PLAIN).cacheControl(noCache).build();
+ "Can not get information about current or completed backups" + e.getMessage()).type(MediaType.TEXT_PLAIN)
+ .cacheControl(noCache).build();
}
}
@@ -824,37 +1026,84 @@
if (restoreJob != null)
{
DetailedInfoEx info =
- new DetailedInfoEx(DetailedInfo.RESTORE, restoreJob.getBackupChainLog(),
- restoreJob.getStartTime(), restoreJob.getEndTime(), restoreJob.getStateRestore(),
- restoreJob.getRepositoryName(), restoreJob.getWorkspaceName(),
+ new DetailedInfoEx(DetailedInfo.RESTORE, restoreJob.getBackupChainLog(), restoreJob.getStartTime(),
+ restoreJob.getEndTime(), restoreJob.getStateRestore(), restoreJob.getRepositoryName(), restoreJob
+ .getWorkspaceName(),
- restoreJob.getWorkspaceEntry(), restoreJob.getRestoreException() == null ? ""
- : restoreJob.getRestoreException().getMessage());
+ restoreJob.getWorkspaceEntry(), restoreJob.getRestoreException() == null ? "" : restoreJob
+ .getRestoreException().getMessage());
return Response.ok(info).cacheControl(noCache).build();
}
else
{
return Response.status(Response.Status.NOT_FOUND).entity(
- "No resrore for workspace /" + repository + "/" + workspace + "'").type(MediaType.TEXT_PLAIN)
- .cacheControl(noCache).build();
+ "No resrore for workspace /" + repository + "/" + workspace + "'").type(MediaType.TEXT_PLAIN)
+ .cacheControl(noCache).build();
}
}
catch (Throwable e)
{
log.error(
- "Can not get information about current restore for workspace /" + repository + "/" + workspace + "'",
- e);
+ "Can not get information about current restore for workspace /" + repository + "/" + workspace + "'", e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(
- "Can not get information about current restore for workspace /" + repository + "/" + workspace
- + "' : " + e.getMessage()).type(MediaType.TEXT_PLAIN).cacheControl(noCache).build();
+ "Can not get information about current restore for workspace /" + repository + "/" + workspace + "' : "
+ + e.getMessage()).type(MediaType.TEXT_PLAIN).cacheControl(noCache).build();
}
}
/**
+ * Will be returned the detailed information about last restore for specific repository.
+ *
+ * @param repository
+ * String, the repository name
+ *
+ * @return Response return the response
+ */
+ @GET
+ @Produces(MediaType.APPLICATION_JSON)
+ @RolesAllowed("administrators")
+ @Path("/info/restore/{repo}/{ws}")
+ public Response infoRestore(@PathParam("repo") String repository)
+ {
+ try
+ {
+ JobRepositoryRestore restoreJob = backupManager.getLastRepositoryRestore(repository);
+
+ if (restoreJob != null)
+ {
+ DetailedInfoEx info =
+ new DetailedInfoEx(DetailedInfo.RESTORE, restoreJob.getRepositoryBackupChainLog(), restoreJob
+ .getStartTime(), restoreJob.getEndTime(), restoreJob.getStateRestore(), restoreJob
+ .getRepositoryName(),
+
+ restoreJob.getRepositoryEntry(), restoreJob.getRestoreException() == null ? "" : restoreJob
+ .getRestoreException().getMessage());
+
+ return Response.ok(info).cacheControl(noCache).build();
+ }
+ else
+ {
+ return Response.status(Response.Status.NOT_FOUND).entity("No restore for repository /" + repository + "'")
+ .type(MediaType.TEXT_PLAIN).cacheControl(noCache).build();
+ }
+
+ }
+ catch (Throwable e)
+ {
+ log.error("Can not get information about current restore for repository /" + repository + "'", e);
+
+ return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(
+ "Can not get information about current restore for repository /" + repository + "' : " + e.getMessage())
+ .type(MediaType.TEXT_PLAIN).cacheControl(noCache).build();
+ }
+
+ }
+
+ /**
* Will be returned the detailed information about last restores.
*
* @return Response return the response
@@ -878,7 +1127,7 @@
for (JobWorkspaceRestore unJob : jobs)
{
if (unJob.getRepositoryName().equals(job.getRepositoryName())
- && unJob.getWorkspaceName().equals(job.getWorkspaceName()))
+ && unJob.getWorkspaceName().equals(job.getWorkspaceName()))
isUnique = false;
}
@@ -891,8 +1140,8 @@
for (JobWorkspaceRestore job : jobs)
{
ShortInfo info =
- new ShortInfo(ShortInfo.RESTORE, job.getBackupChainLog(), job.getStartTime(), job.getEndTime(),
- job.getStateRestore(), job.getRepositoryName(), job.getWorkspaceName());
+ new ShortInfo(ShortInfo.RESTORE, job.getBackupChainLog(), job.getStartTime(), job.getEndTime(), job
+ .getStateRestore(), job.getRepositoryName(), job.getWorkspaceName());
list.add(info);
}
@@ -904,8 +1153,8 @@
log.error("Can not get information about current restores.", e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(
- "Can not get information about current restores : " + e.getMessage()).type(MediaType.TEXT_PLAIN)
- .cacheControl(noCache).build();
+ "Can not get information about current restores : " + e.getMessage()).type(MediaType.TEXT_PLAIN)
+ .cacheControl(noCache).build();
}
}
@@ -923,20 +1172,19 @@
try
{
String defaultWorkspaceName =
- repositoryService.getDefaultRepository().getConfiguration().getDefaultWorkspaceName();
+ repositoryService.getDefaultRepository().getConfiguration().getDefaultWorkspaceName();
for (WorkspaceEntry wEntry : repositoryService.getDefaultRepository().getConfiguration().getWorkspaceEntries())
if (defaultWorkspaceName.equals(wEntry.getName()))
return Response.ok(wEntry).cacheControl(noCache).build();
return Response.status(Response.Status.NOT_FOUND).entity("Can not get default workspace configuration.").type(
- MediaType.TEXT_PLAIN).cacheControl(noCache).build();
+ MediaType.TEXT_PLAIN).cacheControl(noCache).build();
}
catch (Throwable e)
{
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(
- "Can not get default workspace configuration.").type(MediaType.TEXT_PLAIN).cacheControl(noCache)
- .build();
+ "Can not get default workspace configuration.").type(MediaType.TEXT_PLAIN).cacheControl(noCache).build();
}
}
@@ -951,7 +1199,7 @@
* will be generated the exception RepositoryException
*/
private void validateRepositoryName(String repositoryName) throws RepositoryException,
- RepositoryConfigurationException
+ RepositoryConfigurationException
{
repositoryService.getRepository(repositoryName);
}
@@ -973,16 +1221,16 @@
* will be generated the exception LoginException
*/
private void validateWorkspaceName(String repositoryName, String workspaceName) throws LoginException,
- NoSuchWorkspaceException, RepositoryException, RepositoryConfigurationException
+ NoSuchWorkspaceException, RepositoryException, RepositoryConfigurationException
{
Session ses =
- sessionProviderService.getSessionProvider(null).getSession(workspaceName,
- repositoryService.getRepository(repositoryName));
+ sessionProviderService.getSessionProvider(null).getSession(workspaceName,
+ repositoryService.getRepository(repositoryName));
ses.logout();
}
private boolean isWorkspaceExist(String repositoryName, String workspaceName) throws RepositoryException,
- RepositoryConfigurationException
+ RepositoryConfigurationException
{
for (String workspace : repositoryService.getRepository(repositoryName).getWorkspaceNames())
{
@@ -995,6 +1243,12 @@
return false;
}
+ private boolean isRepositoryExist(String repositoryName) throws RepositoryException,
+ RepositoryConfigurationException
+ {
+ return repositoryService.getRepository(repositoryName) != null;
+ }
+
/**
* validateOneBackupInstants.
*
@@ -1012,7 +1266,7 @@
if (bch != null)
throw new WorkspaceRestoreExeption("The backup is already working on workspace '" + "/" + repositoryName + "/"
- + workspaceName + "'");
+ + workspaceName + "'");
}
/**
@@ -1030,15 +1284,34 @@
for (JobWorkspaceRestore job : backupManager.getRestores())
if (repositoryName.equals(job.getRepositoryName())
- && workspaceName.endsWith(job.getWorkspaceName())
- && (job.getStateRestore() == JobWorkspaceRestore.RESTORE_INITIALIZED || job.getStateRestore() == JobWorkspaceRestore.RESTORE_STARTED))
+ && workspaceName.endsWith(job.getWorkspaceName())
+ && (job.getStateRestore() == JobWorkspaceRestore.RESTORE_INITIALIZED || job.getStateRestore() == JobWorkspaceRestore.RESTORE_STARTED))
{
throw new WorkspaceRestoreExeption("The workspace '" + "/" + repositoryName + "/" + workspaceName
- + "' is already restoring.");
+ + "' is already restoring.");
}
}
/**
+ * validateOneRestoreInstants.
+ *
+ * @param repositoryName
+ * the repository name
+ * @throws WorkspaceRestoreExeption
+ * will be generated WorkspaceRestoreExeption
+ */
+ private void validateOneRestoreInstants(String repositoryName) throws WorkspaceRestoreExeption
+ {
+
+ for (JobWorkspaceRestore job : backupManager.getRestores())
+ if (repositoryName.equals(job.getRepositoryName())
+ && (job.getStateRestore() == JobWorkspaceRestore.RESTORE_INITIALIZED || job.getStateRestore() == JobWorkspaceRestore.RESTORE_STARTED))
+ {
+ throw new WorkspaceRestoreExeption("The workspace '" + "/" + repositoryName + "' is already restoring.");
+ }
+ }
+
+ /**
* forceCloseSession. Close sessions on specific workspace.
*
* @param repositoryName
@@ -1052,12 +1325,12 @@
* will be generate RepositoryException
*/
private int forceCloseSession(String repositoryName, String workspaceName) throws RepositoryException,
- RepositoryConfigurationException
+ RepositoryConfigurationException
{
ManageableRepository mr = repositoryService.getRepository(repositoryName);
WorkspaceContainerFacade wc = mr.getWorkspaceContainer(workspaceName);
- SessionRegistry sessionRegistry = (SessionRegistry) wc.getComponent(SessionRegistry.class);
+ SessionRegistry sessionRegistry = (SessionRegistry)wc.getComponent(SessionRegistry.class);
return sessionRegistry.closeSessions(workspaceName);
}
Modified: jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/server/bean/BackupConfigBean.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/server/bean/BackupConfigBean.java 2010-03-25 11:28:12 UTC (rev 2118)
+++ jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/server/bean/BackupConfigBean.java 2010-03-25 11:52:37 UTC (rev 2119)
@@ -19,6 +19,7 @@
package org.exoplatform.services.jcr.ext.backup.server.bean;
import org.exoplatform.services.jcr.ext.backup.BackupConfig;
+import org.exoplatform.services.jcr.ext.backup.RepositoryBackupConfig;
import org.exoplatform.services.jcr.ext.backup.server.bean.response.BackupJobConfig;
/**
@@ -135,6 +136,18 @@
}
/**
+ * BackupConfigBeen constructor.
+ *
+ * @param config
+ * the backup config
+ */
+ public BackupConfigBean(RepositoryBackupConfig config)
+ {
+ this(config.getBackupType(), config.getBackupDir().getAbsolutePath(), config.getIncrementalJobPeriod());
+ this.incrementalRepetitionNumber = config.getIncrementalJobNumber();
+ }
+
+ /**
* getIncrementalJobPeriod.
*
* @return Long return the incremental job period
Modified: jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/server/bean/response/DetailedInfo.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/server/bean/response/DetailedInfo.java 2010-03-25 11:28:12 UTC (rev 2118)
+++ jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/server/bean/response/DetailedInfo.java 2010-03-25 11:52:37 UTC (rev 2119)
@@ -20,6 +20,7 @@
import org.exoplatform.services.jcr.ext.backup.BackupChain;
import org.exoplatform.services.jcr.ext.backup.BackupChainLog;
+import org.exoplatform.services.jcr.ext.backup.RepositoryBackupChainLog;
import org.exoplatform.services.jcr.ext.backup.server.bean.BackupConfigBean;
import java.util.Calendar;
@@ -127,6 +128,33 @@
}
/**
+ * DetailedInfo constructor.
+ *
+ * For restore.
+ *
+ * @param type
+ * int, the type of DetailedInfo
+ * @param chainLog
+ * RepositoryBackupChainLog, chain log for restore
+ * @param startedTime
+ * Calendar, the started time of restore
+ * @param finishedTime
+ * Calendar, the finished time of restore
+ * @param state
+ * int, the state of restore
+ * @param repositroryName
+ * String, the repository name
+ * @param workspaceName
+ * String, the workspace name
+ */
+ public DetailedInfo(int type, RepositoryBackupChainLog chainLog, Calendar startedTime, Calendar finishedTime,
+ int state, String repositroryName)
+ {
+ super(type, chainLog, startedTime, finishedTime, state, repositroryName);
+ this.backupConfig = new BackupConfigBean(chainLog.getBackupConfig());
+ }
+
+ /**
* getBackupConfig.
*
* @return BackupConfigBean return the bean to backup config
Modified: jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/server/bean/response/DetailedInfoEx.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/server/bean/response/DetailedInfoEx.java 2010-03-25 11:28:12 UTC (rev 2118)
+++ jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/server/bean/response/DetailedInfoEx.java 2010-03-25 11:52:37 UTC (rev 2119)
@@ -18,8 +18,10 @@
*/
package org.exoplatform.services.jcr.ext.backup.server.bean.response;
+import org.exoplatform.services.jcr.config.RepositoryEntry;
import org.exoplatform.services.jcr.config.WorkspaceEntry;
import org.exoplatform.services.jcr.ext.backup.BackupChainLog;
+import org.exoplatform.services.jcr.ext.backup.RepositoryBackupChainLog;
import java.util.Calendar;
@@ -35,6 +37,8 @@
protected WorkspaceEntry workspaceEntry;
+ protected RepositoryEntry repositoryEntry;
+
protected String failMessage;
public DetailedInfoEx(int type, BackupChainLog chainLog, Calendar startedTime, Calendar finishedTime, int state,
@@ -46,6 +50,15 @@
this.failMessage = failMessage;
}
+ public DetailedInfoEx(int type, RepositoryBackupChainLog chainLog, Calendar startedTime, Calendar finishedTime,
+ int state, String repositroryName, RepositoryEntry repositoryEntry, String failMessage)
+ {
+ super(type, chainLog, startedTime, finishedTime, state, repositroryName);
+
+ this.repositoryEntry = repositoryEntry;
+ this.failMessage = failMessage;
+ }
+
public String getFailMessage()
{
return failMessage;
Modified: jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/server/bean/response/ShortInfo.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/server/bean/response/ShortInfo.java 2010-03-25 11:28:12 UTC (rev 2118)
+++ jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/server/bean/response/ShortInfo.java 2010-03-25 11:52:37 UTC (rev 2119)
@@ -20,6 +20,8 @@
import org.exoplatform.services.jcr.ext.backup.BackupChain;
import org.exoplatform.services.jcr.ext.backup.BackupChainLog;
+import org.exoplatform.services.jcr.ext.backup.RepositoryBackupChain;
+import org.exoplatform.services.jcr.ext.backup.RepositoryBackupChainLog;
import org.exoplatform.services.jcr.ext.backup.server.HTTPBackupAgent;
import java.text.DateFormat;
@@ -132,6 +134,30 @@
*
* @param type
* int, the tupe of short info
+ * @param chain
+ * RepositoryBackupChain, the backup chain for current backup.
+ */
+ public ShortInfo(int type, RepositoryBackupChain chain)
+ {
+ this.type = type;
+ this.backupType = chain.getBackupConfig().getBackupType();
+ this.backupId = chain.getBackupId();
+ this.repositoryName = chain.getBackupConfig().getRepository();
+ this.state = chain.getState();
+
+ DateFormat df = new SimpleDateFormat(HTTPBackupAgent.Constants.DATE_FORMAT_RFC_1123);
+ this.startedTime = df.format(chain.getStartedTime().getTime());
+
+ // no applicable
+ this.finishedTime = "";
+ this.workspaceName = "";
+ }
+
+ /**
+ * ShortInfo constructor.
+ *
+ * @param type
+ * int, the tupe of short info
* @param chainLog
* BackupChainLog, the backup chain log for completed backup.
*/
@@ -190,6 +216,40 @@
* ShortInfo constructor.
*
* For restore.
+ *
+ * @param type
+ * int, the type of short info
+ * @param chainLog
+ * RepositoryBackupChainLog, the backup chain log for completed backup.
+ * @param startedTime
+ * Calendar, the stated time
+ * @param finishedTime
+ * Calendar, the finished time
+ * @param state
+ * int, the state of restore
+ */
+ public ShortInfo(int type, RepositoryBackupChainLog chainLog, Calendar startedTime, Calendar finishedTime, int state)
+ {
+ this.type = type;
+ this.backupType = chainLog.getBackupConfig().getBackupType();
+ this.backupId = chainLog.getBackupId();
+ this.repositoryName = chainLog.getBackupConfig().getRepository();
+
+ this.state = state;
+
+ DateFormat df = new SimpleDateFormat(HTTPBackupAgent.Constants.DATE_FORMAT_RFC_1123);
+ this.startedTime = df.format(startedTime.getTime());
+
+ if (finishedTime != null)
+ this.finishedTime = df.format(finishedTime.getTime());
+ else
+ this.finishedTime = "";
+ }
+
+ /**
+ * ShortInfo constructor.
+ *
+ * For restore.
*
* @param type
* int, the tupe of short info
@@ -215,6 +275,34 @@
}
/**
+ * ShortInfo constructor.
+ *
+ * For restore.
+ *
+ * @param type
+ * int, the tupe of short info
+ * @param chainLog
+ * BackupChainLog, the backup chain log for completed backup.
+ * @param startedTime
+ * Calendar, the stated time
+ * @param finishedTime
+ * Calendar, the finished time
+ * @param state
+ * int, the state of restore
+ * @param repositroryName
+ * String, the repository name
+ */
+ public ShortInfo(int type, RepositoryBackupChainLog chainLog, Calendar startedTime, Calendar finishedTime,
+ int state, String repositroryName)
+ {
+ this(type, chainLog, startedTime, finishedTime, state);
+ this.repositoryName = repositroryName;
+
+ // no applicable
+ this.workspaceName = "";
+ }
+
+ /**
* getState.
*
* @return Integer the state of backup or restore
More information about the exo-jcr-commits
mailing list