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;
});
}
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());
}
}
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());
}
}
}
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);
}
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;
}
Aggregations