Skip to content
This repository has been archived by the owner on Oct 31, 2021. It is now read-only.

Commit

Permalink
Installer now supports JMX (part of #102)
Browse files Browse the repository at this point in the history
Standard robozonky.sh (robozonky.bat) no longer carries JMX properties. Instead, installer-generated run.sh will supply them through JAVA_OPTS. If users want to supply password-based authentication, it is their responsibility to supply credentials from within their system.
  • Loading branch information
triceo committed Mar 10, 2017
1 parent 818f507 commit 02ce1cb
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
if not defined ROBOZONKY_PORT set ROBOZONKY_PORT=7091
if not defined ROBOZONKY_IP set ROBOZONKY_IP=localhost
set "JMX_OPTS=-Djava.rmi.server.hostname=%ROBOZONKY_IP% -Dcom.sun.management.jmxremote.port=%ROBOZONKY_PORT% -Dcom.sun.management.jmxremote.rmi.port=%ROBOZONKY_PORT% -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false"
set "ROBOZONKY_OPTS=%JMX_OPTS% %JAVA_OPTS% -Dlogback.configurationFile=logback.xml -Dfile.encoding=UTF-8 -Djava.net.preferIPv4Stack=true"
set "ROBOZONKY_OPTS=%JAVA_OPTS% -Dlogback.configurationFile=logback.xml -Dfile.encoding=UTF-8 -Djava.net.preferIPv4Stack=true"
java %ROBOZONKY_OPTS% -jar bin/robozonky-app-${project.version}.jar %*
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
#!/bin/bash
BASEDIR=$(dirname "$0")
ROBOZONKY_PORT=${ROBOZONKY_PORT:-7091}
ROBOZONKY_IP=${ROBOZONKY_IP:-localhost}
JMX_OPTS="-Djava.rmi.server.hostname=$ROBOZONKY_IP -Dcom.sun.management.jmxremote.port=$ROBOZONKY_PORT -Dcom.sun.management.jmxremote.rmi.port=$ROBOZONKY_PORT -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false"
ROBOZONKY_OPTS="$JMX_OPTS $JAVA_OPTS -Dlogback.configurationFile=logback.xml -Dfile.encoding=UTF-8 -Djava.net.preferIPv4Stack=true"
ROBOZONKY_OPTS="$JAVA_OPTS -Dlogback.configurationFile=logback.xml -Dfile.encoding=UTF-8 -Djava.net.preferIPv4Stack=true"
$JAVA_HOME/bin/java $ROBOZONKY_OPTS -jar ${BASEDIR}/bin/robozonky-app-${project.version}.jar "$@"
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@
<name>isEmailEnabled</name>
<value>true</value>
</condition>
<condition type="variable" id="enableJmxPanel">
<name>isJmxEnabled</name>
<value>true</value>
</condition>
<condition type="variable" id="isStrategyByFile">
<name>strategyType</name>
<value>file</value>
Expand Down Expand Up @@ -80,6 +84,7 @@
<panel classname="UserInputPanel" id="emailUserInput" condition="enableEmailPanel">
<validator classname="com.github.triceo.robozonky.installer.panels.EmailSettingsValidator" />
</panel>
<panel classname="UserInputPanel" id="jmxUserInput" condition="enableJmxPanel" />
<panel classname="UserInputPanel" id="strategyUserInput">
<validator classname="com.github.triceo.robozonky.installer.panels.StrategySettingsValidator" />
</panel>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@
<field type="check" variable="isUsingToken">
<spec txt="Neodhlašovat ze Zonky." set="false"/>
</field>
<field type="check" variable="isJmxEnabled">
<spec txt="Povolit vzdálenou správu a monitoring přes JMX." set="false"/>
</field>
<field type="check" variable="isDryRun">
<spec txt="Zapnout zkušební režim. RoboZonky nebude smět investovat." set="false"/>
</field>
Expand Down Expand Up @@ -105,17 +108,13 @@
</field>
<field type="text" variable="smtpHostname">
<spec txt="Adresa SMTP serveru:" id="smtp.hostname" size="20" set=""/>
<validator class="com.izforge.izpack.panels.userinput.validator.NotEmptyValidator"
<validator class="com.izforge.izpack.panels.userinput.validator.HostAddressValidator"
txt="Adresa serveru je povinná položka." />
</field>
<field type="text" variable="smtpPort">
<spec txt="Port na SMTP serveru:" id="smtp.port" size="20" set=""/>
<validator class="com.izforge.izpack.panels.userinput.validator.NotEmptyValidator"
txt="Port serveru je povinná položka." />
<validator class="com.izforge.izpack.panels.userinput.validator.RegularExpressionValidator"
txt="Port musí být číslo.">
<param name="pattern" value="[0-9]+" />
</validator>
<validator class="com.izforge.izpack.panels.userinput.validator.IsPortValidator"
txt="Port musí být číslo." />
</field>
<field type="check" variable="smtpIsTls">
<spec txt="Vyžaduje TLS." set="false"/>
Expand Down Expand Up @@ -147,6 +146,30 @@
<field type="staticText" align="left" bold="true" txt="Pokračováním bude odeslán zkušební e-mail."
id="email.test"/>
</panel>
<panel id="jmxUserInput">
<field type="title" align="left" txt="Nastavení vzdáleného přístupu k JMX" id="jmx.title"/>

<field type="staticText" align="left" bold="true" txt="Parametry připojení"
id="jmx.host.title"/>
<field type="divider" />
<field type="text" variable="jmxHostname">
<spec txt="Vnější adresa zařízení:" id="jmx.hostname" size="20" set="${IP_ADDRESS}"/>
<validator class="com.izforge.izpack.panels.userinput.validator.NotEmptyValidator"
txt="Adresa je povinná položka." />
</field>
<field type="text" variable="jmxPort">
<spec txt="Port pro JMX:" id="jmxPort" size="20" set="7091"/>
<validator class="com.izforge.izpack.panels.userinput.validator.IsPortValidator"
txt="Port musí být číslo." />
</field>
<field type="check" variable="isJmxSecurityEnabled">
<spec txt="Vyžadovat autentizaci." id="jmxSecurity" size="20" set="false"/>
</field>
<field type="space" />
<field type="space" />
<field type="staticText" align="left" bold="true" id="jmx.warning.2"
txt="Pozor: Nevhodné nastavení může způsobit, že se robot nespustí!" />
</panel>
<panel id="strategyUserInput">
<field type="title" align="left" txt="Nastavení investiční strategie" id="strategy.title"/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.TreeMap;
import java.util.stream.Collectors;
import java.util.stream.Stream;

Expand All @@ -33,8 +32,8 @@
public class CommandLinePart {

private final Map<String, Collection<String>> options = new LinkedHashMap<>();
private final Map<String, String> properties = new TreeMap<>();
private final Map<String, String> environmentVariables = new TreeMap<>();
private final Map<String, String> properties = new LinkedHashMap<>();
private final Map<String, String> environmentVariables = new LinkedHashMap<>();


public CommandLinePart setOption(final String key, final String... value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,20 @@ private SecretProvider getSecretProvider(final char[] keystorePassword) {
}
}

CommandLinePart prepareJmx() {
if (!Boolean.valueOf(Variables.IS_JMX_ENABLED.getValue(DATA))) {
return new CommandLinePart();
}
final String port = Variables.JMX_PORT.getValue(DATA);
return new CommandLinePart()
.setProperty("com.sun.management.jmxremote.authenticate",
Variables.IS_JMX_SECURITY_ENABLED.getValue(DATA))
.setProperty("com.sun.management.jmxremote.ssl", "false")
.setProperty("com.sun.management.jmxremote.rmi.port", port)
.setProperty("com.sun.management.jmxremote.port", port)
.setProperty("java.rmi.server.hostname", Variables.JMX_HOSTNAME.getValue(DATA));
}

CommandLinePart prepareCore() {
return prepareCore(KEYSTORE_PASSWORD);
}
Expand Down Expand Up @@ -154,7 +168,7 @@ CommandLinePart prepareCore(final char[] keystorePassword) {
}

CommandLinePart prepareCommandLine(final CommandLinePart strategy, final CommandLinePart emailConfig,
final CommandLinePart credentials) {
final CommandLinePart jmxConfig, final CommandLinePart credentials) {
// assemble the CLI
final CommandLinePart cli = new CommandLinePart();
credentials.getOptions().forEach((k, v) -> cli.setOption(k, v.toArray(new String[v.size()])));
Expand All @@ -167,7 +181,8 @@ CommandLinePart prepareCommandLine(final CommandLinePart strategy, final Command
final CommandLinePart result = new CommandLinePart()
.setOption("@" + CLI_CONFIG_FILE.getAbsolutePath())
.setEnvironmentVariable("JAVA_HOME", Variables.JAVA_HOME.getValue(DATA));
Stream.of(strategy.getProperties(), emailConfig.getProperties(), credentials.getProperties())
Stream.of(strategy.getProperties(), emailConfig.getProperties(), jmxConfig.getProperties(),
credentials.getProperties())
.forEach(m -> m.forEach(result::setProperty));
return result;
} catch (final IOException ex) {
Expand Down Expand Up @@ -234,18 +249,20 @@ void moveLog() {

@Override
public void afterPacks(final List<Pack> packs, final ProgressListener progressListener) {
progressListener.startAction("Konfigurace RoboZonky", 6);
progressListener.startAction("Konfigurace RoboZonky", 7);
progressListener.nextStep("Příprava strategie.", 1, 1);
final CommandLinePart strategyConfig = prepareStrategy();
progressListener.nextStep("Příprava nastavení e-mailu.", 2, 1);
final CommandLinePart emailConfig = prepareEmailConfiguration();
progressListener.nextStep("Příprava nastavení Zonky.", 3, 1);
progressListener.nextStep("Příprava nastavení JMX.", 3, 1);
final CommandLinePart jmx = prepareJmx();
progressListener.nextStep("Příprava nastavení Zonky.", 4, 1);
final CommandLinePart credentials = prepareCore();
progressListener.nextStep("Generování parametrů příkazové řádky.", 4, 1);
final CommandLinePart result = prepareCommandLine(strategyConfig, emailConfig, credentials);
progressListener.nextStep("Příprava nastavení logování.", 5, 1);
progressListener.nextStep("Generování parametrů příkazové řádky.", 5, 1);
final CommandLinePart result = prepareCommandLine(strategyConfig, emailConfig, jmx, credentials);
progressListener.nextStep("Příprava nastavení logování.", 6, 1);
moveLog();
progressListener.nextStep("Generování spustitelného souboru.", 6, 1);
progressListener.nextStep("Generování spustitelného souboru.", 7, 1);
prepareRunScript(result);
progressListener.stopAction();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ enum Variables {
INSTALL_PATH("INSTALL_PATH"),
IS_DRY_RUN("isDryRun"),
IS_EMAIL_ENABLED("isEmailEnabled"),
IS_JMX_ENABLED("isJmxEnabled"),
IS_JMX_SECURITY_ENABLED("isJmxSecurityEnabled"),
IS_USING_OAUTH_TOKEN("isUsingToken"),
IS_WINDOWS("izpack.windowsinstall"),
IS_ZONKOID_ENABLED("isZonkoidEnabled"),
Expand All @@ -38,6 +40,8 @@ enum Variables {
SMTP_PORT("smtpPort"),
SMTP_IS_TLS("smtpIsTls"),
SMTP_IS_SSL("smtpIsSsl"),
JMX_HOSTNAME("jmxHostname"),
JMX_PORT("jmxPort"),
STRATEGY_SOURCE("strategy"),
STRATEGY_TYPE("strategyType"),
ZONKOID_TOKEN("zonkoidToken"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ public void progressUnix() {
softly.assertThat(RoboZonkyInstallerListener.CLI_CONFIG_FILE).exists();
});
Mockito.verify(progress, times(1)).startAction(ArgumentMatchers.anyString(), ArgumentMatchers.anyInt());
Mockito.verify(progress, times(6))
Mockito.verify(progress, times(7))
.nextStep(ArgumentMatchers.anyString(), ArgumentMatchers.anyInt(), ArgumentMatchers.eq(1));
Mockito.verify(progress, times(1)).stopAction();
}
Expand All @@ -267,7 +267,7 @@ public void progressWindows() {
softly.assertThat(RoboZonkyInstallerListener.CLI_CONFIG_FILE).exists();
});
Mockito.verify(progress, times(1)).startAction(ArgumentMatchers.anyString(), ArgumentMatchers.anyInt());
Mockito.verify(progress, times(6))
Mockito.verify(progress, times(7))
.nextStep(ArgumentMatchers.anyString(), ArgumentMatchers.anyInt(), ArgumentMatchers.eq(1));
Mockito.verify(progress, times(1)).stopAction();
}
Expand Down

0 comments on commit 02ce1cb

Please sign in to comment.