Search in sources :

Example 1 with SpinnakerException

use of com.netflix.spinnaker.kork.exceptions.SpinnakerException in project kork by spinnaker.

the class ExceptionSummaryService method createTraceDetail.

private TraceDetail createTraceDetail(Throwable throwable, @Nullable ExceptionDetails exceptionDetails) {
    TraceDetailBuilder detailBuilder = TraceDetail.builder().message(throwable.getMessage());
    if (throwable instanceof SpinnakerException) {
        SpinnakerException spinnakerException = (SpinnakerException) throwable;
        detailBuilder.userMessage(exceptionMessageDecorator.decorate(throwable, spinnakerException.getUserMessage(), exceptionDetails)).retryable(spinnakerException.getRetryable());
    }
    if (throwable instanceof HasAdditionalAttributes) {
        detailBuilder.additionalAttributes(((HasAdditionalAttributes) throwable).getAdditionalAttributes());
    }
    return detailBuilder.build();
}
Also used : SpinnakerException(com.netflix.spinnaker.kork.exceptions.SpinnakerException) HasAdditionalAttributes(com.netflix.spinnaker.kork.exceptions.HasAdditionalAttributes) TraceDetailBuilder(com.netflix.spinnaker.kork.api.exceptions.ExceptionSummary.TraceDetail.TraceDetailBuilder)

Example 2 with SpinnakerException

use of com.netflix.spinnaker.kork.exceptions.SpinnakerException in project fiat by spinnaker.

the class RedisPermissionsRepository method getFromRedis.

private Optional<UserPermission> getFromRedis(@NonNull String id) {
    try {
        TimeoutContext timeoutContext = new TimeoutContext(String.format("getPermission for user: %s", id), clock, configProps.getRepository().getGetPermissionTimeout());
        boolean userExists = UNRESTRICTED.equals(id) || redisRead(timeoutContext, c -> c.sismember(allUsersKey, SafeEncoder.encode(id)));
        if (!userExists) {
            log.debug("request for user {} not found in redis", id);
            return Optional.empty();
        }
        UserPermission userPermission = new UserPermission().setId(id);
        for (Resource r : resources) {
            ResourceType resourceType = r.getResourceType();
            Map<String, Resource> resourcePermissions = getUserResourceMapFromRedis(id, resourceType);
            if (resourcePermissions != null && !resourcePermissions.isEmpty()) {
                userPermission.addResources(resourcePermissions.values());
            }
        }
        if (!UNRESTRICTED.equals(id)) {
            userPermission.setAdmin(redisRead(timeoutContext, c -> c.sismember(adminKey, SafeEncoder.encode(id))));
            userPermission.merge(getUnrestrictedUserPermission());
        }
        return Optional.of(userPermission);
    } catch (Throwable t) {
        String message = String.format("Storage exception reading %s entry.", id);
        log.error(message, t);
        if (t instanceof SpinnakerException) {
            throw (SpinnakerException) t;
        }
        throw new PermissionReadException(message, t);
    }
}
Also used : java.util(java.util) net.jpountz.lz4(net.jpountz.lz4) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) BinaryJedisCommands(redis.clients.jedis.commands.BinaryJedisCommands) SafeEncoder(redis.clients.jedis.util.SafeEncoder) redis.clients.jedis(redis.clients.jedis) Duration(java.time.Duration) TypeReference(com.fasterxml.jackson.core.type.TypeReference) RetryRegistry(io.github.resilience4j.retry.RetryRegistry) RedisClientDelegate(com.netflix.spinnaker.kork.jedis.RedisClientDelegate) Caffeine(com.github.benmanes.caffeine.cache.Caffeine) LoadingCache(com.github.benmanes.caffeine.cache.LoadingCache) NonNull(lombok.NonNull) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ResourceType(com.netflix.spinnaker.fiat.model.resources.ResourceType) IOException(java.io.IOException) UnrestrictedResourceConfig(com.netflix.spinnaker.fiat.config.UnrestrictedResourceConfig) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) ExecutionException(java.util.concurrent.ExecutionException) Resource(com.netflix.spinnaker.fiat.model.resources.Resource) Slf4j(lombok.extern.slf4j.Slf4j) IntegrationException(com.netflix.spinnaker.kork.exceptions.IntegrationException) ForkJoinPool(java.util.concurrent.ForkJoinPool) Role(com.netflix.spinnaker.fiat.model.resources.Role) Clock(java.time.Clock) SpinnakerException(com.netflix.spinnaker.kork.exceptions.SpinnakerException) UserPermission(com.netflix.spinnaker.fiat.model.UserPermission) SpinnakerException(com.netflix.spinnaker.kork.exceptions.SpinnakerException) Resource(com.netflix.spinnaker.fiat.model.resources.Resource) ResourceType(com.netflix.spinnaker.fiat.model.resources.ResourceType) UserPermission(com.netflix.spinnaker.fiat.model.UserPermission)

Aggregations

SpinnakerException (com.netflix.spinnaker.kork.exceptions.SpinnakerException)2 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Caffeine (com.github.benmanes.caffeine.cache.Caffeine)1 LoadingCache (com.github.benmanes.caffeine.cache.LoadingCache)1 UnrestrictedResourceConfig (com.netflix.spinnaker.fiat.config.UnrestrictedResourceConfig)1 UserPermission (com.netflix.spinnaker.fiat.model.UserPermission)1 Resource (com.netflix.spinnaker.fiat.model.resources.Resource)1 ResourceType (com.netflix.spinnaker.fiat.model.resources.ResourceType)1 Role (com.netflix.spinnaker.fiat.model.resources.Role)1 TraceDetailBuilder (com.netflix.spinnaker.kork.api.exceptions.ExceptionSummary.TraceDetail.TraceDetailBuilder)1 HasAdditionalAttributes (com.netflix.spinnaker.kork.exceptions.HasAdditionalAttributes)1 IntegrationException (com.netflix.spinnaker.kork.exceptions.IntegrationException)1 RedisClientDelegate (com.netflix.spinnaker.kork.jedis.RedisClientDelegate)1 RetryRegistry (io.github.resilience4j.retry.RetryRegistry)1 IOException (java.io.IOException)1 Clock (java.time.Clock)1 Duration (java.time.Duration)1 Instant (java.time.Instant)1 java.util (java.util)1