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());
}
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());
}
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());
}
}
}
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());
}
}
Aggregations