Search in sources :

Example 51 with EngineLock

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

the class GlusterSyncJob method syncServers.

private void syncServers(Cluster cluster, List<VDS> existingServers, List<GlusterServerInfo> fetchedServers) {
    log.debug("Existing servers list returned '{}' comparing with fetched servers '{}'", existingServers, fetchedServers);
    boolean serverRemoved = false;
    Network glusterNetwork = findGlusterNetwork(cluster.getId());
    for (VDS server : existingServers) {
        GlusterServerInfo glusterServer = findGlusterServer(server, fetchedServers);
        if (isSyncableStatus(server.getStatus())) {
            if (glusterServer == null) {
                if (cluster.supportsVirtService()) {
                    // If the cluster supports virt service as well, we should not be removing any servers from it, even
                    // if they have been removed from the Gluster cluster using the Gluster cli, as they could
                    // potentially be
                    // used for running VMs. Will mark this server status as DISCONNECTED instead
                    log.debug("As cluster '{}' supports virt service as well, server '{}' detected as removed from glusterfs will not be removed from engine", cluster.getName(), server.getHostName());
                    setNonOperational(server);
                    continue;
                }
                log.info("Server '{}' has been removed directly using the gluster CLI. Removing it from engine as well.", server.getName());
                logUtil.logServerMessage(server, AuditLogType.GLUSTER_SERVER_REMOVED_FROM_CLI);
                try (EngineLock lock = glusterUtil.acquireGlusterLockWait(server.getId())) {
                    removeServerFromDb(server);
                    // if last but one server, reset alternate probed address for last server
                    checkAndResetKnownAddress(existingServers, server);
                    // remove the server from resource manager
                    runVdsCommand(VDSCommandType.RemoveVds, new RemoveVdsVDSCommandParameters(server.getId()));
                    serverRemoved = true;
                } catch (Exception e) {
                    log.error("Error while removing server '{}' from database: {}", server.getName(), e.getMessage());
                    log.debug("Exception", e);
                }
            } else if (server.getStatus() == VDSStatus.Up && glusterServer.getStatus() == PeerStatus.DISCONNECTED) {
                // check gluster is running, if down then move the host to Non-Operational
                VDSReturnValue returnValue = runVdsCommand(VDSCommandType.GlusterServersList, new VdsIdVDSCommandParametersBase(server.getId()));
                if (!returnValue.getSucceeded()) {
                    setNonOperational(server);
                }
            } else {
                // update correct status and check if all interfaces with gluster network have been peer probed.
                updateStatusAndpeerProbeOtherIface(glusterNetwork, server, glusterServer);
            }
        }
    }
    if (serverRemoved) {
        log.info("Servers detached using gluster CLI is removed from engine after inspecting the Gluster servers" + " list returned '{}' - comparing with db servers '{}'", fetchedServers, existingServers);
    }
}
Also used : RemoveVdsVDSCommandParameters(org.ovirt.engine.core.common.vdscommands.RemoveVdsVDSCommandParameters) VdsIdVDSCommandParametersBase(org.ovirt.engine.core.common.vdscommands.VdsIdVDSCommandParametersBase) VDS(org.ovirt.engine.core.common.businessentities.VDS) Network(org.ovirt.engine.core.common.businessentities.network.Network) 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 52 with EngineLock

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

the class GlusterGeoRepSyncJob method refreshGeoRepSessionStatusForSessions.

private void refreshGeoRepSessionStatusForSessions(final Cluster cluster, List<GlusterGeoRepSession> geoRepSessions) {
    if (CollectionUtils.isEmpty(geoRepSessions)) {
        return;
    }
    List<Callable<GlusterGeoRepSession>> geoRepSessionCalls = new ArrayList<>();
    for (final GlusterGeoRepSession geoRepSession : geoRepSessions) {
        geoRepSessionCalls.add(() -> {
            geoRepSession.setSessionDetails((ArrayList) getSessionDetailFromCLI(cluster, geoRepSession));
            return geoRepSession;
        });
    }
    List<GlusterGeoRepSession> updatedSessions = ThreadPoolUtil.invokeAll(geoRepSessionCalls);
    for (GlusterGeoRepSession updatedSession : updatedSessions) {
        if (updatedSession.getSessionDetails() == null) {
            log.info("Geo-replication session details not updated for session '{}' as there was error returning data from VDS", updatedSession.getSessionKey());
            continue;
        }
        try (EngineLock lock = acquireGeoRepSessionLock(updatedSession.getId())) {
            GlusterVolumeEntity masterVolume = volumeDao.getById(updatedSession.getMasterVolumeId());
            updateGeoRepStatus(masterVolume, updatedSession);
            geoRepDao.updateSession(updatedSession);
            updateSessionDetailsInDB(updatedSession);
        } catch (Exception e) {
            log.error("Error updating session details '{}' : '{}'", updatedSession.getSessionKey(), e.getMessage());
            log.debug("Exception", e);
        }
    }
}
Also used : GlusterVolumeEntity(org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeEntity) ArrayList(java.util.ArrayList) GlusterGeoRepSession(org.ovirt.engine.core.common.businessentities.gluster.GlusterGeoRepSession) Callable(java.util.concurrent.Callable) EngineLock(org.ovirt.engine.core.utils.lock.EngineLock) EngineException(org.ovirt.engine.core.common.errors.EngineException)

Example 53 with EngineLock

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

the class GlusterJob method acquireGeoRepSessionLock.

protected EngineLock acquireGeoRepSessionLock(Guid id) {
    EngineLock lock = new EngineLock(Collections.singletonMap(id.toString(), LockMessagesMatchUtil.makeLockingPair(LockingGroup.GLUSTER_GEOREP, EngineMessage.ACTION_TYPE_FAILED_GEOREP_SESSION_LOCKED)), null);
    lockManager.acquireLockWait(lock);
    return lock;
}
Also used : EngineLock(org.ovirt.engine.core.utils.lock.EngineLock)

Example 54 with EngineLock

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

the class GlusterUtil method acquireGlusterLockWait.

public EngineLock acquireGlusterLockWait(Guid clusterId) {
    Map<String, Pair<String, String>> exclusiveLocks = new HashMap<>();
    exclusiveLocks.put(clusterId.toString(), LockMessagesMatchUtil.makeLockingPair(LockingGroup.GLUSTER, EngineMessage.ACTION_TYPE_FAILED_GLUSTER_OPERATION_INPROGRESS));
    EngineLock lock = new EngineLock(exclusiveLocks, null);
    Injector.get(LockManager.class).acquireLockWait(lock);
    return lock;
}
Also used : LockManager(org.ovirt.engine.core.utils.lock.LockManager) HashMap(java.util.HashMap) 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