Search in sources :

Example 16 with GlusterServerHook

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

the class GlusterHookMapper method map.

@Mapping(from = org.ovirt.engine.core.common.businessentities.gluster.GlusterServerHook.class, to = org.ovirt.engine.api.model.GlusterServerHook.class)
public static org.ovirt.engine.api.model.GlusterServerHook map(GlusterServerHook serverHookEntity) {
    org.ovirt.engine.api.model.GlusterServerHook serverHookModel = new org.ovirt.engine.api.model.GlusterServerHook();
    if (serverHookEntity.getServerId() != null) {
        serverHookModel.setHost(new Host());
        serverHookModel.getHost().setId(serverHookEntity.getServerId().toString());
    }
    return serverHookModel;
}
Also used : GlusterServerHook(org.ovirt.engine.core.common.businessentities.gluster.GlusterServerHook) Host(org.ovirt.engine.api.model.Host)

Example 17 with GlusterServerHook

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

the class AddGlusterHookCommand method validate.

@Override
protected boolean validate() {
    if (!super.validate()) {
        return false;
    }
    if (getMissingServerHooks().isEmpty()) {
        addValidationMessage(EngineMessage.ACTION_TYPE_FAILED_GLUSTER_HOOK_NO_CONFLICT_SERVERS);
        return false;
    }
    for (GlusterServerHook serverHook : getMissingServerHooks()) {
        VDS vds = vdsDao.get(serverHook.getServerId());
        if (vds == null || vds.getStatus() != VDSStatus.Up) {
            String vdsName = vds != null ? vds.getName() : GlusterConstants.NO_SERVER;
            setVdsName(vdsName);
            addValidationMessage(EngineMessage.ACTION_TYPE_FAILED_SERVER_STATUS_NOT_UP);
            addValidationMessage(String.format("$%1$s %2$s", "VdsName", vdsName));
            return false;
        }
    }
    return true;
}
Also used : VDS(org.ovirt.engine.core.common.businessentities.VDS) GlusterServerHook(org.ovirt.engine.core.common.businessentities.gluster.GlusterServerHook)

Example 18 with GlusterServerHook

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

the class AddGlusterHookCommand method executeCommand.

@Override
protected void executeCommand() {
    entity = getGlusterHook();
    addCustomValue(GlusterConstants.HOOK_NAME, entity.getName());
    final boolean hookEnabled = entity.getStatus() == GlusterHookStatus.ENABLED;
    List<Callable<Pair<GlusterServerHook, VDSReturnValue>>> taskList = new ArrayList<>();
    for (final GlusterServerHook serverHook : getMissingServerHooks()) {
        taskList.add(() -> {
            VDSReturnValue returnValue;
            returnValue = runVdsCommand(VDSCommandType.AddGlusterHook, new GlusterHookVDSParameters(serverHook.getServerId(), entity.getGlusterCommand(), entity.getStage(), entity.getName(), entity.getContent(), entity.getChecksum(), hookEnabled));
            return new Pair<>(serverHook, returnValue);
        });
    }
    if (!taskList.isEmpty()) {
        List<Pair<GlusterServerHook, VDSReturnValue>> pairResults = ThreadPoolUtil.invokeAll(taskList);
        for (Pair<GlusterServerHook, VDSReturnValue> pairResult : pairResults) {
            VDSReturnValue retValue = pairResult.getSecond();
            if (!retValue.getSucceeded()) {
                errors.add(retValue.getVdsError().getMessage());
            } else {
                // hook added successfully, so remove from gluster server hooks table
                glusterHooksDao.removeGlusterServerHook(pairResult.getFirst().getHookId(), pairResult.getFirst().getServerId());
            }
        }
    }
    if (errors.size() > 0) {
        setSucceeded(false);
        errorType = AuditLogType.GLUSTER_HOOK_ADD_FAILED;
        handleVdsErrors(getAuditLogTypeValue(), errors);
        addCustomValue(GlusterConstants.FAILURE_MESSAGE, StringUtils.join(errors, System.lineSeparator()));
    } else {
        setSucceeded(true);
    }
    if (getSucceeded()) {
        entity.removeMissingConflict();
        updateGlusterHook(entity);
    }
}
Also used : GlusterServerHook(org.ovirt.engine.core.common.businessentities.gluster.GlusterServerHook) ArrayList(java.util.ArrayList) GlusterHookVDSParameters(org.ovirt.engine.core.common.vdscommands.gluster.GlusterHookVDSParameters) Callable(java.util.concurrent.Callable) VDSReturnValue(org.ovirt.engine.core.common.vdscommands.VDSReturnValue) Pair(org.ovirt.engine.core.common.utils.Pair)

Example 19 with GlusterServerHook

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

the class GlusterHookSyncJob method syncExistingHooks.

private void syncExistingHooks(Map<String, GlusterHookEntity> existingHookMap, Map<Guid, Set<VDS>> existingHookServersMap, Map<String, Integer> existingHookConflictMap, Set<VDS> upServers) {
    // Add missing conflicts for hooks that are missing on any one of the servers
    for (Map.Entry<Guid, Set<VDS>> entry : existingHookServersMap.entrySet()) {
        if (entry.getValue().size() == upServers.size()) {
            // hook is present in all of the servers. Nothing to do
            continue;
        }
        // Get servers on which the hooks are missing.
        Set<VDS> hookMissingServers = new HashSet<>(upServers);
        hookMissingServers.removeAll(entry.getValue());
        for (VDS missingServer : hookMissingServers) {
            GlusterServerHook missingServerHook = new GlusterServerHook();
            missingServerHook.setHookId(entry.getKey());
            missingServerHook.setServerId(missingServer.getId());
            missingServerHook.setStatus(GlusterHookStatus.MISSING);
            hooksDao.saveOrUpdateGlusterServerHook(missingServerHook);
        }
        // get the hook from database, as we don't have the hookkey for it
        GlusterHookEntity hookEntity = hooksDao.getById(entry.getKey());
        if (existingHookMap.get(hookEntity.getHookKey()) != null) {
            // if it was an already existing hook, get the hook with
            // updated conflict values from map
            hookEntity = existingHookMap.get(hookEntity.getHookKey());
        }
        hookEntity.addMissingConflict();
        existingHookMap.put(hookEntity.getHookKey(), hookEntity);
    }
    // Update conflict status for existing hooks
    for (GlusterHookEntity hook : existingHookMap.values()) {
        // Check if aggregated conflict status is different from existing hook
        Integer oldConflictStatus = existingHookConflictMap.get(hook.getHookKey());
        if (!hook.getConflictStatus().equals(oldConflictStatus)) {
            log.debug("Conflict change detected for hook '{}' in cluster '{}' ", hook.getHookKey(), hook.getClusterId());
            logMessage(hook.getClusterId(), hook.getHookKey(), AuditLogType.GLUSTER_HOOK_CONFLICT_DETECTED);
            hooksDao.updateGlusterHookConflictStatus(hook.getId(), hook.getConflictStatus());
        }
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) VDS(org.ovirt.engine.core.common.businessentities.VDS) GlusterHookEntity(org.ovirt.engine.core.common.businessentities.gluster.GlusterHookEntity) GlusterServerHook(org.ovirt.engine.core.common.businessentities.gluster.GlusterServerHook) Guid(org.ovirt.engine.core.compat.Guid) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 20 with GlusterServerHook

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

the class GlusterHookSyncJob method addOrUpdateHooks.

private void addOrUpdateHooks(Guid clusterId, List<Pair<VDS, VDSReturnValue>> pairResults) {
    try {
        List<GlusterHookEntity> existingHooks = hooksDao.getByClusterId(clusterId);
        List<Callable<Pair<GlusterHookEntity, VDSReturnValue>>> contentTasksList = new ArrayList<>();
        Map<String, GlusterHookEntity> existingHookMap = new HashMap<>();
        Map<Guid, Set<VDS>> existingHookServersMap = new HashMap<>();
        Map<String, Integer> existingHookConflictMap = new HashMap<>();
        for (final GlusterHookEntity hook : existingHooks) {
            existingHookServersMap.put(hook.getId(), new HashSet<>());
            existingHookConflictMap.put(hook.getHookKey(), hook.getConflictStatus());
            // initialize hook conflict status as this is to be computed again
            hook.setConflictStatus(0);
            existingHookMap.put(hook.getHookKey(), hook);
        }
        Set<String> fetchedHookKeyList = new HashSet<>();
        Map<String, GlusterHookEntity> newHookMap = new HashMap<>();
        List<GlusterServerHook> newServerHooks = new ArrayList<>();
        List<GlusterServerHook> updatedServerHooks = new ArrayList<>();
        Set<VDS> upServers = new HashSet<>();
        for (Pair<VDS, VDSReturnValue> pairResult : pairResults) {
            final VDS server = pairResult.getFirst();
            upServers.add(server);
            if (!pairResult.getSecond().getSucceeded()) {
                log.info("Failed to get list of hooks from server '{}' with error: {}", server, pairResult.getSecond().getVdsError().getMessage());
                logUtil.logServerMessage(server, AuditLogType.GLUSTER_HOOK_LIST_FAILED);
                continue;
            }
            @SuppressWarnings("unchecked") List<GlusterHookEntity> fetchedHooks = (List<GlusterHookEntity>) pairResult.getSecond().getReturnValue();
            for (GlusterHookEntity fetchedHook : fetchedHooks) {
                String key = fetchedHook.getHookKey();
                fetchedHookKeyList.add(key);
                GlusterHookEntity existingHook = existingHookMap.get(key);
                if (existingHook != null) {
                    updateHookServerMap(existingHookServersMap, existingHook.getId(), server);
                    GlusterServerHook serverHook = hooksDao.getGlusterServerHook(existingHook.getId(), server.getId());
                    Integer conflictStatus = getConflictStatus(existingHook, fetchedHook);
                    // aggregate conflicts across hooks
                    existingHook.setConflictStatus(conflictStatus | existingHookMap.get(key).getConflictStatus());
                    if (conflictStatus != 0) {
                        // there is a conflict. we need to either add or update entry in server hook
                        if (serverHook == null) {
                            newServerHooks.add(buildServerHook(server.getId(), existingHook.getId(), fetchedHook));
                        } else {
                            if (!(serverHook.getChecksum().equals(fetchedHook.getChecksum()) && serverHook.getContentType().equals(fetchedHook.getContentType()) && serverHook.getStatus().equals(fetchedHook.getStatus()))) {
                                log.info("Updating existing server hook '{}' in server '{}' ", key, server);
                                serverHook.setChecksum(fetchedHook.getChecksum());
                                serverHook.setContentType(fetchedHook.getContentType());
                                serverHook.setStatus(fetchedHook.getStatus());
                                updatedServerHooks.add(serverHook);
                            }
                        }
                    }
                } else {
                    GlusterHookEntity newHook = newHookMap.get(key);
                    if (newHook == null) {
                        newHook = fetchedHook;
                        newHook.setClusterId(clusterId);
                        newHook.setId(Guid.newGuid());
                        log.info("Detected new hook '{}' in server '{}', adding to engine hooks", key, server);
                        logMessage(clusterId, key, AuditLogType.GLUSTER_HOOK_DETECTED_NEW);
                        updateContentTasksList(contentTasksList, newHook, server);
                        existingHookServersMap.put(newHook.getId(), new HashSet<>());
                    }
                    Integer conflictStatus = getConflictStatus(newHook, fetchedHook);
                    if (conflictStatus > 0) {
                        newHook.getServerHooks().add(buildServerHook(server.getId(), newHook.getId(), fetchedHook));
                    }
                    newHook.setConflictStatus(newHook.getConflictStatus() | conflictStatus);
                    newHookMap.put(key, newHook);
                    updateHookServerMap(existingHookServersMap, newHook.getId(), server);
                }
            }
        }
        // Save new hooks
        saveNewHooks(newHookMap, contentTasksList);
        // Add new server hooks
        for (GlusterServerHook serverHook : newServerHooks) {
            hooksDao.saveGlusterServerHook(serverHook);
        }
        // Update existing server hooks
        for (GlusterServerHook serverHook : updatedServerHooks) {
            hooksDao.updateGlusterServerHook(serverHook);
        }
        syncExistingHooks(existingHookMap, existingHookServersMap, existingHookConflictMap, upServers);
        // Update missing conflicts for hooks found only in db and not on any of the servers
        Set<String> hooksOnlyInDB = new HashSet<>(existingHookMap.keySet());
        hooksOnlyInDB.removeAll(fetchedHookKeyList);
        for (String key : hooksOnlyInDB) {
            GlusterHookEntity hook = existingHookMap.get(key);
            hook.addMissingConflict();
            logMessage(hook.getClusterId(), hook.getHookKey(), AuditLogType.GLUSTER_HOOK_CONFLICT_DETECTED);
            hooksDao.updateGlusterHookConflictStatus(hook.getId(), hook.getConflictStatus());
        }
    } catch (Exception e) {
        log.error("Exception in sync", e);
        throw new EngineException(EngineError.GlusterHookListException, e.getLocalizedMessage());
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) EngineException(org.ovirt.engine.core.common.errors.EngineException) Guid(org.ovirt.engine.core.compat.Guid) Callable(java.util.concurrent.Callable) VDSReturnValue(org.ovirt.engine.core.common.vdscommands.VDSReturnValue) GlusterServerHook(org.ovirt.engine.core.common.businessentities.gluster.GlusterServerHook) ArrayList(java.util.ArrayList) List(java.util.List) HashSet(java.util.HashSet) VDS(org.ovirt.engine.core.common.businessentities.VDS) EngineException(org.ovirt.engine.core.common.errors.EngineException) GlusterHookEntity(org.ovirt.engine.core.common.businessentities.gluster.GlusterHookEntity)

Aggregations

GlusterServerHook (org.ovirt.engine.core.common.businessentities.gluster.GlusterServerHook)22 GlusterHookEntity (org.ovirt.engine.core.common.businessentities.gluster.GlusterHookEntity)8 ArrayList (java.util.ArrayList)6 Test (org.junit.Test)5 VDS (org.ovirt.engine.core.common.businessentities.VDS)5 Guid (org.ovirt.engine.core.compat.Guid)5 GlusterHookContentType (org.ovirt.engine.core.common.businessentities.gluster.GlusterHookContentType)4 VDSReturnValue (org.ovirt.engine.core.common.vdscommands.VDSReturnValue)4 List (java.util.List)3 Callable (java.util.concurrent.Callable)3 GlusterHookStatus (org.ovirt.engine.core.common.businessentities.gluster.GlusterHookStatus)3 GlusterHookVDSParameters (org.ovirt.engine.core.common.vdscommands.gluster.GlusterHookVDSParameters)3 AsyncDataProvider (org.ovirt.engine.ui.uicommonweb.dataprovider.AsyncDataProvider)3 EntityModel (org.ovirt.engine.ui.uicommonweb.models.EntityModel)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Set (java.util.Set)2 ActionParametersBase (org.ovirt.engine.core.common.action.ActionParametersBase)2 ActionType (org.ovirt.engine.core.common.action.ActionType)2 GlusterClusterParameters (org.ovirt.engine.core.common.action.gluster.GlusterClusterParameters)2