From 2525b188944d7d607b856bf290d509c3e2fac852 Mon Sep 17 00:00:00 2001 From: dcrutchf Date: Wed, 16 Sep 2009 21:37:07 +0000 Subject: [PATCH] [HQ-1860] - Licensing requirement: need link in HQ enterprise installer pointing to MySQL enterprise Did some refactoring and added some classes to support adding additional text around setting options --- .../org/hyperic/hq/install/ServerConfig.java | 42 ++++++---- .../util/config/ConfigOptionDisplay.java | 49 ++++++++++++ .../util/config/EnumerationConfigOption.java | 2 +- .../util/config/InstallConfigOption.java | 69 ++++++++++++++++ .../config/InteractiveResponseBuilder.java | 78 ++++++++++++------- 5 files changed, 197 insertions(+), 43 deletions(-) create mode 100644 src/org/hyperic/util/config/ConfigOptionDisplay.java create mode 100644 src/org/hyperic/util/config/InstallConfigOption.java diff --git a/installer/src/org/hyperic/hq/install/ServerConfig.java b/installer/src/org/hyperic/hq/install/ServerConfig.java index c4eb2cc71d..1a3ab9b12e 100644 --- a/installer/src/org/hyperic/hq/install/ServerConfig.java +++ b/installer/src/org/hyperic/hq/install/ServerConfig.java @@ -38,11 +38,13 @@ import org.hyperic.util.InetPortPinger; import org.hyperic.util.JDK; import org.hyperic.util.StringUtil; +import org.hyperic.util.config.ConfigOptionDisplay; import org.hyperic.util.config.ConfigResponse; import org.hyperic.util.config.ConfigSchema; import org.hyperic.util.config.EarlyExitException; import org.hyperic.util.config.EnumerationConfigOption; import org.hyperic.util.config.HiddenConfigOption; +import org.hyperic.util.config.InstallConfigOption; import org.hyperic.util.config.InvalidOptionValueException; import org.hyperic.util.config.IpAddressConfigOption; import org.hyperic.util.config.PortConfigOption; @@ -62,7 +64,10 @@ public class ServerConfig extends BaseConfig { public static final String DBC_ORA10 = "Oracle 10g/11g"; public static final String DBC_PGSQL = "PostgreSQL"; public static final String DBC_BUILTIN = "HQ Built-in Database"; - public static final String DBC_MYSQL = "MySQL 5.x"; + public static final String DBC_MYSQL = "MySQL Enterprise / Community Server 5.x"; + // This note has been added to met a condition of our MySQL license agreement + public static final String DBC_MYSQL_NOTE = "*\n\n\t*Sign up for a MySQL Enterprise Trial subscription at http://www.mysql.com/trials/partner1569.\n"; + // database names we need to use internally public static final String DB_ORA9 = "Oracle9i"; @@ -173,10 +178,11 @@ protected ConfigSchema getInstallSchema (ConfigResponse previous, StringConfigOption usernameOption; StringConfigOption passwordOption; String serverInstallDir; - - InstallMode installMode = - new InstallMode(getProjectProperty("install.mode")); - + InstallMode installMode = new InstallMode(getProjectProperty("install.mode")); + // ...this property allows us to change installer behavior so that it's .org or EE specific, + // currently the eula is only shown for EE, so it's a pretty good indicator right now... + boolean isEEInstall = Boolean.parseBoolean(getProjectProperty("eula.present")); + // Do we have an builtin-postgresql packaged with us? boolean haveBuiltinDB = getReleaseHasBuiltinDB(); @@ -197,6 +203,7 @@ protected ConfigSchema getInstallSchema (ConfigResponse previous, case 2: // Is there in fact an installation we should worry about? serverInstallDir = previous.getValue("server.installdir"); + if ( serverAlreadyInstalled(serverInstallDir) ) { schema.addOption (new YesNoConfigOption("server.overwrite", @@ -209,6 +216,7 @@ protected ConfigSchema getInstallSchema (ConfigResponse previous, (new HiddenConfigOption("server.overwrite", YesNoConfigOption.NO)); } + break; case 3: @@ -244,7 +252,7 @@ protected ConfigSchema getInstallSchema (ConfigResponse previous, (new PortConfigOption("server.webapp.secure.port", Q_PORT_WEBAPP_SECURE, new Integer(7443))); - + schema.addOption (new PortConfigOption("hq-engine.jnp.port", Q_PORT_JNP, @@ -315,16 +323,18 @@ protected ConfigSchema getInstallSchema (ConfigResponse previous, new HiddenConfigOption("server.database.choice", DBC_BUILTIN)); } else { - String defaultDB = haveBuiltinDB ? DBC_BUILTIN : DBC_ORA10; - String[] dbs = haveBuiltinDB - ? new String[] { DBC_BUILTIN, DBC_ORA10, - DBC_PGSQL, DBC_MYSQL } - : new String[] { DBC_ORA10, DBC_PGSQL, DBC_MYSQL }; - schema.addOption( - new EnumerationConfigOption("server.database.choice", - Q_DATABASE, - defaultDB, - dbs)); + // ...setup the different ConfigOptionDisplay values for the databases + // we support... + ConfigOptionDisplay builtInOption = new ConfigOptionDisplay(DBC_BUILTIN); + ConfigOptionDisplay oracleOption = new ConfigOptionDisplay(DBC_ORA10); + ConfigOptionDisplay postgresOption = new ConfigOptionDisplay(DBC_PGSQL); + // ...check for the install type (.org or EE) and show the MySQL note accordingly... + ConfigOptionDisplay mysqlOption = (isEEInstall) ? new ConfigOptionDisplay(DBC_MYSQL, null, DBC_MYSQL_NOTE) + : new ConfigOptionDisplay(DBC_MYSQL); + ConfigOptionDisplay defaultDB = haveBuiltinDB ? builtInOption : oracleOption; + ConfigOptionDisplay[] dbs = haveBuiltinDB ? new ConfigOptionDisplay[] { builtInOption, oracleOption, postgresOption, mysqlOption } + : new ConfigOptionDisplay[] { oracleOption, postgresOption, mysqlOption }; + schema.addOption(new InstallConfigOption("server.database.choice", Q_DATABASE, defaultDB, dbs)); } break; diff --git a/src/org/hyperic/util/config/ConfigOptionDisplay.java b/src/org/hyperic/util/config/ConfigOptionDisplay.java new file mode 100644 index 0000000000..8544cfd86a --- /dev/null +++ b/src/org/hyperic/util/config/ConfigOptionDisplay.java @@ -0,0 +1,49 @@ +package org.hyperic.util.config; + +public class ConfigOptionDisplay { + private String name; + private String description; + private String note; + + public ConfigOptionDisplay() { + this(null); + } + + public ConfigOptionDisplay(String name) { + this(name, null); + } + + public ConfigOptionDisplay(String name, String description) { + this(name, description, null); + } + + public ConfigOptionDisplay(String name, String description, String note) { + this.name = name; + this.description = description; + this.note = note; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getNote() { + return note; + } + + public void setNote(String note) { + this.note = note; + } +} diff --git a/src/org/hyperic/util/config/EnumerationConfigOption.java b/src/org/hyperic/util/config/EnumerationConfigOption.java index 4d38952651..3e43dc23a4 100644 --- a/src/org/hyperic/util/config/EnumerationConfigOption.java +++ b/src/org/hyperic/util/config/EnumerationConfigOption.java @@ -31,7 +31,7 @@ public class EnumerationConfigOption extends ConfigOption implements Serializable { - private ArrayList _values = new ArrayList(); // Values the enum holds + private List _values = new ArrayList(); // Values the enum holds /** * This constructor allows you to create an EnumConfigOption diff --git a/src/org/hyperic/util/config/InstallConfigOption.java b/src/org/hyperic/util/config/InstallConfigOption.java new file mode 100644 index 0000000000..2e0103d544 --- /dev/null +++ b/src/org/hyperic/util/config/InstallConfigOption.java @@ -0,0 +1,69 @@ +package org.hyperic.util.config; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +public class InstallConfigOption extends ConfigOption implements Serializable { + private List _values = new ArrayList(); // Values the enum holds + + /** + * This constructor allows you to create an InstallConfigOption + * and behaves pretty much like the EnumConfigOption class, however + * it deals with ConfigOptionDisplay objects rather than raw Strings. + */ + public InstallConfigOption(String optName, String optDesc, ConfigOptionDisplay defValue, ConfigOptionDisplay[] installOptionValues) + { + this(optName, optDesc, defValue, installOptionValues, null); + } + + public InstallConfigOption(String optName, String optDesc, ConfigOptionDisplay defValue, ConfigOptionDisplay[] installOptionValues, String confirm) { + super(optName, optDesc, defValue.getName()); + + for (int i = 0; i < installOptionValues.length; i++) { + if (installOptionValues[i] != null && installOptionValues[i].getName().length() > 0) { + _values.add(installOptionValues[i]); + } + } + + if (confirm != null) setConfirm(confirm); + } + + public void addValue(ConfigOptionDisplay option){ + _values.add(option); + } + + public List getValues(){ + return _values; + } + + public void checkOptionIsValid(String value) throws InvalidOptionValueException { + boolean valid = false; + + for (int x = 0; x < _values.size(); x++) { + if (((ConfigOptionDisplay) _values.get(x)).getName().equals(value)) { + valid = true; + + break; + } + } + + if (!valid) throw invalidOption("must be one of options presented below. value: " + value); + } + + public String getDefault() { + String defVal = super.getDefault(); + + //if no default was specified, use the first in the list + if ((defVal == null) && (_values.size() > 0)) { + defVal = ((ConfigOptionDisplay) _values.get(0)).getName(); + } + + return defVal; + } + + protected Object clone() throws CloneNotSupportedException { + // TODO Auto-generated method stub + return super.clone(); + } +} diff --git a/src/org/hyperic/util/config/InteractiveResponseBuilder.java b/src/org/hyperic/util/config/InteractiveResponseBuilder.java index 9f9e92e730..cc63008903 100644 --- a/src/org/hyperic/util/config/InteractiveResponseBuilder.java +++ b/src/org/hyperic/util/config/InteractiveResponseBuilder.java @@ -30,6 +30,9 @@ import java.util.List; import java.util.Set; +import org.hyperic.util.config.ConfigOptionDisplay; +import org.hyperic.util.config.InstallConfigOption; + public class InteractiveResponseBuilder implements ResponseBuilder { private InteractiveResponseBuilder_IOHandler inout; @@ -158,22 +161,24 @@ public ConfigResponse processConfigSchema(ConfigSchema schema, } val = val.trim(); - if(opt instanceof EnumerationConfigOption){ + + if(opt instanceof InstallConfigOption) { int index = -1; - List values; - + try { index = Integer.parseInt(val) - 1; } catch(NumberFormatException exc){ sendToErrStream("Value must be an integer"); continue; } - values = ((EnumerationConfigOption) opt).getValues(); + + List values = ((InstallConfigOption) opt).getValues(); + if(index < 0 || index >= values.size()){ sendToErrStream("Value not in range"); continue; } - val = values.get(index).toString(); + val = ((ConfigOptionDisplay) values.get(index)).getName(); } if (val.equals(opt.getConfirm())) { @@ -224,38 +229,59 @@ public void sendToErrStream ( String msg ) { */ private String getInputString ( ConfigOption opt, String defaultValue ) { - String inputStr, desc; - - inputStr = ""; - - if(inout.isDeveloper()) - inputStr += "("+opt.getName()+") "; + StringBuilder result = new StringBuilder(); + String desc; + if(inout.isDeveloper()) { + result.append("(").append(opt.getName()).append(") "); + } + desc = opt.getDescription(); // Treat these special, because we want to display the list // of valid options to the user. - if ( opt instanceof EnumerationConfigOption ) { - inputStr += "Choices:"; - List enumValues = ((EnumerationConfigOption) opt).getValues(); - String enumValue; + if ( opt instanceof InstallConfigOption ) { + result.append("Choices:"); + + List displayValues = ((InstallConfigOption) opt).getValues(); int defaultIndex = -1; - for ( int i=0; i 0) { + result.append(description); + } + + // ...display the note (again, the formatting is determined when the value is set)... + if ( note != null && note.length() > 0) { + result.append(note); + } } + if ( defaultIndex != -1 ) { - inputStr += "\n" + desc + " [default '" - + String.valueOf(defaultIndex+1) + "']"; + result.append("\n").append(desc).append(" [default '").append(defaultIndex + 1).append("']"); } else { - inputStr += "\n" + desc; + result.append("\n").append(desc); } } else { - inputStr += desc; - if( defaultValue != null) - inputStr += " [default '" + defaultValue + "']"; + result.append(desc); + + if( defaultValue != null) { + result.append(" [default '").append(defaultValue).append("']"); + } } - return inputStr; + + return result.toString(); } }