directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pamarce...@apache.org
Subject svn commit: r660195 - in /directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations: ./ actions/ jobs/
Date Mon, 26 May 2008 14:08:54 GMT
Author: pamarcelot
Date: Mon May 26 07:08:52 2008
New Revision: 660195

URL: http://svn.apache.org/viewvc?rev=660195&view=rev
Log:
Added a verification on protocol ports to see if they are not already used before to launch
the server.

Modified:
    directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/ApacheDsPluginUtils.java
    directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/actions/ServerInstanceRunAction.java
    directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/jobs/LaunchServerInstanceJob.java

Modified: directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/ApacheDsPluginUtils.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/ApacheDsPluginUtils.java?rev=660195&r1=660194&r2=660195&view=diff
==============================================================================
--- directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/ApacheDsPluginUtils.java
(original)
+++ directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/ApacheDsPluginUtils.java
Mon May 26 07:08:52 2008
@@ -49,6 +49,9 @@
     /** The version of ApacheDS bundle with the plugin */
     private static final String APACHEDS_VERSION = "1.5.2";
 
+    /** The line separator */
+    public static final String LINE_SEPARATOR = System.getProperty( "line.separator" );
+
     /** This array of String contains all filenames of the needed libraries to launch Apache
DS */
     public static final String[] apachedsLibraries = new String[]
         { "antlr-2.7.7.jar", "apacheds-bootstrap-extract-1.5.2.jar", "apacheds-bootstrap-partition-1.5.2.jar",
@@ -221,9 +224,9 @@
             File apachedsConfFile = new File( confFolder, "apacheds.conf" );
             copyConfigurationFile( "apacheds.conf", apachedsConfFile );
 
-            // Copying log4j.properties file
+            // Creating log4j.properties file
             File log4jPropertiesFile = new File( confFolder, "log4j.properties" );
-            createServerInstanceLog4jPropertiesFile( new FileOutputStream( log4jPropertiesFile
), id, 1024 ); // Setting 1024 as default port
+            createServerInstanceLog4jPropertiesFile( new FileOutputStream( log4jPropertiesFile
), 1024 ); // Setting 1024 as default port
 
             // Copying server.xml file
             File serverXmlFile = new File( confFolder, "server.xml" );
@@ -246,13 +249,10 @@
      *
      * @param os
      *      the {@link OutputStream} to write to
-     * @param id
-     *      the id of the server instance
      * @throws IOException
      *      if an error occurs when writing to the file
      */
-    public static void createServerInstanceLog4jPropertiesFile( OutputStream os, String id,
int port )
-        throws IOException
+    public static void createServerInstanceLog4jPropertiesFile( OutputStream os, int port
) throws IOException
     {
         // Creating the file content in a StringBuffer
         StringBuffer sb = new StringBuffer();

Modified: directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/actions/ServerInstanceRunAction.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/actions/ServerInstanceRunAction.java?rev=660195&r1=660194&r2=660195&view=diff
==============================================================================
--- directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/actions/ServerInstanceRunAction.java
(original)
+++ directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/actions/ServerInstanceRunAction.java
Mon May 26 07:08:52 2008
@@ -20,16 +20,27 @@
 package org.apache.directory.studio.apacheds.experimentations.actions;
 
 
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.directory.studio.apacheds.configuration.model.ServerXmlIOException;
+import org.apache.directory.studio.apacheds.configuration.model.v152.ServerConfigurationV152;
+import org.apache.directory.studio.apacheds.configuration.model.v152.ServerXmlIOV152;
 import org.apache.directory.studio.apacheds.experimentations.ApacheDsPlugin;
 import org.apache.directory.studio.apacheds.experimentations.ApacheDsPluginConstants;
+import org.apache.directory.studio.apacheds.experimentations.ApacheDsPluginUtils;
 import org.apache.directory.studio.apacheds.experimentations.jobs.LaunchServerInstanceJob;
 import org.apache.directory.studio.apacheds.experimentations.model.ServerInstance;
 import org.apache.directory.studio.apacheds.experimentations.views.ServersView;
+import org.apache.mina.util.AvailablePortFinder;
 import org.eclipse.jface.action.Action;
 import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.MessageDialog;
 import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.ISelectionChangedListener;
-import org.eclipse.jface.viewers.SelectionChangedEvent;
 import org.eclipse.jface.viewers.StructuredSelection;
 import org.eclipse.ui.IWorkbenchWindow;
 import org.eclipse.ui.IWorkbenchWindowActionDelegate;
@@ -68,15 +79,180 @@
      */
     public void run()
     {
+        // Getting the selection
         StructuredSelection selection = ( StructuredSelection ) view.getViewer().getSelection();
         if ( ( !selection.isEmpty() ) && ( selection.size() == 1 ) )
         {
-            LaunchServerInstanceJob job = new LaunchServerInstanceJob( ( ServerInstance )
selection.getFirstElement() );
+            // Getting the server instance
+            ServerInstance serverInstance = ( ServerInstance ) selection.getFirstElement();
+
+            // Parsing the 'server.xml' file
+            ServerXmlIOV152 serverXmlIOV152 = new ServerXmlIOV152();
+            ServerConfigurationV152 serverConfiguration = null;
+            try
+            {
+                serverConfiguration = ( ServerConfigurationV152 ) serverXmlIOV152.parse(
new FileInputStream( new File(
+                    ApacheDsPluginUtils.getApacheDsInstancesFolder().append( serverInstance.getId()
).append( "conf" )
+                        .append( "server.xml" ).toOSString() ) ) );
+            }
+            catch ( FileNotFoundException e )
+            {
+                reportErrorReadingServerConfiguration( e.getMessage() );
+                return;
+            }
+            catch ( ServerXmlIOException e )
+            {
+                reportErrorReadingServerConfiguration( e.getMessage() );
+                return;
+            }
+
+            // Checking if we could read the 'server.xml' file
+            if ( serverConfiguration == null )
+            {
+                reportErrorReadingServerConfiguration( null );
+                return;
+            }
+
+            // Verifying if the protocol ports are currently available
+            String[] alreadyInUseProtocolPortsList = getAlreadyInUseProtocolPorts( serverConfiguration
);
+            if ( ( alreadyInUseProtocolPortsList != null ) && ( alreadyInUseProtocolPortsList.length
> 0 ) )
+            {
+                String title = null;
+                String message = null;
+
+                if ( alreadyInUseProtocolPortsList.length == 1 )
+                {
+                    title = "Port already in use";
+                    message = "The port of the protocol " + alreadyInUseProtocolPortsList[0]
+ " is already in use.";
+                }
+                else
+                {
+                    title = "Ports already in use";
+                    message = "The ports of the following protocols are already in use:";
+                    for ( String alreadyInUseProtocolPort : alreadyInUseProtocolPortsList
)
+                    {
+                        message += ApacheDsPluginUtils.LINE_SEPARATOR + "\t" + "- " + alreadyInUseProtocolPort;
+                    }
+                }
+
+                message += ApacheDsPluginUtils.LINE_SEPARATOR + ApacheDsPluginUtils.LINE_SEPARATOR
+                    + "Do you wish to continue?";
+
+                MessageDialog dialog = new MessageDialog( view.getSite().getShell(), title,
null, message,
+                    MessageDialog.WARNING, new String[]
+                        { IDialogConstants.OK_LABEL, IDialogConstants.CANCEL_LABEL }, MessageDialog.OK
);
+                if ( dialog.open() == MessageDialog.CANCEL )
+                {
+                    return;
+                }
+            }
+
+            LaunchServerInstanceJob job = new LaunchServerInstanceJob( serverInstance );
             job.schedule();
         }
     }
 
 
+    /**
+     * Reports to the user an error message indicating the server 
+     * configuration could not be read correctly.
+     *
+     * @param errorMessage
+     *      an error message which can be <code>null</code>
+     */
+    private void reportErrorReadingServerConfiguration( String errorMessage )
+    {
+        String message = null;
+
+        if ( errorMessage == null )
+        {
+            message = "Unable to read the server configuration.";
+        }
+        else
+        {
+            message = "Unable to read the server configuration." + ApacheDsPluginUtils.LINE_SEPARATOR
+                + ApacheDsPluginUtils.LINE_SEPARATOR + "The following error occurred: " +
errorMessage;
+        }
+
+        MessageDialog dialog = new MessageDialog( view.getSite().getShell(), "Unable to read
the server configuration",
+            null, message, MessageDialog.ERROR, new String[]
+                { IDialogConstants.OK_LABEL }, MessageDialog.OK );
+        dialog.open();
+    }
+
+
+    /**
+     * Gets an array of String containing the ports and their associated 
+     * protocols which are already in use.
+     *
+     * @param serverConfiguration
+     *      the server configuration
+     * @return
+     *      an array of String containing the ports and their associated 
+     * protocols which are already in use.
+     */
+    private String[] getAlreadyInUseProtocolPorts( ServerConfigurationV152 serverConfiguration
)
+    {
+        List<String> alreadyInUseProtocolPortsList = new ArrayList<String>();
+
+        // LDAP
+        if ( true ) // Add a isEnableLdap() method to the server configuration
+        {
+            if ( !AvailablePortFinder.available( serverConfiguration.getLdapPort() ) )
+            {
+                alreadyInUseProtocolPortsList.add( "LDAP (port " + serverConfiguration.getLdapPort()
+ ")" );
+            }
+        }
+
+        // LDAPS
+        if ( serverConfiguration.isEnableLdaps() )
+        {
+            if ( !AvailablePortFinder.available( serverConfiguration.getLdapsPort() ) )
+            {
+                alreadyInUseProtocolPortsList.add( "LDAPS (port " + serverConfiguration.getLdapsPort()
+ ")" );
+            }
+        }
+        // Kerberos
+        if ( serverConfiguration.isEnableKerberos() )
+        {
+            if ( !AvailablePortFinder.available( serverConfiguration.getKerberosPort() )
)
+            {
+                alreadyInUseProtocolPortsList.add( "Kerberos (port " + serverConfiguration.getKerberosPort()
+ ")" );
+            }
+        }
+
+        // DNS
+        if ( serverConfiguration.isEnableDns() )
+        {
+            if ( !AvailablePortFinder.available( serverConfiguration.getDnsPort() ) )
+            {
+                alreadyInUseProtocolPortsList.add( "DNS (port " + serverConfiguration.getDnsPort()
+ ")" );
+            }
+        }
+
+        // NTP
+        if ( serverConfiguration.isEnableNtp() )
+        {
+            if ( !AvailablePortFinder.available( serverConfiguration.getNtpPort() ) )
+            {
+                alreadyInUseProtocolPortsList.add( "NTP (port " + serverConfiguration.getNtpPort()
+ ")" );
+            }
+        }
+
+        // Change Password
+        if ( serverConfiguration.isEnableChangePassword() )
+        {
+            if ( !AvailablePortFinder.available( serverConfiguration.getChangePasswordPort()
) )
+            {
+                alreadyInUseProtocolPortsList.add( "ChangePassword (port "
+                    + serverConfiguration.getChangePasswordPort() + ")" );
+            }
+        }
+
+        return alreadyInUseProtocolPortsList.toArray( new String[0] );
+    }
+
+
     /* (non-Javadoc)
      * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
      */

Modified: directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/jobs/LaunchServerInstanceJob.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/jobs/LaunchServerInstanceJob.java?rev=660195&r1=660194&r2=660195&view=diff
==============================================================================
--- directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/jobs/LaunchServerInstanceJob.java
(original)
+++ directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/jobs/LaunchServerInstanceJob.java
Mon May 26 07:08:52 2008
@@ -21,13 +21,16 @@
 
 
 import java.io.File;
+import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
 
-import org.apache.directory.studio.apacheds.experimentations.ApacheDsPlugin;
+import org.apache.directory.studio.apacheds.configuration.model.ServerXmlIOException;
+import org.apache.directory.studio.apacheds.configuration.model.v152.ServerConfigurationV152;
+import org.apache.directory.studio.apacheds.configuration.model.v152.ServerXmlIOV152;
 import org.apache.directory.studio.apacheds.experimentations.ApacheDsPluginUtils;
 import org.apache.directory.studio.apacheds.experimentations.ConsolesHandler;
 import org.apache.directory.studio.apacheds.experimentations.LogMessageConsole;
@@ -43,22 +46,25 @@
 import org.eclipse.core.runtime.Status;
 import org.eclipse.core.runtime.jobs.Job;
 import org.eclipse.debug.core.DebugPlugin;
+import org.eclipse.debug.core.ILaunch;
 import org.eclipse.debug.core.ILaunchConfiguration;
 import org.eclipse.debug.core.ILaunchConfigurationType;
 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
 import org.eclipse.debug.core.ILaunchManager;
-import org.eclipse.debug.ui.DebugUITools;
 import org.eclipse.debug.ui.IDebugUIConstants;
 import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
 import org.eclipse.jdt.launching.IRuntimeClasspathEntry;
 import org.eclipse.jdt.launching.IVMInstall;
 import org.eclipse.jdt.launching.JavaRuntime;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.MessageDialog;
 import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
 
 
 /**
  * This class implements a {@link Job} that is used to launch a server instance.
- *
+ * 
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$, $Date$
  */
@@ -79,7 +85,9 @@
     }
 
 
-    /* (non-Javadoc)
+    /*
+     * (non-Javadoc)
+     * 
      * @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor)
      */
     protected IStatus run( IProgressMonitor monitor )
@@ -87,6 +95,7 @@
         // Setting the name of the Job
         setName( "Starting " + serverInstance.getName() + "..." );
 
+        // Setting the server in a "starting" state
         serverInstance.setState( ServerStateEnum.STARTING );
 
         Display.getDefault().asyncExec( new Runnable()
@@ -113,7 +122,15 @@
         launchSocketServer( port );
 
         // Overwriting the server instance log4j.properties file
-        overwriteServerInstanceLog4jPropertiesFile( port );
+        try
+        {
+            overwriteServerInstanceLog4jPropertiesFile( port );
+        }
+        catch ( IOException e1 )
+        {
+            // TODO Auto-generated catch block
+            e1.printStackTrace();
+        }
 
         // Launching Apache DS
         launchApacheDS();
@@ -134,13 +151,13 @@
 
 
     /**
-     * Launches a Log4J {@link SocketServer} which will be used to redirect 
-     * the logs of Apache DS to the console.
+     * Launches a Log4J {@link SocketServer} which will be used to redirect the
+     * logs of Apache DS to the console.
+     * 
+     * @param port
+     *            the port
+     * @param
      * 
-     * @param port  
-     *      the port
-     * @param 
-     *      
      */
     private void launchSocketServer( int port )
     {
@@ -165,15 +182,20 @@
 
 
     /**
-     * Overwrites the log4j.properties file of the server instance with the given port number.
-     *
+     * Overwrites the log4j.properties file of the server instance with the
+     * given port number.
+     * 
      * @param port
-     *      the port
+     *            the port
+     * @throws IOException 
      */
-    private void overwriteServerInstanceLog4jPropertiesFile( int port )
+    private void overwriteServerInstanceLog4jPropertiesFile( int port ) throws IOException
     {
-        // TODO Auto-generated method stub
-
+        IPath confFolderPath = ApacheDsPluginUtils.getApacheDsInstancesFolder().append( serverInstance.getId()
)
+            .append( "conf" );
+        File confFolder = new File( confFolderPath.toOSString() );
+        ApacheDsPluginUtils.createServerInstanceLog4jPropertiesFile( new FileOutputStream(
new File( confFolder,
+            "log4j.properties" ) ), port );
     }
 
 
@@ -271,7 +293,7 @@
             e.printStackTrace();
         }
 
-        // Launching the launch configuration 
+        // Launching the launch configuration
         try
         {
             configuration.launch( ILaunchManager.RUN_MODE, new NullProgressMonitor() );
@@ -281,6 +303,6 @@
             // TODO Auto-generated catch block
             e.printStackTrace();
         }
-        //        DebugUITools.launch( configuration, ILaunchManager.RUN_MODE );
+        // DebugUITools.launch( configuration, ILaunchManager.RUN_MODE );
     }
 }



Mime
View raw message