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

do-not-reply at jboss.org do-not-reply at jboss.org
Thu Mar 25 11:51:40 EDT 2010


Author: tolusha
Date: 2010-03-25 11:51:39 -0400 (Thu, 25 Mar 2010)
New Revision: 2139

Modified:
   jcr/trunk/exo.jcr.component.ext/pom.xml
   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/test/java/org/exoplatform/services/jcr/ext/backup/server/HTTPBackupAgentTest.java
Log:
EXOJCR-549: fix bugs

Modified: jcr/trunk/exo.jcr.component.ext/pom.xml
===================================================================
--- jcr/trunk/exo.jcr.component.ext/pom.xml	2010-03-25 15:44:18 UTC (rev 2138)
+++ jcr/trunk/exo.jcr.component.ext/pom.xml	2010-03-25 15:51:39 UTC (rev 2139)
@@ -174,13 +174,14 @@
               <include>**/replication/*.java</include>
               <include>**/replication/external/*.java</include>
               <include>**/replication/async/**/*.java</include>
+	      <include>**/**/HTTPBackupAgentTest.java</include>
             </includes>
             <excludes>
               <exclude>**/BaseStandaloneTest.java</exclude>
               <exclude>**/replication/*.java</exclude>
               <exclude>**/replication/external/*.java</exclude>
               <exclude>**/replication/external/BaseTestCaseChecker.java</exclude>
-              <exclude>**/backup/*.java</exclude>
+              <!--exclude>**/backup/*.java</exclude-->
               <exclude>**/access/*.java</exclude>
               <exclude>**/LocalStorageMultithreadTest.java</exclude>
             </excludes>

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 15:44:18 UTC (rev 2138)
+++ jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/server/HTTPBackupAgent.java	2010-03-25 15:51:39 UTC (rev 2139)
@@ -114,6 +114,11 @@
          public static final String RESTORE = "/restore";
 
          /**
+          * Restore repository operations.
+          */
+         public static final String RESTORE_REPOSITORY = "/restore-repository";
+
+         /**
           * Stop backup operations.
           */
          public static final String STOP_BACKUP = "/stop";
@@ -190,6 +195,11 @@
          public static final String GET_DEFAULT_WORKSPACE_CONFIG = "/info/default-ws-config";
 
          /**
+          * The get default repository configuration.
+          */
+         public static final String GET_DEFAULT_REPOSITORY_CONFIG = "/info/default-repository-config";
+
+         /**
           * OperationType constructor.
           */
          private OperationType()
@@ -1450,6 +1460,28 @@
    }
 
    /**
+    * Will be returned the default repository configuration.
+    * 
+    * @return Response return the JSON to WorkspaceEntry
+    */
+   @GET
+   @Produces(MediaType.APPLICATION_JSON)
+   @RolesAllowed("administrators")
+   @Path("/info/default-repository-config")
+   public Response getDefaultRepositoryConfig()
+   {
+      try
+      {
+         return Response.ok(repositoryService.getDefaultRepository().getConfiguration()).cacheControl(noCache).build();
+      }
+      catch (Throwable e)
+      {
+         return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(
+            "Can not get default workspace configuration.").type(MediaType.TEXT_PLAIN).cacheControl(noCache).build();
+      }
+   }
+
+   /**
     * validateRepositoryName.
     * 
     * @param repositoryName

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 15:44:18 UTC (rev 2138)
+++ jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/server/HTTPBackupAgentTest.java	2010-03-25 15:51:39 UTC (rev 2139)
@@ -20,6 +20,7 @@
 
 import org.exoplatform.services.jcr.config.ContainerEntry;
 import org.exoplatform.services.jcr.config.QueryHandlerEntry;
+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;
@@ -192,76 +193,75 @@
    {
       // login to workspace '/db6/ws2'
       // Start repository backup
-      {
-         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();
+      Session session_db6_ws2 = repositoryService.getRepository("db6").login(credentials, "ws2");
+      assertNotNull(session_db6_ws2);
 
-         File f = new File("target/temp/backup/" + System.currentTimeMillis());
-         f.mkdirs();
+      session_db6_ws2.getRootNode().addNode("NODE_NAME_TO_TEST");
+      session_db6_ws2.save();
 
-         BackupConfigBean configBean = new BackupConfigBean(BackupManager.FULL_AND_INCREMENTAL, f.getPath(), 10000l);
+      File f = new File("target/temp/backup/" + System.currentTimeMillis());
+      f.mkdirs();
 
-         JsonGeneratorImpl generatorImpl = new JsonGeneratorImpl();
-         JsonValue json = generatorImpl.createJsonObject(configBean);
+      BackupConfigBean configBean = new BackupConfigBean(BackupManager.FULL_AND_INCREMENTAL, f.getPath(), 10000l);
 
-         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));
+      JsonGeneratorImpl generatorImpl = new JsonGeneratorImpl();
+      JsonValue json = generatorImpl.createJsonObject(configBean);
 
-         ByteArrayContainerResponseWriter responseWriter = new ByteArrayContainerResponseWriter();
-         ContainerResponse cres = new ContainerResponse(responseWriter);
-         handler.handleRequest(creq, cres);
-
-         assertEquals(200, cres.getStatus());
-
-         Thread.sleep(10000);
-      }
-
-      // Get repository 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.CURRENT_BACKUPS_REPOSITORY_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");
-
-         id = info.getBackupId();
-      }
-
       MultivaluedMap<String, String> headers = new MultivaluedMapImpl();
+      headers.putSingle("Content-Type", "application/json; charset=UTF-8");
       ContainerRequestUserRole creq =
-         new ContainerRequestUserRole("GET", new URI(HTTP_BACKUP_AGENT_PATH
-            + HTTPBackupAgent.Constants.OperationType.STOP_BACKUP_REPOSITORY + "/" + id), new URI(""), null,
-            new InputHeadersMap(headers));
+         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(10000);
+
+      //      // Get repository 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.CURRENT_BACKUPS_REPOSITORY_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");
+      //
+      //         id = info.getBackupId();
+      //      }
+      //
+      //      MultivaluedMap<String, String> headers = new MultivaluedMapImpl();
+      //      ContainerRequestUserRole creq =
+      //         new ContainerRequestUserRole("GET", new URI(HTTP_BACKUP_AGENT_PATH
+      //            + HTTPBackupAgent.Constants.OperationType.STOP_BACKUP_REPOSITORY + "/" + id), new URI(""), null,
+      //            new InputHeadersMap(headers));
+      //
+      //      ByteArrayContainerResponseWriter responseWriter = new ByteArrayContainerResponseWriter();
+      //      ContainerResponse cres = new ContainerResponse(responseWriter);
+      //      handler.handleRequest(creq, cres);
+      //
+      //      assertEquals(200, cres.getStatus());
    }
 
    public void testInfoBackup() throws Exception
@@ -769,7 +769,7 @@
          MultivaluedMap<String, String> headers = new MultivaluedMapImpl();
          ContainerRequestUserRole creq =
             new ContainerRequestUserRole("GET", new URI(HTTP_BACKUP_AGENT_PATH
-               + HTTPBackupAgent.Constants.OperationType.COMPLETED_BACKUPS_REPOSITORY_INFO), new URI(""), null,
+               + HTTPBackupAgent.Constants.OperationType.CURRENT_BACKUPS_REPOSITORY_INFO), new URI(""), null,
                new InputHeadersMap(headers));
 
          ByteArrayContainerResponseWriter responseWriter = new ByteArrayContainerResponseWriter();
@@ -786,13 +786,29 @@
          ShortInfo info = list.get(0);
 
          assertEquals(info.getRepositoryName(), "db6");
-         assertEquals(info.getWorkspaceName(), "ws2");
 
          id = info.getBackupId();
       }
 
+      // Getting default RepositoryEntry
+      RepositoryEntry defREntry;
+      {
+         MultivaluedMap<String, String> headers = new MultivaluedMapImpl();
+         ContainerRequestUserRole creq =
+            new ContainerRequestUserRole("GET", new URI(HTTP_BACKUP_AGENT_PATH
+               + HTTPBackupAgent.Constants.OperationType.GET_DEFAULT_REPOSITORY_CONFIG), new URI(""), null,
+               new InputHeadersMap(headers));
+
+         ByteArrayContainerResponseWriter responseWriter = new ByteArrayContainerResponseWriter();
+         ContainerResponse cres = new ContainerResponse(responseWriter);
+         handler.handleRequest(creq, cres);
+
+         assertEquals(200, cres.getStatus());
+         defREntry = (RepositoryEntry)getObject(RepositoryEntry.class, responseWriter.getBody());
+      }
+
       // Getting default WorkspaceEntry
-      WorkspaceEntry defEntry;
+      WorkspaceEntry defWEntry;
       {
          MultivaluedMap<String, String> headers = new MultivaluedMapImpl();
          ContainerRequestUserRole creq =
@@ -805,16 +821,18 @@
          handler.handleRequest(creq, cres);
 
          assertEquals(200, cres.getStatus());
-         defEntry = (WorkspaceEntry)getObject(WorkspaceEntry.class, responseWriter.getBody());
+         defWEntry = (WorkspaceEntry)getObject(WorkspaceEntry.class, responseWriter.getBody());
       }
 
-      WorkspaceEntry wEntry = makeWorkspaceEntry(defEntry, "db6", "ws3", "jdbcjcr24");
+      ArrayList<WorkspaceEntry> wsEntries = new ArrayList<WorkspaceEntry>();
+      wsEntries.add(makeWorkspaceEntry(defWEntry, "db7", "ws1", "jdbcjcr24"));
+      wsEntries.add(makeWorkspaceEntry(defWEntry, "db7", "ws2", "jdbcjcr24"));
+      RepositoryEntry rEntry = makeRepositoryEntry(defREntry, "db7", wsEntries);
 
       // 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.");
+         repositoryService.getRepository("db7");
       }
       catch (Exception e)
       {
@@ -825,14 +843,14 @@
       {
          // Create JSON to WorkspaceEntry
          JsonGeneratorImpl generatorImpl = new JsonGeneratorImpl();
-         JsonValue json = generatorImpl.createJsonObject(wEntry);
+         JsonValue json = generatorImpl.createJsonObject(rEntry);
 
          // 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(""),
+               + HTTPBackupAgent.Constants.OperationType.RESTORE_REPOSITORY + "/" + id), new URI(""),
                new ByteArrayInputStream(json.toString().getBytes("UTF-8")), new InputHeadersMap(headers));
 
          ByteArrayContainerResponseWriter responseWriter = new ByteArrayContainerResponseWriter();
@@ -952,6 +970,22 @@
       return ws1back;
    }
 
+   protected RepositoryEntry makeRepositoryEntry(RepositoryEntry defREntry, String repoName,
+      ArrayList<WorkspaceEntry> wsEntries)
+   {
+      RepositoryEntry rEntry = new RepositoryEntry();
+      rEntry.setAccessControl(defREntry.getAccessControl());
+      rEntry.setAuthenticationPolicy(defREntry.getAuthenticationPolicy());
+      rEntry.setDefaultWorkspaceName(defREntry.getDefaultWorkspaceName());
+      rEntry.setName(repoName);
+      rEntry.setSecurityDomain(defREntry.getSecurityDomain());
+      rEntry.setSessionTimeOut(defREntry.getSessionTimeOut());
+      rEntry.setSystemWorkspaceName(defREntry.getSystemWorkspaceName());
+      rEntry.setWorkspaceEntries(wsEntries);
+
+      return rEntry;
+   }
+
    /**
     * Will be created the Object from JSON binary data.
     * 



More information about the exo-jcr-commits mailing list