Global update for storage and control

This commit is contained in:
Alexander Nozik 2017-05-17 22:55:17 +03:00
parent 4f0b12bbad
commit 4e5b3bb885
22 changed files with 184 additions and 214 deletions

View File

@ -1,50 +0,0 @@
package inr.numass.client;
import hep.dataforge.exceptions.StorageException;
import hep.dataforge.meta.Meta;
import hep.dataforge.storage.api.Loader;
import hep.dataforge.storage.api.Storage;
import hep.dataforge.storage.commons.AbstractStorage;
import java.io.IOException;
/**
* Created by darksnake on 09-Oct-16.
*/
public class RemoteNumassStorage extends AbstractStorage {
private NumassClient client;
private RemoteNumassStorage(Storage parent, String name, Meta annotation) {
super(parent, name, annotation);
}
public RemoteNumassStorage(String name) {
super(name);
}
private String getIP() {
return meta().getString("numass.server.ip", "192.168.111.1");
}
private int getPort() {
return meta().getInt("numass.server.port", 8335);
}
private NumassClient getClient() throws IOException {
if (client == null) {
client = new NumassClient(getIP(), getPort());
}
return client;
}
@Override
public Loader buildLoader(Meta loaderConfiguration) throws StorageException {
throw new UnsupportedOperationException();
}
@Override
public Storage buildShelf(String shelfName, Meta shelfConfiguration) throws StorageException {
return new RemoteNumassStorage(this, shelfName, shelfConfiguration);
}
}

View File

@ -15,7 +15,6 @@ class BoardView : View("Numass control board") {
deviceList = vbox { deviceList = vbox {
bindChildren(controller.devices) { DeviceInfoView(it).root } bindChildren(controller.devices) { DeviceInfoView(it).root }
} }
} }
} }

View File

@ -16,11 +16,11 @@
package inr.numass.cryotemp; package inr.numass.cryotemp;
import hep.dataforge.context.Context; import hep.dataforge.context.Context;
import hep.dataforge.control.RoleDef;
import hep.dataforge.control.collectors.RegularPointCollector; import hep.dataforge.control.collectors.RegularPointCollector;
import hep.dataforge.control.connections.Roles; import hep.dataforge.control.connections.Roles;
import hep.dataforge.control.connections.StorageConnection; import hep.dataforge.control.connections.StorageConnection;
import hep.dataforge.control.devices.PortSensor; import hep.dataforge.control.devices.PortSensor;
import hep.dataforge.control.devices.annotations.RoleDef;
import hep.dataforge.control.measurements.AbstractMeasurement; import hep.dataforge.control.measurements.AbstractMeasurement;
import hep.dataforge.control.measurements.Measurement; import hep.dataforge.control.measurements.Measurement;
import hep.dataforge.control.ports.PortHandler; import hep.dataforge.control.ports.PortHandler;
@ -77,7 +77,7 @@ public class PKT8Device extends PortSensor<PKT8Result> {
public PKT8Device(Context context, Meta meta) { public PKT8Device(Context context, Meta meta) {
setContext(context); setContext(context);
setMetaBase(meta); setMeta(meta);
} }
private PointLoader buildLoader(StorageConnection connection) { private PointLoader buildLoader(StorageConnection connection) {

View File

@ -16,11 +16,11 @@
package inr.numass.control.msp; package inr.numass.control.msp;
import hep.dataforge.context.Context; import hep.dataforge.context.Context;
import hep.dataforge.control.RoleDef;
import hep.dataforge.control.connections.Roles; import hep.dataforge.control.connections.Roles;
import hep.dataforge.control.connections.StorageConnection; import hep.dataforge.control.connections.StorageConnection;
import hep.dataforge.control.devices.SingleMeasurementDevice; import hep.dataforge.control.devices.SingleMeasurementDevice;
import hep.dataforge.control.devices.annotations.RoleDef; import hep.dataforge.control.devices.StateDef;
import hep.dataforge.control.devices.annotations.StateDef;
import hep.dataforge.control.measurements.AbstractMeasurement; import hep.dataforge.control.measurements.AbstractMeasurement;
import hep.dataforge.control.measurements.Measurement; import hep.dataforge.control.measurements.Measurement;
import hep.dataforge.control.ports.PortHandler; import hep.dataforge.control.ports.PortHandler;
@ -75,7 +75,7 @@ public class MspDevice extends SingleMeasurementDevice implements PortHandler.Po
public MspDevice(Context context, Meta meta) { public MspDevice(Context context, Meta meta) {
setContext(context); setContext(context);
setMetaBase(meta); setMeta(meta);
} }
// public MspDevice(String name, Context context, Meta config) { // public MspDevice(String name, Context context, Meta config) {

View File

@ -39,6 +39,8 @@ public class NumassControlUtils {
String numassRun = ClientUtils.getRunName(config); String numassRun = ClientUtils.getRunName(config);
config.getMetaList("storage").forEach(node -> { config.getMetaList("storage").forEach(node -> {
device.getContext().getLogger().debug("Creating storage for device with meta: {}", node); device.getContext().getLogger().debug("Creating storage for device with meta: {}", node);
//building storage in a separate thread
new Thread(() -> {
Storage storage = StorageFactory.buildStorage(device.getContext(), node); Storage storage = StorageFactory.buildStorage(device.getContext(), node);
if (!numassRun.isEmpty()) { if (!numassRun.isEmpty()) {
try { try {
@ -48,6 +50,7 @@ public class NumassControlUtils {
} }
} }
device.connect(new StorageConnection(storage), Roles.STORAGE_ROLE); device.connect(new StorageConnection(storage), Roles.STORAGE_ROLE);
}).start();
}); });
} }
} }

View File

@ -28,7 +28,7 @@ public class CM32Device extends PortSensor<Double> {
public CM32Device(Context context, Meta meta) { public CM32Device(Context context, Meta meta) {
setContext(context); setContext(context);
setMetaBase(meta); setMeta(meta);
} }
@Override @Override

View File

@ -25,7 +25,7 @@ public class MKSBaratronDevice extends PortSensor<Double> {
public MKSBaratronDevice(Context context, Meta meta) { public MKSBaratronDevice(Context context, Meta meta) {
setContext(context); setContext(context);
setMetaBase(meta); setMeta(meta);
} }

View File

@ -7,7 +7,7 @@ package inr.numass.readvac;
import hep.dataforge.context.Context; import hep.dataforge.context.Context;
import hep.dataforge.control.devices.PortSensor; import hep.dataforge.control.devices.PortSensor;
import hep.dataforge.control.devices.annotations.StateDef; import hep.dataforge.control.devices.StateDef;
import hep.dataforge.control.measurements.Measurement; import hep.dataforge.control.measurements.Measurement;
import hep.dataforge.control.measurements.SimpleMeasurement; import hep.dataforge.control.measurements.SimpleMeasurement;
import hep.dataforge.control.ports.PortHandler; import hep.dataforge.control.ports.PortHandler;
@ -35,7 +35,7 @@ public class MKSVacDevice extends PortSensor<Double> {
public MKSVacDevice(Context context, Meta meta) { public MKSVacDevice(Context context, Meta meta) {
setContext(context); setContext(context);
setMetaBase(meta); setMeta(meta);
} }
private String talk(String requestContent) throws ControlException { private String talk(String requestContent) throws ControlException {

View File

@ -30,7 +30,7 @@ public class MeradatVacDevice extends PortSensor<Double> {
public MeradatVacDevice(Context context, Meta meta) { public MeradatVacDevice(Context context, Meta meta) {
setContext(context); setContext(context);
setMetaBase(meta); setMeta(meta);
} }
@Override @Override

View File

@ -5,17 +5,19 @@
*/ */
package inr.numass.readvac; package inr.numass.readvac;
import hep.dataforge.context.Context;
import hep.dataforge.control.RoleDef;
import hep.dataforge.control.collectors.PointCollector; import hep.dataforge.control.collectors.PointCollector;
import hep.dataforge.control.collectors.ValueCollector; import hep.dataforge.control.collectors.ValueCollector;
import hep.dataforge.control.connections.Roles; import hep.dataforge.control.connections.Roles;
import hep.dataforge.control.connections.StorageConnection; import hep.dataforge.control.connections.StorageConnection;
import hep.dataforge.control.devices.annotations.RoleDef; import hep.dataforge.control.devices.StateDef;
import hep.dataforge.control.devices.annotations.StateDef;
import hep.dataforge.control.measurements.AbstractMeasurement; import hep.dataforge.control.measurements.AbstractMeasurement;
import hep.dataforge.control.measurements.Measurement; import hep.dataforge.control.measurements.Measurement;
import hep.dataforge.control.measurements.Sensor; import hep.dataforge.control.measurements.Sensor;
import hep.dataforge.exceptions.ControlException; import hep.dataforge.exceptions.ControlException;
import hep.dataforge.exceptions.MeasurementException; import hep.dataforge.exceptions.MeasurementException;
import hep.dataforge.meta.Meta;
import hep.dataforge.storage.api.PointLoader; import hep.dataforge.storage.api.PointLoader;
import hep.dataforge.storage.commons.LoaderFactory; import hep.dataforge.storage.commons.LoaderFactory;
import hep.dataforge.tables.DataPoint; import hep.dataforge.tables.DataPoint;
@ -45,6 +47,16 @@ import java.util.concurrent.TimeUnit;
public class VacCollectorDevice extends Sensor<DataPoint> { public class VacCollectorDevice extends Sensor<DataPoint> {
private Map<String, Sensor<Double>> sensorMap = new LinkedHashMap<>(); private Map<String, Sensor<Double>> sensorMap = new LinkedHashMap<>();
private int delay = 5000;
public VacCollectorDevice() {
}
public VacCollectorDevice(Context context, Meta meta) {
setContext(context);
setMeta(meta);
}
public void setSensors(Iterable<Sensor<Double>> sensors) { public void setSensors(Iterable<Sensor<Double>> sensors) {
sensorMap = new LinkedHashMap<>(); sensorMap = new LinkedHashMap<>();
@ -84,7 +96,7 @@ public class VacCollectorDevice extends Sensor<DataPoint> {
} }
public void setDelay(int delay) throws MeasurementException { public void setDelay(int delay) throws MeasurementException {
getConfig().setValue("delay", delay); this.delay = 5000;
if (isMeasuring()) { if (isMeasuring()) {
getMeasurement().stop(false); getMeasurement().stop(false);
getMeasurement().start(); getMeasurement().start();
@ -129,7 +141,7 @@ public class VacCollectorDevice extends Sensor<DataPoint> {
collector.put(sensor.getName(), Value.NULL); collector.put(sensor.getName(), Value.NULL);
} }
}); });
}, 0, meta().getInt("delay", 5000), TimeUnit.MILLISECONDS); }, 0, delay, TimeUnit.MILLISECONDS);
} }
@Override @Override

View File

@ -38,8 +38,7 @@ public class VacDeviceFactory implements DeviceFactory<VacCollectorDevice> {
List<Sensor<Double>> sensors = config.getMetaList("sensor").stream() List<Sensor<Double>> sensors = config.getMetaList("sensor").stream()
.map(sensorConfig -> buildSensor(context, sensorConfig)).collect(Collectors.toList()); .map(sensorConfig -> buildSensor(context, sensorConfig)).collect(Collectors.toList());
VacCollectorDevice collector = new VacCollectorDevice(); VacCollectorDevice collector = new VacCollectorDevice(context, config);
collector.configure(config);
collector.setSensors(sensors); collector.setSensors(sensors);
return collector; return collector;
} }

View File

@ -24,11 +24,7 @@ public class NumassDataFactory extends DataFactory<NumassData> {
@Override @Override
protected void buildChildren(Context context, DataTree.Builder<NumassData> builder, DataFilter filter, Meta meta) { protected void buildChildren(Context context, DataTree.Builder<NumassData> builder, DataFilter filter, Meta meta) {
NumassStorage storage = NumassStorage.buildNumassRoot( NumassStorage storage = new NumassStorage(context,meta);
meta.getString("path"),
meta.getBoolean("readOnly", true),
meta.getBoolean("monitor", false)
);
StorageUtils.loaderStream(storage).forEach(pair -> { StorageUtils.loaderStream(storage).forEach(pair -> {
if (pair.getValue() instanceof NumassData) { if (pair.getValue() instanceof NumassData) {
builder.putStatic(pair.getKey(), (NumassData) pair.getValue()); builder.putStatic(pair.getKey(), (NumassData) pair.getValue());

View File

@ -15,14 +15,13 @@
*/ */
package inr.numass.storage; package inr.numass.storage;
import hep.dataforge.context.Context;
import hep.dataforge.events.BasicEvent; import hep.dataforge.events.BasicEvent;
import hep.dataforge.events.EventBuilder; import hep.dataforge.events.EventBuilder;
import hep.dataforge.exceptions.StorageException; import hep.dataforge.exceptions.StorageException;
import hep.dataforge.meta.Meta; import hep.dataforge.meta.Meta;
import hep.dataforge.meta.MetaBuilder;
import hep.dataforge.storage.filestorage.FilePointLoader; import hep.dataforge.storage.filestorage.FilePointLoader;
import hep.dataforge.storage.filestorage.FileStorage; import hep.dataforge.storage.filestorage.FileStorage;
import hep.dataforge.storage.filestorage.VFSUtils;
import inr.numass.data.NMFile; import inr.numass.data.NMFile;
import inr.numass.data.NumassData; import inr.numass.data.NumassData;
import org.apache.commons.io.FilenameUtils; import org.apache.commons.io.FilenameUtils;
@ -35,7 +34,6 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.net.URI;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -56,87 +54,17 @@ public class NumassStorage extends FileStorage {
public static final String NUMASS_ZIP_EXTENSION = ".nm.zip"; public static final String NUMASS_ZIP_EXTENSION = ".nm.zip";
public static final String NUMASS_DATA_LOADER_TYPE = "numassData"; public static final String NUMASS_DATA_LOADER_TYPE = "numassData";
public static final String GROUP_META_FILE = "numass_group_meta";
protected NumassStorage(FileStorage parent, String path, Meta config) throws StorageException { protected NumassStorage(FileStorage parent, String path, Meta config) throws StorageException {
super(parent, path, config); super(parent, path, config);
super.refresh(); super.refresh();
//TODO read meta from numass_group_meta to .numass element
} }
protected NumassStorage(FileObject dir, Meta config) throws StorageException { public NumassStorage(Context context, Meta config) throws StorageException {
super(dir, config); super(context, config);
super.refresh(); super.refresh();
} }
/**
* Create root numass storage
*
* @param dir
* @param readOnly
* @return
* @throws StorageException
*/
public static NumassStorage buildLocalNumassRoot(File dir, boolean readOnly, boolean monitor) throws StorageException {
try {
Meta meta = new MetaBuilder("storage")
.setValue("type", "file.numass")
.setValue("readOnly", readOnly)
.setValue("monitor", monitor);
return new NumassStorage(VFSUtils.getLocalFile(dir), meta);
} catch (FileSystemException ex) {
throw new RuntimeException(ex);
}
}
public static NumassStorage buildLocalNumassRoot(File dir, boolean readOnly) throws StorageException {
return buildLocalNumassRoot(dir, readOnly, false);
}
public static NumassStorage buildRemoteNumassRoot(String ip, int port, String login, String password, String path) throws StorageException {
try {
Meta meta = new MetaBuilder("storage")
.setValue("type", "file.numass")
.setValue("readOnly", true)
.setValue("monitor", false);
return new NumassStorage(VFSUtils.getRemoteFile(ip, port, login, password, path), meta);
} catch (FileSystemException ex) {
throw new RuntimeException(ex);
}
}
public static NumassStorage buildNumassStorage(FileStorage parent, String path, boolean readOnly, boolean monitor) throws StorageException {
Meta meta = new MetaBuilder("storage")
.setValue("type", "file.numass")
.setValue("readOnly", readOnly)
.setValue("monitor", monitor);
return new NumassStorage(parent, path, meta);
}
public static NumassStorage buildNumassRoot(String uri, boolean readOnly, boolean monitor) {
try {
Meta meta = new MetaBuilder("storage")
.setValue("type", "file.numass")
.setValue("readOnly", readOnly)
.setValue("monitor", monitor);
return new NumassStorage(VFSUtils.getFile(uri), meta);
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
public static NumassStorage buildNumassRoot(URI uri, boolean readOnly, boolean monitor) {
try {
Meta meta = new MetaBuilder("storage")
.setValue("type", "file.numass")
.setValue("readOnly", readOnly)
.setValue("monitor", monitor);
return new NumassStorage(VFSUtils.getFile(uri), meta);
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
@Override @Override
protected void updateDirectoryLoaders() { protected void updateDirectoryLoaders() {
try { try {

View File

@ -0,0 +1,90 @@
package inr.numass.storage;
import hep.dataforge.context.Context;
import hep.dataforge.meta.Meta;
import hep.dataforge.storage.api.Storage;
import hep.dataforge.storage.api.StorageType;
/**
* Created by darksnake on 17-May-17.
*/
public class NumassStorageFactory implements StorageType {
// /**
// * Create root numass storage
// *
// * @param dir
// * @param readOnly
// * @return
// * @throws StorageException
// */
// public static NumassStorage buildLocalNumassRoot(File dir, boolean readOnly, boolean monitor) throws StorageException {
// try {
// Meta meta = new MetaBuilder("storage")
// .setValue("type", "file.numass")
// .setValue("readOnly", readOnly)
// .setValue("monitor", monitor);
// return new NumassStorage(VFSUtils.getLocalFile(dir), meta);
// } catch (FileSystemException ex) {
// throw new RuntimeException(ex);
// }
// }
//
// public static NumassStorage buildLocalNumassRoot(File dir, boolean readOnly) throws StorageException {
// return buildLocalNumassRoot(dir, readOnly, false);
// }
//
// public static NumassStorage buildRemoteNumassRoot(String ip, int port, String login, String password, String path) throws StorageException {
// try {
// Meta meta = new MetaBuilder("storage")
// .setValue("type", "file.numass")
// .setValue("readOnly", true)
// .setValue("monitor", false);
// return new NumassStorage(VFSUtils.getRemoteFile(ip, port, login, password, path), meta);
// } catch (FileSystemException ex) {
// throw new RuntimeException(ex);
// }
// }
//
// public static NumassStorage buildNumassStorage(FileStorage parent, String path, boolean readOnly, boolean monitor) throws StorageException {
// Meta meta = new MetaBuilder("storage")
// .setValue("type", "file.numass")
// .setValue("readOnly", readOnly)
// .setValue("monitor", monitor);
// return new NumassStorage(parent, path, meta);
// }
//
// public static NumassStorage buildNumassRoot(String uri, boolean readOnly, boolean monitor) {
// try {
// Meta meta = new MetaBuilder("storage")
// .setValue("type", "file.numass")
// .setValue("readOnly", readOnly)
// .setValue("monitor", monitor);
// return new NumassStorage(VFSUtils.getFile(uri), meta);
// } catch (Exception ex) {
// throw new RuntimeException(ex);
// }
// }
//
// public static NumassStorage buildNumassRoot(URI uri, boolean readOnly, boolean monitor) {
// try {
// Meta meta = new MetaBuilder("storage")
// .setValue("type", "file.numass")
// .setValue("readOnly", readOnly)
// .setValue("monitor", monitor);
// return new NumassStorage(VFSUtils.getFile(uri), meta);
// } catch (Exception ex) {
// throw new RuntimeException(ex);
// }
// }
@Override
public String type() {
return "numass";
}
@Override
public Storage build(Context context, Meta meta) {
return new NumassStorage(context, meta);
}
}

View File

@ -1,22 +0,0 @@
package inr.numass.actions;
import hep.dataforge.actions.OneToOneAction;
import hep.dataforge.context.Context;
import hep.dataforge.description.TypedActionDef;
import hep.dataforge.meta.Laminate;
import inr.numass.storage.NumassStorage;
import java.net.URI;
/**
* TODO generalize and move to dataforge-stoage
* Create a Storage from given URI object
* Created by darksnake on 29-Jan-17.
*/
@TypedActionDef(name = "buildStorage", inputType = URI.class, outputType = NumassStorage.class)
public class BuildStorageAction extends OneToOneAction<URI, NumassStorage> {
@Override
protected NumassStorage execute(Context context, String name, URI input, Laminate inputMeta) {
return NumassStorage.buildNumassRoot(input, inputMeta.getBoolean("readOnly", true), inputMeta.getBoolean("monitor", false));
}
}

View File

@ -24,6 +24,7 @@ import hep.dataforge.meta.Meta;
import hep.dataforge.meta.Metoid; import hep.dataforge.meta.Metoid;
import hep.dataforge.storage.api.ObjectLoader; import hep.dataforge.storage.api.ObjectLoader;
import hep.dataforge.storage.api.StateLoader; import hep.dataforge.storage.api.StateLoader;
import hep.dataforge.storage.api.Storage;
import hep.dataforge.storage.commons.LoaderFactory; import hep.dataforge.storage.commons.LoaderFactory;
import hep.dataforge.storage.commons.MessageFactory; import hep.dataforge.storage.commons.MessageFactory;
import hep.dataforge.values.Value; import hep.dataforge.values.Value;
@ -52,7 +53,7 @@ public class NumassRun implements Metoid, Responder {
/** /**
* The Numass storage for this run (it could be not root) * The Numass storage for this run (it could be not root)
*/ */
private final NumassStorage storage; private final Storage storage;
/** /**
* Default state loader for this run * Default state loader for this run
@ -68,7 +69,7 @@ public class NumassRun implements Metoid, Responder {
// * A set with inverted order of elements (last note first) // * A set with inverted order of elements (last note first)
// */ // */
// private final Set<NumassNote> notes = new TreeSet<>((NumassNote o1, NumassNote o2) -> -o1.time().compareTo(o2.time())); // private final Set<NumassNote> notes = new TreeSet<>((NumassNote o1, NumassNote o2) -> -o1.time().compareTo(o2.time()));
public NumassRun(String path, NumassStorage workStorage, MessageFactory factory) throws StorageException { public NumassRun(String path, Storage workStorage, MessageFactory factory) throws StorageException {
this.storage = workStorage; this.storage = workStorage;
this.states = LoaderFactory.buildStateLoder(storage, RUN_STATE, null); this.states = LoaderFactory.buildStateLoder(storage, RUN_STATE, null);
this.noteLoader = LoaderFactory.buildObjectLoder(storage, RUN_NOTES, null); this.noteLoader = LoaderFactory.buildObjectLoder(storage, RUN_NOTES, null);
@ -167,7 +168,11 @@ public class NumassRun implements Metoid, Responder {
String filePath = message.meta().getString("path", ""); String filePath = message.meta().getString("path", "");
String fileName = message.meta().getString("name") String fileName = message.meta().getString("name")
.replace(NumassStorage.NUMASS_ZIP_EXTENSION, "");// removing .nm.zip if it is present .replace(NumassStorage.NUMASS_ZIP_EXTENSION, "");// removing .nm.zip if it is present
storage.pushNumassData(filePath, fileName, Binary.readToBuffer(message.getData())); if(storage instanceof NumassStorage) {
((NumassStorage) storage).pushNumassData(filePath, fileName, Binary.readToBuffer(message.getData()));
} else {
throw new StorageException("Storage does not support numass point push");
}
//TODO add checksum here //TODO add checksum here
return factory.okResponseBase("numass.data.push.response", false, false).build(); return factory.okResponseBase("numass.data.push.response", false, false).build();
} catch (StorageException | IOException ex) { } catch (StorageException | IOException ex) {
@ -181,7 +186,7 @@ public class NumassRun implements Metoid, Responder {
return storage.meta(); return storage.meta();
} }
public NumassStorage getStorage() { public Storage getStorage() {
return storage; return storage;
} }

View File

@ -15,15 +15,17 @@
*/ */
package inr.numass.server; package inr.numass.server;
import hep.dataforge.context.Context;
import hep.dataforge.context.Encapsulated;
import hep.dataforge.exceptions.StorageException; import hep.dataforge.exceptions.StorageException;
import hep.dataforge.io.envelopes.Envelope; import hep.dataforge.io.envelopes.Envelope;
import hep.dataforge.meta.Meta; import hep.dataforge.meta.Meta;
import hep.dataforge.meta.MetaBuilder; import hep.dataforge.meta.MetaBuilder;
import hep.dataforge.storage.api.StateLoader; import hep.dataforge.storage.api.StateLoader;
import hep.dataforge.storage.api.Storage;
import hep.dataforge.storage.commons.AbstractNetworkListener; import hep.dataforge.storage.commons.AbstractNetworkListener;
import hep.dataforge.storage.commons.LoaderFactory; import hep.dataforge.storage.commons.LoaderFactory;
import hep.dataforge.storage.commons.StorageManager; import hep.dataforge.storage.commons.StorageManager;
import hep.dataforge.storage.filestorage.FileStorage;
import inr.numass.storage.NumassStorage; import inr.numass.storage.NumassStorage;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -35,17 +37,17 @@ import java.io.IOException;
* *
* @author darksnake * @author darksnake
*/ */
public class NumassServer extends AbstractNetworkListener { public class NumassServer extends AbstractNetworkListener implements Encapsulated {
public static final String DEFAULT_RUN_PATH = "default"; public static final String DEFAULT_RUN_PATH = "default";
private final Logger logger = LoggerFactory.getLogger("NUMASS-STORAGE"); private final Logger logger = LoggerFactory.getLogger("NUMASS-STORAGE");
private RatpackServer ratpack; private RatpackServer ratpack;
private FileStorage root; private NumassStorage root;
private StateLoader rootState; private StateLoader rootState;
private NumassRun run; private NumassRun run;
public NumassServer(FileStorage storage, Meta listenerConfig) { public NumassServer(NumassStorage storage, Meta listenerConfig) {
super(listenerConfig); super(listenerConfig);
init(storage); init(storage);
} }
@ -61,7 +63,7 @@ public class NumassServer extends AbstractNetworkListener {
* *
* @param storage * @param storage
*/ */
private void init(FileStorage storage) { private void init(NumassStorage storage) {
new StorageManager().startGlobal(); new StorageManager().startGlobal();
this.root = storage; this.root = storage;
try { try {
@ -90,10 +92,15 @@ public class NumassServer extends AbstractNetworkListener {
// ); // );
} }
private void startRun(Meta annotation) throws StorageException { @Override
String path = annotation.getString("path", DEFAULT_RUN_PATH); public Context getContext() {
//Meta meta = annotation.getMeta("meta", null); return root.getContext();
run = new NumassRun(path, NumassStorage.buildNumassStorage(root, path, false, true), getResponseFactory()); }
private void startRun(Meta meta) throws StorageException {
String path = meta.getString("path", DEFAULT_RUN_PATH);
NumassStorage storage = root.buildShelf(path,meta);
run = new NumassRun(path, storage, getResponseFactory());
getRootState().setValue("numass.current.run", path); getRootState().setValue("numass.current.run", path);
} }
@ -137,7 +144,8 @@ public class NumassServer extends AbstractNetworkListener {
*/ */
private void updateRun() throws StorageException { private void updateRun() throws StorageException {
String currentRun = getRootState().getString("numass.current.run", DEFAULT_RUN_PATH); String currentRun = getRootState().getString("numass.current.run", DEFAULT_RUN_PATH);
this.run = new NumassRun(currentRun, NumassStorage.buildNumassStorage(root, currentRun, false, true), getResponseFactory()); Storage storage = root.optShelf(currentRun).get();
this.run = new NumassRun(currentRun, storage, getResponseFactory());
} }
/** /**

View File

@ -1,10 +1,11 @@
package inr.numass.server; package inr.numass.server;
import hep.dataforge.context.Context;
import hep.dataforge.context.Global;
import hep.dataforge.io.MetaFileReader; import hep.dataforge.io.MetaFileReader;
import hep.dataforge.meta.Meta; import hep.dataforge.meta.Meta;
import hep.dataforge.meta.SimpleConfigurable; import hep.dataforge.meta.SimpleConfigurable;
import inr.numass.storage.NumassStorage; import inr.numass.storage.NumassStorage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.io.File; import java.io.File;
@ -18,17 +19,17 @@ public class ServerRunner extends SimpleConfigurable implements AutoCloseable {
public static final String SERVER_CONFIG_PATH = "numass-server.xml"; public static final String SERVER_CONFIG_PATH = "numass-server.xml";
private static final String NUMASS_REPO_ELEMENT = "numass.repository"; private static final String NUMASS_REPO_ELEMENT = "numass.repository";
private static final String LISTENER_ELEMENT = "listener"; private static final String LISTENER_ELEMENT = "listener";
private static final String NUMASS_REPO_PATH_PROPERTY = "numass.repository.path"; // private static final String NUMASS_REPO_PATH_PROPERTY = "numass.repository.path";
private final static Logger logger = LoggerFactory.getLogger("NUMASS-SERVER");
NumassStorage root; NumassStorage root;
NumassServer listener; NumassServer listener;
Context context = Global.getContext("NUMASS_SERVER");
public ServerRunner() throws IOException, ParseException { public ServerRunner() throws IOException, ParseException {
// Global.instance().pluginManager().load(StorageManager.class); // Global.instance().pluginManager().load(StorageManager.class);
File configFile = new File(SERVER_CONFIG_PATH); File configFile = new File(SERVER_CONFIG_PATH);
if (configFile.exists()) { if (configFile.exists()) {
logger.info("Trying to read server configuration from {}", SERVER_CONFIG_PATH); context.getLogger().info("Trying to read server configuration from {}", SERVER_CONFIG_PATH);
configure(MetaFileReader.read(configFile)); configure(MetaFileReader.read(configFile));
} }
} }
@ -38,7 +39,7 @@ public class ServerRunner extends SimpleConfigurable implements AutoCloseable {
r.start(); r.start();
Runtime.getRuntime().addShutdownHook(new Thread(() -> { Runtime.getRuntime().addShutdownHook(new Thread(() -> {
logger.info("Shutting down"); LoggerFactory.getLogger("NUMASS-SERVER").info("Shutting down");
r.close(); r.close();
})); }));
@ -51,15 +52,13 @@ public class ServerRunner extends SimpleConfigurable implements AutoCloseable {
} }
public ServerRunner start() throws Exception { public ServerRunner start() throws Exception {
String repoPath = meta().getString(NUMASS_REPO_PATH_PROPERTY, "."); // String repoPath = meta().getString(NUMASS_REPO_PATH_PROPERTY, ".");
// Meta repoConfig = null;
// if (meta().hasMeta(NUMASS_REPO_ELEMENT)) {
// repoConfig = meta().getMeta(NUMASS_REPO_ELEMENT);
// }
logger.info("Initializing file storage in {}", repoPath);
root = NumassStorage.buildLocalNumassRoot(new File(repoPath), true, true);//in(new File(repoPath), repoConfig);
logger.info("Starting numass server"); Meta storageMeta = meta().getMetaOrEmpty(NUMASS_REPO_ELEMENT);
context.getLogger().info("Initializing file storage with meta: {}",storageMeta);
root = new NumassStorage(context,storageMeta);
context.getLogger().info("Starting numass server");
if (root != null) { if (root != null) {
root.open(); root.open();
Meta listenerConfig = null; Meta listenerConfig = null;
@ -69,9 +68,9 @@ public class ServerRunner extends SimpleConfigurable implements AutoCloseable {
listener = new NumassServer(root, listenerConfig); listener = new NumassServer(root, listenerConfig);
listener.open(); listener.open();
logger.info("Successfully started numass server"); context.getLogger().info("Successfully started numass server");
} else { } else {
logger.error("Root storage not initialized"); context.getLogger().error("Root storage not initialized");
} }
return this; return this;
@ -79,12 +78,12 @@ public class ServerRunner extends SimpleConfigurable implements AutoCloseable {
@Override @Override
public void close() { public void close() {
logger.info("Stopping numass server"); context.getLogger().info("Stopping numass server");
if (listener != null) { if (listener != null) {
try { try {
listener.close(); listener.close();
} catch (Exception e) { } catch (Exception e) {
logger.error("Failed to close listener", e); context.getLogger().error("Failed to close listener", e);
} }
} }
@ -92,7 +91,7 @@ public class ServerRunner extends SimpleConfigurable implements AutoCloseable {
try { try {
root.close(); root.close();
} catch (Exception ex) { } catch (Exception ex) {
logger.error("Error while closing storage", ex); context.getLogger().error("Error while closing storage", ex);
} }
} }
} }

View File

@ -9,10 +9,10 @@ import hep.dataforge.context.Context;
import hep.dataforge.context.Global; import hep.dataforge.context.Global;
import hep.dataforge.server.ServerManager; import hep.dataforge.server.ServerManager;
import hep.dataforge.storage.commons.StorageManager; import hep.dataforge.storage.commons.StorageManager;
import hep.dataforge.storage.filestorage.FileStorageFactory;
import inr.numass.storage.NumassStorage; import inr.numass.storage.NumassStorage;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.File;
import java.io.InputStreamReader; import java.io.InputStreamReader;
/** /**
@ -34,7 +34,7 @@ public class TestServer {
String path = "D:/temp/test"; String path = "D:/temp/test";
context.getLogger().info("Starting test numass storage servlet in '{}'", path); context.getLogger().info("Starting test numass storage servlet in '{}'", path);
NumassStorage storage = NumassStorage.buildLocalNumassRoot(new File(path), true, true); NumassStorage storage = new NumassStorage(context, FileStorageFactory.buildStorageMeta(path, true, true));
serverManager.addObject("numass", storage, NumassStorageHandler::new); serverManager.addObject("numass", storage, NumassStorageHandler::new);
serverManager.startSetver(); serverManager.startSetver();

View File

@ -27,8 +27,10 @@ dependencies {
compile 'org.controlsfx:controlsfx:8.40.12' compile 'org.controlsfx:controlsfx:8.40.12'
compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:'1.1.2-2" compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:'1.1.2-3"
compile "no.tornado:tornadofx:1.7.4" compile "no.tornado:tornadofx:1.7.4"
} }
apply plugin: 'kotlin'

View File

@ -12,6 +12,7 @@ import hep.dataforge.meta.Metoid
import hep.dataforge.names.AlphanumComparator import hep.dataforge.names.AlphanumComparator
import hep.dataforge.names.Named import hep.dataforge.names.Named
import hep.dataforge.storage.api.Storage import hep.dataforge.storage.api.Storage
import hep.dataforge.storage.filestorage.FileStorageFactory
import inr.numass.NumassProperties import inr.numass.NumassProperties
import inr.numass.data.NumassData import inr.numass.data.NumassData
import inr.numass.storage.NumassStorage import inr.numass.storage.NumassStorage
@ -134,7 +135,7 @@ class MainView : View() {
work.progress = -1.0 work.progress = -1.0
work.status = "Building numass storage tree..." work.status = "Building numass storage tree..."
try { try {
val root = NumassStorage.buildNumassRoot(path, true, false) val root = NumassStorage(context,FileStorageFactory.buildStorageMeta(path,true, true));
setRootStorage(root) setRootStorage(root)
Platform.runLater { storagePathLabel.text = "Storage: " + path } Platform.runLater { storagePathLabel.text = "Storage: " + path }
} catch (ex: Exception) { } catch (ex: Exception) {