Numass server test

This commit is contained in:
Alexander Nozik 2017-05-15 10:18:36 +03:00
parent ac312b7671
commit 15314d2d07
5 changed files with 75 additions and 23 deletions

View File

@ -6,6 +6,7 @@
package inr.numass.server;
import freemarker.template.Template;
import hep.dataforge.server.ServerManager;
import hep.dataforge.server.ServletUtils;
import hep.dataforge.storage.api.Loader;
import hep.dataforge.storage.api.StateLoader;
@ -31,6 +32,7 @@ public class NumassRootHandler implements Handler {
private final JSONMetaWriter writer = new JSONMetaWriter();
NumassServer server;
ServerManager manager;
public NumassRootHandler(NumassServer server) {
this.server = server;
@ -66,7 +68,7 @@ public class NumassRootHandler implements Handler {
StringBuilder b = new StringBuilder();
Storage rootStorage = server.getRun().getStorage();
rootStorage.refresh();
renderStorage(b, rootStorage);
renderStorage(b,manager.resolveObject(rootStorage), rootStorage);
data.put("storageContent", b.toString());
} catch (Exception ex) {
data.put("storageContent", ex.toString());

View File

@ -27,14 +27,9 @@ import hep.dataforge.storage.filestorage.FileStorage;
import inr.numass.storage.NumassStorage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ratpack.handling.Chain;
import ratpack.server.BaseDir;
import ratpack.server.RatpackServer;
import ratpack.server.RatpackServerSpec;
import ratpack.server.ServerConfigBuilder;
import java.io.IOException;
import java.net.InetAddress;
/**
*
@ -81,18 +76,18 @@ public class NumassServer extends AbstractNetworkListener {
public void open() throws Exception {
super.open();
int port = meta().getInt("ratpack.port", 8336);
ratpack = RatpackServer.start((RatpackServerSpec server) -> server
.serverConfig((ServerConfigBuilder config) -> config
// .baseDir(Paths.get(getClass().getResource("/ratpack/.ratpack").toURI()))
.baseDir(BaseDir.find())
.address(InetAddress.getLocalHost())
.port(port))
.handlers((Chain chain) -> chain
.files()
.get(new NumassRootHandler(this))
.get("storage", new NumassStorageHandler(root))
)
);
// ratpack = RatpackServer.start((RatpackServerSpec server) -> server
// .serverConfig((ServerConfigBuilder config) -> config
//// .baseDir(Paths.get(getClass().getResource("/ratpack/.ratpack").toURI()))
// .baseDir(BaseDir.find())
// .address(InetAddress.getLocalHost())
// .port(port))
// .handlers((Chain chain) -> chain
// .files()
// .get(new NumassRootHandler(this))
// .get("storage", new NumassStorageHandler(root))
// )
// );
}
private void startRun(Meta annotation) throws StorageException {

View File

@ -7,6 +7,7 @@ package inr.numass.server;
import freemarker.template.Template;
import hep.dataforge.meta.MetaBuilder;
import hep.dataforge.server.ServerManager;
import hep.dataforge.server.ServletUtils;
import hep.dataforge.server.StorageRatpackHandler;
import hep.dataforge.storage.api.ObjectLoader;
@ -38,8 +39,8 @@ public class NumassStorageHandler extends StorageRatpackHandler {
.withLocale(Locale.US)
.withZone(ZoneId.systemDefault());
public NumassStorageHandler(Storage root) {
super(root);
public NumassStorageHandler(ServerManager manager, Storage root) {
super(manager, root);
}
@Override
@ -74,7 +75,7 @@ public class NumassStorageHandler extends StorageRatpackHandler {
@Override
protected MetaBuilder pointLoaderPlotOptions(PointLoader loader) {
MetaBuilder builder = super.pointLoaderPlotOptions(loader);
if (loader.getName().contains("msp") || loader.getName().contains("vac")) {
if (loader.getName().startsWith("msp") || loader.getName().startsWith("vac") || loader.getName().startsWith("cryptemp")) {
builder.putValue("legend.position", "bottom");
builder.putValue("title", "\"" + loader.getName() + "\"");
builder.putNode(new MetaBuilder("vAxis")

View File

@ -37,7 +37,7 @@ public class ServerRunner extends SimpleConfigurable implements AutoCloseable {
try (ServerRunner r = new ServerRunner()) {
r.start();
Runtime.getRuntime().addShutdownHook(new Thread(()->{
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
logger.info("Shutting down");
r.close();
}));
@ -57,7 +57,7 @@ public class ServerRunner extends SimpleConfigurable implements AutoCloseable {
// repoConfig = meta().getMeta(NUMASS_REPO_ELEMENT);
// }
logger.info("Initializing file storage in {}", repoPath);
root = NumassStorage.buildLocalNumassRoot(new File(repoPath),true);//in(new File(repoPath), repoConfig);
root = NumassStorage.buildLocalNumassRoot(new File(repoPath), true, true);//in(new File(repoPath), repoConfig);
logger.info("Starting numass server");
if (root != null) {

View File

@ -0,0 +1,54 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and read the template in the editor.
*/
package inr.numass.server;
import hep.dataforge.context.Context;
import hep.dataforge.context.Global;
import hep.dataforge.server.ServerManager;
import hep.dataforge.storage.commons.StorageManager;
import inr.numass.storage.NumassStorage;
import java.io.BufferedReader;
import java.io.File;
import java.io.InputStreamReader;
/**
* @author Alexander Nozik
*/
public class TestServer {
/**
* @param args the command line arguments
* @throws hep.dataforge.exceptions.StorageException
*/
public static void main(String[] args) throws Exception {
Context context = Global.getContext("NUMASS-SERVER");
StorageManager storageManager = context.pluginManager().load(StorageManager.class);
ServerManager serverManager = context.pluginManager().load(ServerManager.class);
String path = "D:/temp/test";
context.getLogger().info("Starting test numass storage servlet in '{}'", path);
NumassStorage storage = NumassStorage.buildLocalNumassRoot(new File(path), true, true);
serverManager.addObject("numass", storage, st -> new NumassStorageHandler(serverManager, st));
serverManager.startSetver();
String stopLine = "";
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
while (stopLine == null || !stopLine.startsWith("exit")) {
// print ">"
stopLine = br.readLine();
}
System.out.println("Stopping ratpack");
serverManager.stopServer();
}
}