use of com.cloud.engine.subsystem.api.storage.CopyCommandResult in project cosmic by MissionCriticalCloud.
the class TemplateServiceImpl method copyTemplateCallBack.
protected Void copyTemplateCallBack(final AsyncCallbackDispatcher<TemplateServiceImpl, CopyCommandResult> callback, final TemplateOpContext<TemplateApiResult> context) {
final TemplateInfo destTemplate = context.getTemplate();
final CopyCommandResult result = callback.getResult();
final AsyncCallFuture<TemplateApiResult> future = context.getFuture();
final TemplateApiResult res = new TemplateApiResult(destTemplate);
try {
if (result.isFailed()) {
res.setResult(result.getResult());
destTemplate.processEvent(Event.OperationFailed);
} else {
destTemplate.processEvent(Event.OperationSuccessed, result.getAnswer());
}
future.complete(res);
} catch (final Exception e) {
s_logger.debug("Failed to process copy template callback", e);
res.setResult(e.toString());
future.complete(res);
}
return null;
}
use of com.cloud.engine.subsystem.api.storage.CopyCommandResult in project cosmic by MissionCriticalCloud.
the class StorageSystemDataMotionStrategy method handleCreateVolumeFromSnapshotBothOnStorageSystem.
private Void handleCreateVolumeFromSnapshotBothOnStorageSystem(final SnapshotInfo snapshotInfo, VolumeInfo volumeInfo, final AsyncCompletionCallback<CopyCommandResult> callback) {
try {
// at this point, the snapshotInfo and volumeInfo should have the same disk offering ID (so either one should be OK to get a DiskOfferingVO instance)
final DiskOfferingVO diskOffering = _diskOfferingDao.findByIdIncludingRemoved(volumeInfo.getDiskOfferingId());
final SnapshotVO snapshot = _snapshotDao.findById(snapshotInfo.getId());
// update the volume's hv_ss_reserve (hypervisor snapshot reserve) from a disk offering (used for managed storage)
_volumeService.updateHypervisorSnapshotReserveForVolume(diskOffering, volumeInfo.getId(), snapshot.getHypervisorType());
final AsyncCallFuture<VolumeApiResult> future = _volumeService.createVolumeAsync(volumeInfo, volumeInfo.getDataStore());
final VolumeApiResult result = future.get();
if (result.isFailed()) {
s_logger.debug("Failed to create a volume: " + result.getResult());
throw new CloudRuntimeException(result.getResult());
}
} catch (final Exception ex) {
throw new CloudRuntimeException(ex.getMessage());
}
volumeInfo = _volumeDataFactory.getVolume(volumeInfo.getId(), volumeInfo.getDataStore());
volumeInfo.processEvent(Event.MigrationRequested);
volumeInfo = _volumeDataFactory.getVolume(volumeInfo.getId(), volumeInfo.getDataStore());
final HostVO hostVO = getHost(snapshotInfo.getDataStore().getId());
final String value = _configDao.getValue(Config.PrimaryStorageDownloadWait.toString());
final int primaryStorageDownloadWait = NumbersUtil.parseInt(value, Integer.parseInt(Config.PrimaryStorageDownloadWait.getDefaultValue()));
final CopyCommand copyCommand = new CopyCommand(snapshotInfo.getTO(), volumeInfo.getTO(), primaryStorageDownloadWait, VirtualMachineManager.ExecuteInSequence.value());
CopyCmdAnswer copyCmdAnswer = null;
try {
_volumeService.grantAccess(snapshotInfo, hostVO, snapshotInfo.getDataStore());
_volumeService.grantAccess(volumeInfo, hostVO, volumeInfo.getDataStore());
final Map<String, String> srcDetails = getSnapshotDetails(_storagePoolDao.findById(snapshotInfo.getDataStore().getId()), snapshotInfo);
copyCommand.setOptions(srcDetails);
final Map<String, String> destDetails = getVolumeDetails(volumeInfo);
copyCommand.setOptions2(destDetails);
copyCmdAnswer = (CopyCmdAnswer) _agentMgr.send(hostVO.getId(), copyCommand);
} catch (final Exception ex) {
throw new CloudRuntimeException(ex.getMessage());
} finally {
try {
_volumeService.revokeAccess(snapshotInfo, hostVO, snapshotInfo.getDataStore());
} catch (final Exception ex) {
s_logger.debug(ex.getMessage(), ex);
}
try {
_volumeService.revokeAccess(volumeInfo, hostVO, volumeInfo.getDataStore());
} catch (final Exception ex) {
s_logger.debug(ex.getMessage(), ex);
}
}
String errMsg = null;
if (copyCmdAnswer == null || !copyCmdAnswer.getResult()) {
if (copyCmdAnswer != null && copyCmdAnswer.getDetails() != null && !copyCmdAnswer.getDetails().isEmpty()) {
errMsg = copyCmdAnswer.getDetails();
} else {
errMsg = "Unable to perform host-side operation";
}
}
final CopyCommandResult result = new CopyCommandResult(null, copyCmdAnswer);
result.setResult(errMsg);
callback.complete(result);
return null;
}
use of com.cloud.engine.subsystem.api.storage.CopyCommandResult in project cosmic by MissionCriticalCloud.
the class StorageCacheManagerImpl method createCacheObject.
@Override
public DataObject createCacheObject(final DataObject data, final DataStore store) {
DataObject objOnCacheStore = null;
final Object lock;
final DataObjectType type = data.getType();
final String typeName;
final long storeId = store.getId();
final long dataId = data.getId();
/*
* Make sure any thread knows own lock type.
*/
if (type == DataObjectType.TEMPLATE) {
lock = templateLock;
typeName = "template";
} else if (type == DataObjectType.VOLUME) {
lock = volumeLock;
typeName = "volume";
} else if (type == DataObjectType.SNAPSHOT) {
lock = snapshotLock;
typeName = "snapshot";
} else {
final String msg = "unsupported DataObject comes, then can't acquire correct lock object";
throw new CloudRuntimeException(msg);
}
s_logger.debug("check " + typeName + " cache entry(id: " + dataId + ") on store(id: " + storeId + ")");
DataObject existingDataObj = null;
synchronized (lock) {
DataObjectInStore obj = objectInStoreMgr.findObject(data, store);
if (obj != null) {
State st = obj.getState();
final long miliSeconds = 10000;
final long timeoutSeconds = 3600;
final long timeoutMiliSeconds = timeoutSeconds * 1000;
Date now = new Date();
final long expiredEpoch = now.getTime() + timeoutMiliSeconds;
final Date expiredDate = new Date(expiredEpoch);
/*
* Waiting for completion of cache copy.
*/
while (st == ObjectInDataStoreStateMachine.State.Allocated || st == ObjectInDataStoreStateMachine.State.Creating || st == ObjectInDataStoreStateMachine.State.Copying) {
/*
* Threads must release lock within waiting for cache copy and
* must be waken up at completion.
*/
s_logger.debug("waiting cache copy completion type: " + typeName + ", id: " + obj.getObjectId() + ", lock: " + lock.hashCode());
try {
lock.wait(miliSeconds);
} catch (final InterruptedException e) {
s_logger.debug("[ignored] interupted while waiting for cache copy completion.");
}
s_logger.debug("waken up");
now = new Date();
if (now.after(expiredDate)) {
final String msg = "Waiting time exceeds timeout limit(" + timeoutSeconds + " s)";
throw new CloudRuntimeException(msg);
}
obj = objectInStoreMgr.findObject(data, store);
st = obj.getState();
}
if (st == ObjectInDataStoreStateMachine.State.Ready) {
s_logger.debug("there is already one in the cache store");
final DataObject dataObj = objectInStoreMgr.get(data, store);
dataObj.incRefCount();
existingDataObj = dataObj;
}
}
if (existingDataObj == null) {
s_logger.debug("create " + typeName + " cache entry(id: " + dataId + ") on store(id: " + storeId + ")");
objOnCacheStore = store.create(data);
}
lock.notifyAll();
}
if (existingDataObj != null) {
return existingDataObj;
}
if (objOnCacheStore == null) {
s_logger.error("create " + typeName + " cache entry(id: " + dataId + ") on store(id: " + storeId + ") failed");
return null;
}
final AsyncCallFuture<CopyCommandResult> future = new AsyncCallFuture<>();
CopyCommandResult result = null;
try {
objOnCacheStore.processEvent(Event.CreateOnlyRequested);
dataMotionSvr.copyAsync(data, objOnCacheStore, future);
result = future.get();
if (result.isFailed()) {
objOnCacheStore.processEvent(Event.OperationFailed);
} else {
objOnCacheStore.processEvent(Event.OperationSuccessed, result.getAnswer());
objOnCacheStore.incRefCount();
return objOnCacheStore;
}
} catch (final InterruptedException e) {
s_logger.debug("create cache storage failed: " + e.toString());
throw new CloudRuntimeException(e);
} catch (final ExecutionException e) {
s_logger.debug("create cache storage failed: " + e.toString());
throw new CloudRuntimeException(e);
} finally {
if (result == null) {
objOnCacheStore.processEvent(Event.OperationFailed);
}
synchronized (lock) {
/*
* Wake up all threads waiting for cache copy.
*/
s_logger.debug("wake up all waiting threads(lock: " + lock.hashCode() + ")");
lock.notifyAll();
}
}
return null;
}
use of com.cloud.engine.subsystem.api.storage.CopyCommandResult in project cosmic by MissionCriticalCloud.
the class AbstractHyperVisorStorageMotionStrategy method copyAsync.
@Override
public Void copyAsync(final Map<VolumeInfo, DataStore> volumeMap, final VirtualMachineTO vmTo, final Host srcHost, final Host destHost, final AsyncCompletionCallback<CopyCommandResult> callback) {
Answer answer = null;
String errMsg = null;
try {
final VMInstanceVO instance = instanceDao.findById(vmTo.getId());
if (instance != null) {
if (srcHost.getClusterId().equals(destHost.getClusterId())) {
answer = migrateVmWithVolumesWithinCluster(instance, vmTo, srcHost, destHost, volumeMap);
} else {
answer = migrateVmWithVolumesAcrossCluster(instance, vmTo, srcHost, destHost, volumeMap);
}
} else {
throw new CloudRuntimeException("Unsupported operation requested for moving data.");
}
} catch (final Exception e) {
s_logger.error("copy failed", e);
errMsg = e.toString();
}
final CopyCommandResult result = new CopyCommandResult(null, answer);
result.setResult(errMsg);
callback.complete(result);
return null;
}
use of com.cloud.engine.subsystem.api.storage.CopyCommandResult in project cosmic by MissionCriticalCloud.
the class AbstractHyperVisorStorageMotionStrategy method copyAsync.
@Override
public Void copyAsync(final DataObject srcData, final DataObject destData, final AsyncCompletionCallback<CopyCommandResult> callback) {
final CopyCommandResult result = new CopyCommandResult(null, null);
result.setResult("Unsupported operation requested for copying data.");
callback.complete(result);
return null;
}
Aggregations