Search in sources :

Example 11 with NotFoundException

use of com.netflix.spinnaker.kork.web.exceptions.NotFoundException in project front50 by spinnaker.

the class S3StorageService method loadObject.

@Override
public <T extends Timestamped> T loadObject(ObjectType objectType, String objectKey) throws NotFoundException {
    try {
        S3Object s3Object = amazonS3.getObject(bucket, buildS3Key(objectType.group, objectKey, objectType.defaultMetadataFilename));
        T item = deserialize(s3Object, (Class<T>) objectType.clazz);
        item.setLastModified(s3Object.getObjectMetadata().getLastModified().getTime());
        return item;
    } catch (AmazonS3Exception e) {
        if (e.getStatusCode() == 404) {
            throw new NotFoundException("Object not found (key: " + objectKey + ")");
        }
        throw e;
    } catch (IOException e) {
        throw new IllegalStateException("Unable to deserialize object (key: " + objectKey + ")", e);
    }
}
Also used : NotFoundException(com.netflix.spinnaker.kork.web.exceptions.NotFoundException) IOException(java.io.IOException)

Example 12 with NotFoundException

use of com.netflix.spinnaker.kork.web.exceptions.NotFoundException in project front50 by spinnaker.

the class S3StorageService method listObjectVersions.

@Override
public <T extends Timestamped> Collection<T> listObjectVersions(ObjectType objectType, String objectKey, int maxResults) throws NotFoundException {
    if (maxResults == 1) {
        List<T> results = new ArrayList<>();
        results.add(loadObject(objectType, objectKey));
        return results;
    }
    try {
        VersionListing versionListing = amazonS3.listVersions(new ListVersionsRequest(bucket, buildS3Key(objectType.group, objectKey, objectType.defaultMetadataFilename), null, null, null, maxResults));
        return versionListing.getVersionSummaries().stream().map(s3VersionSummary -> {
            try {
                S3Object s3Object = amazonS3.getObject(new GetObjectRequest(bucket, buildS3Key(objectType.group, objectKey, objectType.defaultMetadataFilename), s3VersionSummary.getVersionId()));
                T item = deserialize(s3Object, (Class<T>) objectType.clazz);
                item.setLastModified(s3Object.getObjectMetadata().getLastModified().getTime());
                return item;
            } catch (IOException e) {
                throw new IllegalStateException(e);
            }
        }).collect(Collectors.toList());
    } catch (AmazonS3Exception e) {
        if (e.getStatusCode() == 404) {
            throw new NotFoundException(String.format("No item found with id of %s", objectKey.toLowerCase()));
        }
        throw e;
    }
}
Also used : java.util(java.util) Logger(org.slf4j.Logger) AmazonServiceException(com.amazonaws.AmazonServiceException) Pipeline(com.netflix.spinnaker.front50.api.model.pipeline.Pipeline) PipelineMixins(com.netflix.spinnaker.front50.jackson.mixins.PipelineMixins) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) LoggerFactory(org.slf4j.LoggerFactory) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException) com.amazonaws.services.s3.model(com.amazonaws.services.s3.model) Collectors(java.util.stream.Collectors) Lists(com.google.common.collect.Lists) ByteArrayInputStream(java.io.ByteArrayInputStream) StringUtils(com.amazonaws.util.StringUtils) Duration(java.time.Duration) TimestampedMixins(com.netflix.spinnaker.front50.jackson.mixins.TimestampedMixins) StructuredArguments.value(net.logstash.logback.argument.StructuredArguments.value) AmazonS3(com.amazonaws.services.s3.AmazonS3) DigestUtils(org.apache.commons.codec.digest.DigestUtils) Timestamped(com.netflix.spinnaker.front50.api.model.Timestamped) NotFoundException(com.netflix.spinnaker.kork.web.exceptions.NotFoundException) NotFoundException(com.netflix.spinnaker.kork.web.exceptions.NotFoundException) IOException(java.io.IOException)

Example 13 with NotFoundException

use of com.netflix.spinnaker.kork.web.exceptions.NotFoundException in project front50 by spinnaker.

the class ReorderPipelinesController method handlePipelineReorder.

private void handlePipelineReorder(Map<String, Object> requestBody, ItemDAO<Pipeline> pipelineItemDAO) {
    String application = (String) requestBody.get("application");
    Map<String, Integer> idsToIndices = (Map<String, Integer>) requestBody.get("idsToIndices");
    if (application == null) {
        throw new InvalidRequestException("`application` is required field on request body");
    }
    if (idsToIndices == null) {
        throw new InvalidRequestException("`idsToIndices` is required field on request body");
    }
    Authentication auth = SecurityContextHolder.getContext().getAuthentication();
    if (!fiatPermissionEvaluator.storeWholePermission() && !fiatPermissionEvaluator.hasPermission(auth, application, "APPLICATION", "WRITE")) {
        throw new InvalidRequestException("Application write permission is required to reorder pipelines");
    }
    for (String id : idsToIndices.keySet()) {
        Pipeline pipeline = pipelineItemDAO.findById(id);
        if (pipeline == null) {
            throw new NotFoundException(String.format("No pipeline of id %s found", id));
        }
        if (!pipeline.getApplication().equals(application)) {
            throw new InvalidRequestException(String.format("Pipeline with id %s does not belong to application %s", id, application));
        }
        pipeline.setIndex(idsToIndices.get(id));
        pipelineItemDAO.update(id, pipeline);
    }
}
Also used : Authentication(org.springframework.security.core.Authentication) NotFoundException(com.netflix.spinnaker.kork.web.exceptions.NotFoundException) InvalidRequestException(com.netflix.spinnaker.front50.exceptions.InvalidRequestException) Map(java.util.Map) Pipeline(com.netflix.spinnaker.front50.api.model.pipeline.Pipeline)

Example 14 with NotFoundException

use of com.netflix.spinnaker.kork.web.exceptions.NotFoundException in project front50 by spinnaker.

the class DeliveryController method upsertConfig.

@PreAuthorize("hasPermission(#config.application, 'APPLICATION', 'WRITE')")
@ApiOperation(value = "", notes = "Update a delivery config")
@RequestMapping(method = RequestMethod.PUT, value = "/deliveries/{id}")
Delivery upsertConfig(@PathVariable String id, @RequestBody Delivery config) {
    if (!id.equals(config.getId())) {
        throw new InvalidRequestException("URL id (" + id + ") does not match submitted id (" + config.getId() + ")");
    }
    try {
        Delivery existing = deliveryRepository.findById(id);
        config.setCreateTs(existing.getCreateTs());
    } catch (NotFoundException e) {
    // ignore because we will create config
    }
    return deliveryRepository.upsertConfig(config);
}
Also used : NotFoundException(com.netflix.spinnaker.kork.web.exceptions.NotFoundException) InvalidRequestException(com.netflix.spinnaker.front50.exceptions.InvalidRequestException) Delivery(com.netflix.spinnaker.front50.model.delivery.Delivery) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 15 with NotFoundException

use of com.netflix.spinnaker.kork.web.exceptions.NotFoundException in project front50 by spinnaker.

the class OracleStorageService method loadObject.

@Override
public <T extends Timestamped> T loadObject(ObjectType objectType, String objectKey) throws NotFoundException {
    WebResource wr = client.resource(UriBuilder.fromPath(endpoint + "/n/{arg1}/b/{arg2}/o/{arg3}").build(region, namespace, bucketName, buildOSSKey(objectType.group, objectKey, objectType.defaultMetadataFilename)));
    wr.accept(MediaType.APPLICATION_JSON_TYPE);
    try {
        T obj = (T) wr.get(objectType.clazz);
        return obj;
    } catch (UniformInterfaceException e) {
        if (e.getResponse().getStatus() == 404) {
            throw new NotFoundException("Object not found (key: " + objectKey + ")");
        }
        throw e;
    }
}
Also used : UniformInterfaceException(com.sun.jersey.api.client.UniformInterfaceException) WebResource(com.sun.jersey.api.client.WebResource) NotFoundException(com.netflix.spinnaker.kork.web.exceptions.NotFoundException)

Aggregations

NotFoundException (com.netflix.spinnaker.kork.web.exceptions.NotFoundException)15 java.util (java.util)5 Collectors (java.util.stream.Collectors)5 Logger (org.slf4j.Logger)5 LoggerFactory (org.slf4j.LoggerFactory)5 Timestamped (com.netflix.spinnaker.front50.api.model.Timestamped)4 StructuredArguments.value (net.logstash.logback.argument.StructuredArguments.value)4 Lists (com.google.common.collect.Lists)3 Pipeline (com.netflix.spinnaker.front50.api.model.pipeline.Pipeline)3 InvalidRequestException (com.netflix.spinnaker.front50.exceptions.InvalidRequestException)3 AuthenticatedRequest (com.netflix.spinnaker.security.AuthenticatedRequest)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 Counter (com.netflix.spectator.api.Counter)2 Registry (com.netflix.spectator.api.Registry)2 Timer (com.netflix.spectator.api.Timer)2 BadRequestException (com.netflix.spinnaker.front50.exception.BadRequestException)2 PipelineMixins (com.netflix.spinnaker.front50.jackson.mixins.PipelineMixins)2 TimestampedMixins (com.netflix.spinnaker.front50.jackson.mixins.TimestampedMixins)2 User (com.netflix.spinnaker.security.User)2 CircuitBreaker (io.github.resilience4j.circuitbreaker.CircuitBreaker)2