Search in sources :

Example 46 with EngineLock

use of org.ovirt.engine.core.utils.lock.EngineLock in project ovirt-engine by oVirt.

the class AutoStartVmsRunner method startFailedAutoStartVmsImpl.

private void startFailedAutoStartVmsImpl() {
    LinkedList<AutoStartVmToRestart> vmsToRemove = new LinkedList<>();
    final DateTime iterationStartTime = DateTime.getNow();
    final Date nextTimeOfRetryToRun = iterationStartTime.addSeconds(RETRY_TO_RUN_AUTO_START_VM_INTERVAL);
    final Date delayedTimeOfRetryToRun = iterationStartTime.addSeconds(DELAY_TO_RUN_AUTO_START_VM_INTERVAL);
    for (AutoStartVmToRestart autoStartVmToRestart : autoStartVmsToRestart) {
        // (we'll try again in the next iteration)
        if (!autoStartVmToRestart.isTimeToRun(iterationStartTime)) {
            continue;
        }
        Guid vmId = autoStartVmToRestart.getVmId();
        if (isNextRunConfiguration(vmId)) {
            // if the NextRun config exists then give the ProcessDownVmCommand time to apply it
            log.debug("NextRun config found for '{}' vm, the RunVm will be delayed", vmId);
            if (autoStartVmToRestart.delayNextTimeToRun(delayedTimeOfRetryToRun)) {
                // The priority is to run the VM even if the NextRun fails to be applied
                continue;
            }
            // Waiting for NextRun config is over, let's run the VM even with the non-applied Next-Run
            log.warn("Failed to wait for the NextRun config to be applied on vm '{}', trying to run the VM anyway", vmId);
        }
        EngineLock runVmLock = createEngineLockForRunVm(vmId);
        // acquired, skip for now  and we'll try again in the next iteration
        if (!acquireLock(runVmLock)) {
            log.debug("Could not acquire lock for auto starting VM '{}'", vmId);
            continue;
        }
        if (!isVmNeedsToBeAutoStarted(vmId)) {
            // if the VM doesn't need to be auto started anymore, release the lock and
            // remove the VM from the collection of VMs that should be auto started
            releaseLock(runVmLock);
            vmsToRemove.add(autoStartVmToRestart);
            continue;
        }
        if (runVm(vmId, runVmLock)) {
            // the VM reached WaitForLunch, so from now on this job is not responsible
            // to auto start it, future failures will be detected by the monitoring
            vmsToRemove.add(autoStartVmToRestart);
        } else {
            logFailedAttemptToRestartVm(vmId);
            if (!autoStartVmToRestart.scheduleNextTimeToRun(nextTimeOfRetryToRun)) {
                // if we could not schedule the next time to run the VM, it means
                // that we reached the maximum number of tried so don't try anymore
                vmsToRemove.add(autoStartVmToRestart);
                logFailureToRestartVm(vmId);
            }
        }
    }
    autoStartVmsToRestart.removeAll(vmsToRemove);
}
Also used : Guid(org.ovirt.engine.core.compat.Guid) LinkedList(java.util.LinkedList) DateTime(org.ovirt.engine.core.compat.DateTime) Date(java.util.Date) EngineLock(org.ovirt.engine.core.utils.lock.EngineLock)

Example 47 with EngineLock

use of org.ovirt.engine.core.utils.lock.EngineLock in project ovirt-engine by oVirt.

the class ChangeVDSClusterCommand method glusterHostAdd.

private boolean glusterHostAdd(Guid targetClusterId) {
    // condition.
    try (EngineLock lock = glusterUtil.acquireGlusterLockWait(targetClusterId)) {
        VDS runningHostInTargetCluster = glusterUtil.getUpServer(targetClusterId);
        if (runningHostInTargetCluster == null) {
            log.error("Cannot add host to target cluster, no host in Up status found in target cluster");
            handleError(-1, "No host in Up status found in target cluster");
            errorType = AuditLogType.GLUSTER_SERVER_ADD_FAILED;
            return false;
        }
        VDSReturnValue returnValue = runVdsCommand(VDSCommandType.AddGlusterServer, new AddGlusterServerVDSParameters(runningHostInTargetCluster.getId(), getVds().getHostName()));
        if (!returnValue.getSucceeded()) {
            handleVdsError(returnValue);
            errorType = AuditLogType.GLUSTER_SERVER_ADD_FAILED;
            return false;
        }
        return true;
    }
}
Also used : VDS(org.ovirt.engine.core.common.businessentities.VDS) AddGlusterServerVDSParameters(org.ovirt.engine.core.common.vdscommands.gluster.AddGlusterServerVDSParameters) EngineLock(org.ovirt.engine.core.utils.lock.EngineLock) VDSReturnValue(org.ovirt.engine.core.common.vdscommands.VDSReturnValue)

Example 48 with EngineLock

use of org.ovirt.engine.core.utils.lock.EngineLock in project ovirt-engine by oVirt.

the class ChangeVDSClusterCommand method glusterHostRemove.

private boolean glusterHostRemove(Guid sourceClusterId) {
    // condition.
    try (EngineLock lock = glusterUtil.acquireGlusterLockWait(sourceClusterId)) {
        VDS runningHostInSourceCluster = glusterUtil.getUpServer(sourceClusterId);
        if (runningHostInSourceCluster == null) {
            log.error("Cannot remove host from source cluster, no host in Up status found in source cluster");
            handleError(-1, "No host in Up status found in source cluster");
            errorType = AuditLogType.GLUSTER_SERVER_REMOVE_FAILED;
            return false;
        }
        VDSReturnValue returnValue = runVdsCommand(VDSCommandType.RemoveGlusterServer, new RemoveGlusterServerVDSParameters(runningHostInSourceCluster.getId(), getVds().getHostName(), false));
        if (!returnValue.getSucceeded()) {
            handleVdsError(returnValue);
            errorType = AuditLogType.GLUSTER_SERVER_REMOVE_FAILED;
            return false;
        }
        return true;
    }
}
Also used : VDS(org.ovirt.engine.core.common.businessentities.VDS) RemoveGlusterServerVDSParameters(org.ovirt.engine.core.common.vdscommands.gluster.RemoveGlusterServerVDSParameters) EngineLock(org.ovirt.engine.core.utils.lock.EngineLock) VDSReturnValue(org.ovirt.engine.core.common.vdscommands.VDSReturnValue)

Example 49 with EngineLock

use of org.ovirt.engine.core.utils.lock.EngineLock in project ovirt-engine by oVirt.

the class HostLocking method acquireMonitorLock.

public EngineLock acquireMonitorLock(VDS host, String lockReleaseMessage, Logger log) {
    Guid hostId = host.getId();
    Map<String, Pair<String, String>> exclusiveLocks = Collections.singletonMap(hostId.toString(), new Pair<>(LockingGroup.VDS_INIT.name(), ""));
    String closingMessage = calculateClosingMessage(lockReleaseMessage, host);
    EngineLock monitoringLock = new HostEngineLock(exclusiveLocks, null, closingMessage, log);
    log.info("Before acquiring lock in order to prevent monitoring for host '{}' from data-center '{}'", host.getName(), host.getStoragePoolName());
    lockManager.acquireLockWait(monitoringLock);
    log.info("Lock acquired, from now a monitoring of host will be skipped for host '{}' from data-center '{}'", host.getName(), host.getStoragePoolName());
    return monitoringLock;
}
Also used : Guid(org.ovirt.engine.core.compat.Guid) EngineLock(org.ovirt.engine.core.utils.lock.EngineLock) Pair(org.ovirt.engine.core.common.utils.Pair)

Example 50 with EngineLock

use of org.ovirt.engine.core.utils.lock.EngineLock in project ovirt-engine by oVirt.

the class GlusterSnapshotSyncJob method addOrUpdateSnapshotsConfig.

private void addOrUpdateSnapshotsConfig(Guid clusterId, GlusterSnapshotConfigInfo configInfo) {
    Cluster cluster = clusterDao.get(clusterId);
    try (EngineLock lock = acquireVolumeSnapshotLock(clusterId)) {
        for (Map.Entry<String, String> entry : configInfo.getClusterConfigOptions().entrySet()) {
            if (entry.getValue() != null) {
                addOrUpdateClusterConfig(cluster, entry.getKey(), entry.getValue());
            }
        }
    } catch (Exception e) {
        log.error("Exception ocuured while adding/updating snapshots configurations from CLI - '{}'", e.getMessage());
        log.debug("Exception", e);
        throw new EngineException(EngineError.GlusterSnapshotInfoFailedException, e.getLocalizedMessage());
    }
    Map<String, Map<String, String>> volumeConfigs = configInfo.getVolumeConfigOptions();
    for (Map.Entry<String, Map<String, String>> entry : volumeConfigs.entrySet()) {
        GlusterVolumeEntity volume = volumeDao.getByName(clusterId, entry.getKey());
        if (volume == null) {
            continue;
        }
        try (EngineLock lock = acquireVolumeSnapshotLock(volume.getId())) {
            Map<String, String> volumeConfig = entry.getValue();
            if (volumeConfig != null) {
                for (Map.Entry<String, String> entry1 : volumeConfig.entrySet()) {
                    if (entry.getValue() != null) {
                        addOrUpdateVolumeConfig(cluster, volume, entry1.getKey(), entry1.getValue());
                    }
                }
            }
        } catch (Exception e) {
            log.error("Exception ocuured while adding/updating snapshots configurations from CLI - '{}'", e.getMessage());
            log.debug("Exception", e);
            throw new EngineException(EngineError.GlusterSnapshotInfoFailedException, e.getLocalizedMessage());
        }
    }
}
Also used : GlusterVolumeEntity(org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeEntity) EngineException(org.ovirt.engine.core.common.errors.EngineException) Cluster(org.ovirt.engine.core.common.businessentities.Cluster) HashMap(java.util.HashMap) Map(java.util.Map) EngineLock(org.ovirt.engine.core.utils.lock.EngineLock) EngineException(org.ovirt.engine.core.common.errors.EngineException)

Aggregations

EngineLock (org.ovirt.engine.core.utils.lock.EngineLock)54 Pair (org.ovirt.engine.core.common.utils.Pair)13 VDS (org.ovirt.engine.core.common.businessentities.VDS)11 HashMap (java.util.HashMap)9 GlusterGeoRepSession (org.ovirt.engine.core.common.businessentities.gluster.GlusterGeoRepSession)9 GlusterVolumeEntity (org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeEntity)9 VDSReturnValue (org.ovirt.engine.core.common.vdscommands.VDSReturnValue)8 ActionReturnValue (org.ovirt.engine.core.common.action.ActionReturnValue)7 Guid (org.ovirt.engine.core.compat.Guid)6 GlusterVolumeGeoRepSessionParameters (org.ovirt.engine.core.common.action.gluster.GlusterVolumeGeoRepSessionParameters)5 EngineException (org.ovirt.engine.core.common.errors.EngineException)5 ArrayList (java.util.ArrayList)4 Map (java.util.Map)4 Date (java.util.Date)3 Set (java.util.Set)3 GlusterServerInfo (org.ovirt.engine.core.common.businessentities.gluster.GlusterServerInfo)3 GlusterVolumeSnapshotEntity (org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeSnapshotEntity)3 Network (org.ovirt.engine.core.common.businessentities.network.Network)3 Callable (java.util.concurrent.Callable)2 CommandContext (org.ovirt.engine.core.bll.context.CommandContext)2