use of org.ovirt.engine.core.common.action.ActionReturnValue in project ovirt-engine by oVirt.
the class UpdateVmPoolCommand method updatePoolVms.
private void updatePoolVms(List<VM> vmsInPool) {
// new latest value
boolean isUpdatedPoolLatest = getParameters().getVmStaticData().isUseLatestVersion();
vmTemplateHandler.lockVmTemplateInTransaction(getParameters().getVmStaticData().getVmtGuid(), getCompensationContext());
for (VM vm : vmsInPool) {
VmManagementParametersBase updateParams = new VmManagementParametersBase(vm);
updateParams.getVmStaticData().setUseLatestVersion(isUpdatedPoolLatest);
if (!isUpdatedPoolLatest) {
updateParams.getVmStaticData().setVmtGuid(getParameters().getVmStaticData().getVmtGuid());
}
ActionReturnValue result = runInternalActionWithTasksContext(ActionType.UpdateVm, updateParams, getLock());
getTaskIdList().addAll(result.getInternalVdsmTaskIdList());
setSucceeded(getSucceeded() && result.getSucceeded());
}
vmTemplateHandler.unlockVmTemplate(getParameters().getVmStaticData().getVmtGuid());
}
use of org.ovirt.engine.core.common.action.ActionReturnValue in project ovirt-engine by oVirt.
the class UpdateVmVersionCommand method executeVmCommand.
@Override
protected void executeVmCommand() {
// load vm init from db
vmHandler.updateVmInitFromDB(getVmTemplate(), false);
if (!VmHandler.copyData(getVmTemplate(), getVm().getStaticData())) {
return;
}
getParameters().setPreviousDiskOperatorAuthzPrincipalDbId(getIdOfDiskOperator());
getParameters().setVmStaticData(getVm().getStaticData());
if (getParameters().getUseLatestVersion() != null) {
getParameters().getVmStaticData().setUseLatestVersion(getParameters().getUseLatestVersion());
}
if (getVm().getVmPoolId() != null) {
getParameters().setVmPoolId(getVm().getVmPoolId());
ActionReturnValue result = runInternalActionWithTasksContext(ActionType.RemoveVmFromPool, buildRemoveVmFromPoolParameters(), getLock());
if (!result.getSucceeded()) {
log.error("Could not detach vm '{}' ({}) from vm-pool '{}'.", getVm().getName(), getVmId(), getVm().getVmPoolName());
return;
}
}
ActionReturnValue result = runInternalActionWithTasksContext(ActionType.RemoveVm, buildRemoveVmParameters(), getLock());
if (result.getSucceeded()) {
if (result.getHasAsyncTasks()) {
getReturnValue().getVdsmTaskIdList().addAll(result.getInternalVdsmTaskIdList());
} else {
endVmCommand();
}
setSucceeded(true);
}
}
use of org.ovirt.engine.core.common.action.ActionReturnValue in project ovirt-engine by oVirt.
the class UpdateClusterCommand method updateTemplates.
private boolean updateTemplates() {
for (VmTemplate template : templatesLockedForUpdate) {
// the object was loaded in before command execution started and thus the value may be outdated
template.setClusterCompatibilityVersion(getCluster().getCompatibilityVersion());
UpdateVmTemplateParameters parameters = new UpdateVmTemplateParameters(template);
// Locking by UpdateVmTemplate is disabled since templates are already locked in #getExclusiveLocks method.
parameters.setLockProperties(LockProperties.create(LockProperties.Scope.None));
parameters.setClusterLevelChangeFromVersion(oldCluster.getCompatibilityVersion());
updateRngDeviceIfNecessary(template.getId(), template.getCustomCompatibilityVersion(), parameters);
updateResumeBehavior(template);
final ActionReturnValue result = runInternalAction(ActionType.UpdateVmTemplate, parameters, cloneContextAndDetachFromParent());
if (!result.getSucceeded()) {
List<String> params = new ArrayList<>();
params.add("$action Update");
params.add("$type Template");
params.add(parseErrorMessage(result.getValidationMessages()));
List<String> messages = Backend.getInstance().getErrorsTranslator().translateErrorText(params);
failedUpgradeEntities.put(template.getName(), getFailedMessage(messages));
}
}
return true;
}
use of org.ovirt.engine.core.common.action.ActionReturnValue in project ovirt-engine by oVirt.
the class UpdateClusterCommand method executeCommand.
@Override
protected void executeCommand() {
Guid newMacPoolId = getNewMacPoolId();
moveMacs.migrateMacsToAnotherMacPool(oldCluster, newMacPoolId, getContext());
getCluster().setArchitecture(getArchitecture());
setDefaultSwitchTypeIfNeeded();
setDefaultFirewallTypeIfNeeded();
// TODO: This code should be revisited and proper compensation logic should be introduced here
checkMaxMemoryOverCommitValue();
if (!Objects.equals(oldCluster.getCompatibilityVersion(), getParameters().getCluster().getCompatibilityVersion())) {
String emulatedMachine = null;
// pick an UP host randomly - all should have latest compat version already if we passed validate.
for (VDS vds : allForCluster) {
if (vds.getStatus() == VDSStatus.Up) {
emulatedMachine = getEmulatedMachineOfHostInCluster(vds);
break;
}
}
if (emulatedMachine == null) {
getParameters().getCluster().setDetectEmulatedMachine(true);
} else {
getParameters().getCluster().setEmulatedMachine(emulatedMachine);
}
} else if (oldCluster.getArchitecture() != getCluster().getArchitecture()) {
// if architecture was changed, emulated machines must be updated when adding new host.
// At this point the cluster is empty and have changed CPU name
getParameters().getCluster().setDetectEmulatedMachine(true);
getParameters().getCluster().setEmulatedMachine(null);
}
if (getParameters().isForceResetEmulatedMachine()) {
getParameters().getCluster().setDetectEmulatedMachine(true);
}
boolean isKsmPolicyChanged = (getCluster().isKsmMergeAcrossNumaNodes() != getPrevCluster().isKsmMergeAcrossNumaNodes()) || (getCluster().isEnableKsm() != getPrevCluster().isEnableKsm());
clusterDao.update(getParameters().getCluster());
addOrUpdateAddtionalClusterFeatures();
if (!oldCluster.supportsGlusterService() && getCluster().supportsGlusterService()) {
// update gluster parameters on all hosts
updateGlusterHosts();
}
if (isAddedToStoragePool) {
for (VDS vds : allForCluster) {
VdsActionParameters parameters = new VdsActionParameters();
parameters.setVdsId(vds.getId());
ActionReturnValue addVdsSpmIdReturn = runInternalAction(ActionType.AddVdsSpmId, parameters, cloneContextAndDetachFromParent());
if (!addVdsSpmIdReturn.getSucceeded()) {
setSucceeded(false);
getReturnValue().setFault(addVdsSpmIdReturn.getFault());
return;
}
}
final NetworkCluster managementNetworkCluster = createManagementNetworkCluster();
networkClusterDao.save(managementNetworkCluster);
}
alertIfFencingDisabled();
if (isKsmPolicyChanged) {
momPolicyUpdatedEvent.fire(getCluster());
}
updateDefaultNetworkProvider();
// Call UpdateVmCommand on all VMs in the cluster to update defaults (i.e. DisplayType)
updateVms();
updateTemplates();
if (getCluster().getFirewallType() != getPrevCluster().getFirewallType()) {
markHostsForReinstall();
}
if (!failedUpgradeEntities.isEmpty()) {
logFailedUpgrades();
failValidation(Arrays.asList(EngineMessage.CLUSTER_CANNOT_UPDATE_CLUSTER_FAILED_TO_UPDATE_VMS), "$VmList " + StringUtils.join(failedUpgradeEntities.keySet(), ", "));
getReturnValue().setValid(false);
setSucceeded(false);
return;
}
if (!Objects.equals(oldCluster.getCompatibilityVersion(), getCluster().getCompatibilityVersion())) {
vmStaticDao.getAllByCluster(getCluster().getId()).forEach(this::updateClusterVersionInManager);
}
setSucceeded(true);
}
use of org.ovirt.engine.core.common.action.ActionReturnValue in project ovirt-engine by oVirt.
the class RemoveVmPoolCommand method removeVm.
private boolean removeVm(VM vm) {
RemoveVmFromPoolParameters removeVmFromPoolParameters = new RemoveVmFromPoolParameters(vm.getId(), false, false);
removeVmFromPoolParameters.setTransactionScopeOption(TransactionScopeOption.Suppress);
ActionReturnValue result = runInternalActionWithTasksContext(ActionType.RemoveVmFromPool, removeVmFromPoolParameters);
if (!result.getSucceeded()) {
return false;
}
result = runInternalAction(ActionType.RemoveVm, new RemoveVmParameters(vm.getId(), false), createRemoveVmStepContext(vm));
if (!result.getSucceeded()) {
return false;
}
vmsRemoved.add(vm.getId());
return true;
}
Aggregations