List of usage examples for com.amazonaws.services.ec2.model Snapshot getVolumeId
public String getVolumeId()
The ID of the volume that was used to create the snapshot.
From source file:com.pearson.eidetic.driver.threads.subthreads.SnapshotCleaner.java
public Boolean eideticClean(AmazonEC2Client ec2Client) { if (ec2Client == null) { return false; }//w w w . j a v a 2s . c om //See if tag has changed on vol. If 7 days old, delete with all snapshots with old tag. Filter[] filters = new Filter[1]; filters[0] = new Filter().withName("tag-key").withValues("Eidetic"); DescribeSnapshotsRequest describeSnapshotRequest = new DescribeSnapshotsRequest().withOwnerIds("self") .withFilters(filters); DescribeSnapshotsResult describeSnapshotsResult = EC2ClientMethods.describeSnapshots(ec2Client, describeSnapshotRequest, numRetries_, maxApiRequestsPerSecond_, uniqueAwsAccountIdentifier_); List<Snapshot> snapshots = describeSnapshotsResult.getSnapshots(); for (Snapshot snapshot : snapshots) { int timeSinceCreation = getDaysBetweenNowAndSnapshot(snapshot); if (timeSinceCreation <= eideticCleanKeepDays_) { continue; } String volId = snapshot.getVolumeId(); Filter[] volfilters = new Filter[1]; volfilters[0] = new Filter().withName("volume-id").withValues(volId); DescribeVolumesRequest describeVolumesRequest = new DescribeVolumesRequest().withFilters(volfilters); DescribeVolumesResult describeVolumeResult = EC2ClientMethods.describeVolumes(ec2Client, describeVolumesRequest, numRetries_, maxApiRequestsPerSecond_, uniqueAwsAccountIdentifier_); List<Volume> volumes = describeVolumeResult.getVolumes(); if (!volumes.isEmpty()) { Collection<Tag> voltags; try { voltags = getResourceTags(volumes.get(0)); } catch (Exception e) { logger.info("awsAccountNickname=\"" + uniqueAwsAccountIdentifier_ + "\",Event=\"Error\", Error=\"error getting vol in Amnesia\", Volumes_toString=\"" + volumes.toString() + "\", Snapshot_id=\"" + snapshot.getSnapshotId() + "\", stacktrace=\"" + e.toString() + System.lineSeparator() + StackTrace.getStringFromStackTrace(e) + "\""); continue; } Tag voltag = null; for (Tag tag : voltags) { if ("Eidetic".equals(tag.getKey())) { voltag = tag; break; } } if (voltag == null) { continue; } Collection<Tag> snapshottags = getResourceTags(snapshot); Tag snaptag = null; for (Tag tag : snapshottags) { if ("Eidetic".equals(tag.getKey())) { snaptag = tag; break; } } if (snaptag == null) { continue; } try { //Checks to see if we modified tag, if it is the same tag the tag retain date m if (snaptag.getValue().equals(voltag.getValue())) { continue; } } catch (Exception e) { logger.info("awsAccountNickname=\"" + uniqueAwsAccountIdentifier_ + "\",Event=\"Error\", Error=\"error comparing vol and snapshot tag values\", Volume_id=\"" + volumes.get(0).getVolumeId() + ", Snapshot_id=\"" + snapshot.getSnapshotId() + "\", stacktrace=\"" + e.toString() + System.lineSeparator() + StackTrace.getStringFromStackTrace(e) + "\""); continue; } try { deleteSnapshot(ec2Client, snapshot, numRetries_, maxApiRequestsPerSecond_, uniqueAwsAccountIdentifier_); } catch (Exception e) { logger.error("awsAccountNickname=\"" + uniqueAwsAccountIdentifier_ + "\",Event=\"Error\", Error=\"error deleting snapshot\", Snapshot_id=\"" + snapshot.getSnapshotId() + "\", stacktrace=\"" + e.toString() + System.lineSeparator() + StackTrace.getStringFromStackTrace(e) + "\""); } } else { //Volume doesn't exist if (timeSinceCreation > eideticCleanKeepDays_) { //See if old vol still exists. If not, if snap is $eideticCleanKeepDays_ days old, delete. try { deleteSnapshot(ec2Client, snapshot, numRetries_, maxApiRequestsPerSecond_, uniqueAwsAccountIdentifier_); } catch (Exception e) { logger.error("awsAccountNickname=\"" + uniqueAwsAccountIdentifier_ + "\",Event=\"Error\", Error=\"error deleting snapshot\", Snapshot_id=\"" + snapshot.getSnapshotId() + "\", stacktrace=\"" + e.toString() + System.lineSeparator() + StackTrace.getStringFromStackTrace(e) + "\""); } } } } filters = new Filter[1]; filters[0] = new Filter().withName("tag-key").withValues("Eidetic-CopySnapshot"); describeSnapshotRequest = new DescribeSnapshotsRequest().withOwnerIds("self").withFilters(filters); describeSnapshotsResult = EC2ClientMethods.describeSnapshots(ec2Client, describeSnapshotRequest, numRetries_, maxApiRequestsPerSecond_, uniqueAwsAccountIdentifier_); snapshots = describeSnapshotsResult.getSnapshots(); for (Snapshot snapshot : snapshots) { int timeSinceCreation = getDaysBetweenNowAndSnapshot(snapshot); if (timeSinceCreation <= eideticCleanKeepDays_) { continue; } try { deleteSnapshot(ec2Client, snapshot, numRetries_, maxApiRequestsPerSecond_, uniqueAwsAccountIdentifier_); } catch (Exception e) { logger.error("awsAccountNickname=\"" + uniqueAwsAccountIdentifier_ + "\",Event=\"Error\", Error=\"error deleting snapshot\", Snapshot_id=\"" + snapshot.getSnapshotId() + "\", stacktrace=\"" + e.toString() + System.lineSeparator() + StackTrace.getStringFromStackTrace(e) + "\""); } } return true; }
From source file:com.pearson.eidetic.driver.threads.subthreads.SnapshotCreationTime.java
public void addCreationComplete(AmazonEC2Client ec2Client) { try {// w w w . j a v a2 s. co m Filter[] filters3 = new Filter[2]; filters3[0] = new Filter().withName("tag-key").withValues("CreationPending"); filters3[1] = new Filter().withName("status").withValues("completed"); DescribeSnapshotsRequest describeSnapshotRequest3 = new DescribeSnapshotsRequest().withOwnerIds("self") .withFilters(filters3); DescribeSnapshotsResult describeSnapshotsResult3 = EC2ClientMethods.describeSnapshots(ec2Client, describeSnapshotRequest3, numRetries_, maxApiRequestsPerSecond_, uniqueAwsAccountIdentifier_); ; List<Snapshot> snapshots3 = describeSnapshotsResult3.getSnapshots(); for (Snapshot snapshot : snapshots3) { try { Collection<Tag> tags = getResourceTags(snapshot); Tag deleteTag = null; for (Tag tag : tags) { if ("CreationPending".equals(tag.getKey())) { deleteTag = tag; tags.remove(tag); break; } } if (deleteTag == null) { continue; } DeleteTagsRequest deleteTagsRequest = new DeleteTagsRequest() .withResources(snapshot.getSnapshotId()).withTags(deleteTag); EC2ClientMethods.deleteTags(ec2Client, deleteTagsRequest, numRetries_, maxApiRequestsPerSecond_, uniqueAwsAccountIdentifier_); String time = Integer.toString(getMinutesBetweenNowAndSnapshot(snapshot)); logger.info("awsAccountNickname=\"" + uniqueAwsAccountIdentifier_ + "\",Event=\"Snapshot_Creation_Time\", Volume_id=\"" + snapshot.getVolumeId() + "\", Snapshot_id=\"" + snapshot.getSnapshotId() + "\", TotalCreationTime=\"" + time.toString() + "\""); Tag tag = new Tag("CreationComplete", time); tags.add(tag); setResourceTags(ec2Client, snapshot, tags, numRetries_, maxApiRequestsPerSecond_, uniqueAwsAccountIdentifier_); } catch (Exception e) { logger.error("awsAccountNickname=\"" + uniqueAwsAccountIdentifier_ + "\",Event=\"Error\", Error=\"error adding tags to snapshot\", Snapshot_id=\"" + snapshot.getSnapshotId() + "\", stacktrace=\"" + e.toString() + System.lineSeparator() + StackTrace.getStringFromStackTrace(e) + "\""); } } } catch (Exception e) { logger.info("awsAccountNickname=\"" + uniqueAwsAccountIdentifier_ + "\",Event=\"Error\", Error=\"error in addCreationComplete\", stacktrace=\"" + e.toString() + System.lineSeparator() + StackTrace.getStringFromStackTrace(e) + "\""); } }
From source file:com.pearson.eidetic.driver.threads.subthreads.SnapshotVolumeNoTime.java
public boolean snapshotCreation(AmazonEC2Client ec2Client, Volume vol, String period, Date date) { if ((date == null) || (ec2Client == null) || (vol == null) || (period == null)) { return false; }//from w ww. ja v a 2 s.com try { if ("day".equalsIgnoreCase(period)) { } else if ("hour".equalsIgnoreCase(period)) { } else if ("week".equalsIgnoreCase(period)) { } else if ("month".equalsIgnoreCase(period)) { } else { logger.error("awsAccountNickname=\"" + uniqueAwsAccountIdentifier_ + "\",Event=Error, Error=\"Malformed Eidetic Tag\", Volume_id=\"" + vol.getVolumeId() + "\""); return false; } Collection<Tag> tags_volume = getResourceTags(vol); String volumeAttachmentInstance = "none"; try { volumeAttachmentInstance = vol.getAttachments().get(0).getInstanceId(); } catch (Exception e) { logger.debug("awsAccountNickname=\"" + uniqueAwsAccountIdentifier_ + "\",Volume not attached to instance: " + vol.getVolumeId()); } String description = period + "_snapshot " + vol.getVolumeId() + " by Eidetic at " + date.toString() + ". Volume attached to " + volumeAttachmentInstance; Snapshot current_snap; try { current_snap = createSnapshotOfVolume(ec2Client, vol, description, numRetries_, maxApiRequestsPerSecond_, uniqueAwsAccountIdentifier_); } catch (Exception e) { logger.info("awsAccountNickname=\"" + uniqueAwsAccountIdentifier_ + "\",Event=\"Error\", Error=\"error creating snapshot from volume\", Volume_id=\"" + vol.getVolumeId() + "\", stacktrace=\"" + e.toString() + System.lineSeparator() + StackTrace.getStringFromStackTrace(e) + "\""); return false; } try { setResourceTags(ec2Client, current_snap, tags_volume, numRetries_, maxApiRequestsPerSecond_, uniqueAwsAccountIdentifier_); } catch (Exception e) { logger.error("awsAccountNickname=\"" + uniqueAwsAccountIdentifier_ + "\",Event\"Error\", Error=\"error adding tags to snapshot\", Snapshot_id=\"" + current_snap.getVolumeId() + "\", stacktrace=\"" + e.toString() + System.lineSeparator() + StackTrace.getStringFromStackTrace(e) + "\""); return false; } } catch (Exception e) { logger.error("awsAccountNickname=\"" + uniqueAwsAccountIdentifier_ + "\",Event=\"Error, Error=\"error in snapshotCreation\", stacktrace=\"" + e.toString() + System.lineSeparator() + StackTrace.getStringFromStackTrace(e) + "\""); return false; } return true; }
From source file:com.pearson.eidetic.driver.threads.subthreads.SnapshotVolumeSync.java
public boolean snapshotCreation(AmazonEC2Client ec2Client, Volume vol, Date date) { if ((date == null) || (ec2Client == null) || (vol == null)) { return false; }/* w ww. j av a2 s . c o m*/ try { Collection<Tag> tags_volume = getResourceTags(vol); String volumeAttachmentInstance = "none"; try { volumeAttachmentInstance = vol.getAttachments().get(0).getInstanceId(); } catch (Exception e) { logger.debug("Volume not attached to instance: " + vol.getVolumeId()); } String description; if (Validator_) { description = "sync_snapshot " + vol.getVolumeId() + " called by Eidetic Validator Synchronizer at " + date.toString() + ". Volume attached to " + volumeAttachmentInstance; } else { description = "sync_snapshot " + vol.getVolumeId() + " by Eidetic Synchronizer at " + date.toString() + ". Volume attached to " + volumeAttachmentInstance; } Snapshot current_snap; try { current_snap = createSnapshotOfVolume(ec2Client, vol, description, numRetries_, maxApiRequestsPerSecond_, uniqueAwsAccountIdentifier_); } catch (Exception e) { logger.error("awsAccountId=\"" + uniqueAwsAccountIdentifier_ + "\",Event=Error, Error=\"Malformed Eidetic Tag\", Volume_id=\"" + vol.getVolumeId() + "\", stacktrace=\"" + e.toString() + System.lineSeparator() + StackTrace.getStringFromStackTrace(e) + "\""); return false; } try { setResourceTags(ec2Client, current_snap, tags_volume, numRetries_, maxApiRequestsPerSecond_, uniqueAwsAccountIdentifier_); } catch (Exception e) { logger.error("awsAccountId=\"" + uniqueAwsAccountIdentifier_ + "\",Event\"Error\", Error=\"error adding tags to snapshot\", Snapshot_id=\"" + current_snap.getVolumeId() + "\", stacktrace=\"" + e.toString() + System.lineSeparator() + StackTrace.getStringFromStackTrace(e) + "\""); return false; } } catch (Exception e) { logger.error("awsAccountId=\"" + uniqueAwsAccountIdentifier_ + "\",Event=\"Error, Error=\"error in snapshotCreation\", stacktrace=\"" + e.toString() + System.lineSeparator() + StackTrace.getStringFromStackTrace(e) + "\""); return false; } return true; }
From source file:com.pearson.eidetic.driver.threads.subthreads.SnapshotVolumeSyncValidator.java
public boolean snapshotCreation(AmazonEC2Client ec2Client, Volume vol, Date date) { if ((date == null) || (ec2Client == null) || (vol == null)) { return false; }//from ww w. ja va2s . co m try { Collection<Tag> tags_volume = getResourceTags(vol); String volumeAttachmentInstance = "none"; try { volumeAttachmentInstance = vol.getAttachments().get(0).getInstanceId(); } catch (Exception e) { logger.debug("Volume not attached to instance: " + vol.getVolumeId()); } String description = "sync_snapshot " + vol.getVolumeId() + " by Eidetic Synchronizer at " + date.toString() + ". Volume attached to " + volumeAttachmentInstance; Snapshot current_snap; try { current_snap = createSnapshotOfVolume(ec2Client, vol, description, numRetries_, maxApiRequestsPerSecond_, uniqueAwsAccountIdentifier_); } catch (Exception e) { logger.error("awsAccountId=\"" + uniqueAwsAccountIdentifier_ + "\",Event=Error, Error=\"Malformed Eidetic Tag\", Volume_id=\"" + vol.getVolumeId() + "\", stacktrace=\"" + e.toString() + System.lineSeparator() + StackTrace.getStringFromStackTrace(e) + "\""); return false; } try { setResourceTags(ec2Client, current_snap, tags_volume, numRetries_, maxApiRequestsPerSecond_, uniqueAwsAccountIdentifier_); } catch (Exception e) { logger.error("awsAccountId=\"" + uniqueAwsAccountIdentifier_ + "\",Event\"Error\", Error=\"error adding tags to snapshot\", Snapshot_id=\"" + current_snap.getVolumeId() + "\", stacktrace=\"" + e.toString() + System.lineSeparator() + StackTrace.getStringFromStackTrace(e) + "\""); return false; } } catch (Exception e) { logger.error("awsAccountId=\"" + uniqueAwsAccountIdentifier_ + "\",Event=\"Error, Error=\"error in snapshotCreation\", stacktrace=\"" + e.toString() + System.lineSeparator() + StackTrace.getStringFromStackTrace(e) + "\""); return false; } return true; }
From source file:com.pearson.eidetic.driver.threads.subthreads.SnapshotVolumeTime.java
public boolean snapshotCreation(AmazonEC2Client ec2Client, Volume vol, String period, Date date) { if ((date == null) | (ec2Client == null) | (vol == null) | (period == null)) { return false; }// w w w .j ava 2 s.c om try { if ("day".equalsIgnoreCase(period)) { } else if ("hour".equalsIgnoreCase(period)) { } else if ("week".equalsIgnoreCase(period)) { } else if ("month".equalsIgnoreCase(period)) { } else { logger.error("awsAccountNickname=\"" + uniqueAwsAccountIdentifier_ + "\",Event=Error, Error=\"Malformed Eidetic Tag\", Volume_id=\"" + vol.getVolumeId() + "\""); return false; } Collection<Tag> tags_volume = getResourceTags(vol); String volumeAttachmentInstance = "none"; try { volumeAttachmentInstance = vol.getAttachments().get(0).getInstanceId(); } catch (Exception e) { logger.debug("Volume not attached to instance: " + vol.getVolumeId()); } String description = period + "_snapshot " + vol.getVolumeId() + " by Eidetic at " + date.toString() + ". Volume attached to " + volumeAttachmentInstance; Snapshot current_snap; try { current_snap = createSnapshotOfVolume(ec2Client, vol, description, numRetries_, maxApiRequestsPerSecond_, uniqueAwsAccountIdentifier_); } catch (Exception e) { logger.error("awsAccountNickname=\"" + uniqueAwsAccountIdentifier_ + "\",Event=Error, Error=\"Malformed Eidetic Tag\", Volume_id=\"" + vol.getVolumeId() + "\", stacktrace=\"" + e.toString() + System.lineSeparator() + StackTrace.getStringFromStackTrace(e) + "\""); return false; } try { setResourceTags(ec2Client, current_snap, tags_volume, numRetries_, maxApiRequestsPerSecond_, uniqueAwsAccountIdentifier_); } catch (Exception e) { logger.error("awsAccountNickname=\"" + uniqueAwsAccountIdentifier_ + "\",Event\"Error\", Error=\"error adding tags to snapshot\", Snapshot_id=\"" + current_snap.getVolumeId() + "\", stacktrace=\"" + e.toString() + System.lineSeparator() + StackTrace.getStringFromStackTrace(e) + "\""); return false; } } catch (Exception e) { logger.error("awsAccountNickname=\"" + uniqueAwsAccountIdentifier_ + "\",Event=\"Error, Error=\"error in snapshotCreation\", stacktrace=\"" + e.toString() + System.lineSeparator() + StackTrace.getStringFromStackTrace(e) + "\""); return false; } return true; }