Skip to content

Commit

Permalink
[HQ-1860] - Licensing requirement: need link in HQ enterprise install…
Browse files Browse the repository at this point in the history
…er pointing to MySQL enterprise

Did some refactoring and added some classes to support adding additional text around setting options
  • Loading branch information
dcrutchf committed Sep 16, 2009
1 parent abadb24 commit 2525b18
Show file tree
Hide file tree
Showing 5 changed files with 197 additions and 43 deletions.
42 changes: 26 additions & 16 deletions installer/src/org/hyperic/hq/install/ServerConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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";
Expand Down Expand Up @@ -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();

Expand All @@ -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",
Expand All @@ -209,6 +216,7 @@ protected ConfigSchema getInstallSchema (ConfigResponse previous,
(new HiddenConfigOption("server.overwrite",
YesNoConfigOption.NO));
}

break;

case 3:
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;

Expand Down
49 changes: 49 additions & 0 deletions src/org/hyperic/util/config/ConfigOptionDisplay.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
2 changes: 1 addition & 1 deletion src/org/hyperic/util/config/EnumerationConfigOption.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
69 changes: 69 additions & 0 deletions src/org/hyperic/util/config/InstallConfigOption.java
Original file line number Diff line number Diff line change
@@ -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();
}
}
78 changes: 52 additions & 26 deletions src/org/hyperic/util/config/InteractiveResponseBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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())) {
Expand Down Expand Up @@ -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<enumValues.size(); i++ ) {
enumValue = enumValues.get(i).toString();
inputStr += "\n\t" + String.valueOf(i+1) + ": " + enumValue;
if ( enumValue.equals(defaultValue) ) defaultIndex = i;

for ( int x = 0; x < displayValues.size(); x++ ) {
String name = ((ConfigOptionDisplay) displayValues.get(x)).getName();
String description = ((ConfigOptionDisplay) displayValues.get(x)).getDescription();
String note = ((ConfigOptionDisplay) displayValues.get(x)).getNote();

result.append("\n\t").append(x + 1).append(": ").append(name);

if ( name.equals(defaultValue) ) {
defaultIndex = x;
}

// ...display the description (the formatting is determined when the value is set)
// and should be a concern here...
if ( description != null && description.length() > 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();
}
}

0 comments on commit 2525b18

Please sign in to comment.