class UserSyncPoller {

    @VisibleForTesting
    void syncAllFreeIpaStacks() {
        try {
            Optional<String> requestId = Optional.of(UUID.randomUUID().toString());
            MDCBuilder.addRequestId(requestId.get());
            LOGGER.debug("Setting request id = {} for this poll", requestId);

            ThreadBasedUserCrnProvider.doAs(INTERNAL_ACTOR_CRN, () -> {
                LOGGER.debug("Attempting to sync users to FreeIPA stacks");
                List<Stack> stackList = stackService.findAllWithStatuses(Status.AVAILABLE_STATUSES);
                LOGGER.debug("Found {} active stacks", stackList.size());

                stackList.stream()
                        .collect(Collectors.groupingBy(Stack::getAccountId))
                        .entrySet().stream()
                        .forEach(stringListEntry -> {
                            String accountId = stringListEntry.getKey();
                            if (userSyncPollerEntitlementChecker.isAccountEntitled(accountId)) {
                                LOGGER.debug("Automatic usersync polling is entitled in account {}", accountId);
                                syncFreeIpaStacksInAccount(requestId, accountId, stringListEntry.getValue());
                            } else {
                                LOGGER.debug("Automatic usersync polling is not entitled in account {}.", accountId);
                            }
                        });
            });
        } finally {
            MDCBuilder.cleanupMdc();
        }
    }

}