Author: tolusha
Date: 2011-03-28 08:42:25 -0400 (Mon, 28 Mar 2011)
New Revision: 4180
Added:
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/JobExistingRepositoryRestore.java
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/JobExistingRepositorySameConfigRestore.java
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/JobExistingWorkspaceRestore.java
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/JobExistingWorkspaceSameConfigRestore.java
Removed:
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/JobExistedRepositoryRDBMSRestore.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/JobExistedWorkspaceRDBMSRestore.java
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/JobExistedWorkspaceRestore.java
Modified:
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/BackupManagerImpl.java
Log:
EXOJCR-1276: Determinate the way of comparing two configurations
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 2011-03-28
12:10:43 UTC (rev 4179)
+++
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/BackupManagerImpl.java 2011-03-28
12:42:25 UTC (rev 4180)
@@ -61,6 +61,8 @@
import org.exoplatform.services.jcr.util.IdGenerator;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
+import org.exoplatform.ws.frameworks.json.impl.JsonException;
+import org.exoplatform.ws.frameworks.json.impl.JsonGeneratorImpl;
import org.picocontainer.Startable;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
@@ -1557,21 +1559,42 @@
// check if we have deal with RDBMS backup
- boolean isRDBMSBackup = false;
+ boolean isSameConfigRestore = false;
try
{
- isRDBMSBackup =
-
(Class.forName(workspacesMapping.get(repositoryEntry.getWorkspaceEntries().get(0).getName())
-
.getFullBackupType()).equals(org.exoplatform.services.jcr.ext.backup.impl.rdbms.FullBackupJob.class));
+ if (Class.forName(
+
workspacesMapping.get(repositoryEntry.getWorkspaceEntries().get(0).getName()).getFullBackupType()).equals(
+ org.exoplatform.services.jcr.ext.backup.impl.rdbms.FullBackupJob.class))
+ {
+ String newConf = new
JsonGeneratorImpl().createJsonObject(repositoryEntry).toString();
+ String currnetConf =
+ new JsonGeneratorImpl().createJsonObject(
+
repoService.getRepository(repositoryEntry.getName()).getConfiguration()).toString();
+
+ isSameConfigRestore = newConf.equals(currnetConf);
+ }
}
+ catch (JsonException e)
+ {
+ this.log.error("Can't get JSON object from wokrspace
configuration", e);
+ }
+ catch (RepositoryException e)
+ {
+ this.log.error(e);
+ }
+ catch (RepositoryConfigurationException e)
+ {
+ this.log.error(e);
+ }
catch (ClassNotFoundException e)
{
this.log.error(e);
}
JobRepositoryRestore jobExistedRepositoryRestore =
- isRDBMSBackup ? new JobExistedRepositoryRDBMSRestore(repoService, this,
repositoryEntry, workspacesMapping,
- rblog) : new JobExistedRepositoryRestore(repoService, this, repositoryEntry,
workspacesMapping, rblog);
+ isSameConfigRestore ? new JobExistingRepositorySameConfigRestore(repoService,
this, repositoryEntry,
+ workspacesMapping, rblog) : new JobExistingRepositoryRestore(repoService,
this, repositoryEntry,
+ workspacesMapping, rblog);
restoreRepositoryJobs.add(jobExistedRepositoryRestore);
if (asynchronous)
@@ -1636,22 +1659,52 @@
throw new WorkspaceRestoreException("Repository \"" +
repositoryName + "\" should be existed", e);
}
- // check if we have deal with RDBMS backup
- boolean isRDBMSBackup = false;
+ // check if we need to use restore with same configuration as original
+ // it allows to use atomic restore in cluster env
+ boolean isSameConfigRestore = false;
try
{
- isRDBMSBackup =
- (Class.forName(log.getFullBackupType())
-
.equals(org.exoplatform.services.jcr.ext.backup.impl.rdbms.FullBackupJob.class));
+ if (Class.forName(log.getFullBackupType()).equals(
+ org.exoplatform.services.jcr.ext.backup.impl.rdbms.FullBackupJob.class))
+ {
+
+ WorkspaceEntry currentWsEntry = null;
+ for (WorkspaceEntry wsEntry :
repoService.getRepository(repositoryName).getConfiguration()
+ .getWorkspaceEntries())
+ {
+ if (wsEntry.getName().equals(workspaceEntry.getName()))
+ {
+ currentWsEntry = wsEntry;
+ break;
+ }
+ }
+
+ String newConf = new
JsonGeneratorImpl().createJsonObject(workspaceEntry).toString();
+ String currnetConf = new
JsonGeneratorImpl().createJsonObject(currentWsEntry).toString();
+
+ isSameConfigRestore = newConf.equals(currnetConf);
+ }
}
+ catch (JsonException e)
+ {
+ this.log.error("Can't get JSON object from wokrspace
configuration", e);
+ }
+ catch (RepositoryException e)
+ {
+ this.log.error(e);
+ }
+ catch (RepositoryConfigurationException e)
+ {
+ this.log.error(e);
+ }
catch (ClassNotFoundException e)
{
this.log.error(e);
}
JobWorkspaceRestore jobRestore =
- isRDBMSBackup ? new JobExistedWorkspaceRDBMSRestore(repoService, this,
repositoryName, log,
- workspaceEntry) : new JobExistedWorkspaceRestore(repoService, this,
repositoryName, log, workspaceEntry);
+ isSameConfigRestore ? new JobExistingWorkspaceSameConfigRestore(repoService,
this, repositoryName, log,
+ workspaceEntry) : new JobExistingWorkspaceRestore(repoService, this,
repositoryName, log, workspaceEntry);
restoreJobs.add(jobRestore);
if (asynchronous)
Deleted:
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/JobExistedRepositoryRDBMSRestore.java
===================================================================
---
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/JobExistedRepositoryRDBMSRestore.java 2011-03-28
12:10:43 UTC (rev 4179)
+++
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/JobExistedRepositoryRDBMSRestore.java 2011-03-28
12:42:25 UTC (rev 4180)
@@ -1,244 +0,0 @@
-/*
- * 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.commons.utils.SecurityHelper;
-import org.exoplatform.services.jcr.RepositoryService;
-import org.exoplatform.services.jcr.config.RepositoryEntry;
-import org.exoplatform.services.jcr.config.WorkspaceEntry;
-import org.exoplatform.services.jcr.dataflow.DataManager;
-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.backup.BackupException;
-import org.exoplatform.services.jcr.impl.backup.Backupable;
-import org.exoplatform.services.jcr.impl.backup.DataRestor;
-import org.exoplatform.services.jcr.impl.backup.JCRRestor;
-import org.exoplatform.services.jcr.impl.backup.JdbcBackupable;
-import org.exoplatform.services.jcr.impl.backup.ResumeException;
-import org.exoplatform.services.jcr.impl.backup.Suspendable;
-import
org.exoplatform.services.jcr.impl.dataflow.persistent.WorkspacePersistentDataManager;
-import org.exoplatform.services.jcr.impl.storage.jdbc.JDBCWorkspaceDataContainer;
-import org.exoplatform.services.jcr.impl.util.io.FileCleanerHolder;
-
-import java.io.File;
-import java.security.PrivilegedExceptionAction;
-import java.sql.Connection;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
-import javax.naming.InitialContext;
-import javax.naming.NameNotFoundException;
-import javax.sql.DataSource;
-
-/**
- * Created by The eXo Platform SAS.
- *
- * Date: 24 01 2011
- *
- * @author <a href="mailto:anatoliy.bazko@exoplatform.com.ua">Anatoliy
Bazko</a>
- * @version $Id: JobExistedRepositoryRestoreSameConfig.java 34360 2010-11-11 11:11:11Z
tolusha $
- */
-public class JobExistedRepositoryRDBMSRestore extends JobRepositoryRestore
-{
-
- /**
- * JobExistedRepositoryRDBMSRestore constructor.
- */
- public JobExistedRepositoryRDBMSRestore(RepositoryService repoService,
BackupManagerImpl backupManagerImpl,
- RepositoryEntry repositoryEntry, Map<String, BackupChainLog>
workspacesMapping,
- RepositoryBackupChainLog backupChainLog)
- {
- super(repoService, backupManagerImpl, repositoryEntry, workspacesMapping,
backupChainLog);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected void restoreRepository() throws RepositoryRestoreExeption
- {
- // list of data restorers
- List<DataRestor> dataRestorer = new ArrayList<DataRestor>();
-
- // the list of components to resume
- List<Suspendable> resumeComponents = new ArrayList<Suspendable>();
-
- try
- {
- WorkspaceEntry wsEntry = repositoryEntry.getWorkspaceEntries().get(0);
-
- // define one common connection for all restores and cleaners for single db
case
- Connection jdbcConn = null;
- if
(!Boolean.parseBoolean(wsEntry.getContainer().getParameterValue(JDBCWorkspaceDataContainer.MULTIDB)))
- {
- String dsName =
wsEntry.getContainer().getParameterValue(JDBCWorkspaceDataContainer.SOURCE_NAME);
-
- final DataSource ds = (DataSource)new InitialContext().lookup(dsName);
- if (ds == null)
- {
- throw new NameNotFoundException("Data source " + dsName + "
not found");
- }
-
- jdbcConn = SecurityHelper.doPrivilegedSQLExceptionAction(new
PrivilegedExceptionAction<Connection>()
- {
- public Connection run() throws Exception
- {
- return ds.getConnection();
-
- }
- });
- jdbcConn.setAutoCommit(false);
- }
-
- // suspend all components
- for (WorkspaceEntry wEntry : repositoryEntry.getWorkspaceEntries())
- {
- List<Suspendable> suspendableComponents =
-
repositoryService.getRepository(this.repositoryEntry.getName()).getWorkspaceContainer(wEntry.getName())
- .getComponentInstancesOfType(Suspendable.class);
-
- for (Suspendable component : suspendableComponents)
- {
- component.suspend();
- resumeComponents.add(component);
- }
- }
-
- // collect all restorers
- for (WorkspaceEntry wEntry : repositoryEntry.getWorkspaceEntries())
- {
- // get all backupable components
- List<Backupable> backupable =
-
repositoryService.getRepository(this.repositoryEntry.getName()).getWorkspaceContainer(wEntry.getName())
- .getComponentInstancesOfType(Backupable.class);
-
- File fullBackupDir =
-
JCRRestor.getFullBackupFile(workspacesMapping.get(wEntry.getName()).getBackupConfig().getBackupDir());
-
- for (Backupable component : backupable)
- {
- if (component instanceof JdbcBackupable && jdbcConn != null)
- {
-
dataRestorer.add(((JdbcBackupable)component).getDataRestorer(fullBackupDir, jdbcConn));
- }
- else
- {
- dataRestorer.add(component.getDataRestorer(fullBackupDir));
- }
- }
- }
-
- for (DataRestor restorer : dataRestorer)
- {
- restorer.clean();
- }
-
- for (DataRestor restorer : dataRestorer)
- {
- restorer.restore();
- }
-
- for (DataRestor restorer : dataRestorer)
- {
- restorer.commit();
- }
-
- // resume components
- for (int i = 0; i < resumeComponents.size(); i++)
- {
- try
- {
- resumeComponents.remove(i).resume();
- }
- catch (ResumeException e)
- {
- log.error("Can't resume component", e);
- }
- }
-
- // incremental restore
- for (WorkspaceEntry wEntry : repositoryEntry.getWorkspaceEntries())
- {
-
repositoryService.getRepository(this.repositoryEntry.getName()).getWorkspaceContainer(wEntry.getName())
- .getComponentInstancesOfType(Backupable.class);
-
- DataManager dataManager =
-
(WorkspacePersistentDataManager)repositoryService.getRepository(this.repositoryEntry.getName())
-
.getWorkspaceContainer(wEntry.getName()).getComponent(WorkspacePersistentDataManager.class);
-
- FileCleanerHolder fileCleanHolder =
-
(FileCleanerHolder)repositoryService.getRepository(this.repositoryEntry.getName())
-
.getWorkspaceContainer(wEntry.getName()).getComponent(FileCleanerHolder.class);
-
- File storageDir =
-
JCRRestor.getFullBackupFile(workspacesMapping.get(wEntry.getName()).getBackupConfig().getBackupDir());
-
- JCRRestor restorer = new JCRRestor(dataManager,
fileCleanHolder.getFileCleaner());
- for (File incrBackupFile : JCRRestor.getIncrementalFiles(storageDir))
- {
- restorer.incrementalRestore(incrBackupFile);
- }
- }
- }
- catch (Throwable t)
- {
- // rollback
- for (DataRestor restorer : dataRestorer)
- {
- try
- {
- restorer.rollback();
- }
- catch (BackupException e)
- {
- log.error("Can't rollback changes", e);
- }
- }
-
- throw new RepositoryRestoreExeption("Repository " +
repositoryEntry.getName() + " was not restored", t);
- }
- finally
- {
- // close
- for (DataRestor restorer : dataRestorer)
- {
- try
- {
- restorer.close();
- }
- catch (BackupException e)
- {
- log.error("Can't close restorer", e);
- }
- }
-
- for (Suspendable component : resumeComponents)
- {
- try
- {
- component.resume();
- }
- catch (ResumeException e)
- {
- log.error("Can't resume component " + component.getClass(),
e);
- }
- }
- }
- }
-}
Deleted:
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 2011-03-28
12:10:43 UTC (rev 4179)
+++
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/JobExistedRepositoryRestore.java 2011-03-28
12:42:25 UTC (rev 4180)
@@ -1,159 +0,0 @@
-/*
- * 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.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.backup.Backupable;
-import org.exoplatform.services.jcr.impl.core.SessionRegistry;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
-import javax.jcr.RepositoryException;
-
-/**
- * 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
-{
-
- /**
- * JobExistedRepositoryRestore constructor.
- */
- public JobExistedRepositoryRestore(RepositoryService repoService, BackupManagerImpl
backupManagerImpl,
- RepositoryEntry repositoryEntry, Map<String, BackupChainLog>
workspacesMapping,
- RepositoryBackupChainLog backupChainLog)
- {
- super(repoService, backupManagerImpl, repositoryEntry, workspacesMapping,
backupChainLog);
- }
-
- @Override
- /**
- * {@inheritDoc}
- */
- protected void restoreRepository() throws RepositoryRestoreExeption
- {
- // list of components to clean
- List<Backupable> backupable = new ArrayList<Backupable>();
-
- try
- {
- // get current repository configuration
- RepositoryEntry repositoryEntry =
-
repositoryService.getConfig().getRepositoryConfiguration(this.repositoryEntry.getName());
-
- if (repositoryEntry == null)
- {
- throw new RepositoryRestoreExeption("Current repository configuration
" + this.repositoryEntry.getName()
- + " did not found");
- }
-
- boolean isDefault =
-
repositoryService.getDefaultRepository().getConfiguration().getName().equals(repositoryEntry.getName());
-
- String systemWsName =
-
repositoryService.getRepository(this.repositoryEntry.getName()).getConfiguration().getSystemWorkspaceName();
-
- //Create local copy of WorkspaceEntry for all workspaces
- ArrayList<WorkspaceEntry> workspaceList = new
ArrayList<WorkspaceEntry>();
- workspaceList.addAll(repositoryEntry.getWorkspaceEntries());
-
- // get all backupable components
- for (WorkspaceEntry wEntry : workspaceList)
- {
-
backupable.addAll(repositoryService.getRepository(this.repositoryEntry.getName())
-
.getWorkspaceContainer(wEntry.getName()).getComponentInstancesOfType(Backupable.class));
- }
-
- //close all session
- for (WorkspaceEntry wEntry : workspaceList)
- {
- forceCloseSession(repositoryEntry.getName(), wEntry.getName());
- }
-
- //remove repository
- if (isDefault)
- {
- ((RepositoryServiceImpl)repositoryService).removeDefaultRepository();
- }
- else
- {
- repositoryService.removeRepository(repositoryEntry.getName());
- }
-
- // clean
- for (Backupable component : backupable)
- {
- component.clean();
- }
-
- super.restoreRepository();
- }
- catch (Throwable t)
- {
- throw new RepositoryRestoreExeption("Repository " +
repositoryEntry.getName() + " was not restored", t);
- }
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected void removeRepository(RepositoryService repositoryService, String
repositoryName)
- throws RepositoryException, RepositoryConfigurationException
- {
- }
-
- /**
- * 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);
- }
-}
Deleted:
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/JobExistedWorkspaceRDBMSRestore.java
===================================================================
---
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/JobExistedWorkspaceRDBMSRestore.java 2011-03-28
12:10:43 UTC (rev 4179)
+++
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/JobExistedWorkspaceRDBMSRestore.java 2011-03-28
12:42:25 UTC (rev 4180)
@@ -1,190 +0,0 @@
-/*
- * 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.RepositoryService;
-import org.exoplatform.services.jcr.config.WorkspaceEntry;
-import org.exoplatform.services.jcr.dataflow.DataManager;
-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.backup.BackupException;
-import org.exoplatform.services.jcr.impl.backup.Backupable;
-import org.exoplatform.services.jcr.impl.backup.DataRestor;
-import org.exoplatform.services.jcr.impl.backup.JCRRestor;
-import org.exoplatform.services.jcr.impl.backup.ResumeException;
-import org.exoplatform.services.jcr.impl.backup.Suspendable;
-import
org.exoplatform.services.jcr.impl.dataflow.persistent.WorkspacePersistentDataManager;
-import org.exoplatform.services.jcr.impl.util.io.FileCleanerHolder;
-import org.exoplatform.services.log.ExoLogger;
-import org.exoplatform.services.log.Log;
-
-import java.io.File;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Created by The eXo Platform SAS.
- *
- * Date: 24 01 2011
- *
- * @author <a href="mailto:anatoliy.bazko@exoplatform.com.ua">Anatoliy
Bazko</a>
- * @version $Id: JobExistedWorkspaceRestoreSameConfig.java 34360 2010-11-11 11:11:11Z
tolusha $
- */
-public class JobExistedWorkspaceRDBMSRestore extends JobWorkspaceRestore
-{
- /**
- * The logger.
- */
- private static Log log =
ExoLogger.getLogger("exo.jcr.component.ext.JobExistedWorkspaceRDBMSRestore");
-
- /**
- * JobExistedWorkspaceRestore JobExistedWorkspaceRDBMSRestore.
- */
- public JobExistedWorkspaceRDBMSRestore(RepositoryService repositoryService,
BackupManager backupManager,
- String repositoryName, BackupChainLog log, WorkspaceEntry wEntry)
- {
- super(repositoryService, backupManager, repositoryName, log, wEntry);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected void restore() throws WorkspaceRestoreException
- {
- // list of data restorers
- List<DataRestor> dataRestorer = new ArrayList<DataRestor>();
-
- // the list of components to resume
- List<Suspendable> resumeComponents = new ArrayList<Suspendable>();
-
- try
- {
- // suspend all components
- List<Suspendable> suspendableComponents =
-
repositoryService.getRepository(repositoryName).getWorkspaceContainer(wEntry.getName())
- .getComponentInstancesOfType(Suspendable.class);
-
- for (Suspendable component : suspendableComponents)
- {
- component.suspend();
- resumeComponents.add(component);
- }
-
- // get all restorers
- List<Backupable> backupable =
-
repositoryService.getRepository(repositoryName).getWorkspaceContainer(wEntry.getName())
- .getComponentInstancesOfType(Backupable.class);
-
- File storageDir = backupChainLog.getBackupConfig().getBackupDir();
-
- for (Backupable component : backupable)
- {
- File fullBackupDir = JCRRestor.getFullBackupFile(storageDir);
- dataRestorer.add(component.getDataRestorer(fullBackupDir));
- }
-
- for (DataRestor restorer : dataRestorer)
- {
- restorer.clean();
- }
-
- for (DataRestor restorer : dataRestorer)
- {
- restorer.restore();
- }
-
- for (DataRestor restorer : dataRestorer)
- {
- restorer.commit();
- }
-
- // resume components
- for (int i = 0; i < resumeComponents.size(); i++)
- {
- try
- {
- resumeComponents.remove(i).resume();
- }
- catch (ResumeException e)
- {
- log.error("Can't resume component", e);
- }
- }
-
- // incremental restore
- DataManager dataManager =
-
(WorkspacePersistentDataManager)repositoryService.getRepository(repositoryName)
-
.getWorkspaceContainer(wEntry.getName()).getComponent(WorkspacePersistentDataManager.class);
-
- FileCleanerHolder fileCleanHolder =
-
(FileCleanerHolder)repositoryService.getRepository(repositoryName).getWorkspaceContainer(wEntry.getName())
- .getComponent(FileCleanerHolder.class);
-
- JCRRestor restorer = new JCRRestor(dataManager,
fileCleanHolder.getFileCleaner());
- for (File incrBackupFile : JCRRestor.getIncrementalFiles(storageDir))
- {
- restorer.incrementalRestore(incrBackupFile);
- }
- }
- catch (Throwable t)
- {
- // rollback
- for (DataRestor restorer : dataRestorer)
- {
- try
- {
- restorer.rollback();
- }
- catch (BackupException e)
- {
- log.error("Can't rollback changes", e);
- }
- }
-
- throw new WorkspaceRestoreException("Workspace " + wEntry.getName() +
" was not restored", t);
- }
- finally
- {
- // close
- for (DataRestor restorer : dataRestorer)
- {
- try
- {
- restorer.close();
- }
- catch (BackupException e)
- {
- log.error("Can't close restorer", e);
- }
- }
-
- for (Suspendable component : resumeComponents)
- {
- try
- {
- component.resume();
- }
- catch (ResumeException e)
- {
- log.error("Can't resume component", e);
- }
- }
- }
- }
-}
Deleted:
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 2011-03-28
12:10:43 UTC (rev 4179)
+++
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/JobExistedWorkspaceRestore.java 2011-03-28
12:42:25 UTC (rev 4180)
@@ -1,141 +0,0 @@
-/*
- * 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.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.backup.Backupable;
-import org.exoplatform.services.jcr.impl.core.SessionRegistry;
-import org.exoplatform.services.log.ExoLogger;
-import org.exoplatform.services.log.Log;
-
-import java.util.List;
-
-import javax.jcr.RepositoryException;
-
-/**
- * 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
-{
- /**
- * The logger.
- */
- private static Log log =
ExoLogger.getLogger("exo.jcr.component.ext.JobExistedWorkspaceRestore");
-
- /**
- * JobExistedWorkspaceRestore constructor.
- */
- public JobExistedWorkspaceRestore(RepositoryService repositoryService, BackupManager
backupManager,
- String repositoryName, BackupChainLog log, WorkspaceEntry wEntry)
- {
- super(repositoryService, backupManager, repositoryName, log, wEntry);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected void restore() throws WorkspaceRestoreException
- {
- try
- {
- // get current workspace configuration
- WorkspaceEntry wEntry = null;;
- for (WorkspaceEntry entry :
repositoryService.getRepository(repositoryName).getConfiguration()
- .getWorkspaceEntries())
- {
- if (entry.getName().equals(this.wEntry.getName()))
- {
- wEntry = entry;
- break;
- }
- }
-
- if (wEntry == null)
- {
- throw new WorkspaceRestoreException("Workspace " +
this.wEntry.getName()
- + " did not found in current repository " + repositoryName +
" configuration");
- }
-
- // get all backupable components
- List<Backupable> backupable =
-
repositoryService.getRepository(repositoryName).getWorkspaceContainer(wEntry.getName())
- .getComponentInstancesOfType(Backupable.class);
-
- // close all session
- forceCloseSession(repositoryName, wEntry.getName());
-
-
repositoryService.getRepository(repositoryName).removeWorkspace(wEntry.getName());
-
- // clean
- for (Backupable component : backupable)
- {
- component.clean();
- }
-
- super.restore();
- }
- catch (Throwable t)
- {
- throw new WorkspaceRestoreException("Workspace " + wEntry.getName() +
" was not restored", t);
- }
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected void removeWorkspace(ManageableRepository mr, String workspaceName) throws
RepositoryException
- {
- }
-
- /**
- * 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);
- }
-}
Copied:
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/JobExistingRepositoryRestore.java
(from rev 4178,
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/JobExistingRepositoryRestore.java
(rev 0)
+++
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/JobExistingRepositoryRestore.java 2011-03-28
12:42:25 UTC (rev 4180)
@@ -0,0 +1,159 @@
+/*
+ * 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.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.backup.Backupable;
+import org.exoplatform.services.jcr.impl.core.SessionRegistry;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import javax.jcr.RepositoryException;
+
+/**
+ * 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 JobExistingRepositoryRestore extends JobRepositoryRestore
+{
+
+ /**
+ * JobExistingRepositoryRestore constructor.
+ */
+ public JobExistingRepositoryRestore(RepositoryService repoService, BackupManagerImpl
backupManagerImpl,
+ RepositoryEntry repositoryEntry, Map<String, BackupChainLog>
workspacesMapping,
+ RepositoryBackupChainLog backupChainLog)
+ {
+ super(repoService, backupManagerImpl, repositoryEntry, workspacesMapping,
backupChainLog);
+ }
+
+ @Override
+ /**
+ * {@inheritDoc}
+ */
+ protected void restoreRepository() throws RepositoryRestoreExeption
+ {
+ // list of components to clean
+ List<Backupable> backupable = new ArrayList<Backupable>();
+
+ try
+ {
+ // get current repository configuration
+ RepositoryEntry repositoryEntry =
+
repositoryService.getConfig().getRepositoryConfiguration(this.repositoryEntry.getName());
+
+ if (repositoryEntry == null)
+ {
+ throw new RepositoryRestoreExeption("Current repository configuration
" + this.repositoryEntry.getName()
+ + " did not found");
+ }
+
+ boolean isDefault =
+
repositoryService.getDefaultRepository().getConfiguration().getName().equals(repositoryEntry.getName());
+
+ String systemWsName =
+
repositoryService.getRepository(this.repositoryEntry.getName()).getConfiguration().getSystemWorkspaceName();
+
+ //Create local copy of WorkspaceEntry for all workspaces
+ ArrayList<WorkspaceEntry> workspaceList = new
ArrayList<WorkspaceEntry>();
+ workspaceList.addAll(repositoryEntry.getWorkspaceEntries());
+
+ // get all backupable components
+ for (WorkspaceEntry wEntry : workspaceList)
+ {
+
backupable.addAll(repositoryService.getRepository(this.repositoryEntry.getName())
+
.getWorkspaceContainer(wEntry.getName()).getComponentInstancesOfType(Backupable.class));
+ }
+
+ //close all session
+ for (WorkspaceEntry wEntry : workspaceList)
+ {
+ forceCloseSession(repositoryEntry.getName(), wEntry.getName());
+ }
+
+ //remove repository
+ if (isDefault)
+ {
+ ((RepositoryServiceImpl)repositoryService).removeDefaultRepository();
+ }
+ else
+ {
+ repositoryService.removeRepository(repositoryEntry.getName());
+ }
+
+ // clean
+ for (Backupable component : backupable)
+ {
+ component.clean();
+ }
+
+ super.restoreRepository();
+ }
+ catch (Throwable t)
+ {
+ throw new RepositoryRestoreExeption("Repository " +
repositoryEntry.getName() + " was not restored", t);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected void removeRepository(RepositoryService repositoryService, String
repositoryName)
+ throws RepositoryException, RepositoryConfigurationException
+ {
+ }
+
+ /**
+ * 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/JobExistingRepositoryRestore.java
___________________________________________________________________
Added: svn:keywords
+ Id
Added: svn:eol-style
+ native
Copied:
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/JobExistingRepositorySameConfigRestore.java
(from rev 4178,
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/JobExistedRepositoryRDBMSRestore.java)
===================================================================
---
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/JobExistingRepositorySameConfigRestore.java
(rev 0)
+++
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/JobExistingRepositorySameConfigRestore.java 2011-03-28
12:42:25 UTC (rev 4180)
@@ -0,0 +1,244 @@
+/*
+ * 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.commons.utils.SecurityHelper;
+import org.exoplatform.services.jcr.RepositoryService;
+import org.exoplatform.services.jcr.config.RepositoryEntry;
+import org.exoplatform.services.jcr.config.WorkspaceEntry;
+import org.exoplatform.services.jcr.dataflow.DataManager;
+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.backup.BackupException;
+import org.exoplatform.services.jcr.impl.backup.Backupable;
+import org.exoplatform.services.jcr.impl.backup.DataRestor;
+import org.exoplatform.services.jcr.impl.backup.JCRRestor;
+import org.exoplatform.services.jcr.impl.backup.JdbcBackupable;
+import org.exoplatform.services.jcr.impl.backup.ResumeException;
+import org.exoplatform.services.jcr.impl.backup.Suspendable;
+import
org.exoplatform.services.jcr.impl.dataflow.persistent.WorkspacePersistentDataManager;
+import org.exoplatform.services.jcr.impl.storage.jdbc.JDBCWorkspaceDataContainer;
+import org.exoplatform.services.jcr.impl.util.io.FileCleanerHolder;
+
+import java.io.File;
+import java.security.PrivilegedExceptionAction;
+import java.sql.Connection;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import javax.naming.InitialContext;
+import javax.naming.NameNotFoundException;
+import javax.sql.DataSource;
+
+/**
+ * Created by The eXo Platform SAS.
+ *
+ * Date: 24 01 2011
+ *
+ * @author <a href="mailto:anatoliy.bazko@exoplatform.com.ua">Anatoliy
Bazko</a>
+ * @version $Id: JobExistingRepositorySameConfigRestore.java 34360 2010-11-11 11:11:11Z
tolusha $
+ */
+public class JobExistingRepositorySameConfigRestore extends JobRepositoryRestore
+{
+
+ /**
+ * JobExistingRepositorySameConfigRestore constructor.
+ */
+ public JobExistingRepositorySameConfigRestore(RepositoryService repoService,
BackupManagerImpl backupManagerImpl,
+ RepositoryEntry repositoryEntry, Map<String, BackupChainLog>
workspacesMapping,
+ RepositoryBackupChainLog backupChainLog)
+ {
+ super(repoService, backupManagerImpl, repositoryEntry, workspacesMapping,
backupChainLog);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected void restoreRepository() throws RepositoryRestoreExeption
+ {
+ // list of data restorers
+ List<DataRestor> dataRestorer = new ArrayList<DataRestor>();
+
+ // the list of components to resume
+ List<Suspendable> resumeComponents = new ArrayList<Suspendable>();
+
+ try
+ {
+ WorkspaceEntry wsEntry = repositoryEntry.getWorkspaceEntries().get(0);
+
+ // define one common connection for all restores and cleaners for single db
case
+ Connection jdbcConn = null;
+ if
(!Boolean.parseBoolean(wsEntry.getContainer().getParameterValue(JDBCWorkspaceDataContainer.MULTIDB)))
+ {
+ String dsName =
wsEntry.getContainer().getParameterValue(JDBCWorkspaceDataContainer.SOURCE_NAME);
+
+ final DataSource ds = (DataSource)new InitialContext().lookup(dsName);
+ if (ds == null)
+ {
+ throw new NameNotFoundException("Data source " + dsName + "
not found");
+ }
+
+ jdbcConn = SecurityHelper.doPrivilegedSQLExceptionAction(new
PrivilegedExceptionAction<Connection>()
+ {
+ public Connection run() throws Exception
+ {
+ return ds.getConnection();
+
+ }
+ });
+ jdbcConn.setAutoCommit(false);
+ }
+
+ // suspend all components
+ for (WorkspaceEntry wEntry : repositoryEntry.getWorkspaceEntries())
+ {
+ List<Suspendable> suspendableComponents =
+
repositoryService.getRepository(this.repositoryEntry.getName()).getWorkspaceContainer(wEntry.getName())
+ .getComponentInstancesOfType(Suspendable.class);
+
+ for (Suspendable component : suspendableComponents)
+ {
+ component.suspend();
+ resumeComponents.add(component);
+ }
+ }
+
+ // collect all restorers
+ for (WorkspaceEntry wEntry : repositoryEntry.getWorkspaceEntries())
+ {
+ // get all backupable components
+ List<Backupable> backupable =
+
repositoryService.getRepository(this.repositoryEntry.getName()).getWorkspaceContainer(wEntry.getName())
+ .getComponentInstancesOfType(Backupable.class);
+
+ File fullBackupDir =
+
JCRRestor.getFullBackupFile(workspacesMapping.get(wEntry.getName()).getBackupConfig().getBackupDir());
+
+ for (Backupable component : backupable)
+ {
+ if (component instanceof JdbcBackupable && jdbcConn != null)
+ {
+
dataRestorer.add(((JdbcBackupable)component).getDataRestorer(fullBackupDir, jdbcConn));
+ }
+ else
+ {
+ dataRestorer.add(component.getDataRestorer(fullBackupDir));
+ }
+ }
+ }
+
+ for (DataRestor restorer : dataRestorer)
+ {
+ restorer.clean();
+ }
+
+ for (DataRestor restorer : dataRestorer)
+ {
+ restorer.restore();
+ }
+
+ for (DataRestor restorer : dataRestorer)
+ {
+ restorer.commit();
+ }
+
+ // resume components
+ for (int i = 0; i < resumeComponents.size(); i++)
+ {
+ try
+ {
+ resumeComponents.remove(i).resume();
+ }
+ catch (ResumeException e)
+ {
+ log.error("Can't resume component", e);
+ }
+ }
+
+ // incremental restore
+ for (WorkspaceEntry wEntry : repositoryEntry.getWorkspaceEntries())
+ {
+
repositoryService.getRepository(this.repositoryEntry.getName()).getWorkspaceContainer(wEntry.getName())
+ .getComponentInstancesOfType(Backupable.class);
+
+ DataManager dataManager =
+
(WorkspacePersistentDataManager)repositoryService.getRepository(this.repositoryEntry.getName())
+
.getWorkspaceContainer(wEntry.getName()).getComponent(WorkspacePersistentDataManager.class);
+
+ FileCleanerHolder fileCleanHolder =
+
(FileCleanerHolder)repositoryService.getRepository(this.repositoryEntry.getName())
+
.getWorkspaceContainer(wEntry.getName()).getComponent(FileCleanerHolder.class);
+
+ File storageDir =
+
JCRRestor.getFullBackupFile(workspacesMapping.get(wEntry.getName()).getBackupConfig().getBackupDir());
+
+ JCRRestor restorer = new JCRRestor(dataManager,
fileCleanHolder.getFileCleaner());
+ for (File incrBackupFile : JCRRestor.getIncrementalFiles(storageDir))
+ {
+ restorer.incrementalRestore(incrBackupFile);
+ }
+ }
+ }
+ catch (Throwable t)
+ {
+ // rollback
+ for (DataRestor restorer : dataRestorer)
+ {
+ try
+ {
+ restorer.rollback();
+ }
+ catch (BackupException e)
+ {
+ log.error("Can't rollback changes", e);
+ }
+ }
+
+ throw new RepositoryRestoreExeption("Repository " +
repositoryEntry.getName() + " was not restored", t);
+ }
+ finally
+ {
+ // close
+ for (DataRestor restorer : dataRestorer)
+ {
+ try
+ {
+ restorer.close();
+ }
+ catch (BackupException e)
+ {
+ log.error("Can't close restorer", e);
+ }
+ }
+
+ for (Suspendable component : resumeComponents)
+ {
+ try
+ {
+ component.resume();
+ }
+ catch (ResumeException e)
+ {
+ log.error("Can't resume component " + component.getClass(),
e);
+ }
+ }
+ }
+ }
+}
Copied:
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/JobExistingWorkspaceRestore.java
(from rev 4178,
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/JobExistingWorkspaceRestore.java
(rev 0)
+++
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/JobExistingWorkspaceRestore.java 2011-03-28
12:42:25 UTC (rev 4180)
@@ -0,0 +1,141 @@
+/*
+ * 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.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.backup.Backupable;
+import org.exoplatform.services.jcr.impl.core.SessionRegistry;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+
+import java.util.List;
+
+import javax.jcr.RepositoryException;
+
+/**
+ * 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 JobExistingWorkspaceRestore extends JobWorkspaceRestore
+{
+ /**
+ * The logger.
+ */
+ private static Log log =
ExoLogger.getLogger("exo.jcr.component.ext.JobExistedWorkspaceRestore");
+
+ /**
+ * JobExistingWorkspaceRestore constructor.
+ */
+ public JobExistingWorkspaceRestore(RepositoryService repositoryService, BackupManager
backupManager,
+ String repositoryName, BackupChainLog log, WorkspaceEntry wEntry)
+ {
+ super(repositoryService, backupManager, repositoryName, log, wEntry);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected void restore() throws WorkspaceRestoreException
+ {
+ try
+ {
+ // get current workspace configuration
+ WorkspaceEntry wEntry = null;;
+ for (WorkspaceEntry entry :
repositoryService.getRepository(repositoryName).getConfiguration()
+ .getWorkspaceEntries())
+ {
+ if (entry.getName().equals(this.wEntry.getName()))
+ {
+ wEntry = entry;
+ break;
+ }
+ }
+
+ if (wEntry == null)
+ {
+ throw new WorkspaceRestoreException("Workspace " +
this.wEntry.getName()
+ + " did not found in current repository " + repositoryName +
" configuration");
+ }
+
+ // get all backupable components
+ List<Backupable> backupable =
+
repositoryService.getRepository(repositoryName).getWorkspaceContainer(wEntry.getName())
+ .getComponentInstancesOfType(Backupable.class);
+
+ // close all session
+ forceCloseSession(repositoryName, wEntry.getName());
+
+
repositoryService.getRepository(repositoryName).removeWorkspace(wEntry.getName());
+
+ // clean
+ for (Backupable component : backupable)
+ {
+ component.clean();
+ }
+
+ super.restore();
+ }
+ catch (Throwable t)
+ {
+ throw new WorkspaceRestoreException("Workspace " + wEntry.getName() +
" was not restored", t);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected void removeWorkspace(ManageableRepository mr, String workspaceName) throws
RepositoryException
+ {
+ }
+
+ /**
+ * 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/JobExistingWorkspaceRestore.java
___________________________________________________________________
Added: svn:keywords
+ Id
Added: svn:eol-style
+ native
Copied:
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/JobExistingWorkspaceSameConfigRestore.java
(from rev 4178,
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/JobExistedWorkspaceRDBMSRestore.java)
===================================================================
---
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/JobExistingWorkspaceSameConfigRestore.java
(rev 0)
+++
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/JobExistingWorkspaceSameConfigRestore.java 2011-03-28
12:42:25 UTC (rev 4180)
@@ -0,0 +1,190 @@
+/*
+ * 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.RepositoryService;
+import org.exoplatform.services.jcr.config.WorkspaceEntry;
+import org.exoplatform.services.jcr.dataflow.DataManager;
+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.backup.BackupException;
+import org.exoplatform.services.jcr.impl.backup.Backupable;
+import org.exoplatform.services.jcr.impl.backup.DataRestor;
+import org.exoplatform.services.jcr.impl.backup.JCRRestor;
+import org.exoplatform.services.jcr.impl.backup.ResumeException;
+import org.exoplatform.services.jcr.impl.backup.Suspendable;
+import
org.exoplatform.services.jcr.impl.dataflow.persistent.WorkspacePersistentDataManager;
+import org.exoplatform.services.jcr.impl.util.io.FileCleanerHolder;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Created by The eXo Platform SAS.
+ *
+ * Date: 24 01 2011
+ *
+ * @author <a href="mailto:anatoliy.bazko@exoplatform.com.ua">Anatoliy
Bazko</a>
+ * @version $Id: JobExistingWorkspaceSameConfigRestore.java 34360 2010-11-11 11:11:11Z
tolusha $
+ */
+public class JobExistingWorkspaceSameConfigRestore extends JobWorkspaceRestore
+{
+ /**
+ * The logger.
+ */
+ private static Log log =
ExoLogger.getLogger("exo.jcr.component.ext.JobExistingWorkspaceSameConfigRestore");
+
+ /**
+ * JobExistingWorkspaceSameConfigRestore constructor.
+ */
+ public JobExistingWorkspaceSameConfigRestore(RepositoryService repositoryService,
BackupManager backupManager,
+ String repositoryName, BackupChainLog log, WorkspaceEntry wEntry)
+ {
+ super(repositoryService, backupManager, repositoryName, log, wEntry);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected void restore() throws WorkspaceRestoreException
+ {
+ // list of data restorers
+ List<DataRestor> dataRestorer = new ArrayList<DataRestor>();
+
+ // the list of components to resume
+ List<Suspendable> resumeComponents = new ArrayList<Suspendable>();
+
+ try
+ {
+ // suspend all components
+ List<Suspendable> suspendableComponents =
+
repositoryService.getRepository(repositoryName).getWorkspaceContainer(wEntry.getName())
+ .getComponentInstancesOfType(Suspendable.class);
+
+ for (Suspendable component : suspendableComponents)
+ {
+ component.suspend();
+ resumeComponents.add(component);
+ }
+
+ // get all restorers
+ List<Backupable> backupable =
+
repositoryService.getRepository(repositoryName).getWorkspaceContainer(wEntry.getName())
+ .getComponentInstancesOfType(Backupable.class);
+
+ File storageDir = backupChainLog.getBackupConfig().getBackupDir();
+
+ for (Backupable component : backupable)
+ {
+ File fullBackupDir = JCRRestor.getFullBackupFile(storageDir);
+ dataRestorer.add(component.getDataRestorer(fullBackupDir));
+ }
+
+ for (DataRestor restorer : dataRestorer)
+ {
+ restorer.clean();
+ }
+
+ for (DataRestor restorer : dataRestorer)
+ {
+ restorer.restore();
+ }
+
+ for (DataRestor restorer : dataRestorer)
+ {
+ restorer.commit();
+ }
+
+ // resume components
+ for (int i = 0; i < resumeComponents.size(); i++)
+ {
+ try
+ {
+ resumeComponents.remove(i).resume();
+ }
+ catch (ResumeException e)
+ {
+ log.error("Can't resume component", e);
+ }
+ }
+
+ // incremental restore
+ DataManager dataManager =
+
(WorkspacePersistentDataManager)repositoryService.getRepository(repositoryName)
+
.getWorkspaceContainer(wEntry.getName()).getComponent(WorkspacePersistentDataManager.class);
+
+ FileCleanerHolder fileCleanHolder =
+
(FileCleanerHolder)repositoryService.getRepository(repositoryName).getWorkspaceContainer(wEntry.getName())
+ .getComponent(FileCleanerHolder.class);
+
+ JCRRestor restorer = new JCRRestor(dataManager,
fileCleanHolder.getFileCleaner());
+ for (File incrBackupFile : JCRRestor.getIncrementalFiles(storageDir))
+ {
+ restorer.incrementalRestore(incrBackupFile);
+ }
+ }
+ catch (Throwable t)
+ {
+ // rollback
+ for (DataRestor restorer : dataRestorer)
+ {
+ try
+ {
+ restorer.rollback();
+ }
+ catch (BackupException e)
+ {
+ log.error("Can't rollback changes", e);
+ }
+ }
+
+ throw new WorkspaceRestoreException("Workspace " + wEntry.getName() +
" was not restored", t);
+ }
+ finally
+ {
+ // close
+ for (DataRestor restorer : dataRestorer)
+ {
+ try
+ {
+ restorer.close();
+ }
+ catch (BackupException e)
+ {
+ log.error("Can't close restorer", e);
+ }
+ }
+
+ for (Suspendable component : resumeComponents)
+ {
+ try
+ {
+ component.resume();
+ }
+ catch (ResumeException e)
+ {
+ log.error("Can't resume component", e);
+ }
+ }
+ }
+ }
+}