dev@javaserverfaces.java.net

Re: Code Review Request.... (None Bug)

From: Doug Donahue <Douglas.Donahue_at_Sun.COM>
Date: Mon, 22 Oct 2007 17:51:43 -0400

After talking with Ryan L. on this issue, he and I agreed that there are
some limitations with the asadmin command and the way it handles exit
codes. I will rework the GlassfishUpdater code in a way that will not
rely on these limitations. Once this done I will send another "cb" out.


     Dougd

Doug Donahue wrote:
> Summary of what I would like to get accomplished by this commit:
>
> The GlassfishUpdater code needs to be "hands off installation" for
> automated testing.(except the License Agreement) So to solve this I
> needed to add the ability to pass in a Properties file. I also needed
> to add the ability to use a none default administration port for
> glassfish.(the default is 4848).
>
> Below is the Change Bundle that I would like reviewed.
>
> *******************************************************************
> * SECTION: Modified Files
> *******************************************************************
> M jsf-tools/src/com/sun/faces/tools/GlassfishUpdater.java
>
>
>
> *******************************************************************
> * SECTION: Diffs
> *******************************************************************
> Index: jsf-tools/src/com/sun/faces/tools/GlassfishUpdater.java
> ===================================================================
> RCS file:
> /cvs/javaserverfaces-sources/jsf-tools/src/com/sun/faces/tools/GlassfishUpdater.java,v
> retrieving revision 1.11
> diff -u -r1.11 GlassfishUpdater.java
> --- jsf-tools/src/com/sun/faces/tools/GlassfishUpdater.java 17 Oct
> 2007 15:18:16 -0000 1.11
> +++ jsf-tools/src/com/sun/faces/tools/GlassfishUpdater.java 19 Oct
> 2007 23:39:58 -0000
> @@ -60,6 +60,7 @@
> "Do you accept the above license terms?";
> private static final String SERVER_MUST_BE_RUNNING_STATEMENT =
> "Ensure the domain is running before continuing.";
> + private static final String ASADMIN_PORT="What is the admin port
> number?";
> private static final String ASADMIN_USERNAME_QUESTION =
> "What is the asadmin administrative user name?";
> private static final String ASADMIN_USER_PASSWORD_QUESTION =
> @@ -106,22 +107,31 @@
> protected GlassfishUpdater() { }
>
> protected static File libDir = null;
> - protected static Properties props;
>
> public static void main(String args[]) throws Exception {
> // For statefile operations.
> if (args.length != 0) {
> if ("-statefile".equals(args[0])) {
> if (args.length == 2) {
> - setStateProps(args[1]);
> - String adminUser = getProp("admin.user");
> - String passwd = getProp("passwd.file");
> - File appHome = new File(getProp("appserver.home"));
> -
> + String passwd = null;
> + Properties steFile = getPropsFile(args[1]);
> + String adminUser = getProp(steFile, "admin.user");
> + String adminPort = getProp(steFile, "admin.port");
> + File appHome = new File(getProp(steFile,
> "appserver.home"));
> +
> + // Get and validate the admin password file.
> + if (steFile.containsKey("passwd.file")){
> + passwd = getProp(steFile,"passwd.file");
> + Properties pFile = getPropsFile(passwd);
> + String adminPasswd = getProp(pFile,
> + "AS_ADMIN_PASSWORD");
> + }
> +
> displayLicense();
> if (askYesOrNoQuestion(AGREE_TO_LICENCE_QUESTION,
> "yes")) {
> unpackJars(appHome);
> - updateClassPathPrefix(appHome, adminUser,
> passwd);
> + updateClassPathPrefix(appHome, adminUser,
> passwd,
> + adminPort);
> System.out.println("Upgrade complete." +
> NEW_LINE +
> "Restart the server for the changes
> to take " +
> "effect.");
> @@ -129,14 +139,18 @@
> } else {
> System.out.println("Provide a properties file
> with the " +
> "following props!" + NEW_LINE +
> "admin.user" +
> - NEW_LINE + "passwd.file" + NEW_LINE +
> - "appserver.home" + NEW_LINE + "Exiting...");
> + NEW_LINE + "passwd.file(OPTIONAL)" +
> NEW_LINE +
> + "admin.port" + NEW_LINE + "appserver.home" +
> + NEW_LINE + "Exiting...");
> System.exit(1);
> }
> } else {
> - System.out.println("Illegal Argument!" + NEW_LINE +
> "Exiting...");
> + System.out.println("Illegal Argument!" + NEW_LINE +
> + "Exiting...");
> System.exit(1);
> }
> + System.out.println("Upgrade complete. Restart the server
> for " +
> + "the changes to take effect.");
> } else {
> // Default no command line args operation.
> displayLicense();
> @@ -146,30 +160,32 @@
> String path = askQuestion(PATH_TO_APPSERVER_QUESTION,
> null);
> installDir = validateServerDirectory(path);
> if (installDir == null) {
> - System.out.println('\'' + path + "' is invalid.
> Please try again.\n");
> + System.out.println('\'' + path + "' is invalid. " +
> + "Please try again." + NEW_LINE);
> }
> }
>
>
> displayContinuationStatement(SERVER_MUST_BE_RUNNING_STATEMENT);
> String user = askQuestion(ASADMIN_USERNAME_QUESTION,
> "admin");
> String pass = askQuestion(ASADMIN_USER_PASSWORD_QUESTION,
> null);
> + String adminPort = askQuestion(ASADMIN_PORT, "4848");
> unpackJars(installDir);
> - updateClassPathPrefix(installDir, user, pass);
> + updateClassPathPrefix(installDir, user, pass, adminPort);
> System.out.println("Upgrade complete. Restart the server
> for the changes to take effect.");
> }
> }
> }
>
> -
> +
> public static void updateClassPathPrefix(File installDir,
> String user,
> - String pathToPasswordFile)
> + String pathToPasswordFile,
> + String adminPort)
> throws Exception {
> File binDir = new File(installDir, "bin");
> Runtime rt = Runtime.getRuntime();
> - Process p = rt.exec(buildCommand(binDir, user,
> pathToPasswordFile, "get", null),
> - null,
> - binDir);
> + Process p = rt.exec(buildCommand(binDir, user, adminPort,
> + pathToPasswordFile, "get", null), null, binDir);
> failUpdateIfNecessary(p);
> BufferedReader reader = new BufferedReader(new
> InputStreamReader(p.getInputStream()));
> String result = reader.readLine();
> @@ -193,9 +209,8 @@
> System.out.println("Updating classpath-prefix....");
> path = parts[1].trim() + '/' + INSTALL_ROOT + "/lib/" +
> JARS.API.getName();
> }
> - p = rt.exec(buildCommand(binDir, user, pathToPasswordFile,
> "set", path),
> - null,
> - binDir);
> + p = rt.exec(buildCommand(binDir, user, adminPort,
> + pathToPasswordFile, "set", path), null, binDir);
> failUpdateIfNecessary(p);
>
> }
> @@ -240,6 +255,7 @@
>
> public static String buildCommand(File binDir,
> String user,
> + String adminPort,
> String pathToPasswordFile,
> String baseCommand,
> String updateInfo) throws
> IOException {
> @@ -260,6 +276,8 @@
> sb.append(pathToPasswordFile.trim());
> sb.append('"');
> }
> + sb.append(" --port ");
> + sb.append(adminPort.trim());
> sb.append(" server.java-config.classpath-prefix");
> if (updateInfo != null) {
> sb.append('=');
> @@ -352,13 +370,12 @@
> }
>
> /*
> - * Set and validate the Properties file.
> + * Read in a given Properties file.
> */
> - public static void setStateProps(String path) {
> + public static Properties getPropsFile(String path) {
>
> - props = new Properties();
> + Properties props = new Properties();
>
> - // Read in the properties file.
> try {
> props.load(new FileInputStream(path));
> } catch (IOException e) {
> @@ -370,25 +387,22 @@
> "Exiting...");
> System.exit(1);
> }
> +
> + return props;
> }
>
> /*
> * Get and validate a given property.
> */
> - public static String getProp(String prop) {
> - String value = props.getProperty(prop);
> + public static String getProp(Properties propFile, String prop) {
> + String value = propFile.getProperty(prop);
>
> - if (value == null) {
> - System.out.println(prop + " Not found in the following
> props " +
> - "list: " + props + NEW_LINE + "This prop must be
> set!" +
> + if (value == null || value.length() == 0) {
> + System.out.println(prop + " NOT FOUND! or NOT SET!" +
> + NEW_LINE + "This property must be set!" +
> NEW_LINE + "Exiting...");
> System.exit(1);
> }
> - if (value.length() == 0) {
> - System.out.println(prop + " NOT SET!" + NEW_LINE +
> - "This prop must be set!" + NEW_LINE + "Exiting...");
> - System.exit(1);
> - }
>
> return value;
> }
>
>