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) {
|
protected Answer cloneVolume(DataObject template, DataObject volume) {
|
||||||
CopyCommand cmd = new CopyCommand(template.getTO(), volume.getTO(), 0);
|
CopyCommand cmd = new CopyCommand(template.getTO(), volume.getTO(), 0);
|
||||||
StoragePool pool = (StoragePool)volume.getDataStore();
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Answer answer = storageMgr.sendToPool(pool, null, cmd);
|
EndPoint ep = this.selector.select(volume.getDataStore());
|
||||||
|
Answer answer = ep.sendMessage(cmd);
|
||||||
return answer;
|
return answer;
|
||||||
} catch (StorageUnavailableException e) {
|
} catch (Exception e) {
|
||||||
s_logger.debug("Failed to send to storage pool", e);
|
s_logger.debug("Failed to send to storage pool", e);
|
||||||
throw new CloudRuntimeException("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) {
|
destData.getType() == DataObjectType.SNAPSHOT) {
|
||||||
answer = copySnapshot(srcData, destData);
|
answer = copySnapshot(srcData, destData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (answer != null && !answer.getResult()) {
|
||||||
|
errMsg = answer.getDetails();
|
||||||
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
s_logger.debug("copy failed", e);
|
s_logger.debug("copy failed", e);
|
||||||
errMsg = e.toString();
|
errMsg = e.toString();
|
||||||
}
|
}
|
||||||
CopyCommandResult result = new CopyCommandResult(null, answer);
|
CopyCommandResult result = new CopyCommandResult(null, answer);
|
||||||
if (!answer.getResult()) {
|
result.setResult(errMsg);
|
||||||
result.setResult(answer.getDetails());
|
|
||||||
}
|
|
||||||
callback.complete(result);
|
callback.complete(result);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -240,9 +240,11 @@ public class VolumeTest extends CloudStackTestNGBase {
|
|||||||
List<HostVO> hosts = new ArrayList<HostVO>();
|
List<HostVO> hosts = new ArrayList<HostVO>();
|
||||||
hosts.add(this.host);
|
hosts.add(this.host);
|
||||||
Mockito.when(resourceMgr.listAllUpAndEnabledHosts((Type) Mockito.any(), Mockito.anyLong(), Mockito.anyLong(), Mockito.anyLong())).thenReturn(hosts);
|
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());
|
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), 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() {
|
public DataStore createPrimaryDataStore() {
|
||||||
|
|||||||
@ -401,12 +401,12 @@ public class VolumeServiceImpl implements VolumeService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private class CreateVolumeFromBaseImageContext<T> extends AsyncRpcConext<T> {
|
private class CreateVolumeFromBaseImageContext<T> extends AsyncRpcConext<T> {
|
||||||
private final VolumeObject vo;
|
private final DataObject vo;
|
||||||
private final AsyncCallFuture<VolumeApiResult> future;
|
private final AsyncCallFuture<VolumeApiResult> future;
|
||||||
private final DataStore primaryStore;
|
private final DataStore primaryStore;
|
||||||
private final DataObject templateOnStore;
|
private final DataObject templateOnStore;
|
||||||
private final SnapshotInfo snapshot;
|
private final SnapshotInfo snapshot;
|
||||||
public CreateVolumeFromBaseImageContext(AsyncCompletionCallback<T> callback, VolumeObject vo,
|
public CreateVolumeFromBaseImageContext(AsyncCompletionCallback<T> callback, DataObject vo,
|
||||||
DataStore primaryStore,
|
DataStore primaryStore,
|
||||||
DataObject templateOnStore,
|
DataObject templateOnStore,
|
||||||
AsyncCallFuture<VolumeApiResult> future, SnapshotInfo snapshot) {
|
AsyncCallFuture<VolumeApiResult> future, SnapshotInfo snapshot) {
|
||||||
@ -426,14 +426,13 @@ public class VolumeServiceImpl implements VolumeService {
|
|||||||
|
|
||||||
@DB
|
@DB
|
||||||
protected void createVolumeFromBaseImageAsync(VolumeInfo volume, DataObject templateOnPrimaryStore, PrimaryDataStore pd, AsyncCallFuture<VolumeApiResult> future) {
|
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);
|
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);
|
motionSrv.copyAsync(context.templateOnStore, volumeOnPrimaryStorage, caller);
|
||||||
return;
|
return;
|
||||||
@ -441,9 +440,9 @@ public class VolumeServiceImpl implements VolumeService {
|
|||||||
|
|
||||||
@DB
|
@DB
|
||||||
protected Void createVolumeFromBaseImageCallBack(AsyncCallbackDispatcher<VolumeServiceImpl, CopyCommandResult> callback, CreateVolumeFromBaseImageContext<VolumeApiResult> context) {
|
protected Void createVolumeFromBaseImageCallBack(AsyncCallbackDispatcher<VolumeServiceImpl, CopyCommandResult> callback, CreateVolumeFromBaseImageContext<VolumeApiResult> context) {
|
||||||
VolumeObject vo = context.vo;
|
DataObject vo = context.vo;
|
||||||
CopyCommandResult result = callback.getResult();
|
CopyCommandResult result = callback.getResult();
|
||||||
VolumeApiResult volResult = new VolumeApiResult(vo);
|
VolumeApiResult volResult = new VolumeApiResult((VolumeObject)vo);
|
||||||
|
|
||||||
if (result.isSuccess()) {
|
if (result.isSuccess()) {
|
||||||
vo.processEvent(Event.OperationSuccessed, result.getAnswer());
|
vo.processEvent(Event.OperationSuccessed, result.getAnswer());
|
||||||
@ -516,7 +515,7 @@ public class VolumeServiceImpl implements VolumeService {
|
|||||||
protected Void createVolumeFromSnapshotCallback(AsyncCallbackDispatcher<VolumeServiceImpl, CopyCommandResult> callback,
|
protected Void createVolumeFromSnapshotCallback(AsyncCallbackDispatcher<VolumeServiceImpl, CopyCommandResult> callback,
|
||||||
CreateVolumeFromBaseImageContext<VolumeApiResult> context) {
|
CreateVolumeFromBaseImageContext<VolumeApiResult> context) {
|
||||||
CopyCommandResult result = callback.getResult();
|
CopyCommandResult result = callback.getResult();
|
||||||
VolumeInfo volume = context.vo;
|
VolumeInfo volume = (VolumeInfo)context.vo;
|
||||||
SnapshotInfo snapshot = context.snapshot;
|
SnapshotInfo snapshot = context.snapshot;
|
||||||
VolumeApiResult apiResult = new VolumeApiResult(volume);
|
VolumeApiResult apiResult = new VolumeApiResult(volume);
|
||||||
Event event = null;
|
Event event = null;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user