mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
fix volume state change
This commit is contained in:
parent
23db72d8b4
commit
acafccfbc6
@ -248,12 +248,11 @@ public class AncientDataMotionStrategy implements DataMotionStrategy {
|
||||
|
||||
protected Answer cloneVolume(DataObject template, DataObject volume) {
|
||||
CopyCommand cmd = new CopyCommand(template.getTO(), volume.getTO(), 0);
|
||||
StoragePool pool = (StoragePool)volume.getDataStore();
|
||||
|
||||
try {
|
||||
Answer answer = storageMgr.sendToPool(pool, null, cmd);
|
||||
EndPoint ep = this.selector.select(volume.getDataStore());
|
||||
Answer answer = ep.sendMessage(cmd);
|
||||
return answer;
|
||||
} catch (StorageUnavailableException e) {
|
||||
} catch (Exception e) {
|
||||
s_logger.debug("Failed to send to storage pool", e);
|
||||
throw new CloudRuntimeException("Failed to send to storage pool", e);
|
||||
}
|
||||
@ -302,16 +301,17 @@ public class AncientDataMotionStrategy implements DataMotionStrategy {
|
||||
destData.getType() == DataObjectType.SNAPSHOT) {
|
||||
answer = copySnapshot(srcData, destData);
|
||||
}
|
||||
|
||||
if (answer != null && !answer.getResult()) {
|
||||
errMsg = answer.getDetails();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
s_logger.debug("copy failed", e);
|
||||
errMsg = e.toString();
|
||||
}
|
||||
CopyCommandResult result = new CopyCommandResult(null, answer);
|
||||
if (!answer.getResult()) {
|
||||
result.setResult(answer.getDetails());
|
||||
}
|
||||
result.setResult(errMsg);
|
||||
callback.complete(result);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@ -240,9 +240,11 @@ public class VolumeTest extends CloudStackTestNGBase {
|
||||
List<HostVO> hosts = new ArrayList<HostVO>();
|
||||
hosts.add(this.host);
|
||||
Mockito.when(resourceMgr.listAllUpAndEnabledHosts((Type) Mockito.any(), Mockito.anyLong(), Mockito.anyLong(), Mockito.anyLong())).thenReturn(hosts);
|
||||
Mockito.when(epSelector.select(Mockito.any(DataObject.class))).thenReturn(new LocalHostEndpoint());
|
||||
|
||||
RemoteHostEndPoint ep = RemoteHostEndPoint.getHypervisorHostEndPoint(this.host.getId(), this.host.getPrivateIpAddress());
|
||||
Mockito.when(epSelector.select(Mockito.any(DataObject.class), Mockito.any(DataObject.class))).thenReturn(ep);
|
||||
Mockito.when(epSelector.select(Mockito.any(DataObject.class))).thenReturn(ep);
|
||||
Mockito.when(epSelector.select(Mockito.any(DataStore.class))).thenReturn(ep);
|
||||
}
|
||||
|
||||
public DataStore createPrimaryDataStore() {
|
||||
|
||||
@ -401,12 +401,12 @@ public class VolumeServiceImpl implements VolumeService {
|
||||
}
|
||||
|
||||
private class CreateVolumeFromBaseImageContext<T> extends AsyncRpcConext<T> {
|
||||
private final VolumeObject vo;
|
||||
private final DataObject vo;
|
||||
private final AsyncCallFuture<VolumeApiResult> future;
|
||||
private final DataStore primaryStore;
|
||||
private final DataObject templateOnStore;
|
||||
private final SnapshotInfo snapshot;
|
||||
public CreateVolumeFromBaseImageContext(AsyncCompletionCallback<T> callback, VolumeObject vo,
|
||||
public CreateVolumeFromBaseImageContext(AsyncCompletionCallback<T> callback, DataObject vo,
|
||||
DataStore primaryStore,
|
||||
DataObject templateOnStore,
|
||||
AsyncCallFuture<VolumeApiResult> future, SnapshotInfo snapshot) {
|
||||
@ -426,14 +426,13 @@ public class VolumeServiceImpl implements VolumeService {
|
||||
|
||||
@DB
|
||||
protected void createVolumeFromBaseImageAsync(VolumeInfo volume, DataObject templateOnPrimaryStore, PrimaryDataStore pd, AsyncCallFuture<VolumeApiResult> future) {
|
||||
VolumeObject vo = (VolumeObject)volume;
|
||||
CreateVolumeFromBaseImageContext<VolumeApiResult> context = new CreateVolumeFromBaseImageContext<VolumeApiResult>(null, vo, pd, templateOnPrimaryStore, future, null);
|
||||
AsyncCallbackDispatcher<VolumeServiceImpl, CopyCommandResult> caller = AsyncCallbackDispatcher.create(this);
|
||||
caller.setCallback(caller.getTarget().createVolumeFromBaseImageCallBack(null, null))
|
||||
.setContext(context);
|
||||
|
||||
DataObject volumeOnPrimaryStorage = pd.create(volume);
|
||||
volume.processEvent(Event.CreateOnlyRequested);
|
||||
volumeOnPrimaryStorage.processEvent(Event.CreateOnlyRequested);
|
||||
|
||||
CreateVolumeFromBaseImageContext<VolumeApiResult> context = new CreateVolumeFromBaseImageContext<VolumeApiResult>(null, volumeOnPrimaryStorage, pd, templateOnPrimaryStore, future, null);
|
||||
AsyncCallbackDispatcher<VolumeServiceImpl, CopyCommandResult> caller = AsyncCallbackDispatcher.create(this);
|
||||
caller.setCallback(caller.getTarget().createVolumeFromBaseImageCallBack(null, null));
|
||||
caller.setContext(context);
|
||||
|
||||
motionSrv.copyAsync(context.templateOnStore, volumeOnPrimaryStorage, caller);
|
||||
return;
|
||||
@ -441,9 +440,9 @@ public class VolumeServiceImpl implements VolumeService {
|
||||
|
||||
@DB
|
||||
protected Void createVolumeFromBaseImageCallBack(AsyncCallbackDispatcher<VolumeServiceImpl, CopyCommandResult> callback, CreateVolumeFromBaseImageContext<VolumeApiResult> context) {
|
||||
VolumeObject vo = context.vo;
|
||||
DataObject vo = context.vo;
|
||||
CopyCommandResult result = callback.getResult();
|
||||
VolumeApiResult volResult = new VolumeApiResult(vo);
|
||||
VolumeApiResult volResult = new VolumeApiResult((VolumeObject)vo);
|
||||
|
||||
if (result.isSuccess()) {
|
||||
vo.processEvent(Event.OperationSuccessed, result.getAnswer());
|
||||
@ -516,7 +515,7 @@ public class VolumeServiceImpl implements VolumeService {
|
||||
protected Void createVolumeFromSnapshotCallback(AsyncCallbackDispatcher<VolumeServiceImpl, CopyCommandResult> callback,
|
||||
CreateVolumeFromBaseImageContext<VolumeApiResult> context) {
|
||||
CopyCommandResult result = callback.getResult();
|
||||
VolumeInfo volume = context.vo;
|
||||
VolumeInfo volume = (VolumeInfo)context.vo;
|
||||
SnapshotInfo snapshot = context.snapshot;
|
||||
VolumeApiResult apiResult = new VolumeApiResult(volume);
|
||||
Event event = null;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user