Arik Hadas has uploaded a new change for review. Change subject: core: change RunVm structure ......................................................................
core: change RunVm structure Change-Id: Ida4e626e0fc138439f3d0c6762968f323a45d8f0 Signed-off-by: Arik Hadas <aha...@redhat.com> --- M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RunVmCommand.java M backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/RunVmCommandTest.java 2 files changed, 35 insertions(+), 30 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/43/22643/1 diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RunVmCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RunVmCommand.java index 9512320..810bb5c 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RunVmCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RunVmCommand.java @@ -213,31 +213,16 @@ protected void runVm() { setActionReturnValue(VMStatus.Down); - VMStatus status = null; - try { - if (connectLunDisks(getVdsId())) { - status = createVm(); - ExecutionHandler.setAsyncJob(getExecutionContext(), true); - } - } catch(VdcBLLException e) { - // if the returned exception is such that shoudn't trigger the re-run process, - // re-throw it. otherwise, continue (the vm will be down and a re-run will be triggered) - switch (e.getErrorCode()) { - case Done: // should never get here with errorCode = 'Done' though - case exist: - case VDS_NETWORK_ERROR: // probably wrong xml format sent. - case PROVIDER_FAILURE: - throw e; - default: - log.warnFormat("Failed to run VM {0}: {1}", getVmName(), e.getMessage()); - } + handleCreateVmResult(createVm()); + } - } finally { - freeLock(); - } + protected void handleCreateVmResult(VMStatus status) { + freeLock(); setActionReturnValue(status); if (status != null && (status.isRunning() || status == VMStatus.RestoringState)) { + // Don't use the memory from the active snapshot anymore if there's a chance that disks were changed + memoryFromSnapshotIrrelevant = true; setSucceeded(true); } else { // Try to rerun Vm on different vds no need to log the command because it is @@ -248,13 +233,13 @@ } } - @Override protected void executeVmCommand() { setActionReturnValue(VMStatus.Down); initVm(); initVds(); + initVmPostInitVds(); perform(); } @@ -441,7 +426,7 @@ setSucceeded(true); } - protected VMStatus createVm() { + protected void initVmPostInitVds() { final String cdPath = chooseCd(); if (StringUtils.isNotEmpty(cdPath)) { log.infoFormat("Running VM with attached cd {0}", cdPath); @@ -460,16 +445,34 @@ if (!StringUtils.isEmpty(getVm().getKernelUrl())) { getVm().setKernelUrl(getIsoPrefixFilePath(getVm().getKernelUrl())); } + } - VMStatus vmStatus = (VMStatus) getBackend() - .getResourceManager() - .RunAsyncVdsCommand(VDSCommandType.CreateVm, buildCreateVmParameters(), this).getReturnValue(); + protected VMStatus createVm() { + try { + if (connectLunDisks(getVdsId())) { + VMStatus vmStatus = (VMStatus) getBackend() + .getResourceManager() + .RunAsyncVdsCommand(VDSCommandType.CreateVm, buildCreateVmParameters(), this).getReturnValue(); - // Don't use the memory from the active snapshot anymore if there's a chance that disks were changed - memoryFromSnapshotIrrelevant = vmStatus.isRunning() || vmStatus == VMStatus.RestoringState; + ExecutionHandler.setAsyncJob(getExecutionContext(), true); + // After VM was create (or not), we can remove the quota vds group memory. + return vmStatus; + } + } catch(VdcBLLException e) { + // if the returned exception is such that shoudn't trigger the re-run process, + // re-throw it. otherwise, continue (the vm will be down and a re-run will be triggered) + switch (e.getErrorCode()) { + case Done: // should never get here with errorCode = 'Done' though + case exist: + case VDS_NETWORK_ERROR: // probably wrong xml format sent. + case PROVIDER_FAILURE: + throw e; + default: + log.warnFormat("Failed to run VM {0}: {1}", getVmName(), e.getMessage()); + } + } - // After VM was create (or not), we can remove the quota vds group memory. - return vmStatus; + return null; } diff --git a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/RunVmCommandTest.java b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/RunVmCommandTest.java index df4ea24..825c17f 100644 --- a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/RunVmCommandTest.java +++ b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/RunVmCommandTest.java @@ -280,6 +280,8 @@ // Set parameter command.getVm().setInitrdUrl(initrd); command.getVm().setKernelUrl(kernel); + command.initVmPostInitVds(); + doReturn(true).when(command).connectLunDisks(any(Guid.class)); command.createVm(); // Check Vm -- To view, visit http://gerrit.ovirt.org/22643 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ida4e626e0fc138439f3d0c6762968f323a45d8f0 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Arik Hadas <aha...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches