mirror of https://github.com/apache/cloudstack.git
create volume on storage refactor
This commit is contained in:
parent
b52daa2be5
commit
d6055c9ae2
|
|
@ -113,7 +113,7 @@ public class CreateVolumeCmd extends BaseAsyncCreateCustomIdCmd implements UserC
|
|||
@Parameter(name = ApiConstants.STORAGE_ID,
|
||||
type = CommandType.UUID,
|
||||
entityType = StoragePoolResponse.class,
|
||||
description = "Storage pool ID to create the volume in.")
|
||||
description = "Storage pool ID to create the volume in. Exclusive with SnapshotId parameter.")
|
||||
private Long storageId;
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
|
|
@ -161,6 +161,9 @@ public class CreateVolumeCmd extends BaseAsyncCreateCustomIdCmd implements UserC
|
|||
}
|
||||
|
||||
public Long getStorageId() {
|
||||
if (snapshotId != null && storageId != null) {
|
||||
throw new IllegalArgumentException("StorageId parameter cannot be specified with the SnapshotId parameter.");
|
||||
}
|
||||
return storageId;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1048,29 +1048,15 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic
|
|||
return true;
|
||||
}
|
||||
|
||||
private VolumeVO allocateVolumeOnStorage(Long volumeId, Long storageId) {
|
||||
private VolumeVO allocateVolumeOnStorage(Long volumeId, Long storageId) throws ExecutionException, InterruptedException {
|
||||
DataStore destStore = dataStoreMgr.getDataStore(storageId, DataStoreRole.Primary);
|
||||
VolumeInfo destVolume = volFactory.getVolume(volumeId, destStore);
|
||||
try {
|
||||
AsyncCallFuture<VolumeApiResult> createVolumeFuture = volService.createVolumeAsync(destVolume, destStore);
|
||||
VolumeApiResult createVolumeResult = createVolumeFuture.get();
|
||||
if (createVolumeResult.isFailed()) {
|
||||
logger.debug("Failed to create dest volume {}, volume can be removed", destVolume);
|
||||
destroyVolume(destVolume.getId());
|
||||
destVolume.processEvent(ObjectInDataStoreStateMachine.Event.ExpungeRequested);
|
||||
destVolume.processEvent(ObjectInDataStoreStateMachine.Event.OperationSucceeded);
|
||||
_volsDao.remove(destVolume.getId());
|
||||
throw new CloudRuntimeException("Creation of a dest volume failed: " + createVolumeResult.getResult());
|
||||
} else {
|
||||
destVolume = volFactory.getVolume(destVolume.getId(), destStore);
|
||||
destVolume.processEvent(ObjectInDataStoreStateMachine.Event.CreateRequested);
|
||||
destVolume.processEvent(ObjectInDataStoreStateMachine.Event.OperationSucceeded);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.debug("Failed to create dest volume {}", destVolume, e);
|
||||
throw new CloudRuntimeException("Creation of a dest volume failed: volume needs cleanup");
|
||||
AsyncCallFuture<VolumeApiResult> createVolumeFuture = volService.createVolumeAsync(destVolume, destStore);
|
||||
VolumeApiResult createVolumeResult = createVolumeFuture.get();
|
||||
if (createVolumeResult.isFailed()) {
|
||||
throw new CloudRuntimeException("Creation of a dest volume failed: " + createVolumeResult.getResult());
|
||||
}
|
||||
return null;
|
||||
return _volsDao.findById(destVolume.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -1113,7 +1099,7 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic
|
|||
}
|
||||
}
|
||||
} else if (storageId != null) {
|
||||
allocateVolumeOnStorage(volumeId, storageId);
|
||||
volume = allocateVolumeOnStorage(volumeId, storageId);
|
||||
}
|
||||
return volume;
|
||||
} catch (Exception e) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue