Skip to content

Commit

Permalink
Monitor v2.1
Browse files Browse the repository at this point in the history
* 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
Fruchuxs committed Feb 1, 2015
1 parent 9f98fad commit d9cc201
Show file tree
Hide file tree
Showing 65 changed files with 2,456 additions and 97 deletions.
6 changes: 3 additions & 3 deletions monitor/nbactions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<goal>org.codehaus.mojo:exec-maven-plugin:1.2.1:exec</goal>
</goals>
<properties>
<exec.args>-da -classpath %classpath de.hsos.ecs.richwps.wpsmonitor.Application</exec.args>
<exec.args>-da -classpath %classpath de.hsos.ecs.richwps.wpsmonitor.Application --ui-type gui</exec.args>
<exec.executable>java</exec.executable>
</properties>
</action>
Expand All @@ -24,7 +24,7 @@
<goal>org.codehaus.mojo:exec-maven-plugin:1.2.1:exec</goal>
</goals>
<properties>
<exec.args>-Xdebug -Xrunjdwp:transport=dt_socket,server=n,address=${jpda.address} -da -classpath %classpath de.hsos.ecs.richwps.wpsmonitor.Application</exec.args>
<exec.args>-Xdebug -Xrunjdwp:transport=dt_socket,server=n,address=${jpda.address} -da -classpath %classpath de.hsos.ecs.richwps.wpsmonitor.Application --ui-type gui</exec.args>
<exec.executable>java</exec.executable>
<jpda.listen>true</jpda.listen>
</properties>
Expand All @@ -39,7 +39,7 @@
<goal>org.codehaus.mojo:exec-maven-plugin:1.2.1:exec</goal>
</goals>
<properties>
<exec.args>-da -classpath %classpath de.hsos.ecs.richwps.wpsmonitor.Application</exec.args>
<exec.args>-da -classpath %classpath de.hsos.ecs.richwps.wpsmonitor.Application --ui-type gui</exec.args>
<exec.executable>java</exec.executable>
</properties>
</action>
Expand Down
30 changes: 20 additions & 10 deletions monitor/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>de.hsos.ecs.richwps</groupId>
<artifactId>WPSMonitor</artifactId>
<version>2.0</version>
<version>2.1</version>
<packaging>jar</packaging>
<build>
<plugins>
Expand Down Expand Up @@ -153,33 +153,28 @@
<groupId>com.sparkjava</groupId>
<artifactId>spark-core</artifactId>
<version>1.1.1</version>
</dependency>
</dependency><!--
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
<type>zip</type>
</dependency>
</dependency>-->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.0-rc1</version>
<version>2.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.0-rc1</version>
<version>2.1</version>
</dependency>
<dependency>
<groupId>com.thoughtworks.xstream</groupId>
<artifactId>xstream</artifactId>
<version>1.4.7</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.5</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
Expand Down Expand Up @@ -207,6 +202,21 @@
<artifactId>SemanticProxyClient</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>2.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-jul</artifactId>
<version>2.1</version>
</dependency>
<dependency>
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>
<version>1.2</version>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down
106 changes: 87 additions & 19 deletions monitor/src/main/java/de/hsos/ecs/richwps/wpsmonitor/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 ...");
Expand All @@ -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
*
Expand All @@ -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()
Expand All @@ -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();
}
}
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() {

}
}
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;
}
}
Loading

0 comments on commit d9cc201

Please sign in to comment.