/** * We group the tasks by the root command id, so that we can identify the commands that were * partially submitted to vdsm */ private Map<Guid, List<AsyncTask>> groupTasksByRootCommandId(List<AsyncTask> tasksInDB) { Map<Guid, List<AsyncTask>> rootCommandIdToCommandsMap = new HashMap<>(); for (AsyncTask task : tasksInDB) { MultiValueMapUtils.addToMap(task.getRootCommandId(), task, rootCommandIdToCommandsMap); } return rootCommandIdToCommandsMap; }
// the last image in each list is the leaf public static Map<Guid, List<DiskImage>> getImagesLeaf(List<DiskImage> images) { Map<Guid, List<DiskImage>> retVal = new HashMap<>(); for (DiskImage image : images) { MultiValueMapUtils.addToMap(image.getId(), image, retVal); } for (List<DiskImage> list : retVal.values()) { sortImageList(list); } return retVal; }
/** Get a list of all domains id that the template is on */ private Set<Guid> getStorageDomainsByDisks( List<DiskImage> disks, boolean isFillStorageTodDiskMap) { Set<Guid> domainsList = new HashSet<>(); if (disks != null) { for (DiskImage disk : disks) { domainsList.addAll(disk.getStorageIds()); if (isFillStorageTodDiskMap) { for (Guid storageDomainId : disk.getStorageIds()) { MultiValueMapUtils.addToMap(storageDomainId, disk, storageToDisksMap); } } } } return domainsList; }
public static List<DbUser> sync(List<DbUser> dbUsers) { List<DbUser> usersToUpdate = new ArrayList<>(); Map<String, Map<String, Set<String>>> authzToNamespaceToUserIds = new HashMap<>(); Map<String, List<DbUser>> dbUsersPerAuthz = new HashMap<>(); // Initialize the entries based on authz in the map for (DbUser dbUser : dbUsers) { MultiValueMapUtils.addToMap(dbUser.getDomain(), dbUser, dbUsersPerAuthz); if (!authzToNamespaceToUserIds.containsKey(dbUser.getDomain())) { authzToNamespaceToUserIds.put(dbUser.getDomain(), new HashMap<String, Set<String>>()); } MultiValueMapUtils.addToMapOfSets( dbUser.getNamespace(), dbUser.getExternalId(), authzToNamespaceToUserIds.get(dbUser.getDomain())); } for (Entry<String, Map<String, Set<String>>> entry : authzToNamespaceToUserIds.entrySet()) { Map<String, DbUser> activeUsers = new HashMap<>(); String authz = entry.getKey(); try { ExtensionProxy authzExtension = EngineExtensionsManager.getInstance().getExtensionByName(authz); for (Entry<String, Set<String>> userIdsPerNamespace : entry.getValue().entrySet()) { for (ExtMap principal : AuthzUtils.fetchPrincipalsByIdsRecursively( authzExtension, userIdsPerNamespace.getKey(), userIdsPerNamespace.getValue())) { DirectoryUtils.flatGroups(principal); DbUser dbUser = DirectoryUtils.mapPrincipalRecordToDbUser(authz, principal); dbUser.setGroupIds(DirectoryUtils.getGroupIdsFromPrincipal(authz, principal)); activeUsers.put(dbUser.getExternalId(), dbUser); } } for (DbUser dbUser : dbUsersPerAuthz.get(authz)) { DbUser activeUser = activeUsers.get(dbUser.getExternalId()); if (activeUser != null) { if (!activeUser.equals(dbUser)) { activeUser.setId(dbUser.getId()); activeUser.setAdmin(dbUser.isAdmin()); log.infoFormat( "Principal {0}::{1} synchronized", activeUser.getLoginName(), activeUser.getDomain()); usersToUpdate.add(activeUser); } } else { log.infoFormat( "Deactivating non existing principal {0}::{1}", dbUser.getLoginName(), dbUser.getDomain()); dbUser.setActive(false); usersToUpdate.add(dbUser); } } } catch (Exception ex) { log.errorFormat( "Error during user synchronization of extension {0}. Exception message is {1}", authz, ex.getMessage()); log.debug("", ex); } } return usersToUpdate; }