Skip to content

Commit

Permalink
Added snapshot() to the rest service
Browse files Browse the repository at this point in the history
  • Loading branch information
chenson42 committed Dec 10, 2012
1 parent 063aef4 commit d2d86c6
Showing 1 changed file with 44 additions and 2 deletions.
Expand Up @@ -20,6 +20,10 @@
*/
package org.jumpmind.symmetric.web.rest;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.lang.annotation.Annotation;
import java.util.Collection;
import java.util.HashSet;
Expand All @@ -28,8 +32,11 @@

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import org.jumpmind.exception.IoException;
import org.jumpmind.symmetric.ISymmetricEngine;
import org.jumpmind.symmetric.model.IncomingBatch;
import org.jumpmind.symmetric.model.IncomingBatch.Status;
Expand Down Expand Up @@ -210,7 +217,42 @@ public final NodeList getChildrenByEngine(
}

/**
* Loads a profile for the single engine on the node.
* Takes a snapshot and streams it to the client.
*
* @param file A file stream that contains the profile itself.
*/
@RequestMapping(value = "engine/snapshot", method = RequestMethod.GET)
@ResponseStatus( HttpStatus.OK )
@ResponseBody
public final void snapshot(HttpServletResponse resp) {
snapshot(getSymmetricEngine().getEngineName(), resp);
}

/**
* Takes a snapshot for the specified engine and streams it to the client.
*
* @param file A file stream that contains the profile itself.
*/
@RequestMapping(value = "engine/{engine}/snapshot", method = RequestMethod.GET)
@ResponseStatus( HttpStatus.OK )
@ResponseBody
public final void snapshot(@PathVariable("engine") String engineName, HttpServletResponse resp) {
BufferedInputStream bis = null;
try {
ISymmetricEngine engine = getSymmetricEngine(engineName);
File file = engine.snapshot();
bis = new BufferedInputStream(new FileInputStream(file));
IOUtils.copy(bis, resp.getOutputStream());
} catch (IOException e) {
throw new IoException(e);
} finally {
IOUtils.closeQuietly(bis);
}
}


/**
* Loads a configuration profile for the single engine on the node.
*
* @param file A file stream that contains the profile itself.
*/
Expand All @@ -222,7 +264,7 @@ public final void postProfile(@RequestParam MultipartFile file) {
}

/**
* Loads a profile for the specified engine on the node.
* Loads a configuration profile for the specified engine on the node.
*
* @param engine The engine name for which the action is intended.
* @param file A file stream that contains the profile itself.
Expand Down

0 comments on commit d2d86c6

Please sign in to comment.