use of org.ovirt.engine.core.utils.lock.EngineLock in project ovirt-engine by oVirt.
the class RestoreGlusterVolumeSnapshotCommand method restoreSlaveVolumesToSnapshot.
private boolean restoreSlaveVolumesToSnapshot(List<GlusterGeoRepSession> geoRepSessions) {
for (GlusterGeoRepSession session : geoRepSessions) {
GlusterVolumeEntity slaveVolume = glusterVolumeDao.getById(session.getSlaveVolumeId());
if (slaveVolume == null) {
// continue with other sessions and try to pause
continue;
}
VDS slaveUpServer = glusterUtil.getRandomUpServer(slaveVolume.getClusterId());
if (slaveUpServer == null) {
handleVdsError(AuditLogType.GLUSTER_VOLUME_SNAPSHOT_RESTORE_FAILED, EngineError.NoUpServerFoundInRemoteCluster.name());
setSucceeded(false);
return false;
}
try (EngineLock lock = acquireEngineLock(slaveVolume.getClusterId(), LockingGroup.GLUSTER_SNAPSHOT)) {
if (!restoreVolumeToSnapshot(slaveUpServer.getId(), slaveVolume, getSnapshot().getSnapshotName())) {
return false;
}
}
}
return true;
}
use of org.ovirt.engine.core.utils.lock.EngineLock in project ovirt-engine by oVirt.
the class RestoreGlusterVolumeSnapshotCommand method resumeGeoRepSessions.
private boolean resumeGeoRepSessions(List<GlusterGeoRepSession> geoRepSessions) {
for (GlusterGeoRepSession session : geoRepSessions) {
GlusterVolumeEntity slaveVolume = glusterVolumeDao.getById(session.getSlaveVolumeId());
if (slaveVolume == null) {
// continue with other sessions and try to pause
continue;
}
try (EngineLock lock = acquireGeoRepSessionLock(session.getId())) {
ActionReturnValue retVal = runInternalAction(ActionType.ResumeGeoRepSession, new GlusterVolumeGeoRepSessionParameters(getGlusterVolumeId(), session.getId()));
if (!retVal.getSucceeded()) {
handleVdsError(AuditLogType.GLUSTER_VOLUME_GEO_REP_RESUME_FAILED, retVal.getExecuteFailedMessages().toString());
setSucceeded(false);
return false;
}
}
}
return true;
}
use of org.ovirt.engine.core.utils.lock.EngineLock in project ovirt-engine by oVirt.
the class RestoreGlusterVolumeSnapshotCommand method stopGeoReplicationSessions.
private boolean stopGeoReplicationSessions(List<GlusterGeoRepSession> geoRepSessions) {
for (GlusterGeoRepSession session : geoRepSessions) {
if (!(session.getStatus() == GeoRepSessionStatus.STOPPED || session.getStatus() == GeoRepSessionStatus.CREATED)) {
try (EngineLock lock = acquireGeoRepSessionLock(session.getId())) {
ActionReturnValue retVal = runInternalAction(ActionType.StopGeoRepSession, new GlusterVolumeGeoRepSessionParameters(getGlusterVolumeId(), session.getId()));
if (!retVal.getSucceeded()) {
handleVdsError(AuditLogType.GEOREP_SESSION_STOP_FAILED, retVal.getExecuteFailedMessages().toString());
setSucceeded(false);
return false;
}
session.setStatus(GeoRepSessionStatus.STOPPED);
engineStoppedSessions.add(session);
}
}
}
return true;
}
use of org.ovirt.engine.core.utils.lock.EngineLock in project ovirt-engine by oVirt.
the class RestoreGlusterVolumeSnapshotCommand method executeCommand.
@Override
public void executeCommand() {
Boolean tranRetVal = TransactionSupport.executeInNewTransaction(() -> {
if (georepSessions != null) {
// Stop the geo-replication session
if (!stopGeoReplicationSessions(georepSessions)) {
return false;
}
// Stop the slave volumes
if (!stopSlaveVolumes(georepSessions)) {
return false;
}
// Restore the slave volumes to said the snapshot
if (!restoreSlaveVolumesToSnapshot(georepSessions)) {
return false;
}
}
return true;
});
if (!tranRetVal) {
return;
}
// Stop the master volume
if (!stopVolume(getGlusterVolume())) {
if (!georepSessions.isEmpty()) {
handleVdsError(AuditLogType.GLUSTER_MASTER_VOLUME_STOP_FAILED_DURING_SNAPSHOT_RESTORE, EngineError.FailedToStopMasterVolumeDuringVolumeSnapshotRestore.name());
}
return;
}
// Restore the master volume to the said snapshot
try (EngineLock lock = acquireEngineLock(getGlusterVolume().getClusterId(), LockingGroup.GLUSTER_SNAPSHOT)) {
if (!restoreVolumeToSnapshot(upServer.getId(), getGlusterVolume(), getParameters().getSnapshotName())) {
if (!georepSessions.isEmpty()) {
handleVdsError(AuditLogType.GLUSTER_MASTER_VOLUME_SNAPSHOT_RESTORE_FAILED, EngineError.FailedToRestoreMasterVolumeDuringVolumeSnapshotRestore.name());
}
return;
}
}
// Start the slave volumes
if (engineStoppedSessions != null && !startSlaveVolumes(engineStoppedSessions)) {
return;
}
// Start the master volume
if (!startVolume(getGlusterVolumeId())) {
return;
}
if (engineStoppedSessions != null) {
// Start the geo-replication sessions
if (!startGeoRepSessions(engineStoppedSessions)) {
return;
}
// Resume the geo-replication sessions
if (!resumeGeoRepSessions(engineStoppedSessions)) {
return;
}
}
setSucceeded(true);
}
use of org.ovirt.engine.core.utils.lock.EngineLock in project ovirt-engine by oVirt.
the class CommandBase method acquireLockInternal.
protected boolean acquireLockInternal() {
// if commandLock is null then we acquire new lock, otherwise probably we got lock from caller command.
if (context.getLock() == null) {
EngineLock lock = buildLock();
if (lock != null) {
Pair<Boolean, Set<String>> lockAcquireResult = lockManager.acquireLock(lock);
if (lockAcquireResult.getFirst()) {
log.info("Lock Acquired to object '{}'", lock);
context.withLock(lock);
} else {
log.info("Failed to Acquire Lock to object '{}'", lock);
getReturnValue().getValidationMessages().addAll(extractVariableDeclarations(lockAcquireResult.getSecond()));
return false;
}
}
}
return true;
}
Aggregations