john pfeiffer
  • Home
  • Categories
  • Tags
  • Archives

Report 0.6 StorageReport

//2012-10-23 johnpfeiffer  requires StorageGatewayDAO , StorageGateway, NetworkAccountDAO, NetworkAccount


import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.ListIterator;
import java.util.Properties;

class StorageReport
{
    private String dbms;
    private String host;
    private String port;
    private String user;
    private String password;
    ArrayList <String> results;
    ArrayList <String> authenticationReport;
    private int storageGatewayCount;

    StorageReport( ) throws SQLException
    {
        Connection c = null;
        results = new ArrayList <String> ();
        try{
            this.dbms = "mysql";
            this.host = "data1.SERVER.rds.amazonaws.com";           this.port = "3306";             this.user = "USERNAME";         this.password = "PASSWORD";

            c = this.getConnection();

            NetworkAccountDAO networkAccountDAO = new NetworkAccountDAO( c );
            ArrayList <NetworkAccount> networkAccountList = networkAccountDAO.getList();
            System.out.println( "Accounts Found: " + networkAccountList.size() );

            Collections.sort( networkAccountList , NetworkAccount.COMPARE_BY_CREATEDATETIME );
            ListIterator <NetworkAccount> it = networkAccountList.listIterator();

            NetworkAccount current = null;
            authenticationReport = new ArrayList <String>();
            while( it.hasNext() )
            {
                current = it.next();
                if( current.isExternalAuthenticationEnabled() )
                {
                    authenticationReport.add( current.getCreateDatetime() + "," + current.getName() + "," + current.loginUrl() + "," + current.getOid() + ",deleted="
                            + current.isDeleted() );
                }
            }

/*
            StorageGatewayDAO sgw = new StorageGatewayDAO( c );
            ArrayList <StorageGateway> sgwList = sgw.getStorageGatewayList();
            this.storageGatewayCount = sgw.getRowCount();

            results.add( "oid , hash , address , connected , lastModified , deviceType , networkAccountOid , storageSizeInMB , creationDate , accountId , accountName ");
            Collections.sort( sgwList , StorageGateway.COMPARE_BY_CREATIONDATE );   //StorageGateway.COMPARE_BY_ADDRESS or COMPARE_BY_LASTMODIFIED

          ListIterator <StorageGateway> it = sgwList.listIterator();
            while ( it.hasNext () )
          {
                StorageGateway temp = it.next();
                String accountOid = temp.getNetworkAccountOid();

                if( temp.isPrivateGateway() )
                {
                    NetworkAccountDAO accountWrapper = new NetworkAccountDAO( c , accountOid );
                    NetworkAccount account = accountWrapper.getNetworkAccount();

                    if( account != null )
                    {       results.add( temp.getStorageGatewayCSV() + " , " + account.getAccountId() + " , " + account.getName()  );
                    }
                }else
                {           results.add(  temp.getStorageGatewayCSV() + " , is a public cloud owned by " + accountOid );
                }
          }
            */

            c.close();
        }finally
        {
            try{
                if( c != null ){        c.close();  }
            }catch( Exception e )
            {}
        }
    }

    ArrayList <String> getAuthenticationReport()
    {
        return authenticationReport;
    }

    protected int getStorageGatewayCount()
    {       return this.storageGatewayCount;
    }

    protected ArrayList <String> get()
    {       return results;
    }


    Connection getConnection() throws SQLException
    {
        DriverManager.registerDriver( new com.mysql.jdbc.Driver() );

        Connection conn = null;
        Properties connectionProps = new Properties();
        connectionProps.put( "user" , this.user );
        connectionProps.put( "password" , this.password );

        if( this.dbms.equals( "mysql" ) )
        {
            conn = DriverManager.getConnection( "jdbc:" + this.dbms + "://" + this.host + ":" + this.port + "/mysql" , connectionProps );

        }else if( this.dbms.equals( "derby" ) )
        {// conn = DriverManager.getConnection( "jdbc:" + this.dbms + ":" + this.dbName + ";create=true", connectionProps );
        }
        return conn;
    }

    /*
    protected Connection getConnection() throws SQLException
    {
        DriverManager.registerDriver( new com.mysql.jdbc.Driver() );

    Connection conn = null;
    Properties connectionProps = new Properties();
    connectionProps.put( "user" , this.user );
    connectionProps.put( "password" , this.password );

    if( this.dbms.equals( "mysql" ) )
    {       conn = DriverManager.getConnection( "jdbc:" + this.dbms + "://" + this.host + ":" + this.port + "/mysql", connectionProps );
    }else if( this.dbms.equals( "derby" ) )
    {//   conn = DriverManager.getConnection( "jdbc:" + this.dbms + ":" + this.dbName + ";create=true", connectionProps );
    }
    return conn;
    }
    */
} //end class

  • « Webdav cadaver
  • Report 0.6 »

Published

Oct 23, 2012

Category

java-servlet

~296 words

Tags

  • 0.6 6
  • java-servlet 61
  • report 14
  • storagereport 1