class CleanupService {

    public Pair<Set<String>, Map<String, String>> removeUsers(Long stackId, Set<String> users, String clusterName, String environmentCrn)
            throws FreeIpaClientException {
        FreeIpaClient client = getFreeIpaClient(stackId);
        Set<String> userCleanupSuccess = new HashSet<>();
        Map<String, String> userCleanupFailed = new HashMap<>();
        Set<String> usersUid = client.userFindAll().stream().map(User::getUid).collect(Collectors.toSet());
        users.stream().filter(usersUid::contains).forEach(userUid -> {
            try {
                LOGGER.debug("Delete user: {}", userUid);
                client.deleteUser(userUid);
                userCleanupSuccess.add(userUid);
            } catch (FreeIpaClientException e) {
                if (FreeIpaClientExceptionUtil.isNotFoundException(e)) {
                    userCleanupSuccess.add(userUid);
                } else {
                    LOGGER.info("User delete failed for user: {}", userUid, e);
                    userCleanupFailed.put(userUid, e.getMessage());
                }
            }
        });
        if (StringUtils.isNotBlank(clusterName)) {
            Stack stack = stackService.getStackById(stackId);
            if (StringUtils.isEmpty(environmentCrn)) {
                environmentCrn = stack.getEnvironmentCrn();
            }
            String accountId = stack.getAccountId();
            try {
                kerberosConfigService.delete(environmentCrn, accountId, clusterName);
            } catch (NotFoundException e) {
                LOGGER.warn("No kerberos config found for cluster [{}] to delete", clusterName);
            }
            try {
                ldapConfigService.delete(environmentCrn, accountId, clusterName);
            } catch (NotFoundException e) {
                LOGGER.warn("No ldap config found for cluster [{}] to delete", clusterName);
            }
        }
        return Pair.of(userCleanupSuccess, userCleanupFailed);
    }

}