Search in sources :

Example 26 with ActionReturnValue

use of org.ovirt.engine.core.common.action.ActionReturnValue 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;
    });
}
Also used : MoveOrCopyImageGroupParameters(org.ovirt.engine.core.common.action.MoveOrCopyImageGroupParameters) ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) EntityInfo(org.ovirt.engine.core.common.asynctasks.EntityInfo) EngineException(org.ovirt.engine.core.common.errors.EngineException) Guid(org.ovirt.engine.core.compat.Guid) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage)

Example 27 with ActionReturnValue

use of org.ovirt.engine.core.common.action.ActionReturnValue in project ovirt-engine by oVirt.

the class ImportVmCommand method moveOrCopyAllImageGroups.

protected void moveOrCopyAllImageGroups(Guid containerID, Iterable<DiskImage> disks) {
    for (DiskImage disk : disks) {
        ActionReturnValue vdcRetValue = runInternalActionWithTasksContext(ActionType.CopyImageGroup, buildMoveOrCopyImageGroupParametersForDisk(disk, containerID));
        if (!vdcRetValue.getSucceeded()) {
            throw new EngineException(vdcRetValue.getFault().getError(), "Failed to copy disk!");
        }
        // TODO: Currently REST-API doesn't support coco for async commands, remove when bug 1199011 fixed
        getTaskIdList().addAll(vdcRetValue.getVdsmTaskIdList());
    }
}
Also used : ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) EngineException(org.ovirt.engine.core.common.errors.EngineException) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage)

Example 28 with ActionReturnValue

use of org.ovirt.engine.core.common.action.ActionReturnValue in project ovirt-engine by oVirt.

the class ImportVmCommand method copyAllMemoryImages.

private void copyAllMemoryImages(Guid containerId) {
    Set<Guid> handledMemoryDisks = new HashSet<>();
    for (Snapshot snapshot : getVm().getSnapshots()) {
        if (!snapshot.containsMemory()) {
            continue;
        }
        Guid memoryDiskId = snapshot.getMemoryDiskId();
        if (!handledMemoryDisks.contains(memoryDiskId)) {
            handledMemoryDisks.add(memoryDiskId);
            // copy the memory dump image
            ActionReturnValue vdcRetValue = runInternalActionWithTasksContext(ActionType.CopyImageGroup, buildMoveOrCopyImageGroupParametersForMemoryDumpImage(containerId, memoryDiskDomainMap.get(memoryDiskId), memoryDiskId, getMemoryDiskImageId(memoryDiskId)));
            if (!vdcRetValue.getSucceeded()) {
                throw new EngineException(vdcRetValue.getFault().getError(), "Failed to copy memory image");
            }
            // TODO: Currently REST-API doesn't support coco for async commands, remove when bug 1199011 fixed
            getTaskIdList().addAll(vdcRetValue.getVdsmTaskIdList());
        }
        Guid confDiskId = snapshot.getMetadataDiskId();
        if (!handledMemoryDisks.contains(confDiskId)) {
            handledMemoryDisks.add(confDiskId);
            // copy the memory configuration (of the VM) image
            ActionReturnValue vdcRetValue = runInternalActionWithTasksContext(ActionType.CopyImageGroup, buildMoveOrCopyImageGroupParametersForMemoryConfImage(containerId, memoryDiskDomainMap.get(confDiskId), confDiskId, getMemoryDiskImageId(confDiskId)));
            if (!vdcRetValue.getSucceeded()) {
                throw new EngineException(vdcRetValue.getFault().getError(), "Failed to copy metadata image");
            }
            // TODO: Currently REST-API doesn't support coco for async commands, remove when bug 1199011 fixed
            getTaskIdList().addAll(vdcRetValue.getVdsmTaskIdList());
        }
    }
}
Also used : Snapshot(org.ovirt.engine.core.common.businessentities.Snapshot) ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) EngineException(org.ovirt.engine.core.common.errors.EngineException) Guid(org.ovirt.engine.core.compat.Guid) HashSet(java.util.HashSet)

Example 29 with ActionReturnValue

use of org.ovirt.engine.core.common.action.ActionReturnValue in project ovirt-engine by oVirt.

the class CreateGlusterVolumeGeoRepSessionCommand method executeCommand.

@Override
protected void executeCommand() {
    boolean rootSession = getParameters().getUserName().equalsIgnoreCase("root");
    boolean succeeded = true;
    Set<Guid> remoteServerIds = getServerIds(remoteServersSet);
    Guid slaveHostId = getParameters().getSlaveHostId();
    if (!rootSession) {
        ActionReturnValue completeMountBrokerSetupOnSlaveInternalAction = backend.runInternalAction(ActionType.SetupGlusterGeoRepMountBrokerInternal, new SetUpMountBrokerParameters(vdsDao.get(slaveHostId).getClusterId(), new HashSet<>(Collections.singletonList(getParameters().getSlaveHostId())), getParameters().getSlaveVolumeName(), getParameters().getUserName(), getParameters().getUserGroup()));
        succeeded = evaluateReturnValue(AuditLogType.GLUSTER_GEOREP_SETUP_MOUNT_BROKER_FAILED, completeMountBrokerSetupOnSlaveInternalAction);
        remoteServerIds.remove(slaveHostId);
        if (succeeded) {
            auditLogDirector.log(this, AuditLogType.GLUSTER_SETUP_GEOREP_MOUNT_BROKER);
            if (!remoteServerIds.isEmpty()) {
                ActionReturnValue mountBrokerPartialSetupInternalAction = backend.runInternalAction(ActionType.SetupGlusterGeoRepMountBrokerInternal, new SetUpMountBrokerParameters(vdsDao.get(slaveHostId).getClusterId(), remoteServerIds, getParameters().getSlaveVolumeName(), getParameters().getUserName()));
                succeeded = evaluateReturnValue(AuditLogType.GLUSTER_GEOREP_SETUP_MOUNT_BROKER_FAILED, mountBrokerPartialSetupInternalAction);
                if (succeeded) {
                    auditLogDirector.log(this, AuditLogType.GLUSTER_SETUP_GEOREP_MOUNT_BROKER);
                }
            }
        }
    }
    if (succeeded) {
        remoteServerIds.add(slaveHostId);
        ActionReturnValue setUpPasswordLessSSHinternalAction = runInternalAction(ActionType.SetUpPasswordLessSSHInternal, new SetUpPasswordLessSSHParameters(upServer.getClusterId(), remoteServerIds, getParameters().getUserName()));
        succeeded = evaluateReturnValue(errorType, setUpPasswordLessSSHinternalAction);
        if (succeeded) {
            auditLogDirector.log(this, AuditLogType.SET_UP_PASSWORDLESS_SSH);
            VDSReturnValue createVdsReturnValue = runVdsCommand(VDSCommandType.CreateGlusterVolumeGeoRepSession, new GlusterVolumeGeoRepSessionVDSParameters(upServer.getId(), getGlusterVolumeName(), vdsDao.get(slaveHostId).getHostName(), getParameters().getSlaveVolumeName(), getParameters().getUserName(), getParameters().isForce()));
            succeeded = evaluateReturnValue(AuditLogType.GLUSTER_GEOREP_SESSION_CREATE_FAILED, createVdsReturnValue);
            if (succeeded) {
                glusterGeoRepSyncJob.refreshGeoRepDataForVolume(getGlusterVolume());
            }
        }
    }
    setSucceeded(succeeded);
}
Also used : SetUpMountBrokerParameters(org.ovirt.engine.core.common.action.gluster.SetUpMountBrokerParameters) ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) GlusterVolumeGeoRepSessionVDSParameters(org.ovirt.engine.core.common.vdscommands.gluster.GlusterVolumeGeoRepSessionVDSParameters) Guid(org.ovirt.engine.core.compat.Guid) SetUpPasswordLessSSHParameters(org.ovirt.engine.core.common.action.gluster.SetUpPasswordLessSSHParameters) HashSet(java.util.HashSet) VDSReturnValue(org.ovirt.engine.core.common.vdscommands.VDSReturnValue)

Example 30 with ActionReturnValue

use of org.ovirt.engine.core.common.action.ActionReturnValue in project ovirt-engine by oVirt.

the class CreateGlusterVolumeSnapshotCommand method pauseAndCreateSnapshotForGeoRepSessions.

private boolean pauseAndCreateSnapshotForGeoRepSessions() {
    if (georepSessions != null && georepSessions.size() > 0) {
        for (GlusterGeoRepSession session : georepSessions) {
            final GlusterVolumeEntity slaveVolume = glusterVolumeDao.getById(session.getSlaveVolumeId());
            if (slaveVolume == null) {
                // Continue to other geo-rep sessions and pause them for snapshot purpose
                continue;
            }
            VDS slaveUpServer = glusterUtil.getRandomUpServer(slaveVolume.getClusterId());
            if (slaveUpServer == null) {
                handleVdsError(AuditLogType.GLUSTER_VOLUME_SNAPSHOT_CREATE_FAILED, "No up server found in slave cluster of geo-rep session");
                setSucceeded(false);
                return false;
            }
            // Pause the geo-rep session if required
            if (!(session.getStatus() == GeoRepSessionStatus.CREATED || session.getStatus() == GeoRepSessionStatus.PAUSED || session.getStatus() == GeoRepSessionStatus.STOPPED)) {
                ActionReturnValue sessionPauseRetVal = null;
                try (EngineLock lock = acquireEngineLock(slaveVolume.getId(), LockingGroup.GLUSTER_SNAPSHOT)) {
                    sessionPauseRetVal = runInternalAction(ActionType.PauseGlusterVolumeGeoRepSession, new GlusterVolumeGeoRepSessionParameters(getGlusterVolumeId(), session.getId()));
                }
                if (sessionPauseRetVal != null && !sessionPauseRetVal.getSucceeded()) {
                    handleVdsErrors(AuditLogType.GLUSTER_VOLUME_GEO_REP_PAUSE_FAILED, sessionPauseRetVal.getExecuteFailedMessages());
                    setSucceeded(false);
                    return false;
                }
                session.setStatus(GeoRepSessionStatus.PAUSED);
                enginePausedSessions.add(session);
            }
            // Create snapshot for slave volume
            VDSReturnValue snapCreationRetVal = runVdsCommand(VDSCommandType.CreateGlusterVolumeSnapshot, new CreateGlusterVolumeSnapshotVDSParameters(slaveUpServer.getId(), session.getSlaveVolumeName(), snapshot.getSnapshotName(), snapshot.getDescription(), force));
            if (!snapCreationRetVal.getSucceeded()) {
                handleVdsError(AuditLogType.GLUSTER_VOLUME_SNAPSHOT_CREATE_FAILED, snapCreationRetVal.getVdsError().getMessage());
                setSucceeded(false);
                return false;
            } else {
                // Persist the snapshot details
                GlusterVolumeSnapshotEntity slaveVolumeSnapshot = (GlusterVolumeSnapshotEntity) snapCreationRetVal.getReturnValue();
                slaveVolumeSnapshot.setClusterId(slaveVolume.getClusterId());
                slaveVolumeSnapshot.setVolumeId(slaveVolume.getId());
                slaveVolumeSnapshot.setDescription(snapshot.getDescription());
                slaveVolumeSnapshot.setStatus(GlusterSnapshotStatus.DEACTIVATED);
                glusterVolumeSnapshotDao.save(slaveVolumeSnapshot);
                // check if the snapshot soft limit reached now for the volume and alert
                glusterUtil.alertVolumeSnapshotLimitsReached(slaveVolume);
            }
        }
    }
    return true;
}
Also used : CreateGlusterVolumeSnapshotVDSParameters(org.ovirt.engine.core.common.vdscommands.gluster.CreateGlusterVolumeSnapshotVDSParameters) VDS(org.ovirt.engine.core.common.businessentities.VDS) ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) GlusterVolumeEntity(org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeEntity) GlusterVolumeGeoRepSessionParameters(org.ovirt.engine.core.common.action.gluster.GlusterVolumeGeoRepSessionParameters) GlusterVolumeSnapshotEntity(org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeSnapshotEntity) GlusterGeoRepSession(org.ovirt.engine.core.common.businessentities.gluster.GlusterGeoRepSession) EngineLock(org.ovirt.engine.core.utils.lock.EngineLock) VDSReturnValue(org.ovirt.engine.core.common.vdscommands.VDSReturnValue)

Aggregations

ActionReturnValue (org.ovirt.engine.core.common.action.ActionReturnValue)293 ArrayList (java.util.ArrayList)57 Guid (org.ovirt.engine.core.compat.Guid)55 ActionParametersBase (org.ovirt.engine.core.common.action.ActionParametersBase)50 Test (org.junit.Test)37 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)27 ActionType (org.ovirt.engine.core.common.action.ActionType)26 EngineException (org.ovirt.engine.core.common.errors.EngineException)25 VDS (org.ovirt.engine.core.common.businessentities.VDS)23 HashSet (java.util.HashSet)16 QueryReturnValue (org.ovirt.engine.core.common.queries.QueryReturnValue)15 ExecutionException (java.util.concurrent.ExecutionException)13 StorageDomain (org.ovirt.engine.core.common.businessentities.StorageDomain)13 CinderDisk (org.ovirt.engine.core.common.businessentities.storage.CinderDisk)13 StorageServerConnectionParametersBase (org.ovirt.engine.core.common.action.StorageServerConnectionParametersBase)12 StoragePool (org.ovirt.engine.core.common.businessentities.StoragePool)12 List (java.util.List)11 ChangeVDSClusterParameters (org.ovirt.engine.core.common.action.ChangeVDSClusterParameters)11 VM (org.ovirt.engine.core.common.businessentities.VM)11 UICommand (org.ovirt.engine.ui.uicommonweb.UICommand)11