Skip to content

Commit

Permalink
Merge pull request #168 from xspanger3770/docker_or_something_idk
Browse files Browse the repository at this point in the history
Dockerize GQ Server
  • Loading branch information
xspanger3770 authored Nov 10, 2023
2 parents 3eb54fd + af6b0c9 commit 90c7220
Show file tree
Hide file tree
Showing 6 changed files with 159 additions and 25 deletions.
62 changes: 62 additions & 0 deletions Container/globalQuake.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#Fun fact: I've never felt an earthquake in my life
#Fri Nov 10 14:33:39 CET 2023
displayTime=true
oldEventsOpacity=100.0
stationIntensityVisibilityZoomLevel=0.2
focusOnEvent=true
alertLocal=true
fpsIdle=30
displayHomeLocation=true
hypocenterDetectionResolution=212.0
stationsTriangles=false
alertGlobal=true
displayMagnitudeHistogram=true
alertRegion=true
alertGlobalMag=6.0
selectedDateFormatIndex=0
intensityScaleIndex=0
reduceRevisions=true
alertRegionMag=3.5
selectedEventColorIndex=0
alertLocalDist=200.0
use24HFormat=true
displayClusters=false
cinemaModeOnStartup=true
distanceUnitsIndex=0
displayAdditionalQuakeInfo=false
jumpToAlert=true
hypocenterCorrectThreshold=50.0
displayCoreWaves=false
displayAlertBox=true
shakingLevelIndex=0
strongShakingLevelScale=0
shakingLevelScale=0
strongShakingLevelIndex=5
recalibrateOnLaunch=true
oldEventsTimeFilterEnabled=false
lastServerIP=0.0.0.0
parallelHypocenterLocations=true
confidencePolygons=false
displaySystemInfo=true
displayArchivedQuakes=true
homeLon=0.0
logsStoreTimeMinutes=5
maxEvents=300
oldEventsMagnitudeFilter=4.0
pWaveInaccuracyThreshold=2200.0
hideDeadStations=false
cinemaModeSwitchTime=10
homeLat=0.0
stationsSizeMul=1.0
lastServerPORT=38000
enableSound=true
oldEventsMagnitudeFilterEnabled=false
antialiasing=false
oldEventsTimeFilter=24.0
cinemaModeReenable=true
minimumStationsForEEW=6
maxArchivedQuakes=100
cinemaModeZoomMultiplier=100
alertRegionDist=1000.0
useOldColorScheme=false
reportsEnabled=false
Binary file added Container/stationDatabase/database.dat
Binary file not shown.
37 changes: 37 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
FROM ubuntu:22.04
LABEL authors="xspanger3770"

# Update the package list and install essential dependencies
RUN apt-get update && \
apt-get install -y \
openjdk-17-jdk \
maven \
build-essential \
curl \
&& rm -rf /var/lib/apt/lists/*

# Install NVIDIA CUDA Toolkit
RUN DEBIAN_FRONTEND=noninteractive apt-get update && \
apt-get install -y \
nvidia-cuda-toolkit \
&& rm -rf /var/lib/apt/lists/*

# Set environment variables for CUDA
ENV LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH
ENV PATH=/usr/local/cuda/bin:$PATH


# Set the working directory inside the container
WORKDIR /usr/src/app

# Copy the application JAR file into the container at the working directory
COPY out/artifacts/GlobalQuakeServer/GlobalQuakeServer_v0.10.0_pre5.jar .

# Copy station database and configuration files
COPY Container ./.GlobalQuakeServerData

# Copy CUDA library
COPY GQHypocenterSearch/build/lib ./lib

# Run GQ Server
CMD ["java", "-jar", "-Dtinylog.writer.level=debug", "-Djava.library.path=./lib", "GlobalQuakeServer_v0.10.0_pre5.jar", "--headless"]
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import globalquake.core.earthquake.data.Hypocenter;
import globalquake.core.earthquake.data.PickedEvent;
import globalquake.core.geo.taup.TauPTravelTimeCalculator;
import globalquake.ui.ProgressUpdateFunction;
import globalquake.utils.GeoUtils;
import org.tinylog.Logger;

Expand All @@ -15,6 +16,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.function.Function;

@SuppressWarnings("unused")
public class EarthquakeAnalysisTraining {
Expand Down Expand Up @@ -65,7 +67,7 @@ public static void main(String[] args) throws Exception {

private static final long TARGET_TIME = 400;

public static void calibrateResolution(JProgressBar progressBar, JSlider slider){
public static void calibrateResolution(ProgressUpdateFunction progressUpdateFunction, JSlider slider){
Settings.hypocenterDetectionResolution = 0.0;
long lastTime;
int seed = 6543;
Expand All @@ -78,8 +80,8 @@ public static void calibrateResolution(JProgressBar progressBar, JSlider slider)
failed = 0;
Settings.hypocenterDetectionResolution += 2.5;
}
if(progressBar !=null){
progressBar.setString("Calibrating: Resolution %.2f took %d ms".formatted(Settings.hypocenterDetectionResolution / 100.0, lastTime));
if(progressUpdateFunction !=null){
progressUpdateFunction.update("Calibrating: Resolution %.2f took %d ms".formatted(Settings.hypocenterDetectionResolution / 100.0, lastTime), 0);
}
if(slider != null){
slider.setValue(Settings.hypocenterDetectionResolution.intValue());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package globalquake.ui;

@FunctionalInterface
public interface ProgressUpdateFunction {
void update(String status, int value);
}
71 changes: 49 additions & 22 deletions GlobalQuakeServer/src/main/java/gqserver/main/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import gqserver.server.GlobalQuakeServer;
import gqserver.ui.server.DatabaseMonitorFrame;
import org.tinylog.Logger;

import java.io.File;
import java.util.concurrent.Executors;
Expand All @@ -26,20 +27,28 @@ public class Main {
public static final String fullName = "GlobalQuakeServer " + GlobalQuake.version;
private static DatabaseMonitorFrame databaseMonitorFrame;
private static StationDatabaseManager databaseManager;
private static boolean headless;

private static void startDatabaseManager() throws FatalIOException {
databaseManager = new StationDatabaseManager();
databaseManager.load();

new GlobalQuakeServer(databaseManager);

databaseMonitorFrame = new DatabaseMonitorFrame(databaseManager);
databaseMonitorFrame.setVisible(true);
if (!headless) {
databaseMonitorFrame = new DatabaseMonitorFrame(databaseManager);
databaseMonitorFrame.setVisible(true);
}
}

public static void main(String[] args) {
initErrorHandler();

if(args.length > 0 && (args[0].equals("--headless"))){
headless = true;
Logger.info("Running as headless");
}

GlobalQuake.prepare(Main.MAIN_FOLDER, Main.getErrorHandler());

try {
Expand All @@ -60,45 +69,63 @@ public static void main(String[] args) {
private static final double PHASES = 6.0;
private static int phase = 0;

private static void initAll() throws Exception {
databaseMonitorFrame.getMainProgressBar().setString("Loading regions...");
databaseMonitorFrame.getMainProgressBar().setValue((int) ((phase++ / PHASES) * 100.0));
public static void updateProgressBar(String status, int value) {
if(headless){
Logger.info("%d%%: %s".formatted(value, status));
}else{
databaseMonitorFrame.getMainProgressBar().setString(status);
databaseMonitorFrame.getMainProgressBar().setValue(value);
}
}

public static void initAll() throws Exception{
updateProgressBar("Loading regions...", (int) ((phase++ / PHASES) * 100.0));
Regions.init();
databaseMonitorFrame.getMainProgressBar().setString("Filling up intensity table...");
databaseMonitorFrame.getMainProgressBar().setValue((int) ((phase++ / PHASES) * 100.0));

updateProgressBar("Filling up intensity table...", (int) ((phase++ / PHASES) * 100.0));
IntensityTable.init();
databaseMonitorFrame.getMainProgressBar().setString("Loading travel table...");
databaseMonitorFrame.getMainProgressBar().setValue((int) ((phase++ / PHASES) * 100.0));

updateProgressBar("Loading travel table...", (int) ((phase++ / PHASES) * 100.0));
TauPTravelTimeCalculator.init();
databaseMonitorFrame.getMainProgressBar().setString("Calibrating...");
databaseMonitorFrame.getMainProgressBar().setValue((int) ((phase++ / PHASES) * 100.0));

updateProgressBar("Calibrating...", (int) ((phase++ / PHASES) * 100.0));
if(Settings.recalibrateOnLaunch) {
EarthquakeAnalysisTraining.calibrateResolution(databaseMonitorFrame.getMainProgressBar(), null);
EarthquakeAnalysisTraining.calibrateResolution(Main::updateProgressBar, null);
}
databaseMonitorFrame.getMainProgressBar().setString("Updating Station Sources...");
databaseMonitorFrame.getMainProgressBar().setValue((int) ((phase++ / PHASES) * 100.0));
databaseManager.runUpdate(databaseManager.getStationDatabase().getStationSources().stream()

updateProgressBar("Updating Station Sources...", (int) ((phase++ / PHASES) * 100.0));
databaseManager.runUpdate(
databaseManager.getStationDatabase().getStationSources().stream()
.filter(StationSource::isOutdated).collect(Collectors.toList()),
() -> {
databaseMonitorFrame.getMainProgressBar().setString("Checking Seedlink Networks...");
databaseMonitorFrame.getMainProgressBar().setValue((int) ((phase++ / PHASES) * 100.0));
updateProgressBar("Checking Seedlink Networks...", (int) ((phase++ / PHASES) * 100.0));
databaseManager.runAvailabilityCheck(databaseManager.getStationDatabase().getSeedlinkNetworks(), () -> {
databaseMonitorFrame.getMainProgressBar().setString("Saving...");
databaseMonitorFrame.getMainProgressBar().setValue((int) ((phase++ / PHASES) * 100.0));
updateProgressBar("Saving...", (int) ((phase++ / PHASES) * 100.0));

try {
databaseManager.save();
} catch (FatalIOException e) {
getErrorHandler().handleException(new RuntimeException(e));
}
databaseMonitorFrame.initDone();

databaseMonitorFrame.getMainProgressBar().setString("Done");
databaseMonitorFrame.getMainProgressBar().setValue((int) ((phase++ / PHASES) * 100.0));
if(!headless) {
databaseMonitorFrame.initDone();
}

updateProgressBar("Done", (int) ((phase++ / PHASES) * 100.0));

if(headless){
autoStartServer();
}
});
});
}

private static void autoStartServer() {
GlobalQuakeServer.instance.getServerSocket().run(Settings.lastServerIP, Settings.lastServerPORT);
GlobalQuakeServer.instance.startRuntime();
}

public static ApplicationErrorHandler getErrorHandler() {
if(errorHandler == null) {
errorHandler = new ApplicationErrorHandler(null);
Expand Down

0 comments on commit 90c7220

Please sign in to comment.