[exo-jcr-commits] exo-jcr SVN: r3592 - in jcr/trunk/exo.jcr.component.ext: src/main/java/org/exoplatform/services/jcr/ext/backup/impl and 2 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Thu Dec 2 05:39:22 EST 2010


Author: tolusha
Date: 2010-12-02 05:39:21 -0500 (Thu, 02 Dec 2010)
New Revision: 3592

Added:
   jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/FileNameProducer.java
   jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/rdbms/
Removed:
   jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/fs/FileNameProducer.java
Modified:
   jcr/trunk/exo.jcr.component.ext/pom.xml
   jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/fs/FullBackupJob.java
   jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/fs/IncrementalBackupJob.java
   jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/TestFileNameProduser.java
Log:
EXOJCR-1078: adopt filename producer

Modified: jcr/trunk/exo.jcr.component.ext/pom.xml
===================================================================
--- jcr/trunk/exo.jcr.component.ext/pom.xml	2010-12-02 07:10:21 UTC (rev 3591)
+++ jcr/trunk/exo.jcr.component.ext/pom.xml	2010-12-02 10:39:21 UTC (rev 3592)
@@ -185,7 +185,8 @@
               <include>**/replication/*.java</include>
               <include>**/replication/external/*.java</include>
               <include>**/replication/async/**/*.java</include>
-              <include>**/**/TestBackupManager.java</include>
+              <include>**/backup/TestBackupManager.java</include>
+              <include>**/backup/TestFileNameProduser.java</include>
             </includes>
             <excludes>
               <exclude>**/BaseStandaloneTest.java</exclude>

Copied: jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/FileNameProducer.java (from rev 3591, 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/FileNameProducer.java	                        (rev 0)
+++ jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/FileNameProducer.java	2010-12-02 10:39:21 UTC (rev 3592)
@@ -0,0 +1,228 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.exoplatform.services.jcr.ext.backup.impl;
+
+import org.exoplatform.commons.utils.PrivilegedFileHelper;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Calendar;
+
+/**
+ * Created by The eXo Platform SARL Author : Alex Reshetnyak alex.reshetnyak at exoplatform.com.ua Nov
+ * 20, 2007
+ */
+public class FileNameProducer
+{
+   /**
+    * Backup set name.
+    */
+   private final String backupSetName;
+
+   /**
+    * Backup set directory.
+    */
+   private final File backupSetDir;
+
+   /**
+    * Indicates is full backup or not.
+    */
+   private boolean isFullBackup;
+
+   /**
+    * Indicates that need to create a directory for full backup otherwise is will be the single file.
+    */
+   private final boolean isDirectoryForFullBackup;
+
+   /**
+    * Constructor FileNameProducer.
+    * 
+    * @param backupSetName
+    *          backup set name
+    * @param backupDir
+    *          backup directory
+    * @param timeStamp
+    *          time stamp for creation unique backup set directory 
+    * @param isFullBackup
+    *          indicates is full backup or not 
+    * @param isDirectory
+    *          indicates that need to create a directory for full backup otherwise is will be the single file
+    */
+   public FileNameProducer(String backupSetName, String backupDir, Calendar timeStamp, boolean isFullBackup,
+      boolean isDirectory)
+   {
+      this.backupSetName = backupSetName;
+      this.isFullBackup = isFullBackup;
+      this.isDirectoryForFullBackup = isDirectory;
+
+      String sTime = "-" + getStrDate(timeStamp) + "_" + getStrTime(timeStamp);
+      this.backupSetDir = new File(backupDir + File.separator + backupSetName + sTime);
+
+      if (!PrivilegedFileHelper.exists(backupSetDir))
+      {
+         PrivilegedFileHelper.mkdirs(backupSetDir);
+      }
+   }
+
+   /**
+    * Constructor FileNameProducer.
+    * 
+    * @param repositoryName
+    *          repository name for creation backup set name
+    * @param workspaceName
+    *          workspace name for creation backup set name
+    * @param backupDir
+    *          backup directory
+    * @param timeStamp
+    *          time stamp for creation unique backup set directory 
+    * @param isFullBackup
+    *          indicates is full backup or not 
+    * @param isDirectory
+    *          indicates that need to create a directory for full backup otherwise is will be the single file
+    */
+   public FileNameProducer(String repositoryName, String workspaceName, String backupDir, Calendar timeStamp,
+      boolean isFullBackup, boolean isDirectory)
+   {
+      this(repositoryName + "_" + workspaceName, backupDir, timeStamp, isFullBackup, isDirectory);
+   }
+
+   /**
+    * Constructor FileNameProducer.
+    * 
+    * @param repositoryName
+    *          repository name for creation backup set name
+    * @param workspaceName
+    *          workspace name for creation backup set name
+    * @param backupDir
+    *          backup directory
+    * @param timeStamp
+    *          time stamp for creation unique backup set directory 
+    * @param isFullBackup
+    *          indicates is full backup or not 
+    */
+   public FileNameProducer(String repositoryName, String workspaceName, String backupDir, Calendar timeStamp,
+      boolean isFullBackup)
+   {
+      this(repositoryName + "_" + workspaceName, backupDir, timeStamp, isFullBackup, false);
+   }
+
+   /**
+    * Get next file in backup set.
+    * 
+    * @return
+    *       file
+    */
+   public File getNextFile()
+   {
+      File nextFile = null;
+
+      try
+      {
+         String sNextName = generateName();
+
+         nextFile = new File(backupSetDir.getAbsoluteFile() + File.separator + sNextName);
+         if (isFullBackup && isDirectoryForFullBackup)
+         {
+            if (!PrivilegedFileHelper.exists(nextFile))
+            {
+               PrivilegedFileHelper.mkdirs(nextFile);
+            }
+         }
+         else
+         {
+            PrivilegedFileHelper.createNewFile(nextFile);
+         }
+      }
+      catch (IOException e)
+      {
+         e.printStackTrace();
+      }
+
+      return nextFile;
+   }
+
+   /**
+    * Generate name for backup file (directory) based on backup set name and current time.
+    */
+   private String generateName()
+   {
+
+      Calendar date = Calendar.getInstance();
+
+      String sDate = getStrDate(date);
+      String sTime = getStrTime(date);
+
+      String fileName = backupSetName + "-" + sDate + "_" + sTime + ".";
+
+      if (isFullBackup)
+      {
+         fileName += "0";
+      }
+      else
+      {
+         fileName += getNextSufix();
+      }
+
+      return fileName;
+   }
+
+   private String getNextSufix()
+   {
+
+      String[] fileList = PrivilegedFileHelper.list(backupSetDir);
+
+      int sufix = 0;
+
+      for (int i = 0; i < fileList.length; i++)
+      {
+         String[] stringArray = fileList[i].split("[.]");
+         
+         int currentSufix = Integer.valueOf(stringArray[stringArray.length - 1]).intValue();
+
+         if (currentSufix > sufix)
+         {
+            sufix = currentSufix;
+         }
+      }
+
+      return String.valueOf(++sufix);
+   }
+
+   /**
+    * Returns date as String in format YYYYMMDD.
+    */
+   private String getStrDate(Calendar c)
+   {
+      int m = c.get(Calendar.MONTH) + 1;
+      int d = c.get(Calendar.DATE);
+      return "" + c.get(Calendar.YEAR) + (m < 10 ? "0" + m : m) + (d < 10 ? "0" + d : d);
+   }
+
+   /**
+    * Returns time as String in format HHMMSS.
+    */
+   private String getStrTime(Calendar c)
+   {
+      int h = c.get(Calendar.HOUR);
+      int m = c.get(Calendar.MINUTE);
+      int s = c.get(Calendar.SECOND);
+      return "" + (h < 10 ? "0" + h : h) + (m < 10 ? "0" + m : m) + (s < 10 ? "0" + s : s);
+   }
+
+}

Deleted: 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-12-02 07:10:21 UTC (rev 3591)
+++ jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/fs/FileNameProducer.java	2010-12-02 10:39:21 UTC (rev 3592)
@@ -1,145 +0,0 @@
-/*
- * Copyright (C) 2009 eXo Platform SAS.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.exoplatform.services.jcr.ext.backup.impl.fs;
-
-import org.exoplatform.commons.utils.PrivilegedFileHelper;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.Calendar;
-
-/**
- * Created by The eXo Platform SARL Author : Alex Reshetnyak alex.reshetnyak at exoplatform.com.ua Nov
- * 20, 2007
- */
-public class FileNameProducer
-{
-   private String serviceDir;
-
-   private String backupSetName;
-
-   private File backupSetDir;
-
-   private boolean isFullBackup;
-
-   private Calendar timeStamp;
-
-   public FileNameProducer(String backupSetName, String serviceDir, Calendar timeStamp, boolean isFullBackup)
-   {
-      this.backupSetName = backupSetName;
-      this.serviceDir = serviceDir;
-      this.isFullBackup = isFullBackup;
-      this.timeStamp = timeStamp;
-   }
-
-   public FileNameProducer(String repositoryName, String workspaceName, String serviceDir, Calendar timeStamp,
-      boolean isFullBackup)
-   {
-      this.backupSetName = repositoryName + "_" + workspaceName;
-      this.serviceDir = serviceDir;
-      this.isFullBackup = isFullBackup;
-      this.timeStamp = timeStamp;
-   }
-
-   public File getNextFile()
-   {
-      File nextFile = null;
-
-      try
-      {
-         // TODO use SimpleDateFormat
-         // String sTime = "-" + new SimpleDateFormat("yyyyMMdd_hhmmss").fprmat(timeStamp);
-         String sTime = "-" + getStrDate(timeStamp) + "_" + getStrTime(timeStamp);
-
-         backupSetDir = new File(serviceDir + File.separator + backupSetName + sTime);
-
-         if (!PrivilegedFileHelper.exists(backupSetDir))
-         {
-            PrivilegedFileHelper.mkdirs(backupSetDir);
-         }
-
-         String sNextName = generateName();
-
-         nextFile = new File(backupSetDir.getAbsoluteFile() + File.separator + sNextName);
-         PrivilegedFileHelper.createNewFile(nextFile);
-      }
-      catch (IOException e)
-      {
-         e.printStackTrace();
-      }
-
-      return nextFile;
-   }
-
-   private String generateName()
-   {
-
-      Calendar date = Calendar.getInstance();
-
-      String sDate = getStrDate(date);
-      String sTime = getStrTime(date);
-
-      String fileName = backupSetName + "-" + sDate + "_" + sTime + ".";
-
-      if (isFullBackup)
-         fileName += "0";
-      else
-         fileName += getNextSufix();
-
-      return fileName;
-   }
-
-   private String getNextSufix()
-   {
-
-      String[] fileList = PrivilegedFileHelper.list(backupSetDir);
-
-      int sufix = 0;
-
-      for (int i = 0; i < fileList.length; i++)
-      {
-         String[] stringArray = fileList[i].split("[.]");
-         
-         int currentSufix = Integer.valueOf(stringArray[stringArray.length - 1]).intValue();
-
-         if (currentSufix > sufix)
-            sufix = currentSufix;
-      }
-
-      return String.valueOf(++sufix);
-   }
-
-   public static String getStrDate(Calendar c)
-   {
-      // Returns as a String (YYYYMMDD) a Calendar date
-      int m = c.get(Calendar.MONTH) + 1;
-      int d = c.get(Calendar.DATE);
-      return "" + c.get(Calendar.YEAR) + (m < 10 ? "0" + m : m) + (d < 10 ? "0" + d : d);
-   }
-
-   public static String getStrTime(Calendar c)
-   {
-      // Returns as a String (YYYYMMDD) a Calendar date
-      int h = c.get(Calendar.HOUR);
-      int m = c.get(Calendar.MINUTE);
-      int s = c.get(Calendar.SECOND);
-      return "" + (h < 10 ? "0" + h : h) + (m < 10 ? "0" + m : m) + (s < 10 ? "0" + s : s);
-   }
-
-}

Modified: jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/fs/FullBackupJob.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/fs/FullBackupJob.java	2010-12-02 07:10:21 UTC (rev 3591)
+++ jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/fs/FullBackupJob.java	2010-12-02 10:39:21 UTC (rev 3592)
@@ -22,6 +22,7 @@
 import org.exoplatform.services.jcr.core.ManageableRepository;
 import org.exoplatform.services.jcr.ext.backup.BackupConfig;
 import org.exoplatform.services.jcr.ext.backup.impl.AbstractFullBackupJob;
+import org.exoplatform.services.jcr.ext.backup.impl.FileNameProducer;
 import org.exoplatform.services.jcr.impl.core.SessionImpl;
 import org.exoplatform.services.log.ExoLogger;
 import org.exoplatform.services.log.Log;
@@ -51,8 +52,7 @@
 
       FileNameProducer fnp =
          new FileNameProducer(config.getRepository(), config.getWorkspace(),
-            PrivilegedFileHelper.getAbsolutePath(config.getBackupDir()),
-            super.timeStamp, true);
+            PrivilegedFileHelper.getAbsolutePath(config.getBackupDir()), super.timeStamp, true);
 
       return new URL("file:" + PrivilegedFileHelper.getAbsolutePath(fnp.getNextFile()));
    }

Modified: jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/fs/IncrementalBackupJob.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/fs/IncrementalBackupJob.java	2010-12-02 07:10:21 UTC (rev 3591)
+++ jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/fs/IncrementalBackupJob.java	2010-12-02 10:39:21 UTC (rev 3592)
@@ -25,6 +25,7 @@
 import org.exoplatform.services.jcr.dataflow.TransactionChangesLog;
 import org.exoplatform.services.jcr.ext.backup.BackupConfig;
 import org.exoplatform.services.jcr.ext.backup.impl.AbstractIncrementalBackupJob;
+import org.exoplatform.services.jcr.ext.backup.impl.FileNameProducer;
 import org.exoplatform.services.jcr.ext.backup.impl.PendingChangesLog;
 import org.exoplatform.services.jcr.ext.replication.FixupStream;
 import org.exoplatform.services.jcr.impl.util.io.FileCleaner;

Modified: jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/TestFileNameProduser.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/TestFileNameProduser.java	2010-12-02 07:10:21 UTC (rev 3591)
+++ jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/TestFileNameProduser.java	2010-12-02 10:39:21 UTC (rev 3592)
@@ -20,7 +20,7 @@
 
 import junit.framework.TestCase;
 
-import org.exoplatform.services.jcr.ext.backup.impl.fs.FileNameProducer;
+import org.exoplatform.services.jcr.ext.backup.impl.FileNameProducer;
 
 import java.io.File;
 import java.util.Calendar;
@@ -31,36 +31,56 @@
  */
 public class TestFileNameProduser extends TestCase
 {
-   FileNameProducer nameProducer;
+   private File tempDir;
 
-   File tempDir;
+   private String backupsetName;
 
-   String backupsetName;
+   private Calendar calendar;
 
-   public void testGetNextName() throws Exception
+   @Override
+   public void setUp() throws Exception
    {
+      super.setUp();
+
       tempDir = new File("target" + File.separator + "temp" + File.separator + "fileProduser");
       tempDir.mkdirs();
-
       backupsetName = String.valueOf(System.currentTimeMillis());
+      calendar = Calendar.getInstance();
+   }
 
-      nextName(true);
-      nextName(false);
-      nextName(false);
-      nextName(false);
-      nextName(false);
-      nextName(false);
+   public void testGetNextNameJCRBackup() throws Exception
+   {
+      FileNameProducer nameProducer =
+         new FileNameProducer(backupsetName, tempDir.getAbsolutePath(), calendar, true, false);
+      File file = nameProducer.getNextFile();
 
-      assertEquals(1, 1);
+      assertTrue(file.isFile());
+      assertTrue(file.getName().endsWith(".0"));
+
+      nameProducer = new FileNameProducer(backupsetName, tempDir.getAbsolutePath(), calendar, false, false);
+      file = nameProducer.getNextFile();
+
+      assertTrue(file.isFile());
+      assertTrue(file.getName().endsWith(".1"));
+      assertTrue(nameProducer.getNextFile().getName().endsWith(".2"));
+      assertTrue(nameProducer.getNextFile().getName().endsWith(".3"));
    }
 
-   private void nextName(boolean isFullBackup) throws InterruptedException
+   public void testGetNextNameRDBMSBackup() throws Exception
    {
-      // nameProducer = new FileNameProducer("reposytory", "production", tempDir.getAbsolutePath(),
-      // isFullBackup);
-      Thread.sleep(100);
-      nameProducer =
-         new FileNameProducer(backupsetName, tempDir.getAbsolutePath(), Calendar.getInstance(), isFullBackup);
-      System.out.println(nameProducer.getNextFile().getName());
+      FileNameProducer nameProducer =
+         new FileNameProducer(backupsetName, tempDir.getAbsolutePath(), calendar, true, true);
+      File file = nameProducer.getNextFile();
+
+      assertTrue(file.isDirectory());
+      assertTrue(file.getName().endsWith(".0"));
+
+      nameProducer = new FileNameProducer(backupsetName, tempDir.getAbsolutePath(), calendar, false, false);
+      file = nameProducer.getNextFile();
+
+      assertTrue(file.isFile());
+      assertTrue(file.getName().endsWith(".1"));
+      assertTrue(nameProducer.getNextFile().getName().endsWith(".2"));
+      assertTrue(nameProducer.getNextFile().getName().endsWith(".3"));
    }
 }



More information about the exo-jcr-commits mailing list