blob: 570cf1fa06912c5b56a06269f44a153ffcf67fdc (
plain) (
tree)
|
|
package org.openslx.bwlp.sat;
import java.security.NoSuchAlgorithmException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Logger;
import org.apache.thrift.transport.TTransportException;
import org.openslx.bwlp.sat.database.Database;
import org.openslx.bwlp.sat.database.mappers.DbImage;
import org.openslx.bwlp.sat.fileserv.FileServer;
import org.openslx.bwlp.sat.thrift.BinaryListener;
import org.openslx.bwlp.sat.thrift.cache.OperatingSystemList;
import org.openslx.bwlp.sat.thrift.cache.OrganizationList;
import org.openslx.bwlp.sat.util.Configuration;
import org.openslx.bwlp.sat.util.Json;
import org.openslx.bwlp.thrift.iface.ImageSummaryRead;
import org.openslx.bwlp.thrift.iface.NetDirection;
import org.openslx.bwlp.thrift.iface.NetRule;
import org.openslx.bwlp.thrift.iface.UserInfo;
import org.openslx.thrifthelper.ThriftManager;
import org.openslx.util.QuickTimer;
import org.openslx.util.QuickTimer.Task;
public class App {
private static Logger LOGGER = Logger.getLogger(App.class);
private static List<Thread> servers = new ArrayList<>();
public static boolean DEBUG = false;
public static void main(String[] args) throws TTransportException, NoSuchAlgorithmException {
//get going and show basic information in log file
BasicConfigurator.configure();
if (args.length != 0 && args[0].equals("debug")) {
DEBUG = true;
}
LOGGER.info("****************************************************************");
LOGGER.info("******************* Starting Application ***********************");
LOGGER.info("****************************************************************");
// get Configuration
try {
LOGGER.info("Loading configuration");
Configuration.load();
} catch (Exception e1) {
LOGGER.fatal("Could not load configuration", e1);
System.exit(1);
}
ThriftManager.setMasterServerAddress("bwlp-masterserver.ruf.uni-freiburg.de");
// Load useful things from master server
//LOGGER.info(ThriftManager.getMasterClient().getUserFromToken("9ECAC1AFC02FF295292362BD165847AE"));
OrganizationList.get();
OperatingSystemList.get();
// Start file transfer server
if (!FileServer.instance().start()) {
LOGGER.error("Could not start internal file server.");
return;
}
// Start Server
Thread t;
t = new Thread(new BinaryListener(9090, false));
servers.add(t);
t.start();
// DEBUG
if (DEBUG) {
Database.printCharsetInformation();
List<ImageSummaryRead> allVisible;
try {
allVisible = DbImage.getAllVisible(new UserInfo("bla", "blu", null, null, null), null, 0);
LOGGER.info("Got " + allVisible.size());
} catch (SQLException e) {
LOGGER.warn("could not test query getallvisible");
}
QuickTimer.scheduleAtFixedDelay(new Task() {
@Override
public void fire() {
Database.printDebug();
}
}, 100, 5000);
NetRule nr = new NetRule(2, NetDirection.OUT, "dsafg", 1336);
String data = Json.serialize(nr);
LOGGER.info(data);
Json.registerThriftClass(NetRule.class);
NetRule nn = Json.deserializeThrift(data, NetRule.class);
LOGGER.info(nn);
}
// Wait for servers
for (Thread wait : servers) {
boolean success = false;
while (!success) {
try {
wait.join();
success = true;
} catch (InterruptedException e) {
// Do nothing...
}
}
}
QuickTimer.cancel();
LOGGER.info(new Date() + " - all Servers shut down, exiting...\n");
}
}
|