Search in sources :

Example 41 with EngineLock

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

the class VdsEventListener method restartVmsWithLease.

@Override
public void restartVmsWithLease(List<Guid> vmIds) {
    if (vmIds.isEmpty()) {
        return;
    }
    EngineLock engineLock = new EngineLock(Collections.emptyMap(), Collections.emptyMap());
    ThreadPoolUtil.execute(() -> {
        for (Guid vmId : vmIds) {
            resourceManagerProvider.get().removeAsyncRunningVm(vmId);
            backend.runInternalAction(ActionType.RunVm, buildRunVmParameters(vmId), ExecutionHandler.createInternalJobContext(engineLock));
        }
    });
}
Also used : Guid(org.ovirt.engine.core.compat.Guid) EngineLock(org.ovirt.engine.core.utils.lock.EngineLock)

Example 42 with EngineLock

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

the class RemoveVdsCommand method glusterHostRemove.

private void glusterHostRemove() {
    if (clusterHasMultipleHosts() && !hasVolumeBricksOnServer()) {
        try (EngineLock lock = glusterUtil.acquireGlusterLockWait(getClusterId())) {
            VDSReturnValue returnValue = runVdsCommand(VDSCommandType.RemoveGlusterServer, new RemoveGlusterServerVDSParameters(upServer.getId(), getVds().getHostName(), getParameters().isForceAction()));
            // If the host is already removed Cluster using Gluster CLI then we can setSucceeded to true.
            setSucceeded(returnValue.getSucceeded() || EngineError.GlusterHostIsNotPartOfCluster == returnValue.getVdsError().getCode());
            if (!getSucceeded()) {
                if (returnValue.getVdsError().getCode() == EngineError.GlusterHostRemoveFailedException) {
                    List<GlusterServerInfo> glusterServers = getGlusterPeers(upServer);
                    if (glusterServers != null) {
                        if (!glusterUtil.isHostExists(glusterServers, getVds())) {
                            setSucceeded(true);
                        }
                    }
                }
                if (!getSucceeded()) {
                    getReturnValue().getFault().setError(returnValue.getVdsError().getCode());
                    getReturnValue().getFault().setMessage(returnValue.getVdsError().getMessage());
                    errorType = AuditLogType.GLUSTER_SERVER_REMOVE_FAILED;
                    return;
                }
            }
            // if last but one host in cluster, update the last host's known addresses
            if (clusterUtils.getServerCount(getClusterId()) == 2) {
                removeOtherKnowAddressesForGlusterServer(upServer.getId());
            }
        }
    }
}
Also used : RemoveGlusterServerVDSParameters(org.ovirt.engine.core.common.vdscommands.gluster.RemoveGlusterServerVDSParameters) GlusterServerInfo(org.ovirt.engine.core.common.businessentities.gluster.GlusterServerInfo) EngineLock(org.ovirt.engine.core.utils.lock.EngineLock) VDSReturnValue(org.ovirt.engine.core.common.vdscommands.VDSReturnValue)

Example 43 with EngineLock

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

the class InitGlusterCommandHelper method initGlusterPeerProcess.

/**
 * This method executes a "gluster peer probe" to add the newly added host to the cluster - this
 * is done only if there's another UP server in cluster and the host being added is not already
 * part of the UP server's peer list.
 * Also, acquiring a wait lock only during a gluster peer process (wait as there's periodic job that also
 * acquires lock.
 */
private boolean initGlusterPeerProcess(VDS vds) {
    // condition.
    try (EngineLock lock = glusterUtil.acquireGlusterLockWait(vds.getClusterId())) {
        Map<String, String> customLogValues = new HashMap<>();
        List<VDS> vdsList = vdsDao.getAllForClusterWithStatus(vds.getClusterId(), VDSStatus.Up);
        // If the cluster already having Gluster servers, get an up server
        if (!vdsList.isEmpty()) {
            // If new server is not part of the existing gluster peers, add into peer group
            Optional<VDS> potentialUpServer = vdsList.stream().filter(existingVds -> !vds.getId().equals(existingVds.getId())).findFirst();
            if (potentialUpServer.isPresent()) {
                VDS upServer = potentialUpServer.get();
                List<GlusterServerInfo> glusterServers = getGlusterPeers(upServer);
                customLogValues.put("Server", upServer.getHostName());
                if (glusterServers.isEmpty()) {
                    customLogValues.put("Command", "gluster peer status");
                    setNonOperational(vds, NonOperationalReason.GLUSTER_COMMAND_FAILED, customLogValues);
                    return false;
                } else if (!glusterUtil.isHostExists(glusterServers, vds)) {
                    if (!glusterPeerProbe(vds, upServer.getId(), vds.getHostName())) {
                        customLogValues.put("Command", "gluster peer probe " + vds.getHostName());
                        setNonOperational(vds, NonOperationalReason.GLUSTER_COMMAND_FAILED, customLogValues);
                        return false;
                    }
                    int retries = 0;
                    while (retries < getMaxRetriesGlusterProbeStatus()) {
                        // though gluster peer probe succeeds, it takes some time for the host to be
                        // listed as a peer. Return success only when the host is acknowledged as peer
                        // from another upServer.
                        VDS newUpServer = getNewUpServer(vds, upServer);
                        if (newUpServer == null) {
                            // there's no other up server. so there's no issue with peer status results
                            return true;
                        }
                        List<GlusterServerInfo> newGlusterServers = getGlusterPeers(newUpServer);
                        if (!glusterUtil.isHostExists(newGlusterServers, vds)) {
                            log.info("Failed to find host '{}' in gluster peer list from '{}' on attempt {}", vds, newUpServer, ++retries);
                            // if num of attempts done
                            if (retries == getMaxRetriesGlusterProbeStatus()) {
                                customLogValues.put("Command", "gluster peer status " + vds.getHostName());
                                setNonOperational(vds, NonOperationalReason.GLUSTER_COMMAND_FAILED, customLogValues);
                                return false;
                            }
                            try {
                                // give time for gluster peer probe to propogate to servers.
                                Thread.sleep(1000);
                            } catch (Exception e) {
                                log.error(e.getMessage());
                                break;
                            }
                        } else {
                            return true;
                        }
                    }
                }
            }
        }
        return true;
    }
}
Also used : GlusterServerDao(org.ovirt.engine.core.dao.gluster.GlusterServerDao) ResourceManager(org.ovirt.engine.core.vdsbroker.ResourceManager) Guid(org.ovirt.engine.core.compat.Guid) EngineException(org.ovirt.engine.core.common.errors.EngineException) LoggerFactory(org.slf4j.LoggerFactory) NonOperationalReason(org.ovirt.engine.core.common.businessentities.NonOperationalReason) HashMap(java.util.HashMap) VDSParametersBase(org.ovirt.engine.core.common.vdscommands.VDSParametersBase) Singleton(javax.inject.Singleton) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) ActionType(org.ovirt.engine.core.common.action.ActionType) GlusterServer(org.ovirt.engine.core.common.businessentities.gluster.GlusterServer) PeerStatus(org.ovirt.engine.core.common.businessentities.gluster.PeerStatus) GlusterUtil(org.ovirt.engine.core.bll.utils.GlusterUtil) AddGlusterServerVDSParameters(org.ovirt.engine.core.common.vdscommands.gluster.AddGlusterServerVDSParameters) VdsDao(org.ovirt.engine.core.dao.VdsDao) BackendInternal(org.ovirt.engine.core.bll.interfaces.BackendInternal) Map(java.util.Map) Config(org.ovirt.engine.core.common.config.Config) VdsIdVDSCommandParametersBase(org.ovirt.engine.core.common.vdscommands.VdsIdVDSCommandParametersBase) VdsActionParameters(org.ovirt.engine.core.common.action.VdsActionParameters) Logger(org.slf4j.Logger) GlusterServerInfo(org.ovirt.engine.core.common.businessentities.gluster.GlusterServerInfo) AuditLogDirector(org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogDirector) VDSReturnValue(org.ovirt.engine.core.common.vdscommands.VDSReturnValue) EngineLock(org.ovirt.engine.core.utils.lock.EngineLock) ConfigValues(org.ovirt.engine.core.common.config.ConfigValues) SyncGlusterStorageDevicesParameter(org.ovirt.engine.core.common.action.gluster.SyncGlusterStorageDevicesParameter) AuditLogable(org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogable) List(java.util.List) VDSStatus(org.ovirt.engine.core.common.businessentities.VDSStatus) Optional(java.util.Optional) AuditLogType(org.ovirt.engine.core.common.AuditLogType) VDSCommandType(org.ovirt.engine.core.common.vdscommands.VDSCommandType) Validate(org.apache.commons.lang.Validate) GlusterEventFactory(org.ovirt.engine.core.bll.utils.GlusterEventFactory) VDS(org.ovirt.engine.core.common.businessentities.VDS) VDS(org.ovirt.engine.core.common.businessentities.VDS) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) GlusterServerInfo(org.ovirt.engine.core.common.businessentities.gluster.GlusterServerInfo) EngineLock(org.ovirt.engine.core.utils.lock.EngineLock) EngineException(org.ovirt.engine.core.common.errors.EngineException)

Example 44 with EngineLock

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

the class ActivateVdsCommand method executeCommand.

@Override
protected void executeCommand() {
    final VDS vds = getVds();
    try (EngineLock monitoringLock = acquireMonitorLock("Activate host")) {
        executionHandler.updateSpecificActionJobCompleted(vds.getId(), ActionType.MaintenanceVds, false);
        setSucceeded(setVdsStatus(VDSStatus.Unassigned).getSucceeded());
        if (getSucceeded()) {
            TransactionSupport.executeInNewTransaction(() -> {
                // set network to operational / non-operational
                List<Network> networks = networkDao.getAllForCluster(vds.getClusterId());
                networkClusterHelper.setStatus(vds.getClusterId(), networks);
                return null;
            });
            // Start glusterd service on the node, which would haven been stopped due to maintenance
            if (vds.getClusterSupportsGlusterService()) {
                runVdsCommand(VDSCommandType.ManageGlusterService, new GlusterServiceVDSParameters(vds.getId(), Arrays.asList("glusterd"), "restart"));
            }
        }
    }
}
Also used : VDS(org.ovirt.engine.core.common.businessentities.VDS) Network(org.ovirt.engine.core.common.businessentities.network.Network) GlusterServiceVDSParameters(org.ovirt.engine.core.common.vdscommands.gluster.GlusterServiceVDSParameters) EngineLock(org.ovirt.engine.core.utils.lock.EngineLock)

Example 45 with EngineLock

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

the class CommandBase method acquireLockAndWait.

private void acquireLockAndWait() {
    // if commandLock is null then we acquire new lock, otherwise probably we got lock from caller command.
    if (context.getLock() == null) {
        Map<String, Pair<String, String>> exclusiveLocks = getExclusiveLocks();
        if (exclusiveLocks != null) {
            EngineLock lock = new EngineLock(exclusiveLocks, null);
            log.info("Before acquiring and wait lock '{}'", lock);
            lockManager.acquireLockWait(lock);
            context.withLock(lock);
            log.info("Lock-wait acquired to object '{}'", lock);
        }
    }
}
Also used : EngineLock(org.ovirt.engine.core.utils.lock.EngineLock) Pair(org.ovirt.engine.core.common.utils.Pair)

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