directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kayyag...@apache.org
Subject svn commit: r770070 - in /directory/apacheds/branches/apacheds-replication/syncrepl/src/main/java/org/apache/directory/server/syncrepl: SyncreplConfiguration.java SyncreplRunnerUI.java
Date Thu, 30 Apr 2009 05:22:04 GMT
Author: kayyagari
Date: Thu Apr 30 05:22:01 2009
New Revision: 770070

URL: http://svn.apache.org/viewvc?rev=770070&view=rev
Log:
o syncrepl configuration(temporary)
o a test UI using swing

Added:
    directory/apacheds/branches/apacheds-replication/syncrepl/src/main/java/org/apache/directory/server/syncrepl/SyncreplConfiguration.java
    directory/apacheds/branches/apacheds-replication/syncrepl/src/main/java/org/apache/directory/server/syncrepl/SyncreplRunnerUI.java

Added: directory/apacheds/branches/apacheds-replication/syncrepl/src/main/java/org/apache/directory/server/syncrepl/SyncreplConfiguration.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-replication/syncrepl/src/main/java/org/apache/directory/server/syncrepl/SyncreplConfiguration.java?rev=770070&view=auto
==============================================================================
--- directory/apacheds/branches/apacheds-replication/syncrepl/src/main/java/org/apache/directory/server/syncrepl/SyncreplConfiguration.java
(added)
+++ directory/apacheds/branches/apacheds-replication/syncrepl/src/main/java/org/apache/directory/server/syncrepl/SyncreplConfiguration.java
Thu Apr 30 05:22:01 2009
@@ -0,0 +1,284 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.syncrepl;
+
+import org.apache.directory.shared.ldap.filter.SearchScope;
+
+/**
+ * 
+ * A class for holding the syncrepl consumer's configuration.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class SyncreplConfiguration
+{
+    /** host name of the syncrepl provider server */
+    private String providerHost;
+
+    /** port number of the syncrepl provider server */
+    private int port;
+
+    /** bind dn */
+    private String bindDn;
+
+    /** password for binding with bind dn */
+    private String credentials;
+
+    /** flag to represent refresh and persist or refreh only mode */
+    private boolean refreshPersist = true;
+
+    /** time interval for successive sync requests */
+    private long consumerInterval = 5 * 1000;
+
+    /** the base DN whose content will be searched for syncing */
+    private String baseDn;
+
+    /** the ldap filter for fetching the entries */
+    private String filter;
+
+    /** a comma separated string of attribute names */
+    private String attributes;
+
+    /** the numer for setting the limit on numer of search results to be fteched
+     * default value is 0 (i.e no limit) */
+    private int searchSizeLimit = 0;
+
+    /** the timeout value to be used while doing a search 
+     * default value is 0 (i.e no limit)*/
+    private int searchTimeout = 0;
+
+    /** the search scope */
+    private int searchScope = SearchScope.ONELEVEL.getJndiScope();
+
+    /** the replica's id */
+    private int replicaId;
+    
+    /**
+     * @return the providerHost
+     */
+    public String getProviderHost()
+    {
+        return providerHost;
+    }
+
+    /**
+     * @param providerHost the providerHost to set
+     */
+    public void setProviderHost( String providerHost )
+    {
+        this.providerHost = providerHost;
+    }
+
+    /**
+     * @return the port
+     */
+    public int getPort()
+    {
+        return port;
+    }
+
+    /**
+     * @param port the port to set
+     */
+    public void setPort( int port )
+    {
+        this.port = port;
+    }
+
+    /**
+     * @return the bindDn
+     */
+    public String getBindDn()
+    {
+        return bindDn;
+    }
+
+    /**
+     * @param bindDn the bindDn to set
+     */
+    public void setBindDn( String bindDn )
+    {
+        this.bindDn = bindDn;
+    }
+
+    /**
+     * @return the credentials
+     */
+    public String getCredentials()
+    {
+        return credentials;
+    }
+
+    /**
+     * @param credentials the credentials to set
+     */
+    public void setCredentials( String credentials )
+    {
+        this.credentials = credentials;
+    }
+
+    /**
+     * @return the refreshPersist
+     */
+    public boolean isRefreshPersist()
+    {
+        return refreshPersist;
+    }
+
+    /**
+     * @param refreshPersist the refreshPersist to set
+     */
+    public void setRefreshPersist( boolean refreshPersist )
+    {
+        this.refreshPersist = refreshPersist;
+    }
+
+    /**
+     * @return the consumerInterval
+     */
+    public long getConsumerInterval()
+    {
+        return consumerInterval;
+    }
+
+    /**
+     * @param consumerInterval the consumerInterval to set
+     */
+    public void setConsumerInterval( long consumerInterval )
+    {
+        this.consumerInterval = consumerInterval;
+    }
+
+    /**
+     * @return the baseDn
+     */
+    public String getBaseDn()
+    {
+        return baseDn;
+    }
+
+    /**
+     * @param baseDn the baseDn to set
+     */
+    public void setBaseDn( String baseDn )
+    {
+        this.baseDn = baseDn;
+    }
+
+    /**
+     * @return the filter
+     */
+    public String getFilter()
+    {
+        return filter;
+    }
+
+    /**
+     * @param filter the filter to set
+     */
+    public void setFilter( String filter )
+    {
+        this.filter = filter;
+    }
+
+    /**
+     * @return the attributes
+     */
+    public String getAttributes()
+    {
+        return attributes;
+    }
+
+    /**
+     * @param attributes the attributes to set
+     */
+    public void setAttributes( String attributes )
+    {
+        this.attributes = attributes;
+    }
+
+    /**
+     * @return the searchSizeLimit
+     */
+    public int getSearchSizeLimit()
+    {
+        return searchSizeLimit;
+    }
+
+    /**
+     * @param searchSizeLimit the searchSizeLimit to set
+     */
+    public void setSearchSizeLimit( int searchSizeLimit )
+    {
+        this.searchSizeLimit = searchSizeLimit;
+    }
+
+    /**
+     * @return the searchTimeout
+     */
+    public int getSearchTimeout()
+    {
+        return searchTimeout;
+    }
+
+    /**
+     * @param searchTimeout the searchTimeout to set
+     */
+    public void setSearchTimeout( int searchTimeout )
+    {
+        this.searchTimeout = searchTimeout;
+    }
+
+    /**
+     * @return the searchScope
+     */
+    public int getSearchScope()
+    {
+        return searchScope;
+    }
+
+    /**
+     * @param searchScope the searchScope to set
+     */
+    public void setSearchScope( int searchScope )
+    {
+        this.searchScope = searchScope;
+    }
+
+    /**
+     * @return the replicaId
+     */
+    public int getReplicaId()
+    {
+        return replicaId;
+    }
+
+    /**
+     * @param replicaId the replicaId to set
+     */
+    public void setReplicaId( int replicaId )
+    {
+        this.replicaId = replicaId;
+    }
+
+    
+    
+}

Added: directory/apacheds/branches/apacheds-replication/syncrepl/src/main/java/org/apache/directory/server/syncrepl/SyncreplRunnerUI.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-replication/syncrepl/src/main/java/org/apache/directory/server/syncrepl/SyncreplRunnerUI.java?rev=770070&view=auto
==============================================================================
--- directory/apacheds/branches/apacheds-replication/syncrepl/src/main/java/org/apache/directory/server/syncrepl/SyncreplRunnerUI.java
(added)
+++ directory/apacheds/branches/apacheds-replication/syncrepl/src/main/java/org/apache/directory/server/syncrepl/SyncreplRunnerUI.java
Thu Apr 30 05:22:01 2009
@@ -0,0 +1,280 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.syncrepl;
+
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+import java.io.File;
+
+import javax.swing.JButton;
+import javax.swing.JFrame;
+import javax.swing.JPanel;
+import javax.swing.SwingUtilities;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.directory.server.core.DefaultDirectoryService;
+import org.apache.directory.server.core.DirectoryService;
+import org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmPartition;
+import org.apache.directory.server.ldap.LdapService;
+import org.apache.directory.server.ldap.handlers.extended.StartTlsHandler;
+import org.apache.directory.server.ldap.handlers.extended.StoredProcedureExtendedOperationHandler;
+import org.apache.directory.server.protocol.shared.transport.TcpTransport;
+import org.apache.directory.shared.ldap.filter.SearchScope;
+import org.apache.directory.shared.ldap.name.LdapDN;
+import org.apache.mina.util.AvailablePortFinder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * 
+ *  A simple swing UI to start stop syncrepl consumer.
+ *  This class avoids the costly operation of setting up config 
+ *  and directory service between start/stop of consumer.
+ *  
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class SyncreplRunnerUI implements ActionListener
+{
+    private SyncreplConfiguration config;
+    
+    private SyncReplConsumer agent = new SyncReplConsumer();
+    
+    private File workDir;
+    
+    private DirectoryService dirService;
+    
+    private LdapService ldapService;
+    
+    private static final Logger LOG = LoggerFactory.getLogger( SyncreplRunnerUI.class );
+    
+    // UI components
+    private JButton btnStart;
+    
+    private JButton btnStop;
+    
+    private JButton btnCleanStart;
+    
+    public SyncreplRunnerUI()
+    {
+        config = new SyncreplConfiguration();
+        config.setProviderHost( "localhost" );
+        config.setPort( 389 );
+        config.setBindDn( "cn=admin,dc=nodomain" );
+        config.setCredentials( "secret" );
+        config.setBaseDn( "dc=test,dc=nodomain" );
+        config.setFilter( "(objectclass=*)" );
+        config.setSearchScope( SearchScope.SUBTREE.getJndiScope() );
+        config.setReplicaId( 1 );
+        agent.setConfig( config );
+        
+        workDir = new File( System.getProperty( "java.io.tmpdir" ) + "/work" );
+    }
+
+    
+    public void start()
+    {
+        try
+        {
+            if ( ! workDir.exists() )
+            {
+                workDir.mkdirs();
+            }
+            
+            dirService = startEmbeddedServer( workDir );
+            
+            agent.init( dirService );
+            agent.bind();
+            agent.prepareSyncSearchRequest();
+            agent.startSync();
+        }
+        catch( Exception e )
+        {
+            LOG.error( "Failed to start the embedded server & syncrepl consumer", e );
+            throw new RuntimeException( e );
+        }
+    }
+
+    public void stop()
+    {
+        try
+        {
+            agent.disconnet();
+            dirService.shutdown();
+            ldapService.stop();
+        }
+        catch( Exception e )
+        {
+            LOG.error( "Failed to stop", e );
+        }
+    }
+    
+    public void cleanStart()
+    {
+        try
+        {
+            if( workDir.exists() )
+            {
+                FileUtils.forceDelete( workDir );
+            }
+        }
+        catch( Exception e )
+        {
+            LOG.error( "Failed to delete the work directory", e );
+        }
+
+        agent.deleteCookieFile();
+        start();
+    }
+    
+    
+    private DirectoryService startEmbeddedServer( File workDir )
+    {
+        try
+        {
+            DefaultDirectoryService dirService = new DefaultDirectoryService();
+            dirService.setShutdownHookEnabled( false );
+            dirService.setWorkingDirectory( workDir );
+            int consumerPort = AvailablePortFinder.getNextAvailable( 1024 );
+            ldapService = new LdapService();
+            ldapService.setTcpTransport( new TcpTransport( consumerPort ) );
+            ldapService.setDirectoryService( dirService );
+
+            LdapDN suffix = new LdapDN( config.getBaseDn() );
+            JdbmPartition partition = new JdbmPartition();
+            partition.setSuffix( suffix.getUpName() );
+            partition.setId( "syncrepl" );
+            partition.setSyncOnWrite( true );
+            partition.init( dirService );
+
+            dirService.addPartition( partition );
+
+            dirService.startup();
+
+            ldapService.addExtendedOperationHandler( new StartTlsHandler() );
+            ldapService.addExtendedOperationHandler( new StoredProcedureExtendedOperationHandler()
);
+
+            ldapService.start();
+            return dirService;
+        }
+        catch ( Exception e )
+        {
+            e.printStackTrace();
+        }
+        
+        return null;
+    }
+
+    public void show()
+    {
+        JFrame frame = new JFrame();
+        frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
+        frame.setTitle( "Syncrepl consumer UI" );
+        
+        btnStart = new JButton( "Start" );
+        btnStart.setMnemonic( 'S' );
+        btnStart.addActionListener( this );
+        
+        
+        btnCleanStart = new JButton( "Clean Start" );
+        btnCleanStart.setMnemonic( 'R' );
+        btnCleanStart.addActionListener( this );
+        
+        btnStop = new JButton( "Stop" );
+        btnStop.setMnemonic( 'O' );
+        btnStop.setEnabled( false );
+        btnStop.addActionListener( this );
+        
+        JPanel panel = new JPanel();
+        panel.add( btnStart );
+        panel.add( btnStop );
+        panel.add( btnCleanStart );
+        
+        frame.getContentPane().add( panel );
+        frame.addWindowListener( new WindowAdapter()
+        {
+            @Override
+            public void windowClosed( WindowEvent e )
+            {
+                stop();
+            }
+        });
+
+        frame.pack();
+        frame.setVisible( true );
+    }
+
+
+    public void actionPerformed( ActionEvent e )
+    {
+        Object src = e.getSource();
+        
+        if( src == btnStart )
+        {
+            btnStart.setEnabled( false );
+            btnCleanStart.setEnabled( false );
+            SwingUtilities.invokeLater( new Runnable()
+            {
+                public void run()
+                {
+                    start();
+                }
+            } );
+            btnStop.setEnabled( true );
+        }
+        else if( src == btnStop )
+        {
+            btnStop.setEnabled( false );
+            SwingUtilities.invokeLater( new Runnable()
+            {
+                public void run()
+                {
+                    stop();
+                }
+            } );
+
+            btnStart.setEnabled( true );
+            btnCleanStart.setEnabled( true );
+        }
+        else if( src == btnCleanStart )
+        {
+            btnCleanStart.setEnabled( false );
+            btnStart.setEnabled( false );
+
+            SwingUtilities.invokeLater( new Runnable()
+            {
+                public void run()
+                {
+                    cleanStart();
+                }
+            } );
+            btnStop.setEnabled( true );
+        }
+    }
+
+
+    public static void main( String[] args )
+    {
+        SyncreplRunnerUI runnerUi = new SyncreplRunnerUI();
+        runnerUi.show();
+    }
+}



Mime
View raw message