use of org.ovirt.engine.core.common.errors.EngineException in project ovirt-engine by oVirt.
the class AddVmCommand method addVmImages.
protected boolean addVmImages() {
if (!vmDisksSource.getDiskTemplateMap().isEmpty()) {
if (getVm().getStatus() != VMStatus.Down) {
log.error("Cannot add images. VM is not Down");
throw new EngineException(EngineError.IRS_IMAGE_STATUS_ILLEGAL);
}
lockVM();
Collection<DiskImage> templateDisks = getImagesToCheckDestinationStorageDomains();
List<DiskImage> diskImages = DisksFilter.filterImageDisks(templateDisks, ONLY_NOT_SHAREABLE, ONLY_ACTIVE);
for (DiskImage image : diskImages) {
ActionReturnValue result = runInternalActionWithTasksContext(getDiskCreationCommandType(), buildDiskCreationParameters(image));
// if couldn't create snapshot then stop the transaction and the command
if (!result.getSucceeded()) {
throw new EngineException(result.getFault().getError());
} else {
getTaskIdList().addAll(result.getInternalVdsmTaskIdList());
DiskImage newImage = result.getActionReturnValue();
srcDiskIdToTargetDiskIdMapping.put(image.getId(), newImage.getId());
}
}
// Clone volumes for Cinder disk templates
addVmCinderDisks(templateDisks);
}
return true;
}
use of org.ovirt.engine.core.common.errors.EngineException in project ovirt-engine by oVirt.
the class AddVmTemplateCommand method executeCommand.
@Override
protected void executeCommand() {
// relevant only if template created from vm
if (isVmInDb) {
VmDynamic vmDynamic = vmDynamicDao.get(getVmId());
if (!isVmStatusValid(vmDynamic.getStatus())) {
throw new EngineException(EngineError.IRS_IMAGE_STATUS_ILLEGAL);
}
vmHandler.lockVm(vmDynamic, getCompensationContext());
}
setActionReturnValue(Guid.Empty);
// set template id as base for new templates
if (!isTemplateVersion()) {
getParameters().setBaseTemplateId(getVmTemplateId());
if (StringUtils.isEmpty(getParameters().getTemplateVersionName())) {
getParameters().setTemplateVersionName(BASE_TEMPLATE_VERSION_NAME);
}
} else {
// template version name should be the same as the base template name
setVmTemplateName(getBaseTemplate().getName());
String jobId = updateVmsJobHashMap.remove(getParameters().getBaseTemplateId());
if (!StringUtils.isEmpty(jobId)) {
log.info("Cancelling current running update for vms for base template id '{}'", getParameters().getBaseTemplateId());
try {
updateVmsJobMap.remove(getParameters().getBaseTemplateId()).cancel(true);
} catch (Exception e) {
log.warn("Failed deleting job '{}' at cancelRecoveryJob", jobId);
}
}
}
TransactionSupport.executeInNewTransaction(() -> {
addVmTemplateToDb();
getCompensationContext().stateChanged();
return null;
});
final Map<Guid, Guid> srcDeviceIdToTargetDeviceIdMapping = addAllTemplateDisks();
srcDeviceIdToTargetDeviceIdMapping.forEach((oldImageId, newImageId) -> addTemplateDiskVmElement(newImageId, oldImageId));
TransactionSupport.executeInNewTransaction(() -> {
addPermission();
addVmInterfaces(srcDeviceIdToTargetDeviceIdMapping);
Set<GraphicsType> graphicsToSkip = getParameters().getGraphicsDevices().keySet();
if (isVmInDb) {
getVmDeviceUtils().copyVmDevices(getVmId(), getVmTemplateId(), srcDeviceIdToTargetDeviceIdMapping, getParameters().isSoundDeviceEnabled(), getParameters().isConsoleEnabled(), getParameters().isVirtioScsiEnabled(), getVmDeviceUtils().hasMemoryBalloon(getVmId()), graphicsToSkip, false, getEffectiveCompatibilityVersion());
} else {
// for instance type and new template without a VM
getVmDeviceUtils().copyVmDevices(VmTemplateHandler.BLANK_VM_TEMPLATE_ID, getVmTemplateId(), srcDeviceIdToTargetDeviceIdMapping, getParameters().isSoundDeviceEnabled(), getParameters().isConsoleEnabled(), getParameters().isVirtioScsiEnabled(), Boolean.TRUE.equals(getParameters().isBalloonEnabled()), graphicsToSkip, false, getEffectiveCompatibilityVersion());
}
updateWatchdog(getVmTemplateId());
updateRngDevice(getVmTemplateId());
addGraphicsDevice();
setSucceeded(true);
return null;
});
if (getParameters().getTemplateType() != VmEntityType.INSTANCE_TYPE) {
vmHandler.warnMemorySizeLegal(getVmTemplate(), getVm().getCompatibilityVersion());
}
// means that there are no asynchronous tasks to execute and that we can
// end the command synchronously
pendingAsyncTasks = !getReturnValue().getVdsmTaskIdList().isEmpty() || !commandCoordinatorUtil.getChildCommandIds(getCommandId()).isEmpty();
if (!pendingAsyncTasks) {
endSuccessfullySynchronous();
}
}
use of org.ovirt.engine.core.common.errors.EngineException in project ovirt-engine by oVirt.
the class ImportVmFromExternalProviderCommand method createDisk.
protected Guid createDisk(DiskImage image) {
ActionReturnValue actionReturnValue = runInternalActionWithTasksContext(ActionType.AddDisk, buildAddDiskParameters(image));
if (!actionReturnValue.getSucceeded()) {
throw new EngineException(actionReturnValue.getFault().getError(), "Failed to create disk!");
}
getTaskIdList().addAll(actionReturnValue.getInternalVdsmTaskIdList());
return actionReturnValue.getActionReturnValue();
}
use of org.ovirt.engine.core.common.errors.EngineException in project ovirt-engine by oVirt.
the class ImportVmTemplateCommand method moveOrCopyAllImageGroups.
@Override
protected void moveOrCopyAllImageGroups(final Guid containerID, final Iterable<DiskImage> disks) {
TransactionSupport.executeInNewTransaction(() -> {
for (DiskImage disk : disks) {
Guid originalDiskId = newDiskIdForDisk.get(disk.getId()).getId();
Guid destinationDomain = imageToDestinationDomainMap.get(originalDiskId);
MoveOrCopyImageGroupParameters p = new MoveOrCopyImageGroupParameters(containerID, originalDiskId, newDiskIdForDisk.get(disk.getId()).getImageId(), disk.getId(), disk.getImageId(), destinationDomain, ImageOperation.Copy);
p.setParentCommand(getActionType());
p.setUseCopyCollapse(true);
p.setVolumeType(disk.getVolumeType());
p.setVolumeFormat(disk.getVolumeFormat());
p.setCopyVolumeType(CopyVolumeType.SharedVol);
p.setSourceDomainId(getParameters().getSourceDomainId());
p.setForceOverride(getParameters().getForceOverride());
p.setImportEntity(true);
p.setEntityInfo(new EntityInfo(VdcObjectType.VmTemplate, containerID));
p.setRevertDbOperationScope(ImageDbOperationScope.IMAGE);
for (DiskImage diskImage : getParameters().getVmTemplate().getDiskList()) {
if (originalDiskId.equals(diskImage.getId())) {
p.setQuotaId(diskImage.getQuotaId());
p.setDiskProfileId(diskImage.getDiskProfileId());
break;
}
}
p.setParentParameters(getParameters());
ActionReturnValue vdcRetValue = runInternalActionWithTasksContext(ActionType.CopyImageGroup, p);
if (!vdcRetValue.getSucceeded()) {
throw vdcRetValue.getFault() != null ? new EngineException(vdcRetValue.getFault().getError()) : new EngineException(EngineError.ENGINE);
}
getReturnValue().getVdsmTaskIdList().addAll(vdcRetValue.getInternalVdsmTaskIdList());
}
return null;
});
}
use of org.ovirt.engine.core.common.errors.EngineException in project ovirt-engine by oVirt.
the class GlusterGeoRepSyncJob method refreshGeoRepDataForVolume.
/**
* Exposing this to be called via BLL command in case of force sync of geo-replication session data for volume
*/
public void refreshGeoRepDataForVolume(final GlusterVolumeEntity volume) {
if (volume == null) {
throw new EngineException(EngineError.GlusterVolumeGeoRepSyncFailed, "No volume information");
}
Cluster cluster = clusterDao.get(volume.getClusterId());
discoverGeoRepDataInCluster(cluster, volume);
List<GlusterGeoRepSession> geoRepSessions = geoRepDao.getGeoRepSessions(volume.getId());
refreshGeoRepSessionStatusForSessions(cluster, geoRepSessions);
}
Aggregations