use of com.cloud.exception.StorageUnavailableException in project cosmic by MissionCriticalCloud.
the class VolumeOrchestrator method recreateVolume.
private Pair<VolumeVO, DataStore> recreateVolume(final VolumeVO vol, final VirtualMachineProfile vm, final DeployDestination dest) throws StorageUnavailableException {
VolumeVO newVol;
final boolean recreate = RecreatableSystemVmEnabled.value();
DataStore destPool = null;
if (recreate && (dest.getStorageForDisks() == null || dest.getStorageForDisks().get(vol) == null)) {
destPool = dataStoreMgr.getDataStore(vol.getPoolId(), DataStoreRole.Primary);
s_logger.debug("existing pool: " + destPool.getId());
} else {
final StoragePool pool = dest.getStorageForDisks().get(vol);
destPool = dataStoreMgr.getDataStore(pool.getId(), DataStoreRole.Primary);
}
if (vol.getState() == Volume.State.Allocated || vol.getState() == Volume.State.Creating) {
newVol = vol;
} else {
newVol = switchVolume(vol, vm);
// changed
if (dest.getStorageForDisks() != null && dest.getStorageForDisks().containsKey(vol)) {
final StoragePool poolWithOldVol = dest.getStorageForDisks().get(vol);
dest.getStorageForDisks().put(newVol, poolWithOldVol);
dest.getStorageForDisks().remove(vol);
}
if (s_logger.isDebugEnabled()) {
s_logger.debug("Created new volume " + newVol + " for old volume " + vol);
}
}
VolumeInfo volume = volFactory.getVolume(newVol.getId(), destPool);
final Long templateId = newVol.getTemplateId();
for (int i = 0; i < 2; i++) {
// retry one more time in case of template reload is required for Vmware case
AsyncCallFuture<VolumeService.VolumeApiResult> future = null;
if (templateId == null) {
final DiskOffering diskOffering = _entityMgr.findById(DiskOffering.class, volume.getDiskOfferingId());
final HypervisorType hyperType = vm.getVirtualMachine().getHypervisorType();
// update the volume's hv_ss_reserve (hypervisor snapshot reserve) from a disk offering (used for managed storage)
volService.updateHypervisorSnapshotReserveForVolume(diskOffering, volume.getId(), hyperType);
volume = volFactory.getVolume(newVol.getId(), destPool);
future = volService.createVolumeAsync(volume, destPool);
} else {
final TemplateInfo templ = tmplFactory.getReadyTemplateOnImageStore(templateId, dest.getZone().getId());
if (templ == null) {
s_logger.debug("can't find ready template: " + templateId + " for data center " + dest.getZone().getId());
throw new CloudRuntimeException("can't find ready template: " + templateId + " for data center " + dest.getZone().getId());
}
final PrimaryDataStore primaryDataStore = (PrimaryDataStore) destPool;
if (primaryDataStore.isManaged()) {
final DiskOffering diskOffering = _entityMgr.findById(DiskOffering.class, volume.getDiskOfferingId());
final HypervisorType hyperType = vm.getVirtualMachine().getHypervisorType();
// update the volume's hv_ss_reserve (hypervisor snapshot reserve) from a disk offering (used for managed storage)
volService.updateHypervisorSnapshotReserveForVolume(diskOffering, volume.getId(), hyperType);
final long hostId = vm.getVirtualMachine().getHostId();
future = volService.createManagedStorageAndVolumeFromTemplateAsync(volume, destPool.getId(), templ, hostId);
} else {
future = volService.createVolumeFromTemplateAsync(volume, destPool.getId(), templ);
}
}
VolumeService.VolumeApiResult result = null;
try {
result = future.get();
if (result.isFailed()) {
if (result.getResult().contains("request template reload") && (i == 0)) {
s_logger.debug("Retry template re-deploy for vmware");
continue;
} else {
s_logger.debug("Unable to create " + newVol + ":" + result.getResult());
throw new StorageUnavailableException("Unable to create " + newVol + ":" + result.getResult(), destPool.getId());
}
}
final StoragePoolVO storagePool = _storagePoolDao.findById(destPool.getId());
if (storagePool.isManaged()) {
final long hostId = vm.getVirtualMachine().getHostId();
final Host host = _hostDao.findById(hostId);
volService.grantAccess(volFactory.getVolume(newVol.getId()), host, destPool);
}
newVol = _volsDao.findById(newVol.getId());
// break out of template-redeploy retry loop
break;
} catch (final InterruptedException e) {
s_logger.error("Unable to create " + newVol, e);
throw new StorageUnavailableException("Unable to create " + newVol + ":" + e.toString(), destPool.getId());
} catch (final ExecutionException e) {
s_logger.error("Unable to create " + newVol, e);
throw new StorageUnavailableException("Unable to create " + newVol + ":" + e.toString(), destPool.getId());
}
}
return new Pair<>(newVol, destPool);
}
use of com.cloud.exception.StorageUnavailableException in project cosmic by MissionCriticalCloud.
the class StartVMCmd method execute.
@Override
public void execute() throws ResourceUnavailableException, ResourceAllocationException {
try {
CallContext.current().setEventDetails("Vm Id: " + getId());
final UserVm result;
result = _userVmService.startVirtualMachine(this);
if (result != null) {
final UserVmResponse response = _responseGenerator.createUserVmResponse(ResponseView.Restricted, "virtualmachine", result).get(0);
response.setResponseName(getCommandName());
setResponseObject(response);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to start a vm");
}
} catch (final ConcurrentOperationException ex) {
s_logger.warn("Exception: ", ex);
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
} catch (final StorageUnavailableException ex) {
s_logger.warn("Exception: ", ex);
throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage());
} catch (final ExecutionException ex) {
s_logger.warn("Exception: ", ex);
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
} catch (final InsufficientCapacityException ex) {
final StringBuilder message = new StringBuilder(ex.getMessage());
if (ex instanceof InsufficientServerCapacityException) {
if (((InsufficientServerCapacityException) ex).isAffinityApplied()) {
message.append(", Please check the affinity groups provided, there may not be sufficient capacity to follow them");
}
}
s_logger.info(ex.toString());
s_logger.info(message.toString(), ex);
throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR, message.toString());
}
}
use of com.cloud.exception.StorageUnavailableException in project cosmic by MissionCriticalCloud.
the class CloudStackPrimaryDataStoreDriverImpl method createAsync.
@Override
public void createAsync(final DataStore dataStore, final DataObject data, final AsyncCompletionCallback<CreateCmdResult> callback) {
String errMsg = null;
Answer answer = null;
final CreateCmdResult result = new CreateCmdResult(null, null);
if (data.getType() == DataObjectType.VOLUME) {
try {
answer = createVolume((VolumeInfo) data);
if ((answer == null) || (!answer.getResult())) {
result.setSuccess(false);
if (answer != null) {
result.setResult(answer.getDetails());
}
} else {
result.setAnswer(answer);
}
} catch (final StorageUnavailableException e) {
s_logger.debug("failed to create volume", e);
errMsg = e.toString();
} catch (final Exception e) {
s_logger.debug("failed to create volume", e);
errMsg = e.toString();
}
}
if (errMsg != null) {
result.setResult(errMsg);
}
callback.complete(result);
}
use of com.cloud.exception.StorageUnavailableException in project cosmic by MissionCriticalCloud.
the class VolumeApiServiceImpl method orchestrateMigrateVolume.
private Volume orchestrateMigrateVolume(final long volumeId, final long destPoolId, final boolean liveMigrateVolume) {
final VolumeVO vol = _volsDao.findById(volumeId);
assert vol != null;
final StoragePool destPool = (StoragePool) dataStoreMgr.getDataStore(destPoolId, DataStoreRole.Primary);
assert destPool != null;
final Volume newVol;
try {
if (liveMigrateVolume) {
newVol = liveMigrateVolume(vol, destPool);
} else {
newVol = _volumeMgr.migrateVolume(vol, destPool);
}
} catch (final StorageUnavailableException e) {
s_logger.debug("Failed to migrate volume", e);
throw new CloudRuntimeException(e.getMessage());
} catch (final Exception e) {
s_logger.debug("Failed to migrate volume", e);
throw new CloudRuntimeException(e.getMessage());
}
return newVol;
}
use of com.cloud.exception.StorageUnavailableException in project cosmic by MissionCriticalCloud.
the class SnapshotManagerImpl method sendToPool.
@Override
public Answer sendToPool(final Volume vol, final Command cmd) {
final StoragePool pool = (StoragePool) dataStoreMgr.getPrimaryDataStore(vol.getPoolId());
long[] hostIdsToTryFirst = null;
final Long vmHostId = getHostIdForSnapshotOperation(vol);
if (vmHostId != null) {
hostIdsToTryFirst = new long[] { vmHostId };
}
final List<Long> hostIdsToAvoid = new ArrayList<>();
for (int retry = _totalRetries; retry >= 0; retry--) {
try {
final Pair<Long, Answer> result = _storageMgr.sendToPool(pool, hostIdsToTryFirst, hostIdsToAvoid, cmd);
if (result.second().getResult()) {
return result.second();
}
if (s_logger.isDebugEnabled()) {
s_logger.debug("The result for " + cmd.getClass().getName() + " is " + result.second().getDetails() + " through " + result.first());
}
hostIdsToAvoid.add(result.first());
} catch (final StorageUnavailableException e1) {
s_logger.warn("Storage unavailable ", e1);
return null;
}
try {
Thread.sleep(_pauseInterval * 1000);
} catch (final InterruptedException e) {
s_logger.debug("[ignored] interupted while retry cmd.");
}
s_logger.debug("Retrying...");
}
s_logger.warn("After " + _totalRetries + " retries, the command " + cmd.getClass().getName() + " did not succeed.");
return null;
}
Aggregations