[exo-jcr-commits] exo-jcr SVN: r2127 - in jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup: server and 1 other directory.
do-not-reply at jboss.org
do-not-reply at jboss.org
Thu Mar 25 09:46:47 EDT 2010
Author: areshetnyak
Date: 2010-03-25 09:46:47 -0400 (Thu, 25 Mar 2010)
New Revision: 2127
Added:
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/server/RepositoryRestoreExeption.java
Modified:
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/RepositoryBackupChainLog.java
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/server/HTTPBackupAgent.java
Log:
EXOJCR-549 : The implementation backup/restore whole repository in HTTPBackupAgent.
Modified: jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/RepositoryBackupChainLog.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/RepositoryBackupChainLog.java 2010-03-25 13:43:19 UTC (rev 2126)
+++ jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/RepositoryBackupChainLog.java 2010-03-25 13:46:47 UTC (rev 2127)
@@ -211,7 +211,7 @@
protected static Log logger = ExoLogger.getLogger("ext.BackupChainLog");
- private static final String PREFIX = "repository-backup-";
+ public static final String PREFIX = "repository-backup-";
private static final String SUFFIX = ".xml";
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 13:43:19 UTC (rev 2126)
+++ jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/server/HTTPBackupAgent.java 2010-03-25 13:46:47 UTC (rev 2127)
@@ -626,21 +626,19 @@
try
{
- validateOneRestoreInstants(rEntry.getName());
+ validateOneRepositoryRestoreInstants(rEntry.getName());
- File backupLog = getBackupLogbyId(backupId);
+ File backupLog = getRepositoryBackupLogbyId(backupId);
// validate backup log file
if (backupLog == null)
{
- throw new BackupLogNotFoundException("The backup log file with id " + backupId + " not exists.");
+ throw new BackupLogNotFoundException("The repository backup log file with id " + backupId + " not exists.");
}
- validateRepositoryName(rEntry.getName());
-
if (isRepositoryExist(rEntry.getName()))
{
- throw new Exception("Repository " + rEntry.getName() + " already exist!");
+ throw new RepositoryRestoreExeption("Repository " + rEntry.getName() + " already exist!");
}
RepositoryBackupChainLog backupChainLog = new RepositoryBackupChainLog(backupLog);
@@ -651,28 +649,14 @@
Thread.sleep(100);
// search necessary restore
- List<JobRepositoryRestore> restoreJobs = backupManager.getRepositoryRestores();
- JobRepositoryRestore restore = null;
- for (JobRepositoryRestore curRestore : restoreJobs)
- {
- if (curRestore.getRepositoryName().equals(rEntry.getName()))
- {
- restore = curRestore;
- break;
- }
- }
+ JobRepositoryRestore restore = backupManager.getLastRepositoryRestore(rEntry.getName());
+ ShortInfo info =
+ new ShortInfo(ShortInfo.RESTORE, restore.getRepositoryBackupChainLog(), restore.getStartTime(),
+ restore.getEndTime(), restore.getStateRestore(), restore.getRepositoryName());
- 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();
+ return Response.ok(info).cacheControl(noCache).build();
}
- catch (WorkspaceRestoreExeption e)
+ catch (RepositoryRestoreExeption e)
{
exception = e;
status = Response.Status.FORBIDDEN;
@@ -1294,7 +1278,15 @@
private boolean isRepositoryExist(String repositoryName) throws RepositoryException,
RepositoryConfigurationException
{
- return repositoryService.getRepository(repositoryName) != null;
+ try
+ {
+ return repositoryService.getRepository(repositoryName) != null;
+ }
+ catch (RepositoryException e)
+ {
+ return false;
+ }
+
}
/**
@@ -1339,6 +1331,26 @@
+ "' is already restoring.");
}
}
+
+ /**
+ * validateOneRepositoryRestoreInstants.
+ *
+ * @param repositoryName
+ * the repository name
+ * @throws WorkspaceRestoreExeption
+ * will be generated WorkspaceRestoreExeption
+ */
+ private void validateOneRepositoryRestoreInstants(String repositoryName) throws RepositoryRestoreExeption
+ {
+ for (JobRepositoryRestore job : backupManager.getRepositoryRestores())
+ {
+ if (repositoryName.equals(job.getRepositoryName())
+ && (job.getStateRestore() == JobWorkspaceRestore.RESTORE_INITIALIZED || job.getStateRestore() == JobWorkspaceRestore.RESTORE_STARTED))
+ {
+ throw new RepositoryRestoreExeption("The repository '" + "/" + repositoryName + "' is already restoring.");
+ }
+ }
+ }
/**
* validateOneRestoreInstants.
@@ -1410,4 +1422,32 @@
return null;
}
+
+ /**
+ * getRepositoryBackupLogbyId.
+ *
+ * @param backupId
+ * String, the backup identifier
+ * @return File return backup log file
+ */
+ private File getRepositoryBackupLogbyId(String backupId)
+ {
+ FilenameFilter backupLogsFilter = new FilenameFilter()
+ {
+
+ public boolean accept(File dir, String name)
+ {
+ return (name.endsWith(".xml") && name.startsWith(RepositoryBackupChainLog.PREFIX));
+ }
+ };
+
+ File[] files = backupManager.getBackupDirectory().listFiles(backupLogsFilter);
+
+ if (files.length != 0)
+ for (File f : files)
+ if (f.getName().replaceAll(".xml", "").replaceAll(RepositoryBackupChainLog.PREFIX, "").equals(backupId))
+ return f;
+
+ return null;
+ }
}
Added: jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/server/RepositoryRestoreExeption.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/server/RepositoryRestoreExeption.java (rev 0)
+++ jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/server/RepositoryRestoreExeption.java 2010-03-25 13:46:47 UTC (rev 2127)
@@ -0,0 +1,42 @@
+/*
+ * 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.server;
+
+/**
+ * Created by The eXo Platform SAS.
+ *
+ * <br/>Date: 2010
+ *
+ * @author <a href="mailto:alex.reshetnyak at exoplatform.com.ua">Alex Reshetnyak</a>
+ * @version $Id$
+ */
+public class RepositoryRestoreExeption
+ extends Exception
+{
+ /**
+ * WorkspaceRestoreExeption constructor.
+ *
+ * @param message
+ * String, the exception message
+ * @param e
+ * the cause exception
+ */
+ public RepositoryRestoreExeption(String message)
+ {
+ super(message);
+ }
+}
Property changes on: jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/server/RepositoryRestoreExeption.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
More information about the exo-jcr-commits
mailing list