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

do-not-reply at jboss.org do-not-reply at jboss.org
Thu Mar 25 10:04:37 EDT 2010


Author: tolusha
Date: 2010-03-25 10:04:36 -0400 (Thu, 25 Mar 2010)
New Revision: 2128

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/BackupManager.java
   jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/BackupManagerImpl.java
   jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/server/HTTPBackupAgent.java
   jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/server/bean/response/ShortInfo.java
   jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/server/HTTPBackupAgentTest.java
Log:
EXOJCR-549: fix bubs

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-25 13:46:47 UTC (rev 2127)
+++ jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/BackupChainLog.java	2010-03-25 14:04:36 UTC (rev 2128)
@@ -55,7 +55,7 @@
 
    protected static Log logger = ExoLogger.getLogger("ext.BackupChainLog");
 
-   private static final String PREFIX = "backup-";
+   public static final String PREFIX = "backup-";
 
    private static final String SUFFIX = ".xml";
 

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-25 13:46:47 UTC (rev 2127)
+++ jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/BackupManager.java	2010-03-25 14:04:36 UTC (rev 2128)
@@ -60,7 +60,7 @@
     *           return the set of current backups 
     */
    Set<BackupChain> getCurrentBackups();
-   
+
    /**
     * Getting current repository backups.
     *
@@ -88,7 +88,7 @@
     *           return the job to restore
     */
    JobWorkspaceRestore getLastRestore(String repositoryName, String workspaceName);
-   
+
    /**
     * Getting list of repository restores.
     *
@@ -116,6 +116,14 @@
    BackupChainLog[] getBackupsLogs();
 
    /**
+    * Getting all repository backup logs.
+    *
+    * @return RepositoryBackupChainLog[]
+    *           return the all repository backup logs
+    */
+   RepositoryBackupChainLog[] getRepositoryBackupsLogs();
+
+   /**
     * Starting backup.
     *
     * @param config
@@ -258,7 +266,7 @@
     *           return the default incremental job period 
     */
    long getDefaultIncrementalJobPeriod();
-   
+
    /**
     * Starting repository backup.
     *
@@ -275,9 +283,9 @@
     * @throws RepositoryConfigurationException
     *           will be generate the exception RepositoryConfigurationException
     */
-   RepositoryBackupChain startBackup(RepositoryBackupConfig config) throws BackupOperationException, BackupConfigurationException,
-      RepositoryException, RepositoryConfigurationException;
-   
+   RepositoryBackupChain startBackup(RepositoryBackupConfig config) throws BackupOperationException,
+      BackupConfigurationException, RepositoryException, RepositoryConfigurationException;
+
    /**
     * Stop backup.
     *
@@ -285,7 +293,7 @@
     *          RepositoryBackupChain, the repositroy backup chain 
     */
    void stopBackup(RepositoryBackupChain backup);
-   
+
    /**
     * Repository restore from backup.
     *
@@ -306,10 +314,10 @@
     * @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;
-   
+   void restore(RepositoryBackupChainLog log, RepositoryEntry repositoryEntry,
+      Map<String, String> workspaceNamesCorrespondMap, boolean asynchronous) throws BackupOperationException,
+      BackupConfigurationException, RepositoryException, RepositoryConfigurationException;
+
    /**
     * Repository restore from backup.
     *
@@ -341,5 +349,5 @@
     *           return the current backup to repository 
     */
    RepositoryBackupChain findRepositoryBackup(String repository);
-   
+
 }

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-25 13:46:47 UTC (rev 2127)
+++ jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/BackupManagerImpl.java	2010-03-25 14:04:36 UTC (rev 2128)
@@ -246,15 +246,24 @@
       }
    }
 
-   class LogsFilter implements FileFilter
+   class BackupLogsFilter implements FileFilter
    {
 
       public boolean accept(File pathname)
       {
-         return pathname.getName().endsWith(".xml");
+         return pathname.getName().endsWith(".xml") && pathname.getName().startsWith(BackupChainLog.PREFIX);
       }
    }
 
+   class RepositoryBackupLogsFilter implements FileFilter
+   {
+
+      public boolean accept(File pathname)
+      {
+         return pathname.getName().endsWith(".xml") && pathname.getName().startsWith(RepositoryBackupChainLog.PREFIX);
+      }
+   }
+
    class TaskFilter implements FileFilter
    {
 
@@ -425,7 +434,7 @@
     */
    public BackupChainLog[] getBackupsLogs()
    {
-      File[] cfs = logsDirectory.listFiles(new LogsFilter());
+      File[] cfs = logsDirectory.listFiles(new BackupLogsFilter());
       List<BackupChainLog> logs = new ArrayList<BackupChainLog>();
       for (int i = 0; i < cfs.length; i++)
       {
@@ -447,6 +456,32 @@
    }
 
    /**
+    * {@inheritDoc}
+    */
+   public RepositoryBackupChainLog[] getRepositoryBackupsLogs()
+   {
+      File[] cfs = logsDirectory.listFiles(new RepositoryBackupLogsFilter());
+      List<RepositoryBackupChainLog> logs = new ArrayList<RepositoryBackupChainLog>();
+      for (int i = 0; i < cfs.length; i++)
+      {
+         File cf = cfs[i];
+
+         try
+         {
+            if (!isCurrentBackup(cf))
+               logs.add(new RepositoryBackupChainLog(cf));
+         }
+         catch (BackupOperationException e)
+         {
+            log.warn("Log file " + cf.getAbsolutePath() + " is bussy or corrupted. Skipped. " + e, e);
+         }
+      }
+      RepositoryBackupChainLog[] ls = new RepositoryBackupChainLog[logs.size()];
+      logs.toArray(ls);
+      return ls;
+   }
+
+   /**
     * isCurrentBackup.
     * 
     * @param log

Modified: jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/server/HTTPBackupAgent.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/server/HTTPBackupAgent.java	2010-03-25 13:46:47 UTC (rev 2127)
+++ jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/server/HTTPBackupAgent.java	2010-03-25 14:04:36 UTC (rev 2128)
@@ -651,8 +651,8 @@
          // search necessary restore
          JobRepositoryRestore restore = backupManager.getLastRepositoryRestore(rEntry.getName());
          ShortInfo info =
-                  new ShortInfo(ShortInfo.RESTORE, restore.getRepositoryBackupChainLog(), restore.getStartTime(),
-                           restore.getEndTime(), restore.getStateRestore(), restore.getRepositoryName());
+            new ShortInfo(ShortInfo.RESTORE, restore.getRepositoryBackupChainLog(), restore.getStartTime(), restore
+               .getEndTime(), restore.getStateRestore(), restore.getRepositoryName());
 
          return Response.ok(info).cacheControl(noCache).build();
       }
@@ -820,6 +820,42 @@
    }
 
    /**
+    * Will be returned the list short info of current and completed backups .
+    * 
+    * @return Response return the response
+    */
+   @GET
+   @Produces(MediaType.APPLICATION_JSON)
+   @RolesAllowed("administrators")
+   @Path("/info/backup/repository")
+   public Response infoBackupRepository()
+   {
+      try
+      {
+         List<ShortInfo> list = new ArrayList<ShortInfo>();
+
+         for (RepositoryBackupChain chain : backupManager.getCurrentRepositoryBackups())
+            list.add(new ShortInfo(ShortInfo.CURRENT, chain));
+
+         for (RepositoryBackupChainLog chainLog : backupManager.getRepositoryBackupsLogs())
+            if (backupManager.findBackup(chainLog.getBackupId()) == null)
+               list.add(new ShortInfo(ShortInfo.COMPLETED, chainLog));
+
+         ShortInfoList shortInfoList = new ShortInfoList(list);
+
+         return Response.ok(shortInfoList).cacheControl(noCache).build();
+      }
+      catch (Throwable e)
+      {
+         log.error("Can not get information about current or completed backups", e);
+
+         return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(
+            "Can not get information about current or completed backups" + e.getMessage()).type(MediaType.TEXT_PLAIN)
+            .cacheControl(noCache).build();
+      }
+   }
+
+   /**
     * Will be returned the detailed info of current or completed backup by 'id'.
     * 
     * @param id
@@ -1278,7 +1314,7 @@
    private boolean isRepositoryExist(String repositoryName) throws RepositoryException,
       RepositoryConfigurationException
    {
-      try 
+      try
       {
          return repositoryService.getRepository(repositoryName) != null;
       }
@@ -1286,7 +1322,7 @@
       {
          return false;
       }
-      
+
    }
 
    /**
@@ -1331,7 +1367,7 @@
                + "' is already restoring.");
          }
    }
-   
+
    /**
     * validateOneRepositoryRestoreInstants.
     * 
@@ -1422,7 +1458,7 @@
 
       return null;
    }
-   
+
    /**
     * getRepositoryBackupLogbyId.
     * 

Modified: jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/server/bean/response/ShortInfo.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/server/bean/response/ShortInfo.java	2010-03-25 13:46:47 UTC (rev 2127)
+++ jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/server/bean/response/ShortInfo.java	2010-03-25 14:04:36 UTC (rev 2128)
@@ -180,6 +180,30 @@
    /**
     * ShortInfo constructor.
     * 
+    * @param type
+    *          int, the tupe of short info
+    * @param chainLog
+    *          BackupChainLog, the backup chain log for completed backup.
+    */
+   public ShortInfo(int type, RepositoryBackupChainLog chainLog)
+   {
+      this.type = type;
+      this.backupType = chainLog.getBackupConfig().getBackupType();
+      this.backupId = chainLog.getBackupId();
+      this.repositoryName = chainLog.getBackupConfig().getRepository();
+      this.workspaceName = "";
+
+      // do not use
+      this.state = 0;
+
+      DateFormat df = new SimpleDateFormat(HTTPBackupAgent.Constants.DATE_FORMAT_RFC_1123);
+      this.startedTime = df.format(chainLog.getStartedTime().getTime());
+      this.finishedTime = df.format(chainLog.getFinishedTime().getTime());;
+   }
+
+   /**
+    * ShortInfo constructor.
+    * 
     * For restore.
     * 
     * @param type

Modified: jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/server/HTTPBackupAgentTest.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/server/HTTPBackupAgentTest.java	2010-03-25 13:46:47 UTC (rev 2127)
+++ jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/server/HTTPBackupAgentTest.java	2010-03-25 14:04:36 UTC (rev 2128)
@@ -188,6 +188,39 @@
       Thread.sleep(5000);
    }
 
+   public void testRepositoryStart() throws Exception
+   {
+      // login to workspace '/db6/ws2'
+      Session session_db6_ws2 = repositoryService.getRepository("db6").login(credentials, "ws2");
+      assertNotNull(session_db6_ws2);
+
+      session_db6_ws2.getRootNode().addNode("NODE_NAME_TO_TEST");
+      session_db6_ws2.save();
+
+      File f = new File("target/temp/backup/" + System.currentTimeMillis());
+      f.mkdirs();
+
+      BackupConfigBean configBean = new BackupConfigBean(BackupManager.FULL_AND_INCREMENTAL, f.getPath(), 10000l);
+
+      JsonGeneratorImpl generatorImpl = new JsonGeneratorImpl();
+      JsonValue json = generatorImpl.createJsonObject(configBean);
+
+      MultivaluedMap<String, String> headers = new MultivaluedMapImpl();
+      headers.putSingle("Content-Type", "application/json; charset=UTF-8");
+      ContainerRequestUserRole creq =
+         new ContainerRequestUserRole("POST", new URI(HTTP_BACKUP_AGENT_PATH
+            + HTTPBackupAgent.Constants.OperationType.START_BACKUP + "/db6"), new URI(""), new ByteArrayInputStream(
+            json.toString().getBytes("UTF-8")), new InputHeadersMap(headers));
+
+      ByteArrayContainerResponseWriter responseWriter = new ByteArrayContainerResponseWriter();
+      ContainerResponse cres = new ContainerResponse(responseWriter);
+      handler.handleRequest(creq, cres);
+
+      assertEquals(200, cres.getStatus());
+
+      Thread.sleep(5000);
+   }
+
    public void testInfoBackup() throws Exception
    {
       MultivaluedMap<String, String> headers = new MultivaluedMapImpl();
@@ -684,6 +717,156 @@
       }
    }
 
+   public void testRestoreRepository() throws Exception
+   {
+      // Get backup id for backup on workspace /db6/ws2
+      String id = null;
+
+      {
+         MultivaluedMap<String, String> headers = new MultivaluedMapImpl();
+         ContainerRequestUserRole creq =
+            new ContainerRequestUserRole("GET", new URI(HTTP_BACKUP_AGENT_PATH
+               + HTTPBackupAgent.Constants.OperationType.COMPLETED_BACKUPS_INFO), new URI(""), null,
+               new InputHeadersMap(headers));
+
+         ByteArrayContainerResponseWriter responseWriter = new ByteArrayContainerResponseWriter();
+         ContainerResponse cres = new ContainerResponse(responseWriter);
+         handler.handleRequest(creq, cres);
+
+         assertEquals(200, cres.getStatus());
+
+         ShortInfoList infoList = (ShortInfoList)getObject(ShortInfoList.class, responseWriter.getBody());
+         List<ShortInfo> list = new ArrayList<ShortInfo>(infoList.getBackups());
+
+         assertEquals(1, list.size());
+
+         ShortInfo info = list.get(0);
+
+         assertEquals(info.getRepositoryName(), "db6");
+         assertEquals(info.getWorkspaceName(), "ws2");
+
+         id = info.getBackupId();
+      }
+
+      // Getting default WorkspaceEntry
+      WorkspaceEntry defEntry;
+      {
+         MultivaluedMap<String, String> headers = new MultivaluedMapImpl();
+         ContainerRequestUserRole creq =
+            new ContainerRequestUserRole("GET", new URI(HTTP_BACKUP_AGENT_PATH
+               + HTTPBackupAgent.Constants.OperationType.GET_DEFAULT_WORKSPACE_CONFIG), new URI(""), null,
+               new InputHeadersMap(headers));
+
+         ByteArrayContainerResponseWriter responseWriter = new ByteArrayContainerResponseWriter();
+         ContainerResponse cres = new ContainerResponse(responseWriter);
+         handler.handleRequest(creq, cres);
+
+         assertEquals(200, cres.getStatus());
+         defEntry = (WorkspaceEntry)getObject(WorkspaceEntry.class, responseWriter.getBody());
+      }
+
+      WorkspaceEntry wEntry = makeWorkspaceEntry(defEntry, "db6", "ws3", "jdbcjcr24");
+
+      // Check the workspace /db6/ws3 not exists.
+      try
+      {
+         Session sessin_ws3 = repositoryService.getRepository("db6").login(credentials, "ws3");
+         fail("The workspace /db6/ws3 should not exists.");
+      }
+      catch (Exception e)
+      {
+         // ok
+      }
+
+      // Restore
+      {
+         // Create JSON to WorkspaceEntry
+         JsonGeneratorImpl generatorImpl = new JsonGeneratorImpl();
+         JsonValue json = generatorImpl.createJsonObject(wEntry);
+
+         // Execute restore
+         MultivaluedMap<String, String> headers = new MultivaluedMapImpl();
+         headers.putSingle("Content-Type", "application/json; charset=UTF-8");
+         ContainerRequestUserRole creq =
+            new ContainerRequestUserRole("POST", new URI(HTTP_BACKUP_AGENT_PATH
+               + HTTPBackupAgent.Constants.OperationType.RESTORE + "/" + "db6" + "/" + id), new URI(""),
+               new ByteArrayInputStream(json.toString().getBytes("UTF-8")), new InputHeadersMap(headers));
+
+         ByteArrayContainerResponseWriter responseWriter = new ByteArrayContainerResponseWriter();
+         ContainerResponse cres = new ContainerResponse(responseWriter);
+         handler.handleRequest(creq, cres);
+
+         assertEquals(200, cres.getStatus());
+      }
+
+      Thread.sleep(2000);
+
+      // Get restore info to workspace /db6/ws3
+      {
+         MultivaluedMap<String, String> headers = new MultivaluedMapImpl();
+         ContainerRequestUserRole creq =
+            new ContainerRequestUserRole("GET", new URI(HTTP_BACKUP_AGENT_PATH
+               + HTTPBackupAgent.Constants.OperationType.CURRENT_RESTORE_INFO_ON_WS + "/" + "db6" + "/" + "ws3"),
+               new URI(""), null, new InputHeadersMap(headers));
+
+         ByteArrayContainerResponseWriter responseWriter = new ByteArrayContainerResponseWriter();
+         ContainerResponse cres = new ContainerResponse(responseWriter);
+         handler.handleRequest(creq, cres);
+
+         assertEquals(200, cres.getStatus());
+
+         DetailedInfo info = (DetailedInfo)getObject(DetailedInfo.class, responseWriter.getBody());
+
+         assertNotNull(info);
+         assertEquals(BackupManager.FULL_AND_INCREMENTAL, info.getBackupType().intValue());
+         assertNotNull(info.getStartedTime());
+         assertNotNull(info.getFinishedTime());
+         assertEquals(ShortInfo.RESTORE, info.getType().intValue());
+         assertEquals(JobWorkspaceRestore.RESTORE_SUCCESSFUL, info.getState().intValue());
+         assertEquals("db6", info.getRepositoryName());
+         assertEquals("ws3", info.getWorkspaceName());
+         assertNotNull(info.getBackupConfig());
+
+         Session sessin_ws3 = repositoryService.getRepository("db6").login(credentials, "ws3");
+         assertNotNull(sessin_ws3);
+         assertNotNull(sessin_ws3.getRootNode());
+      }
+
+      // Get restores info
+      {
+         MultivaluedMap<String, String> headers = new MultivaluedMapImpl();
+         ContainerRequestUserRole creq =
+            new ContainerRequestUserRole("GET", new URI(HTTP_BACKUP_AGENT_PATH
+               + HTTPBackupAgent.Constants.OperationType.CURRENT_RESTORES), new URI(""), null, new InputHeadersMap(
+               headers));
+
+         ByteArrayContainerResponseWriter responseWriter = new ByteArrayContainerResponseWriter();
+         ContainerResponse cres = new ContainerResponse(responseWriter);
+         handler.handleRequest(creq, cres);
+
+         assertEquals(200, cres.getStatus());
+
+         ShortInfoList infoList = (ShortInfoList)getObject(ShortInfoList.class, responseWriter.getBody());
+         assertNotNull(infoList);
+
+         ShortInfo info = new ArrayList<ShortInfo>(infoList.getBackups()).get(0);
+
+         assertNotNull(info);
+         assertEquals(BackupManager.FULL_AND_INCREMENTAL, info.getBackupType().intValue());
+         assertNotNull(info.getStartedTime());
+         assertNotNull(info.getFinishedTime());
+         assertEquals(ShortInfo.RESTORE, info.getType().intValue());
+         assertEquals(JobWorkspaceRestore.RESTORE_SUCCESSFUL, info.getState().intValue());
+         assertEquals("db6", info.getRepositoryName());
+         assertEquals("ws3", info.getWorkspaceName());
+         assertNotNull(info.getBackupId());
+
+         Session sessin_ws3 = repositoryService.getRepository("db6").login(credentials, "ws3");
+         assertNotNull(sessin_ws3);
+         assertNotNull(sessin_ws3.getRootNode());
+      }
+   }
+
    protected WorkspaceEntry makeWorkspaceEntry(WorkspaceEntry defWEntry, String repoNmae, String wsName,
       String sourceName)
    {



More information about the exo-jcr-commits mailing list