List of usage examples for com.amazonaws.regions Region getName
public String getName()
From source file:org.zalando.stups.fullstop.plugin.SaveSecurityGroupsPlugin.java
License:Apache License
@Override public void processEvent(final CloudTrailEvent event) { List<String> securityGroupIds = readSecurityGroupIds(event); Region region = getRegion(event); String accountId = getAccountId(event); List<String> instanceIds = getInstanceIds(event); DateTime instanceLaunchTime = new DateTime(getInstanceLaunchTime(event)); String securityGroup = getSecurityGroup(securityGroupIds, region, accountId); String prefix = Paths.get(accountId, region.getName(), instanceLaunchTime.toString("YYYY"), instanceLaunchTime.toString("MM"), instanceLaunchTime.toString("dd")).toString() + "/"; List<String> s3InstanceObjects = listS3Objects(bucketName, prefix); for (String instanceId : instanceIds) { List<String> instanceBuckets = Lists.newArrayList(); for (String s3InstanceObject : s3InstanceObjects) { String s = Paths.get(s3InstanceObject).getFileName().toString(); if (s.startsWith(instanceId)) { instanceBuckets.add(s);/*w w w .j a v a2 s . c o m*/ } } if (instanceBuckets.isEmpty()) { continue; } String instanceBucketNameControlElement = null; DateTime instanceBootTimeControlElement = null; for (String instanceBucket : instanceBuckets) { List<String> currentBucket = Lists.newArrayList( Splitter.on('-').limit(3).trimResults().omitEmptyStrings().split(instanceBucket)); String currentBucketName = currentBucket.get(0) + "-" + currentBucket.get(1); DateTime currentBucketDate = new DateTime(currentBucket.get(2), UTC); //TODO we should use absolute values if (instanceBucketNameControlElement != null || instanceBootTimeControlElement != null) { if (instanceLaunchTime.getMillis() - currentBucketDate.getMillis() < instanceLaunchTime.getMillis() - instanceBootTimeControlElement.getMillis()) { instanceBucketNameControlElement = currentBucketName; instanceBootTimeControlElement = currentBucketDate; } } else { instanceBucketNameControlElement = currentBucketName; instanceBootTimeControlElement = currentBucketDate; } } prefix = prefix + instanceBucketNameControlElement + "-" + instanceBootTimeControlElement; writeToS3(securityGroup, prefix); } }