Search in sources :

Example 6 with AccountPreferences

use of com.sequenceiq.cloudbreak.domain.AccountPreferences in project cloudbreak by hortonworks.

the class StackRequestToStackConverter method getDefaultTags.

private Map<String, String> getDefaultTags(StackRequest source) {
    Map<String, String> result = new HashMap<>();
    try {
        AccountPreferences pref = accountPreferencesService.getByAccount(source.getAccount());
        if (pref != null && pref.getDefaultTags() != null && StringUtils.isNoneBlank(pref.getDefaultTags().getValue())) {
            result = pref.getDefaultTags().get(Map.class);
        }
        result.putAll(defaultCostTaggingService.prepareDefaultTags(source.getAccount(), source.getOwnerEmail(), result, source.getCloudPlatform()));
    } catch (IOException e) {
        LOGGER.debug("Exception during reading default tags.", e);
    }
    return result;
}
Also used : HashMap(java.util.HashMap) IOException(java.io.IOException) HashMap(java.util.HashMap) Map(java.util.Map) AccountPreferences(com.sequenceiq.cloudbreak.domain.AccountPreferences)

Example 7 with AccountPreferences

use of com.sequenceiq.cloudbreak.domain.AccountPreferences in project cloudbreak by hortonworks.

the class AccountPreferencesValidator method validate.

private void validate(Iterable<InstanceGroup> instanceGroups, Integer nodeCount, String account, String owner) throws AccountPreferencesValidationException {
    AccountPreferences preferences = accountPreferencesService.getByAccount(account);
    validateNumberOfNodesPerCluster(nodeCount, preferences);
    validateNumberOfClusters(account, preferences);
    validateAllowedInstanceTypes(instanceGroups, preferences);
    validateNumberOfClustersPerUser(owner, preferences);
    validateUserTimeToLive(owner, preferences);
}
Also used : AccountPreferences(com.sequenceiq.cloudbreak.domain.AccountPreferences)

Example 8 with AccountPreferences

use of com.sequenceiq.cloudbreak.domain.AccountPreferences in project cloudbreak by hortonworks.

the class ScheduledAccountPreferencesValidator method validate.

@Scheduled(cron = EVERY_HOUR_0MIN_0SEC)
public void validate() {
    LOGGER.info("Validate account preferences for all 'running' stack.");
    Map<String, AccountPreferences> accountPreferences = new HashMap<>();
    List<Stack> allAlive = stackService.getAllAlive();
    for (Stack stack : allAlive) {
        AccountPreferences preferences = getAccountPreferences(stack.getAccount(), accountPreferences);
        try {
            preferencesValidator.validateClusterTimeToLive(stack.getCreated(), preferences.getClusterTimeToLive());
            preferencesValidator.validateUserTimeToLive(stack.getOwner(), preferences);
        } catch (AccountPreferencesValidationException ignored) {
            terminateStack(stack);
        }
    }
}
Also used : HashMap(java.util.HashMap) AccountPreferences(com.sequenceiq.cloudbreak.domain.AccountPreferences) Stack(com.sequenceiq.cloudbreak.domain.Stack) Scheduled(org.springframework.scheduling.annotation.Scheduled)

Example 9 with AccountPreferences

use of com.sequenceiq.cloudbreak.domain.AccountPreferences in project cloudbreak by hortonworks.

the class ScheduledAccountPreferencesValidator method getAccountPreferences.

private AccountPreferences getAccountPreferences(String account, Map<String, AccountPreferences> accountPreferences) {
    if (accountPreferences.containsKey(account)) {
        return accountPreferences.get(account);
    } else {
        AccountPreferences preferences = accountPreferencesService.getByAccount(account);
        accountPreferences.put(account, preferences);
        return preferences;
    }
}
Also used : AccountPreferences(com.sequenceiq.cloudbreak.domain.AccountPreferences)

Aggregations

AccountPreferences (com.sequenceiq.cloudbreak.domain.AccountPreferences)9 HashMap (java.util.HashMap)2 IdentityUser (com.sequenceiq.cloudbreak.common.model.user.IdentityUser)1 BadRequestException (com.sequenceiq.cloudbreak.controller.BadRequestException)1 Stack (com.sequenceiq.cloudbreak.domain.Stack)1 IOException (java.io.IOException)1 Map (java.util.Map)1 Scheduled (org.springframework.scheduling.annotation.Scheduled)1