use of com.cloud.engine.subsystem.api.storage.CreateCmdResult in project cosmic by MissionCriticalCloud.
the class VolumeServiceImpl method registerVolumeCallback.
protected Void registerVolumeCallback(final AsyncCallbackDispatcher<VolumeServiceImpl, CreateCmdResult> callback, final CreateVolumeContext<VolumeApiResult> context) {
final CreateCmdResult result = callback.getResult();
final VolumeObject vo = (VolumeObject) context.volume;
try {
if (result.isFailed()) {
vo.processEvent(Event.OperationFailed);
// delete the volume entry from volumes table in case of failure
final VolumeVO vol = volDao.findById(vo.getId());
if (vol != null) {
volDao.remove(vo.getId());
}
} else {
vo.processEvent(Event.OperationSuccessed, result.getAnswer());
if (vo.getSize() != null) {
// publish usage events
// get physical size from volume_store_ref table
final DataStore ds = vo.getDataStore();
final VolumeDataStoreVO volStore = _volumeStoreDao.findByStoreVolume(ds.getId(), vo.getId());
if (volStore == null) {
s_logger.warn("No entry found in volume_store_ref for volume id: " + vo.getId() + " and image store id: " + ds.getId() + " at the end of uploading volume!");
}
final Scope dsScope = ds.getScope();
if (dsScope.getScopeType() == ScopeType.REGION) {
_resourceLimitMgr.incrementResourceCount(vo.getAccountId(), ResourceType.secondary_storage, vo.getSize());
}
}
}
final VolumeApiResult res = new VolumeApiResult(vo);
context.future.complete(res);
return null;
} catch (final Exception e) {
s_logger.error("register volume failed: ", e);
// delete the volume entry from volumes table in case of failure
final VolumeVO vol = volDao.findById(vo.getId());
if (vol != null) {
volDao.remove(vo.getId());
}
final VolumeApiResult res = new VolumeApiResult(null);
context.future.complete(res);
return null;
}
}
use of com.cloud.engine.subsystem.api.storage.CreateCmdResult in project cosmic by MissionCriticalCloud.
the class CloudStackPrimaryDataStoreDriverImpl method takeSnapshot.
@Override
public void takeSnapshot(final SnapshotInfo snapshot, final AsyncCompletionCallback<CreateCmdResult> callback) {
CreateCmdResult result = null;
try {
final SnapshotObjectTO snapshotTO = (SnapshotObjectTO) snapshot.getTO();
final Object payload = snapshot.getPayload();
if (payload != null && payload instanceof CreateSnapshotPayload) {
final CreateSnapshotPayload snapshotPayload = (CreateSnapshotPayload) payload;
snapshotTO.setQuiescevm(snapshotPayload.getQuiescevm());
}
final CreateObjectCommand cmd = new CreateObjectCommand(snapshotTO);
final EndPoint ep = epSelector.select(snapshot, StorageAction.TAKESNAPSHOT);
Answer answer = null;
if (ep == null) {
final String errMsg = "No remote endpoint to send createObjectCommand, check if host or ssvm is down?";
s_logger.error(errMsg);
answer = new Answer(cmd, false, errMsg);
} else {
answer = ep.sendMessage(cmd);
}
result = new CreateCmdResult(null, answer);
if (answer != null && !answer.getResult()) {
result.setResult(answer.getDetails());
}
callback.complete(result);
return;
} catch (final Exception e) {
s_logger.debug("Failed to take snapshot: " + snapshot.getId(), e);
result = new CreateCmdResult(null, null);
result.setResult(e.toString());
}
callback.complete(result);
}
use of com.cloud.engine.subsystem.api.storage.CreateCmdResult in project cosmic by MissionCriticalCloud.
the class VolumeServiceImpl method createVolumeAsync.
@Override
public AsyncCallFuture<VolumeApiResult> createVolumeAsync(final VolumeInfo volume, final DataStore dataStore) {
final AsyncCallFuture<VolumeApiResult> future = new AsyncCallFuture<>();
final DataObject volumeOnStore = dataStore.create(volume);
volumeOnStore.processEvent(Event.CreateOnlyRequested);
try {
final CreateVolumeContext<VolumeApiResult> context = new CreateVolumeContext<>(null, volumeOnStore, future);
final AsyncCallbackDispatcher<VolumeServiceImpl, CreateCmdResult> caller = AsyncCallbackDispatcher.create(this);
caller.setCallback(caller.getTarget().createVolumeCallback(null, null)).setContext(context);
dataStore.getDriver().createAsync(dataStore, volumeOnStore, caller);
} catch (final CloudRuntimeException ex) {
// clean up already persisted volume_store_ref entry in case of createVolumeCallback is never called
final VolumeDataStoreVO volStoreVO = _volumeStoreDao.findByStoreVolume(dataStore.getId(), volume.getId());
if (volStoreVO != null) {
final VolumeInfo volObj = volFactory.getVolume(volume, dataStore);
volObj.processEvent(ObjectInDataStoreStateMachine.Event.OperationFailed);
}
final VolumeApiResult volResult = new VolumeApiResult((VolumeObject) volumeOnStore);
volResult.setResult(ex.getMessage());
future.complete(volResult);
}
return future;
}
use of com.cloud.engine.subsystem.api.storage.CreateCmdResult in project cosmic by MissionCriticalCloud.
the class VolumeServiceImpl method createBaseImageAsync.
@DB
protected void createBaseImageAsync(final VolumeInfo volume, final PrimaryDataStore dataStore, final TemplateInfo template, final AsyncCallFuture<VolumeApiResult> future) {
final DataObject templateOnPrimaryStoreObj = dataStore.create(template);
VMTemplateStoragePoolVO templatePoolRef = _tmpltPoolDao.findByPoolTemplate(dataStore.getId(), template.getId());
if (templatePoolRef == null) {
throw new CloudRuntimeException("Failed to find template " + template.getUniqueName() + " in storage pool " + dataStore.getId());
} else {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Found template " + template.getUniqueName() + " in storage pool " + dataStore.getId() + " with VMTemplateStoragePool id: " + templatePoolRef.getId());
}
}
final long templatePoolRefId = templatePoolRef.getId();
final CreateBaseImageContext<CreateCmdResult> context = new CreateBaseImageContext<>(null, volume, dataStore, template, future, templateOnPrimaryStoreObj, templatePoolRefId);
final AsyncCallbackDispatcher<VolumeServiceImpl, CopyCommandResult> caller = AsyncCallbackDispatcher.create(this);
caller.setCallback(caller.getTarget().copyBaseImageCallback(null, null)).setContext(context);
final int storagePoolMaxWaitSeconds = NumbersUtil.parseInt(configDao.getValue(Config.StoragePoolMaxWaitSeconds.key()), 3600);
if (s_logger.isDebugEnabled()) {
s_logger.debug("Acquire lock on VMTemplateStoragePool " + templatePoolRefId + " with timeout " + storagePoolMaxWaitSeconds + " seconds");
}
templatePoolRef = _tmpltPoolDao.acquireInLockTable(templatePoolRefId, storagePoolMaxWaitSeconds);
if (templatePoolRef == null) {
if (s_logger.isDebugEnabled()) {
s_logger.info("Unable to acquire lock on VMTemplateStoragePool " + templatePoolRefId);
}
templatePoolRef = _tmpltPoolDao.findByPoolTemplate(dataStore.getId(), template.getId());
if (templatePoolRef != null && templatePoolRef.getState() == ObjectInDataStoreStateMachine.State.Ready) {
s_logger.info("Unable to acquire lock on VMTemplateStoragePool " + templatePoolRefId + ", But Template " + template.getUniqueName() + " is already copied to primary storage, skip copying");
createVolumeFromBaseImageAsync(volume, templateOnPrimaryStoreObj, dataStore, future);
return;
}
throw new CloudRuntimeException("Unable to acquire lock on VMTemplateStoragePool: " + templatePoolRefId);
}
if (s_logger.isDebugEnabled()) {
s_logger.info("lock is acquired for VMTemplateStoragePool " + templatePoolRefId);
}
try {
if (templatePoolRef.getState() == ObjectInDataStoreStateMachine.State.Ready) {
s_logger.info("Template " + template.getUniqueName() + " is already copied to primary storage, skip copying");
createVolumeFromBaseImageAsync(volume, templateOnPrimaryStoreObj, dataStore, future);
return;
}
templateOnPrimaryStoreObj.processEvent(Event.CreateOnlyRequested);
motionSrv.copyAsync(template, templateOnPrimaryStoreObj, caller);
} finally {
if (s_logger.isDebugEnabled()) {
s_logger.info("releasing lock for VMTemplateStoragePool " + templatePoolRefId);
}
_tmpltPoolDao.releaseFromLockTable(templatePoolRefId);
}
return;
}
use of com.cloud.engine.subsystem.api.storage.CreateCmdResult in project cosmic by MissionCriticalCloud.
the class CloudStackPrimaryDataStoreDriverImpl method resize.
@Override
public void resize(final DataObject data, final AsyncCompletionCallback<CreateCmdResult> callback) {
final VolumeObject vol = (VolumeObject) data;
final StoragePool pool = (StoragePool) data.getDataStore();
final ResizeVolumePayload resizeParameter = (ResizeVolumePayload) vol.getpayload();
final ResizeVolumeCommand resizeCmd = new ResizeVolumeCommand(vol.getPath(), new StorageFilerTO(pool), vol.getSize(), resizeParameter.newSize, resizeParameter.shrinkOk, resizeParameter.instanceName);
final CreateCmdResult result = new CreateCmdResult(null, null);
try {
final ResizeVolumeAnswer answer = (ResizeVolumeAnswer) storageMgr.sendToPool(pool, resizeParameter.hosts, resizeCmd);
if (answer != null && answer.getResult()) {
final long finalSize = answer.getNewSize();
s_logger.debug("Resize: volume started at size " + vol.getSize() + " and ended at size " + finalSize);
vol.setSize(finalSize);
vol.update();
} else if (answer != null) {
result.setResult(answer.getDetails());
} else {
s_logger.debug("return a null answer, mark it as failed for unknown reason");
result.setResult("return a null answer, mark it as failed for unknown reason");
}
} catch (final Exception e) {
s_logger.debug("sending resize command failed", e);
result.setResult(e.toString());
}
callback.complete(result);
}
Aggregations