directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r414574 - /directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/StoredProcedureCommand.java
Date Thu, 15 Jun 2006 13:09:02 GMT
Author: akarasulu
Date: Thu Jun 15 06:09:01 2006
New Revision: 414574

URL: http://svn.apache.org/viewvc?rev=414574&view=rev
Log:
adding command to execute stored procedures to apacheds-tools

Added:
    directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/StoredProcedureCommand.java

Added: directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/StoredProcedureCommand.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/StoredProcedureCommand.java?rev=414574&view=auto
==============================================================================
--- directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/StoredProcedureCommand.java
(added)
+++ directory/trunks/apacheds/server-tools/src/main/java/org/apache/directory/server/tools/StoredProcedureCommand.java
Thu Jun 15 06:09:01 2006
@@ -0,0 +1,205 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.directory.server.tools;
+
+
+import java.util.Hashtable;
+
+import javax.naming.ldap.InitialLdapContext;
+import javax.naming.ldap.LdapContext;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.Options;
+import org.apache.directory.daemon.AvailablePortFinder;
+import org.apache.directory.shared.ldap.message.extended.StoredProcedureRequest;
+
+
+/**
+ * A command used to send a command to execute a stored procedure on the server.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class StoredProcedureCommand extends ToolCommand
+{
+    public static final String PORT_RANGE = "(" + AvailablePortFinder.MIN_PORT_NUMBER + ",
"
+        + AvailablePortFinder.MAX_PORT_NUMBER + ")";
+
+    private int port = 10389;
+    private String host = "localhost";
+    private String password = "secret";
+
+
+    protected StoredProcedureCommand()
+    {
+        super( "proc" );
+    }
+
+
+    public void execute( CommandLine cmd ) throws Exception
+    {
+        processOptions( cmd );
+
+        if ( isDebugEnabled() )
+        {
+            System.out.println( "Parameters for StoredProcedure extended request:" );
+            System.out.println( "port = " + port );
+            System.out.println( "host = " + host );
+            System.out.println( "password = " + password );
+        }
+
+        Hashtable env = new Hashtable();
+        env.put( "java.naming.factory.initial", "com.sun.jndi.ldap.LdapCtxFactory" );
+        env.put( "java.naming.provider.url", "ldap://" + host + ":" + port );
+        env.put( "java.naming.security.principal", "uid=admin,ou=system" );
+        env.put( "java.naming.security.credentials", password );
+        env.put( "java.naming.security.authentication", "simple" );
+
+        LdapContext ctx = new InitialLdapContext( env, null );
+        if ( !isQuietEnabled() )
+        {
+            System.out.println( "Connection to the server established.\n"
+                + "Sending extended request and blocking for shutdown:" );
+        }
+
+        String language = "java";
+        String procedure = "hello";
+        StoredProcedureRequest req = new StoredProcedureRequest( 0, procedure, language );
+        ctx.extendedOperation( req );
+        ctx.close();
+    }
+
+
+    private void processOptions( CommandLine cmd )
+    {
+        if ( isDebugEnabled() )
+        {
+            System.out.println( "Processing options for graceful shutdown ..." );
+        }
+
+        // -------------------------------------------------------------------
+        // figure out and error check the port value
+        // -------------------------------------------------------------------
+
+        if ( cmd.hasOption( 'p' ) ) // - user provided port w/ -p takes precedence
+        {
+            String val = cmd.getOptionValue( 'p' );
+            try
+            {
+                port = Integer.parseInt( val );
+            }
+            catch ( NumberFormatException e )
+            {
+                System.err.println( "port value of '" + val + "' is not a number" );
+                System.exit( 1 );
+            }
+
+            if ( port > AvailablePortFinder.MAX_PORT_NUMBER )
+            {
+                System.err.println( "port value of '" + val + "' is larger than max port
number: "
+                    + AvailablePortFinder.MAX_PORT_NUMBER );
+                System.exit( 1 );
+            }
+            else if ( port < AvailablePortFinder.MIN_PORT_NUMBER )
+            {
+                System.err.println( "port value of '" + val + "' is smaller than the minimum
port number: "
+                    + AvailablePortFinder.MIN_PORT_NUMBER );
+                System.exit( 1 );
+            }
+
+            if ( isDebugEnabled() )
+            {
+                System.out.println( "port overriden by -p option: " + port );
+            }
+        }
+        else if ( getConfiguration() != null )
+        {
+            port = getConfiguration().getLdapPort();
+
+            if ( isDebugEnabled() )
+            {
+                System.out.println( "port overriden by server.xml configuration: " + port
);
+            }
+        }
+        else if ( isDebugEnabled() )
+        {
+            System.out.println( "port set to default: " + port );
+        }
+
+        // -------------------------------------------------------------------
+        // figure out the host value
+        // -------------------------------------------------------------------
+
+        if ( cmd.hasOption( 'h' ) )
+        {
+            host = cmd.getOptionValue( 'h' );
+
+            if ( isDebugEnabled() )
+            {
+                System.out.println( "host overriden by -h option: " + host );
+            }
+        }
+        else if ( isDebugEnabled() )
+        {
+            System.out.println( "host set to default: " + host );
+        }
+
+        // -------------------------------------------------------------------
+        // figure out the password value
+        // -------------------------------------------------------------------
+
+        if ( cmd.hasOption( 'w' ) )
+        {
+            password = cmd.getOptionValue( 'w' );
+
+            if ( isDebugEnabled() )
+            {
+                System.out.println( "password overriden by -w option: " + password );
+            }
+        }
+        else if ( isDebugEnabled() )
+        {
+            System.out.println( "password set to default: " + password );
+        }
+    }
+
+
+    public Options getOptions()
+    {
+        Options opts = new Options();
+        Option op = new Option( "h", "host", true, "server host: defaults to localhost" );
+        op.setRequired( false );
+        opts.addOption( op );
+        op = new Option( "p", "port", true, "server port: defaults to 10389 or server.xml
specified port" );
+        op.setRequired( false );
+        opts.addOption( op );
+        op = new Option( "e", "delay", true, "delay (seconds) before shutdown: defaults to
0" );
+        op.setRequired( false );
+        opts.addOption( op );
+        op = new Option( "w", "password", true, "the apacheds administrator's password: defaults
to secret" );
+        op.setRequired( false );
+        opts.addOption( op );
+        op = new Option( "t", "time-offline", true, "server offline time (minutes): defaults
to 0 (indefinate)" );
+        op.setRequired( false );
+        opts.addOption( op );
+        op = new Option( "i", "install-path", true, "path to apacheds installation directory"
);
+        op.setRequired( false );
+        opts.addOption( op );
+        return opts;
+    }
+}



Mime
View raw message