directory-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Tony Blanchard (JIRA)" <directory-...@incubator.apache.org>
Subject [jira] Created: (DIREVE-182) A new GUI to manage server start/shutdown.
Date Mon, 11 Jul 2005 12:49:10 GMT
A new GUI to manage server start/shutdown.
------------------------------------------

         Key: DIREVE-182
         URL: http://issues.apache.org/jira/browse/DIREVE-182
     Project: Directory Server
        Type: New Feature
  Components: server main  
 Environment: Tested on XP SP2 with JDK 1.5
    Reporter: Tony Blanchard
 Assigned to: Alex Karasulu 
    Priority: Minor


Here are the changes made to build this new GUI.

In server main,
Project.properties :
Change of this value "maven.javaapp.mainclass=org.apache.ldap.server.ServerMainGUI" to build
an executable jar which launch the new GUI.

Porject.xml : 
Adding in project block
<build>
	<resources>
	<resource>
<directory>${basedir}/src/main/java/res"</directory>
<targetPath>res</targetPath>
</resource>
</resources>
</build>

under "main\java" folder :
Adding a new folder named "res" with to files named "msg.properties" and "msg_fr_FR.properties".

msg.properties :
#ResourceBundle properties file
default_conf_msg=default
conf_label=Configuration file:
conf_button_label=Configuration
status_label=Status:
start_button_label=Start
stop_button_label=Stop
status_started=Started
status_stopped=Stopped
status_loading_conf=Loading configuration...
status_init_start_env=Initializing environment...
status_init_start=Starting server...
status_init_stop_env=Initializing stopping environment...
status_init_stop=Stopping server...
server_main_gui_title=LDAP server manager
status_not_stopped=Was unable to stop !
status_not_started=Was unable to start !
conf_selection_title=Configuration file selection

msg_fr_FR.properties:
#ResourceBundle properties file
default_conf_msg=Défaut
conf_label=Fichier de configuration :
conf_button_label=Configuration
status_label=Status :
start_button_label=Démarrage
stop_button_label=Arrêt
status_started=Démarré
status_stopped=Arrêté
status_loading_conf=Chargement de la configuration...
status_init_start_env=Initialisation de l''environment...
status_init_start=Démarrage du serveur...
status_init_stop_env=Initialisation de l''environement d'arrêt...
status_init_stop=Arrêt du serveur...
server_main_gui_title=Gestion du serveur LDAP
status_not_stopped=Arrêt impossible !
status_not_started=Démarrage impossible !
conf_selection_title=Configuration file selection

Under the package "org.apache.ldap.server" :
Addition of the class "org.apache.ldap.server.ServerMainGUI"
/*
 * ServerMainGUI.java
 *
 * Created on 7 juillet 2005, 15:56
 */

package org.apache.ldap.server;

import java.util.Properties;
import java.util.ResourceBundle;

import javax.naming.Context;
import javax.naming.NamingException;
import javax.naming.directory.InitialDirContext;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.JFileChooser;
import java.awt.Dimension;
import java.awt.Insets;

import java.io.PrintStream;
import java.io.ByteArrayOutputStream;

import org.apache.ldap.server.configuration.MutableServerStartupConfiguration;
import org.apache.ldap.server.configuration.ShutdownConfiguration;
import org.apache.ldap.server.configuration.ServerStartupConfiguration;
import org.apache.ldap.server.jndi.ServerContextFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;

/**
 * A box which enables to choose a server configuration file to start the server with.
 * It allows to start or stop the server as needed.
 * The main entry point of the application uses the "LDAP_SERVER_CONF" environment variable
or
 * application argument to locate the configuration file else, default values are used to
start
 * the server.
 * The command line argument is prioritary facing the system environment variable.
 * @author  Tony Blanchard - 2005
 */
public class ServerMainGUI extends javax.swing.JDialog
{
    protected Properties env;
    protected ServerStartupConfiguration cfg;
    private boolean confFileProvided = false;
    
    /** Creates new form ServerMainGUI. */
    public ServerMainGUI(java.awt.Frame pParent, boolean pModal)
    {
        super(pParent, pModal);
        initComponents();
        
        //Default configuration for the first run and while admin password is default
        env = new Properties();
        env.put( "java.naming.security.authentication", "simple");
        env.put( Context.SECURITY_PRINCIPAL, "uid=admin,ou=system" );
        env.put( Context.SECURITY_CREDENTIALS, "secret" );
        
        cfg = new MutableServerStartupConfiguration();
        
        setLocationRelativeTo(pParent);
        setTitle(ResourceBundle.getBundle("res/msg").getString("server_main_gui_title"));
    }
    
    /**
     * Enlarge the box to show the user what's wrong with it.
     */
    protected void printError(Throwable pError)
    {
        errorOptionalPanel.add(errorScrollPanel);
        Insets lBoxInsets = this.getInsets();
        errorOptionalPanel.setPreferredSize(new Dimension(this.getWidth()- (lBoxInsets.left
+ lBoxInsets.right),200));
        
        //compute the stack trace...
        ByteArrayOutputStream lOutputStream = new ByteArrayOutputStream();
        pError.printStackTrace(new PrintStream(lOutputStream));
        errorMessage.append(lOutputStream.toString());
        errorMessage.append(" ---\n");
        pack();
    }
    
    /**
     * Changes the configuration file path to use to load LDAP configuration file.
     */
    public void setConfigurationFile(String pConfFilePath)
    {
        confFieldValue.setText(pConfFilePath);
        confFieldValue.setToolTipText(pConfFilePath);
        confFileProvided = true;
    }
    
    /**
     * Start button reaction.
     */
    protected void stopServer()
    {
        ResourceBundle lBundle = null;
        try//For the case where a shema is missing we could want to catch
                //ClassNotFoundException for instance
        {
            lBundle = ResourceBundle.getBundle("res/msg");
            
            //Initializing environment
            statusFieldValue.setText(lBundle.getString("status_init_stop_env"));
            
            env.putAll( new ShutdownConfiguration().toJndiEnvironment() );
            
            try
            {
                statusFieldValue.setText(lBundle.getString("status_init_stop"));
                InitialDirContext lDir= new InitialDirContext( env );
                env.clear();
                statusFieldValue.setText(lBundle.getString("status_stopped"));
            }
            catch (NamingException pError)
            {
                printError(pError);
                statusFieldValue.setText(lBundle.getString("status_not_stopped"));
            }
            finally
            {
                stopServer.setEnabled(false);
                startServer.setEnabled(true);
            }
        }
        catch (Throwable pError)
        {
            printError(pError);
            statusFieldValue.setText(lBundle.getString("status_not_stopped"));
        }
    }
    
    /**
     * Start button reaction.
     */
    protected void startServer()
    {
        ResourceBundle lBundle = null;
        try//For the case where a shema is missing we could want to catch
                //ClassNotFoundException for instance
        {
            lBundle = ResourceBundle.getBundle("res/msg");
            
            //Loading configuration or using the default one.
            if (confFileProvided)
            {
                statusFieldValue.setText(lBundle.getString("status_loading_conf"));
                ApplicationContext factory = new FileSystemXmlApplicationContext( confFieldValue.getText()
);
                cfg = ( ServerStartupConfiguration ) factory.getBean( "configuration" );
                env = ( Properties ) factory.getBean( "environment" );
            }
            
            //Initializing environment
            statusFieldValue.setText(lBundle.getString("status_init_start_env"));
            env.setProperty( Context.PROVIDER_URL, "ou=system" );
            env.setProperty( Context.INITIAL_CONTEXT_FACTORY, ServerContextFactory.class.getName()
);
            env.putAll( cfg.toJndiEnvironment() );
            
            
            try
            {
                statusFieldValue.setText(lBundle.getString("status_init_start"));
                //Starting server
                new InitialDirContext( env );
                statusFieldValue.setText(lBundle.getString("status_started"));
            }
            catch (NamingException pError)
            {
                printError(pError);
                statusFieldValue.setText(lBundle.getString("status_not_started"));
            }
            finally
            {
                stopServer.setEnabled(true);
                startServer.setEnabled(false);
            }
            
        }
        catch (Throwable pError)
        {
            printError(pError);
            statusFieldValue.setText(lBundle.getString("status_not_started"));
        }
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
    private void initComponents()
    {
        errorScrollPanel = new javax.swing.JScrollPane();
        errorMessage = new javax.swing.JTextArea();
        mainPanel = new javax.swing.JPanel();
        infoPanel = new javax.swing.JPanel();
        confPanel = new javax.swing.JPanel();
        confFieldValue = new javax.swing.JLabel();
        confTitle = new javax.swing.JLabel();
        statusPanel = new javax.swing.JPanel();
        statusTitle = new javax.swing.JLabel();
        statusFieldValue = new javax.swing.JLabel();
        commandPanel = new javax.swing.JPanel();
        loadConf = new javax.swing.JButton();
        startServer = new javax.swing.JButton();
        stopServer = new javax.swing.JButton();
        errorOptionalPanel = new javax.swing.JPanel();

        errorScrollPanel.setMaximumSize(new java.awt.Dimension(500, 200));
        errorMessage.setEditable(false);
        errorMessage.setFont(new java.awt.Font("Bitstream Vera Sans", 0, 10));
        errorMessage.setBorder(null);
        errorMessage.setMaximumSize(new java.awt.Dimension(500, 200));
        errorScrollPanel.setViewportView(errorMessage);

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        mainPanel.setLayout(new java.awt.GridLayout(2, 0));

        mainPanel.setPreferredSize(new java.awt.Dimension(400, 95));
        infoPanel.setLayout(new java.awt.GridLayout(2, 0, 0, 2));

        confPanel.setLayout(new java.awt.BorderLayout(4, 0));

        confFieldValue.setText(java.util.ResourceBundle.getBundle("res/msg").getString("default_conf_msg"));
        confPanel.add(confFieldValue, java.awt.BorderLayout.CENTER);

        confTitle.setFont(new java.awt.Font("Microsoft Sans Serif", 1, 11));
        confTitle.setText(java.util.ResourceBundle.getBundle("res/msg").getString("conf_label"));
        confPanel.add(confTitle, java.awt.BorderLayout.WEST);

        infoPanel.add(confPanel);

        statusPanel.setLayout(new java.awt.BorderLayout(4, 0));

        statusTitle.setFont(new java.awt.Font("Microsoft Sans Serif", 1, 11));
        statusTitle.setText(java.util.ResourceBundle.getBundle("res/msg").getString("status_label"));
        statusPanel.add(statusTitle, java.awt.BorderLayout.WEST);

        statusFieldValue.setText(java.util.ResourceBundle.getBundle("res/msg").getString("status_stopped"));
        statusPanel.add(statusFieldValue, java.awt.BorderLayout.CENTER);

        infoPanel.add(statusPanel);

        mainPanel.add(infoPanel);

        getContentPane().add(mainPanel, java.awt.BorderLayout.CENTER);

        commandPanel.setLayout(new java.awt.GridLayout(4, 0));

        loadConf.setText(java.util.ResourceBundle.getBundle("res/msg").getString("conf_button_label"));
        loadConf.addActionListener(new java.awt.event.ActionListener()
        {
            public void actionPerformed(java.awt.event.ActionEvent evt)
            {
                loadConfActionPerformed(evt);
            }
        });

        commandPanel.add(loadConf);

        startServer.setText(java.util.ResourceBundle.getBundle("res/msg").getString("start_button_label"));
        startServer.addActionListener(new java.awt.event.ActionListener()
        {
            public void actionPerformed(java.awt.event.ActionEvent evt)
            {
                startServerActionPerformed(evt);
            }
        });

        commandPanel.add(startServer);

        stopServer.setText(java.util.ResourceBundle.getBundle("res/msg").getString("stop_button_label"));
        stopServer.setEnabled(false);
        stopServer.addActionListener(new java.awt.event.ActionListener()
        {
            public void actionPerformed(java.awt.event.ActionEvent evt)
            {
                stopServerActionPerformed(evt);
            }
        });

        commandPanel.add(stopServer);

        getContentPane().add(commandPanel, java.awt.BorderLayout.EAST);

        errorOptionalPanel.setLayout(new java.awt.BorderLayout());

        getContentPane().add(errorOptionalPanel, java.awt.BorderLayout.SOUTH);

        pack();
    }
    // </editor-fold>//GEN-END:initComponents
    
    private void loadConfActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_loadConfActionPerformed
    {//GEN-HEADEREND:event_loadConfActionPerformed
        JFileChooser lConfFileChooser = new JFileChooser();
        
        lConfFileChooser.setDialogTitle(ResourceBundle.getBundle("res/msg").getString("conf_selection_title"));
        int lReturnVal = lConfFileChooser.showOpenDialog(this);
        if(lReturnVal == JFileChooser.APPROVE_OPTION)
        {
            setConfigurationFile(lConfFileChooser.getSelectedFile().toString());
        }
    }//GEN-LAST:event_loadConfActionPerformed
    
    private void stopServerActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_stopServerActionPerformed
    {//GEN-HEADEREND:event_stopServerActionPerformed
        stopServer();
    }//GEN-LAST:event_stopServerActionPerformed
    
    private void startServerActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_startServerActionPerformed
    {//GEN-HEADEREND:event_startServerActionPerformed
        startServer();
    }//GEN-LAST:event_startServerActionPerformed
    
    /**
     * The manager main entry point.
     * @param pArgs the command line arguments
     */
    public static void main(String pArgs[])
    {
        try
        {
            //Setting the look and feel to the current system laf
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        }
        catch (Throwable pError)
        {
            System.err.println(pError.getMessage());
        }
        
        ServerMainGUI lGUI = new ServerMainGUI(null, true);
        
        String lLDAP_SERVER_CONF = System.getenv("LDAP_SERVER_CONF");
        if (lLDAP_SERVER_CONF != null)
            lGUI.setConfigurationFile(lLDAP_SERVER_CONF);
        
        if ( pArgs.length > 0 )
            lGUI.setConfigurationFile(pArgs[0]);
        
        lGUI.setVisible(true);
    }
    
    /**
     * Stop the server when living the GUI manager
     */
    public void dispose()
    {
        stopServer();
        super.dispose();
    }
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel commandPanel;
    private javax.swing.JLabel confFieldValue;
    private javax.swing.JPanel confPanel;
    private javax.swing.JLabel confTitle;
    private javax.swing.JTextArea errorMessage;
    private javax.swing.JPanel errorOptionalPanel;
    private javax.swing.JScrollPane errorScrollPanel;
    private javax.swing.JPanel infoPanel;
    private javax.swing.JButton loadConf;
    private javax.swing.JPanel mainPanel;
    private javax.swing.JButton startServer;
    private javax.swing.JLabel statusFieldValue;
    private javax.swing.JPanel statusPanel;
    private javax.swing.JLabel statusTitle;
    private javax.swing.JButton stopServer;
    // End of variables declaration//GEN-END:variables
}


Now you can make a symbolic link under windows with a target like this:
javaw -cp main.jar confFile.xml

or main.jar if the environment variable describe below has been defined.

This GUI can also been feed with LDAP_SERVER_CONF system environment variable.

Launching it without configuration file will create a new working dir with admin default password
authentication : "secret"

This GUI is aimed to help non skilled users with apacheds server at deployment site.
If you think it is not interseting, just forget it.
Tony

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


Mime
View raw message