@ Override public Map < String , List < CloudInstance > > getCloudInstances ( CloudInstanceRepository repository ) { DescribeInstancesResult instanceResult ; if ( null == settings . getFilters ( ) || settings . getFilters ( ) . isEmpty ( ) ) { instanceResult = ec2Client . describeInstances ( ) ; } else { instanceResult = ec2Client . describeInstances ( buildFilterRequest ( settings . getFilters ( ) ) ) ; } DescribeAutoScalingInstancesResult autoScaleResult = autoScalingClient . describeAutoScalingInstances ( ) ; List < AutoScalingInstanceDetails > autoScalingInstanceDetails = autoScaleResult . getAutoScalingInstances ( ) ; Map < String , String > autoScaleMap = new HashMap <> ( ) ; for ( AutoScalingInstanceDetails ai : autoScalingInstanceDetails ) { autoScaleMap . put ( ai . getInstanceId ( ) , ai . getAutoScalingGroupName ( ) ) ; } Map < String , List < Instance > > ownerInstanceMap = new HashMap <> ( ) ; List < Instance > instanceList = new ArrayList <> ( ) ; List < Reservation > reservations = instanceResult . getReservations ( ) ; for ( Reservation currRes : reservations ) { List < Instance > currInstanceList = currRes . getInstances ( ) ; if ( CollectionUtils . isEmpty ( ownerInstanceMap . get ( currRes . getOwnerId ( ) ) ) ) { ownerInstanceMap . put ( currRes . getOwnerId ( ) , currRes . getInstances ( ) ) ; } else { ownerInstanceMap . get ( currRes . getOwnerId ( ) ) . addAll ( currRes . getInstances ( ) ) ; } instanceList . addAll ( currInstanceList ) ; } Map < String , List < CloudInstance > > returnList = new HashMap <> ( ) ; int i = 0 ; for ( String acct : ownerInstanceMap . keySet ( ) ) { ArrayList < CloudInstance > rawDataList = new ArrayList <> ( ) ; for ( Instance currInstance : ownerInstanceMap . get ( acct ) ) { i = i + 1 ; LOGGER . info ( "Collecting instance details for " + i + " of " + instanceList . size ( ) + ". Instance ID=" + currInstance . getInstanceId ( ) ) ; CloudInstance object = getCloudInstanceDetails ( acct , currInstance , autoScaleMap , repository ) ; rawDataList . add ( object ) ; } if ( CollectionUtils . isEmpty ( returnList . get ( acct ) ) ) { returnList . put ( acct , rawDataList ) ; } else { returnList . get ( acct ) . addAll ( rawDataList ) ; } } return returnList ; }
Calls AWS API and collects instance details .