Skip to content
Snippets Groups Projects
Commit 606c6f3d authored by Vojtech Moravec's avatar Vojtech Moravec
Browse files

Custom parameters from CLI option.

Save our CLI options to custom parameter class.
Also reformatted some class with automatic formatting.
parent 5981d62f
No related branches found
No related tags found
No related merge requests found
package bdv.server;
import compression.quantization.scalar.LloydMaxU16ScalarQuantization;
import gnu.trove.impl.sync.TSynchronizedShortByteMap;
import mpicbg.spim.data.SpimDataException;
import org.apache.commons.cli.*;
......@@ -46,46 +45,39 @@ import java.util.Map.Entry;
* by default.)
* -m enable statistics and manager context. EXPERIMENTAL!
* </pre>
*
* <p>
* To enable the {@code -m} option, build with
* {@link Constants#ENABLE_EXPERIMENTAL_FEATURES} set to {@code true}.
*
* @author Tobias Pietzsch &lt;tobias.pietzsch@gmail.com&gt;
* @author HongKee Moon &lt;moon@mpi-cbg.quantization.de&gt;
*/
public class BigDataServer
{
public class BigDataServer {
private static final org.eclipse.jetty.util.log.Logger LOG = Log.getLogger(BigDataServer.class);
private static LloydMaxU16ScalarQuantization quantizer;
static Parameters getDefaultParameters()
{
static Parameters getDefaultParameters() {
final int port = 8080;
String hostname;
try
{
try {
hostname = InetAddress.getLocalHost().getHostName();
}
catch ( final UnknownHostException e )
{
} catch (final UnknownHostException e) {
hostname = "localhost";
}
final String thumbnailDirectory = null;
final boolean enableManagerContext = false;
return new Parameters( port, hostname, new HashMap< String, String >(), thumbnailDirectory, enableManagerContext, CellHandler.DumpFile);
return new Parameters(port, hostname, new HashMap<String, String>(), thumbnailDirectory, enableManagerContext,
new CustomCompressionParameters("", "", 8, false, false));
}
public static void main( final String[] args ) throws Exception
{
public static void main(final String[] args) throws Exception {
System.setProperty("org.eclipse.jetty.util.log.class", "org.eclipse.jetty.util.log.StdErrLog");
final Parameters params = processOptions(args, getDefaultParameters());
if (params == null)
return;
CellHandler.DumpFile = params.getDumpFile();
final String thumbnailsDirectoryName = getThumbnailDirectoryPath(params);
// Threadpool for multiple connections
......@@ -100,19 +92,24 @@ public class BigDataServer
final String baseURL = "http://" + server.getURI().getHost() + ":" + params.getPort();
quantizer = new LloydMaxU16ScalarQuantization("D:\\tmp\\server-dump\\initial_load.bin",8);
final CustomCompressionParameters compParams = params.getCompressionParams();
if (compParams.shouldCompressData() || compParams.renderDifference()) {
//TODO(Moravec): Replace LloydMaxU16ScalarQuantization with some ICompressor.
quantizer = new LloydMaxU16ScalarQuantization(compParams.getTrainFile(), compParams.getBitTarget());
quantizer.train(true);
}
// Handler initialization
final HandlerCollection handlers = new HandlerCollection();
final ContextHandlerCollection datasetHandlers = createHandlers( baseURL, params.getDatasets(), thumbnailsDirectoryName );
final ContextHandlerCollection datasetHandlers = createHandlers(baseURL, params, thumbnailsDirectoryName);
handlers.addHandler(datasetHandlers);
handlers.addHandler(new JsonDatasetListHandler(server, datasetHandlers));
Handler handler = handlers;
if ( params.enableManagerContext() )
{
if (params.enableManagerContext()) {
// Add Statistics bean to the connector
final ConnectorStatistics connectorStats = new ConnectorStatistics();
connector.addBean(connectorStats);
......@@ -125,7 +122,6 @@ public class BigDataServer
}
LOG.info("Set handler: " + handler);
server.setHandler(handler);
LOG.info("Server Base URL: " + baseURL);
......@@ -137,8 +133,7 @@ public class BigDataServer
/**
* Server parameters: hostname, port, datasets.
*/
private static class Parameters
{
private static class Parameters {
private final int port;
private final String hostname;
......@@ -150,32 +145,31 @@ public class BigDataServer
private final String thumbnailDirectory;
private final String dumpFile;
private final CustomCompressionParameters compressionParam;
private final boolean enableManagerContext;
Parameters( final int port, final String hostname, final Map< String, String > datasetNameToXml, final String thumbnailDirectory, final boolean enableManagerContext, final String dumpFile)
{
Parameters(final int port, final String hostname, final Map<String, String> datasetNameToXml,
final String thumbnailDirectory, final boolean enableManagerContext,
final CustomCompressionParameters customCompressionParameters) {
this.port = port;
this.hostname = hostname;
this.datasetNameToXml = datasetNameToXml;
this.thumbnailDirectory = thumbnailDirectory;
this.enableManagerContext = enableManagerContext;
this.dumpFile = dumpFile;
this.compressionParam = customCompressionParameters;
}
public int getPort()
{
public int getPort() {
return port;
}
public String getHostname()
{
public String getHostname() {
return hostname;
}
public String getThumbnailDirectory()
{
public String getThumbnailDirectory() {
return thumbnailDirectory;
}
......@@ -184,24 +178,28 @@ public class BigDataServer
*
* @return datasets as a map from dataset name to dataset xml path.
*/
public Map< String, String > getDatasets()
{
public Map<String, String> getDatasets() {
return datasetNameToXml;
}
public boolean enableManagerContext()
{
public boolean enableManagerContext() {
return enableManagerContext;
}
public String getDumpFile() {
return dumpFile;
public CustomCompressionParameters getCompressionParams() {
return compressionParam;
}
}
@SuppressWarnings("static-access")
static private Parameters processOptions( final String[] args, final Parameters defaultParameters ) throws IOException
{
static private Parameters processOptions(final String[] args, final Parameters defaultParameters) throws IOException {
final String BIT_TARGET = "bits";
final String ENABLE_COMPRESSION = "compression";
final String ENABLE_COMPRESSION_DIFF = "diff";
final String DUMP_FILE = "dump";
final String TRAIN_FILE = "train";
// create Options object
final Options options = new Options();
......@@ -238,20 +236,38 @@ public class BigDataServer
options.addOption(OptionBuilder
.withDescription( "File in which to store data dump" )
.withDescription("File in which to store request data dump")
.hasArg()
.withArgName("DUMP")
.create( "dump" ) );
.create(DUMP_FILE));
options.addOption(OptionBuilder
.withDescription("Enable request compression")
.create(ENABLE_COMPRESSION));
options.addOption(OptionBuilder
.withDescription("Compression train file")
.hasArg()
.withArgName("TRAINFILE")
.create(TRAIN_FILE));
options.addOption(OptionBuilder
.withDescription("Compression bit target")
.hasArg()
.withArgName("BITS")
.create(BIT_TARGET));
if ( Constants.ENABLE_EXPERIMENTAL_FEATURES )
{
options.addOption(OptionBuilder
.withDescription("Send compression difference")
.create(ENABLE_COMPRESSION_DIFF));
if (Constants.ENABLE_EXPERIMENTAL_FEATURES) {
options.addOption(OptionBuilder
.withDescription("enable statistics and manager context. EXPERIMENTAL!")
.create("m"));
}
try
{
try {
final CommandLineParser parser = new BasicParser();
final CommandLine cmd = parser.parse(options, args);
......@@ -259,7 +275,6 @@ public class BigDataServer
final String portString = cmd.getOptionValue("p", Integer.toString(defaultParameters.getPort()));
final int port = Integer.parseInt(portString);
final String dumpFile = cmd.getOptionValue("dump", defaultParameters.getDumpFile());
// Getting server name option
final String serverName = cmd.getOptionValue("s", defaultParameters.getHostname());
......@@ -267,19 +282,36 @@ public class BigDataServer
// Getting thumbnail directory option
final String thumbnailDirectory = cmd.getOptionValue("t", defaultParameters.getThumbnailDirectory());
final HashMap<String, String> datasets = new HashMap<String, String>(defaultParameters.getDatasets());
// Custom compression parameters
//cmd.hasOption()
final HashMap< String, String > datasets = new HashMap< String, String >( defaultParameters.getDatasets() );
final String dumpFile = cmd.getOptionValue(DUMP_FILE, "");
final boolean enableCompression = cmd.hasOption(ENABLE_COMPRESSION);
final boolean enableCompressionDiff = cmd.hasOption(ENABLE_COMPRESSION_DIFF);
final String trainFile = cmd.getOptionValue(TRAIN_FILE, "");
final int bitTarget = Integer.parseInt(cmd.getOptionValue(BIT_TARGET, "8"));
if ((enableCompression || enableCompressionDiff) && (trainFile.isEmpty())) {
throw new MissingArgumentException(String.format("!!! %s must be specified when %s or %s is specified !!!",
TRAIN_FILE, ENABLE_COMPRESSION, ENABLE_COMPRESSION_DIFF));
}
final CustomCompressionParameters customCompParams = new CustomCompressionParameters(dumpFile, trainFile, bitTarget,
enableCompression, enableCompressionDiff);
LOG.info("Compression is " + (enableCompression ? "Matched" : "Not matched"));
LOG.info("Compression-Diff is " + (enableCompressionDiff ? "Matched" : "Not matched"));
boolean enableManagerContext = false;
if ( Constants.ENABLE_EXPERIMENTAL_FEATURES )
{
if (Constants.ENABLE_EXPERIMENTAL_FEATURES) {
if (cmd.hasOption("m"))
enableManagerContext = true;
}
if ( cmd.hasOption( "d" ) )
{
if (cmd.hasOption("d")) {
// process the file given with "-d"
final String datasetFile = cmd.getOptionValue("d");
......@@ -292,17 +324,13 @@ public class BigDataServer
// Process dataset list file
final List<String> lines = Files.readAllLines(path, StandardCharsets.UTF_8);
for ( final String str : lines )
{
for (final String str : lines) {
final String[] tokens = str.split("\\s*\\t\\s*");
if ( tokens.length == 2 && StringUtils.isNotEmpty( tokens[ 0 ].trim() ) && StringUtils.isNotEmpty( tokens[ 1 ].trim() ) )
{
if (tokens.length == 2 && StringUtils.isNotEmpty(tokens[0].trim()) && StringUtils.isNotEmpty(tokens[1].trim())) {
final String name = tokens[0].trim();
final String xmlpath = tokens[1].trim();
tryAddDataset(datasets, name, xmlpath);
}
else
{
} else {
LOG.warn("Invalid dataset file line (will be skipped): {" + str + "}");
}
}
......@@ -314,8 +342,7 @@ public class BigDataServer
if (leftoverArgs.length % 2 != 0)
throw new IllegalArgumentException("Dataset list has an error while processing.");
for ( int i = 0; i < leftoverArgs.length; i += 2 )
{
for (int i = 0; i < leftoverArgs.length; i += 2) {
final String name = leftoverArgs[i];
final String xmlpath = leftoverArgs[i + 1];
tryAddDataset(datasets, name, xmlpath);
......@@ -324,10 +351,9 @@ public class BigDataServer
if (datasets.isEmpty())
throw new IllegalArgumentException("Dataset list is empty.");
return new Parameters( port, serverName, datasets, thumbnailDirectory, enableManagerContext, dumpFile );
}
catch ( final ParseException | IllegalArgumentException e )
{
return new Parameters(port, serverName, datasets, thumbnailDirectory, enableManagerContext,
customCompParams);
} catch (final ParseException | IllegalArgumentException e) {
LOG.warn(e.getMessage());
System.out.println();
final HelpFormatter formatter = new HelpFormatter();
......@@ -336,8 +362,7 @@ public class BigDataServer
return null;
}
private static void tryAddDataset( final HashMap< String, String > datasetNameToXML, final String name, final String xmlpath ) throws IllegalArgumentException
{
private static void tryAddDataset(final HashMap<String, String> datasetNameToXML, final String name, final String xmlpath) throws IllegalArgumentException {
for (final String reserved : Constants.RESERVED_CONTEXT_NAMES)
if (name.equals(reserved))
throw new IllegalArgumentException("Cannot use dataset name: \"" + name + "\" (reserved for internal use).");
......@@ -349,27 +374,19 @@ public class BigDataServer
LOG.info("Dataset added: {" + name + ", " + xmlpath + "}");
}
private static String getThumbnailDirectoryPath( final Parameters params ) throws IOException
{
private static String getThumbnailDirectoryPath(final Parameters params) throws IOException {
final String thumbnailDirectoryName = params.getThumbnailDirectory();
if ( thumbnailDirectoryName != null )
{
if (thumbnailDirectoryName != null) {
Path thumbnails = Paths.get(thumbnailDirectoryName);
if ( ! Files.exists( thumbnails ) )
{
try
{
if (!Files.exists(thumbnails)) {
try {
thumbnails = Files.createDirectories(thumbnails);
return thumbnails.toFile().getAbsolutePath();
}
catch ( final IOException e )
{
} catch (final IOException e) {
LOG.warn(e.getMessage());
LOG.warn("Could not create thumbnails directory \"" + thumbnailDirectoryName + "\".\n Trying to create temporary directory.");
}
}
else
{
} else {
if (!Files.isDirectory(thumbnails))
LOG.warn("Thumbnails directory \"" + thumbnailDirectoryName + "\" is not a directory.\n Trying to create temporary directory.");
else
......@@ -381,16 +398,21 @@ public class BigDataServer
return thumbnails.toFile().getAbsolutePath();
}
private static ContextHandlerCollection createHandlers( final String baseURL, final Map< String, String > dataSet, final String thumbnailsDirectoryName ) throws SpimDataException, IOException
{
private static ContextHandlerCollection createHandlers(final String baseURL,
final Parameters params,
final String thumbnailsDirectoryName) throws SpimDataException, IOException {
final ContextHandlerCollection handlers = new ContextHandlerCollection();
for ( final Entry< String, String > entry : dataSet.entrySet() )
{
final Map<String, String> dataSet = params.getDatasets();
for (final Entry<String, String> entry : dataSet.entrySet()) {
final String name = entry.getKey();
final String xmlpath = entry.getValue();
final String context = "/" + name;
final CellHandler ctx = new CellHandler( baseURL + context + "/", xmlpath, name, thumbnailsDirectoryName, quantizer );
final CellHandler ctx = new CellHandler(baseURL + context + "/", xmlpath, name,
thumbnailsDirectoryName,
params.getCompressionParams(), quantizer);
ctx.setContextPath(context);
handlers.addHandler(ctx);
}
......
......@@ -11,6 +11,7 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import compression.quantization.scalar.LloydMaxU16ScalarQuantization;
import compression.utilities.Utils;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.util.log.Log;
......@@ -42,13 +43,11 @@ import mpicbg.spim.data.SpimDataException;
import net.imglib2.img.basictypeaccess.volatiles.array.VolatileShortArray;
import net.imglib2.realtransform.AffineTransform3D;
public class CellHandler extends ContextHandler
{
public class CellHandler extends ContextHandler {
private long transferedDataSize = 0;
private static final org.eclipse.jetty.util.log.Logger LOG = Log.getLogger(CellHandler.class);
public static String DumpFile = "";
private int counter = 0;
private final VolatileGlobalCellCache cache;
......@@ -91,16 +90,19 @@ public class CellHandler extends ContextHandler
* Full path to thumbnail png.
*/
private final String thumbnailFilename;
final CustomCompressionParameters compressionParams;
private LloydMaxU16ScalarQuantization quantizer;
public CellHandler(final String baseUrl, final String xmlFilename, final String datasetName, final String thumbnailsDirectory, final LloydMaxU16ScalarQuantization quantizer) throws SpimDataException, IOException
{
public CellHandler(final String baseUrl, final String xmlFilename, final String datasetName, final String thumbnailsDirectory,
final CustomCompressionParameters compressionParams,
final LloydMaxU16ScalarQuantization quantizer) throws SpimDataException, IOException {
final XmlIoSpimDataMinimal io = new XmlIoSpimDataMinimal();
final SpimDataMinimal spimData = io.load(xmlFilename);
final SequenceDescriptionMinimal seq = spimData.getSequenceDescription();
final Hdf5ImageLoader imgLoader = (Hdf5ImageLoader) seq.getImgLoader();
this.quantizer = quantizer;
this.compressionParams = compressionParams;
cache = imgLoader.getCacheControl();
loader = imgLoader.getShortArrayLoader();
......@@ -119,40 +121,34 @@ public class CellHandler extends ContextHandler
}
@Override
public void doHandle( final String target, final Request baseRequest, final HttpServletRequest request, final HttpServletResponse response ) throws IOException
{
if ( target.equals( "/settings" ) )
{
public void doHandle(final String target, final Request baseRequest, final HttpServletRequest request, final HttpServletResponse response) throws IOException {
if (target.equals("/settings")) {
if (settingsXmlString != null)
respondWithString(baseRequest, response, "application/xml", settingsXmlString);
return;
}
if ( target.equals( "/png" ) )
{
if (target.equals("/png")) {
provideThumbnail(baseRequest, response);
return;
}
final String cellString = request.getParameter("p");
if ( cellString == null )
{
if (cellString == null) {
respondWithString(baseRequest, response, "application/xml", datasetXmlString);
return;
}
final String[] parts = cellString.split("/");
if ( parts[ 0 ].equals( "cell" ) )
{
if (parts[0].equals("cell")) {
final int index = Integer.parseInt(parts[1]);
final int timepoint = Integer.parseInt(parts[2]);
final int setup = Integer.parseInt(parts[3]);
final int level = Integer.parseInt(parts[4]);
final Key key = new VolatileGlobalCellCache.Key(timepoint, setup, level, index);
VolatileCell<?> cell = cache.getLoadingVolatileCache().getIfPresent(key, cacheHints);
if ( cell == null )
{
if (cell == null) {
final int[] cellDims = new int[]{
Integer.parseInt(parts[5]),
Integer.parseInt(parts[6]),
......@@ -167,37 +163,42 @@ public class CellHandler extends ContextHandler
@SuppressWarnings("unchecked")
short[] data = ((VolatileCell<VolatileShortArray>) cell).getData().getCurrentStorageArray();
if (quantizer != null) {
if (compressionParams.shouldCompressData()) {
assert (quantizer != null) : "Compressor wasn't created";
data = quantizer.quantize(data);
} else if (compressionParams.renderDifference()) {
assert (quantizer != null) : "Compressor wasn't created";
short[] compressedData = quantizer.quantize(data);
for (int i = 0; i < data.length; i++) {
// Original - Compressed
data[i] = Utils.u16BitsToShort(data[i]-compressedData[i]);
// Compressed - Original
//data[i] = Utils.u16BitsToShort(compressedData[i]-data[i]);
}
/*
* NOTE(Moravec): This is possible place, where to compress data. Image data are inside data array, but we access only part of the image.
* if (compressionEnabled)
* {
* data = compress(data);
* }
* */
//LOG.warn("Not yet implemented.");
}
final byte[] buf = new byte[2 * data.length];
for ( int i = 0, j = 0; i < data.length; i++ )
{
for (int i = 0, j = 0; i < data.length; i++) {
final short s = data[i];
buf[j++] = (byte) ((s >> 8) & 0xff);
buf[j++] = (byte) (s & 0xff);
}
if (!DumpFile.equals("")) {
//String requestLog = String.format("%s\\request_%d_%d.data", DumpFile, buf.length, counter++);
FileOutputStream dumpStream = new FileOutputStream(DumpFile, true);
if (compressionParams.shouldDumpRequestData()) {
FileOutputStream dumpStream = new FileOutputStream(compressionParams.getDumpFile(), true);
dumpStream.write(buf);
dumpStream.flush();
dumpStream.close();
}
transferedDataSize += buf.length;
LOG.info(String.format("Total transfered data: [%d KB] [%d MB]", (transferedDataSize/1000), ((transferedDataSize/1000)/1000)));
LOG.info(String.format("I:%d;T:%d;S:%d;L:%d Total transfered data: [%d KB] [%d MB]",
index, timepoint, setup, level,
(transferedDataSize / 1000), ((transferedDataSize / 1000) / 1000)));
response.setContentType("application/octet-stream");
response.setContentLength(buf.length);
......@@ -206,21 +207,16 @@ public class CellHandler extends ContextHandler
final OutputStream os = response.getOutputStream();
os.write(buf);
os.close();
}
else if ( parts[ 0 ].equals( "init" ) )
{
} else if (parts[0].equals("init")) {
respondWithString(baseRequest, response, "application/json", metadataJson);
}
}
private void provideThumbnail( final Request baseRequest, final HttpServletResponse response ) throws IOException
{
private void provideThumbnail(final Request baseRequest, final HttpServletResponse response) throws IOException {
final Path path = Paths.get(thumbnailFilename);
if ( Files.exists( path ) )
{
if (Files.exists(path)) {
final byte[] imageData = Files.readAllBytes(path);
if ( imageData != null )
{
if (imageData != null) {
response.setContentType("image/png");
response.setContentLength(imageData.length);
response.setStatus(HttpServletResponse.SC_OK);
......@@ -233,23 +229,19 @@ public class CellHandler extends ContextHandler
}
}
public String getXmlFile()
{
public String getXmlFile() {
return xmlFilename;
}
public String getDataSetURL()
{
public String getDataSetURL() {
return dataSetURL;
}
public String getThumbnailUrl()
{
public String getThumbnailUrl() {
return dataSetURL + "png";
}
public String getDescription()
{
public String getDescription() {
throw new UnsupportedOperationException();
}
......@@ -258,8 +250,7 @@ public class CellHandler extends ContextHandler
* (image sizes and resolutions) provided by the given
* {@link Hdf5ImageLoader}.
*/
private static String buildMetadataJsonString( final Hdf5ImageLoader imgLoader, final SequenceDescriptionMinimal seq )
{
private static String buildMetadataJsonString(final Hdf5ImageLoader imgLoader, final SequenceDescriptionMinimal seq) {
final RemoteImageLoaderMetaData metadata = new RemoteImageLoaderMetaData(imgLoader, seq);
final GsonBuilder gsonBuilder = new GsonBuilder();
gsonBuilder.registerTypeAdapter(AffineTransform3D.class, new AffineTransform3DJsonSerializer());
......@@ -271,8 +262,7 @@ public class CellHandler extends ContextHandler
* Create a modified dataset XML by replacing the ImageLoader with an
* {@link RemoteImageLoader} pointing to the data we are serving.
*/
private static String buildRemoteDatasetXML( final XmlIoSpimDataMinimal io, final SpimDataMinimal spimData, final String baseUrl ) throws IOException, SpimDataException
{
private static String buildRemoteDatasetXML(final XmlIoSpimDataMinimal io, final SpimDataMinimal spimData, final String baseUrl) throws IOException, SpimDataException {
final SpimDataMinimal s = new SpimDataMinimal(spimData, new RemoteImageLoader(baseUrl, false));
final Document doc = new Document(io.toXml(s, s.getBasePath()));
final XMLOutputter xout = new XMLOutputter(Format.getPrettyFormat());
......@@ -287,22 +277,17 @@ public class CellHandler extends ContextHandler
* @return contents of {@code baseFilename.settings.xml} or {@code null} if
* that file couldn't be read.
*/
private static String buildSettingsXML( final String baseFilename )
{
private static String buildSettingsXML(final String baseFilename) {
final String settings = baseFilename + ".settings.xml";
if ( new File( settings ).exists() )
{
try
{
if (new File(settings).exists()) {
try {
final SAXBuilder sax = new SAXBuilder();
final Document doc = sax.build(settings);
final XMLOutputter xout = new XMLOutputter(Format.getPrettyFormat());
final StringWriter sw = new StringWriter();
xout.output(doc, sw);
return sw.toString();
}
catch ( JDOMException | IOException e )
{
} catch (JDOMException | IOException e) {
LOG.warn("Could not read settings file \"" + settings + "\"");
LOG.warn(e.getMessage());
}
......@@ -313,19 +298,15 @@ public class CellHandler extends ContextHandler
/**
* Create PNG thumbnail file named "{@code <baseFilename>.png}".
*/
private static String createThumbnail( final SpimDataMinimal spimData, final String baseFilename, final String datasetName, final String thumbnailsDirectory )
{
private static String createThumbnail(final SpimDataMinimal spimData, final String baseFilename, final String datasetName, final String thumbnailsDirectory) {
final String thumbnailFileName = thumbnailsDirectory + "/" + datasetName + ".png";
final File thumbnailFile = new File(thumbnailFileName);
if (!thumbnailFile.isFile()) // do not recreate thumbnail if it already exists
{
final BufferedImage bi = ThumbnailGenerator.makeThumbnail(spimData, baseFilename, Constants.THUMBNAIL_WIDTH, Constants.THUMBNAIL_HEIGHT);
try
{
try {
ImageIO.write(bi, "png", thumbnailFile);
}
catch ( final IOException e )
{
} catch (final IOException e) {
LOG.warn("Could not create thumbnail png for dataset \"" + baseFilename + "\"");
LOG.warn(e.getMessage());
}
......@@ -336,8 +317,7 @@ public class CellHandler extends ContextHandler
/**
* Handle request by sending a UTF-8 string.
*/
private static void respondWithString( final Request baseRequest, final HttpServletResponse response, final String contentType, final String string ) throws IOException
{
private static void respondWithString(final Request baseRequest, final HttpServletResponse response, final String contentType, final String string) throws IOException {
response.setContentType(contentType);
response.setCharacterEncoding("UTF-8");
response.setStatus(HttpServletResponse.SC_OK);
......
package bdv.server;
public class CustomCompressionParameters {
private final boolean dumpRequestData;
private final String dumpFile;
private final String trainFile;
private final int bitTarget;
public String getTrainFile() {
return trainFile;
}
public int getBitTarget() {
return bitTarget;
}
private final boolean enableRequestCompression;
private final boolean renderDifference;
public CustomCompressionParameters(final String dumpFile,
final String trainFile,
final int bitTarget,
final boolean enableRequestCompression,
final boolean renderDifference) {
this.dumpFile = dumpFile;
this.trainFile = trainFile;
this.bitTarget=bitTarget;
this.dumpRequestData = !this.dumpFile.isEmpty();
this.enableRequestCompression = enableRequestCompression;
this.renderDifference = renderDifference;
}
public boolean shouldDumpRequestData() {
return dumpRequestData;
}
public String getDumpFile() {
return dumpFile;
}
public boolean shouldCompressData() {
return enableRequestCompression;
}
public boolean renderDifference() {
return renderDifference;
}
}
......@@ -27,8 +27,7 @@ import java.text.DecimalFormat;
* @author HongKee Moon &lt;moon@mpi-cbg.quantization.de&gt;
* @author Tobias Pietzsch &lt;tobias.pietzsch@gmail.com&gt;
*/
public class ManagerHandler extends ContextHandler
{
public class ManagerHandler extends ContextHandler {
private static final org.eclipse.jetty.util.log.Logger LOG = Log.getLogger(ManagerHandler.class);
private final String baseURL;
......@@ -56,8 +55,7 @@ public class ManagerHandler extends ContextHandler
final StatisticsHandler statHandler,
final ContextHandlerCollection handlers,
final String thumbnailsDirectoryName)
throws IOException, URISyntaxException
{
throws IOException, URISyntaxException {
this.baseURL = baseURL;
this.server = server;
this.handlers = handlers;
......@@ -68,29 +66,22 @@ public class ManagerHandler extends ContextHandler
}
@Override
public void doHandle( final String target, final Request baseRequest, final HttpServletRequest request, final HttpServletResponse response ) throws IOException, ServletException
{
public void doHandle(final String target, final Request baseRequest, final HttpServletRequest request, final HttpServletResponse response) throws IOException, ServletException {
final String op = request.getParameter("op");
if ( op == null )
{
if (op == null) {
list(baseRequest, response);
}
else if ( op.equals( "deploy" ) )
{
} else if (op.equals("deploy")) {
final String ds = request.getParameter("ds");
final String file = request.getParameter("file");
deploy(ds, file, baseRequest, response);
}
else if ( op.equals( "undeploy" ) )
{
} else if (op.equals("undeploy")) {
final String ds = request.getParameter("ds");
undeploy(ds, baseRequest, response);
}
}
public String getByteSizeString( final long size )
{
public String getByteSizeString(final long size) {
if (size <= 0)
return "0";
final String[] units = new String[]{"B", "kB", "MB", "GB", "TB"};
......@@ -98,8 +89,7 @@ public class ManagerHandler extends ContextHandler
return new DecimalFormat("#,##0.#").format(size / Math.pow(1024, digitGroups)) + " " + units[digitGroups];
}
private void list( final Request baseRequest, final HttpServletResponse response ) throws IOException
{
private void list(final Request baseRequest, final HttpServletResponse response) throws IOException {
response.setContentType("text/html");
response.setStatus(HttpServletResponse.SC_OK);
baseRequest.setHandled(true);
......@@ -110,8 +100,7 @@ public class ManagerHandler extends ContextHandler
ow.close();
}
private String getHtml()
{
private String getHtml() {
final StringTemplateGroup templates = new StringTemplateGroup("manager");
final StringTemplate t = templates.getInstanceOf("templates/manager");
......@@ -132,16 +121,13 @@ public class ManagerHandler extends ContextHandler
return t.toString();
}
private void getContexts()
{
if ( contexts == null )
{
private void getContexts() {
if (contexts == null) {
noDataSets = 0;
sizeDataSets = 0;
final StringBuilder sb = new StringBuilder();
for ( final Handler handler : server.getChildHandlersByClass( CellHandler.class ) )
{
for (final Handler handler : server.getChildHandlersByClass(CellHandler.class)) {
sb.append("<tr>\n<th>");
final CellHandler contextHandler = (CellHandler) handler;
sb.append(contextHandler.getContextPath() + "</th>\n<td>");
......@@ -153,32 +139,27 @@ public class ManagerHandler extends ContextHandler
}
}
private void deploy( final String datasetName, final String fileLocation, final Request baseRequest, final HttpServletResponse response ) throws IOException
{
private void deploy(final String datasetName, final String fileLocation, final Request baseRequest, final HttpServletResponse response) throws IOException {
LOG.info("Add new context: " + datasetName);
final String context = "/" + datasetName;
boolean alreadyExists = false;
for ( final Handler handler : server.getChildHandlersByClass( CellHandler.class ) )
{
for (final Handler handler : server.getChildHandlersByClass(CellHandler.class)) {
final CellHandler contextHandler = (CellHandler) handler;
if ( context.equals( contextHandler.getContextPath() ) )
{
if (context.equals(contextHandler.getContextPath())) {
LOG.info("Context " + datasetName + " already exists.");
alreadyExists = true;
break;
}
}
if ( ! alreadyExists )
{
if (!alreadyExists) {
CellHandler ctx = null;
try
{
ctx = new CellHandler( baseURL + context + "/", fileLocation, datasetName, thumbnailsDirectoryName, null );
}
catch ( final SpimDataException e )
{
try {
LOG.warn("We are creating CellHandler without compression params!");
ctx = new CellHandler(baseURL + context + "/", fileLocation, datasetName, thumbnailsDirectoryName,
null, null);
} catch (final SpimDataException e) {
LOG.warn("Failed to create a CellHandler", e);
e.printStackTrace();
}
......@@ -198,23 +179,17 @@ public class ManagerHandler extends ContextHandler
ow.close();
}
private void undeploy( final String datasetName, final Request baseRequest, final HttpServletResponse response ) throws IOException
{
private void undeploy(final String datasetName, final Request baseRequest, final HttpServletResponse response) throws IOException {
LOG.info("Remove the context: " + datasetName);
boolean ret = false;
final String context = "/" + datasetName;
for ( final Handler handler : server.getChildHandlersByClass( CellHandler.class ) )
{
for (final Handler handler : server.getChildHandlersByClass(CellHandler.class)) {
final CellHandler contextHandler = (CellHandler) handler;
if ( context.equals( contextHandler.getContextPath() ) )
{
try
{
if (context.equals(contextHandler.getContextPath())) {
try {
contextHandler.stop();
}
catch ( final Exception e )
{
} catch (final Exception e) {
e.printStackTrace();
}
contextHandler.destroy();
......@@ -224,8 +199,7 @@ public class ManagerHandler extends ContextHandler
}
}
if ( ret )
{
if (ret) {
response.setContentType("text/html");
response.setStatus(HttpServletResponse.SC_OK);
baseRequest.setHandled(true);
......
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta http-equiv="refresh" content="5"/>
<title>BigDataServer</title>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap-theme.min.css">
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"></script>
</head>
<body class="tundra">
This page is refreshed in every 5 secs.<br/>
<div class="contentelement">
<h1>$title$</h1>
<hr>
<table cellspacing="2">
<tr>
<th>Bytes sent total:</th>
<td>$bytesSent$</td>
</tr>
<tr>
<th>Messages per second:</th>
<td>$msgPerSec$</td>
</tr>
<tr>
<th>Open connections:</th>
<td>$openConnections$</td>
</tr>
<tr>
<th>Max open connections:</th>
<td>$maxOpenConnections$</td>
</tr>
<tr>
<th>Number of datasets:</th>
<td>$noDataSets$</td>
</tr>
<tr>
<th>Total size of datasets:</th>
<td>$sizeDataSets$</td>
</tr>
</table>
<hr>
<h1> Datasets: </h1>
<table cellspacing="2">
$contexts$
</table>
<hr>
<table cellspacing="2">
<tr>
<td>
$statHtml$
</td>
</tr>
</table>
</div>
</body>
</html>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment