Example usage for com.amazonaws.services.ec2.model VolumeState InUse

List of usage examples for com.amazonaws.services.ec2.model VolumeState InUse

Introduction

In this page you can find the example usage for com.amazonaws.services.ec2.model VolumeState InUse.

Prototype

VolumeState InUse

To view the source code for com.amazonaws.services.ec2.model VolumeState InUse.

Click Source Link

Usage

From source file:jp.primecloud.auto.process.aws.AwsCommonProcess.java

License:Open Source License

public Volume waitVolume(AwsProcessClient awsProcessClient, String volumeId) {
    // ???/*from   ww w  .ja  va2  s.  c  o m*/
    Volume volume;
    while (true) {
        try {
            Thread.sleep(1000L * awsProcessClient.getDescribeInterval());
        } catch (InterruptedException ignore) {
        }

        volume = describeVolume(awsProcessClient, volumeId);
        VolumeState state;
        try {
            state = VolumeState.fromValue(volume.getState());
        } catch (IllegalArgumentException e) {
            // ???
            AutoException exception = new AutoException("EPROCESS-000112", volume, volume.getState());
            exception.addDetailInfo("result=" + ReflectionToStringBuilder.toString(volume));
            throw exception;
        }

        // ?????
        if (state == VolumeState.Available || state == VolumeState.InUse || state == VolumeState.Deleted
                || state == VolumeState.Error) {
            break;
        }
    }

    return volume;
}

From source file:jp.primecloud.auto.process.aws.AwsVolumeProcess.java

License:Open Source License

public void waitAttachVolume(AwsProcessClient awsProcessClient, Long instanceNo, Long volumeNo) {
    AwsVolume awsVolume = awsVolumeDao.read(volumeNo);
    String volumeId = awsVolume.getVolumeId();

    Volume volume = null;/*from   w  w w.jav a  2s. c  o  m*/
    try {
        // volume = awsProcessClient.waitAttachVolume(volumeId, instanceId);
        // TODO: ????????????
        int retry = 6;
        for (int i = 0; i < retry; i++) {
            volume = awsCommonProcess.waitVolume(awsProcessClient, volumeId);
            if (StringUtils.equals(volume.getState(), VolumeState.InUse.toString())) {
                break;
            }
        }

        if (!StringUtils.equals(volume.getState(), VolumeState.InUse.toString())) {
            // ?????
            AutoException exception = new AutoException("EPROCESS-000115", awsVolume.getInstanceId(), volumeId,
                    volume.getState());
            exception.addDetailInfo("result=" + ReflectionToStringBuilder.toString(volume));
            throw exception;
        }

        // 
        if (log.isInfoEnabled()) {
            log.info(MessageUtils.getMessage("IPROCESS-100124", volumeId, awsVolume.getInstanceId()));
        }
    } catch (AutoException e) {
        // ?????
        awsVolume = awsVolumeDao.read(volumeNo);
        awsVolume.setStatus(VolumeState.Error.toString());
        awsVolume.setInstanceId(null);
        awsVolumeDao.update(awsVolume);

        throw e;
    }

    //
    Component component = null;
    if (awsVolume.getComponentNo() != null) {
        component = componentDao.read(awsVolume.getComponentNo());
    }
    Instance instance = instanceDao.read(instanceNo);
    processLogger.debug(component, instance, "AwsEbsAttachFinish",
            new Object[] { instance.getInstanceName(), awsVolume.getVolumeId(), awsVolume.getDevice() });

    // ?
    awsVolume = awsVolumeDao.read(volumeNo);
    awsVolume.setStatus(volume.getState());
    awsVolumeDao.update(awsVolume);
}