Search in sources :

Example 6 with GlusterServerInfo

use of org.ovirt.engine.core.common.businessentities.gluster.GlusterServerInfo in project ovirt-engine by oVirt.

the class GetAddedGlusterServersQuery method getAddedGlusterServers.

private Map<String, String> getAddedGlusterServers(List<GlusterServerInfo> glusterServers) {
    Map<String, String> serversAndFingerprint = new HashMap<>();
    for (GlusterServerInfo server : glusterServers) {
        if (server.getStatus() == PeerStatus.CONNECTED && !serverExists(server)) {
            String fingerprint = null;
            QueryReturnValue returnValue;
            if (getParameters().isServerKeyFingerprintRequired()) {
                returnValue = runInternalQuery(QueryType.GetServerSSHKeyFingerprint, new ServerParameters(server.getHostnameOrIp()));
                if (returnValue != null && returnValue.getSucceeded() && returnValue.getReturnValue() != null) {
                    fingerprint = returnValue.getReturnValue().toString();
                }
            }
            serversAndFingerprint.put(server.getHostnameOrIp(), fingerprint == null ? "" : fingerprint);
        }
    }
    return serversAndFingerprint;
}
Also used : ServerParameters(org.ovirt.engine.core.common.queries.ServerParameters) QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) HashMap(java.util.HashMap) GlusterServerInfo(org.ovirt.engine.core.common.businessentities.gluster.GlusterServerInfo)

Example 7 with GlusterServerInfo

use of org.ovirt.engine.core.common.businessentities.gluster.GlusterServerInfo 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 8 with GlusterServerInfo

use of org.ovirt.engine.core.common.businessentities.gluster.GlusterServerInfo 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 9 with GlusterServerInfo

use of org.ovirt.engine.core.common.businessentities.gluster.GlusterServerInfo 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)

Aggregations

GlusterServerInfo (org.ovirt.engine.core.common.businessentities.gluster.GlusterServerInfo)9 ArrayList (java.util.ArrayList)4 VDSReturnValue (org.ovirt.engine.core.common.vdscommands.VDSReturnValue)4 VDS (org.ovirt.engine.core.common.businessentities.VDS)3 VdsIdVDSCommandParametersBase (org.ovirt.engine.core.common.vdscommands.VdsIdVDSCommandParametersBase)3 EngineLock (org.ovirt.engine.core.utils.lock.EngineLock)3 HashMap (java.util.HashMap)2 Guid (org.ovirt.engine.core.compat.Guid)2 AuditLogable (org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogable)2 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Inject (javax.inject.Inject)1 Singleton (javax.inject.Singleton)1 Validate (org.apache.commons.lang.Validate)1 BackendInternal (org.ovirt.engine.core.bll.interfaces.BackendInternal)1 GlusterEventFactory (org.ovirt.engine.core.bll.utils.GlusterEventFactory)1 GlusterUtil (org.ovirt.engine.core.bll.utils.GlusterUtil)1 AuditLogType (org.ovirt.engine.core.common.AuditLogType)1 ActionType (org.ovirt.engine.core.common.action.ActionType)1