Updated Branches: refs/heads/trunk 1507d9959 -> 4c45b6fe4
WHIRR-721: Improve robustness of volume device detection Project: http://git-wip-us.apache.org/repos/asf/whirr/repo Commit: http://git-wip-us.apache.org/repos/asf/whirr/commit/4c45b6fe Tree: http://git-wip-us.apache.org/repos/asf/whirr/tree/4c45b6fe Diff: http://git-wip-us.apache.org/repos/asf/whirr/diff/4c45b6fe Branch: refs/heads/trunk Commit: 4c45b6fe4a38f90d6e0eb78d7cab6e2cb147025f Parents: 1507d99 Author: Graham Gear <graham.g...@gmail.com> Authored: Fri May 3 08:24:03 2013 +0100 Committer: Graham Gear <graham.g...@gmail.com> Committed: Fri May 3 08:24:03 2013 +0100 ---------------------------------------------------------------------- CHANGES.txt | 2 + .../apache/whirr/service/hadoop/VolumeManager.java | 24 ++++-- .../main/resources/functions/prepare_all_disks.sh | 64 +++++++++------ 3 files changed, 58 insertions(+), 32 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/whirr/blob/4c45b6fe/CHANGES.txt ---------------------------------------------------------------------- diff --git a/CHANGES.txt b/CHANGES.txt index 1006d6a..f3fc5ba 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -6,6 +6,8 @@ Release 0.9.0 (Unreleased Changes) IMPROVEMENTS + WHIRR-721. Improve robustness of volume device detection. (graham) + BUG FIXES Release 0.8.2 - 2013-04-23 http://git-wip-us.apache.org/repos/asf/whirr/blob/4c45b6fe/services/hadoop/src/main/java/org/apache/whirr/service/hadoop/VolumeManager.java ---------------------------------------------------------------------- diff --git a/services/hadoop/src/main/java/org/apache/whirr/service/hadoop/VolumeManager.java b/services/hadoop/src/main/java/org/apache/whirr/service/hadoop/VolumeManager.java index cd73e23..23da91e 100644 --- a/services/hadoop/src/main/java/org/apache/whirr/service/hadoop/VolumeManager.java +++ b/services/hadoop/src/main/java/org/apache/whirr/service/hadoop/VolumeManager.java @@ -18,16 +18,18 @@ package org.apache.whirr.service.hadoop; -import com.google.common.collect.Maps; - import java.util.List; import java.util.Map; +import java.util.SortedSet; +import java.util.TreeSet; import org.apache.whirr.Cluster.Instance; import org.apache.whirr.ClusterSpec; import org.jclouds.compute.domain.Hardware; import org.jclouds.compute.domain.Volume; +import com.google.common.collect.Maps; + public class VolumeManager { public static final String MOUNT_PREFIX = "/data"; @@ -41,12 +43,22 @@ public class VolumeManager { if (hardware != null) { List<? extends Volume> volumes = instance.getNodeMetadata().getHardware().getVolumes(); + boolean foundBootDevice = false; + SortedSet<String> volumeDevicesSansBoot = new TreeSet<String>(); for (Volume volume : volumes) { - if (volume.isBootDevice()) { - continue; + if (!volume.isBootDevice()) { + volumeDevicesSansBoot.add(volume.getDevice()); + } else { + foundBootDevice = true; } - - mappings.put(MOUNT_PREFIX + number++, volume.getDevice()); + } + // if no boot device is reported from the cloud provider (as is sometimes the case) + // assume it is the first in the natural order list of devices + if (!foundBootDevice && !volumeDevicesSansBoot.isEmpty()) { + volumeDevicesSansBoot.remove(volumeDevicesSansBoot.iterator().next()); + } + for (String device : volumeDevicesSansBoot) { + mappings.put(MOUNT_PREFIX + number++, device); } } return mappings; http://git-wip-us.apache.org/repos/asf/whirr/blob/4c45b6fe/services/hadoop/src/main/resources/functions/prepare_all_disks.sh ---------------------------------------------------------------------- diff --git a/services/hadoop/src/main/resources/functions/prepare_all_disks.sh b/services/hadoop/src/main/resources/functions/prepare_all_disks.sh index 1681cf3..e8e5fa6 100644 --- a/services/hadoop/src/main/resources/functions/prepare_all_disks.sh +++ b/services/hadoop/src/main/resources/functions/prepare_all_disks.sh @@ -55,34 +55,46 @@ function prep_disk() { device=$(echo "$device"|sed -e 's/\/sd/\/xvd/') fi - # is device formatted? - if [ $(mountpoint -q -x $device) ]; then - echo "$device is formatted" - else - if which dpkg &> /dev/null; then - apt-get install -y xfsprogs - elif which rpm &> /dev/null; then - yum install -y xfsprogs - fi - echo "warning: ERASING CONTENTS OF $device" - mkfs.xfs -f $device + # match /dev/sd* devices to their Xen VPS equivalents and set device if found + deviceXen=$(echo "$device"|sed -e 's/\/sd/\/xvd/') + if [ ! -e $deviceXen ]; then + # match /dev/sd(.) to a new RHEL 6.1 Xen VPS naming scheme - https://bugzilla.redhat.com/show_bug.cgi?id=729586 + deviceXen=$(echo "$device"|sed -e 's/\/sd./\/xvd/'|xargs -I £ echo "£"$(printf \\$(printf '%03o' $(($(printf "%d\n" \'${device:${#device} - 1})+4)) ))) fi - # is device mounted? - mount | grep -q $device - if [ $? == 0 ]; then - echo "$device is mounted" - if [ ! -d $mount ]; then - echo "Symlinking to $mount" - ln -s $(grep $device /proc/mounts | awk '{print $2}') $mount - fi - else - echo "Mounting $device on $mount" - if [ ! -e $mount ]; then - mkdir $mount + if [ -e $deviceXen ]; then + device=$deviceXen + fi + + if [ -e $device ]; then + # is device formatted? + if [ $(mountpoint -q -x $device) ]; then + echo "$device is formatted" + else + if which dpkg &> /dev/null; then + apt-get install -y xfsprogs + elif which rpm &> /dev/null; then + yum install -y xfsprogs + fi + echo "warning: ERASING CONTENTS OF $device" + mkfs.xfs -f $device fi - mount -o defaults,noatime $device $mount - if $automount ; then - echo "$device $mount xfs defaults,noatime 0 0" >> /etc/fstab + # is device mounted? + mount | grep -q $device + if [ $? == 0 ]; then + echo "$device is mounted" + if [ ! -d $mount ]; then + echo "Symlinking to $mount" + ln -s $(grep $device /proc/mounts | awk '{print $2}') $mount + fi + else + echo "Mounting $device on $mount" + if [ ! -e $mount ]; then + mkdir $mount + fi + mount -o defaults,noatime $device $mount + if $automount ; then + echo "$device $mount xfs defaults,noatime 0 0" >> /etc/fstab + fi fi fi }