forked from Fruchuxs/RichWPS-Monitor
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* All logging outputs now redirected to log4j to prevent massive spam * Only Level.ERROR and above events are printed to the console * CLI added * Start parameters added * `ApplicationInfo` class added with some constants like VERSION, PROJECT_SITE, etc. * `getProcess(endpoint : URL, identifier : String) : WpsProcessEntity` method added to the `MonitorControl` facade * The RESTful Interface now implements the `java.lang.AutoCloseable` interface * `Monitor#shutdown()` now also shutdowns the underlying Jetty Webserver
- Loading branch information
Showing
65 changed files
with
2,456 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,19 @@ | |
*/ | ||
package de.hsos.ecs.richwps.wpsmonitor; | ||
|
||
import de.hsos.ecs.richwps.wpsmonitor.boundary.cli.CommandLineInterfaceBuilder; | ||
import de.hsos.ecs.richwps.wpsmonitor.boundary.cli.command.exception.CommandException; | ||
import de.hsos.ecs.richwps.wpsmonitor.boundary.cli.command.impl.AddCommand; | ||
import de.hsos.ecs.richwps.wpsmonitor.boundary.cli.command.impl.CreateCommand; | ||
import de.hsos.ecs.richwps.wpsmonitor.boundary.cli.command.impl.DeleteCommand; | ||
import de.hsos.ecs.richwps.wpsmonitor.boundary.cli.command.impl.MonitorExitCommand; | ||
import de.hsos.ecs.richwps.wpsmonitor.boundary.cli.command.impl.PauseCommand; | ||
import de.hsos.ecs.richwps.wpsmonitor.boundary.cli.command.impl.ResumeCommand; | ||
import de.hsos.ecs.richwps.wpsmonitor.boundary.cli.command.impl.ShowCommand; | ||
import de.hsos.ecs.richwps.wpsmonitor.boundary.cli.command.impl.StatusCommand; | ||
import de.hsos.ecs.richwps.wpsmonitor.boundary.cli.command.impl.TestCommand; | ||
import de.hsos.ecs.richwps.wpsmonitor.boundary.cli.console.MonitorConsole; | ||
import de.hsos.ecs.richwps.wpsmonitor.boundary.cli.console.MonitorConsoleBuilder; | ||
import de.hsos.ecs.richwps.wpsmonitor.boundary.gui.GuiStarter; | ||
import de.hsos.ecs.richwps.wpsmonitor.boundary.gui.datasource.DataSourceCreator; | ||
import de.hsos.ecs.richwps.wpsmonitor.boundary.gui.datasource.semanticproxy.SemanticProxyData; | ||
|
@@ -51,28 +64,26 @@ | |
* @author Florian Vogelpohl <[email protected]> | ||
*/ | ||
public class Application { | ||
|
||
private static final Logger LOG = LogManager.getLogger(); | ||
private static final String LOG_DIRECTORY = Log4j2Utils.getFileNameIfExists(); | ||
private static final Logger LOG; | ||
private final ApplicationStartOptions opt; | ||
|
||
public static void main(String[] args) { | ||
Locale.setDefault(Locale.GERMANY); | ||
|
||
try { | ||
new Application().run(); | ||
new Application(new ApplicationStartOptions(args)).run(); | ||
} catch (Throwable ex) { | ||
LOG.fatal("Execution Error. Execution of WPS-Monitor aborted.", ex); | ||
|
||
// exit the application | ||
LOG.fatal("Fatal execution Error.", ex); | ||
Runtime.getRuntime().exit(1); | ||
} | ||
} | ||
|
||
public Application() { | ||
public Application(final ApplicationStartOptions opt) { | ||
this.opt = opt; | ||
Log4j2Utils.setLogLevel(this.opt.getLogLevel()); | ||
} | ||
|
||
public void run() { | ||
try { | ||
|
||
Monitor monitor = setupMonitor(); | ||
|
||
LOG.trace("WpsMonitor is starting up ..."); | ||
|
@@ -82,21 +93,70 @@ public void run() { | |
RestInterface rest = setupRest(monitor.getMonitorControl()); | ||
rest.start(); | ||
|
||
LOG.trace("Setup DataDriver Set ..."); | ||
Set<DataSourceCreator> drivers = new HashSet<>(); | ||
drivers.add(new SemanticProxyData()); | ||
|
||
LOG.trace("Start GUI ..."); | ||
GuiStarter.start(monitor, LOG_DIRECTORY, drivers); | ||
|
||
LOG.info("WpsMonitor is started."); | ||
monitor.addShutdownRoutine(rest); | ||
|
||
switch (opt.getUi()) { | ||
case CLI: | ||
startCli(monitor); | ||
break; | ||
case GUI: | ||
startGui(monitor); | ||
break; | ||
case NONE: | ||
default: | ||
LOG.trace("Start Monitor in server mode..."); | ||
break; | ||
} | ||
} catch (MonitorException ex) { | ||
throw new AssertionError("Can't start the monitor!", ex); | ||
} catch (BuilderException ex) { | ||
throw new AssertionError("Can't build the monitor!", ex); | ||
} | ||
} | ||
|
||
public void startGui(final Monitor monitor) { | ||
LOG.trace("Setup DataDriver Set ..."); | ||
Set<DataSourceCreator> drivers = new HashSet<>(); | ||
drivers.add(new SemanticProxyData()); | ||
|
||
LOG.trace("Start GUI ..."); | ||
GuiStarter.start(monitor, ApplicationInfo.LOG_DIRECTORY, drivers); | ||
} | ||
|
||
/** | ||
* Starts the CLI with silence mode. The silence mode is a dirty hack | ||
* to prevent bad libraries to print content to the std out if the cli is | ||
* active. | ||
* | ||
* @param monitor Monitor instance | ||
*/ | ||
public void startCli(final Monitor monitor) { | ||
try { | ||
LOG.trace("Start CLI ..."); | ||
|
||
final MonitorConsole console = new MonitorConsoleBuilder() | ||
.withStdInAndOut() | ||
.silenceMode(true) | ||
.build(); | ||
|
||
new CommandLineInterfaceBuilder(console) | ||
.addCommand(new AddCommand(monitor)) | ||
.addCommand(new MonitorExitCommand(monitor)) | ||
.addCommand(new CreateCommand(monitor)) | ||
.addCommand(new ShowCommand(monitor)) | ||
.addCommand(new StatusCommand(monitor)) | ||
.addCommand(new DeleteCommand(monitor)) | ||
.addCommand(new ResumeCommand(monitor)) | ||
.addCommand(new PauseCommand(monitor)) | ||
.addCommand(new TestCommand(monitor)) | ||
.withDefaultCommands() | ||
.build() | ||
.run(); | ||
} catch (CommandException ex) { | ||
LOG.fatal("Can't build CLI.", ex); | ||
} | ||
} | ||
|
||
/** | ||
* Setup the Monitor-instance | ||
* | ||
|
@@ -122,7 +182,7 @@ public Monitor setupMonitor() throws BuilderException { | |
* @return RestInterface Instance | ||
* @throws de.hsos.ecs.richwps.wpsmonitor.util.BuilderException | ||
*/ | ||
public RestInterface setupRest(MonitorControl monitor) throws BuilderException { | ||
public RestInterface setupRest(final MonitorControl monitor) throws BuilderException { | ||
|
||
// create RESTful service | ||
RestInterface restInterface = new RestInterfaceBuilder() | ||
|
@@ -148,4 +208,12 @@ public MonitorRoute create() throws CreateException { | |
|
||
return restInterface; | ||
} | ||
|
||
static { | ||
// forces all JUL logging prints to log4j | ||
System.setProperty("java.util.logging.manager", org.apache.logging.log4j.jul.LogManager.class.getName()); | ||
Locale.setDefault(Locale.GERMANY); | ||
|
||
LOG = LogManager.getLogger(); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
monitor/src/main/java/de/hsos/ecs/richwps/wpsmonitor/ApplicationInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright 2015 Florian Vogelpohl <[email protected]>. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package de.hsos.ecs.richwps.wpsmonitor; | ||
|
||
import de.hsos.ecs.richwps.wpsmonitor.util.Log4j2Utils; | ||
|
||
/** | ||
* | ||
* @author Florian Vogelpohl <[email protected]> | ||
*/ | ||
public class ApplicationInfo { | ||
public static final String VERSION = "2.1"; | ||
public static final String PROJECT_SITE = "https://github.com/richwps/monitor"; | ||
public static final String AUTHOR = "Florian Vogelpohl <[email protected]>"; | ||
|
||
public static final String LOG_DIRECTORY; | ||
|
||
static { | ||
LOG_DIRECTORY = Log4j2Utils.getFileNameIfExists(); | ||
} | ||
|
||
private ApplicationInfo() { | ||
|
||
} | ||
} |
80 changes: 80 additions & 0 deletions
80
monitor/src/main/java/de/hsos/ecs/richwps/wpsmonitor/ApplicationStartOptions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
* Copyright 2015 Florian Vogelpohl <[email protected]>. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package de.hsos.ecs.richwps.wpsmonitor; | ||
|
||
import org.apache.commons.cli.CommandLine; | ||
import org.apache.commons.cli.GnuParser; | ||
import org.apache.commons.cli.Options; | ||
import org.apache.commons.cli.ParseException; | ||
import org.apache.logging.log4j.Level; | ||
|
||
/** | ||
* | ||
* @author Florian Vogelpohl <[email protected]> | ||
*/ | ||
public class ApplicationStartOptions { | ||
private final CommandLine cmd; | ||
private final static Options opt; | ||
|
||
public final static Level DEFAULT_LOG_LEVEL = Level.INFO; | ||
|
||
public enum UiType { | ||
GUI, CLI, NONE | ||
}; | ||
|
||
static { | ||
opt = new Options(); | ||
opt.addOption("ut", "ui-type", true, "Type of ui. Possibilities: gui, cli"); | ||
opt.addOption("ll", "log-level", true, "Log Level. Possibilities: debug, none"); | ||
} | ||
|
||
private Level logLevel; | ||
private UiType ui; | ||
|
||
public ApplicationStartOptions(final String[] args) throws ParseException { | ||
this.cmd = new GnuParser().parse(opt, args); | ||
this.ui = UiType.GUI; | ||
this.logLevel = DEFAULT_LOG_LEVEL; | ||
|
||
init(); | ||
} | ||
|
||
private void init() { | ||
if(cmd.hasOption("ui-type") && cmd.getOptionValue("ui-type").equals("cli")) { | ||
ui = UiType.CLI; | ||
} | ||
|
||
if(cmd.hasOption("log-level")) { | ||
String strLogLevel = cmd.getOptionValue("log-level"); | ||
|
||
if(strLogLevel.equals("debug")) { | ||
logLevel = Level.DEBUG; | ||
} | ||
} | ||
} | ||
|
||
public Level getLogLevel() { | ||
return logLevel; | ||
} | ||
|
||
public UiType getUi() { | ||
return ui; | ||
} | ||
|
||
public static Options getOpt() { | ||
return opt; | ||
} | ||
} |
Oops, something went wrong.