public Map < String , List < CloudVolumeStorage > > getCloudVolumes ( Map < String , String > instanceToAccountMap ) { Map < String , List < CloudVolumeStorage > > returnMap = new HashMap <> ( ) ; DescribeVolumesResult volumeResult = ec2Client . describeVolumes ( ) ; for ( Volume v : volumeResult . getVolumes ( ) ) { CloudVolumeStorage object = new CloudVolumeStorage ( ) ; for ( VolumeAttachment va : v . getAttachments ( ) ) { object . getAttachInstances ( ) . add ( va . getInstanceId ( ) ) ; } String account = NO_ACCOUNT ; //Get any instance id if any and get corresponding account number if ( ! CollectionUtils . isEmpty ( object . getAttachInstances ( ) ) && ! StringUtils . isEmpty ( instanceToAccountMap . get ( object . getAttachInstances ( ) . get ( 0 ) ) ) ) { account = instanceToAccountMap . get ( object . getAttachInstances ( ) . get ( 0 ) ) ; } object . setAccountNumber ( account ) ; object . setZone ( v . getAvailabilityZone ( ) ) ; object . setAccountNumber ( account ) ; object . setCreationDate ( v . getCreateTime ( ) . getTime ( ) ) ; object . setEncrypted ( v . isEncrypted ( ) ) ; object . setSize ( v . getSize ( ) ) ; object . setStatus ( v . getState ( ) ) ; object . setType ( v . getVolumeType ( ) ) ; object . setVolumeId ( v . getVolumeId ( ) ) ; List < Tag > tags = v . getTags ( ) ; if ( ! CollectionUtils . isEmpty ( tags ) ) { for ( Tag tag : tags ) { NameValue nv = new NameValue ( tag . getKey ( ) , tag . getValue ( ) ) ; object . getTags ( ) . add ( nv ) ; } } if ( CollectionUtils . isEmpty ( returnMap . get ( object . getAccountNumber ( ) ) ) ) { List < CloudVolumeStorage > temp = new ArrayList <> ( ) ; temp . add ( object ) ; returnMap . put ( account , temp ) ; } else { returnMap . get ( account ) . add ( object ) ; } } return returnMap ; }
Returns a map of account number of list of volumes associated with the account