Search in sources :

Example 51 with Guid

use of org.ovirt.engine.core.compat.Guid in project ovirt-engine by oVirt.

the class AddVmTemplateCommand method createDiskDummiesForSpaceValidations.

/**
 * Space Validations are done using data extracted from the disks. The disks in question in this command
 * don't have all the needed data, and in order not to contaminate the command's data structures, an alter
 * one is created specifically for this validation - hence dummy.
 */
private List<DiskImage> createDiskDummiesForSpaceValidations(Collection<DiskImage> disksList) {
    List<DiskImage> dummies = new ArrayList<>(disksList.size());
    for (DiskImage image : disksList) {
        Guid targetSdId = diskInfoDestinationMap.get(image.getId()).getStorageIds().get(0);
        DiskImage dummy = imagesHandler.createDiskImageWithExcessData(image, targetSdId);
        dummies.add(dummy);
    }
    return dummies;
}
Also used : ArrayList(java.util.ArrayList) Guid(org.ovirt.engine.core.compat.Guid) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage)

Example 52 with Guid

use of org.ovirt.engine.core.compat.Guid in project ovirt-engine by oVirt.

the class AddVmTemplateCommand method getPermissionCheckSubjects.

/**
 * in case of non-existing cluster the backend query will return a null
 */
@Override
public List<PermissionSubject> getPermissionCheckSubjects() {
    if (permissionCheckSubject == null) {
        permissionCheckSubject = new ArrayList<>();
        if (getParameters().getTemplateType() != VmEntityType.INSTANCE_TYPE) {
            Guid storagePoolId = getCluster() == null ? null : getCluster().getStoragePoolId();
            permissionCheckSubject.add(new PermissionSubject(storagePoolId, VdcObjectType.StoragePool, getActionType().getActionGroup()));
            // host-specific parameters can be changed by administration role only
            if (!new HashSet<>(getParameters().getMasterVm().getDedicatedVmForVdsList()).equals(new HashSet<>(getVm().getDedicatedVmForVdsList())) || !StringUtils.isEmpty(getParameters().getMasterVm().getCpuPinning())) {
                permissionCheckSubject.add(new PermissionSubject(storagePoolId, VdcObjectType.StoragePool, ActionGroup.EDIT_ADMIN_TEMPLATE_PROPERTIES));
            }
        } else {
            permissionCheckSubject.add(new PermissionSubject(Guid.SYSTEM, VdcObjectType.System, getActionType().getActionGroup()));
        }
    }
    return permissionCheckSubject;
}
Also used : PermissionSubject(org.ovirt.engine.core.bll.utils.PermissionSubject) Guid(org.ovirt.engine.core.compat.Guid)

Example 53 with Guid

use of org.ovirt.engine.core.compat.Guid 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();
    }
}
Also used : GraphicsType(org.ovirt.engine.core.common.businessentities.GraphicsType) VmDynamic(org.ovirt.engine.core.common.businessentities.VmDynamic) EngineException(org.ovirt.engine.core.common.errors.EngineException) Guid(org.ovirt.engine.core.compat.Guid) EngineException(org.ovirt.engine.core.common.errors.EngineException)

Example 54 with Guid

use of org.ovirt.engine.core.compat.Guid in project ovirt-engine by oVirt.

the class ImportVmCommandBase method createDiskDummiesForSpaceValidations.

/**
 * Space Validations are done using data extracted from the disks. The disks in question in this command
 * don't have all the needed data, and in order not to contaminate the command's data structures, an alter
 * one is created specifically fo this validation - hence dummy.
 */
protected List<DiskImage> createDiskDummiesForSpaceValidations(List<DiskImage> disksList) {
    List<DiskImage> dummies = new ArrayList<>(disksList.size());
    for (DiskImage image : disksList) {
        Guid targetSdId = imageToDestinationDomainMap.get(image.getId());
        DiskImage dummy = imagesHandler.createDiskImageWithExcessData(image, targetSdId);
        dummies.add(dummy);
    }
    return dummies;
}
Also used : ArrayList(java.util.ArrayList) Guid(org.ovirt.engine.core.compat.Guid) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage)

Example 55 with Guid

use of org.ovirt.engine.core.compat.Guid in project ovirt-engine by oVirt.

the class ImportVmCommandBase method generateNewDiskId.

/**
 * Cloning a new disk with a new generated id, with the same parameters as <code>disk</code>. Also
 * adding the disk to <code>newDiskGuidForDisk</code> map, so we will be able to link between the new cloned disk
 * and the old disk id.
 *
 * @param disk
 *            - The disk which is about to be cloned
 */
protected Guid generateNewDiskId(DiskImage disk) {
    Guid newGuidForDisk = Guid.newGuid();
    // Copy the disk so it will preserve the old disk id and image id.
    newDiskIdForDisk.put(newGuidForDisk, DiskImage.copyOf(disk));
    disk.setId(newGuidForDisk);
    disk.setImageId(Guid.newGuid());
    return newGuidForDisk;
}
Also used : Guid(org.ovirt.engine.core.compat.Guid)

Aggregations

Guid (org.ovirt.engine.core.compat.Guid)1431 ArrayList (java.util.ArrayList)330 Test (org.junit.Test)322 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)219 HashMap (java.util.HashMap)211 List (java.util.List)167 VM (org.ovirt.engine.core.common.businessentities.VM)144 Map (java.util.Map)118 VDS (org.ovirt.engine.core.common.businessentities.VDS)117 IdQueryParameters (org.ovirt.engine.core.common.queries.IdQueryParameters)106 HashSet (java.util.HashSet)102 StorageDomain (org.ovirt.engine.core.common.businessentities.StorageDomain)89 Pair (org.ovirt.engine.core.common.utils.Pair)79 ActionReturnValue (org.ovirt.engine.core.common.action.ActionReturnValue)77 StoragePool (org.ovirt.engine.core.common.businessentities.StoragePool)72 VDSReturnValue (org.ovirt.engine.core.common.vdscommands.VDSReturnValue)70 Cluster (org.ovirt.engine.core.common.businessentities.Cluster)69 QueryReturnValue (org.ovirt.engine.core.common.queries.QueryReturnValue)57 ActionType (org.ovirt.engine.core.common.action.ActionType)56 Set (java.util.Set)52