@Override public int hashCode() { final int prime = 31; int hashCode = 1; hashCode = prime * hashCode + ((getAttachments() == null) ? 0 : getAttachments().hashCode()); hashCode = prime * hashCode + ((getAvailabilityZone() == null) ? 0 : getAvailabilityZone().hashCode()); hashCode = prime * hashCode + ((getCreateTime() == null) ? 0 : getCreateTime().hashCode()); hashCode = prime * hashCode + ((getEncrypted() == null) ? 0 : getEncrypted().hashCode()); hashCode = prime * hashCode + ((getKmsKeyId() == null) ? 0 : getKmsKeyId().hashCode()); hashCode = prime * hashCode + ((getSize() == null) ? 0 : getSize().hashCode()); hashCode = prime * hashCode + ((getSnapshotId() == null) ? 0 : getSnapshotId().hashCode()); hashCode = prime * hashCode + ((getState() == null) ? 0 : getState().hashCode()); hashCode = prime * hashCode + ((getVolumeId() == null) ? 0 : getVolumeId().hashCode()); hashCode = prime * hashCode + ((getIops() == null) ? 0 : getIops().hashCode()); hashCode = prime * hashCode + ((getTags() == null) ? 0 : getTags().hashCode()); hashCode = prime * hashCode + ((getVolumeType() == null) ? 0 : getVolumeType().hashCode()); return hashCode; }
public Volume unmarshall(StaxUnmarshallerContext context) throws Exception { Volume volume = new Volume(); int originalDepth = context.getCurrentDepth(); int targetDepth = originalDepth + 1; volume.withAttachments(new ArrayList<VolumeAttachment>()); continue; volume.withAttachments(VolumeAttachmentStaxUnmarshaller.getInstance().unmarshall(context)); continue; volume.setAvailabilityZone(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; volume.setCreateTime(DateStaxUnmarshallerFactory.getInstance("iso8601").unmarshall(context)); continue; volume.setEncrypted(BooleanStaxUnmarshaller.getInstance().unmarshall(context)); continue; volume.setKmsKeyId(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; volume.setSize(IntegerStaxUnmarshaller.getInstance().unmarshall(context)); continue; volume.setSnapshotId(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; volume.setState(StringStaxUnmarshaller.getInstance().unmarshall(context));
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (obj instanceof CreateVolumeResult == false) return false; CreateVolumeResult other = (CreateVolumeResult) obj; if (other.getVolume() == null ^ this.getVolume() == null) return false; if (other.getVolume() != null && other.getVolume().equals(this.getVolume()) == false) return false; return true; }
public Volume unmarshall(StaxUnmarshallerContext context) throws Exception { Volume volume = new Volume(); int originalDepth = context.getCurrentDepth(); int targetDepth = originalDepth + 1; volume.setVolumeId(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; volume.setSize(IntegerStaxUnmarshaller.getInstance().unmarshall(context)); continue; volume.setSnapshotId(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; volume.setAvailabilityZone(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; volume.setState(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; volume.setCreateTime(DateStaxUnmarshaller.getInstance().unmarshall(context)); continue; volume.getAttachments().add(VolumeAttachmentStaxUnmarshaller.getInstance().unmarshall(context)); continue; volume.getTags().add(TagStaxUnmarshaller.getInstance().unmarshall(context)); continue; volume.setVolumeType(StringStaxUnmarshaller.getInstance().unmarshall(context));
DescribeVolumesRequest dvs = new DescribeVolumesRequest(); ArrayList<String> volumeIds = new ArrayList<String>(); volumeIds.add(createVolumeResult.getVolume().getVolumeId()); DescribeVolumesResult dvsresult = ec2.describeVolumes(dvs); running = "available".equals(dvsresult.getVolumes().get(0).getState()); System.out.println(dvsresult.getVolumes().get(0).getState()); if(! running) { try { .withInstanceId(instanceId) .withDevice("/dev/sda2") .withVolumeId(createVolumeResult.getVolume().getVolumeId());
/** * * @param availabilityZone - * @param size - size (in Gb) of the volume to be created. Must be larger than snapshot if used * @param snapshotId - optional if you want to create from a snapshot * @param ec2Client * @return volumeId - the id of the newly created volume */ public String createEbsVolume(String availabilityZone, int size, String snapshotId, AmazonEC2 ec2Client) { CreateVolumeRequest request = new CreateVolumeRequest() .withAvailabilityZone(availabilityZone) .withSize(size); // Only create from a snapshot if the snapshotId is not null, otherwise make new volume if (snapshotId != null && !snapshotId.equals("")) { request = request.withSnapshotId(snapshotId); } CreateVolumeResult result = ec2Client.createVolume(request); String volumeId = result.getVolume().getVolumeId(); return volumeId; }
/** * Information about the volume attachments. * <p> * Returns a reference to this object so that method calls can be chained together. * * @param attachments Information about the volume attachments. * * @return A reference to this updated object so that method calls can be chained * together. */ public Volume withAttachments(VolumeAttachment... attachments) { if (getAttachments() == null) setAttachments(new java.util.ArrayList<VolumeAttachment>(attachments.length)); for (VolumeAttachment value : attachments) { getAttachments().add(value); } return this; }
/** * Return true if this volume is attached to anything. ie if volume.getAttachments() is not empty */ private boolean isAttached(String volumeId) { Volume volume = getVolume(volumeId); List<VolumeAttachment> attachments = volume.getAttachments(); return !isEmpty(attachments); }
private String waitForVolumeState(String volumeId, VolumeState desiredState, long timeout) { VolumeState currentState = null; Stopwatch sw = createStarted(); while (!desiredState.equals(currentState)) { checkedWait(sw, timeout, SLEEP_MILLIS); DescribeVolumesRequest dvr = new DescribeVolumesRequest(); dvr.setVolumeIds(asList(volumeId)); DescribeVolumesResult result = client.describeVolumes(dvr); Volume volume = getSingleElement(result.getVolumes()); currentState = VolumeState.fromValue(volume.getState()); } return volumeId; }
@Override public String createVolume(CreateVolumeRequest request) { checkNotNull(request, "request"); com.amazonaws.services.ec2.model.CreateVolumeRequest cvr = new com.amazonaws.services.ec2.model.CreateVolumeRequest(); cvr.setAvailabilityZone(request.getZone()); cvr.setSize(request.getSize()); cvr.setVolumeType(request.getType()); String volumeId = client.createVolume(cvr).getVolume().getVolumeId(); return waitForVolumeState(volumeId, request.getRequiredState(), request.getTimeout()); }
/** * Wait until the first attachment has the desired state */ private TimedInterval waitForAttachmentState(String volumeId, VolumeAttachmentState desiredState, long timeout) { Stopwatch sw = createStarted(); Volume volume = getVolume(volumeId); List<VolumeAttachment> attachments = volume.getAttachments(); VolumeAttachment first = getSingleElement(attachments); VolumeAttachmentState currentState = VolumeAttachmentState.fromValue(first.getState()); while (!currentState.equals(desiredState)) { checkedWait(sw, timeout, SLEEP_MILLIS); volume = getVolume(volumeId); attachments = volume.getAttachments(); first = getSingleElement(attachments); currentState = VolumeAttachmentState.fromValue(first.getState()); } return TimedInterval.build(sw); }
return false; Volume other = (Volume) obj; if (other.getAttachments() == null ^ this.getAttachments() == null) return false; if (other.getAttachments() != null && other.getAttachments().equals(this.getAttachments()) == false) return false; if (other.getAvailabilityZone() == null ^ this.getAvailabilityZone() == null) return false; if (other.getAvailabilityZone() != null && other.getAvailabilityZone().equals(this.getAvailabilityZone()) == false) return false; if (other.getCreateTime() == null ^ this.getCreateTime() == null) return false; if (other.getCreateTime() != null && other.getCreateTime().equals(this.getCreateTime()) == false) return false; if (other.getEncrypted() == null ^ this.getEncrypted() == null) return false; if (other.getEncrypted() != null && other.getEncrypted().equals(this.getEncrypted()) == false) return false; if (other.getKmsKeyId() == null ^ this.getKmsKeyId() == null) return false; if (other.getKmsKeyId() != null && other.getKmsKeyId().equals(this.getKmsKeyId()) == false) return false; if (other.getSize() == null ^ this.getSize() == null) return false; if (other.getSize() != null && other.getSize().equals(this.getSize()) == false) return false; if (other.getSnapshotId() == null ^ this.getSnapshotId() == null) return false; if (other.getSnapshotId() != null && other.getSnapshotId().equals(this.getSnapshotId()) == false)
public Volume unmarshall(StaxUnmarshallerContext context) throws Exception { Volume volume = new Volume(); int originalDepth = context.getCurrentDepth(); int targetDepth = originalDepth + 1; volume.withAttachments(new ArrayList<VolumeAttachment>()); continue; volume.withAttachments(VolumeAttachmentStaxUnmarshaller.getInstance().unmarshall(context)); continue; volume.setAvailabilityZone(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; volume.setCreateTime(DateStaxUnmarshallerFactory.getInstance("iso8601").unmarshall(context)); continue; volume.setEncrypted(BooleanStaxUnmarshaller.getInstance().unmarshall(context)); continue; volume.setKmsKeyId(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; volume.setSize(IntegerStaxUnmarshaller.getInstance().unmarshall(context)); continue; volume.setSnapshotId(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; volume.setState(StringStaxUnmarshaller.getInstance().unmarshall(context));
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (obj instanceof CreateVolumeResult == false) return false; CreateVolumeResult other = (CreateVolumeResult)obj; if (other.getVolume() == null ^ this.getVolume() == null) return false; if (other.getVolume() != null && other.getVolume().equals(this.getVolume()) == false) return false; return true; }
StringBuilder sb = new StringBuilder(); sb.append("{"); if (getAttachments() != null) sb.append("Attachments: ").append(getAttachments()).append(","); if (getAvailabilityZone() != null) sb.append("AvailabilityZone: ").append(getAvailabilityZone()).append(","); if (getCreateTime() != null) sb.append("CreateTime: ").append(getCreateTime()).append(","); if (getEncrypted() != null) sb.append("Encrypted: ").append(getEncrypted()).append(","); if (getKmsKeyId() != null) sb.append("KmsKeyId: ").append(getKmsKeyId()).append(","); if (getSize() != null) sb.append("Size: ").append(getSize()).append(","); if (getSnapshotId() != null) sb.append("SnapshotId: ").append(getSnapshotId()).append(","); if (getState() != null) sb.append("State: ").append(getState()).append(","); if (getVolumeId() != null) sb.append("VolumeId: ").append(getVolumeId()).append(","); if (getIops() != null) sb.append("Iops: ").append(getIops()).append(","); if (getTags() != null) sb.append("Tags: ").append(getTags()).append(","); if (getVolumeType() != null) sb.append("VolumeType: ").append(getVolumeType()); sb.append("}"); return sb.toString();
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (obj instanceof CreateVolumeResult == false) return false; CreateVolumeResult other = (CreateVolumeResult) obj; if (other.getVolume() == null ^ this.getVolume() == null) return false; if (other.getVolume() != null && other.getVolume().equals(this.getVolume()) == false) return false; return true; }
@Override public int hashCode() { final int prime = 31; int hashCode = 1; hashCode = prime * hashCode + ((getVolumeId() == null) ? 0 : getVolumeId().hashCode()); hashCode = prime * hashCode + ((getSize() == null) ? 0 : getSize().hashCode()); hashCode = prime * hashCode + ((getSnapshotId() == null) ? 0 : getSnapshotId().hashCode()); hashCode = prime * hashCode + ((getAvailabilityZone() == null) ? 0 : getAvailabilityZone().hashCode()); hashCode = prime * hashCode + ((getState() == null) ? 0 : getState().hashCode()); hashCode = prime * hashCode + ((getCreateTime() == null) ? 0 : getCreateTime().hashCode()); hashCode = prime * hashCode + ((getAttachments() == null) ? 0 : getAttachments().hashCode()); hashCode = prime * hashCode + ((getTags() == null) ? 0 : getTags().hashCode()); hashCode = prime * hashCode + ((getVolumeType() == null) ? 0 : getVolumeType().hashCode()); hashCode = prime * hashCode + ((getIops() == null) ? 0 : getIops().hashCode()); hashCode = prime * hashCode + ((isEncrypted() == null) ? 0 : isEncrypted().hashCode()); hashCode = prime * hashCode + ((getKmsKeyId() == null) ? 0 : getKmsKeyId().hashCode()); return hashCode; }
Volume other = (Volume)obj; if (other.getVolumeId() == null ^ this.getVolumeId() == null) return false; if (other.getVolumeId() != null && other.getVolumeId().equals(this.getVolumeId()) == false) return false; if (other.getSize() == null ^ this.getSize() == null) return false; if (other.getSize() != null && other.getSize().equals(this.getSize()) == false) return false; if (other.getSnapshotId() == null ^ this.getSnapshotId() == null) return false; if (other.getSnapshotId() != null && other.getSnapshotId().equals(this.getSnapshotId()) == false) return false; if (other.getAvailabilityZone() == null ^ this.getAvailabilityZone() == null) return false; if (other.getAvailabilityZone() != null && other.getAvailabilityZone().equals(this.getAvailabilityZone()) == false) return false; if (other.getState() == null ^ this.getState() == null) return false; if (other.getState() != null && other.getState().equals(this.getState()) == false) return false; if (other.getCreateTime() == null ^ this.getCreateTime() == null) return false; if (other.getCreateTime() != null && other.getCreateTime().equals(this.getCreateTime()) == false) return false; if (other.getAttachments() == null ^ this.getAttachments() == null) return false; if (other.getAttachments() != null && other.getAttachments().equals(this.getAttachments()) == false) return false; if (other.getTags() == null ^ this.getTags() == null) return false; if (other.getTags() != null && other.getTags().equals(this.getTags()) == false) return false; if (other.getVolumeType() == null ^ this.getVolumeType() == null) return false; if (other.getVolumeType() != null && other.getVolumeType().equals(this.getVolumeType()) == false) return false; if (other.getIops() == null ^ this.getIops() == null) return false; if (other.getIops() != null && other.getIops().equals(this.getIops()) == false) return false; if (other.isEncrypted() == null ^ this.isEncrypted() == null) return false; if (other.isEncrypted() != null && other.isEncrypted().equals(this.isEncrypted()) == false) return false; if (other.getKmsKeyId() == null ^ this.getKmsKeyId() == null) return false; if (other.getKmsKeyId() != null && other.getKmsKeyId().equals(this.getKmsKeyId()) == false) return false; return true;
/** * Returns a string representation of this object; useful for testing and * debugging. * * @return A string representation of this object. * * @see java.lang.Object#toString() */ @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("{"); if (getVolumeId() != null) sb.append("VolumeId: " + getVolumeId() + ","); if (getSize() != null) sb.append("Size: " + getSize() + ","); if (getSnapshotId() != null) sb.append("SnapshotId: " + getSnapshotId() + ","); if (getAvailabilityZone() != null) sb.append("AvailabilityZone: " + getAvailabilityZone() + ","); if (getState() != null) sb.append("State: " + getState() + ","); if (getCreateTime() != null) sb.append("CreateTime: " + getCreateTime() + ","); if (getAttachments() != null) sb.append("Attachments: " + getAttachments() + ","); if (getTags() != null) sb.append("Tags: " + getTags() + ","); if (getVolumeType() != null) sb.append("VolumeType: " + getVolumeType() + ","); if (getIops() != null) sb.append("Iops: " + getIops() + ","); if (isEncrypted() != null) sb.append("Encrypted: " + isEncrypted() + ","); if (getKmsKeyId() != null) sb.append("KmsKeyId: " + getKmsKeyId() ); sb.append("}"); return sb.toString(); }
@Override public int hashCode() { final int prime = 31; int hashCode = 1; hashCode = prime * hashCode + ((getAttachments() == null) ? 0 : getAttachments().hashCode()); hashCode = prime * hashCode + ((getAvailabilityZone() == null) ? 0 : getAvailabilityZone().hashCode()); hashCode = prime * hashCode + ((getCreateTime() == null) ? 0 : getCreateTime().hashCode()); hashCode = prime * hashCode + ((getEncrypted() == null) ? 0 : getEncrypted().hashCode()); hashCode = prime * hashCode + ((getKmsKeyId() == null) ? 0 : getKmsKeyId().hashCode()); hashCode = prime * hashCode + ((getSize() == null) ? 0 : getSize().hashCode()); hashCode = prime * hashCode + ((getSnapshotId() == null) ? 0 : getSnapshotId().hashCode()); hashCode = prime * hashCode + ((getState() == null) ? 0 : getState().hashCode()); hashCode = prime * hashCode + ((getVolumeId() == null) ? 0 : getVolumeId().hashCode()); hashCode = prime * hashCode + ((getIops() == null) ? 0 : getIops().hashCode()); hashCode = prime * hashCode + ((getTags() == null) ? 0 : getTags().hashCode()); hashCode = prime * hashCode + ((getVolumeType() == null) ? 0 : getVolumeType().hashCode()); return hashCode; }