Search in sources :

Example 31 with GlusterHookEntity

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

the class GlusterHooksDaoTest method testGetById.

@Test
public void testGetById() {
    GlusterHookEntity hook = dao.getById(FixturesTool.HOOK_ID);
    assertNotNull(hook);
    assertEquals(FixturesTool.HOOK_ID, hook.getId());
}
Also used : GlusterHookEntity(org.ovirt.engine.core.common.businessentities.gluster.GlusterHookEntity) Test(org.junit.Test)

Example 32 with GlusterHookEntity

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

the class GlusterHooksDaoTest method testUpdateGlusterHookStatus.

@Test
public void testUpdateGlusterHookStatus() {
    dao.updateGlusterHookStatus(FixturesTool.HOOK_ID, GlusterHookStatus.ENABLED);
    GlusterHookEntity hook = dao.getById(FixturesTool.HOOK_ID);
    assertNotNull(hook);
    assertEquals(GlusterHookStatus.ENABLED, hook.getStatus());
}
Also used : GlusterHookEntity(org.ovirt.engine.core.common.businessentities.gluster.GlusterHookEntity) Test(org.junit.Test)

Example 33 with GlusterHookEntity

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

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

GlusterHookEntity (org.ovirt.engine.core.common.businessentities.gluster.GlusterHookEntity)34 Test (org.junit.Test)13 ArrayList (java.util.ArrayList)11 GlusterServerHook (org.ovirt.engine.core.common.businessentities.gluster.GlusterServerHook)8 Guid (org.ovirt.engine.core.compat.Guid)6 ActionParametersBase (org.ovirt.engine.core.common.action.ActionParametersBase)5 GlusterHookParameters (org.ovirt.engine.core.common.action.gluster.GlusterHookParameters)5 ConfirmationModel (org.ovirt.engine.ui.uicommonweb.models.ConfirmationModel)5 List (java.util.List)4 UICommand (org.ovirt.engine.ui.uicommonweb.UICommand)4 ActionType (org.ovirt.engine.core.common.action.ActionType)3 GlusterClusterParameters (org.ovirt.engine.core.common.action.gluster.GlusterClusterParameters)3 GlusterHookManageParameters (org.ovirt.engine.core.common.action.gluster.GlusterHookManageParameters)3 Cluster (org.ovirt.engine.core.common.businessentities.Cluster)3 GlusterHookContentType (org.ovirt.engine.core.common.businessentities.gluster.GlusterHookContentType)3 GlusterHookStatus (org.ovirt.engine.core.common.businessentities.gluster.GlusterHookStatus)3 ApplicationMode (org.ovirt.engine.core.common.mode.ApplicationMode)3 VDSReturnValue (org.ovirt.engine.core.common.vdscommands.VDSReturnValue)3 Frontend (org.ovirt.engine.ui.frontend.Frontend)3 AsyncDataProvider (org.ovirt.engine.ui.uicommonweb.dataprovider.AsyncDataProvider)3