john pfeiffer
  • Home
  • Categories
  • Tags
  • Archives

atmos display by path

import com.emc.esu.api.*;
import com.emc.esu.api.rest.*;

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

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

public class AtmosDisplayByPath
{
    private static Logger rootLogger = Logger.getRootLogger();

    public static void main( String[] args )
    {
        if( !rootLogger.getAllAppenders().hasMoreElements() )
        {
            rootLogger.setLevel( Level.INFO );
            rootLogger.addAppender( new ConsoleAppender(  new PatternLayout(PatternLayout.TTCC_CONVERSION_PATTERN )  ) );
            rootLogger.info("Starting application...");
        }

        if( args.length != 6 )
        {
            System.out.println( args.length + " does not equal the 6 required arguments.");
            System.out.println( "version 0.1: java -jar atmosdisplaybypath.jar HOST PORT SUBTENANTID/UID SECRETKEY /PATH/ MAXLIMIT" );
            System.out.println( "example: java -jar atmosdisplaybypath.jar storage.synaptic.att.com 443 1a2b3c/uid 9z8y7x / 10" );
            System.out.println( "example: java -jar atmosdisplaybypath.jar storage.synaptic.att.com 443 1a2b3c/uid 9z8y7x /foldername/filename 1" );
            System.exit( 1 );
        }

        String HOST = args[0];
        int PORT = Integer.parseInt( args[1] );
        String FULLTOKENID = args[2];
        String SECRETKEY = args[3];
        String PATH = args[4];
        int MAXRESULTSLIMIT = Integer.parseInt( args[5] );  //max number of ListOptions.getToken() to recursively use

        displayConnectionCredentials( HOST , PORT , FULLTOKENID , SECRETKEY , PATH , MAXRESULTSLIMIT );

        EsuApi myEsuApi = null;
        try
        {   myEsuApi = new EsuRestApi( HOST, PORT, FULLTOKENID, SECRETKEY );
        }catch( EsuException e )
        {
            System.out.println( "EsuRestApi Constructor failed. " + e.getMessage() );
            e.printStackTrace();
        }
      displayAtmosInformation( myEsuApi );

      ObjectPath objectPath = new ObjectPath( PATH );
      if( objectPath.isDirectory() )
      {
        displayAtmosDirectoryListing( myEsuApi , objectPath , MAXRESULTSLIMIT );
      }
      else
      {
        displayAtmosObjectByPath( objectPath , myEsuApi );
      }

        rootLogger.info("Application Finished Successfully");
    } // end main()

    private static void displayConnectionCredentials( String HOST , int PORT , String FULLTOKENID , String SECRETKEY , String PATH , int MAXRESULTSLIMIT )
    {
        System.out.println( "Connecting to Host: " + HOST );
        System.out.println( "Connecting on Port: " + PORT );
        System.out.println( "Full Token ID: " + FULLTOKENID );
        System.out.println( "Secret Key: **************" );
        System.out.println( "Namespace Path: " + PATH );
        System.out.println( "Maximum number of pages results to return: " + MAXRESULTSLIMIT );
    }

    private static void displayAtmosInformation( EsuApi myEsuApi )
    {
        try{
            ServiceInformation atmosServiceInformation = myEsuApi.getServiceInformation();
            String atmosVersion = atmosServiceInformation.getAtmosVersion();
            System.out.println( "Atmos Version: " + atmosVersion );
        }
        catch( EsuException ee )
        {   rootLogger.error( "Get Atmos system version failed. " + ee + " AtmosCode: " + ee.getAtmosCode() );
        }
        catch( Exception e )
        {   System.out.println( "Get Atmos system version failed. " + e );
            System.out.println( e );
        }
    }

    private static void displayAtmosDirectoryListing( EsuApi myEsuApi , ObjectPath myObjectPath , int MAXRESULTSLIMIT )
    {
        int tokencounter = 0;
        int filecounter = 0;
        List<DirectoryEntry> myDirectoryEntryList = new ArrayList<DirectoryEntry>();
        ListOptions options = new ListOptions();

        System.out.println( "Atmos Directory Listing: " );
        try{
            myDirectoryEntryList = myEsuApi.listDirectory( myObjectPath , options );
            while( options.getToken() != null && tokencounter < MAXRESULTSLIMIT  )  //recursively populate the ArrayList
        {
                System.out.print( "." );    //display tokens found progress
                myDirectoryEntryList.addAll(  myEsuApi.listDirectory( myObjectPath , options ) );
                tokencounter++;
        }
            System.out.println( );

            ListIterator<DirectoryEntry> it = myDirectoryEntryList.listIterator();
            while ( it.hasNext () )
        {
          System.out.println( it.next() );
          filecounter++;
        }
        }catch( EsuException ee )
        {   rootLogger.error( "Directory listing failed. " + ee + " Atmos Code: " + ee.getAtmosCode() );
        }
        catch(Exception e)
        {   System.out.println("Directory Listing failed. " + e );
        }
        System.out.println();
        System.out.println( tokencounter + " tokens used and " + filecounter + " files listed.");
    }

    private static void displayAtmosObjectByPath( ObjectPath objectpath , EsuApi myEsuApi )
    {
        ObjectInfo myObjectInfo = null;
        try{
            myObjectInfo = myEsuApi.getObjectInfo( objectpath );
            System.out.println( "ObjectInfo as XML: " + myObjectInfo.getRawXml() );
        }
        catch( EsuException ee )
        {   rootLogger.error( "Get Object Info failed. " + ee + " AtmosCode: " + ee.getAtmosCode() );
        }
        catch( Exception e )
        {   System.out.println( "Get Object Info failed. " + e );
        }

        ObjectMetadata myObjectMetadata = null;
        MetadataList myMetadataList  = null;
        Metadata metadata = null;
        try{
            myObjectMetadata = myEsuApi.getAllMetadata( objectpath );
            myMetadataList = myObjectMetadata.getMetadata();
            System.out.println( "Number of Metadata Tags: " + myMetadataList.count() );

          Iterator<Metadata> iterator = myMetadataList.iterator();
          while( iterator.hasNext() )
          {
            metadata = iterator.next();
        System.out.println( metadata.getName() + "," + metadata.getValue() + "," + metadata.isListable());
          }
        }
        catch( EsuException ee )
        {   rootLogger.error( "Getting and listing all Object Metadata failed. " + ee + " AtmosCode: " + ee.getAtmosCode() );
        }
        catch( Exception e )
        {   System.out.println("Getting and listing all Object Metadata failed. " + e );
        }
    }

}// end class

  • « Linux benchmark from command line baselines
  • atmos get »

Published

Nov 27, 2011

Category

java

~443 words

Tags

  • atmos 11
  • display 7
  • java 252
  • path 6