Author: tolusha
Date: 2010-03-25 10:59:27 -0400 (Thu, 25 Mar 2010)
New Revision: 2135
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/test/java/org/exoplatform/services/jcr/ext/backup/server/HTTPBackupAgentTest.java
Log:
EXOJCR-549: fix bugs
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
14:37:44 UTC (rev 2134)
+++
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/server/HTTPBackupAgent.java 2010-03-25
14:59:27 UTC (rev 2135)
@@ -119,6 +119,11 @@
public static final String STOP_BACKUP = "/stop";
/**
+ * Stop repository backup operations.
+ */
+ public static final String STOP_BACKUP_REPOSITORY =
"stop-repository";
+
+ /**
* The current and completed backups info operation.
*/
public static final String CURRENT_AND_COMPLETED_BACKUPS_INFO =
"/info/backup";
@@ -134,6 +139,11 @@
public static final String CURRENT_BACKUPS_INFO =
"/info/backup/current";
/**
+ * The current repository backups info operations.
+ */
+ public static final String CURRENT_BACKUPS_REPOSITORY_INFO =
"/info/backup-repository/current";
+
+ /**
* The current or completed backup info operations.
*/
public static final String CURRENT_OR_COMPLETED_BACKUP_INFO =
"/info/backup";
@@ -156,7 +166,7 @@
/**
* The completed repository backups info operations.
*/
- public static final String COMPLETED_BACKUPS_REPOSITORY_INFO =
"/info/backup/repository/completed";
+ public static final String COMPLETED_BACKUPS_REPOSITORY_INFO =
"/info/backup-repository/completed";
/**
* The backup service info operations.
@@ -731,7 +741,6 @@
if (backupId.equals(chainLog.getBackupId()))
{
shortInfo = new ShortInfo(ShortInfo.COMPLETED, chainLog);
- System.out.println();
break;
}
@@ -760,6 +769,64 @@
}
/**
+ * The repository backup stop by 'id'.
+ *
+ * @param backupId
+ * String, the identifier to backup
+ * @return Response return the response
+ */
+ @GET
+ @Produces(MediaType.APPLICATION_JSON)
+ @RolesAllowed("administrators")
+ @Path("/stop-repository/{id}")
+ public Response stopRepository(@PathParam("id") String backupId)
+ {
+ String failMessage;
+ Response.Status status;
+ Throwable exception;
+
+ try
+ {
+ RepositoryBackupChain bch = backupManager.findRepositoryBackupId(backupId);
+
+ if (bch != null)
+ backupManager.stopBackup(bch);
+ else
+ throw new BackupNotFoundException("No active repository backup with id
'" + backupId + "'");
+
+ ShortInfo shortInfo = null;
+ for (RepositoryBackupChainLog chainLog :
backupManager.getRepositoryBackupsLogs())
+ if (backupId.equals(chainLog.getBackupId()))
+ {
+ shortInfo = new ShortInfo(ShortInfo.COMPLETED, chainLog);
+ break;
+ }
+
+ if (shortInfo == null)
+ throw new BackupNotFoundException("No completed backup with id
'" + backupId + "'");
+
+ return Response.ok(shortInfo).cacheControl(noCache).build();
+ }
+ catch (BackupNotFoundException e)
+ {
+ exception = e;
+ status = Response.Status.NOT_FOUND;
+ failMessage = e.getMessage();
+ }
+ catch (Throwable e)
+ {
+ exception = e;
+ status = Response.Status.INTERNAL_SERVER_ERROR;
+ failMessage = e.getMessage();
+ }
+
+ log.error("Can not stop repository backup ", exception);
+
+ return Response.status(status).entity("Can not stop repository backup : "
+ failMessage).type(
+ MediaType.TEXT_PLAIN).cacheControl(noCache).build();
+ }
+
+ /**
* Will be returned the backup service info.
*
* @return Response return the response
@@ -943,16 +1010,17 @@
return Response.ok(info).cacheControl(noCache).build();
}
- return Response.status(Response.Status.NOT_FOUND).entity("No current or
completed repository backup with 'id' " + id)
- .type(MediaType.TEXT_PLAIN).cacheControl(noCache).build();
+ return Response.status(Response.Status.NOT_FOUND).entity(
+ "No current or completed repository backup with 'id' " +
id).type(MediaType.TEXT_PLAIN).cacheControl(
+ noCache).build();
}
catch (Throwable e)
{
log.error("Can not get information about current or completed repository
backup with 'id' " + id, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(
- "Can not get information about current or completed repository backup
with 'id' " + id + " : " + e.getMessage()).type(
- MediaType.TEXT_PLAIN).cacheControl(noCache).build();
+ "Can not get information about current or completed repository backup
with 'id' " + id + " : "
+ +
e.getMessage()).type(MediaType.TEXT_PLAIN).cacheControl(noCache).build();
}
}
@@ -1061,8 +1129,8 @@
@GET
@Produces(MediaType.APPLICATION_JSON)
@RolesAllowed("administrators")
- @Path("/info/backup/repository/completed")
- public Response infoBackupRepositoryCompleted()
+ @Path("/info/backup-repository/completed")
+ public Response infoRepositoryBackupCompleted()
{
try
{
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
14:37:44 UTC (rev 2134)
+++
jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/server/HTTPBackupAgentTest.java 2010-03-25
14:59:27 UTC (rev 2135)
@@ -188,37 +188,80 @@
Thread.sleep(5000);
}
- public void testRepositoryStart() throws Exception
+ public void testRepositoryStartBackup() throws Exception
{
// login to workspace '/db6/ws2'
- Session session_db6_ws2 =
repositoryService.getRepository("db6").login(credentials, "ws2");
- assertNotNull(session_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_db6_ws2.getRootNode().addNode("NODE_NAME_TO_TEST");
+ session_db6_ws2.save();
- File f = new File("target/temp/backup/" + System.currentTimeMillis());
- f.mkdirs();
+ File f = new File("target/temp/backup/" +
System.currentTimeMillis());
+ f.mkdirs();
- BackupConfigBean configBean = new
BackupConfigBean(BackupManager.FULL_AND_INCREMENTAL, f.getPath(), 10000l);
+ BackupConfigBean configBean = new
BackupConfigBean(BackupManager.FULL_AND_INCREMENTAL, f.getPath(), 10000l);
- JsonGeneratorImpl generatorImpl = new JsonGeneratorImpl();
- JsonValue json = generatorImpl.createJsonObject(configBean);
+ 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(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("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));
+ 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());
-
- Thread.sleep(5000);
}
public void testInfoBackup() throws Exception