john pfeiffer
  • Home
  • Categories
  • Tags
  • Archives

AtmosDirectoryListing INCOMPLETE

//2012-03-20 johnpfeiffer

import java.util.ArrayList;
import java.util.List;
import java.util.ListIterator;

import com.emc.esu.api.EsuApi;
import com.emc.esu.api.DirectoryEntry;
import com.emc.esu.api.EsuException;
import com.emc.esu.api.ListOptions;
import com.emc.esu.api.ObjectPath;


public class AtmosDirectoryListing
{
    public static final String CLASSVERSION = "0.1";
    private ObjectPath objectPath;
    private DirectoryEntry dir;
    List<DirectoryEntry> dirListing;
    public static final int RESULTSBATCHCOUNT = 10000;
    private int tokenCount;

    AtmosDirectoryListing( String path ) throws EsuException
    {
        if( path == null )
        {       throw new NullPointerException( "Path cannot be null" );
        }
        if( path.isEmpty() )
        {       throw new IllegalArgumentException( "Path cannot be empty" );
        }

        objectPath = new ObjectPath( path );
        dir = new DirectoryEntry();
        dir.setPath( objectPath );
    }

    int getTokenCount()
    {
        return tokenCount;
    }

    void calculateTokens( int limit )
    {
        int quotient = 0;
        int remainder  = 0;

        if( limit < 1 )
        {       throw new IllegalArgumentException( "limit can not be less than 1" );
        }else   if( limit < RESULTSBATCHCOUNT + 1 )
        {
            tokenCount = 1;
        }else
        {
            quotient = limit / 10000;
            remainder = limit % 10000;
            System.out.println( "limit " + limit + " = " + quotient + " * " + RESULTSBATCHCOUNT + " + " + remainder );
            tokenCount = quotient + 1;
        }
    }

    // should just return a collection?
    // should allow for Filters (i.e.  options = isIncludeMetadata()
    void displayListing( EsuApi myEsuApi , int limit ) throws EsuException
    {
        if( myEsuApi == null )
        {       throw new IllegalArgumentException( "EsuApi can not be null" );
        }
        if( limit > 0 )
        {
            int resultCount = 0;

            ListOptions options = new ListOptions();
            this.calculateTokens( limit );


            /*
            if( limit < resultsBatchCount + 1)
            {
                options.setLimit( limit );
              dirListing = myEsuApi.listDirectory( objectPath , options );
            }else
            {
                options.setLimit( resultsBatchCount );
              dirListing = myEsuApi.listDirectory( objectPath , options );
              limit = limit - resultsBatchCount;

                while( options.getToken() != null  && resultCount < limit )
            {
                    List<DirectoryEntry> temp = myEsuApi.listDirectory( objectPath , options );
                    System.out.println( "DEBUG: adding = " + temp.size() );
                    dirListing.addAll( temp  );
                    resultCount = resultCount + temp.size();

            }


            }
                */

            resultCount = dirListing.size();
            System.out.println( "DEBUG: total size = " + resultCount );
            /*
            tempList = myEsuApi.listDirectory( objectPath , options );
            System.out.println( "DEBUG: found = " + tempList.size() );
            dirListing.addAll( tempList  );
            System.out.println( "DEBUG: listing size = " + dirListing.size() );

            while( options.getToken() != null )     // Atmos uses tokens to retrieve larger result sets
            {
                tempList = myEsuApi.listDirectory( objectPath , options );
                System.out.println( "DEBUG: found = " + tempList.size() );
                dirListing.addAll( tempList  );
            }
            System.out.println( "DEBUG: listing size = " + dirListing.size() );
        */

            ListIterator<DirectoryEntry> it = dirListing.listIterator();
            while ( it.hasNext () )
        {
                //System.out.println( it.next() );
        }
        }else
        {       throw new IllegalArgumentException( "Limit must be greater than 0" );
        }
    }



    String getVersion()
    {
        return CLASSVERSION;
    }

    @Override public String toString()
    {
        String lineSeparator = System.getProperty( "line.separator" );
        StringBuilder result = new StringBuilder();
        result.append(this.getClass().getName() + " Object {" + lineSeparator );
        result.append( "version: " + CLASSVERSION + lineSeparator);
        result.append( "objectPath: " + objectPath + lineSeparator);
        result.append( "DirectoryEntry: " + dir + lineSeparator);
        result.append( "}" );
        return result.toString();
    }


} //end class





// 2012-03-15 requires AtmosConnection, CommandLineParametersRequirements

import java.util.ArrayList;
import java.util.List;
import java.util.ListIterator;

import org.apache.log4j.ConsoleAppender;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.apache.log4j.PatternLayout;

import com.emc.esu.api.DirectoryEntry;
import com.emc.esu.api.EsuApi;
import com.emc.esu.api.EsuException;
import com.emc.esu.api.ListOptions;
import com.emc.esu.api.ObjectPath;
import com.emc.esu.api.ServiceInformation;
import com.emc.esu.api.rest.EsuRestApi;

public class Main
{
    static Logger rootLogger = Logger.getRootLogger();
    private static AtmosConnection atmos;
    private static EsuApi myEsuApi;
    private static ObjectPath objectPath;

    public static void main( String[] args )
    {
        String server = "HOST";
        String port = "PORT" ;
        String user = "SUBTENANTID/UID";
        String password = "SECRETKEY";
        String directory = "/foldername/";
        CommandLineParameterRequirements required = new CommandLineParameterRequirements( 5, "version 0.1: java -jar AtmosDirectoryListing.jar " + server + " " + port + " " + user + " " + password + " " + directory );
        if( ! required.isValid( args , System.out ) )
        {       System.exit( 1 );
        }

        server = args[0];
        port = args[1];
        user = args[2];
        password = args[3];
        directory = args[4];


        server = "storage.synaptic.att.com";
        port = "443";
        user = "2c1d6f41934840b397bc78c670cf1e15/Oxygen";
        password = "YTQZqdt9jA0vwEa8H2qF01tbOIA=";
        directory = "/oxygencloud-storage/";


        initializeLogger();

        try{
            atmos = new AtmosConnection( server , port , user , password );
            myEsuApi = atmos.getEsuApi();
        }catch( Exception e )
        {   e.printStackTrace();
            System.exit( 1 );
        }
        AtmosDirectoryListing dirlist = null;
        try{
             dirlist = new AtmosDirectoryListing( directory );
        }catch( EsuException ee )
        {       rootLogger.error( "Error: \n" + ee.getMessage() );
        }
        EsuApi ea = new EsuRestApi( server , 443 , user , password );
        try{
            dirlist.displayListing( ea , 31000 );
        }catch( EsuException ee )
        {       rootLogger.error( "Error: \n" + ee.getMessage() );
        }


    }

    private static void initializeLogger()
    {
        if( !rootLogger.getAllAppenders().hasMoreElements() )
        {
            rootLogger.setLevel( Level.INFO );
            rootLogger.addAppender( new ConsoleAppender(  new PatternLayout(PatternLayout.TTCC_CONVERSION_PATTERN )  ) );
        }
    }

}// end class

  • « AtmosDirectoryListingTest INCOMPLETE
  • InstallCert modified »

Published

Mar 21, 2012

Category

java-classes

~494 words

Tags

  • atmos 11
  • atmosdirectorylisting 1
  • classes 92
  • incomplete 22
  • java 252