List of usage examples for com.amazonaws.services.ec2.model VolumeAttachment getDevice
public String getDevice()
The device name.
From source file:com.pearson.eidetic.driver.threads.subthreads.TagChecker.java
private List<Volume> checkVolumes(AmazonEC2Client ec2Client, List<Instance> instances) { List<Volume> volumesWithNoTags = new ArrayList(); /*//from w w w .j a v a 2 s . c o m Here is what we have: Instance: -instance.id -> String -instance.blockdevicemapping -> InstanceBlockDeviceMapping -BlockDeviceMapping: --BlockDeviceMapping.deviceName -> String == (/dev/xvdk) --BlockDeviceMapping.getEbs -> EbsInstanceBlockDevice --EbsInstanceBLockDevice: ---EbsInstanceBLockDevice.id - String == (volume.id) For instances Set<HashMap<instance.id,HashMap<deviceName,volume.id>>> Volume: -volume.id -> String -volume.getAttachments -> volumeAttachments -volumeAttachments: --getDevice -> String == (/dev/xvdk) --getInstanceId -> String == instance.id For vols Set<HashMap<instance.id,HashMap<deviceName,volume.id>>> If anything remians in the instance set */ List<Volume> volumes = getEideticVolumes(ec2Client); //if (volumes.isEmpty()) { //return volumesWithNoTags; //} //Set<HashMap<instance.id,HashMap<deviceName,volume.id>>> Set<HashMap<String, HashMap<String, String>>> volumeSet = new HashSet(); for (Volume volume : volumes) { String volumeId = volume.getVolumeId(); List<VolumeAttachment> attachments = volume.getAttachments(); for (VolumeAttachment attach : attachments) { HashMap<String, HashMap<String, String>> setMember = new HashMap(); HashMap<String, String> internalHash = new HashMap(); if (volumeId == null || attach.getDevice() == null || attach.getInstanceId() == null) { continue; } internalHash.put(attach.getDevice(), volumeId); setMember.put(attach.getInstanceId(), internalHash); volumeSet.add(setMember); } } //Set<HashMap<instance.id,HashMap<deviceName,volume.id>>> Set<HashMap<String, HashMap<String, String>>> instanceSet = new HashSet(); for (Instance instance : instances) { String instanceId = instance.getInstanceId(); List<InstanceBlockDeviceMapping> blocks = instance.getBlockDeviceMappings(); List<Tag> tags = instance.getTags(); Tag tagz = null; for (Tag t : tags) { if (t.getKey().equalsIgnoreCase("Data")) { tagz = t; break; } } if (tagz == null) { continue; } String[] stringtags = tagz.getValue().split(","); for (String tag : stringtags) { String deviceName; String volumeId; for (InstanceBlockDeviceMapping instanceBlockDeviceMapping : blocks) { deviceName = instanceBlockDeviceMapping.getDeviceName(); if (!deviceName.equalsIgnoreCase(tag)) { continue; } volumeId = instanceBlockDeviceMapping.getEbs().getVolumeId(); HashMap<String, HashMap<String, String>> setMember = new HashMap(); HashMap<String, String> internalHash = new HashMap(); if (volumeId == null | volumeId == null) { continue; } internalHash.put(deviceName, volumeId); setMember.put(instanceId, internalHash); instanceSet.add(setMember); } } } if (instanceSet.isEmpty()) { return volumesWithNoTags; } //Need to validate instanceSet.removeAll(volumeSet); if (instanceSet.isEmpty()) { return volumesWithNoTags; } //Instance keys, to get volumeIds Set<String> volumeIds = new HashSet(); for (HashMap<String, HashMap<String, String>> i : instanceSet) { Set<String> curSet = i.keySet(); for (String s : curSet) { Set<String> dvns = i.get(s).keySet(); for (String dvn : dvns) { if (!volumeIds.contains(dvn)) { volumeIds.add(i.get(s).get(dvn)); } } } } for (String i : volumeIds) { DescribeVolumesRequest describeVolumesRequest = new DescribeVolumesRequest().withVolumeIds(i); DescribeVolumesResult describeVolumeResult = EC2ClientMethods.describeVolumes(ec2Client, describeVolumesRequest, numRetries_, maxApiRequestsPerSecond_, uniqueAwsAccountIdentifier_); Volume volume = null; try { volume = describeVolumeResult.getVolumes().get(0); } catch (Exception e) { logger.error("awsAccountNickname=\"" + uniqueAwsAccountIdentifier_ + "\",Event\"Error\", Error=\"volume id does not exist\", stacktrace=\"" + e.toString() + System.lineSeparator() + StackTrace.getStringFromStackTrace(e) + "\""); } volumesWithNoTags.add(volume); } return volumesWithNoTags; }
From source file:org.xmlsh.aws.util.AWSEC2Command.java
License:BSD License
protected void writeAttachment(VolumeAttachment attachment) throws XMLStreamException { startElement("attachment"); attribute("delete-on-termination", AWSUtil.parseBoolean(attachment.getDeleteOnTermination())); attribute("attach-date", Util.formatXSDateTime(attachment.getAttachTime())); attribute("device", attachment.getDevice()); attribute("instance-id", attachment.getInstanceId()); attribute("volume-id", attachment.getVolumeId()); attribute("state", attachment.getState()); endElement();//from w ww .j av a2 s. co m }