public SyncStatusDetail synchronizeStack(Stack stack, UmsUsersState umsUsersState, UserSyncOptions options) {
        MDCBuilder.buildMdcContext(stack);
        String environmentCrn = stack.getEnvironmentCrn();
        Multimap<String, String> warnings = ArrayListMultimap.create();
        try {
            FreeIpaClient freeIpaClient = freeIpaClientFactory.getFreeIpaClientForStack(stack);
            UsersStateDifference usersStateDifferenceBeforeSync = compareUmsAndFreeIpa(umsUsersState, options, freeIpaClient);
            stateApplier.applyDifference(umsUsersState, environmentCrn, warnings, usersStateDifferenceBeforeSync, options, freeIpaClient);
            retrySyncIfBatchCallHasWarnings(stack, umsUsersState, warnings, options, freeIpaClient, usersStateDifferenceBeforeSync);
            if (options.isFullSync()) {
                // TODO For now we only sync cloud ids during full sync. We should eventually allow more granular syncs (actor level and group level sync).
                if (entitlementService.cloudIdentityMappingEnabled(stack.getAccountId())) {
                    LOGGER.debug("Starting {} ...", SYNC_CLOUD_IDENTITIES);
                    cloudIdentitySyncService.syncCloudIdentities(stack, umsUsersState, warnings::put);
                    LOGGER.debug("Finished {}.", SYNC_CLOUD_IDENTITIES);
                }
                if (entitlementService.isEnvironmentPrivilegedUserEnabled(stack.getAccountId())) {
                    LOGGER.debug("Starting {} ...", ADD_SUDO_RULES);
                    try {
                        sudoRuleService.setupSudoRule(stack, freeIpaClient);
                    } catch (Exception e) {
                        warnings.put(stack.getEnvironmentCrn(), e.getMessage());
                        LOGGER.error("{} failed for environment '{}'.", ADD_SUDO_RULES, stack.getEnvironmentCrn(), e);
                    }
                    LOGGER.debug("Finished {}.", ADD_SUDO_RULES);
                }
            }
            return toSyncStatusDetail(environmentCrn, warnings);
        } catch (TimeoutException e) {
            LOGGER.warn("Timed out while synchronizing environment {}", environmentCrn, e);
            return SyncStatusDetail.fail(environmentCrn, "Timed out", warnings);
        } catch (Exception e) {
            LOGGER.warn("Failed to synchronize environment {}", environmentCrn, e);
            return SyncStatusDetail.fail(environmentCrn, e.getLocalizedMessage(), warnings);
        }
    }
public SyncStatusDetail synchronizeStack(Stack stack, UmsUsersState umsUsersState, UserSyncOptions options) {
        MDCBuilder.buildMdcContext(stack);
        String environmentCrn = stack.getEnvironmentCrn();
        Multimap<String, String> warnings = ArrayListMultimap.create();
        try {
            FreeIpaClient freeIpaClient = freeIpaClientFactory.getFreeIpaClientForStack(stack);
            UsersStateDifference usersStateDifferenceBeforeSync = compareUmsAndFreeIpa(umsUsersState, options, freeIpaClient);
            stateApplier.applyDifference(umsUsersState, environmentCrn, warnings, usersStateDifferenceBeforeSync, options, freeIpaClient);
            retrySyncIfBatchCallHasWarnings(stack, umsUsersState, warnings, options, freeIpaClient, usersStateDifferenceBeforeSync);
            if (options.isFullSync()) {
               
                if (entitlementService.cloudIdentityMappingEnabled(stack.getAccountId())) {
                    LOGGER.debug("Starting {} ...", SYNC_CLOUD_IDENTITIES);
                    cloudIdentitySyncService.syncCloudIdentities(stack, umsUsersState, warnings::put);
                    LOGGER.debug("Finished {}.", SYNC_CLOUD_IDENTITIES);
                }
                if (entitlementService.isEnvironmentPrivilegedUserEnabled(stack.getAccountId())) {
                    LOGGER.debug("Starting {} ...", ADD_SUDO_RULES);
                    try {
                        sudoRuleService.setupSudoRule(stack, freeIpaClient);
                    } catch (Exception e) {
                        warnings.put(stack.getEnvironmentCrn(), e.getMessage());
                        LOGGER.error("{} failed for environment '{}'.", ADD_SUDO_RULES, stack.getEnvironmentCrn(), e);
                    }
                    LOGGER.debug("Finished {}.", ADD_SUDO_RULES);
                }
            }
            return toSyncStatusDetail(environmentCrn, warnings);
        } catch (TimeoutException e) {
            LOGGER.warn("Timed out while synchronizing environment {}", environmentCrn, e);
            return SyncStatusDetail.fail(environmentCrn, "Timed out", warnings);
        } catch (Exception e) {
            LOGGER.warn("Failed to synchronize environment {}", environmentCrn, e);
            return SyncStatusDetail.fail(environmentCrn, e.getLocalizedMessage(), warnings);
        }
    }
public syncstatusdetail synchronizestack(stack stack, umsusersstate umsusersstate, usersyncoptions options) { mdcbuilder.buildmdccontext(stack); string environmentcrn = stack.getenvironmentcrn(); multimap<string, string> warnings = arraylistmultimap.create(); try { freeipaclient freeipaclient = freeipaclientfactory.getfreeipaclientforstack(stack); usersstatedifference usersstatedifferencebeforesync = compareumsandfreeipa(umsusersstate, options, freeipaclient); stateapplier.applydifference(umsusersstate, environmentcrn, warnings, usersstatedifferencebeforesync, options, freeipaclient); retrysyncifbatchcallhaswarnings(stack, umsusersstate, warnings, options, freeipaclient, usersstatedifferencebeforesync); if (options.isfullsync()) { if (entitlementservice.cloudidentitymappingenabled(stack.getaccountid())) { logger.debug("starting {} ...", sync_cloud_identities); cloudidentitysyncservice.synccloudidentities(stack, umsusersstate, warnings::put); logger.debug("finished {}.", sync_cloud_identities); } if (entitlementservice.isenvironmentprivilegeduserenabled(stack.getaccountid())) { logger.debug("starting {} ...", add_sudo_rules); try { sudoruleservice.setupsudorule(stack, freeipaclient); } catch (exception e) { warnings.put(stack.getenvironmentcrn(), e.getmessage()); logger.error("{} failed for environment '{}'.", add_sudo_rules, stack.getenvironmentcrn(), e); } logger.debug("finished {}.", add_sudo_rules); } } return tosyncstatusdetail(environmentcrn, warnings); } catch (timeoutexception e) { logger.warn("timed out while synchronizing environment {}", environmentcrn, e); return syncstatusdetail.fail(environmentcrn, "timed out", warnings); } catch (exception e) { logger.warn("failed to synchronize environment {}", environmentcrn, e); return syncstatusdetail.fail(environmentcrn, e.getlocalizedmessage(), warnings); } }