Author: areshetnyak
Date: 2010-09-28 08:01:50 -0400 (Tue, 28 Sep 2010)
New Revision: 3210
Added:
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/ExtendedBackupManager.java
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/WorkspaceRestoreException.java
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/IndexCleanerService.java
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/JobExistedRepositoryRestore.java
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/JobExistedWorkspaceRestore.java
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/ValueStorageCleanerService.java
Modified:
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/BackupManager.java
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/impl/JobWorkspaceRestore.java
jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/AbstractBackupTestCase.java
jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/TestBackupManager.java
Log:
EXOJCR-747 : Make backup restore easier implementation.
Modified:
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/BackupManager.java
===================================================================
---
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/BackupManager.java 2010-09-28
11:57:59 UTC (rev 3209)
+++
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/BackupManager.java 2010-09-28
12:01:50 UTC (rev 3210)
@@ -359,5 +359,5 @@
* return the current backup to repository
*/
RepositoryBackupChain findRepositoryBackupId(String id);
-
+
}
Added:
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/ExtendedBackupManager.java
===================================================================
---
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/ExtendedBackupManager.java
(rev 0)
+++
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/ExtendedBackupManager.java 2010-09-28
12:01:50 UTC (rev 3210)
@@ -0,0 +1,107 @@
+/*
+ * Copyright (C) 2003-2010 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not,
see<http://www.gnu.org/licenses/>.
+ */
+package org.exoplatform.services.jcr.ext.backup;
+
+import org.exoplatform.services.jcr.config.RepositoryEntry;
+import org.exoplatform.services.jcr.config.WorkspaceEntry;
+
+/**
+ * Created by The eXo Platform SAS.
+ *
+ * <br/>Date: 2010
+ *
+ * @author <a href="mailto:alex.reshetnyak@exoplatform.com.ua">Alex
Reshetnyak</a>
+ * @version $Id$
+ */
+public interface ExtendedBackupManager extends BackupManager
+{
+ /**
+ * Restoration over an existing repository.
+ * Will be deleted old data.
+ * Get status of repository restore was necessary use JobRepositoryRestore
BackupManager.getLastRestore(String repositoryName).
+ *
+ * @param log
+ * RepositoryBackupChainLog, the repository backup log
+ * @param repositoryEntry
+ * RepositoryEntry, the repository entry
+ * @param asynchronous
+ * boolean, in 'true' then asynchronous restore.
+ * @throws BackupOperationException
+ * will be generate the exception BackupOperationException
+ * @throws BackupConfigurationException
+ * will be generate the exception BackupConfigurationException
+ */
+ void restoreExistedRepository(RepositoryBackupChainLog log, RepositoryEntry
repositoryEntry, boolean asynchronous) throws BackupOperationException,
BackupConfigurationException;
+
+ /**
+ * Restoration over an existing workspace.
+ * Will be deleted old data.
+ * Get status of workspace restore was necessary use JobWorkspaceRestore
BackupManager.getLastRestore(String repositoryName, String workspaceName).
+ *
+ * @param log
+ * BackupChainLog, the backup log
+ * @param repositoryName
+ * String, repository name
+ * @param workspaceEntry
+ * WorkspaceEntry, the workspace entry
+ * @param asynchronous
+ * boolean, in 'true' then asynchronous restore.
+ * @throws BackupOperationException
+ * will be generate the exception BackupOperationException
+ * @throws BackupConfigurationException
+ * will be generate the exception BackupConfigurationException
+ */
+ void restoreExistedWorkspace(BackupChainLog log, String repositoryName, WorkspaceEntry
workspaceEntry, boolean asynchronous) throws BackupOperationException,
BackupConfigurationException;
+
+ /**
+ * Restoration over an existing repository.
+ * Will be deleted old data.
+ * Get status of repository restore was necessary use JobRepositoryRestore
BackupManager.getLastRestore(String repositoryName).
+ *
+ * @param repositoryBackupIdentifier
+ * String, identifier of repository backup
+ * @param repositoryEntry
+ * RepositoryEntry, the repository entry
+ * @param asynchronous
+ * boolean, in 'true' then asynchronous restore.
+ * @throws BackupOperationException
+ * will be generate the exception BackupOperationException
+ * @throws BackupConfigurationException
+ * will be generate the exception BackupConfigurationException
+ */
+ void restoreExistedRepository(String repositoryBackupIdentifier, RepositoryEntry
repositoryEntry, boolean asynchronous) throws BackupOperationException,
BackupConfigurationException;
+
+ /**
+ * Restoration over an existing workspace.
+ * Will be deleted old data.
+ * Get status of workspace restore was necessary use JobWorkspaceRestore
BackupManager.getLastRestore(String repositoryName, String workspaceName).
+ *
+ * @param workspaceBackupIdentifier
+ * String, identifier of workspace backup
+ * @param repositoryName
+ * String, repository name
+ * @param workspaceEntry
+ * WorkspaceEntry, the workspace entry
+ * @param asynchronous
+ * boolean, in 'true' then asynchronous restore.
+ * @throws BackupOperationException
+ * will be generate the exception BackupOperationException
+ * @throws BackupConfigurationException
+ * will be generate the exception BackupConfigurationException
+ */
+ void restoreExistedWorkspace(String workspaceBackupIdentifier, String repositoryName,
WorkspaceEntry workspaceEntry, boolean asynchronous) throws BackupOperationException,
BackupConfigurationException;
+}
Property changes on:
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/ExtendedBackupManager.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added:
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/WorkspaceRestoreException.java
===================================================================
---
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/WorkspaceRestoreException.java
(rev 0)
+++
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/WorkspaceRestoreException.java 2010-09-28
12:01:50 UTC (rev 3210)
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2003-2010 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not,
see<http://www.gnu.org/licenses/>.
+ */
+package org.exoplatform.services.jcr.ext.backup;
+
+/**
+ * Created by The eXo Platform SAS.
+ *
+ * <br/>Date: 2010
+ *
+ * @author <a href="mailto:alex.reshetnyak@exoplatform.com.ua">Alex
Reshetnyak</a>
+ * @version $Id$
+ */
+public class WorkspaceRestoreException
+ extends BackupConfigurationException
+{
+
+ /**
+ * WorkspaceRestoreException constructor.
+ *
+ * @param message
+ * String, the exception message
+ */
+ public WorkspaceRestoreException(String message)
+ {
+ super(message);
+ }
+
+ /**
+ * WorkspaceRestoreException constructor.
+ *
+ * @param message
+ * String, the exception message
+ * @param e
+ * Throwable, the cause exception
+ */
+ public WorkspaceRestoreException(String message, Throwable e)
+ {
+ super(message, e);
+ }
+}
\ No newline at end of file
Property changes on:
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/WorkspaceRestoreException.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
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-09-28
11:57:59 UTC (rev 3209)
+++
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/BackupManagerImpl.java 2010-09-28
12:01:50 UTC (rev 3210)
@@ -66,10 +66,12 @@
import org.exoplatform.services.jcr.ext.backup.BackupJobListener;
import org.exoplatform.services.jcr.ext.backup.BackupManager;
import org.exoplatform.services.jcr.ext.backup.BackupOperationException;
+import org.exoplatform.services.jcr.ext.backup.ExtendedBackupManager;
import org.exoplatform.services.jcr.ext.backup.JobEntryInfo;
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.WorkspaceRestoreException;
import org.exoplatform.services.jcr.ext.common.SessionProvider;
import org.exoplatform.services.jcr.ext.registry.RegistryEntry;
import org.exoplatform.services.jcr.ext.registry.RegistryService;
@@ -98,7 +100,7 @@
* @version $Id: $
*/
-public class BackupManagerImpl implements BackupManager, Startable
+public class BackupManagerImpl implements ExtendedBackupManager, Startable
{
protected static Log log =
ExoLogger.getLogger("exo.jcr.component.ext.BackupManagerImpl");
@@ -1555,4 +1557,169 @@
}
return null;
}
+
+ /**
+ * {@inheritDoc}
+ */
+ public void restoreExistedRepository(RepositoryBackupChainLog rblog, RepositoryEntry
repositoryEntry,
+ boolean asynchronous) throws BackupOperationException,
BackupConfigurationException
+ {
+ try
+ {
+ //repository should be existed
+ repoService.getRepository(repositoryEntry.getName());
+ }
+ catch (RepositoryException e)
+ {
+ throw new WorkspaceRestoreException("Repository \"" +
repositoryEntry.getName() + "\" should be existed", e);
+ }
+ catch (RepositoryConfigurationException e)
+ {
+ throw new WorkspaceRestoreException("Repository \"" +
repositoryEntry.getName() + "\" should be existed", e);
+ }
+
+ Map<String, BackupChainLog> workspacesMapping = new HashedMap();
+
+ Map<String, BackupChainLog> backups = new HashedMap();
+
+ for (String path : rblog.getWorkspaceBackupsInfo())
+ {
+ BackupChainLog bLog = new BackupChainLog(new File(path));
+ backups.put(bLog.getBackupConfig().getWorkspace(), bLog);
+ }
+
+ 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());
+ }
+
+ 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());
+ }
+
+ for (WorkspaceEntry wsEntry : repositoryEntry.getWorkspaceEntries())
+ {
+ if (!backups.containsKey(wsEntry.getName()))
+ {
+ throw new BackupConfigurationException("The workspace '" +
wsEntry.getName() + "' is not found in backup "
+ + rblog.getLogFilePath());
+ }
+ else
+ {
+ workspacesMapping.put(wsEntry.getName(), backups.get(wsEntry.getName()));
+ }
+ }
+
+ JobExistedRepositoryRestore jobExistedRepositoryRestore =
+ new JobExistedRepositoryRestore(repoService, this, repositoryEntry,
workspacesMapping, rblog);
+
+ restoreRepositoryJobs.add(jobExistedRepositoryRestore);
+ if (asynchronous)
+ {
+ jobExistedRepositoryRestore.start();
+ }
+ else
+ {
+ jobExistedRepositoryRestore.restore();
+ }
+
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void restoreExistedRepository(String repositoryBackupIdentifier,
RepositoryEntry repositoryEntry,
+ boolean asynchronous) throws BackupOperationException,
BackupConfigurationException
+ {
+ RepositoryBackupChainLog backupChainLog = null;
+
+ for(RepositoryBackupChainLog chainLog : getRepositoryBackupsLogs())
+ {
+ if (chainLog.getBackupId().equals(repositoryBackupIdentifier))
+ {
+ backupChainLog = chainLog;
+ break;
+ }
+ }
+
+ if (backupChainLog == null)
+ {
+ throw new BackupConfigurationException("Can not founf backup of repository
with id \"" + repositoryBackupIdentifier + "\"");
+ }
+
+ this.restoreExistedRepository(backupChainLog, repositoryEntry, asynchronous);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void restoreExistedWorkspace(BackupChainLog log, String repositoryName,
WorkspaceEntry workspaceEntry,
+ boolean asynchronous) throws BackupOperationException,
BackupConfigurationException
+ {
+ try
+ {
+ //repository should be existed
+ repoService.getRepository(repositoryName);
+
+ //workspace should be existed
+ if (!workspaceAlreadyExist(repositoryName, workspaceEntry.getName()))
+ {
+ throw new WorkspaceRestoreException("Workspace \"" +
workspaceEntry.getName() + "\" should be existed in repository \"" +
repositoryName + "\".");
+ }
+ }
+ catch (RepositoryException e)
+ {
+ throw new WorkspaceRestoreException("Repository \"" +
repositoryName + "\" should be existed", e);
+ }
+ catch (RepositoryConfigurationException e)
+ {
+ throw new WorkspaceRestoreException("Repository \"" +
repositoryName + "\" should be existed", e);
+ }
+
+ JobExistedWorkspaceRestore jobRestore =
+ new JobExistedWorkspaceRestore(repoService, this, repositoryName, log,
workspaceEntry);
+ restoreJobs.add(jobRestore);
+
+ if (asynchronous)
+ {
+ jobRestore.start();
+ }
+ else
+ {
+ jobRestore.restore();
+ }
+
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void restoreExistedWorkspace(String workspaceBackupIdentifier, String
repositoryName,
+ WorkspaceEntry workspaceEntry, boolean asynchronous) throws
BackupOperationException,
+ BackupConfigurationException
+ {
+ BackupChainLog backupChainLog = null;
+
+ for(BackupChainLog chainLog : getBackupsLogs())
+ {
+ if (chainLog.getBackupId().equals(workspaceBackupIdentifier))
+ {
+ backupChainLog = chainLog;
+ break;
+ }
+ }
+
+ if (backupChainLog == null)
+ {
+ throw new BackupConfigurationException("Can not founf backup of workspace
with id \"" + workspaceBackupIdentifier + "\"");
+ }
+
+ this.restoreExistedWorkspace(backupChainLog, repositoryName, workspaceEntry,
asynchronous);
+ }
+
}
Added:
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/IndexCleanerService.java
===================================================================
---
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/IndexCleanerService.java
(rev 0)
+++
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/IndexCleanerService.java 2010-09-28
12:01:50 UTC (rev 3210)
@@ -0,0 +1,87 @@
+/*
+ * Copyright (C) 2003-2010 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not,
see<http://www.gnu.org/licenses/>.
+ */
+package org.exoplatform.services.jcr.ext.backup.impl;
+
+import java.io.File;
+import java.io.IOError;
+import java.io.IOException;
+
+import javax.jcr.RepositoryException;
+import javax.naming.NamingException;
+
+import org.exoplatform.services.jcr.config.QueryHandlerParams;
+import org.exoplatform.services.jcr.config.RepositoryConfigurationException;
+import org.exoplatform.services.jcr.config.WorkspaceEntry;
+
+/**
+ * IndexCleanerService deliver tools for clean index data of workspace or repository.
+ *
+ * Created by The eXo Platform SAS.
+ *
+ * <br/>Date: 2010
+ *
+ * @author <a href="mailto:alex.reshetnyak@exoplatform.com.ua">Alex
Reshetnyak</a>
+ * @version $Id$
+ */
+public class IndexCleanerService
+{
+ /**
+ * Remove all file of workspace index.
+ *
+ * @param wsConfig - workspace configuration.
+ * @param isSystem - 'true' to clean system workspace.
+ * @throws RepositoryConfigurationException - exception on parsing workspace
configuration
+ * @throws IOException - exception on remove index folder
+ */
+ public static void removeWorkspaceIndex(WorkspaceEntry wsConfig, boolean isSystem)
throws RepositoryConfigurationException, IOException
+ {
+ String indexDir =
wsConfig.getQueryHandler().getParameterValue(QueryHandlerParams.PARAM_INDEX_DIR);
+
+ removeFolder(new File(indexDir));
+
+ if (isSystem)
+ {
+ removeFolder(new File(indexDir + "_system"));
+ }
+ }
+
+ /**
+ * Remove folder
+ */
+ private static void removeFolder(File dir) throws IOException
+ {
+ if (dir.isDirectory())
+ {
+ for (File subFile : dir.listFiles())
+ {
+ removeFolder(subFile);
+ }
+
+ if (!dir.delete())
+ {
+ throw new IOException("Index folder was not deleted : " +
dir.getCanonicalPath());
+ }
+ }
+ else
+ {
+ if (!dir.delete())
+ {
+ throw new IOException("Index file was not deleted : " +
dir.getCanonicalPath());
+ }
+ }
+ }
+}
Property changes on:
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/IndexCleanerService.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added:
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/JobExistedRepositoryRestore.java
===================================================================
---
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/JobExistedRepositoryRestore.java
(rev 0)
+++
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/JobExistedRepositoryRestore.java 2010-09-28
12:01:50 UTC (rev 3210)
@@ -0,0 +1,125 @@
+/*
+ * Copyright (C) 2003-2010 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not,
see<http://www.gnu.org/licenses/>.
+ */
+package org.exoplatform.services.jcr.ext.backup.impl;
+
+import java.util.Map;
+
+import javax.jcr.RepositoryException;
+
+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;
+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.impl.RepositoryServiceImpl;
+import org.exoplatform.services.jcr.impl.core.SessionRegistry;
+import org.exoplatform.services.jcr.impl.util.jdbc.DBCleanerService;
+
+/**
+ * Created by The eXo Platform SAS.
+ *
+ * <br/>Date: 2010
+ *
+ * @author <a href="mailto:alex.reshetnyak@exoplatform.com.ua">Alex
Reshetnyak</a>
+ * @version $Id$
+ */
+public class JobExistedRepositoryRestore
+ extends JobRepositoryRestore
+{
+
+ public JobExistedRepositoryRestore(RepositoryService repoService, BackupManagerImpl
backupManagerImpl,
+ RepositoryEntry repositoryEntry, Map<String, BackupChainLog>
workspacesMapping,
+ RepositoryBackupChainLog backupChainLog)
+ {
+ super(repoService, backupManagerImpl, repositoryEntry, workspacesMapping,
backupChainLog);
+ }
+
+ protected void restore() throws RepositoryRestoreExeption
+ {
+ try
+ {
+ boolean isDefault =
repositoryService.getDefaultRepository().getConfiguration().getName().equals(repositoryEntry.getName());
+
+ //close all session
+ for (WorkspaceEntry wEntry : repositoryEntry.getWorkspaceEntries())
+ {
+ forceCloseSession(repositoryEntry.getName(), wEntry.getName());
+ }
+
+ //remove repository
+ if (isDefault)
+ {
+ ((RepositoryServiceImpl)repositoryService).removeDefaultRepository();
+ }
+ else
+ {
+ repositoryService.removeRepository(repositoryEntry.getName());
+ }
+
+ //clean database
+ DBCleanerService.removeRepositoryData(repositoryEntry);
+
+ //clean index
+ for (WorkspaceEntry wEntry : repositoryEntry.getWorkspaceEntries())
+ {
+ IndexCleanerService.removeWorkspaceIndex(wEntry,
repositoryEntry.getSystemWorkspaceName().equals(wEntry.getName()));
+ }
+
+
+ //clean value storage
+ for (WorkspaceEntry wEntry : repositoryEntry.getWorkspaceEntries())
+ {
+ ValueStorageCleanerService.removeWorkspaceValueStorage(wEntry);
+ }
+
+ super.restore();
+ }
+ catch (Throwable t)
+ {
+ throw new RepositoryRestoreExeption("Repository " +
repositoryEntry.getName() + " was not restored", t);
+ }
+ }
+
+ /**
+ * forceCloseSession. Close sessions on specific workspace.
+ *
+ * @param repositoryName
+ * repository name
+ * @param workspaceName
+ * workspace name
+ * @return int return the how many sessions was closed
+ * @throws RepositoryConfigurationException
+ * will be generate RepositoryConfigurationException
+ * @throws RepositoryException
+ * will be generate RepositoryException
+ */
+ private int forceCloseSession(String repositoryName, String workspaceName) throws
RepositoryException,
+ RepositoryConfigurationException
+ {
+ ManageableRepository mr = repositoryService.getRepository(repositoryName);
+ WorkspaceContainerFacade wc = mr.getWorkspaceContainer(workspaceName);
+
+ SessionRegistry sessionRegistry =
(SessionRegistry)wc.getComponent(SessionRegistry.class);
+
+ return sessionRegistry.closeSessions(workspaceName);
+ }
+
+}
Property changes on:
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/JobExistedRepositoryRestore.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added:
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/JobExistedWorkspaceRestore.java
===================================================================
---
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/JobExistedWorkspaceRestore.java
(rev 0)
+++
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/JobExistedWorkspaceRestore.java 2010-09-28
12:01:50 UTC (rev 3210)
@@ -0,0 +1,154 @@
+/*
+ * Copyright (C) 2003-2010 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not,
see<http://www.gnu.org/licenses/>.
+ */
+package org.exoplatform.services.jcr.ext.backup.impl;
+
+import javax.jcr.RepositoryException;
+
+import org.exoplatform.container.ExoContainer;
+import org.exoplatform.services.jcr.RepositoryService;
+import org.exoplatform.services.jcr.config.RepositoryConfigurationException;
+import org.exoplatform.services.jcr.config.WorkspaceEntry;
+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.BackupManager;
+import org.exoplatform.services.jcr.ext.backup.WorkspaceRestoreException;
+import org.exoplatform.services.jcr.impl.RepositoryContainer;
+import org.exoplatform.services.jcr.impl.core.RepositoryImpl;
+import org.exoplatform.services.jcr.impl.core.SessionRegistry;
+import org.exoplatform.services.jcr.impl.util.jdbc.DBCleanerService;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+
+/**
+ * Created by The eXo Platform SAS.
+ *
+ * <br/>Date: 2010
+ *
+ * @author <a href="mailto:alex.reshetnyak@exoplatform.com.ua">Alex
Reshetnyak</a>
+ * @version $Id$
+ */
+public class JobExistedWorkspaceRestore
+ extends JobWorkspaceRestore
+{
+
+ class RepositoryImplHelper extends RepositoryImpl
+ {
+
+ public RepositoryImplHelper(RepositoryContainer container) throws
RepositoryException,
+ RepositoryConfigurationException
+ {
+ super(container);
+ }
+
+ public void removeSystemWorkspace() throws RepositoryException
+ {
+ super.removeSystemWorkspace();
+ }
+ }
+
+ /**
+ * The apache logger.
+ */
+ private static Log log =
ExoLogger.getLogger("exo.jcr.component.ext.JobExistedWorkspaceRestore");
+
+ public JobExistedWorkspaceRestore(RepositoryService repositoryService, BackupManager
backupManager,
+ String repositoryName, BackupChainLog log, WorkspaceEntry wEntry)
+ {
+ super(repositoryService, backupManager, repositoryName, log, wEntry);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ protected void restore() throws WorkspaceRestoreException
+ {
+ try {
+ boolean isSystem =
repositoryService.getRepository(repositoryName).getConfiguration().getSystemWorkspaceName().equals(wEntry.getName());
+
+ //close all session
+ forceCloseSession(repositoryName, wEntry.getName());
+
+ //remove workspace
+ if (isSystem)
+ {
+ RepositoryImpl repositoryImpl =
(RepositoryImpl)repositoryService.getRepository(repositoryName);
+ repositoryImpl.removeSystemWorkspace();
+ }
+ else
+ {
+
repositoryService.getRepository(repositoryName).removeWorkspace(wEntry.getName());
+ }
+
+ //clean database
+ DBCleanerService.removeWorkspaceData(wEntry);
+
+ //clean index
+ IndexCleanerService.removeWorkspaceIndex(wEntry, isSystem);
+
+ //clean value storage
+ ValueStorageCleanerService.removeWorkspaceValueStorage(wEntry);
+
+ super.restore();
+ }
+ catch (Throwable t)
+ {
+ throw new WorkspaceRestoreException("Workspace " + wEntry.getName() +
" was not restored", t);
+ }
+ }
+
+ /**
+ * forceCloseSession. Close sessions on specific workspace.
+ *
+ * @param repositoryName
+ * repository name
+ * @param workspaceName
+ * workspace name
+ * @return int return the how many sessions was closed
+ * @throws RepositoryConfigurationException
+ * will be generate RepositoryConfigurationException
+ * @throws RepositoryException
+ * will be generate RepositoryException
+ */
+ private int forceCloseSession(String repositoryName, String workspaceName) throws
RepositoryException,
+ RepositoryConfigurationException
+ {
+ ManageableRepository mr = repositoryService.getRepository(repositoryName);
+ WorkspaceContainerFacade wc = mr.getWorkspaceContainer(workspaceName);
+
+ SessionRegistry sessionRegistry =
(SessionRegistry)wc.getComponent(SessionRegistry.class);
+
+ return sessionRegistry.closeSessions(workspaceName);
+ }
+}
+
+class ExtendedRepository extends RepositoryImpl
+{
+
+ public ExtendedRepository(RepositoryContainer container) throws RepositoryException,
+ RepositoryConfigurationException
+ {
+ super(container);
+ }
+
+ public void removeSystemWorkspace() throws RepositoryException
+ {
+ super.removeSystemWorkspace();
+ }
+}
+
+
Property changes on:
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/JobExistedWorkspaceRestore.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
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-09-28
11:57:59 UTC (rev 3209)
+++
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/JobRepositoryRestore.java 2010-09-28
12:01:50 UTC (rev 3210)
@@ -97,11 +97,11 @@
*/
private Throwable restoreException = null;
- private RepositoryService repositoryService;
+ protected RepositoryService repositoryService;
private BackupManagerImpl backupManager;
- private RepositoryEntry repositoryEntry;
+ protected RepositoryEntry repositoryEntry;
private Map<String, BackupChainLog> workspacesMapping;
Modified:
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/JobWorkspaceRestore.java
===================================================================
---
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/JobWorkspaceRestore.java 2010-09-28
11:57:59 UTC (rev 3209)
+++
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/JobWorkspaceRestore.java 2010-09-28
12:01:50 UTC (rev 3210)
@@ -80,17 +80,17 @@
/**
* The destination repository.
*/
- private final String repositoryName;
+ protected final String repositoryName;
/**
* The WorkspaceEntry to restored workspace.
*/
- private final WorkspaceEntry wEntry;
+ protected final WorkspaceEntry wEntry;
/**
* The repository service.
*/
- private final RepositoryService repositoryService;
+ protected final RepositoryService repositoryService;
/**
* The backup manager.
@@ -172,7 +172,7 @@
* @throws Throwable
* will be generated the Throwable
*/
- private void restore() throws Throwable
+ protected void restore() throws Throwable
{
boolean restored = true;
RepositoryImpl repository =
(RepositoryImpl)repositoryService.getRepository(repositoryName);
Added:
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/ValueStorageCleanerService.java
===================================================================
---
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/ValueStorageCleanerService.java
(rev 0)
+++
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/ValueStorageCleanerService.java 2010-09-28
12:01:50 UTC (rev 3210)
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2003-2010 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not,
see<http://www.gnu.org/licenses/>.
+ */
+package org.exoplatform.services.jcr.ext.backup.impl;
+
+import org.exoplatform.services.jcr.config.ValueStorageEntry;
+import org.exoplatform.services.jcr.config.WorkspaceEntry;
+
+/**
+ * Created by The eXo Platform SAS.
+ *
+ * <br/>Date: 2010
+ *
+ * @author <a href="mailto:alex.reshetnyak@exoplatform.com.ua">Alex
Reshetnyak</a>
+ * @version $Id$
+ */
+public class ValueStorageCleanerService
+{
+
+ public static void removeWorkspaceValueStorage(WorkspaceEntry wEntry)
+ {
+ /*for( ValueStorageEntry valueStorageEntry :
wEntry.getContainer().getValueStorages())
+ {
+
+ }*/
+ }
+
+}
Property changes on:
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/ValueStorageCleanerService.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Modified:
jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/AbstractBackupTestCase.java
===================================================================
---
jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/AbstractBackupTestCase.java 2010-09-28
11:57:59 UTC (rev 3209)
+++
jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/AbstractBackupTestCase.java 2010-09-28
12:01:50 UTC (rev 3210)
@@ -37,6 +37,7 @@
import org.exoplatform.services.jcr.config.ContainerEntry;
import org.exoplatform.services.jcr.config.QueryHandlerEntry;
+import org.exoplatform.services.jcr.config.QueryHandlerParams;
import org.exoplatform.services.jcr.config.RepositoryConfigurationException;
import org.exoplatform.services.jcr.config.RepositoryEntry;
import org.exoplatform.services.jcr.config.SimpleParameterEntry;
@@ -61,7 +62,7 @@
protected SessionImpl ws2Session;
- protected BackupManager backup;
+ protected ExtendedBackupManager backup;
class LogFilter implements FileFilter
{
@@ -79,7 +80,7 @@
// RepositoryContainer rcontainer = (RepositoryContainer)
// container.getComponentInstanceOfType(RepositoryContainer.class);
- backup = (BackupManager)container.getComponentInstanceOfType(BackupManager.class);
+ backup =
(ExtendedBackupManager)container.getComponentInstanceOfType(BackupManager.class);
if (backup == null)
throw new Exception("There are no BackupManagerImpl in
configuration");
@@ -129,7 +130,6 @@
}
}
- super.tearDown();
}
protected WorkspaceEntry makeWorkspaceEntry(String name, String sourceName)
@@ -224,12 +224,19 @@
ws1back.setInitializer(baseWorkspaceEntry.getInitializer());
// Indexer
- ArrayList qParams = new ArrayList();
- qParams.add(new SimpleParameterEntry("indexDir", "target" +
File.separator + repoName + "_" + wsName));
- QueryHandlerEntry qEntry =
- new
QueryHandlerEntry("org.exoplatform.services.jcr.impl.core.query.lucene.SearchIndex",
qParams);
-
- ws1back.setQueryHandler(qEntry);
+ if (sourceName != null)
+ {
+ ArrayList qParams = new ArrayList();
+ qParams.add(new SimpleParameterEntry(QueryHandlerParams.PARAM_INDEX_DIR,
"target" + File.separator + repoName + "_" + wsName));
+ QueryHandlerEntry qEntry =
+ new
QueryHandlerEntry("org.exoplatform.services.jcr.impl.core.query.lucene.SearchIndex",
qParams);
+
+ ws1back.setQueryHandler(qEntry);
+ }
+ else
+ {
+ ws1back.setQueryHandler(baseWorkspaceEntry.getQueryHandler());
+ }
ArrayList params = new ArrayList();
for (Iterator i = ws1back.getContainer().getParameters().iterator(); i.hasNext();)
@@ -238,7 +245,12 @@
SimpleParameterEntry newp = new SimpleParameterEntry(p.getName(),
p.getValue());
if (newp.getName().equals("source-name"))
- newp.setValue(sourceName);
+ {
+ if (sourceName != null)
+ {
+ newp.setValue(sourceName);
+ }
+ }
else if (newp.getName().equals("swap-directory"))
newp.setValue("target/temp/swap/" + repoName + "_" +
wsName);
else if (newp.getName().equals("multi-db"))
@@ -321,8 +333,4 @@
Thread.sleep(250);
}
- public void testname() throws Exception
- {
- assertEquals(true, true);
- }
}
Modified:
jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/TestBackupManager.java
===================================================================
---
jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/TestBackupManager.java 2010-09-28
11:57:59 UTC (rev 3209)
+++
jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/TestBackupManager.java 2010-09-28
12:01:50 UTC (rev 3210)
@@ -22,6 +22,7 @@
import org.exoplatform.services.jcr.config.RepositoryEntry;
import org.exoplatform.services.jcr.config.WorkspaceEntry;
import org.exoplatform.services.jcr.core.ManageableRepository;
+import org.exoplatform.services.jcr.ext.backup.impl.BackupManagerImpl;
import org.exoplatform.services.jcr.ext.backup.impl.JobRepositoryRestore;
import org.exoplatform.services.jcr.ext.backup.impl.JobWorkspaceRestore;
import org.exoplatform.services.jcr.impl.core.SessionImpl;
@@ -794,7 +795,7 @@
SessionImpl back1 = null;
try
{
- back1 = (SessionImpl)repository.login(credentials, wsName);
+ back1 = (SessionImpl)restoredRepository.login(credentials, wsName);
Node ws1backTestRoot =
back1.getRootNode().getNode("backupTest");
assertEquals("Restored content should be same",
"property-5", ws1backTestRoot.getNode("node_5")
.getProperty("exo:data").getString());
@@ -950,7 +951,7 @@
SessionImpl back1 = null;
try
{
- back1 = (SessionImpl)repository.login(credentials, wsName);
+ back1 = (SessionImpl)restoredRepository.login(credentials, wsName);
Node ws1backTestRoot =
back1.getRootNode().getNode("backupTest");
assertEquals("Restored content should be same",
"property-5", ws1backTestRoot.getNode("node_5")
.getProperty("exo:data").getString());
@@ -1052,7 +1053,7 @@
SessionImpl back1 = null;
try
{
- back1 = (SessionImpl)repository.login(credentials,
workspaceMapping.get(wsName));
+ back1 = (SessionImpl)restoredRepository.login(credentials,
workspaceMapping.get(wsName));
Node ws1backTestRoot =
back1.getRootNode().getNode("backupTest");
assertEquals("Restored content should be same",
"property-5", ws1backTestRoot.getNode("node_5")
.getProperty("exo:data").getString());
@@ -1226,4 +1227,648 @@
else
fail("There are no backup files in " + backDir.getAbsolutePath());
}
+
+ public void testExistedWorkspaceRestore() throws Exception
+ {
+ // backup
+ File backDir = new File("target/backup/ws1");
+ backDir.mkdirs();
+
+ BackupConfig config = new BackupConfig();
+ config.setRepository(repository.getName());
+ config.setWorkspace("ws1");
+ config.setBackupType(BackupManager.FULL_BACKUP_ONLY);
+
+ config.setBackupDir(backDir);
+
+ backup.startBackup(config);
+
+ BackupChain bch = backup.findBackup(repository.getName(), "ws1");
+
+ // wait till full backup will be stopped
+ while (bch.getFullBackupState() != BackupJob.FINISHED)
+ {
+ Thread.yield();
+ Thread.sleep(50);
+ }
+
+ // stop fullBackup
+
+ if (bch != null)
+ backup.stopBackup(bch);
+ else
+ fail("Can't get fullBackup chain");
+
+ // restore
+ RepositoryEntry re =
(RepositoryEntry)ws1Session.getContainer().getComponentInstanceOfType(RepositoryEntry.class);
+ WorkspaceEntry ws1 = null;
+ for (WorkspaceEntry we : re.getWorkspaceEntries())
+ {
+ if (ws1Session.getWorkspace().getName().equals(we.getName()))
+ {
+ ws1 = we;
+ break;
+ }
+ }
+
+ File backLog = new File(bch.getLogFilePath());
+ if (backLog.exists())
+ {
+ BackupChainLog bchLog = new BackupChainLog(backLog);
+
+ assertNotNull(bchLog.getStartedTime());
+ assertNotNull(bchLog.getFinishedTime());
+
+ backup.restoreExistedWorkspace(bchLog, re.getName(), ws1, false);
+
+ // check
+ SessionImpl back1 = null;
+ try
+ {
+ back1 = (SessionImpl)repository.login(credentials, "ws1");
+ Node ws1backTestRoot = back1.getRootNode().getNode("backupTest");
+ assertEquals("Restored content should be same",
"property-5", ws1backTestRoot.getNode("node_5")
+ .getProperty("exo:data").getString());
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ finally
+ {
+ if (back1 != null)
+ back1.logout();
+ }
+ }
+ else
+ fail("There are no backup files in " + backDir.getAbsolutePath());
+ }
+
+ public void testExistedWorkspaceRestoreAsync() throws Exception
+ {
+ // backup
+ File backDir = new File("target/backup/ws1");
+ backDir.mkdirs();
+
+ BackupConfig config = new BackupConfig();
+ config.setRepository(repository.getName());
+ config.setWorkspace("ws1");
+ config.setBackupType(BackupManager.FULL_BACKUP_ONLY);
+
+ config.setBackupDir(backDir);
+
+ backup.startBackup(config);
+
+ BackupChain bch = backup.findBackup(repository.getName(), "ws1");
+
+ // wait till full backup will be stopped
+ while (bch.getFullBackupState() != BackupJob.FINISHED)
+ {
+ Thread.yield();
+ Thread.sleep(50);
+ }
+
+ // stop fullBackup
+
+ if (bch != null)
+ backup.stopBackup(bch);
+ else
+ fail("Can't get fullBackup chain");
+
+ // restore
+ RepositoryEntry re =
(RepositoryEntry)ws1Session.getContainer().getComponentInstanceOfType(RepositoryEntry.class);
+ WorkspaceEntry ws1 = null;
+ for (WorkspaceEntry we : re.getWorkspaceEntries())
+ {
+ if (ws1Session.getWorkspace().getName().equals(we.getName()))
+ {
+ ws1 = we;
+ break;
+ }
+ }
+
+ File backLog = new File(bch.getLogFilePath());
+ if (backLog.exists())
+ {
+ BackupChainLog bchLog = new BackupChainLog(backLog);
+
+ assertNotNull(bchLog.getStartedTime());
+ assertNotNull(bchLog.getFinishedTime());
+
+ backup.restoreExistedWorkspace(bchLog, re.getName(), ws1, true);
+
+ while (backup.getLastRestore(repository.getName(),
ws1.getName()).getStateRestore() != JobWorkspaceRestore.RESTORE_SUCCESSFUL
+ && backup.getLastRestore(repository.getName(),
ws1.getName()).getStateRestore() != JobWorkspaceRestore.RESTORE_FAIL)
+ {
+ Thread.sleep(50);
+ }
+
+ // check
+ SessionImpl back1 = null;
+ try
+ {
+ back1 = (SessionImpl)repository.login(credentials, "ws1");
+ Node ws1backTestRoot = back1.getRootNode().getNode("backupTest");
+ assertEquals("Restored content should be same",
"property-5", ws1backTestRoot.getNode("node_5")
+ .getProperty("exo:data").getString());
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ finally
+ {
+ if (back1 != null)
+ back1.logout();
+ }
+ }
+ else
+ fail("There are no backup files in " + backDir.getAbsolutePath());
+ }
+
+ public void testExistedWorkspaceRestoreAsync2() throws Exception
+ {
+ // backup
+ File backDir = new File("target/backup/ws1");
+ backDir.mkdirs();
+
+ BackupConfig config = new BackupConfig();
+ config.setRepository(repository.getName());
+ config.setWorkspace("ws1");
+ config.setBackupType(BackupManager.FULL_BACKUP_ONLY);
+
+ config.setBackupDir(backDir);
+
+ backup.startBackup(config);
+
+ BackupChain bch = backup.findBackup(repository.getName(), "ws1");
+
+ // wait till full backup will be stopped
+ while (bch.getFullBackupState() != BackupJob.FINISHED)
+ {
+ Thread.yield();
+ Thread.sleep(50);
+ }
+
+ // stop fullBackup
+
+ if (bch != null)
+ backup.stopBackup(bch);
+ else
+ fail("Can't get fullBackup chain");
+
+ // restore
+ RepositoryEntry re =
(RepositoryEntry)ws1Session.getContainer().getComponentInstanceOfType(RepositoryEntry.class);
+ WorkspaceEntry ws1 = null;
+ for (WorkspaceEntry we : re.getWorkspaceEntries())
+ {
+ if (ws1Session.getWorkspace().getName().equals(we.getName()))
+ {
+ ws1 = we;
+ break;
+ }
+ }
+
+ File backLog = new File(bch.getLogFilePath());
+ if (backLog.exists())
+ {
+ BackupChainLog bchLog = new BackupChainLog(backLog);
+
+ assertNotNull(bchLog.getStartedTime());
+ assertNotNull(bchLog.getFinishedTime());
+
+ backup.restoreExistedWorkspace(bchLog.getBackupId(), re.getName(), ws1, true);
+
+ while (backup.getLastRestore(repository.getName(),
ws1.getName()).getStateRestore() != JobWorkspaceRestore.RESTORE_SUCCESSFUL
+ && backup.getLastRestore(repository.getName(),
ws1.getName()).getStateRestore() != JobWorkspaceRestore.RESTORE_FAIL)
+ {
+ Thread.sleep(50);
+ }
+
+ // check
+ SessionImpl back1 = null;
+ try
+ {
+ back1 = (SessionImpl)repository.login(credentials, "ws1");
+ Node ws1backTestRoot = back1.getRootNode().getNode("backupTest");
+ assertEquals("Restored content should be same",
"property-5", ws1backTestRoot.getNode("node_5")
+ .getProperty("exo:data").getString());
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ finally
+ {
+ if (back1 != null)
+ back1.logout();
+ }
+ }
+ else
+ fail("There are no backup files in " + backDir.getAbsolutePath());
+ }
+
+ public void testExistedRepositoryRestore() throws Exception
+ {
+ // backup
+ File backDir = new File("target/backup");
+ backDir.mkdirs();
+
+ RepositoryBackupConfig config = new RepositoryBackupConfig();
+ config.setRepository(repository.getName());
+ config.setBackupType(BackupManager.FULL_BACKUP_ONLY);
+
+ config.setBackupDir(backDir);
+
+ backup.startBackup(config);
+
+ RepositoryBackupChain bch = backup.findRepositoryBackup(repository.getName());
+
+ // wait till full backup will be stopped
+ while (bch.getState() != RepositoryBackupChain.FINISHED)
+ {
+ Thread.yield();
+ Thread.sleep(50);
+ }
+
+ // stop fullBackup
+
+ backup.stopBackup(bch);
+
+ // restore
+ RepositoryEntry baseRE =
(RepositoryEntry)ws1Session.getContainer().getComponentInstanceOfType(RepositoryEntry.class);
+ RepositoryEntry re = makeRepositoryEntry(baseRE.getName() , baseRE, null, null);
+
+ File backLog = new File(bch.getLogFilePath());
+ if (backLog.exists())
+ {
+ RepositoryBackupChainLog bchLog = new RepositoryBackupChainLog(backLog);
+
+ assertNotNull(bchLog.getStartedTime());
+ assertNotNull(bchLog.getFinishedTime());
+
+ backup.restoreExistedRepository(bchLog, re, false);
+
+ assertEquals(JobWorkspaceRestore.RESTORE_SUCCESSFUL,
backup.getLastRepositoryRestore(
+ re.getName()).getStateRestore());
+
+ // check
+ ManageableRepository restoredRepository =
repositoryService.getRepository(re.getName());
+
+ for (String wsName : restoredRepository.getWorkspaceNames())
+ {
+ SessionImpl back1 = null;
+ try
+ {
+ back1 = (SessionImpl)restoredRepository.login(credentials, wsName);
+ Node ws1backTestRoot =
back1.getRootNode().getNode("backupTest");
+ assertEquals("Restored content should be same",
"property-5", ws1backTestRoot.getNode("node_5")
+ .getProperty("exo:data").getString());
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ finally
+ {
+ if (back1 != null)
+ back1.logout();
+ }
+ }
+ }
+ else
+ fail("There are no backup files in " + backDir.getAbsolutePath());
+ }
+
+ public void testExistedRepositoryRestoreAsync() throws Exception
+ {
+ // backup
+ File backDir = new File("target/backup");
+ backDir.mkdirs();
+
+ RepositoryBackupConfig config = new RepositoryBackupConfig();
+ config.setRepository(repository.getName());
+ config.setBackupType(BackupManager.FULL_BACKUP_ONLY);
+
+ config.setBackupDir(backDir);
+
+ backup.startBackup(config);
+
+ RepositoryBackupChain bch = backup.findRepositoryBackup(repository.getName());
+
+ // wait till full backup will be stopped
+ while (bch.getState() != RepositoryBackupChain.FINISHED)
+ {
+ Thread.yield();
+ Thread.sleep(50);
+ }
+
+ // stop fullBackup
+
+ backup.stopBackup(bch);
+
+ // restore
+ RepositoryEntry baseRE =
(RepositoryEntry)ws1Session.getContainer().getComponentInstanceOfType(RepositoryEntry.class);
+ RepositoryEntry re = makeRepositoryEntry(baseRE.getName() , baseRE, null, null);
+
+ File backLog = new File(bch.getLogFilePath());
+ if (backLog.exists())
+ {
+ RepositoryBackupChainLog bchLog = new RepositoryBackupChainLog(backLog);
+
+ assertNotNull(bchLog.getStartedTime());
+ assertNotNull(bchLog.getFinishedTime());
+
+ backup.restoreExistedRepository(bchLog, re, true);
+
+ JobRepositoryRestore job = backup.getLastRepositoryRestore(re.getName());
+
+ Thread.sleep(30*1000);
+
+ while (job.getStateRestore() !=
JobRepositoryRestore.REPOSITORY_RESTORE_SUCCESSFUL
+ && job.getStateRestore() !=
JobRepositoryRestore.REPOSITORY_RESTORE_FAIL)
+ {
+ Thread.sleep(50);
+ }
+
+ assertEquals(JobRepositoryRestore.REPOSITORY_RESTORE_SUCCESSFUL,
backup.getLastRepositoryRestore(
+ re.getName()).getStateRestore());
+
+ // check
+ ManageableRepository restoredRepository =
repositoryService.getRepository(re.getName());
+
+ for (String wsName : restoredRepository.getWorkspaceNames())
+ {
+ SessionImpl back1 = null;
+ try
+ {
+ back1 = (SessionImpl)restoredRepository.login(credentials, wsName);
+ Node ws1backTestRoot =
back1.getRootNode().getNode("backupTest");
+ assertEquals("Restored content should be same",
"property-5", ws1backTestRoot.getNode("node_5")
+ .getProperty("exo:data").getString());
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ finally
+ {
+ if (back1 != null)
+ back1.logout();
+ }
+ }
+ }
+ else
+ fail("There are no backup files in " + backDir.getAbsolutePath());
+ }
+
+ public void testExistedRepositoryRestoreAsync2() throws Exception
+ {
+ // backup
+ File backDir = new File("target/backup");
+ backDir.mkdirs();
+
+ RepositoryBackupConfig config = new RepositoryBackupConfig();
+ config.setRepository(repository.getName());
+ config.setBackupType(BackupManager.FULL_BACKUP_ONLY);
+
+ config.setBackupDir(backDir);
+
+ backup.startBackup(config);
+
+ RepositoryBackupChain bch = backup.findRepositoryBackup(repository.getName());
+
+ // wait till full backup will be stopped
+ while (bch.getState() != RepositoryBackupChain.FINISHED)
+ {
+ Thread.yield();
+ Thread.sleep(50);
+ }
+
+ // stop fullBackup
+
+ backup.stopBackup(bch);
+
+ // restore
+ RepositoryEntry baseRE =
(RepositoryEntry)ws1Session.getContainer().getComponentInstanceOfType(RepositoryEntry.class);
+ RepositoryEntry re = makeRepositoryEntry(baseRE.getName() , baseRE, null, null);
+
+ File backLog = new File(bch.getLogFilePath());
+ if (backLog.exists())
+ {
+ RepositoryBackupChainLog bchLog = new RepositoryBackupChainLog(backLog);
+
+ assertNotNull(bchLog.getStartedTime());
+ assertNotNull(bchLog.getFinishedTime());
+
+ backup.restoreExistedRepository(bchLog.getBackupId(), re, true);
+
+ JobRepositoryRestore job = backup.getLastRepositoryRestore(re.getName());
+
+ while (job.getStateRestore() !=
JobRepositoryRestore.REPOSITORY_RESTORE_SUCCESSFUL
+ && job.getStateRestore() !=
JobRepositoryRestore.REPOSITORY_RESTORE_FAIL)
+ {
+ Thread.sleep(50);
+ }
+
+ assertEquals(JobWorkspaceRestore.RESTORE_SUCCESSFUL,
backup.getLastRepositoryRestore(
+ re.getName()).getStateRestore());
+
+ // check
+ ManageableRepository restoredRepository =
repositoryService.getRepository(re.getName());
+
+ for (String wsName : restoredRepository.getWorkspaceNames())
+ {
+ SessionImpl back1 = null;
+ try
+ {
+ back1 = (SessionImpl)restoredRepository.login(credentials, wsName);
+ Node ws1backTestRoot =
back1.getRootNode().getNode("backupTest");
+ assertEquals("Restored content should be same",
"property-5", ws1backTestRoot.getNode("node_5")
+ .getProperty("exo:data").getString());
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ finally
+ {
+ if (back1 != null)
+ back1.logout();
+ }
+ }
+ }
+ else
+ fail("There are no backup files in " + backDir.getAbsolutePath());
+ }
+
+ public void testExistedSystemWorkspaceRestore() throws Exception
+ {
+ String systemWS = repository.getSystemWorkspaceName();
+
+ // backup
+ File backDir = new File("target/backup/" + systemWS);
+ backDir.mkdirs();
+
+ BackupConfig config = new BackupConfig();
+ config.setRepository(repository.getName());
+ config.setWorkspace(systemWS);
+ config.setBackupType(BackupManager.FULL_BACKUP_ONLY);
+
+ config.setBackupDir(backDir);
+
+ backup.startBackup(config);
+
+ BackupChain bch = backup.findBackup(repository.getName(), systemWS);
+
+ // wait till full backup will be stopped
+ while (bch.getFullBackupState() != BackupJob.FINISHED)
+ {
+ Thread.yield();
+ Thread.sleep(50);
+ }
+
+ // stop fullBackup
+
+ if (bch != null)
+ backup.stopBackup(bch);
+ else
+ fail("Can't get fullBackup chain");
+
+ // restore
+ RepositoryEntry re =
(RepositoryEntry)ws1Session.getContainer().getComponentInstanceOfType(RepositoryEntry.class);
+ WorkspaceEntry ws1 = null;
+ for (WorkspaceEntry we : re.getWorkspaceEntries())
+ {
+ if (systemWS.equals(we.getName()))
+ {
+ ws1 = we;
+ break;
+ }
+ }
+
+ File backLog = new File(bch.getLogFilePath());
+ if (backLog.exists())
+ {
+ BackupChainLog bchLog = new BackupChainLog(backLog);
+
+ assertNotNull(bchLog.getStartedTime());
+ assertNotNull(bchLog.getFinishedTime());
+
+ backup.restoreExistedWorkspace(bchLog, re.getName(), ws1, false);
+
+ // check
+ SessionImpl back1 = null;
+ try
+ {
+ back1 = (SessionImpl)repository.login(credentials, systemWS);
+ Node ws1backTestRoot = back1.getRootNode().getNode("backupTest");
+ assertEquals("Restored content should be same",
"property-5", ws1backTestRoot.getNode("node_5")
+ .getProperty("exo:data").getString());
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ finally
+ {
+ if (back1 != null)
+ back1.logout();
+ }
+ }
+ else
+ fail("There are no backup files in " + backDir.getAbsolutePath());
+ }
+
+ public void testExistedSystemWorkspaceRestoreAsync() throws Exception
+ {
+ String systemWS = repository.getSystemWorkspaceName();
+
+ // backup
+ File backDir = new File("target/backup/" + systemWS);
+ backDir.mkdirs();
+
+ BackupConfig config = new BackupConfig();
+ config.setRepository(repository.getName());
+ config.setWorkspace(systemWS);
+ config.setBackupType(BackupManager.FULL_BACKUP_ONLY);
+
+ config.setBackupDir(backDir);
+
+ backup.startBackup(config);
+
+ BackupChain bch = backup.findBackup(repository.getName(), systemWS);
+
+ // wait till full backup will be stopped
+ while (bch.getFullBackupState() != BackupJob.FINISHED)
+ {
+ Thread.yield();
+ Thread.sleep(50);
+ }
+
+ // stop fullBackup
+
+ if (bch != null)
+ backup.stopBackup(bch);
+ else
+ fail("Can't get fullBackup chain");
+
+ // restore
+ RepositoryEntry re =
(RepositoryEntry)ws1Session.getContainer().getComponentInstanceOfType(RepositoryEntry.class);
+ WorkspaceEntry ws1 = null;
+ for (WorkspaceEntry we : re.getWorkspaceEntries())
+ {
+ if (systemWS.equals(we.getName()))
+ {
+ ws1 = we;
+ break;
+ }
+ }
+
+ File backLog = new File(bch.getLogFilePath());
+ if (backLog.exists())
+ {
+ BackupChainLog bchLog = new BackupChainLog(backLog);
+
+ assertNotNull(bchLog.getStartedTime());
+ assertNotNull(bchLog.getFinishedTime());
+
+ backup.restoreExistedWorkspace(bchLog, re.getName(), ws1, true);
+
+ while (backup.getLastRestore(repository.getName(),
ws1.getName()).getStateRestore() != JobWorkspaceRestore.RESTORE_SUCCESSFUL
+ && backup.getLastRestore(repository.getName(),
ws1.getName()).getStateRestore() != JobWorkspaceRestore.RESTORE_FAIL)
+ {
+ Thread.sleep(50);
+ }
+
+ // check
+ SessionImpl back1 = null;
+ try
+ {
+ back1 = (SessionImpl)repository.login(credentials, systemWS);
+ Node ws1backTestRoot = back1.getRootNode().getNode("backupTest");
+ assertEquals("Restored content should be same",
"property-5", ws1backTestRoot.getNode("node_5")
+ .getProperty("exo:data").getString());
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ finally
+ {
+ if (back1 != null)
+ back1.logout();
+ }
+ }
+ else
+ fail("There are no backup files in " + backDir.getAbsolutePath());
+ }
}