summaryrefslogtreecommitdiffstats
path: root/dozentenmodulserver/src/main/java/server
diff options
context:
space:
mode:
authorSimon Rettberg2015-06-11 18:40:49 +0200
committerSimon Rettberg2015-06-11 18:40:49 +0200
commite0005ceecfd9281230c4add7575b18ee88307774 (patch)
treea73bbcfc213df478c701aac120ae2b7c6e52bb1b /dozentenmodulserver/src/main/java/server
parent[server] db stuff, new interface, ... (diff)
downloadtutor-module-e0005ceecfd9281230c4add7575b18ee88307774.tar.gz
tutor-module-e0005ceecfd9281230c4add7575b18ee88307774.tar.xz
tutor-module-e0005ceecfd9281230c4add7575b18ee88307774.zip
[server] On mah way (lots of restructuring, some early db classes, sql dump of current schema)
Diffstat (limited to 'dozentenmodulserver/src/main/java/server')
-rw-r--r--dozentenmodulserver/src/main/java/server/BinaryListener.java49
-rw-r--r--dozentenmodulserver/src/main/java/server/ServerHandler.java215
-rw-r--r--dozentenmodulserver/src/main/java/server/SessionManager.java101
-rw-r--r--dozentenmodulserver/src/main/java/server/StartServer.java62
-rw-r--r--dozentenmodulserver/src/main/java/server/TBinaryProtocolSafe.java123
5 files changed, 0 insertions, 550 deletions
diff --git a/dozentenmodulserver/src/main/java/server/BinaryListener.java b/dozentenmodulserver/src/main/java/server/BinaryListener.java
deleted file mode 100644
index 92954322..00000000
--- a/dozentenmodulserver/src/main/java/server/BinaryListener.java
+++ /dev/null
@@ -1,49 +0,0 @@
-package server;
-
-import java.util.Date;
-
-import org.apache.log4j.Logger;
-import org.apache.thrift.protocol.TProtocolFactory;
-import org.apache.thrift.server.TServer;
-import org.apache.thrift.server.TThreadPoolServer;
-import org.apache.thrift.server.TThreadPoolServer.Args;
-import org.apache.thrift.transport.TServerSocket;
-import org.apache.thrift.transport.TServerTransport;
-import org.apache.thrift.transport.TTransportException;
-import org.openslx.bwlp.thrift.iface.SatelliteServer;
-
-public class BinaryListener implements Runnable {
- private static Logger log = Logger.getLogger(BinaryListener.class);
-
- private final int MINWORKERTHREADS = 20; // keine ahnung ob das passt...
- private final int MAXWORKERTHREADS = 80; // ebenso
-
- @Override
- public void run() {
- final ServerHandler handler = new ServerHandler();
- final SatelliteServer.Processor<ServerHandler> processor = new SatelliteServer.Processor<ServerHandler>(
- handler);
- final TServerTransport transport;
- final TProtocolFactory protFactory = new TBinaryProtocolSafe.Factory(
- true, true);
- try {
- transport = new TServerSocket(9090);
- log.info(new Date() + " - Listening on Port 9090");
-
- } catch (TTransportException e) {
- log.fatal(new Date() + " - Could not listen on port 9090");
- return;
- }
- TServer server = new TThreadPoolServer(new Args(transport)
- .protocolFactory(protFactory).processor(processor)
- .minWorkerThreads(MINWORKERTHREADS)
- .maxWorkerThreads(MAXWORKERTHREADS));
-
- log.info(new Date() + " - Started running BinaryListener");
- log.info(new Date() + " - MINWORKERTHREADS=" + MINWORKERTHREADS
- + " and MAXWORKERTHREADS=" + MAXWORKERTHREADS + "\n");
- server.serve();
-
- }
-
-}
diff --git a/dozentenmodulserver/src/main/java/server/ServerHandler.java b/dozentenmodulserver/src/main/java/server/ServerHandler.java
deleted file mode 100644
index dddec9be..00000000
--- a/dozentenmodulserver/src/main/java/server/ServerHandler.java
+++ /dev/null
@@ -1,215 +0,0 @@
-package server;
-
-import java.nio.ByteBuffer;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.log4j.Logger;
-import org.apache.thrift.TException;
-import org.openslx.bwlp.thrift.iface.ImageBaseWrite;
-import org.openslx.bwlp.thrift.iface.ImageDetailsRead;
-import org.openslx.bwlp.thrift.iface.ImagePermissions;
-import org.openslx.bwlp.thrift.iface.ImageSummaryRead;
-import org.openslx.bwlp.thrift.iface.ImageVersionWrite;
-import org.openslx.bwlp.thrift.iface.LecturePermissions;
-import org.openslx.bwlp.thrift.iface.LectureRead;
-import org.openslx.bwlp.thrift.iface.LectureSummary;
-import org.openslx.bwlp.thrift.iface.LectureWrite;
-import org.openslx.bwlp.thrift.iface.OperatingSystem;
-import org.openslx.bwlp.thrift.iface.Organization;
-import org.openslx.bwlp.thrift.iface.SatelliteServer;
-import org.openslx.bwlp.thrift.iface.TAuthorizationException;
-import org.openslx.bwlp.thrift.iface.TInvalidTokenException;
-import org.openslx.bwlp.thrift.iface.TNotFoundException;
-import org.openslx.bwlp.thrift.iface.TTransferRejectedException;
-import org.openslx.bwlp.thrift.iface.TransferInformation;
-import org.openslx.bwlp.thrift.iface.UploadStatus;
-import org.openslx.bwlp.thrift.iface.UserInfo;
-import org.openslx.bwlp.thrift.iface.Virtualizer;
-import org.openslx.sat.thrift.version.Version;
-
-import sql.models.DbImage;
-import thrift.OperatingSystemList;
-import fileserv.ActiveUpload;
-import fileserv.FileServer;
-
-public class ServerHandler implements SatelliteServer.Iface {
-
- private static final Logger log = Logger.getLogger(ServerHandler.class);
-
- private static final FileServer fileServer = FileServer.instance();
-
- @Override
- public long getVersion() throws TException {
- return Version.VERSION;
- }
-
- @Override
- public TransferInformation requestImageVersionUpload(String userToken, String imageBaseId, long fileSize,
- List<ByteBuffer> blockHashes) throws TTransferRejectedException, TAuthorizationException,
- TException {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public void cancelUpload(String uploadToken) throws TException {
- ActiveUpload upload = fileServer.getUploadByToken(uploadToken);
- if (upload != null)
- upload.cancel();
-
- }
-
- @Override
- public UploadStatus queryUploadStatus(String uploadToken) throws TInvalidTokenException, TException {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public TransferInformation requestDownload(String userToken, String imageVersionId)
- throws TAuthorizationException, TException {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public void cancelDownload(String downloadToken) throws TException {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public boolean isAuthenticated(String userToken) throws TException {
- return SessionManager.get(userToken) != null;
- }
-
- @Override
- public void invalidateSession(String userToken) throws TException {
- SessionManager.remove(userToken);
- }
-
- @Override
- public List<OperatingSystem> getOperatingSystems() throws TException {
- return OperatingSystemList.get();
- }
-
- @Override
- public List<Virtualizer> getVirtualizers() throws TException {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public List<Organization> getAllOrganizations() throws TException {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public List<ImageSummaryRead> getImageList(String userToken, List<String> tagSearch)
- throws TAuthorizationException, TException {
- UserInfo user = SessionManager.getOrFail(userToken);
- return DbImage.getAllVisible(user, tagSearch);
- }
-
- @Override
- public ImageDetailsRead getImageDetails(String userToken, String imageBaseId)
- throws TAuthorizationException, TNotFoundException, TException {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public boolean updateImageBase(String userToken, String imageBaseId, ImageBaseWrite image)
- throws TAuthorizationException, TException {
- // TODO Auto-generated method stub
- return false;
- }
-
- @Override
- public boolean updateImageVersion(String userToken, String imageVersionId, ImageVersionWrite image)
- throws TAuthorizationException, TException {
- // TODO Auto-generated method stub
- return false;
- }
-
- @Override
- public boolean deleteImageVersion(String userToken, String imageVersionId)
- throws TAuthorizationException, TNotFoundException, TException {
- // TODO Auto-generated method stub
- return false;
- }
-
- @Override
- public boolean writeImagePermissions(String userToken, String imageId,
- Map<String, ImagePermissions> permissions) throws TAuthorizationException, TNotFoundException,
- TException {
- // TODO Auto-generated method stub
- return false;
- }
-
- @Override
- public Map<String, ImagePermissions> getImagePermissions(String userToken, String imageBaseId)
- throws TAuthorizationException, TNotFoundException, TException {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public String createLecture(String userToken, LectureWrite lecture) throws TAuthorizationException,
- TException {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public boolean updateLecture(String userToken, String lectureId, LectureWrite lecture)
- throws TAuthorizationException, TNotFoundException, TException {
- // TODO Auto-generated method stub
- return false;
- }
-
- @Override
- public List<LectureSummary> getLectureList(String userToken) throws TAuthorizationException, TException {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public LectureRead getLectureDetails(String userToken, String lectureId) throws TAuthorizationException,
- TNotFoundException, TException {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public List<LectureSummary> getLecturesByImageVersion(String userToken, String imageVersionId)
- throws TAuthorizationException, TNotFoundException, TException {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public boolean deleteLecture(String userToken, String lectureId) throws TAuthorizationException,
- TNotFoundException, TException {
- // TODO Auto-generated method stub
- return false;
- }
-
- @Override
- public boolean writeLecturePermissions(String userToken, String lectureId,
- Map<String, LecturePermissions> permissions) throws TAuthorizationException, TNotFoundException,
- TException {
- // TODO Auto-generated method stub
- return false;
- }
-
- @Override
- public Map<String, LecturePermissions> getLecturePermissions(String userToken, String lectureId)
- throws TAuthorizationException, TNotFoundException, TException {
- // TODO Auto-generated method stub
- return null;
- }
-
-}// end class
diff --git a/dozentenmodulserver/src/main/java/server/SessionManager.java b/dozentenmodulserver/src/main/java/server/SessionManager.java
deleted file mode 100644
index 3f4d4257..00000000
--- a/dozentenmodulserver/src/main/java/server/SessionManager.java
+++ /dev/null
@@ -1,101 +0,0 @@
-package server;
-
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.TimeUnit;
-
-import org.apache.log4j.Logger;
-import org.openslx.bwlp.thrift.iface.AuthorizationError;
-import org.openslx.bwlp.thrift.iface.TAuthorizationException;
-import org.openslx.bwlp.thrift.iface.UserInfo;
-import org.openslx.thrifthelper.ThriftManager;
-
-/**
- * Manages user sessions. Mainly used to map tokens to users.
- *
- */
-public class SessionManager {
-
- private static final Logger LOGGER = Logger.getLogger(SessionManager.class);
-
- private static class Entry {
- private static final long SESSION_TIMEOUT = TimeUnit.DAYS.toMillis(1);
- private final UserInfo user;
- private long validUntil;
-
- private Entry(UserInfo user) {
- this.user = user;
- this.validUntil = System.currentTimeMillis() + SESSION_TIMEOUT;
- }
-
- public void touch(long now) {
- this.validUntil = now + SESSION_TIMEOUT;
- }
- }
-
- // saves the current tokens and the mapped userdata, returning from the server
- private static Map<String, Entry> tokenManager = new ConcurrentHashMap<>();
-
- /**
- * Get the user corresponding to the given token.
- *
- * @param token user's token
- * @return UserInfo for the matching user
- * @throws TAuthorizationException if the token is not known or the session
- * expired
- */
- public static UserInfo getOrFail(String token) throws TAuthorizationException {
- UserInfo ui = get(token);
- if (ui != null)
- return ui;
- throw new TAuthorizationException(AuthorizationError.NOT_AUTHENTICATED,
- "Your session token is not known to the server");
- }
-
- /**
- * Get the user corresponding to the given token. Returns null if the token
- * is not known, or the session already timed out.
- *
- * @param token user's token
- * @return UserInfo for the matching user
- */
- public static UserInfo get(String token) {
- Entry e = tokenManager.get(token);
- if (e != null) {
- // User session already cached
- final long now = System.currentTimeMillis();
- if (e.validUntil < now) {
- tokenManager.remove(token);
- return getRemote(token);
- }
- e.touch(now);
- return e.user;
- }
- return getRemote(token);
- }
-
- /**
- * Remove session matching the given token
- *
- * @param token
- */
- public static void remove(String token) {
- tokenManager.remove(token);
- }
-
- private static UserInfo getRemote(String token) {
- UserInfo ui = null;
- try {
- ui = ThriftManager.getMasterClient().getUserFromToken(token);
- } catch (Exception e) {
- LOGGER.warn("Could not reach master server to query for user token of a client!", e);
- }
- if (ui == null)
- return null;
- tokenManager.put(token, new Entry(ui));
- return ui;
- }
-
- // TODO: Clean map of old entries periodically
-
-}
diff --git a/dozentenmodulserver/src/main/java/server/StartServer.java b/dozentenmodulserver/src/main/java/server/StartServer.java
deleted file mode 100644
index a5631622..00000000
--- a/dozentenmodulserver/src/main/java/server/StartServer.java
+++ /dev/null
@@ -1,62 +0,0 @@
-package server;
-
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-
-import models.Configuration;
-
-import org.apache.log4j.BasicConfigurator;
-import org.apache.log4j.Logger;
-
-import fileserv.FileServer;
-
-public class StartServer {
-
- private static Logger log = Logger.getLogger(StartServer.class);
-
- private static List<Thread> servers = new ArrayList<>();
-
- public static void main(String[] args) {
-
- //get going and show basic information in logfile
- BasicConfigurator.configure();
- log.info("****************************************************************");
- log.info("******************* starting Application ***********************");
- log.info("****************************************************************");
-
- // get Configuration
- try {
- log.info("Loading configuration");
- Configuration.load();
- } catch (Exception e1) {
- log.fatal("Could not load configuration", e1);
- System.exit(1);
- }
-
- // Start file transfer server
- if (!FileServer.instance().start()) {
- log.error("Could not start internal file server.");
- return;
- }
- // Start Server
- Thread t;
- t = new Thread(new BinaryListener());
- servers.add(t);
- t.start();
- // Wait for servers
- for (Thread wait : servers) {
- boolean success = false;
- while (!success) {
- try {
- wait.join();
- success = true;
- } catch (InterruptedException e) {
- // Do nothing...
- }
- }
- }
- log.info(new Date() + " - all Servers shut down, exiting...\n");
- }
-
-}
diff --git a/dozentenmodulserver/src/main/java/server/TBinaryProtocolSafe.java b/dozentenmodulserver/src/main/java/server/TBinaryProtocolSafe.java
deleted file mode 100644
index 843b58b1..00000000
--- a/dozentenmodulserver/src/main/java/server/TBinaryProtocolSafe.java
+++ /dev/null
@@ -1,123 +0,0 @@
-package server;
-
-import java.io.UnsupportedEncodingException;
-import java.nio.ByteBuffer;
-
-import org.apache.thrift.TException;
-import org.apache.thrift.protocol.TBinaryProtocol;
-import org.apache.thrift.protocol.TMessage;
-import org.apache.thrift.protocol.TProtocol;
-import org.apache.thrift.protocol.TProtocolException;
-import org.apache.thrift.protocol.TProtocolFactory;
-import org.apache.thrift.transport.TTransport;
-
-/**
- * Binary protocol implementation for thrift.
- * Will not read messages bigger than 12MiB.
- *
- */
-public class TBinaryProtocolSafe extends TBinaryProtocol
-{
- /**
- * Factory
- */
- @SuppressWarnings( "serial" )
- public static class Factory implements TProtocolFactory
- {
-
- protected boolean strictRead_ = false;
- protected boolean strictWrite_ = true;
-
- public Factory()
- {
- this( false, true );
- }
-
- public Factory(boolean strictRead, boolean strictWrite)
- {
- strictRead_ = strictRead;
- strictWrite_ = strictWrite;
- }
-
- public TProtocol getProtocol( TTransport trans )
- {
- return new TBinaryProtocolSafe( trans, strictRead_, strictWrite_ );
- }
- }
-
- private static final int maxLen = 12 * 1024 * 1024; // 12 MiB
-
- /**
- * Constructor
- */
- public TBinaryProtocolSafe(TTransport trans)
- {
- this( trans, false, true );
- }
-
- public TBinaryProtocolSafe(TTransport trans, boolean strictRead, boolean strictWrite)
- {
- super( trans );
- strictRead_ = strictRead;
- strictWrite_ = strictWrite;
- }
-
- /**
- * Reading methods.
- */
-
- public TMessage readMessageBegin() throws TException
- {
- int size = readI32();
- if ( size > maxLen )
- throw new TProtocolException( TProtocolException.SIZE_LIMIT, "Payload too big." );
- if ( size < 0 ) {
- int version = size & VERSION_MASK;
- if ( version != VERSION_1 ) {
- throw new TProtocolException( TProtocolException.BAD_VERSION, "Bad version in readMessageBegin" );
- }
- return new TMessage( readString(), (byte) ( size & 0x000000ff ), readI32() );
- } else {
- if ( strictRead_ ) {
- throw new TProtocolException( TProtocolException.BAD_VERSION, "Missing version in readMessageBegin, old client?" );
- }
- return new TMessage( readStringBody( size ), readByte(), readI32() );
- }
- }
-
- public String readString() throws TException
- {
- int size = readI32();
- if ( size > maxLen )
- throw new TProtocolException( TProtocolException.SIZE_LIMIT, "Payload too big." );
- if ( trans_.getBytesRemainingInBuffer() >= size ) {
- try {
- String s = new String( trans_.getBuffer(), trans_.getBufferPosition(), size, "UTF-8" );
- trans_.consumeBuffer( size );
- return s;
- } catch ( UnsupportedEncodingException e ) {
- throw new TException( "JVM DOES NOT SUPPORT UTF-8" );
- }
- }
-
- return readStringBody( size );
- }
-
- public ByteBuffer readBinary() throws TException
- {
- int size = readI32();
- if ( size > maxLen )
- throw new TProtocolException( TProtocolException.SIZE_LIMIT, "Payload too big." );
- if ( trans_.getBytesRemainingInBuffer() >= size ) {
- ByteBuffer bb = ByteBuffer.wrap( trans_.getBuffer(), trans_.getBufferPosition(), size );
- trans_.consumeBuffer( size );
- return bb;
- }
-
- byte[] buf = new byte[ size ];
- trans_.readAll( buf, 0, size );
- return ByteBuffer.wrap( buf );
- }
-
-}
-