opends/src/quicksetup/org/opends/quicksetup/Configuration.java
@@ -27,27 +27,37 @@ package org.opends.quicksetup; import org.opends.quicksetup.util.Utils; import java.io.File; import java.io.FileReader; import java.io.BufferedReader; import java.io.IOException; import java.util.Set; import java.util.HashSet; import java.util.logging.Logger; /** * Represents the contents of an OpenDS configuration file. */ public class Configuration { private String contents = null; static private final Logger LOG = Logger.getLogger(Configuration.class.getName()); private String contents = null; private Installation install = null; private File file = null; /** * Create a Configuration from a file. * @param install of which this configuration is part * @param file config.ldif file */ public Configuration(File file) { public Configuration(Installation install, File file) { if (install == null) { throw new NullPointerException("config file cannot be null"); } if (file == null) { throw new NullPointerException("config file cannot be null"); } else if ( @@ -56,6 +66,7 @@ !file.getName().startsWith("config.ldif")) { throw new IllegalArgumentException("file must be a config.ldif file"); } this.install = install; this.file = file; } @@ -110,18 +121,18 @@ private int getPort(String portAttr) throws IOException { int port = -1; int index = getContents().indexOf("cn=ldap connection handler"); String contents = getContents(); int index = contents.indexOf("cn=ldap connection handler"); if (index != -1) { String attrWithPoints = portAttr + ":"; int index1 = getContents().indexOf(attrWithPoints, index); int index1 = contents.indexOf(attrWithPoints, index); if (index1 != -1) { int index2 = getContents().indexOf(Constants.LINE_SEPARATOR, index1); contents.indexOf(Constants.LINE_SEPARATOR, index1); if (index2 != -1) { String sPort = getContents().substring(attrWithPoints.length() + contents.substring(attrWithPoints.length() + index1, index2).trim(); try { @@ -160,12 +171,59 @@ } /** * Returns a Set of relative paths containing the log paths outside the * installation. * @return a Set of relative paths containing the log paths outside the * installation. * @throws IOException if there is trouble reading the config file */ public Set<String> getOutsideLogs() throws IOException { return getOutsidePaths(getLogPaths()); } /** * Returns a Set of relative paths containing the db paths outside the * installation. * @return a Set of relative paths containing the db paths outside the * installation. * @throws IOException if there is trouble reading the config file */ public Set<String> getOutsideDbs() throws IOException { return getOutsidePaths(getDatabasePaths()); } private Set<String> getOutsidePaths(Set<String> paths) { Set<String> outsidePaths = new HashSet<String>(); for (String path : paths) { File fullDbPath; // Assume that if the path starts with a file separator // that it is an absolute path. Otherwise its a relative // path. if (path.startsWith(File.separator)) { fullDbPath = new File(path); } else { fullDbPath = new File(install.getRootDirectory(), path); } if (!Utils.isDescendant(fullDbPath, install.getRootDirectory())) { outsidePaths.add(Utils.getPath(fullDbPath)); } } return outsidePaths; } /** * Provides the contents of the config.ldif file in a String. * * @return a String representing the contents of the config.ldif file. * @throws IOException if there was a problem reading the file */ private String getContents() throws IOException { public String getContents() throws IOException { if (contents == null) { load(); } @@ -173,11 +231,24 @@ } /** * Returns the list of paths where the databases are installed as they appear * in the configuration file. * * @return the list of paths where the databases are installed as they appear * in the configuration file. * @throws IOException if there is a problem reading the config file. */ public Set<String> getDatabasePaths() throws IOException { return getConfigurationValues("ds-cfg-backend-directory"); } /** * Loads the contents of the configuration file into memory. * @throws IOException if there were problems loading the file */ public void load() throws IOException { StringBuffer buf = new StringBuffer(); StringBuilder buf = new StringBuilder(); FileReader reader = new FileReader(file); BufferedReader in = new BufferedReader(reader); String line; @@ -194,16 +265,17 @@ { Set<String> set = new HashSet<String>(); attrName += ":"; int index1 = getContents().indexOf(attrName); String contents = getContents(); int index1 = contents.indexOf(attrName); while (index1 != -1) { int index2 = getContents().indexOf(Constants.LINE_SEPARATOR, index1); int index2 = contents.indexOf(Constants.LINE_SEPARATOR, index1); String value; if (index2 > (index1 + attrName.length())) { value = getContents().substring(attrName.length() + index1, value = contents.substring(attrName.length() + index1, index2).trim(); } else if (getContents().length() > (index1 + attrName.length())) { } else if (contents.length() > (index1 + attrName.length())) { // Assume end of file value = getContents().substring( value = contents.substring( attrName.length() + index1).trim(); } else { value = null; @@ -213,7 +285,7 @@ set.add(value); } index1 = getContents().indexOf(attrName, index1 = contents.indexOf(attrName, index1 + attrName.length()); } return set; opends/src/quicksetup/org/opends/quicksetup/CurrentInstallStatus.java
@@ -27,13 +27,11 @@ package org.opends.quicksetup; import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; import java.util.ArrayList; import java.util.HashSet; import java.util.Set; import java.util.logging.Level; import java.util.logging.Logger; import org.opends.quicksetup.i18n.ResourceProvider; import org.opends.quicksetup.util.Utils; @@ -50,26 +48,15 @@ public class CurrentInstallStatus { static private final Logger LOG = Logger.getLogger(CurrentInstallStatus.class.getName()); private boolean isInstalled; private boolean canOverwriteCurrentInstall; private String installationMsg; private String configFileContents; private Set<String> directoryManagerDns; private Set<String> dbPaths; private Set<String> logPaths; private String ldapUrl; private String ldapsUrl; private static boolean lockPathInitialized; /** * The constructor of a CurrentInstallStatus object. * @@ -81,10 +68,11 @@ isInstalled = false; } else { Installation installation = Installation.getLocal(); boolean dbFileExists = false; ArrayList<String> msgs = new ArrayList<String>(); if (isServerRunning()) if (installation.getStatus().isServerRunning()) { msgs.add(getMsg("installstatus-serverrunning", new String[] { String.valueOf(getPort()) })); @@ -160,217 +148,14 @@ return installationMsg; } /** * Returns the list of directory manager dns as they appear in the * configuration file. * * @return the list of directory manager dns as they appear in the * configuration file. */ public Set<String> getDirectoryManagerDns() { if (directoryManagerDns == null) { directoryManagerDns = new HashSet<String>(); String directoryManagerDnAttr = "ds-cfg-alternate-bind-dn"; updateSetWithValues(directoryManagerDns, directoryManagerDnAttr); } return directoryManagerDns; } /** * Returns the list of paths where the databases are installed as they appear * in the configuration file. * * @return the list of paths where the databases are installed as they appear * in the configuration file. */ public Set<String> getDatabasePaths() { if (dbPaths == null) { dbPaths = new HashSet<String>(); String dbFileAttr = "ds-cfg-backend-directory"; updateSetWithValues(dbPaths, dbFileAttr); } return dbPaths; } /** * Returns the list of paths where the logs files are located as they appear * in the configuration file. * * @return the list of paths where the logs files are located as they appear * in the configuration file. */ public Set<String> getLogPaths() { if (logPaths == null) { logPaths = new HashSet<String>(); String logFileAttr = "ds-cfg-log-file"; updateSetWithValues(logPaths, logFileAttr); } return logPaths; } /** * Returns if the server is running on the given path. The location * of the 'locks' directory which is required for this method is * determined by getting the installation path from the classpath. * NOTE: this method is to be called only when the OpenDS.jar class has * already been loaded as it uses classes in that jar. * * LIMITATIONS: * If the locks directory does not exist the mechanism fails if the server is * stopped. However if the server.lock does not exist AND the server is not * running the mechanism should work most of the times (see failing case 3). * * The cases where this mechanism does not work are: * * 1. The user deletes/renames the locks directory. * 2. The user deletes/renames the server.lock file AND the server is running. * 3. The server is not running but the user that is running the code does not * have file system access rights. * 4. The server is not running and another process has a lock on the file. * @return <CODE>true</CODE> if the server is running and <CODE>false</CODE> * otherwise. */ public static boolean isServerRunning() { File locksDir = new File(Utils.getInstallPathFromClasspath(), org.opends.server.util.ServerConstants.LOCKS_DIRECTORY); return isServerRunning(locksDir); } /** * Returns if the server is running on the given path. * NOTE: this method is to be called only when the OpenDS.jar class has * already been loaded as it uses classes in that jar. * @param locksDir File representing the location of the server's 'locks' * directory * @return <CODE>true</CODE> if the server is running and <CODE>false</CODE> * otherwise. */ public static boolean isServerRunning(File locksDir) { boolean isServerRunning; if (!lockPathInitialized) { System.setProperty( org.opends.server.util.ServerConstants.PROPERTY_LOCK_DIRECTORY, Utils.getPath(locksDir)); lockPathInitialized = true; } String lockFile = org.opends.server.core.LockFileManager.getServerLockFileName(); StringBuilder failureReason = new StringBuilder(); try { if (org.opends.server.core.LockFileManager.acquireExclusiveLock(lockFile, failureReason)) { org.opends.server.core.LockFileManager.releaseLock(lockFile, failureReason); isServerRunning = false; } else { isServerRunning = true; } } catch (Throwable t) { // Assume that if we cannot acquire the lock file the server is // running. isServerRunning = true; } return isServerRunning; } /** * Provides the ldap url to the server (assumes we are calling this locally). * * @return the ldap url to the server. */ public String getLdapUrl() { if (ldapUrl == null) { if (getPort() != -1) { ldapUrl = "ldap://localhost:"+getPort(); } } return ldapUrl; } /** * Provides the ldap secure url to the server (assumes we are calling this * locally). * * @return the ldap secure url to the server. */ public String getLdapsUrl() { if (ldapsUrl == null) { if (getSecurePort() != -1) { ldapsUrl = "ldaps://localhost:"+getSecurePort(); } } return ldapsUrl; } /** * Provides the LDAP port as is specified in the config.ldif file. * * @return the LDAP port specified in the config.ldif file. */ private int getPort() { return getPort("ds-cfg-listen-port"); } /** * Provides the LDAP secure port as is specified in the config.ldif file. * * @return the LDAP secure port specified in the config.ldif file. */ private int getSecurePort() { // TODO find out which is the attribute for this port. return getPort("ds-cfg-listen-secure-port"); } private int getPort(String portAttr) { int port = -1; int index = getConfigFileContents().indexOf("cn=ldap connection handler"); if (index != -1) { String attrWithPoints = portAttr+":"; int index1 = getConfigFileContents().indexOf(attrWithPoints, index); if (index1 != -1) { int index2 = getConfigFileContents().indexOf(Constants.LINE_SEPARATOR, index1); if (index2 != -1) { String sPort = getConfigFileContents().substring(attrWithPoints.length() + index1, index2).trim(); try { port = Integer.parseInt(sPort); } catch (NumberFormatException nfe) { } } } try { port = Installation.getLocal().getCurrentConfiguration(). getPort(); } catch (IOException ioe) { LOG.log(Level.INFO, "Failed to get port", ioe); } return port; } @@ -384,7 +169,8 @@ private boolean dbFilesExist() { boolean dbFilesExist = false; File dbDir = new File(Utils.getInstallPathFromClasspath(), "db"); File dbDir = Installation.getLocal().getDatabasesDirectory(); File[] children = dbDir.listFiles(); if ((children != null) && (children.length > 0)) { @@ -403,53 +189,16 @@ */ private boolean isConfigFileModified() { boolean isConfigFileModified = getPort() != 389; if (!isConfigFileModified) { // TODO: this is not really stable isConfigFileModified = getConfigFileContents().indexOf("# cddl header start") == -1; boolean mod = false; try { mod = Installation.getLocal().getCurrentConfiguration() .hasBeenModified(); } catch (IOException ioe) { LOG.log(Level.INFO, "failed to determine if config modified", ioe); } return isConfigFileModified; return mod; } /** * Provides the contents of the config.ldif file in a String. * * @return a String representing the contents of the config.ldif file. */ private String getConfigFileContents() { if (configFileContents == null) { StringBuilder buf = new StringBuilder(); try { Installation installation = getInstallationFromClassPath(); FileReader reader = new FileReader(installation.getCurrentConfigurationFile()); BufferedReader in = new BufferedReader(reader); String line; // We do not care about encoding: we are just interested in the ports while ((line = in.readLine()) != null) { buf.append(line).append(Constants.LINE_SEPARATOR); } reader.close(); } catch (IOException ioe) { } configFileContents = buf.toString().toLowerCase(); } return configFileContents; } /** * The following three methods are just commodity methods to get localized * messages. */ private String getMsg(String key) { return getI18n().getMsg(key); @@ -465,42 +214,4 @@ return ResourceProvider.getInstance(); } private void updateSetWithValues(Set<String> set, String attrName) { attrName += ":"; int index1 = getConfigFileContents().indexOf(attrName); while (index1 != -1) { int index2 = getConfigFileContents().indexOf( Constants.LINE_SEPARATOR, index1); String value; if (index2 > (index1 + attrName.length())) { value = getConfigFileContents().substring(attrName.length() + index1, index2).trim(); } else if (getConfigFileContents().length() > (index1 + attrName.length())) { // Assume end of file value = getConfigFileContents().substring( attrName.length() + index1).trim(); } else { value = null; } if ((value != null) && (value.length() > 0)) { set.add(value); } index1 = getConfigFileContents().indexOf(attrName, index1 + attrName.length()); } } private Installation getInstallationFromClassPath() { return new Installation(Utils.getInstallPathFromClasspath()); } } opends/src/quicksetup/org/opends/quicksetup/Installation.java
@@ -263,6 +263,29 @@ } } static private Installation local; /** * Obtains the installation by reading the classpath of the running * JVM to determine the location of the jars and determine the * installation root. * @return Installation obtained by reading the classpath */ static public Installation getLocal() { if (local == null) { // This allows testing of configuration components when the OpenDS.jar // in the classpath does not necessarily point to the server's String installRoot = System.getProperty("org.opends.quicksetup.Root"); if (installRoot == null) { installRoot = Utils.getInstallPathFromClasspath(); } local = new Installation(installRoot); } return local; } static private final Logger LOG = Logger.getLogger(Installation.class.getName()); @@ -369,7 +392,7 @@ */ public Configuration getCurrentConfiguration() { if (configuration == null) { configuration = new Configuration(getCurrentConfigurationFile()); configuration = new Configuration(this, getCurrentConfigurationFile()); } return configuration; } @@ -384,7 +407,7 @@ */ public Configuration getBaseConfiguration() throws ApplicationException { if (baseConfiguration == null) { baseConfiguration = new Configuration(getBaseConfigurationFile()); baseConfiguration = new Configuration(this, getBaseConfigurationFile()); } return baseConfiguration; } opends/src/quicksetup/org/opends/quicksetup/QuickSetupLog.java
@@ -59,12 +59,21 @@ logger.addHandler(fileHandler); logger.log(Level.INFO, getInitialLogRecord()); logger = Logger.getLogger("org.opends.admin.ads"); logger.setUseParentHandlers(false); // disable logging to console logger.addHandler(fileHandler); disableConsoleLogging(); } } /** * Prevents messages written to loggers from appearing in the console * output. */ static public void disableConsoleLogging() { Logger logger = Logger.getLogger("org.opends.quicksetup"); logger.setUseParentHandlers(false); } /** * Gets the name of the log file. * @return File representing the log file */ opends/src/quicksetup/org/opends/quicksetup/Status.java
@@ -27,6 +27,10 @@ package org.opends.quicksetup; import org.opends.server.util.ServerConstants; import org.opends.server.core.LockFileManager; import org.opends.quicksetup.util.Utils; import java.io.File; import java.io.IOException; @@ -90,28 +94,37 @@ * NOTE: this method is to be called only when the OpenDS.jar class has * already been loaded as it uses classes in that jar. * * LIMITATIONS: * If the locks directory does not exist the mechanism fails if the server is * stopped. However if the server.lock does not exist AND the server is not * running the mechanism should work most of the times (see failing case 3). * * The cases where this mechanism does not work are: * * 1. The user deletes/renames the locks directory. * 2. The user deletes/renames the server.lock file AND the server is running. * 3. The server is not running but the user that is running the code does not * have file system access rights. * 4. The server is not running and another process has a lock on the file. * @return <CODE>true</CODE> if the server is running and <CODE>false</CODE> * otherwise. * @throws java.io.IOException if there was a problem reading required * configuration information * otherwise. */ public boolean isServerRunning() throws IOException { public boolean isServerRunning() { boolean isServerRunning; if (!lockPathInitialized) { File lockDirectory = installation.getLocksDirectory(); File locksDir = installation.getLocksDirectory(); System.setProperty( org.opends.server.util.ServerConstants.PROPERTY_LOCK_DIRECTORY, lockDirectory.getCanonicalPath()); ServerConstants.PROPERTY_LOCK_DIRECTORY, Utils.getPath(locksDir)); lockPathInitialized = true; } String lockFile = org.opends.server.core.LockFileManager.getServerLockFileName(); String lockFile = LockFileManager.getServerLockFileName(); StringBuilder failureReason = new StringBuilder(); try { if (org.opends.server.core.LockFileManager.acquireExclusiveLock(lockFile, if (LockFileManager.acquireExclusiveLock(lockFile, failureReason)) { org.opends.server.core.LockFileManager.releaseLock(lockFile, LockFileManager.releaseLock(lockFile, failureReason); isServerRunning = false; } else { @@ -119,8 +132,8 @@ } } catch (Throwable t) { // Assume that if we cannot acquire the lock file the server is // running. // Assume that if we cannot acquire the lock file the // server is running. isServerRunning = true; } return isServerRunning; opends/src/quicksetup/org/opends/quicksetup/resources/Resources.properties
@@ -1038,6 +1038,8 @@ progress-deleting-installation-files=Deleting Files under the Installation Path: progress-deleting-file=Deleting file {0} progress-deleting-directory=Deleting directory {0} progress-deleting-file-does-not-exist=Ignoring file {0} since it does not exist. progress-copying-file=Copying file {0} to {1} progress-server-already-stopped=The Directory Server is already stopped. progress-server-waiting-to-stop=Waiting for Server to stop... opends/src/quicksetup/org/opends/quicksetup/ui/ConfirmUninstallPanel.java
@@ -28,6 +28,8 @@ package org.opends.quicksetup.ui; import org.opends.quicksetup.CurrentInstallStatus; import org.opends.quicksetup.Installation; import org.opends.quicksetup.Configuration; import org.opends.quicksetup.util.Utils; import javax.swing.*; @@ -36,6 +38,9 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Set; import java.util.logging.Level; import java.util.logging.Logger; import java.io.IOException; /** * This is the panel displayed when the user is uninstalling Open DS. It is @@ -45,6 +50,9 @@ */ public class ConfirmUninstallPanel extends QuickSetupStepPanel { private static final Logger LOG = Logger.getLogger(ConfirmUninstallPanel.class.getName()); private static final long serialVersionUID = 81730510134697056L; private CurrentInstallStatus installStatus; @@ -202,8 +210,20 @@ panel.add(p, gbc); outsideDbs = Utils.getOutsideDbs(installStatus); outsideLogs = Utils.getOutsideLogs(installStatus); Installation installation = Installation.getLocal(); Configuration config = installation.getCurrentConfiguration(); try { outsideDbs = config.getOutsideDbs(); } catch (IOException ioe) { LOG.log(Level.INFO, "Unable to determin outside databases", ioe); } try { outsideLogs = config.getOutsideLogs(); } catch (IOException ioe) { LOG.log(Level.INFO, "Unable to determin outside logs", ioe); } gbc.insets.top = UIFactory.TOP_INSET_PRIMARY_FIELD; gbc.fill = GridBagConstraints.HORIZONTAL; opends/src/quicksetup/org/opends/quicksetup/ui/DirectoryManagerAuthenticationDialog.java
@@ -35,6 +35,9 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.Set; import java.util.logging.Level; import java.util.logging.Logger; import java.io.IOException; import javax.naming.NamingException; import javax.naming.directory.SearchControls; @@ -48,7 +51,7 @@ import javax.swing.JTextField; import javax.swing.text.JTextComponent; import org.opends.quicksetup.CurrentInstallStatus; import org.opends.quicksetup.Installation; import org.opends.quicksetup.event.MinimumSizeComponentListener; import org.opends.quicksetup.i18n.ResourceProvider; import org.opends.quicksetup.util.BackgroundTask; @@ -61,12 +64,14 @@ */ public class DirectoryManagerAuthenticationDialog extends JDialog { private static final Logger LOG = Logger.getLogger( DirectoryManagerAuthenticationDialog.class.getName()); private static final long serialVersionUID = 9049409381101152000L; private JFrame parent; private CurrentInstallStatus installStatus; private JLabel lDn; private JLabel lPwd; @@ -83,16 +88,13 @@ /** * Constructor of the DirectoryManagerAuthenticationDialog. * @param parent the parent frame for this dialog. * @param installStatus the object describing the current installation * status. */ public DirectoryManagerAuthenticationDialog(JFrame parent, CurrentInstallStatus installStatus) public DirectoryManagerAuthenticationDialog(JFrame parent) { super(parent); setTitle(getMsg("shutdown-directory-manager-dialog-title")); this.parent = parent; this.installStatus = installStatus; getContentPane().add(createPanel()); } @@ -312,8 +314,14 @@ private String getProposedDirectoryManagerDn() { String dn; Set<String> dns = installStatus.getDirectoryManagerDns(); if (dns.size() > 0) Set<String> dns = null; try { dns = Installation.getLocal().getCurrentConfiguration(). getDirectoryManagerDns(); } catch (IOException ioe) { LOG.log(Level.INFO, "error obtaining dirmanager DNs", ioe); } if (dns != null && dns.size() > 0) { dn = dns.iterator().next(); } @@ -340,8 +348,12 @@ Boolean isServerRunning = Boolean.TRUE; try { String installPath = Utils.getInstallPathFromClasspath(); Installation installation = new Installation(installPath); int port = installation.getCurrentConfiguration().getPort(); String ldapUrl = "ldap://localhost:"+port; InitialLdapContext ctx = Utils.createLdapContext(installStatus.getLdapUrl(), tfDn.getText(), Utils.createLdapContext(ldapUrl, tfDn.getText(), tfPwd.getText(), Utils.getDefaultLDAPTimeout(), null); /* @@ -357,7 +369,7 @@ } catch (NamingException ne) { if (CurrentInstallStatus.isServerRunning()) if (Installation.getLocal().getStatus().isServerRunning()) { throw ne; } @@ -394,11 +406,17 @@ else { boolean found = false; Iterator<String> it = installStatus.getDirectoryManagerDns().iterator(); while (it.hasNext() && !found) { found = Utils.areDnsEqual(dn, it.next()); try { Set<String> dns; dns = Installation.getLocal().getCurrentConfiguration() .getDirectoryManagerDns(); Iterator<String> it = dns.iterator(); while (it.hasNext() && !found) { found = Utils.areDnsEqual(dn, it.next()); } } catch (IOException ioe) { LOG.log(Level.INFO, "error obtaining dirmanager DNs", ioe); } if (!found) { @@ -517,8 +535,7 @@ { // UIFactory.initialize(); DirectoryManagerAuthenticationDialog dlg = new DirectoryManagerAuthenticationDialog(new JFrame(), new CurrentInstallStatus()); new DirectoryManagerAuthenticationDialog(new JFrame()); dlg.packAndShow(); } catch (Exception ex) { opends/src/quicksetup/org/opends/quicksetup/ui/GuiApplication.java
@@ -36,7 +36,6 @@ import javax.swing.*; import java.awt.event.WindowEvent; import java.io.IOException; import java.io.File; import java.security.cert.X509Certificate; import java.util.LinkedHashSet; @@ -492,6 +491,7 @@ Thread.sleep(300); } catch (Exception ex) { // do nothing; } } } @@ -526,13 +526,8 @@ } InProcessServerController ipsc = new InProcessServerController(getInstallation()); ipsc.disableConnectionHandlers(true); InProcessServerController.disableConnectionHandlers(true); ipsc.startServer(); } catch (IOException e) { String msg = getMsg("error-determining-server-state"); LOG.log(Level.INFO, msg, e); throw new ApplicationException(ApplicationException.Type.IMPORT_ERROR, msg, e); } catch (Throwable t) { String msg = getMsg("error-starting-server-with-no-connection-handlers", (t.getMessage() == null) ? t.toString() : t.getMessage()); opends/src/quicksetup/org/opends/quicksetup/uninstaller/UninstallCliHelper.java
@@ -33,6 +33,10 @@ import java.util.HashSet; import java.util.Set; import java.util.Collections; import java.util.logging.Level; import java.util.logging.Logger; import java.io.IOException; /** * The class used to provide some CLI interface in the uninstall. @@ -46,6 +50,9 @@ */ class UninstallCliHelper extends CliApplicationHelper { static private final Logger LOG = Logger.getLogger(UninstallCliHelper.class.getName()); static private String FORMAT_KEY = "cli-uninstall-confirm-prompt"; /** @@ -83,8 +90,23 @@ /* Step 2: If this is not a silent install ask for confirmation to delete * the different parts of the installation */ Set<String> outsideDbs = getOutsideDbs(installStatus); Set<String> outsideLogs = getOutsideLogs(installStatus); Set<String> outsideDbs; Set<String> outsideLogs; Configuration config = Installation.getLocal().getCurrentConfiguration(); try { outsideDbs = config.getOutsideDbs(); } catch (IOException ioe) { outsideDbs = Collections.emptySet(); LOG.log(Level.INFO, "error determining outside databases", ioe); } try { outsideLogs = config.getOutsideLogs(); } catch (IOException ioe) { outsideLogs = Collections.emptySet(); LOG.log(Level.INFO, "error determining outside logs", ioe); } if (silentUninstall) { @@ -121,30 +143,6 @@ } /** * Returns a Set of relative paths containing the db paths outside the * installation. * @param installStatus the Current Install Status object. * @return a Set of relative paths containing the db paths outside the * installation. */ private Set<String> getOutsideDbs(CurrentInstallStatus installStatus) { return Utils.getOutsideDbs(installStatus); } /** * Returns a Set of relative paths containing the log paths outside the * installation. * @param installStatus the Current Install Status object. * @return a Set of relative paths containing the log paths outside the * installation. */ private Set<String> getOutsideLogs(CurrentInstallStatus installStatus) { return Utils.getOutsideLogs(installStatus); } /** * Commodity method used to ask the user to confirm the deletion of certain * parts of the server. It updates the provided UserData object * accordingly. Returns <CODE>true</CODE> if the user cancels and <CODE> @@ -325,8 +323,8 @@ throws UserDataException { boolean cancelled = false; if (CurrentInstallStatus.isServerRunning()) Status status = Installation.getLocal().getStatus(); if (status.isServerRunning()) { if (!silentUninstall) { @@ -337,7 +335,7 @@ if (!cancelled) { /* During all the confirmations, the server might be stopped. */ userData.setStopServer(CurrentInstallStatus.isServerRunning()); userData.setStopServer(status.isServerRunning()); } } else opends/src/quicksetup/org/opends/quicksetup/uninstaller/Uninstaller.java
@@ -271,7 +271,8 @@ throw new UserDataException(cStep, getThrowableMsg("bug-msg", t)); } return CurrentInstallStatus.isServerRunning(); Status status = Installation.getLocal().getStatus(); return status.isServerRunning(); } public void backgroundTaskCompleted(Object returnValue, @@ -812,7 +813,7 @@ // Just tell that the file/directory does not exist. String[] arg = {file.toString()}; notifyListeners(getFormattedWarning( getMsg("deleting-file-does-not-exist", arg))); getMsg("progress-deleting-file-does-not-exist", arg))); } } opends/src/quicksetup/org/opends/quicksetup/util/ServerController.java
@@ -161,8 +161,7 @@ boolean stopped = false; for (int i = 0; i < nTries && !stopped; i++) { stopped = !CurrentInstallStatus.isServerRunning( installation.getLocksDirectory()); installation.getStatus().isServerRunning(); if (!stopped) { if (application != null) { String msg = opends/src/quicksetup/org/opends/quicksetup/util/Utils.java
@@ -209,7 +209,6 @@ */ public static boolean isDescendant(String descendant, String path) { boolean isDescendant = false; File f1; File f2; @@ -230,16 +229,28 @@ { f2 = new File(descendant); } return isDescendant(f1, f2); } f2 = f2.getParentFile(); while ((f2 != null) && !isDescendant) { isDescendant = f1.equals(f2); if (!isDescendant) { f2 = f2.getParentFile(); /** * Returns <CODE>true</CODE> if the first provided path is under the second * path in the file system. * @param descendant the descendant candidate path. * @param path the path. * @return <CODE>true</CODE> if the first provided path is under the second * path in the file system; <code>false</code> otherwise or if * either of the files are null */ public static boolean isDescendant(File descendant, File path) { boolean isDescendant = false; if (descendant != null && path != null) { File parent = descendant.getParentFile(); while ((parent != null) && !isDescendant) { isDescendant = path.equals(parent); if (!isDescendant) { parent = parent.getParentFile(); } } } return isDescendant; @@ -885,7 +896,7 @@ * * @see javax.naming.Context * @see javax.naming.ldap.InitialLdapContext * @see TrustedSocketFactory * @see org.opends.admin.ads.util.TrustedSocketFactory */ public static InitialLdapContext createLdapsContext(String ldapsURL, String dn, String pwd, int timeout, Hashtable<String, String> env, @@ -924,7 +935,7 @@ * @see javax.naming.ldap.InitialLdapContext * @see javax.naming.ldap.StartTlsRequest * @see javax.naming.ldap.StartTlsResponse * @see TrustedSocketFactory * @see org.opends.admin.ads.util.TrustedSocketFactory */ public static InitialLdapContext createStartTLSContext(String ldapsURL, @@ -1088,55 +1099,6 @@ } /** * Returns a Set of relative paths containing the db paths outside the * installation. * @param installStatus the Current Install Status object. * @return a Set of relative paths containing the db paths outside the * installation. */ public static Set<String> getOutsideDbs(CurrentInstallStatus installStatus) { String installPath = getInstallPathFromClasspath(); Set<String> dbs = installStatus.getDatabasePaths(); Set<String> outsideDbs = new HashSet<String>(); for (String relativePath : dbs) { /* The db paths are relative */ String fullDbPath = getPath(installPath, relativePath); if (!isDescendant(fullDbPath, installPath)) { outsideDbs.add(fullDbPath); } } return outsideDbs; } /** * Returns a Set of relative paths containing the log paths outside the * installation. * @param installStatus the Current Install Status object. * @return a Set of relative paths containing the log paths outside the * installation. */ public static Set<String> getOutsideLogs(CurrentInstallStatus installStatus) { String installPath = getInstallPathFromClasspath(); Set<String> logs = installStatus.getLogPaths(); Set<String> outsideLogs = new HashSet<String>(); for (String relativePath : logs) { /* The db paths are relative */ String fullDbPath = getPath(installPath, relativePath); if (!isDescendant(fullDbPath, installPath)) { outsideLogs.add(fullDbPath); } } return outsideLogs; } /** * Returns the max size in character of a line to be displayed in the command * line. opends/src/statuspanel/org/opends/statuspanel/ServerStatusPooler.java
@@ -30,7 +30,7 @@ import java.io.File; import java.util.HashSet; import org.opends.quicksetup.CurrentInstallStatus; import org.opends.quicksetup.Installation; import org.opends.quicksetup.util.Utils; import org.opends.statuspanel.event.ServerStatusChangeEvent; import org.opends.statuspanel.event.ServerStatusChangeListener; @@ -151,6 +151,7 @@ } catch (Throwable t) { // do nothing; } } @@ -300,7 +301,7 @@ { desc.setStatus(ServerStatusDescriptor.ServerStatus.STOPPING); } else if (CurrentInstallStatus.isServerRunning()) else if (Installation.getLocal().getStatus().isServerRunning()) { desc.setStatus(ServerStatusDescriptor.ServerStatus.STARTED); } @@ -412,10 +413,6 @@ } } /** * The following three methods are just commodity methods to get localized * messages. */ private String getMsg(String key) { return getI18n().getMsg(key); opends/src/statuspanel/org/opends/statuspanel/StatusCli.java
@@ -40,8 +40,8 @@ import javax.swing.table.TableModel; import org.opends.quicksetup.CurrentInstallStatus; import org.opends.quicksetup.Installation; import org.opends.quicksetup.QuickSetupLog; import org.opends.quicksetup.util.Utils; import org.opends.server.core.DirectoryServer; @@ -52,8 +52,6 @@ import static org.opends.server.tools.ToolConstants.*; import org.opends.server.util.PasswordReader; import static org.opends.server.messages.ToolMessages.*; import static org.opends.server.messages.MessageHandler.*; /** * The class used to provide some CLI interface to display status. @@ -90,6 +88,7 @@ */ public static void main(String[] args) { QuickSetupLog.disableConsoleLogging(); StatusCli cli = new StatusCli(args); System.exit(cli.run()); } @@ -274,7 +273,8 @@ } else { boolean isServerRunning = CurrentInstallStatus.isServerRunning(); boolean isServerRunning = Installation.getLocal().getStatus().isServerRunning(); /* This is required to retrieve the ldap url to be used by the * ConfigFromLDAP class. */ @@ -397,7 +397,7 @@ ServerStatusDescriptor desc = new ServerStatusDescriptor(); desc.setAuthenticated((dn != null) && (pwd != null)); if (CurrentInstallStatus.isServerRunning()) if (Installation.getLocal().getStatus().isServerRunning()) { desc.setStatus(ServerStatusDescriptor.ServerStatus.STARTED); } opends/src/statuspanel/org/opends/statuspanel/StatusPanelController.java
@@ -39,7 +39,6 @@ import org.opends.server.core.DirectoryServer; import org.opends.quicksetup.CurrentInstallStatus; import org.opends.quicksetup.Installation; import org.opends.quicksetup.ui.UIFactory; import org.opends.quicksetup.util.BackgroundTask; @@ -579,7 +578,7 @@ boolean running = false; for (int i=0; i<5 && !running; i++) { running = CurrentInstallStatus.isServerRunning(); running = Installation.getLocal().getStatus().isServerRunning(); } if (!running) @@ -696,7 +695,8 @@ int nTries = 10; for (int i=0; i<nTries && !stopped; i++) { stopped = !CurrentInstallStatus.isServerRunning(); stopped = !Installation.getLocal().getStatus() .isServerRunning(); if (!stopped) { String msg = opends/src/statuspanel/org/opends/statuspanel/ui/LoginDialog.java
@@ -48,7 +48,7 @@ import javax.swing.JTextField; import javax.swing.text.JTextComponent; import org.opends.quicksetup.CurrentInstallStatus; import org.opends.quicksetup.Installation; import org.opends.quicksetup.event.MinimumSizeComponentListener; import org.opends.quicksetup.ui.UIFactory; import org.opends.quicksetup.util.BackgroundTask; @@ -545,7 +545,7 @@ */ private boolean isServerRunning() { return CurrentInstallStatus.isServerRunning(); return Installation.getLocal().getStatus().isServerRunning(); } /** opends/tests/unit-tests-testng/src/server/org/opends/quicksetup/ConfigurationTest.java
New file @@ -0,0 +1,103 @@ /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at * trunk/opends/resource/legal-notices/OpenDS.LICENSE * or https://OpenDS.dev.java.net/OpenDS.LICENSE. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable, * add the following below this CDDL HEADER, with the fields enclosed * by brackets "[]" replaced with your own identifying information: * Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END * * * Portions Copyright 2006-2007 Sun Microsystems, Inc. */ package org.opends.quicksetup; import static org.testng.Assert.*; import org.testng.annotations.*; import java.io.IOException; import java.util.Set; /** * Configuration Tester. */ @Test(groups = {"slow"}) public class ConfigurationTest extends QuickSetupTestCase { Configuration config; @BeforeClass public void setUp() throws Exception { config = Utils.getInstallation().getCurrentConfiguration(); } @Test public void testGetDirectoryManagerDns() throws IOException { Set<String> dns = config.getDirectoryManagerDns(); assertTrue(dns.size() > 0); } @Test public void testGetPort() throws IOException { assertTrue(Utils.ldapPort.equals(config.getPort())); } @Test public void testGetSecurePort() throws IOException { // TODO: something more useful config.getSecurePort(); } @Test public void testGetLogPaths() throws IOException { // TODO: something more useful config.getLogPaths(); } @Test public void testHasBeenModified() throws IOException { assertTrue(config.hasBeenModified()); } @Test public void testGetOutsideLogs() throws IOException { // TODO: something more useful config.getOutsideLogs(); } @Test public void testGetOutsideDbs() throws IOException { // TODO: something more useful config.getOutsideDbs(); } @Test public void testGetContents() throws IOException { assertNotNull(config.getContents()); } @Test public void testGetDatabasePaths() throws IOException { assertTrue(config.getDatabasePaths().size() > 0); } public void testLoad() { //TODO: need way to verify reload } } opends/tests/unit-tests-testng/src/server/org/opends/quicksetup/InstallationTest.java
@@ -38,12 +38,12 @@ */ @Test(groups = {"slow"}) public class InstallationTest extends QuickSetupTestCase { Installation installation; @BeforeClass public void setUp() throws Exception { Utils.extractServer(); installation = new Installation(Utils.getQuickSetupTestServerRootDir()); installation = Utils.getInstallation(); } /** opends/tests/unit-tests-testng/src/server/org/opends/quicksetup/QuickSetupTestCase.java
@@ -31,6 +31,8 @@ import org.testng.annotations.AfterSuite; import org.opends.server.TestCaseUtils; import java.io.IOException; /** * */ @@ -41,8 +43,16 @@ TestCaseUtils.suppressOutput(); } @BeforeSuite public final void initServer() throws IOException, ApplicationException, InterruptedException { Utils.initServer(); } @AfterSuite public final void shutdownServer() { public final void shutdownServer() throws ApplicationException { Utils.stopServer(); TestCaseUtils.unsupressOutput(); } opends/tests/unit-tests-testng/src/server/org/opends/quicksetup/Utils.java
@@ -28,11 +28,16 @@ package org.opends.quicksetup; import org.opends.quicksetup.util.ZipExtractor; import org.opends.quicksetup.util.ServerController; import org.opends.server.TestCaseUtils; import org.opends.server.types.OperatingSystem; import java.io.File; import java.io.FileNotFoundException; import java.io.PrintStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.net.ServerSocket; import java.util.List; import java.util.ArrayList; /** * @@ -45,10 +50,70 @@ public static final String PROPERTY_BUILD_ROOT = "org.opends.server.BuildRoot"; static public void extractServer() throws FileNotFoundException, ApplicationException { ZipExtractor extractor = new ZipExtractor(getInstallPackageFile()); extractor.extract(getQuickSetupTestServerRootDir()); public static final String DIRECTORY_MANAGER_PASSWORD = "password"; public static Integer ldapPort; public static Integer jmxPort; private static boolean initialized; static public void initServer() throws IOException, ApplicationException, InterruptedException { File qsServerRoot = getQuickSetupTestServerRootDir(); if (!initialized) { if (qsServerRoot.exists()) { stopServer(); if (!qsServerRoot.delete()) { throw new IllegalStateException("cannot delete stale installation"); } } ZipExtractor extractor = new ZipExtractor(getInstallPackageFile()); extractor.extract(qsServerRoot); setupServer(); initialized = true; } } static public Installation getInstallation() { return new Installation(Utils.getQuickSetupTestServerRootDir()); } static private void setupServer() throws IOException, InterruptedException { ServerSocket ldapSocket = TestCaseUtils.bindFreePort(); ldapPort = ldapSocket.getLocalPort(); ldapSocket.close(); ServerSocket jmxSocket = TestCaseUtils.bindFreePort(); jmxPort = jmxSocket.getLocalPort(); jmxSocket.close(); List<String> args = new ArrayList<String>(); File root = getQuickSetupTestServerRootDir(); if (OperatingSystem.isUNIXBased( OperatingSystem.forName(System.getProperty("os.name")))) { args.add(new File(root, "setup").getPath()); } else { args.add(new File(root, "setup.bat").getPath()); } args.add("--cli"); args.add("-s"); args.add("-p"); args.add(Integer.toString(ldapPort)); args.add("-x"); args.add(Integer.toString(jmxPort)); args.add("-w"); args.add(DIRECTORY_MANAGER_PASSWORD); ProcessBuilder pb = new ProcessBuilder(args); Process p = pb.start(); if (p.waitFor() != 0) { throw new IllegalStateException("setup server failed"); } } static public void stopServer() throws ApplicationException { ServerController controller = new ServerController(getInstallation()); controller.stopServer(); } static public File getInstallPackageFile() throws FileNotFoundException { opends/tests/unit-tests-testng/src/server/org/opends/quicksetup/util/ServerControllerTest.java
New file @@ -0,0 +1,81 @@ /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at * trunk/opends/resource/legal-notices/OpenDS.LICENSE * or https://OpenDS.dev.java.net/OpenDS.LICENSE. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable, * add the following below this CDDL HEADER, with the fields enclosed * by brackets "[]" replaced with your own identifying information: * Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END * * * Portions Copyright 2006-2007 Sun Microsystems, Inc. */ package org.opends.quicksetup.util; import org.testng.annotations.*; import org.opends.quicksetup.*; import org.opends.quicksetup.Utils; import org.opends.server.TestCaseUtils; import java.io.FileNotFoundException; /** * ServerController Tester. */ @Test(groups = {"slow"}) public class ServerControllerTest extends QuickSetupTestCase { ServerController controller; Status status; @BeforeClass public void setUp() throws Exception { Installation installation = Utils.getInstallation(); controller = new ServerController(installation); status = installation.getStatus(); } /** * Tests ability to stop the server. * @throws ApplicationException */ @Test public void testStopServer() throws ApplicationException { if (!status.isServerRunning()) { controller.startServer(); } assert (status.isServerRunning()); controller.stopServer(); assert (!status.isServerRunning()); } /** * Tests ability to start the server. * @throws ApplicationException */ @Test public void testStartServer() throws ApplicationException { if (status.isServerRunning()) { controller.stopServer(); } assert (!status.isServerRunning()); controller.startServer(); assert (status.isServerRunning()); } }