exo-jcr SVN: r2117 - jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/fs.
by do-not-reply@jboss.org
Author: areshetnyak
Date: 2010-03-25 07:12:26 -0400 (Thu, 25 Mar 2010)
New Revision: 2117
Modified:
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/fs/FileNameProducer.java
Log:
EXOJCR-549 : The implementation backup/restore whole repository.
Modified: jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/fs/FileNameProducer.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/fs/FileNameProducer.java 2010-03-25 11:03:40 UTC (rev 2116)
+++ jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/fs/FileNameProducer.java 2010-03-25 11:12:26 UTC (rev 2117)
@@ -110,11 +110,10 @@
for (int i = 0; i < fileList.length; i++)
{
-
String[] stringArray = fileList[i].split("[.]");
+
+ int currentSufix = Integer.valueOf(stringArray[stringArray.length - 1]).intValue();
- int currentSufix = Integer.valueOf(stringArray[1]).intValue();
-
if (currentSufix > sufix)
sufix = currentSufix;
}
16 years, 1 month
exo-jcr SVN: r2116 - in jcr/trunk/docs/reference/en/src/main/docbook/en-US/modules: kernel and 1 other directory.
by do-not-reply@jboss.org
Author: pnedonosko
Date: 2010-03-25 07:03:40 -0400 (Thu, 25 Mar 2010)
New Revision: 2116
Modified:
jcr/trunk/docs/reference/en/src/main/docbook/en-US/modules/core/db-creator-service.xml
jcr/trunk/docs/reference/en/src/main/docbook/en-US/modules/kernel/jndi-naming.xml
Log:
EXOJCR-573: DBCreator docs cleanup
Modified: jcr/trunk/docs/reference/en/src/main/docbook/en-US/modules/core/db-creator-service.xml
===================================================================
--- jcr/trunk/docs/reference/en/src/main/docbook/en-US/modules/core/db-creator-service.xml 2010-03-25 10:56:01 UTC (rev 2115)
+++ jcr/trunk/docs/reference/en/src/main/docbook/en-US/modules/core/db-creator-service.xml 2010-03-25 11:03:40 UTC (rev 2116)
@@ -9,23 +9,24 @@
<section>
<title>About</title>
- <para>Database Creator is responsible for execution DDL script at runtime.
- A DDL script may contain templates for database name, user name and
- password which will be replaced by real values at execution time.</para>
+ <para>Database creator<envar> DBCreator</envar> is responsible for
+ execution DDL script in runtime. A DDL script may contain templates for
+ database name, user name and password which will be replaced by real
+ values at execution time.</para>
- <para>Supports 3 templates:</para>
+ <para>Three templates supported:</para>
<itemizedlist>
<listitem>
- <para>${database} for database name;</para>
+ <para><envar>${database}</envar> for database name;</para>
</listitem>
<listitem>
- <para>${username} for user name;</para>
+ <para><envar>${username}</envar> for user name;</para>
</listitem>
<listitem>
- <para>${password} for user's password;</para>
+ <para><envar>${password}</envar> for user's password;</para>
</listitem>
</itemizedlist>
</section>
@@ -35,12 +36,13 @@
<para>Service provide method for execute script for new database creation.
Database name which are passed as parameter will be substituted in DDL
- script instead of ${database} template. Returns DBConnectionInfo object
- (with all neccesary information of new database's connection) or throws
- DBScriptExecutorException exception if any errors occurs in other
- case.</para>
+ script instead of <envar>${database}</envar> template. Returns
+ <envar>DBConnectionInfo</envar> object (with all neccesary information of
+ new database's connection) or throws <envar>DBCreatorException</envar>
+ exception if any errors occurs in other case.</para>
- <programlisting>public DBConnectionInfo createDatabase(String dbName) throws DBCreatorException;</programlisting>
+ <programlisting>
+public DBConnectionInfo createDatabase(String dbName) throws DBCreatorException;</programlisting>
<para>For MSSQL and Sybase servers uses autocommit mode set true for
connection. It's due to after execution "create database" command newly
@@ -53,7 +55,7 @@
<para>Service's configuration.</para>
- <programlisting><component>
+ <programlisting> <component>
<key>org.exoplatform.services.database.creator.DBCreator</key>
<type>org.exoplatform.services.database.creator.DBCreator</type>
<init-params>
@@ -75,30 +77,31 @@
</init-params>
</component></programlisting>
- <para>db-connection properties section contains parameters needed for
- connection to database server</para>
+ <para><envar>db-connection</envar> properties section contains parameters
+ needed for connection to database server</para>
- <para>db-creation properties section contains paramaters for database
- creation using DDL script:</para>
+ <para><envar>db-creation</envar> properties section contains paramaters
+ for database creation using DDL script:</para>
<itemizedlist>
<listitem>
- <para>scriptPath: absolute path to DDL script file;</para>
+ <para><envar>scriptPath</envar> absolute path to DDL script
+ file;</para>
</listitem>
<listitem>
- <para>username: user name for substitution ${username} template in DDL
- script;</para>
+ <para><envar>username</envar> user name for substitution
+ <envar>${username}</envar> template in DDL script;</para>
</listitem>
<listitem>
- <para>password: user's password for substitution ${password} template
- in DDL script;</para>
+ <para><envar>password</envar> user's password for substitution
+ <envar>${password}</envar> template in DDL script;</para>
</listitem>
</itemizedlist>
- <para>Specific db-connection properties section for different
- databases.</para>
+ <para>Specific <envar>db-connection</envar> properties section for
+ different databases.</para>
<para>MySQL:</para>
Modified: jcr/trunk/docs/reference/en/src/main/docbook/en-US/modules/kernel/jndi-naming.xml
===================================================================
--- jcr/trunk/docs/reference/en/src/main/docbook/en-US/modules/kernel/jndi-naming.xml 2010-03-25 10:56:01 UTC (rev 2115)
+++ jcr/trunk/docs/reference/en/src/main/docbook/en-US/modules/kernel/jndi-naming.xml 2010-03-25 11:03:40 UTC (rev 2116)
@@ -134,8 +134,8 @@
</init-params>
</component></programlisting></para>
- <para>The BindReferencePlugin component plugin configuration example (for
- JDBC datasource):</para>
+ <para>The <envar>BindReferencePlugin</envar> component plugin
+ configuration example (for JDBC datasource):</para>
<para><programlisting> <component-plugins>
<component-plugin>
16 years, 1 month
exo-jcr SVN: r2115 - in jcr/trunk/docs/reference/en/src/main/docbook/en-US/modules: kernel and 1 other directory.
by do-not-reply@jboss.org
Author: pnedonosko
Date: 2010-03-25 06:56:01 -0400 (Thu, 25 Mar 2010)
New Revision: 2115
Added:
jcr/trunk/docs/reference/en/src/main/docbook/en-US/modules/kernel/jndi-naming.xml
Removed:
jcr/trunk/docs/reference/en/src/main/docbook/en-US/modules/kernel/initial-context-binder-service.xml
Modified:
jcr/trunk/docs/reference/en/src/main/docbook/en-US/modules/kernel.xml
Log:
EXOJCR-573: docs about DataSources binding in runtime
Deleted: jcr/trunk/docs/reference/en/src/main/docbook/en-US/modules/kernel/initial-context-binder-service.xml
===================================================================
--- jcr/trunk/docs/reference/en/src/main/docbook/en-US/modules/kernel/initial-context-binder-service.xml 2010-03-25 10:52:28 UTC (rev 2114)
+++ jcr/trunk/docs/reference/en/src/main/docbook/en-US/modules/kernel/initial-context-binder-service.xml 2010-03-25 10:56:01 UTC (rev 2115)
@@ -1,60 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
-"http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
-<chapter>
- <?dbhtml filename="ch-initial-context-binder-service.html"?>
-
- <title>Initial Context Binder</title>
-
- <section>
- <title>About</title>
-
- <para>Initial Context Binder is responsible for binding references at
- runtime, persisting in file and automatically rebinding after restart.
- Java temp directory is used to persist references in bind-references.xml
- file.</para>
- </section>
-
- <section>
- <title>API</title>
-
- <para>Service provide methods for binding reference.</para>
-
- <programlisting>public void bind(String bindName, String className, String factory, String factoryLocation, Map<String, String> refAddr) throws NamingException, FileNotFoundException, XMLStreamException;</programlisting>
-
- <itemizedlist>
- <listitem>
- <para>bindName - name of binding</para>
- </listitem>
-
- <listitem>
- <para>className - the fully-qualified name of the class of the object
- to which this Reference refers</para>
- </listitem>
-
- <listitem>
- <para>factory - the name of the factory class for creating an instance
- of the object to which this Reference refers</para>
- </listitem>
-
- <listitem>
- <para>factoryLocation - the location of the factory class</para>
- </listitem>
-
- <listitem>
- <para>refAddr - object's properties map</para>
- </listitem>
- </itemizedlist>
- </section>
-
- <section>
- <title>A configuration examples</title>
-
- <para>Service's configuration.</para>
-
- <programlisting><component>
- <key>org.exoplatform.services.naming.InitialContextBinder</key>
- <type>org.exoplatform.services.naming.InitialContextBinder</type>
-</component></programlisting>
- </section>
-</chapter>
Added: jcr/trunk/docs/reference/en/src/main/docbook/en-US/modules/kernel/jndi-naming.xml
===================================================================
--- jcr/trunk/docs/reference/en/src/main/docbook/en-US/modules/kernel/jndi-naming.xml (rev 0)
+++ jcr/trunk/docs/reference/en/src/main/docbook/en-US/modules/kernel/jndi-naming.xml 2010-03-25 10:56:01 UTC (rev 2115)
@@ -0,0 +1,248 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
+"http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
+<chapter>
+ <?dbhtml filename="ch-jndi-naming.html"?>
+
+ <title>JNDI naming</title>
+
+ <section>
+ <title>Prerequisites</title>
+
+ <para>We need to configure JNDI environment properties and Reference
+ binding with the eXo container standard mechanism.</para>
+
+ <para>The Naming service covers:</para>
+
+ <para><itemizedlist>
+ <listitem>
+ <para>Configuring the current Naming Context Factory implemented as
+ an ExoContainer Component
+ <envar>org.exoplatform.services.naming.InitialContextInitializer</envar>.</para>
+ </listitem>
+
+ <listitem>
+ <para>Binding Objects (References) to the current Context using
+ <envar>org.exoplatform.services.naming.BindReferencePlugin</envar>
+ component plugin.</para>
+ </listitem>
+ </itemizedlist></para>
+ </section>
+
+ <section>
+ <title>How it works</title>
+
+ <para>Make sure you understand the <ulink
+ url="http://java.sun.com/products/jndi/1.2/javadoc/index.html">Java Naming
+ and Directory InterfaceTM (JNDI)</ulink> concepts before using this
+ service.</para>
+
+ <section>
+ <title>JNDI System property initialization</title>
+
+ <para>After the start time the Context Initializer
+ (org.exoplatform.services.naming.InitialContextInitializer) traverses
+ all initial parameters (that concern the Naming Context) configured in
+ <envar>default-properties</envar> and
+ <envar>mandatory-properties</envar> (see Configuration examples)
+ and:</para>
+
+ <itemizedlist>
+ <listitem>
+ <para>for <envar>default-properties</envar> checks if this property
+ is already set as a System property
+ (<envar>System.getProperty(name)</envar>) and sets this property if
+ it's not found. Using those properties is recommended with a third
+ party Naming service provider</para>
+ </listitem>
+
+ <listitem>
+ <para>for <envar>mandatory-properties</envar> it just sets the
+ property without checking</para>
+ </listitem>
+ </itemizedlist>
+
+ <para>Standard JNDI properties:</para>
+
+ <itemizedlist>
+ <listitem>
+ <para><envar>java.naming.factory.initial</envar></para>
+ </listitem>
+
+ <listitem>
+ <para><envar>java.naming.provider.url</envar></para>
+ </listitem>
+ </itemizedlist>
+
+ <para>and others (see JNDI docs)</para>
+ </section>
+
+ <section>
+ <title>JNDI reference binding</title>
+
+ <para>Another responsibility of Context Initializer
+ <envar>org.exoplatform.services.naming.InitialContextInitializer</envar>
+ is binding of preconfigured references to the naming context. For this
+ purpose it uses a standard eXo component plugin mechanism and in
+ particular the
+ <envar>org.exoplatform.services.naming.BindReferencePlugin</envar>
+ component plugin. The configuration of this plugin includes three
+ mandatory value parameters:</para>
+
+ <itemizedlist>
+ <listitem>
+ <para><envar>bind-name</envar> - the name of binding
+ reference</para>
+ </listitem>
+
+ <listitem>
+ <para><envar>class-name</envar> - the type of binding
+ reference</para>
+ </listitem>
+
+ <listitem>
+ <para><envar>factory</envar> - the object factory type</para>
+ </listitem>
+ </itemizedlist>
+
+ <para>And also <envar>ref-addresses</envar> property parameter with a
+ set of references' properties. (see Configuration examples) Context
+ Initializer uses those parameters to bind the neccessary reference
+ automatically.</para>
+ </section>
+ </section>
+
+ <section>
+ <title>Configuration examples</title>
+
+ <para>The <envar>InitialContextInitializer</envar> configuration
+ example:</para>
+
+ <para><programlisting> <component>
+ <type>org.exoplatform.services.naming.InitialContextInitializer</type>
+ <init-params>
+ <properties-param>
+ <name>default-properties</name>
+ <description>Default initial context properties</description>
+ <property name="java.naming.factory.initial" value="org.exoplatform.services.naming.SimpleContextFactory"/>
+ </properties-param>
+ <properties-param>
+ <name>mandatory-properties</name>
+ <description>Mandatory initial context properties</description>
+ <property name="java.naming.provider.url" value="rmi://localhost:9999"/>
+ </properties-param>
+ </init-params>
+ </component></programlisting></para>
+
+ <para>The BindReferencePlugin component plugin configuration example (for
+ JDBC datasource):</para>
+
+ <para><programlisting> <component-plugins>
+ <component-plugin>
+ <name>bind.datasource</name>
+ <set-method>addPlugin</set-method>
+ <type>org.exoplatform.services.naming.BindReferencePlugin</type>
+ <init-params>
+ <value-param>
+ <name>bind-name</name>
+ <value>jdbcjcr</value>
+ </value-param>
+ <value-param>
+ <name>class-name</name>
+ <value>javax.sql.DataSource</value>
+ </value-param>
+ <value-param>
+ <name>factory</name>
+ <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
+ </value-param>
+ <properties-param>
+ <name>ref-addresses</name>
+ <description>ref-addresses</description>
+ <property name="driverClassName" value="org.hsqldb.jdbcDriver"/>
+ <property name="url" value="jdbc:hsqldb:file:target/temp/data/portal"/>
+ <property name="username" value="sa"/>
+ <property name="password" value=""/>
+ </properties-param>
+ </init-params>
+ </component-plugin></programlisting></para>
+ </section>
+
+ <section>
+ <title>Recommendations for Application Developers</title>
+
+ <para><itemizedlist>
+ <listitem>
+ <para><envar>SimpleContextFactory</envar> is created for testing
+ purposes only, do not use it for production.</para>
+ </listitem>
+
+ <listitem>
+ <para>In J2EE environment use Naming Factory objects provided with
+ the Application Server.</para>
+ </listitem>
+ </itemizedlist></para>
+ </section>
+
+ <section>
+ <title>InitialContextInitializer API</title>
+
+ <para><envar>InitialContextInitalizer</envar> also provides feature of
+ references binding in runtime. References have bind in runtime will be
+ persisted and automatically rebinded on a next system start. Java temp
+ directory is used to persist references in bind-references.xml
+ file.</para>
+
+ <para>Service provide methods for binding reference.</para>
+
+ <programlisting>
+ public void bind(String bindName,
+ String className,
+ String factory,
+ String factoryLocation,
+ Map<String, String> refAddr)
+ throws NamingException, FileNotFoundException, XMLStreamException;</programlisting>
+
+ <itemizedlist>
+ <listitem>
+ <para><envar>bindName</envar> - name of binding</para>
+ </listitem>
+
+ <listitem>
+ <para><envar>className</envar> - the fully-qualified name of the class
+ of the object to which this Reference refers</para>
+ </listitem>
+
+ <listitem>
+ <para><envar>factory</envar> - the name of the factory class for
+ creating an instance of the object to which this Reference
+ refers</para>
+ </listitem>
+
+ <listitem>
+ <para><envar>factoryLocation</envar> - the location of the factory
+ class</para>
+ </listitem>
+
+ <listitem>
+ <para><envar>refAddr</envar> - object's properties map</para>
+ </listitem>
+ </itemizedlist>
+
+ <para>Example of usage:</para>
+
+ <programlisting>
+ // obtain InitialContextInitializer instance from ExoContainer (e.g. PortalContainer)
+ InitialContextInitializer initContext = (InitialContextInitializer)container.getComponentInstanceOfType(InitialContextInitializer.class);
+
+ Map<String, String> refAddr = new HashMap<String, String>();
+ refAddr.put("driverClassName", "oracle.jdbc.OracleDriver");
+ refAddr.put("url", "jdbc:oracle:thin:@oraclehost:1521:orcl");
+ refAddr.put("username", "exouser");
+ refAddr.put("password", "exopassword");
+
+ initContext.bind("jdbcexco", "javax.sql.DataSource", "org.apache.commons.dbcp.BasicDataSourceFactory", null, refAddr);
+
+ // try to get just bound DataSource
+ DataSource ds = (DataSource)new InitialContext().lookup("jdbcexo");</programlisting>
+ </section>
+</chapter>
Modified: jcr/trunk/docs/reference/en/src/main/docbook/en-US/modules/kernel.xml
===================================================================
--- jcr/trunk/docs/reference/en/src/main/docbook/en-US/modules/kernel.xml 2010-03-25 10:52:28 UTC (rev 2114)
+++ jcr/trunk/docs/reference/en/src/main/docbook/en-US/modules/kernel.xml 2010-03-25 10:56:01 UTC (rev 2115)
@@ -18,7 +18,7 @@
<xi:include href="kernel/transaction-service.xml"
xmlns:xi="http://www.w3.org/2001/XInclude" />
- <xi:include href="kernel/initial-context-binder-service.xml"
+ <xi:include href="kernel/jndi-naming.xml"
xmlns:xi="http://www.w3.org/2001/XInclude" />
</part>
16 years, 1 month
exo-jcr SVN: r2114 - jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl.
by do-not-reply@jboss.org
Author: areshetnyak
Date: 2010-03-25 06:52:28 -0400 (Thu, 25 Mar 2010)
New Revision: 2114
Modified:
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/RepositoryBackupChainImpl.java
Log:
EXOJCR-549 : The implementation backup/restore whole repository.
Modified: jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/RepositoryBackupChainImpl.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/RepositoryBackupChainImpl.java 2010-03-25 10:50:17 UTC (rev 2113)
+++ jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/RepositoryBackupChainImpl.java 2010-03-25 10:52:28 UTC (rev 2114)
@@ -36,6 +36,8 @@
import org.exoplatform.services.jcr.ext.backup.RepositoryBackupChainLog;
import org.exoplatform.services.jcr.ext.backup.RepositoryBackupConfig;
import org.exoplatform.services.jcr.util.IdGenerator;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
/**
* Created by The eXo Platform SAS.
@@ -48,6 +50,10 @@
public class RepositoryBackupChainImpl
implements RepositoryBackupChain
{
+ /**
+ * The apache logger.
+ */
+ private static Log log = ExoLogger.getLogger("ext.RepositoryBackupChainImpl");
private final RepositoryBackupConfig config;
@@ -110,9 +116,11 @@
{
if (state != FINISHED)
{
- for (BackupChain bc : workspaceBackups)
- {
- System.out.println( repositoryBackupId + " : " + getState(bc.getFullBackupState()));
+ if (log.isDebugEnabled()) {
+ for (BackupChain bc : workspaceBackups)
+ {
+ log.debug( repositoryBackupId + " : " + getState(bc.getFullBackupState()));
+ }
}
int fullBackupsState =-1;
16 years, 1 month
exo-jcr SVN: r2113 - in jcr/trunk/exo.jcr.component.ext/src: test/java/org/exoplatform/services/jcr/ext/backup and 1 other directory.
by do-not-reply@jboss.org
Author: areshetnyak
Date: 2010-03-25 06:50:17 -0400 (Thu, 25 Mar 2010)
New Revision: 2113
Modified:
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/RepositoryBackupChainImpl.java
jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/TestBackupManager.java
Log:
EXOJCR-549 : The implementation backup/restore whole repository.
Modified: jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/RepositoryBackupChainImpl.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/RepositoryBackupChainImpl.java 2010-03-25 10:10:58 UTC (rev 2112)
+++ jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/RepositoryBackupChainImpl.java 2010-03-25 10:50:17 UTC (rev 2113)
@@ -110,18 +110,36 @@
{
if (state != FINISHED)
{
+ for (BackupChain bc : workspaceBackups)
+ {
+ System.out.println( repositoryBackupId + " : " + getState(bc.getFullBackupState()));
+ }
+
int fullBackupsState =-1;
int incrementalBackupsState = -1;
for (BackupChain bc : workspaceBackups)
{
fullBackupsState = bc.getFullBackupState();
-
- if (bc.getBackupConfig().getBackupType() == BackupManager.FULL_AND_INCREMENTAL)
+
+ if (fullBackupsState != BackupJob.FINISHED)
{
- incrementalBackupsState = bc.getIncrementalBackupState();
+ break;
}
}
+
+ for (BackupChain bChein : workspaceBackups)
+ {
+ if (bChein.getBackupConfig().getBackupType() == BackupManager.FULL_AND_INCREMENTAL)
+ {
+ incrementalBackupsState = bChein.getIncrementalBackupState();
+
+ if (incrementalBackupsState == BackupJob.WORKING )
+ {
+ break;
+ }
+ }
+ }
if (config.getBackupType() == BackupManager.FULL_BACKUP_ONLY)
{
@@ -218,4 +236,19 @@
return config;
}
+ private String getState(int type)
+ {
+ String state = "UNDEFINED STATE";
+
+ if (type == BackupJob.FINISHED)
+ state = "FINISHED";
+ else if (type == BackupJob.STARTING)
+ state = "STARTING";
+ else if (type == BackupJob.WAITING)
+ state = "WAITING";
+ else if (type == BackupJob.WORKING)
+ state = "WORKING";
+
+ return state;
+ }
}
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-03-25 10:10:58 UTC (rev 2112)
+++ jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/TestBackupManager.java 2010-03-25 10:50:17 UTC (rev 2113)
@@ -46,7 +46,7 @@
public class TestBackupManager extends AbstractBackupTestCase
{
- /*public void testFullBackupRestore() throws Exception
+ public void testFullBackupRestore() throws Exception
{
// backup
File backDir = new File("target/backup/ws1");
@@ -201,11 +201,11 @@
fail("There are no backup files in " + backDir.getAbsolutePath());
}
- *//**
+ /**
* With BLOBs, locks, copy and move
*
* @throws Exception
- *//*
+ */
public void testIncrementalBackupRestore2() throws Exception
{
// full backup with BLOBs & incremental with BLOBs
@@ -737,7 +737,7 @@
}
else
fail("There are no backup files in " + backDir.getAbsolutePath());
- }*/
+ }
public void testRepositoryFullBackupRestore() throws Exception
16 years, 1 month
exo-jcr SVN: r2112 - in jcr/trunk/exo.jcr.component.ext/src: main/java/org/exoplatform/services/jcr/ext/backup/impl and 1 other directories.
by do-not-reply@jboss.org
Author: areshetnyak
Date: 2010-03-25 06:10:58 -0400 (Thu, 25 Mar 2010)
New Revision: 2112
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/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/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-549 : The implementation backup/restore whole repository.
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-24 16:42:33 UTC (rev 2111)
+++ jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/RepositoryBackupChainLog.java 2010-03-25 10:10:58 UTC (rev 2112)
@@ -293,23 +293,23 @@
}
catch (FileNotFoundException e)
{
- throw new BackupOperationException("Can not read RepositoryBackupChainLog from file ...", e);
+ throw new BackupOperationException("Can not read RepositoryBackupChainLog from file :" + log.getAbsolutePath(), e);
}
catch (XMLStreamException e)
{
- throw new BackupOperationException("Can not read RepositoryBackupChainLog from file ...", e);
+ throw new BackupOperationException("Can not read RepositoryBackupChainLog from file :" + log.getAbsolutePath(), e);
}
catch (FactoryConfigurationError e)
{
- throw new BackupOperationException("Can not read RepositoryBackupChainLog from file ...", e);
+ throw new BackupOperationException("Can not read RepositoryBackupChainLog from file :" + log.getAbsolutePath(), e);
}
catch (MalformedURLException e)
{
- throw new BackupOperationException("Can not read RepositoryBackupChainLog from file ...", e);
+ throw new BackupOperationException("Can not read RepositoryBackupChainLog from file :" + log.getAbsolutePath(), e);
}
catch (ValueFormatException e)
{
- throw new BackupOperationException("Can not read RepositoryBackupChainLog from file ...", e);
+ throw new BackupOperationException("Can not read RepositoryBackupChainLog from file :" + log.getAbsolutePath(), e);
}
}
Modified: jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/BackupManagerImpl.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/BackupManagerImpl.java 2010-03-24 16:42:33 UTC (rev 2111)
+++ jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/BackupManagerImpl.java 2010-03-25 10:10:58 UTC (rev 2112)
@@ -29,6 +29,7 @@
import org.exoplatform.services.jcr.config.WorkspaceEntry;
import org.exoplatform.services.jcr.config.WorkspaceInitializerEntry;
import org.exoplatform.services.jcr.core.ManageableRepository;
+import org.exoplatform.services.jcr.core.WorkspaceContainerFacade;
import org.exoplatform.services.jcr.dataflow.ChangesLogIterator;
import org.exoplatform.services.jcr.dataflow.ItemState;
import org.exoplatform.services.jcr.dataflow.PlainChangesLog;
@@ -159,7 +160,9 @@
private final MessagesListener messagesListener;
- private final AutoStopper stopper;
+ private final WorkspaceBackupAutoStopper workspaceBackupStopper;
+
+ private final RepositoryBackupAutoStopper repositoryBackupStopper;
class MessagesListener
implements BackupJobListener
@@ -265,7 +268,7 @@
}
}
- class AutoStopper
+ class WorkspaceBackupAutoStopper
extends Thread
{
@@ -312,8 +315,52 @@
}
}
}
+
+ class RepositoryBackupAutoStopper
+ extends Thread
+{
/**
+ * {@inheritDoc}
+ */
+ public void run()
+ {
+ while (true)
+ {
+ try
+ {
+ Thread.sleep(AUTO_STOPPER_TIMEOUT);
+
+ Iterator<RepositoryBackupChain> it = currentRepositoryBackups.iterator();
+ List<RepositoryBackupChain> stopedList = new ArrayList<RepositoryBackupChain>();
+
+ while (it.hasNext())
+ {
+ RepositoryBackupChain chain = it.next();
+
+ if (chain.isFinished())
+ {
+ stopedList.add(chain);
+ }
+ }
+
+ // STOP backups
+ for (RepositoryBackupChain chain : stopedList)
+ stopBackup(chain);
+ }
+ catch (InterruptedException e)
+ {
+ log.error("The interapted this thread.", e);
+ }
+ catch (Throwable e)
+ {
+ log.error("The unknown error", e);
+ }
+ }
+ }
+}
+
+ /**
* BackupManagerImpl constructor.
*
* @param initParams
@@ -355,8 +402,12 @@
this.restoreJobs = new ArrayList<JobWorkspaceRestore>();
this.restoreRepositoryJobs = new ArrayList<JobRepositoryRestore>();
- this.stopper = new AutoStopper();
- this.stopper.start();
+
+ this.workspaceBackupStopper = new WorkspaceBackupAutoStopper();
+ this.workspaceBackupStopper.start();
+
+ this.repositoryBackupStopper = new RepositoryBackupAutoStopper();
+ this.repositoryBackupStopper.start();
}
/**
@@ -717,7 +768,8 @@
private void fullRestoreOverInitializer(String pathBackupFile, String repositoryName, WorkspaceEntry workspaceEntry)
throws FileNotFoundException, IOException, RepositoryException, RepositoryConfigurationException
{
-
+ WorkspaceInitializerEntry wieOriginal = workspaceEntry.getInitializer();
+
RepositoryImpl defRep = (RepositoryImpl) repoService.getRepository(repositoryName);
// set the initializer SysViewWorkspaceInitializer
@@ -734,6 +786,11 @@
//restore
defRep.configWorkspace(workspaceEntry);
defRep.createWorkspace(workspaceEntry.getName());
+
+ //set original workspace initializer
+ WorkspaceContainerFacade wcf = defRep.getWorkspaceContainer(workspaceEntry.getName());
+ WorkspaceEntry createdWorkspaceEntry = (WorkspaceEntry) wcf.getComponent(WorkspaceEntry.class);
+ createdWorkspaceEntry.setInitializer(wieOriginal);
}
private void incrementalRestore(String pathBackupFile, String repositoryName, String workspaceName)
@@ -1259,14 +1316,14 @@
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 (workspaceNamesCorrespondMap == null)
{
+ for (String path : rblog.getWorkspaceBackupsInfo())
+ {
+ BackupChainLog bLog = new BackupChainLog(new File(path));
+ backups.put(bLog.getBackupConfig().getWorkspace(), bLog);
+ }
+
if (!rblog.getSystemWorkspace().equals(repositoryEntry.getSystemWorkspaceName()))
{
throw new BackupConfigurationException("The backup to system workspace is not system workspace in repository entry: " + rblog.getSystemWorkspace() + " is not equal " + repositoryEntry.getSystemWorkspaceName());
@@ -1279,7 +1336,7 @@
for (WorkspaceEntry wsEntry : repositoryEntry.getWorkspaceEntries())
{
- if (!backups.containsKey(wsEntry.getName()))
+ if (!backups.containsKey(wsEntry.getName()))
{
throw new BackupConfigurationException("The workspace '" + wsEntry.getName() + "' is not found in backup " + rblog.getLogFilePath());
}
@@ -1291,11 +1348,27 @@
}
else
{
+ // Crate map [new_ws_name : backupLog to that workspace].
+ for (String path : rblog.getWorkspaceBackupsInfo())
+ {
+ BackupChainLog bLog = new BackupChainLog(new File(path));
+
+ if (!workspaceNamesCorrespondMap.containsKey(bLog.getBackupConfig().getWorkspace()))
+ {
+ throw new BackupConfigurationException("Can not found coresptonding workspace name to workspace '"
+ + bLog.getBackupConfig().getWorkspace() + "' in " + workspaceNamesCorrespondMap .keySet());
+ }
+
+ backups.put(workspaceNamesCorrespondMap.get(bLog.getBackupConfig().getWorkspace()), bLog);
+ }
+
+ // Checking system workspace.
if (!repositoryEntry.getSystemWorkspaceName().equals(workspaceNamesCorrespondMap.get(rblog.getSystemWorkspace())))
{
throw new BackupConfigurationException("The backup to system workspace is not system workspace in repository entry: " + repositoryEntry.getSystemWorkspaceName() + " is not equal " + workspaceNamesCorrespondMap.get(rblog.getSystemWorkspace()));
}
+ // Checking count of corresponding workspaces.
if (workspaceNamesCorrespondMap.size() != repositoryEntry.getWorkspaceEntries().size())
{
throw new BackupConfigurationException("The repository entry is contains more or less workspace entry than backups of workspace in " + rblog.getLogFilePath());
@@ -1303,9 +1376,9 @@
for (WorkspaceEntry wsEntry : repositoryEntry.getWorkspaceEntries())
{
- if (!workspaceNamesCorrespondMap.containsKey(wsEntry.getName()))
+ if (!workspaceNamesCorrespondMap.containsValue(wsEntry.getName()))
{
- throw new BackupConfigurationException("The workspace '" + wsEntry.getName() + "' is not found workspaceNamesCorrespondMap : " + workspaceNamesCorrespondMap.keySet());
+ throw new BackupConfigurationException("The workspace '" + wsEntry.getName() + "' is not found workspaceNamesCorrespondMap : " + workspaceNamesCorrespondMap.values());
}
else if (!backups.containsKey(wsEntry.getName()))
{
Modified: jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/JobRepositoryRestore.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/JobRepositoryRestore.java 2010-03-24 16:42:33 UTC (rev 2111)
+++ jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/JobRepositoryRestore.java 2010-03-25 10:10:58 UTC (rev 2112)
@@ -37,6 +37,7 @@
import org.exoplatform.services.jcr.ext.backup.RepositoryRestoreExeption;
import org.exoplatform.services.jcr.ext.backup.server.WorkspaceRestoreExeption;
import org.exoplatform.services.jcr.impl.core.BackupWorkspaceInitializer;
+import org.exoplatform.services.jcr.impl.core.RepositoryImpl;
import org.exoplatform.services.jcr.impl.core.SessionRegistry;
import org.exoplatform.services.jcr.impl.core.SysViewWorkspaceInitializer;
import org.exoplatform.services.log.ExoLogger;
@@ -137,6 +138,8 @@
}
}
+ WorkspaceInitializerEntry wieOriginal = systemWorkspaceEntry.getInitializer();
+
//getting backup cahil log to system workspace.
BackupChainLog systemBackupChainLog = workspacesMapping.get(systemWorkspaceEntry.getName());
File fullBackupFile = new File(systemBackupChainLog.getJobEntryInfos().get(0).getURL().getPath());
@@ -164,8 +167,16 @@
try
{
repositoryService.createRepository(repositoryEntry);
- repositoryService.getConfig().retain(); // save configuration to persistence (file or persister)
+ //set original initializer to created workspace.
+ RepositoryImpl defRep = (RepositoryImpl) repositoryService.getRepository(repositoryEntry.getName());
+ WorkspaceContainerFacade wcf = defRep.getWorkspaceContainer(systemWorkspaceEntry.getName());
+ WorkspaceEntry createdWorkspaceEntry = (WorkspaceEntry) wcf.getComponent(WorkspaceEntry.class);
+ createdWorkspaceEntry.setInitializer(wieOriginal);
+
+ // save configuration to persistence (file or persister)
+ repositoryService.getConfig().retain();
+
for (WorkspaceEntry wsEntry : originalWorkspaceEntrys)
{
if (!(wsEntry.getName().equals(repositoryEntry.getSystemWorkspaceName())))
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-03-24 16:42:33 UTC (rev 2111)
+++ jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/AbstractBackupTestCase.java 2010-03-25 10:10:58 UTC (rev 2112)
@@ -146,6 +146,7 @@
ws1back.setCache(ws1e.getCache());
ws1back.setContainer(ws1e.getContainer());
ws1back.setLockManager(ws1e.getLockManager());
+ ws1back.setInitializer(ws1e.getInitializer());
// Indexer
ArrayList qParams = new ArrayList();
@@ -220,6 +221,7 @@
ws1back.setCache(baseWorkspaceEntry.getCache());
ws1back.setContainer(baseWorkspaceEntry.getContainer());
ws1back.setLockManager(baseWorkspaceEntry.getLockManager());
+ ws1back.setInitializer(baseWorkspaceEntry.getInitializer());
// Indexer
ArrayList qParams = new ArrayList();
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-03-24 16:42:33 UTC (rev 2111)
+++ jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/TestBackupManager.java 2010-03-25 10:10:58 UTC (rev 2112)
@@ -24,7 +24,6 @@
import org.exoplatform.services.jcr.core.ManageableRepository;
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.RepositoryImpl;
import org.exoplatform.services.jcr.impl.core.SessionImpl;
import java.io.ByteArrayInputStream;
@@ -47,7 +46,7 @@
public class TestBackupManager extends AbstractBackupTestCase
{
- public void testFullBackupRestore() throws Exception
+ /*public void testFullBackupRestore() throws Exception
{
// backup
File backDir = new File("target/backup/ws1");
@@ -202,11 +201,11 @@
fail("There are no backup files in " + backDir.getAbsolutePath());
}
- /**
+ *//**
* With BLOBs, locks, copy and move
*
* @throws Exception
- */
+ *//*
public void testIncrementalBackupRestore2() throws Exception
{
// full backup with BLOBs & incremental with BLOBs
@@ -503,7 +502,7 @@
SessionImpl sessionWS1 = (SessionImpl)repository.login(credentials, "ws3");
sessionWS1.getRootNode().addNode("asdasdasda", "nt:unstructured")
- .setProperty("data", /*"data_1"*/new FileInputStream(createBLOBTempFile(1024)));
+ .setProperty("data", new FileInputStream(createBLOBTempFile(1024)));
sessionWS1.save();
// 1-st backup
@@ -541,7 +540,7 @@
// add date to restored workspace
back1.getRootNode().addNode("gdfgrghfhf", "nt:unstructured")
- .setProperty("data", /*"data_2"*/new FileInputStream(createBLOBTempFile(1024)));
+ .setProperty("data", new FileInputStream(createBLOBTempFile(1024)));
back1.save();
}
else
@@ -738,7 +737,7 @@
}
else
fail("There are no backup files in " + backDir.getAbsolutePath());
- }
+ }*/
public void testRepositoryFullBackupRestore() throws Exception
@@ -997,10 +996,10 @@
fail("There are no backup files in " + backDir.getAbsolutePath());
}
- /*public void testAutoStopRepositoryBackupIncrRepetion() throws Exception
+ public void testAutoStopRepositoryBackupIncrRepetion() throws Exception
{
// backup
- File backDir = new File("target/backup/" + repository.getName() + "123");
+ File backDir = new File("target/backup/" + repository.getName() + "_" + System.currentTimeMillis());
backDir.mkdirs();
RepositoryBackupConfig config = new RepositoryBackupConfig();
@@ -1019,5 +1018,5 @@
for (RepositoryBackupChain chain : backup.getCurrentRepositoryBackups())
if (bch.getBackupId().equals(chain.getBackupId()))
fail("The backup with id '" + chain.getBackupId() + "' should not be active");
- }*/
+ }
}
16 years, 1 month
exo-jcr SVN: r2111 - jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core.
by do-not-reply@jboss.org
Author: tolusha
Date: 2010-03-24 12:42:33 -0400 (Wed, 24 Mar 2010)
New Revision: 2111
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/XASessionImpl.java
Log:
EXOJCR-608: XaSessionImpl as XA resource should be unique per user, workspace and repository
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/XASessionImpl.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/XASessionImpl.java 2010-03-24 16:19:38 UTC (rev 2110)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/XASessionImpl.java 2010-03-24 16:42:33 UTC (rev 2111)
@@ -279,7 +279,12 @@
if (resource instanceof XASessionImpl)
{
XASessionImpl session = (XASessionImpl)resource;
- boolean isSame = getUserID().equals(session.getUserID());
+ boolean isSame =
+ getUserID().equals(session.getUserID())
+ && getWorkspace().getName().equals(session.getWorkspace().getName())
+ && ((RepositoryImpl)getRepository()).getName().equals(
+ ((RepositoryImpl)session.getRepository()).getName());
+
if (LOG.isDebugEnabled())
{
LOG.debug("isSameRM: " + getSessionInfo() + " -- " + session.getSessionInfo() + " : " + isSame + ", "
16 years, 1 month
exo-jcr SVN: r2110 - core/trunk/exo.core.component.database/src/test/java/org/exoplatform/services/database and 2 other directories.
by do-not-reply@jboss.org
Author: pnedonosko
Date: 2010-03-24 12:19:38 -0400 (Wed, 24 Mar 2010)
New Revision: 2110
Modified:
core/trunk/exo.core.component.database/src/main/java/org/exoplatform/services/database/creator/DBConnectionInfo.java
core/trunk/exo.core.component.database/src/main/java/org/exoplatform/services/database/creator/DBCreator.java
core/trunk/exo.core.component.database/src/main/java/org/exoplatform/services/database/creator/DBCreatorException.java
core/trunk/exo.core.component.database/src/test/java/org/exoplatform/services/database/TestDBCreator.java
core/trunk/exo.core.component.database/src/test/resources/conf/standalone/test-configuration.xml
kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/naming/InitialContextBinder.java
kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/naming/InitialContextInitializer.java
Log:
EXOJCR-573 binder used inside InitialContextInitializer (new method bind); cleanup and some renaming.
Modified: core/trunk/exo.core.component.database/src/main/java/org/exoplatform/services/database/creator/DBConnectionInfo.java
===================================================================
--- core/trunk/exo.core.component.database/src/main/java/org/exoplatform/services/database/creator/DBConnectionInfo.java 2010-03-24 15:42:01 UTC (rev 2109)
+++ core/trunk/exo.core.component.database/src/main/java/org/exoplatform/services/database/creator/DBConnectionInfo.java 2010-03-24 16:19:38 UTC (rev 2110)
@@ -22,7 +22,7 @@
* Class contains needed database connection information.
*
* @author <a href="anatoliy.bazko(a)exoplatform.org">Anatoliy Bazko</a>
- * @version $Id: DBConnectionInfo.java 111 2010-11-11 11:11:11Z tolusha $
+ * @version $Id$
*/
public class DBConnectionInfo
{
Property changes on: core/trunk/exo.core.component.database/src/main/java/org/exoplatform/services/database/creator/DBConnectionInfo.java
___________________________________________________________________
Name: svn:keywords
+ Id
Modified: core/trunk/exo.core.component.database/src/main/java/org/exoplatform/services/database/creator/DBCreator.java
===================================================================
--- core/trunk/exo.core.component.database/src/main/java/org/exoplatform/services/database/creator/DBCreator.java 2010-03-24 15:42:01 UTC (rev 2109)
+++ core/trunk/exo.core.component.database/src/main/java/org/exoplatform/services/database/creator/DBCreator.java 2010-03-24 16:19:38 UTC (rev 2110)
@@ -33,7 +33,7 @@
/**
* @author <a href="anatoliy.bazko(a)exoplatform.org">Anatoliy Bazko</a>
- * @version $Id: DBCreator.java 111 2010-11-11 11:11:11Z tolusha $
+ * @version $Id$
*/
public class DBCreator
{
Property changes on: core/trunk/exo.core.component.database/src/main/java/org/exoplatform/services/database/creator/DBCreator.java
___________________________________________________________________
Name: svn:keywords
+ Id
Modified: core/trunk/exo.core.component.database/src/main/java/org/exoplatform/services/database/creator/DBCreatorException.java
===================================================================
--- core/trunk/exo.core.component.database/src/main/java/org/exoplatform/services/database/creator/DBCreatorException.java 2010-03-24 15:42:01 UTC (rev 2109)
+++ core/trunk/exo.core.component.database/src/main/java/org/exoplatform/services/database/creator/DBCreatorException.java 2010-03-24 16:19:38 UTC (rev 2110)
@@ -20,7 +20,7 @@
/**
* @author <a href="anatoliy.bazko(a)exoplatform.org">Anatoliy Bazko</a>
- * @version $Id: DBCreatorException.java 111 2010-11-11 11:11:11Z tolusha $
+ * @version $Id$
*/
public class DBCreatorException extends Exception
{
Property changes on: core/trunk/exo.core.component.database/src/main/java/org/exoplatform/services/database/creator/DBCreatorException.java
___________________________________________________________________
Name: svn:keywords
+ Id
Modified: core/trunk/exo.core.component.database/src/test/java/org/exoplatform/services/database/TestDBCreator.java
===================================================================
--- core/trunk/exo.core.component.database/src/test/java/org/exoplatform/services/database/TestDBCreator.java 2010-03-24 15:42:01 UTC (rev 2109)
+++ core/trunk/exo.core.component.database/src/test/java/org/exoplatform/services/database/TestDBCreator.java 2010-03-24 16:19:38 UTC (rev 2110)
@@ -18,10 +18,11 @@
*/
package org.exoplatform.services.database;
+import junit.framework.TestCase;
+
import org.exoplatform.container.PortalContainer;
import org.exoplatform.services.database.creator.DBConnectionInfo;
import org.exoplatform.services.database.creator.DBCreator;
-import org.exoplatform.services.naming.InitialContextBinder;
import org.exoplatform.services.naming.InitialContextInitializer;
import java.sql.Connection;
@@ -30,19 +31,15 @@
import javax.sql.DataSource;
-import junit.framework.TestCase;
-
/**
* @author <a href="anatoliy.bazko(a)exoplatform.org">Anatoliy Bazko</a>
- * @version $Id: TestDBCreator.java 111 2010-11-11 11:11:11Z tolusha $
+ * @version $Id$
*/
public class TestDBCreator extends TestCase
{
protected DBCreator dbCreator;
- private InitialContextBinder initialContextBinder;
-
private InitialContextInitializer initContext;
public void setUp() throws Exception
@@ -51,7 +48,6 @@
dbCreator = (DBCreator)container.getComponentInstanceOfType(DBCreator.class);
initContext = (InitialContextInitializer)container.getComponentInstanceOfType(InitialContextInitializer.class);
- initialContextBinder = (InitialContextBinder)container.getComponentInstanceOfType(InitialContextBinder.class);
}
public void testDBCreate() throws Exception
@@ -66,7 +62,7 @@
refAddr.put("username", dbInfo.getUsername());
refAddr.put("password", dbInfo.getPassword());
- initialContextBinder.bind("testjdbcjcr", "javax.sql.DataSource",
+ initContext.bind("testjdbcjcr", "javax.sql.DataSource",
"org.apache.commons.dbcp.BasicDataSourceFactory", null, refAddr);
DataSource ds = (DataSource)initContext.getInitialContext().lookup("testjdbcjcr");
Property changes on: core/trunk/exo.core.component.database/src/test/java/org/exoplatform/services/database/TestDBCreator.java
___________________________________________________________________
Name: svn:keywords
+ Id
Modified: core/trunk/exo.core.component.database/src/test/resources/conf/standalone/test-configuration.xml
===================================================================
--- core/trunk/exo.core.component.database/src/test/resources/conf/standalone/test-configuration.xml 2010-03-24 15:42:01 UTC (rev 2109)
+++ core/trunk/exo.core.component.database/src/test/resources/conf/standalone/test-configuration.xml 2010-03-24 16:19:38 UTC (rev 2110)
@@ -73,11 +73,6 @@
</component>
<component>
- <key>org.exoplatform.services.naming.InitialContextBinder</key>
- <type>org.exoplatform.services.naming.InitialContextBinder</type>
- </component>
-
- <component>
<key>org.exoplatform.services.naming.InitialContextInitializer</key>
<type>org.exoplatform.services.naming.InitialContextInitializer</type>
<component-plugins>
Modified: kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/naming/InitialContextBinder.java
===================================================================
--- kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/naming/InitialContextBinder.java 2010-03-24 15:42:01 UTC (rev 2109)
+++ kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/naming/InitialContextBinder.java 2010-03-24 16:19:38 UTC (rev 2110)
@@ -78,12 +78,12 @@
/**
* Absolute file path to references's storage.
*/
- protected final String bindReferencesPath;
+ protected final String bindingsStorePath;
/**
* All current binded references.
*/
- protected Map<String, Reference> bindReferences;
+ protected Map<String, Reference> bindings;
/**
* InitialContextBinder constructor.
@@ -99,17 +99,17 @@
* @throws NamingException
* @throws NamingException
*/
- public InitialContextBinder(InitialContextInitializer initialContextInitializer) throws FileNotFoundException,
+ InitialContextBinder(InitialContextInitializer initialContextInitializer) throws FileNotFoundException,
XMLStreamException, NamingException
{
this.initialContextInitializer = initialContextInitializer;
- this.bindReferences = new HashMap<String, Reference>();
- this.bindReferencesPath = System.getProperty("java.io.tmpdir") + File.separator + "bind-references.xml";
+ this.bindings = new HashMap<String, Reference>();
+ this.bindingsStorePath = System.getProperty("java.io.tmpdir") + File.separator + "bind-references.xml";
- if (new File(bindReferencesPath).exists())
+ if (new File(bindingsStorePath).exists())
{
- Map<String, Reference> importedRefs = doImport();
+ Map<String, Reference> importedRefs = readBindings();
for (Entry<String, Reference> entry : importedRefs.entrySet())
{
bind(entry.getKey(), entry.getValue());
@@ -141,20 +141,20 @@
Map<String, String> refAddr) throws NamingException, FileNotFoundException, XMLStreamException
{
Reference reference = new Reference(className, factory, factoryLocation);
- for (Entry entry : refAddr.entrySet())
+ for (Map.Entry<String, String> entry : refAddr.entrySet())
{
- reference.add(new StringRefAddr((String)entry.getKey(), (String)entry.getValue()));
+ reference.add(new StringRefAddr(entry.getKey(), entry.getValue()));
}
bind(bindName, reference);
- doExport();
+ saveBindings();
}
private void bind(String bindName, Reference reference) throws NamingException
{
initialContextInitializer.getInitialContext().bind(bindName, reference);
- bindReferences.put(bindName, reference);
+ bindings.put(bindName, reference);
}
/**
@@ -165,15 +165,15 @@
* @throws FileNotFoundException
* if can't open output stream from file
*/
- protected void doExport() throws FileNotFoundException, XMLStreamException
+ protected void saveBindings() throws FileNotFoundException, XMLStreamException
{
XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
- XMLStreamWriter writer = outputFactory.createXMLStreamWriter(new FileOutputStream(bindReferencesPath), "UTF-8");
+ XMLStreamWriter writer = outputFactory.createXMLStreamWriter(new FileOutputStream(bindingsStorePath), "UTF-8");
writer.writeStartDocument("UTF-8", "1.0");
writer.writeStartElement(BIND_REFERENCES_ELEMENT);
- for (Entry<String, Reference> entry : bindReferences.entrySet())
+ for (Entry<String, Reference> entry : bindings.entrySet())
{
String bindName = entry.getKey();
Reference reference = entry.getValue();
@@ -218,14 +218,14 @@
* @throws FileNotFoundException
* if can't open input stream from file
*/
- protected Map<String, Reference> doImport() throws FileNotFoundException, XMLStreamException
+ protected Map<String, Reference> readBindings() throws FileNotFoundException, XMLStreamException
{
Stack<RefEntity> stack = new Stack<RefEntity>();
Map<String, Reference> importedRefs = new HashMap<String, Reference>();
XMLInputFactory factory = XMLInputFactory.newInstance();
- XMLEventReader reader = factory.createXMLEventReader(new FileInputStream(bindReferencesPath), "UTF-8");
+ XMLEventReader reader = factory.createXMLEventReader(new FileInputStream(bindingsStorePath), "UTF-8");
while (reader.hasNext())
{
Modified: kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/naming/InitialContextInitializer.java
===================================================================
--- kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/naming/InitialContextInitializer.java 2010-03-24 15:42:01 UTC (rev 2109)
+++ kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/naming/InitialContextInitializer.java 2010-03-24 16:19:38 UTC (rev 2110)
@@ -26,16 +26,23 @@
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
+import java.io.File;
+import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NameAlreadyBoundException;
import javax.naming.NamingException;
import javax.naming.Reference;
+import javax.naming.StringRefAddr;
+import javax.xml.stream.XMLStreamException;
/**
* Created by The eXo Platform SAS.<br/> Initializer for
@@ -59,13 +66,18 @@
private final InitialContext initialContext;
+ private final InitialContextBinder binder;
+
/**
* @param params
* @throws NamingException
* @throws ConfigurationException if no context factory initialized and no
* context-factory nor default-context-factory configured
+ * @throws XMLStreamException if error of serialized bindings read
+ * @throws FileNotFoundException if cannot open file with serialized bindings
*/
- public InitialContextInitializer(InitParams params) throws NamingException, ConfigurationException
+ public InitialContextInitializer(InitParams params) throws NamingException, ConfigurationException,
+ FileNotFoundException, XMLStreamException
{
for (Iterator propsParams = params.getPropertiesParamIterator(); propsParams.hasNext();)
{
@@ -97,6 +109,9 @@
}
initialContext = new InitialContext();
bindReferencesPlugins = new ArrayList<BindReferencePlugin>();
+
+ // binder
+ binder = new InitialContextBinder(this);
}
private void setSystemProperty(String propName, String propValue, String propParamName)
@@ -110,13 +125,17 @@
}
// for out-of-container testing
- private InitialContextInitializer(String name, Reference reference) throws NamingException
+ private InitialContextInitializer(String name, Reference reference) throws NamingException, FileNotFoundException, XMLStreamException
{
if (System.getProperty(Context.INITIAL_CONTEXT_FACTORY) == null)
+ {
System.setProperty(Context.INITIAL_CONTEXT_FACTORY, defaultContextFactory);
+ }
initialContext = new InitialContext();
initialContext.rebind(name, reference);
+ // binder
+ binder = new InitialContextBinder(this);
}
/**
@@ -191,8 +210,34 @@
}
// for out-of-container testing
- public static void initialize(String name, Reference reference) throws NamingException
+ public static void initialize(String name, Reference reference) throws NamingException, FileNotFoundException, XMLStreamException
{
new InitialContextInitializer(name, reference);
}
+
+ /**
+ * Constructs references from params, binds in initial contexts and persists list of all binded
+ * references into file.
+ *
+ * @param bindName
+ * bind name
+ * @param className
+ * class name
+ * @param factory
+ * factory name
+ * @param factoryLocation
+ * factory location
+ * @param refAddr
+ * map of references's properties
+ *
+ * @throws NamingException
+ * if error occurs due to binding
+ * @throws XMLStreamException
+ * @throws FileNotFoundException
+ */
+ public void bind(String bindName, String className, String factory, String factoryLocation,
+ Map<String, String> refAddr) throws NamingException, FileNotFoundException, XMLStreamException
+ {
+ binder.bind(bindName, className, factory, factoryLocation, refAddr);
+ }
}
16 years, 1 month
exo-jcr SVN: r2109 - jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene.
by do-not-reply@jboss.org
Author: nzamosenchuk
Date: 2010-03-24 11:42:01 -0400 (Wed, 24 Mar 2010)
New Revision: 2109
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MultiIndex.java
Log:
EXOJCR-589: Persistent UpdateInProgress is now set to true in MultiIndex.update() method if flush would be performed.
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MultiIndex.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MultiIndex.java 2010-03-24 14:18:24 UTC (rev 2108)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MultiIndex.java 2010-03-24 15:42:01 UTC (rev 2109)
@@ -434,12 +434,12 @@
//updateInProgress = true;
indexUpdateMonitor.setUpdateInProgress(true, false);
}
+ boolean flush = false;
try
{
long transactionId = nextTransactionId++;
executeAndLog(new Start(transactionId));
- boolean flush = false;
for (Iterator it = remove.iterator(); it.hasNext();)
{
executeAndLog(new DeleteNode(transactionId, (String)it.next()));
@@ -459,6 +459,11 @@
// flush whole index when volatile index has been commited.
if (flush)
{
+ // if we are going to flush, need to set persistent update
+ synchronized (updateMonitor)
+ {
+ indexUpdateMonitor.setUpdateInProgress(true, true);
+ }
flush();
}
}
@@ -467,7 +472,8 @@
synchronized (updateMonitor)
{
//updateInProgress = false;
- indexUpdateMonitor.setUpdateInProgress(false, false);
+
+ indexUpdateMonitor.setUpdateInProgress(false, flush);
updateMonitor.notifyAll();
releaseMultiReader();
}
16 years, 1 month
exo-jcr SVN: r2108 - in jcr/trunk/exo.jcr.component.ext/src: main/java/org/exoplatform/services/jcr/ext/backup/impl and 5 other directories.
by do-not-reply@jboss.org
Author: areshetnyak
Date: 2010-03-24 10:18:24 -0400 (Wed, 24 Mar 2010)
New Revision: 2108
Added:
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/RepositoryBackupChain.java
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/RepositoryBackupConfig.java
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/RepositoryRestoreExeption.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/RepositoryBackupChainImpl.java
Modified:
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/BackupChain.java
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/BackupChainLog.java
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/BackupConfig.java
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/BackupChainImpl.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/server/HTTPBackupAgent.java
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/replication/test/ReplicationTestService.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
jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/repository/RestRepositoryServiceTest.java
jcr/trunk/exo.jcr.component.ext/src/test/resources/conf/standalone/test-configuration.xml
Log:
EXOJCR-549 : The implementation backup/restore whole repository.
Modified: jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/BackupChain.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/BackupChain.java 2010-03-24 13:11:41 UTC (rev 2107)
+++ jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/BackupChain.java 2010-03-24 14:18:24 UTC (rev 2108)
@@ -26,7 +26,7 @@
* Author : Alex Reshetnyak alex.reshetnyak(a)exoplatform.com.ua
* 09.01.2008
*/
-public interface BackupChain
+public interface BackupChain extends RepositoryBackupChain
{
/**
* The full backup state.
@@ -39,16 +39,6 @@
public static final int INCREMENTAL_WORKING = 2;
/**
- * State of backup FINISHED.
- */
- public static final int FINISHED = 4;
-
- /**
- * Sate of backup INITIALIZED.
- */
- public static final int INITIALIZED = 0;
-
- /**
* The timeout.
*/
public long TIMEOUT = 10000;
@@ -62,18 +52,6 @@
List<BackupJob> getBackupJobs();
/**
- * Call start backup.
- *
- */
- void startBackup();
-
- /**
- * Call stop backup.
- *
- */
- void stopBackup();
-
- /**
* Getting backup config.
*
* @return BackupConfig
@@ -88,32 +66,16 @@
* return state of full backup
*/
int getFullBackupState();
-
+
/**
- * Getting state of backup.
+ * Getting the state of incremental backup.
*
* @return int
- * return state of backup
+ * return state of full backup
*/
- int getState();
+ int getIncrementalBackupState();
/**
- * isFinished.
- *
- * @return boolean
- * return 'true' if backup was finished.
- */
- boolean isFinished();
-
- /**
- * Getting path to backup log.
- *
- * @return String
- * return path to backup log
- */
- String getLogFilePath();
-
- /**
* Add listener to all existing and will be created in future jobs.
*
* @param listener
@@ -128,21 +90,4 @@
* BackupJobListener, the backup job listener
*/
void removeListener(BackupJobListener listener);
-
- /**
- * Getting identifier of backup.
- *
- * @return String
- * return identifier of backup
- */
- String getBackupId();
-
- /**
- * Getting started time of backup.
- *
- * @return Calendar
- * return started time of backup
- */
- Calendar getStartedTime();
-
}
Modified: jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/BackupChainLog.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/BackupChainLog.java 2010-03-24 13:11:41 UTC (rev 2107)
+++ jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/BackupChainLog.java 2010-03-24 14:18:24 UTC (rev 2108)
@@ -309,7 +309,7 @@
return finishedTime;
}
- class LogReader
+ private class LogReader
{
protected Log logger = ExoLogger.getLogger("ext.LogWriter");
@@ -533,7 +533,7 @@
}
}
- class LogWriter
+ private class LogWriter
{
protected Log logger = ExoLogger.getLogger("ext.LogWriter");
Modified: jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/BackupConfig.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/BackupConfig.java 2010-03-24 13:11:41 UTC (rev 2107)
+++ jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/BackupConfig.java 2010-03-24 14:18:24 UTC (rev 2108)
@@ -27,107 +27,14 @@
* @version $Id: $
*/
-public class BackupConfig
+public class BackupConfig extends RepositoryBackupConfig
{
-
/**
- * The backup type.
- */
- private int backupType;
-
- /**
- * The repository name.
- */
- private String repository;
-
- /**
* The workspace name.
*/
private String workspace;
/**
- * The incremental job period.
- */
- private long incrementalJobPeriod;
-
- /**
- * The incremental job number (the repetition numper).
- */
- private int incrementalJobNumber;
-
- /**
- * The backup directory.
- */
- private File backupDir;
-
- /**
- * Getting incremental job period.
- *
- * @return long
- * return incremental job period.
- */
- public long getIncrementalJobPeriod()
- {
- return incrementalJobPeriod;
- }
-
- /**
- * Setting incremental job period.
- *
- * @param incrementalJobPeriod
- * long, the incremental job period
- */
- public void setIncrementalJobPeriod(long incrementalJobPeriod)
- {
- this.incrementalJobPeriod = incrementalJobPeriod;
- }
-
- /**
- * Getting incremental job period (the repetition period).
- *
- * @return int
- * return incremental job period
- */
- public int getIncrementalJobNumber()
- {
- return incrementalJobNumber;
- }
-
- /**
- * Setting incremental job number (the repetition period).
- *
- * @param incrementalJobNumber
- * int, the incremental job number
- *
- */
- public void setIncrementalJobNumber(int incrementalJobNumber)
- {
- this.incrementalJobNumber = incrementalJobNumber;
- }
-
- /**
- * Getting the repository name.
- *
- * @return String
- * return the repository name
- */
- public String getRepository()
- {
- return repository;
- }
-
- /**
- * Setting the repository name.
- *
- * @param repository
- * String, the repository name
- */
- public void setRepository(String repository)
- {
- this.repository = repository;
- }
-
- /**
* Getting the workspace name.
*
* @return String
@@ -148,48 +55,4 @@
{
this.workspace = workspace;
}
-
- /**
- * Getting backup directory.
- *
- * @return File
- * return c
- */
- public File getBackupDir()
- {
- return backupDir;
- }
-
- /**
- * Setting the backup directory.
- *
- * @param backupDir
- * File, the backup directory
- */
- public void setBackupDir(File backupDir)
- {
- this.backupDir = backupDir;
- }
-
- /**
- * Getting the backup type.
- *
- * @return int
- * return the backup type
- */
- public int getBackupType()
- {
- return backupType;
- }
-
- /**
- * Setting the backup type.
- *
- * @param backupType
- * int, the backup type
- */
- public void setBackupType(int backupType)
- {
- this.backupType = backupType;
- }
}
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-03-24 13:11:41 UTC (rev 2107)
+++ jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/BackupManager.java 2010-03-24 14:18:24 UTC (rev 2108)
@@ -19,13 +19,16 @@
package org.exoplatform.services.jcr.ext.backup;
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.ext.backup.impl.BackupMessage;
import org.exoplatform.services.jcr.ext.backup.impl.BackupScheduler;
+import org.exoplatform.services.jcr.ext.backup.impl.JobRepositoryRestore;
import org.exoplatform.services.jcr.ext.backup.impl.JobWorkspaceRestore;
import java.io.File;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import javax.jcr.RepositoryException;
@@ -57,6 +60,14 @@
* return the set of current backups
*/
Set<BackupChain> getCurrentBackups();
+
+ /**
+ * Getting current repository backups.
+ *
+ * @return Set
+ * return the set of current backups
+ */
+ Set<RepositoryBackupChain> getCurrentRepositoryBackups();
/**
* Getting list of restores.
@@ -67,7 +78,7 @@
List<JobWorkspaceRestore> getRestores();
/**
- * Getting last restore by repository nam workspace.
+ * Getting last restore by repository and workspace name.
*
* @param repositoryName
* String, the repository name
@@ -77,8 +88,26 @@
* return the job to restore
*/
JobWorkspaceRestore getLastRestore(String repositoryName, String workspaceName);
+
+ /**
+ * Getting list of repository restores.
+ *
+ * @return List
+ * return the list of backups
+ */
+ List<JobRepositoryRestore> getRepositoryRestores();
/**
+ * Getting last repository restore by repository name.
+ *
+ * @param repositoryName
+ * String, the repository name
+ * @return JobWorkspaceRestore
+ * return the job to restore
+ */
+ JobRepositoryRestore getLastRepositoryRestore(String repositoryName);
+
+ /**
* Getting all backup logs .
*
* @return BackupChainLog[]
@@ -229,4 +258,88 @@
* return the default incremental job period
*/
long getDefaultIncrementalJobPeriod();
+
+ /**
+ * Starting repository backup.
+ *
+ * @param config
+ * RepositoryBackupConfig, the backup configuration to repository
+ * @return RepositoryBackupChain
+ * return the repository backup chain
+ * @throws BackupOperationException BackupOperationException
+ * will be generate the exception BackupOperationException
+ * @throws BackupConfigurationException
+ * will be generate the exception BackupConfigurationException
+ * @throws RepositoryException
+ * will be generate the exception RepositoryException
+ * @throws RepositoryConfigurationException
+ * will be generate the exception RepositoryConfigurationException
+ */
+ RepositoryBackupChain startBackup(RepositoryBackupConfig config) throws BackupOperationException, BackupConfigurationException,
+ RepositoryException, RepositoryConfigurationException;
+
+ /**
+ * Stop backup.
+ *
+ * @param backup
+ * RepositoryBackupChain, the repositroy backup chain
+ */
+ void stopBackup(RepositoryBackupChain backup);
+
+ /**
+ * Repository restore from backup.
+ *
+ * @param log
+ * RepositoryBackupChainLog, the repository backup log
+ * @param repositoryEntry
+ * RepositoryEntry, the repository entry
+ * @param workspaceNamesCorrespondMap
+ * Map<String, String>, the map with correspondence workspace name in RepositoryEntry and RepositoryBackupChainLog.
+ * @param asynchronous
+ * boolean, in 'true' then asynchronous restore.
+ * @throws BackupOperationException
+ * will be generate the exception BackupOperationException
+ * @throws BackupConfigurationException
+ * will be generate the exception BackupConfigurationException
+ * @throws RepositoryException
+ * will be generate the exception RepositoryException
+ * @throws RepositoryConfigurationException
+ * will be generate the exception RepositoryConfigurationException
+ */
+ void restore(RepositoryBackupChainLog log, RepositoryEntry repositoryEntry, Map<String, String> workspaceNamesCorrespondMap, boolean asynchronous)
+ throws BackupOperationException, BackupConfigurationException, RepositoryException,
+ RepositoryConfigurationException;
+
+ /**
+ * Repository restore from backup.
+ *
+ * @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
+ * @throws RepositoryException
+ * will be generate the exception RepositoryException
+ * @throws RepositoryConfigurationException
+ * will be generate the exception RepositoryConfigurationException
+ */
+ void restore(RepositoryBackupChainLog log, RepositoryEntry repositoryEntry, boolean asynchronous)
+ throws BackupOperationException, BackupConfigurationException, RepositoryException,
+ RepositoryConfigurationException;
+
+ /**
+ * Finding current backup by repository.
+ *
+ * @param reposytore
+ * String, the repository name
+ * @return RepositoryBackupChain
+ * return the current backup to repository
+ */
+ RepositoryBackupChain findRepositoryBackup(String repository);
+
}
Added: jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/RepositoryBackupChain.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/RepositoryBackupChain.java (rev 0)
+++ jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/RepositoryBackupChain.java 2010-03-24 14:18:24 UTC (rev 2108)
@@ -0,0 +1,112 @@
+/*
+ * 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 java.util.Calendar;
+
+/**
+ * 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 RepositoryBackupChain
+{
+
+ /**
+ * State of backup : full backup was finished and incremental backup is working.
+ */
+ public static final int FULL_BACKUP_FINISHED_INCREMENTAL_BACKUP_WORKING = 16;
+
+ /**
+ * State of backup WORKING.
+ */
+ public static final int WORKING = 8;
+
+ /**
+ * State of backup FINISHED.
+ */
+ public static final int FINISHED = 4;
+
+ /**
+ * Sate of backup INITIALIZED.
+ */
+ public static final int INITIALIZED = 0;
+
+ /**
+ * Call start backup.
+ *
+ */
+ void startBackup();
+
+ /**
+ * Call stop backup.
+ *
+ */
+ void stopBackup();
+
+ /**
+ * Getting state of backup.
+ *
+ * @return int
+ * return state of backup
+ */
+ int getState();
+
+ /**
+ * isFinished.
+ *
+ * @return boolean
+ * return 'true' if backup was finished.
+ */
+ boolean isFinished();
+
+ /**
+ * Getting path to backup log.
+ *
+ * @return String
+ * return path to backup log
+ */
+ String getLogFilePath();
+
+ /**
+ * Getting identifier of backup.
+ *
+ * @return String
+ * return identifier of backup
+ */
+ String getBackupId();
+
+ /**
+ * Getting started time of backup.
+ *
+ * @return Calendar
+ * return started time of backup
+ */
+ Calendar getStartedTime();
+
+ /**
+ * Getting repository backup config.
+ *
+ * @return RepositoryBackupConfig
+ * return the repository backup config
+ */
+ RepositoryBackupConfig getBackupConfig();
+
+}
Property changes on: jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/RepositoryBackupChain.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/RepositoryBackupChainLog.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/RepositoryBackupChainLog.java (rev 0)
+++ jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/RepositoryBackupChainLog.java 2010-03-24 14:18:24 UTC (rev 2108)
@@ -0,0 +1,409 @@
+/*
+ * 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 java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.List;
+
+import javax.jcr.ValueFormatException;
+import javax.xml.stream.FactoryConfigurationError;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+import javax.xml.stream.events.StartElement;
+
+import org.exoplatform.services.jcr.impl.util.JCRDateFormat;
+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 RepositoryBackupChainLog
+{
+ private class LogWriter
+ {
+
+ protected Log logger = ExoLogger.getLogger("ext.LogWriter");
+
+ private File logFile;
+
+ XMLStreamWriter writer;
+
+ public LogWriter(File logFile) throws FileNotFoundException, XMLStreamException, FactoryConfigurationError
+ {
+ this.logFile = logFile;
+
+ writer = XMLOutputFactory.newInstance().createXMLStreamWriter(new FileOutputStream(this.logFile));
+
+ writer.writeStartDocument();
+ writer.writeStartElement("repository-backup-cain-log");
+ writer.flush();
+
+ writer.writeStartElement("start-time");
+ writer.writeCharacters(JCRDateFormat.format(startedTime));
+ writer.writeEndElement();
+ }
+
+ public void writeSystemWorkspaceName(String wsName) throws XMLStreamException
+ {
+ writer.writeStartElement("system-workspace");
+ writer.writeCharacters(wsName);
+ writer.writeEndElement();
+ writer.flush();
+ }
+
+ public void writeBackupsPath(List<String> wsLogFilePathList) throws XMLStreamException
+ {
+ writer.writeStartElement("workspaces-backup-info");
+
+ for (String path : wsLogFilePathList)
+ {
+ writer.writeStartElement("url");
+ writer.writeCharacters(path);
+ writer.writeEndElement();
+ }
+
+ writer.writeEndElement();
+
+ writer.flush();
+ }
+
+ public synchronized void writeEndLog()
+ {
+ try
+ {
+ writer.writeStartElement("finish-time");
+ writer.writeCharacters(JCRDateFormat.format(finishedTime));
+ writer.writeEndElement();
+
+ writer.writeEndElement();
+ writer.writeEndDocument();
+ writer.flush();
+ }
+ catch (Exception e)
+ {
+ logger.error("Can't write end log", e);
+ }
+ }
+ }
+
+ private class LogReader
+ {
+ protected Log logger = ExoLogger.getLogger("ext.LogWriter");
+
+ private File logFile;
+
+ private XMLStreamReader reader;
+
+ public LogReader(File logFile) throws FileNotFoundException, XMLStreamException, FactoryConfigurationError
+ {
+ this.logFile = logFile;
+ reader = XMLInputFactory.newInstance().createXMLStreamReader(new FileInputStream(logFile));
+ }
+
+ public void readLogFile() throws XMLStreamException, MalformedURLException, ValueFormatException
+ {
+ boolean endDocument = false;
+
+ while (!endDocument)
+ {
+ int eventCode = reader.next();
+ switch (eventCode)
+ {
+
+ case StartElement.START_ELEMENT :
+ String name = reader.getLocalName();
+
+ if (name.equals("system-workspace"))
+ workspaceSystem = readContent();
+
+ if (name.equals("workspaces-backup-info"))
+ workspaceBackupsInfo = readWorkspaceBackupInfo();
+
+ if (name.equals("start-time"))
+ startedTime = JCRDateFormat.parse(readContent());
+
+ if (name.equals("finish-time"))
+ finishedTime = JCRDateFormat.parse(readContent());
+
+ break;
+
+ case StartElement.END_DOCUMENT :
+ endDocument = true;
+ break;
+ }
+ }
+ }
+
+ private List<String> readWorkspaceBackupInfo() throws XMLStreamException
+ {
+ List<String> wsBackupInfo = new ArrayList<String>();
+
+ boolean endWorkspaceBackupInfo = false;
+
+ while (!endWorkspaceBackupInfo)
+ {
+ int eventCode = reader.next();
+ switch (eventCode)
+ {
+
+ case StartElement.START_ELEMENT :
+ String name = reader.getLocalName();
+
+ if (name.equals("url"))
+ wsBackupInfo.add(readContent());
+
+ break;
+
+ case StartElement.END_ELEMENT :
+ String tagName = reader.getLocalName();
+
+ if (tagName.equals("workspaces-backup-info"))
+ endWorkspaceBackupInfo = true;
+ break;
+ }
+ }
+
+ return wsBackupInfo;
+ }
+
+ private String readContent() throws XMLStreamException
+ {
+ String content = null;
+
+ int eventCode = reader.next();
+
+ if (eventCode == StartElement.CHARACTERS)
+ content = reader.getText();
+
+ return content;
+ }
+ }
+
+ protected static Log logger = ExoLogger.getLogger("ext.BackupChainLog");
+
+ private static final String PREFIX = "repository-backup-";
+
+ private static final String SUFFIX = ".xml";
+
+ private File log;
+
+ private LogWriter logWriter;
+
+ private LogReader logReader;
+
+ private RepositoryBackupConfig config;
+
+ private String backupId;
+
+ private Calendar startedTime;
+
+ private Calendar finishedTime;
+
+ private boolean finalized;
+
+ private List<String> workspaceBackupsInfo;
+
+ private String workspaceSystem;
+
+ /**
+ * @param logDirectory
+ * @param config
+ * @param systemWorkspace
+ * @param wsLogFilePathList
+ * @param backupId
+ * @param startTime
+ * @throws BackupOperationException
+ */
+ public RepositoryBackupChainLog(File logDirectory, RepositoryBackupConfig config, String systemWorkspace, List<String> wsLogFilePathList,
+ String backupId, Calendar startTime) throws BackupOperationException
+ {
+ try
+ {
+ this.finalized = false;
+ this.log = new File(logDirectory.getCanonicalPath() + File.separator + (PREFIX + backupId + SUFFIX));
+ this.log.createNewFile();
+ this.backupId = backupId;
+ this.config = config;
+ this.startedTime = Calendar.getInstance();
+
+ logWriter = new LogWriter(log);
+ logWriter.writeSystemWorkspaceName(systemWorkspace);
+ logWriter.writeBackupsPath(wsLogFilePathList);
+
+ this.workspaceBackupsInfo = wsLogFilePathList;
+ this.workspaceSystem = systemWorkspace;
+ }
+ catch (IOException e)
+ {
+ throw new BackupOperationException("Can not create backup log ...", e);
+ }
+ catch (XMLStreamException e)
+ {
+ throw new BackupOperationException("Can not create backup log ...", e);
+ }
+ catch (FactoryConfigurationError e)
+ {
+ throw new BackupOperationException("Can not create backup log ...", e);
+ }
+ }
+
+ /**
+ * @param log
+ * @throws BackupOperationException
+ */
+ public RepositoryBackupChainLog(File log) throws BackupOperationException
+ {
+ this.log = log;
+ this.backupId = log.getName().replaceAll(PREFIX, "").replaceAll(SUFFIX, "");
+
+ try
+ {
+ logReader = new LogReader(log);
+ logReader.readLogFile();
+ }
+ catch (FileNotFoundException e)
+ {
+ throw new BackupOperationException("Can not read RepositoryBackupChainLog from file ...", e);
+ }
+ catch (XMLStreamException e)
+ {
+ throw new BackupOperationException("Can not read RepositoryBackupChainLog from file ...", e);
+ }
+ catch (FactoryConfigurationError e)
+ {
+ throw new BackupOperationException("Can not read RepositoryBackupChainLog from file ...", e);
+ }
+ catch (MalformedURLException e)
+ {
+ throw new BackupOperationException("Can not read RepositoryBackupChainLog from file ...", e);
+ }
+ catch (ValueFormatException e)
+ {
+ throw new BackupOperationException("Can not read RepositoryBackupChainLog from file ...", e);
+ }
+ }
+
+ /**
+ * Getting log file path.
+ *
+ * @return String
+ * return the path to backup log
+ */
+ public String getLogFilePath()
+ {
+ return log.getAbsolutePath();
+ }
+
+ /**
+ * Getting repository backup configuration.
+ *
+ * @return ReposiotoryBackupConfig
+ * return the repository backup configuration
+ */
+ public RepositoryBackupConfig getBackupConfig()
+ {
+ return config;
+ }
+
+ /**
+ * Getting the started time.
+ *
+ * @return Calendar
+ * return the started time
+ */
+ public Calendar getStartedTime()
+ {
+ return startedTime;
+ }
+
+ /**
+ * Getting the finished time.
+ *
+ * @return Calendar
+ * return the finished time
+ */
+ public Calendar getFinishedTime()
+ {
+ return finishedTime;
+ }
+
+ public boolean isFinilized()
+ {
+ return finalized;
+ }
+
+ /**
+ * Finalize log.
+ *
+ */
+ public void endLog()
+ {
+ finishedTime = Calendar.getInstance();
+ finalized = true;
+ logWriter.writeEndLog();
+ }
+
+ /**
+ * Getting the system workspace name.
+ *
+ * @return String
+ * return the system workspace name.
+ */
+ public String getSystemWorkspace()
+ {
+ return workspaceSystem;
+ }
+
+ /**
+ * Getting the workspace backups info.
+ *
+ * @return Collection
+ * return the list with path to backups.
+ */
+ public List<String> getWorkspaceBackupsInfo()
+ {
+ return workspaceBackupsInfo;
+ }
+
+ /**
+ * Getting the backup id.
+ *
+ * @return int
+ * return the backup id
+ */
+ public String getBackupId()
+ {
+ return backupId;
+ }
+
+}
Property changes on: jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/RepositoryBackupChainLog.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/RepositoryBackupConfig.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/RepositoryBackupConfig.java (rev 0)
+++ jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/RepositoryBackupConfig.java 2010-03-24 14:18:24 UTC (rev 2108)
@@ -0,0 +1,166 @@
+/*
+ * 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 java.io.File;
+
+/**
+ * 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 RepositoryBackupConfig
+{
+ /**
+ * The backup type.
+ */
+ private int backupType;
+
+ /**
+ * The repository name.
+ */
+ private String repository;
+
+ /**
+ * The incremental job period.
+ */
+ private long incrementalJobPeriod;
+
+ /**
+ * The incremental job number (the repetition numper).
+ */
+ private int incrementalJobNumber;
+
+ /**
+ * The backup directory.
+ */
+ private File backupDir;
+
+ /**
+ * Getting incremental job period.
+ *
+ * @return long
+ * return incremental job period.
+ */
+ public long getIncrementalJobPeriod()
+ {
+ return incrementalJobPeriod;
+ }
+
+ /**
+ * Setting incremental job period.
+ *
+ * @param incrementalJobPeriod
+ * long, the incremental job period
+ */
+ public void setIncrementalJobPeriod(long incrementalJobPeriod)
+ {
+ this.incrementalJobPeriod = incrementalJobPeriod;
+ }
+
+ /**
+ * Getting incremental job period (the repetition period).
+ *
+ * @return int
+ * return incremental job period
+ */
+ public int getIncrementalJobNumber()
+ {
+ return incrementalJobNumber;
+ }
+
+ /**
+ * Setting incremental job number (the repetition period).
+ *
+ * @param incrementalJobNumber
+ * int, the incremental job number
+ *
+ */
+ public void setIncrementalJobNumber(int incrementalJobNumber)
+ {
+ this.incrementalJobNumber = incrementalJobNumber;
+ }
+
+ /**
+ * Getting the repository name.
+ *
+ * @return String
+ * return the repository name
+ */
+ public String getRepository()
+ {
+ return repository;
+ }
+
+ /**
+ * Setting the repository name.
+ *
+ * @param repository
+ * String, the repository name
+ */
+ public void setRepository(String repository)
+ {
+ this.repository = repository;
+ }
+
+ /**
+ * Getting backup directory.
+ *
+ * @return File
+ * return c
+ */
+ public File getBackupDir()
+ {
+ return backupDir;
+ }
+
+ /**
+ * Setting the backup directory.
+ *
+ * @param backupDir
+ * File, the backup directory
+ */
+ public void setBackupDir(File backupDir)
+ {
+ this.backupDir = backupDir;
+ }
+
+ /**
+ * Getting the backup type.
+ *
+ * @return int
+ * return the backup type
+ */
+ public int getBackupType()
+ {
+ return backupType;
+ }
+
+ /**
+ * Setting the backup type.
+ *
+ * @param backupType
+ * int, the backup type
+ */
+ public void setBackupType(int backupType)
+ {
+ this.backupType = backupType;
+ }
+}
Property changes on: jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/RepositoryBackupConfig.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/RepositoryRestoreExeption.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/RepositoryRestoreExeption.java (rev 0)
+++ jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/RepositoryRestoreExeption.java 2010-03-24 14:18:24 UTC (rev 2108)
@@ -0,0 +1,45 @@
+/*
+ * 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 javax.jcr.InvalidItemStateException;
+
+/**
+ * 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 RepositoryRestoreExeption
+ extends BackupConfigurationException
+{
+
+ /**
+ * RepositoryRestoreExeption constructor.
+ *
+ * @param message
+ * String, the exception message
+ * @param e
+ * Throwable, the cause exception
+ */
+ public RepositoryRestoreExeption(String message, Throwable e)
+ {
+ super(message, e);
+ }
+}
Property changes on: jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/RepositoryRestoreExeption.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/BackupChainImpl.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/BackupChainImpl.java 2010-03-24 13:11:41 UTC (rev 2107)
+++ jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/BackupChainImpl.java 2010-03-24 14:18:24 UTC (rev 2108)
@@ -247,6 +247,14 @@
{
return fullBackup.getState();
}
+
+ public int getIncrementalBackupState()
+ {
+ if (incrementalBackup == null)
+ throw new RuntimeException("The incremental bacup was not configured. Only full backup.");
+
+ return incrementalBackup.getState();
+ }
public String getLogFilePath()
{
Modified: jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/BackupManagerImpl.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/BackupManagerImpl.java 2010-03-24 13:11:41 UTC (rev 2107)
+++ jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/BackupManagerImpl.java 2010-03-24 14:18:24 UTC (rev 2108)
@@ -18,13 +18,17 @@
*/
package org.exoplatform.services.jcr.ext.backup.impl;
+import org.apache.commons.collections.map.HashedMap;
+import org.bouncycastle.jce.interfaces.BCKeyStore;
import org.exoplatform.container.xml.InitParams;
import org.exoplatform.container.xml.PropertiesParam;
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.SimpleParameterEntry;
import org.exoplatform.services.jcr.config.WorkspaceEntry;
import org.exoplatform.services.jcr.config.WorkspaceInitializerEntry;
+import org.exoplatform.services.jcr.core.ManageableRepository;
import org.exoplatform.services.jcr.dataflow.ChangesLogIterator;
import org.exoplatform.services.jcr.dataflow.ItemState;
import org.exoplatform.services.jcr.dataflow.PlainChangesLog;
@@ -40,6 +44,9 @@
import org.exoplatform.services.jcr.ext.backup.BackupManager;
import org.exoplatform.services.jcr.ext.backup.BackupOperationException;
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.common.SessionProvider;
import org.exoplatform.services.jcr.ext.registry.RegistryEntry;
import org.exoplatform.services.jcr.ext.registry.RegistryService;
@@ -75,6 +82,7 @@
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import javax.jcr.PathNotFoundException;
@@ -122,11 +130,18 @@
private String incrementalBackupType;
private final Set<BackupChain> currentBackups;
+
+ private final Set<RepositoryBackupChain> currentRepositoryBackups;
/**
- * The list of restore job.
+ * The list of workspace restore job.
*/
private List<JobWorkspaceRestore> restoreJobs;
+
+ /**
+ * The list of repository restore job.
+ */
+ private List<JobRepositoryRestore> restoreRepositoryJobs;
private InitParams initParams;
@@ -329,6 +344,8 @@
this.initParams = initParams;
currentBackups = Collections.synchronizedSet(new HashSet<BackupChain>());
+
+ currentRepositoryBackups = Collections.synchronizedSet(new HashSet<RepositoryBackupChain>());
fileCleaner = new FileCleaner(10000);
@@ -337,6 +354,7 @@
scheduler = new BackupScheduler(this, messages);
this.restoreJobs = new ArrayList<JobWorkspaceRestore>();
+ this.restoreRepositoryJobs = new ArrayList<JobRepositoryRestore>();
this.stopper = new AutoStopper();
this.stopper.start();
}
@@ -411,10 +429,10 @@
BackupConfig config = log.getBackupConfig();
String reposytoryName = (repositoryName == null ? config.getRepository() : repositoryName);
- String workspaseName = workspaceEntry.getName();
+ String workspaceName = workspaceEntry.getName();
// ws should be registered not created
- if (!workspaceAlreadyExist(reposytoryName, workspaseName))
+ if (!workspaceAlreadyExist(reposytoryName, workspaceName))
{
for (int i = 0; i < list.size(); i++)
@@ -423,7 +441,7 @@
{
try
{
- fullRestore(list.get(i).getURL().getPath(), reposytoryName, workspaseName, workspaceEntry);
+ fullRestore(list.get(i).getURL().getPath(), reposytoryName, workspaceName, workspaceEntry);
}
catch (FileNotFoundException e)
{
@@ -440,7 +458,7 @@
// events which are logged in chan log one after another
try
{
- incrementalRestore(list.get(i).getURL().getPath(), reposytoryName, workspaseName);
+ incrementalRestore(list.get(i).getURL().getPath(), reposytoryName, workspaceName);
}
catch (FileNotFoundException e)
{
@@ -458,7 +476,7 @@
}
}
else
- throw new BackupConfigurationException("Workspace should exists " + workspaseName);
+ throw new BackupConfigurationException("Workspace should exists " + workspaceName);
}
protected void restoreOverInitializer(BackupChainLog log, String repositoryName, WorkspaceEntry workspaceEntry)
@@ -470,10 +488,10 @@
BackupConfig config = log.getBackupConfig();
String reposytoryName = (repositoryName == null ? config.getRepository() : repositoryName);
- String workspaseName = workspaceEntry.getName();
+ String workspaceName = workspaceEntry.getName();
// ws should be registered not created
- if (!workspaceAlreadyExist(reposytoryName, workspaseName))
+ if (!workspaceAlreadyExist(reposytoryName, workspaceName))
{
for (int i = 0; i < list.size(); i++)
@@ -501,7 +519,7 @@
// events which are logged in chan log one after another
try
{
- incrementalRestore(list.get(i).getURL().getPath(), reposytoryName, workspaseName);
+ incrementalRestore(list.get(i).getURL().getPath(), reposytoryName, workspaceName);
}
catch (FileNotFoundException e)
{
@@ -519,7 +537,7 @@
}
}
else
- throw new BackupConfigurationException("Workspace should exists " + workspaseName);
+ throw new BackupConfigurationException("Workspace should exists " + workspaceName);
}
private boolean workspaceAlreadyExist(String repository, String workspace) throws RepositoryException,
@@ -557,20 +575,12 @@
BackupChain startBackup(BackupConfig config, BackupJobListener jobListener) throws BackupOperationException,
BackupConfigurationException, RepositoryException, RepositoryConfigurationException
{
+ validateBackupConfig(config);
- if (config.getIncrementalJobPeriod() < 0)
- throw new BackupConfigurationException("The parameter 'incremental job period' can not be negative.");
-
- if (config.getIncrementalJobNumber() < 0)
- throw new BackupConfigurationException("The parameter 'incremental job number' can not be negative.");
-
- if (config.getIncrementalJobPeriod() == 0 && config.getBackupType() == BackupManager.FULL_AND_INCREMENTAL)
- config.setIncrementalJobPeriod(defaultIncrementalJobPeriod);
-
BackupChain bchain =
- new BackupChainImpl(config, logsDirectory, repoService.getRepository(config.getRepository()),
- fullBackupType, incrementalBackupType, IdGenerator.generate());
-
+ new BackupChainImpl(config, logsDirectory, repoService.getRepository(config.getRepository()),
+ fullBackupType, incrementalBackupType, IdGenerator.generate());
+
bchain.addListener(messagesListener);
bchain.addListener(jobListener);
@@ -579,7 +589,29 @@
return bchain;
}
+
+ /**
+ * Initialize backup chain to workspace backup.
+ *
+ * @param config
+ * @return
+ * @throws BackupOperationException
+ * @throws BackupConfigurationException
+ * @throws RepositoryException
+ * @throws RepositoryConfigurationException
+ */
+ private void validateBackupConfig(RepositoryBackupConfig config) throws BackupConfigurationException
+ {
+ if (config.getIncrementalJobPeriod() < 0)
+ throw new BackupConfigurationException("The parameter 'incremental job period' can not be negative.");
+ if (config.getIncrementalJobNumber() < 0)
+ throw new BackupConfigurationException("The parameter 'incremental job number' can not be negative.");
+
+ if (config.getIncrementalJobPeriod() == 0 && config.getBackupType() == BackupManager.FULL_AND_INCREMENTAL)
+ config.setIncrementalJobPeriod(defaultIncrementalJobPeriod);
+ }
+
/**
* {@inheritDoc}
*/
@@ -1160,7 +1192,32 @@
return null;
}
+
+ /**
+ * {@inheritDoc}
+ */
+ public JobRepositoryRestore getLastRepositoryRestore(String repositoryName)
+ {
+
+ for (int i = restoreRepositoryJobs.size() - 1; i >= 0; i--)
+ {
+ JobRepositoryRestore job = restoreRepositoryJobs.get(i);
+ if (repositoryName.equals(job.getRepositoryName()))
+ {
+ return job;
+
+ }
+ }
+
+ return null;
+ }
+
+ public List<JobRepositoryRestore> getRepositoryRestores()
+ {
+ return restoreRepositoryJobs;
+ }
+
/**
* {@inheritDoc}
*/
@@ -1180,4 +1237,154 @@
this.restoreOverInitializer(log, repositoryName, workspaceEntry);
}
}
+
+ /**
+ * {@inheritDoc}
+ */
+ public void restore(RepositoryBackupChainLog log, RepositoryEntry repositoryEntry, boolean asynchronous)
+ throws BackupOperationException, BackupConfigurationException, RepositoryException,
+ RepositoryConfigurationException
+ {
+ this.restore(log, repositoryEntry, null, asynchronous);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void restore(RepositoryBackupChainLog rblog, RepositoryEntry repositoryEntry,
+ Map<String, String> workspaceNamesCorrespondMap, boolean asynchronous) throws BackupOperationException,
+ BackupConfigurationException, RepositoryException, RepositoryConfigurationException
+ {
+ Map<String, 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 (workspaceNamesCorrespondMap == null)
+ {
+ 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()));
+ }
+ }
+ }
+ else
+ {
+ if (!repositoryEntry.getSystemWorkspaceName().equals(workspaceNamesCorrespondMap.get(rblog.getSystemWorkspace())))
+ {
+ throw new BackupConfigurationException("The backup to system workspace is not system workspace in repository entry: " + repositoryEntry.getSystemWorkspaceName() + " is not equal " + workspaceNamesCorrespondMap.get(rblog.getSystemWorkspace()));
+ }
+
+ if (workspaceNamesCorrespondMap.size() != repositoryEntry.getWorkspaceEntries().size())
+ {
+ throw new BackupConfigurationException("The repository entry is contains more or less workspace entry than backups of workspace in " + rblog.getLogFilePath());
+ }
+
+ for (WorkspaceEntry wsEntry : repositoryEntry.getWorkspaceEntries())
+ {
+ if (!workspaceNamesCorrespondMap.containsKey(wsEntry.getName()))
+ {
+ throw new BackupConfigurationException("The workspace '" + wsEntry.getName() + "' is not found workspaceNamesCorrespondMap : " + workspaceNamesCorrespondMap.keySet());
+ }
+ else 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()));
+ }
+ }
+ }
+
+ JobRepositoryRestore jobRepositoryRestore =
+ new JobRepositoryRestore(repoService, this, repositoryEntry, workspacesMapping);
+
+ if (asynchronous)
+ {
+ restoreRepositoryJobs.add(jobRepositoryRestore);
+ jobRepositoryRestore.start();
+ }
+ else
+ {
+ jobRepositoryRestore.restore();
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public RepositoryBackupChain startBackup(RepositoryBackupConfig config) throws BackupOperationException,
+ BackupConfigurationException, RepositoryException, RepositoryConfigurationException
+ {
+ validateBackupConfig(config);
+
+ ManageableRepository repository = repoService.getRepository(config.getRepository());
+
+ File dir =
+ new File(config.getBackupDir() + File.separator + "repository_" + config.getRepository() + "_backup_"
+ + System.currentTimeMillis());
+ dir.mkdir();
+ config.setBackupDir(dir);
+
+ RepositoryBackupChain repositoryBackupChain =
+ new RepositoryBackupChainImpl(config, logsDirectory, repository, fullBackupType, incrementalBackupType,
+ IdGenerator.generate());
+
+ repositoryBackupChain.startBackup();
+
+ currentRepositoryBackups.add(repositoryBackupChain);
+
+ return repositoryBackupChain;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void stopBackup(RepositoryBackupChain backup)
+ {
+ backup.stopBackup();
+ currentRepositoryBackups.remove(backup);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public RepositoryBackupChain findRepositoryBackup(String repository)
+ {
+ Iterator<RepositoryBackupChain> it = currentRepositoryBackups.iterator();
+ while (it.hasNext())
+ {
+ RepositoryBackupChain chain = it.next();
+ if (repository.equals(chain.getBackupConfig().getRepository()))
+ return chain;
+ }
+ return null;
+ }
+
+ public Set<RepositoryBackupChain> getCurrentRepositoryBackups()
+ {
+ return currentRepositoryBackups;
+ }
}
Added: 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 (rev 0)
+++ jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/JobRepositoryRestore.java 2010-03-24 14:18:24 UTC (rev 2108)
@@ -0,0 +1,320 @@
+/*
+ * 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.util.ArrayList;
+import java.util.Calendar;
+import java.util.List;
+import java.util.Map;
+
+import javax.jcr.InvalidItemStateException;
+import javax.jcr.NoSuchWorkspaceException;
+import javax.jcr.RepositoryException;
+
+import org.exoplatform.services.jcr.RepositoryService;
+import org.exoplatform.services.jcr.config.RepositoryEntry;
+import org.exoplatform.services.jcr.config.SimpleParameterEntry;
+import org.exoplatform.services.jcr.config.WorkspaceEntry;
+import org.exoplatform.services.jcr.config.WorkspaceInitializerEntry;
+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.RepositoryRestoreExeption;
+import org.exoplatform.services.jcr.ext.backup.server.WorkspaceRestoreExeption;
+import org.exoplatform.services.jcr.impl.core.BackupWorkspaceInitializer;
+import org.exoplatform.services.jcr.impl.core.SessionRegistry;
+import org.exoplatform.services.jcr.impl.core.SysViewWorkspaceInitializer;
+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 JobRepositoryRestore extends Thread
+{
+ /**
+ * The apache logger.
+ */
+ private static Log log = ExoLogger.getLogger("ext.JobRepositoryRestore");
+
+ /**
+ * REPOSITORY_RESTORE_STARTED. The state of start restore.
+ */
+ public static final int REPOSITORY_RESTORE_STARTED = 1;
+
+ /**
+ * REPOSITORY_RESTORE_SUCCESSFUL. The state of restore successful.
+ */
+ public static final int REPOSITORY_RESTORE_SUCCESSFUL = 2;
+
+ /**
+ * REPOSITORY_RESTORE_FAIL. The state of restore fail.
+ */
+ public static final int REPOSITORY_RESTORE_FAIL = 3;
+
+ /**
+ * REPOSITORY_RESTORE_STARTED. The state of initialized restore.
+ */
+ public static final int REPOSITORY_RESTORE_INITIALIZED = 4;
+
+ /**
+ * The state of restore.
+ */
+ private int stateRestore;
+
+ /**
+ * The start time of restore.
+ */
+ private Calendar startTime;
+
+ /**
+ * The end time of restore.
+ */
+ private Calendar endTime;
+
+ /**
+ * The exception on restore.
+ */
+ private Throwable restoreException = null;
+
+ private RepositoryService repositoryService;
+
+ private BackupManagerImpl backupManager;
+
+ private RepositoryEntry repositoryEntry;
+
+ private Map<String, BackupChainLog> workspacesMapping;
+
+ public JobRepositoryRestore(RepositoryService repoService, BackupManagerImpl backupManagerImpl,
+ RepositoryEntry repositoryEntry, Map<String, BackupChainLog> workspacesMapping)
+ {
+ this.repositoryService = repoService;
+ this.backupManager = backupManagerImpl;
+ this.repositoryEntry = repositoryEntry;
+ this.workspacesMapping = workspacesMapping;
+ }
+
+ /**
+ * Will be restored the workspace.
+ * @throws RepositoryRestoreExeption
+ *
+ * @throws Throwable
+ * will be generated the Throwable
+ */
+ protected void restore() throws RepositoryRestoreExeption
+ {
+ List<WorkspaceEntry> originalWorkspaceEntrys = repositoryEntry.getWorkspaceEntries();
+
+ //Getting system workspace entry
+ WorkspaceEntry systemWorkspaceEntry = null;
+
+ for (WorkspaceEntry wsEntry : originalWorkspaceEntrys)
+ {
+ if (wsEntry.getName().equals(repositoryEntry.getSystemWorkspaceName()))
+ {
+ systemWorkspaceEntry = wsEntry;
+ break;
+ }
+ }
+
+ //getting backup cahil log to system workspace.
+ BackupChainLog systemBackupChainLog = workspacesMapping.get(systemWorkspaceEntry.getName());
+ File fullBackupFile = new File(systemBackupChainLog.getJobEntryInfos().get(0).getURL().getPath());
+
+ // set the initializer SysViewWorkspaceInitializer
+ WorkspaceInitializerEntry wiEntry = new WorkspaceInitializerEntry();
+ wiEntry.setType(BackupWorkspaceInitializer.class.getCanonicalName());
+
+ List<SimpleParameterEntry> wieParams = new ArrayList<SimpleParameterEntry>();
+ wieParams.add(new SimpleParameterEntry(BackupWorkspaceInitializer.RESTORE_PATH_PARAMETER, fullBackupFile.getParent()));
+
+ wiEntry.setParameters(wieParams);
+
+ // set initializer
+ systemWorkspaceEntry.setInitializer(wiEntry);
+
+ ArrayList<WorkspaceEntry> newEntries = new ArrayList<WorkspaceEntry>();
+ newEntries.add(systemWorkspaceEntry);
+
+ repositoryEntry.setWorkspaceEntries(newEntries);
+
+ String currennWorkspaceName = repositoryEntry.getSystemWorkspaceName();
+
+ boolean restored = true;
+ try
+ {
+ repositoryService.createRepository(repositoryEntry);
+ repositoryService.getConfig().retain(); // save configuration to persistence (file or persister)
+
+ for (WorkspaceEntry wsEntry : originalWorkspaceEntrys)
+ {
+ if (!(wsEntry.getName().equals(repositoryEntry.getSystemWorkspaceName())))
+ {
+ currennWorkspaceName = wsEntry.getName();
+ backupManager.restore(workspacesMapping.get(wsEntry.getName()), repositoryEntry.getName(), wsEntry, false);
+ }
+ }
+ }
+ catch (InvalidItemStateException e)
+ {
+ restored = false;
+ throw new RepositoryRestoreExeption("Workspace '" + "/" + repositoryEntry.getName() + "/" + currennWorkspaceName
+ + "' can not be restored! There was database error!", e);
+
+ }
+ catch (Throwable t)
+ {
+ restored = false;
+ throw new RepositoryRestoreExeption("Workspace '" + "/" + repositoryEntry.getName() + "/" + currennWorkspaceName
+ + "' can not be restored!", t);
+
+ }
+ finally
+ {
+ if (!restored)
+ {
+ try
+ {
+ ManageableRepository mr = null;
+
+ try
+ {
+ mr = repositoryService.getRepository(repositoryEntry.getName());
+ }
+ catch (RepositoryException e)
+ {
+ // The repository not exist.
+ }
+
+ if (mr != null)
+ {
+ closeAllSession(mr);
+ repositoryService.removeRepository(repositoryEntry.getName());
+ repositoryService.getConfig().retain(); // save configuration to persistence (file or persister)
+ }
+ }
+ catch (Throwable thr)
+ {
+ throw new RepositoryRestoreExeption("Reprository '" + "/" + repositoryEntry.getName() +
+ "' can not be restored!", thr);
+ }
+ }
+ }
+ }
+
+ /**
+ * Close all open session in repository
+ *
+ * @param mr
+ *
+ * @throws NoSuchWorkspaceException
+ */
+ private void closeAllSession(ManageableRepository mr) throws NoSuchWorkspaceException
+ {
+ for (String wsName : mr.getWorkspaceNames())
+ {
+ if (!mr.canRemoveWorkspace(wsName))
+ {
+ WorkspaceContainerFacade wc = mr.getWorkspaceContainer(wsName);
+ SessionRegistry sessionRegistry = (SessionRegistry) wc.getComponent(SessionRegistry.class);
+ sessionRegistry.closeSessions(wsName);
+ }
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void run()
+ {
+
+ try
+ {
+ stateRestore = REPOSITORY_RESTORE_STARTED;
+ startTime = Calendar.getInstance();
+
+ restore();
+
+ stateRestore = REPOSITORY_RESTORE_SUCCESSFUL;
+ endTime = Calendar.getInstance();
+ }
+ catch (Throwable t)
+ {
+ stateRestore = REPOSITORY_RESTORE_FAIL;
+ restoreException = t;
+
+ log.error("The restore was fail", t);
+ }
+ }
+
+ /**
+ * getRestoreException.
+ *
+ * @return Throwable return the exception of repository restore.
+ */
+ public Throwable getRestoreException()
+ {
+ return restoreException;
+ }
+
+ /**
+ * getStateRestore.
+ *
+ * @return int return state of restore.
+ */
+ public int getStateRestore()
+ {
+ return stateRestore;
+ }
+
+ /**
+ * getBeginTime.
+ *
+ * @return Calendar return the start time of restore
+ */
+ public Calendar getStartTime()
+ {
+ return startTime;
+ }
+
+ /**
+ * getEndTime.
+ *
+ * @return Calendar return the end time of restore
+ */
+ public Calendar getEndTime()
+ {
+ return endTime;
+ }
+
+ /**
+ * getRepositoryName.
+ *
+ * @return String
+ * the name of destination repository
+ */
+ public String getRepositoryName()
+ {
+ return repositoryEntry.getName();
+ }
+}
Property changes on: jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/JobRepositoryRestore.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/RepositoryBackupChainImpl.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/RepositoryBackupChainImpl.java (rev 0)
+++ jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/RepositoryBackupChainImpl.java 2010-03-24 14:18:24 UTC (rev 2108)
@@ -0,0 +1,221 @@
+/*
+ * 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.util.ArrayList;
+import java.util.Calendar;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.exoplatform.services.jcr.config.WorkspaceEntry;
+import org.exoplatform.services.jcr.core.ManageableRepository;
+import org.exoplatform.services.jcr.ext.backup.BackupChain;
+import org.exoplatform.services.jcr.ext.backup.BackupConfig;
+import org.exoplatform.services.jcr.ext.backup.BackupConfigurationException;
+import org.exoplatform.services.jcr.ext.backup.BackupJob;
+import org.exoplatform.services.jcr.ext.backup.BackupManager;
+import org.exoplatform.services.jcr.ext.backup.BackupOperationException;
+import org.exoplatform.services.jcr.ext.backup.RepositoryBackupChain;
+import org.exoplatform.services.jcr.ext.backup.RepositoryBackupChainLog;
+import org.exoplatform.services.jcr.ext.backup.RepositoryBackupConfig;
+import org.exoplatform.services.jcr.util.IdGenerator;
+
+/**
+ * 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 RepositoryBackupChainImpl
+ implements RepositoryBackupChain
+{
+
+ private final RepositoryBackupConfig config;
+
+ private final Set<BackupChain> workspaceBackups;
+
+ private final RepositoryBackupChainLog repositoryChainLog;
+
+ private final String repositoryBackupId;
+
+ private final Calendar startTime;
+
+ private int state;
+
+ public RepositoryBackupChainImpl(RepositoryBackupConfig config, File logDirectory, ManageableRepository repository,
+ String fullBackupType, String incrementalBackupType, String repositoryBackupId) throws BackupOperationException,
+ BackupConfigurationException
+ {
+ this.config = config;
+ this.workspaceBackups = Collections.synchronizedSet(new HashSet<BackupChain>());
+ this.startTime = Calendar.getInstance();
+ this.repositoryBackupId = repositoryBackupId;
+
+ List<String> wsLogFilePathList = new ArrayList<String>();
+
+ for (WorkspaceEntry workspaceEntry : repository.getConfiguration().getWorkspaceEntries())
+ {
+ BackupConfig wsBackupConfig = new BackupConfig();
+ wsBackupConfig.setRepository(config.getRepository());
+ wsBackupConfig.setWorkspace(workspaceEntry.getName());
+ wsBackupConfig.setBackupDir(config.getBackupDir());
+ wsBackupConfig.setBackupType(config.getBackupType());
+ wsBackupConfig.setIncrementalJobNumber(config.getIncrementalJobNumber());
+ wsBackupConfig.setIncrementalJobPeriod(config.getIncrementalJobPeriod());
+
+ BackupChain bchain =
+ new BackupChainImpl(wsBackupConfig, config.getBackupDir(), repository,
+ fullBackupType, incrementalBackupType, IdGenerator.generate());
+
+ wsLogFilePathList.add(bchain.getLogFilePath());
+ workspaceBackups.add(bchain);
+ }
+
+ this.repositoryChainLog = new RepositoryBackupChainLog(logDirectory, this.config, repository.getConfiguration().getSystemWorkspaceName(), wsLogFilePathList, this.repositoryBackupId, startTime);
+
+ state = INITIALIZED;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getLogFilePath()
+ {
+ return repositoryChainLog.getLogFilePath();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public int getState()
+ {
+ if (state != FINISHED)
+ {
+ int fullBackupsState =-1;
+ int incrementalBackupsState = -1;
+
+ for (BackupChain bc : workspaceBackups)
+ {
+ fullBackupsState = bc.getFullBackupState();
+
+ if (bc.getBackupConfig().getBackupType() == BackupManager.FULL_AND_INCREMENTAL)
+ {
+ incrementalBackupsState = bc.getIncrementalBackupState();
+ }
+ }
+
+ if (config.getBackupType() == BackupManager.FULL_BACKUP_ONLY)
+ {
+ if (fullBackupsState == BackupJob.FINISHED)
+ {
+ state = FINISHED;
+ }
+ else
+ {
+ state = WORKING;
+ }
+ }
+ else
+ {
+ if (fullBackupsState == BackupJob.FINISHED && incrementalBackupsState == BackupJob.FINISHED)
+ {
+ state = FINISHED;
+ }
+ else if (fullBackupsState == BackupJob.FINISHED && incrementalBackupsState != BackupJob.WORKING)
+ {
+ state = FULL_BACKUP_FINISHED_INCREMENTAL_BACKUP_WORKING;
+ }
+
+ else
+ {
+ state = WORKING;
+ }
+ }
+ }
+
+ return state;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isFinished()
+ {
+ return this.getState() == FINISHED;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void startBackup()
+ {
+ for (BackupChain wsChain : workspaceBackups)
+ {
+ wsChain.startBackup();
+ }
+
+ state = WORKING;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void stopBackup()
+ {
+ if (state != INITIALIZED || this.getState() != FINISHED)
+ {
+ for (BackupChain wsChain : workspaceBackups)
+ {
+ wsChain.stopBackup();
+ }
+
+ repositoryChainLog.endLog();
+ }
+
+ state = this.getState();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getBackupId()
+ {
+ return repositoryBackupId;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Calendar getStartedTime()
+ {
+ return startTime;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public RepositoryBackupConfig getBackupConfig()
+ {
+ return config;
+ }
+
+}
Property changes on: jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/RepositoryBackupChainImpl.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/server/HTTPBackupAgent.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/server/HTTPBackupAgent.java 2010-03-24 13:11:41 UTC (rev 2107)
+++ jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/server/HTTPBackupAgent.java 2010-03-24 14:18:24 UTC (rev 2108)
@@ -762,7 +762,7 @@
@Produces(MediaType.APPLICATION_JSON)
@RolesAllowed("administrators")
@Path("/info/backup/{repo}/{ws}")
- public Response infoBackupByWorkspase(@PathParam("repo") String repository, @PathParam("ws") String workspace)
+ public Response infoBackupByWorkspace(@PathParam("repo") String repository, @PathParam("ws") String workspace)
{
try
{
Modified: jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/replication/test/ReplicationTestService.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/replication/test/ReplicationTestService.java 2010-03-24 13:11:41 UTC (rev 2107)
+++ jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/replication/test/ReplicationTestService.java 2010-03-24 14:18:24 UTC (rev 2108)
@@ -131,7 +131,7 @@
/**
* The move node by workspace.
*/
- public static final String WORKSPASE_MOVE = "workspaceMove";
+ public static final String WORKSPACE_MOVE = "workspaceMove";
/**
* The move node by session.
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-03-24 13:11:41 UTC (rev 2107)
+++ jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/AbstractBackupTestCase.java 2010-03-24 14:18:24 UTC (rev 2108)
@@ -18,33 +18,33 @@
*/
package org.exoplatform.services.jcr.ext.backup;
-import org.exoplatform.services.jcr.config.ContainerEntry;
-import org.exoplatform.services.jcr.config.QueryHandlerEntry;
-import org.exoplatform.services.jcr.config.RepositoryConfigurationException;
-import org.exoplatform.services.jcr.config.RepositoryEntry;
-import org.exoplatform.services.jcr.config.SimpleParameterEntry;
-import org.exoplatform.services.jcr.config.WorkspaceEntry;
-import org.exoplatform.services.jcr.ext.BaseStandaloneTest;
-import org.exoplatform.services.jcr.impl.core.RepositoryImpl;
-import org.exoplatform.services.jcr.impl.core.SessionImpl;
-
import java.io.File;
import java.io.FileFilter;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.Iterator;
+import java.util.Map;
import javax.jcr.ItemExistsException;
import javax.jcr.Node;
import javax.jcr.PathNotFoundException;
-import javax.jcr.Repository;
import javax.jcr.RepositoryException;
import javax.jcr.ValueFormatException;
import javax.jcr.lock.LockException;
import javax.jcr.nodetype.ConstraintViolationException;
import javax.jcr.version.VersionException;
+import org.exoplatform.services.jcr.config.ContainerEntry;
+import org.exoplatform.services.jcr.config.QueryHandlerEntry;
+import org.exoplatform.services.jcr.config.RepositoryConfigurationException;
+import org.exoplatform.services.jcr.config.RepositoryEntry;
+import org.exoplatform.services.jcr.config.SimpleParameterEntry;
+import org.exoplatform.services.jcr.config.WorkspaceEntry;
+import org.exoplatform.services.jcr.ext.BaseStandaloneTest;
+import org.exoplatform.services.jcr.impl.core.RepositoryImpl;
+import org.exoplatform.services.jcr.impl.core.SessionImpl;
+
/**
* Created by The eXo Platform SAS Author : Peter Nedonosko peter.nedonosko(a)exoplatform.com.ua
* 04.02.2008
@@ -85,13 +85,26 @@
throw new Exception("There are no BackupManagerImpl in configuration");
// ws1
- SessionImpl ws1 = (SessionImpl)repository.login(credentials, "ws1");
- ws1TestRoot = ws1.getRootNode().addNode("backupTest");
- ws1.save();
- ws1Session = ws1;
+
+ for (String wsName : repository.getWorkspaceNames())
+ {
+ if ("ws1".equals(wsName))
+ {
+ ws1Session = (SessionImpl) repository.login(credentials, "ws1");
+ ws1TestRoot = ws1Session.getRootNode().addNode("backupTest");
+ ws1Session.save();
+ addContent(ws1TestRoot, 1, 10, 1);
+
+ }
+ else
+ {
+ SessionImpl ws = (SessionImpl) repository.login(credentials, wsName);
+ Node wsTestRoot = ws.getRootNode().addNode("backupTest");
+ ws.save();
+ addContent(wsTestRoot, 1, 10, 1);
+ }
+ }
- addContent(ws1TestRoot, 1, 10, 1);
-
// ws2
ws2Session = (SessionImpl)repository.login(credentials, "ws2");
}
@@ -100,8 +113,21 @@
protected void tearDown() throws Exception
{
- ws1Session.getRootNode().getNode("backupTest").remove();
- ws1Session.save();
+ for (String wsName : repository.getWorkspaceNames())
+ {
+ if ("ws1".equals(wsName))
+ {
+ ws1Session = (SessionImpl) repository.login(credentials, "ws1");
+ ws1Session.getRootNode().getNode("backupTest").remove();
+ ws1Session.save();
+ }
+ else
+ {
+ SessionImpl ws = (SessionImpl)repository.login(credentials, wsName);
+ ws.getRootNode().getNode("backupTest").remove();
+ ws.save();
+ }
+ }
super.tearDown();
}
@@ -116,11 +142,7 @@
// container.getComponentInstanceOfType(RepositoryContainer.class);
ws1back.setUniqueName(((RepositoryImpl)ws1Session.getRepository()).getName() + "_" + ws1back.getName()); // EXOMAN
- Repository repository1;
-
ws1back.setAccessManager(ws1e.getAccessManager());
- ws1back.setAutoInitializedRootNt(ws1e.getAutoInitializedRootNt());
- ws1back.setAutoInitPermissions(ws1e.getAutoInitPermissions());
ws1back.setCache(ws1e.getCache());
ws1back.setContainer(ws1e.getContainer());
ws1back.setLockManager(ws1e.getLockManager());
@@ -129,7 +151,7 @@
ArrayList qParams = new ArrayList();
// qParams.add(new SimpleParameterEntry("indexDir", "target" + File.separator+ "temp" +
// File.separator +"index" + name));
- qParams.add(new SimpleParameterEntry("indexDir", "target" + File.separator + name));
+ qParams.add(new SimpleParameterEntry("indexDir", "target" + File.separator + name + System.currentTimeMillis()));
QueryHandlerEntry qEntry =
new QueryHandlerEntry("org.exoplatform.services.jcr.impl.core.query.lucene.SearchIndex", qParams);
@@ -144,7 +166,7 @@
if (newp.getName().equals("source-name"))
newp.setValue(sourceName);
else if (newp.getName().equals("swap-directory"))
- newp.setValue("target/temp/swap/" + name);
+ newp.setValue("target/temp/swap/" + name + System.currentTimeMillis());
params.add(newp);
}
@@ -155,7 +177,81 @@
return ws1back;
}
+
+ protected RepositoryEntry makeRepositoryEntry(String repoName, RepositoryEntry baseRepoEntry, String sourceName, Map<String, String> workspaceMapping)
+ {
+ ArrayList<WorkspaceEntry> wsEntries = new ArrayList<WorkspaceEntry>();
+
+ for (WorkspaceEntry wsEntry : baseRepoEntry.getWorkspaceEntries())
+ {
+ String newWorkspaceName = wsEntry.getName();
+ if (workspaceMapping != null)
+ {
+ newWorkspaceName = workspaceMapping.get(wsEntry.getName());
+ }
+
+ WorkspaceEntry newWSEntry = makeWorkspaceEntry(wsEntry, newWorkspaceName, repoName, sourceName);
+
+ wsEntries.add(newWSEntry);
+ }
+
+ RepositoryEntry newRepositoryEntry = new RepositoryEntry();
+
+ newRepositoryEntry.setSystemWorkspaceName(workspaceMapping == null ? baseRepoEntry.getSystemWorkspaceName() : workspaceMapping.get(baseRepoEntry.getSystemWorkspaceName()));
+ newRepositoryEntry.setAccessControl(baseRepoEntry.getAccessControl());
+ newRepositoryEntry.setAuthenticationPolicy(baseRepoEntry.getAuthenticationPolicy());
+ newRepositoryEntry.setDefaultWorkspaceName(workspaceMapping == null ? baseRepoEntry.getDefaultWorkspaceName() : workspaceMapping.get(baseRepoEntry.getDefaultWorkspaceName()));
+ newRepositoryEntry.setName(repoName);
+ newRepositoryEntry.setSecurityDomain(baseRepoEntry.getSecurityDomain());
+ newRepositoryEntry.setSessionTimeOut(baseRepoEntry.getSessionTimeOut());
+
+ newRepositoryEntry.setWorkspaceEntries(wsEntries);
+
+ return newRepositoryEntry;
+ }
+
+ protected WorkspaceEntry makeWorkspaceEntry(WorkspaceEntry baseWorkspaceEntry, String wsName, String repoName, String sourceName)
+ {
+ WorkspaceEntry ws1back = new WorkspaceEntry();
+ ws1back.setName(wsName);
+ ws1back.setUniqueName(repoName + "_" + ws1back.getName());
+ ws1back.setAccessManager(baseWorkspaceEntry.getAccessManager());
+ ws1back.setCache(baseWorkspaceEntry.getCache());
+ ws1back.setContainer(baseWorkspaceEntry.getContainer());
+ ws1back.setLockManager(baseWorkspaceEntry.getLockManager());
+
+ // 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);
+
+ ArrayList params = new ArrayList();
+ for (Iterator i = ws1back.getContainer().getParameters().iterator(); i.hasNext();)
+ {
+ SimpleParameterEntry p = (SimpleParameterEntry)i.next();
+ SimpleParameterEntry newp = new SimpleParameterEntry(p.getName(), p.getValue());
+
+ if (newp.getName().equals("source-name"))
+ newp.setValue(sourceName);
+ else if (newp.getName().equals("swap-directory"))
+ newp.setValue("target/temp/swap/" + repoName + "_" + wsName);
+ else if (newp.getName().equals("multi-db"))
+ newp.setValue("false");
+
+ params.add(newp);
+ }
+
+ ContainerEntry ce =
+ new ContainerEntry("org.exoplatform.services.jcr.impl.storage.jdbc.JDBCWorkspaceDataContainer", params);
+ ws1back.setContainer(ce);
+
+ return ws1back;
+ }
+
protected void restoreAndCheck(String workspaceName, String datasourceName, String backupLogFilePath, File backDir,
int startIndex, int stopIndex) throws RepositoryConfigurationException, RepositoryException,
BackupOperationException, BackupConfigurationException
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-03-24 13:11:41 UTC (rev 2107)
+++ jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/TestBackupManager.java 2010-03-24 14:18:24 UTC (rev 2108)
@@ -18,15 +18,20 @@
*/
package org.exoplatform.services.jcr.ext.backup;
+import org.apache.commons.collections.map.HashedMap;
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.JobRepositoryRestore;
import org.exoplatform.services.jcr.ext.backup.impl.JobWorkspaceRestore;
+import org.exoplatform.services.jcr.impl.core.RepositoryImpl;
import org.exoplatform.services.jcr.impl.core.SessionImpl;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
+import java.util.Map;
import javax.jcr.Node;
import javax.jcr.lock.Lock;
@@ -498,7 +503,7 @@
SessionImpl sessionWS1 = (SessionImpl)repository.login(credentials, "ws3");
sessionWS1.getRootNode().addNode("asdasdasda", "nt:unstructured")
- .setProperty("data", "data_1"/*new FileInputStream(createBLOBTempFile(1024))*/);
+ .setProperty("data", /*"data_1"*/new FileInputStream(createBLOBTempFile(1024)));
sessionWS1.save();
// 1-st backup
@@ -536,7 +541,7 @@
// add date to restored workspace
back1.getRootNode().addNode("gdfgrghfhf", "nt:unstructured")
- .setProperty("data", "data_2"/*new FileInputStream(createBLOBTempFile(1024))*/);
+ .setProperty("data", /*"data_2"*/new FileInputStream(createBLOBTempFile(1024)));
back1.save();
}
else
@@ -734,5 +739,285 @@
else
fail("There are no backup files in " + backDir.getAbsolutePath());
}
+
+
+ public void testRepositoryFullBackupRestore() 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 re = (RepositoryEntry)ws1Session.getContainer().getComponentInstanceOfType(RepositoryEntry.class);
+
+ String newRepositoryName = "repo_restored_1";
+ RepositoryEntry newRepositoryEntry = makeRepositoryEntry(newRepositoryName, re, "jdbcjcr_to_repository_restore_1", null);
+
+ File backLog = new File(bch.getLogFilePath());
+ if (backLog.exists())
+ {
+ RepositoryBackupChainLog bchLog = new RepositoryBackupChainLog(backLog);
+
+ assertNotNull(bchLog.getStartedTime());
+ assertNotNull(bchLog.getFinishedTime());
+
+ backup.restore(bchLog, newRepositoryEntry, false);
+
+ // check
+ ManageableRepository restoredRepository = repositoryService.getRepository(newRepositoryName);
+
+ for (String wsName : restoredRepository.getWorkspaceNames())
+ {
+ SessionImpl back1 = null;
+ try
+ {
+ back1 = (SessionImpl)repository.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 testRepositoryFullBackupAsynchronusRestore() 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 re = (RepositoryEntry)ws1Session.getContainer().getComponentInstanceOfType(RepositoryEntry.class);
+
+ String newRepositoryName = "repo_restored_2";
+ RepositoryEntry newRepositoryEntry = makeRepositoryEntry(newRepositoryName, re, "jdbcjcr_to_repository_restore_1", null);
+
+ File backLog = new File(bch.getLogFilePath());
+ if (backLog.exists())
+ {
+ RepositoryBackupChainLog bchLog = new RepositoryBackupChainLog(backLog);
+
+ assertNotNull(bchLog.getStartedTime());
+ assertNotNull(bchLog.getFinishedTime());
+
+ backup.restore(bchLog, newRepositoryEntry, true);
+
+ JobRepositoryRestore job = backup.getLastRepositoryRestore(newRepositoryName);
+
+ while (job.getStateRestore() != JobRepositoryRestore.REPOSITORY_RESTORE_SUCCESSFUL
+ || job.getStateRestore() == JobRepositoryRestore.REPOSITORY_RESTORE_FAIL)
+ {
+ Thread.yield();
+ Thread.sleep(50);
+ }
+
+ // check
+ ManageableRepository restoredRepository = repositoryService.getRepository(newRepositoryName);
+
+ for (String wsName : restoredRepository.getWorkspaceNames())
+ {
+ SessionImpl back1 = null;
+ try
+ {
+ back1 = (SessionImpl)repository.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 testRepositoryFullBackupAsynchronusRestoreWorkspaceMapping() 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 re = (RepositoryEntry)ws1Session.getContainer().getComponentInstanceOfType(RepositoryEntry.class);
+
+ String newRepositoryName = "repo_restored_3";
+ RepositoryEntry newRepositoryEntry = makeRepositoryEntry(newRepositoryName, re, "jdbcjcr_to_repository_restore_1", null);
+
+ // create workspace mappingS
+ Map<String, String> workspaceMapping = new HashedMap();
+ for (WorkspaceEntry we : newRepositoryEntry.getWorkspaceEntries())
+ {
+ workspaceMapping.put(we.getName(), we.getName() + "_mapped");
+ }
+
+ // Change workspaeNames
+ for (WorkspaceEntry we : newRepositoryEntry.getWorkspaceEntries())
+ {
+ if (newRepositoryEntry.getSystemWorkspaceName().equals(we.getName()))
+ {
+ newRepositoryEntry.setSystemWorkspaceName(workspaceMapping.get(we.getName()));
+ newRepositoryEntry.setDefaultWorkspaceName(workspaceMapping.get(we.getName()));
+ }
+
+ we.setName(workspaceMapping.get(we.getName()));
+ we.setUniqueName(we.getUniqueName() + workspaceMapping.get(we.getName()));
+ }
+
+ File backLog = new File(bch.getLogFilePath());
+ if (backLog.exists())
+ {
+ RepositoryBackupChainLog bchLog = new RepositoryBackupChainLog(backLog);
+
+ assertNotNull(bchLog.getStartedTime());
+ assertNotNull(bchLog.getFinishedTime());
+
+ backup.restore(bchLog, newRepositoryEntry, workspaceMapping,true);
+
+ JobRepositoryRestore job = backup.getLastRepositoryRestore(newRepositoryName);
+
+ while (job.getStateRestore() != JobRepositoryRestore.REPOSITORY_RESTORE_SUCCESSFUL
+ || job.getStateRestore() == JobRepositoryRestore.REPOSITORY_RESTORE_FAIL)
+ {
+ Thread.yield();
+ Thread.sleep(50);
+ }
+
+ // check
+ ManageableRepository restoredRepository = repositoryService.getRepository(newRepositoryName);
+
+ for (String wsName : restoredRepository.getWorkspaceNames())
+ {
+ SessionImpl back1 = null;
+ try
+ {
+ back1 = (SessionImpl)repository.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());
+ }
+ 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 testAutoStopRepositoryBackupIncrRepetion() throws Exception
+ {
+ // backup
+ File backDir = new File("target/backup/" + repository.getName() + "123");
+ backDir.mkdirs();
+
+ RepositoryBackupConfig config = new RepositoryBackupConfig();
+ config.setRepository(repository.getName());
+ config.setBackupType(BackupManager.FULL_AND_INCREMENTAL);
+ config.setBackupDir(backDir);
+ config.setIncrementalJobPeriod(4);
+ config.setIncrementalJobNumber(2);
+
+ final RepositoryBackupChain bch = backup.startBackup(config);
+
+ Thread.sleep(20000);
+
+ assertTrue(bch.isFinished());
+
+ for (RepositoryBackupChain chain : backup.getCurrentRepositoryBackups())
+ if (bch.getBackupId().equals(chain.getBackupId()))
+ fail("The backup with id '" + chain.getBackupId() + "' should not be active");
+ }*/
}
Modified: jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/repository/RestRepositoryServiceTest.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/repository/RestRepositoryServiceTest.java 2010-03-24 13:11:41 UTC (rev 2107)
+++ jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/repository/RestRepositoryServiceTest.java 2010-03-24 14:18:24 UTC (rev 2108)
@@ -205,6 +205,8 @@
new ContainerRequestUserRole("POST", new URI(REST_REPOSITORY_SERVICE_PATH
+ RestRepositoryService.Constants.OperationType.CREATE_REPOSITORY), new URI(""),
new ByteArrayInputStream(json.toString().getBytes("UTF-8")), new InputHeadersMap(headers));
+
+ System.out.print("testCreateRepository : " +json.toString());
ByteArrayContainerResponseWriter responseWriter = new ByteArrayContainerResponseWriter();
ContainerResponse cres = new ContainerResponse(responseWriter);
@@ -239,6 +241,8 @@
+ RestRepositoryService.Constants.OperationType.CREATE_WORKSPACE + "/"
+ rName), new URI(""),
new ByteArrayInputStream(json.toString().getBytes("UTF-8")), new InputHeadersMap(headers));
+
+ System.out.print("testCreateWorkspace : " +json.toString());
ByteArrayContainerResponseWriter responseWriter = new ByteArrayContainerResponseWriter();
ContainerResponse cres = new ContainerResponse(responseWriter);
Modified: jcr/trunk/exo.jcr.component.ext/src/test/resources/conf/standalone/test-configuration.xml
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/test/resources/conf/standalone/test-configuration.xml 2010-03-24 13:11:41 UTC (rev 2107)
+++ jcr/trunk/exo.jcr.component.ext/src/test/resources/conf/standalone/test-configuration.xml 2010-03-24 14:18:24 UTC (rev 2108)
@@ -1885,6 +1885,33 @@
</properties-param>
</init-params>
</component-plugin>
+ <component-plugin>
+ <name>bind.datasource</name>
+ <set-method>addPlugin</set-method>
+ <type>org.exoplatform.services.naming.BindReferencePlugin</type>
+ <init-params>
+ <value-param>
+ <name>bind-name</name>
+ <value>jdbcjcr_to_repository_restore_1</value>
+ </value-param>
+ <value-param>
+ <name>class-name</name>
+ <value>javax.sql.DataSource</value>
+ </value-param>
+ <value-param>
+ <name>factory</name>
+ <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
+ </value-param>
+ <properties-param>
+ <name>ref-addresses</name>
+ <description>ref-addresses</description>
+ <property name="driverClassName" value="org.hsqldb.jdbcDriver" />
+ <property name="url" value="jdbc:hsqldb:file:target/temp/data/jdbcjcr_to_repository_restore_1" />
+ <property name="username" value="sa" />
+ <property name="password" value="" />
+ </properties-param>
+ </init-params>
+ </component-plugin>
</external-component-plugins>
</configuration>
16 years, 1 month