Search in sources :

Example 81 with PUT

use of javax.ws.rs.PUT in project graylog2-server by Graylog2.

the class StreamRuleResource method update.

@PUT
@Path("/{streamRuleId}")
@Timed
@ApiOperation(value = "Update a stream rule")
@ApiResponses(value = { @ApiResponse(code = 404, message = "Stream or stream rule not found."), @ApiResponse(code = 400, message = "Invalid JSON Body.") })
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@AuditEvent(type = AuditEventTypes.STREAM_RULE_UPDATE)
public SingleStreamRuleSummaryResponse update(@ApiParam(name = "streamid", value = "The stream id this rule belongs to.", required = true) @PathParam("streamid") String streamid, @ApiParam(name = "streamRuleId", value = "The stream rule id we are updating", required = true) @PathParam("streamRuleId") String streamRuleId, @ApiParam(name = "JSON body", required = true) @Valid @NotNull CreateStreamRuleRequest cr) throws NotFoundException, ValidationException {
    checkPermission(RestPermissions.STREAMS_EDIT, streamid);
    checkNotDefaultStream(streamid, "Cannot update stream rules on default stream.");
    final StreamRule streamRule;
    streamRule = streamRuleService.load(streamRuleId);
    if (!streamRule.getStreamId().equals(streamid)) {
        throw new NotFoundException("Couldn't update stream rule " + streamRuleId + "in stream " + streamid);
    }
    final StreamRuleType streamRuleType = StreamRuleType.fromInteger(cr.type());
    if (null == streamRuleType) {
        throw new BadRequestException("Unknown stream rule type " + cr.type());
    }
    streamRule.setField(cr.field());
    streamRule.setType(streamRuleType);
    streamRule.setInverted(cr.inverted());
    streamRule.setValue(cr.value());
    streamRule.setDescription(cr.description());
    streamRuleService.save(streamRule);
    clusterEventBus.post(StreamsChangedEvent.create(streamid));
    return SingleStreamRuleSummaryResponse.create(streamRule.getId());
}
Also used : StreamRule(org.graylog2.plugin.streams.StreamRule) StreamRuleType(org.graylog2.plugin.streams.StreamRuleType) NotFoundException(org.graylog2.database.NotFoundException) BadRequestException(javax.ws.rs.BadRequestException) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) AuditEvent(org.graylog2.audit.jersey.AuditEvent) PUT(javax.ws.rs.PUT) ApiResponses(io.swagger.annotations.ApiResponses)

Example 82 with PUT

use of javax.ws.rs.PUT in project graylog2-server by Graylog2.

the class GrokResource method bulkUpdatePatterns.

@PUT
@Timed
@ApiOperation("Add a list of new patterns")
@AuditEvent(type = AuditEventTypes.GROK_PATTERN_IMPORT_CREATE)
public Response bulkUpdatePatterns(@ApiParam(name = "patterns", required = true) @NotNull GrokPatternList patternList, @ApiParam(name = "replace", value = "Replace all patterns with the new ones.") @QueryParam("replace") @DefaultValue("false") boolean replace) throws ValidationException {
    checkPermission(RestPermissions.INPUTS_CREATE);
    final Set<String> updatedPatternNames = Sets.newHashSet();
    for (final GrokPattern pattern : patternList.patterns()) {
        updatedPatternNames.add(pattern.name());
        if (!grokPatternService.validate(pattern)) {
            throw new ValidationException("Invalid pattern " + pattern + ". Did not save any patterns.");
        }
    }
    grokPatternService.saveAll(patternList.patterns(), replace);
    clusterBus.post(GrokPatternsChangedEvent.create(Collections.emptySet(), updatedPatternNames));
    return Response.accepted().build();
}
Also used : ValidationException(org.graylog2.plugin.database.ValidationException) GrokPattern(org.graylog2.grok.GrokPattern) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) AuditEvent(org.graylog2.audit.jersey.AuditEvent) PUT(javax.ws.rs.PUT)

Example 83 with PUT

use of javax.ws.rs.PUT in project graylog2-server by Graylog2.

the class AuditCoverageTest method testAuditCoverage.

@Test
public void testAuditCoverage() throws Exception {
    final ConfigurationBuilder configurationBuilder = new ConfigurationBuilder().setUrls(ClasspathHelper.forPackage("org.graylog2")).setScanners(new MethodAnnotationsScanner());
    final Set<String> auditEventTypes = new AuditEventTypes().auditEventTypes();
    final Reflections reflections = new Reflections(configurationBuilder);
    final ImmutableSet.Builder<Method> methods = ImmutableSet.builder();
    final ImmutableSet.Builder<Method> missing = ImmutableSet.builder();
    final ImmutableSet.Builder<Method> unregisteredAction = ImmutableSet.builder();
    methods.addAll(reflections.getMethodsAnnotatedWith(POST.class));
    methods.addAll(reflections.getMethodsAnnotatedWith(PUT.class));
    methods.addAll(reflections.getMethodsAnnotatedWith(DELETE.class));
    for (Method method : methods.build()) {
        if (!method.isAnnotationPresent(AuditEvent.class) && !method.isAnnotationPresent(NoAuditEvent.class)) {
            missing.add(method);
        } else {
            if (method.isAnnotationPresent(AuditEvent.class)) {
                final AuditEvent annotation = method.getAnnotation(AuditEvent.class);
                if (!auditEventTypes.contains(annotation.type())) {
                    unregisteredAction.add(method);
                }
            }
        }
    }
    assertThat(missing.build()).describedAs("Check that there are no POST, PUT and DELETE resources which do not have the @AuditEvent annotation").isEmpty();
    assertThat(unregisteredAction.build()).describedAs("Check that there are no @AuditEvent annotations with unregistered event types").isEmpty();
}
Also used : ConfigurationBuilder(org.reflections.util.ConfigurationBuilder) POST(javax.ws.rs.POST) Method(java.lang.reflect.Method) PUT(javax.ws.rs.PUT) DELETE(javax.ws.rs.DELETE) MethodAnnotationsScanner(org.reflections.scanners.MethodAnnotationsScanner) ImmutableSet(com.google.common.collect.ImmutableSet) NoAuditEvent(org.graylog2.audit.jersey.NoAuditEvent) AuditEvent(org.graylog2.audit.jersey.AuditEvent) Reflections(org.reflections.Reflections) Test(org.junit.Test)

Example 84 with PUT

use of javax.ws.rs.PUT in project incubator-atlas by apache.

the class TaxonomyService method updateTerm.

@PUT
@Path("{taxonomyName}/terms/{termName}")
@Produces(Servlets.JSON_MEDIA_TYPE)
public Response updateTerm(String body, @Context HttpHeaders headers, @Context UriInfo ui, @PathParam("taxonomyName") String taxonomyName, @PathParam("termName") String termName) throws CatalogException {
    AtlasPerfTracer perf = null;
    try {
        if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
            perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "TaxonomyService.updateTerm(" + taxonomyName + ", " + termName + ")");
        }
        Map<String, Object> queryProperties = new HashMap<>();
        queryProperties.put("termPath", new TermPath(taxonomyName, termName));
        Map<String, Object> updateProperties = parsePayload(body);
        updateResource(termResourceProvider, new InstanceRequest(queryProperties, updateProperties));
        return Response.status(Response.Status.OK).entity(new Results(ui.getRequestUri().toString(), 200)).build();
    } finally {
        AtlasPerfTracer.log(perf);
    }
}
Also used : HashMap(java.util.HashMap) AtlasPerfTracer(org.apache.atlas.utils.AtlasPerfTracer) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT)

Example 85 with PUT

use of javax.ws.rs.PUT in project incubator-atlas by apache.

the class TaxonomyService method updateTaxonomy.

@PUT
@Path("{taxonomyName}")
@Produces(Servlets.JSON_MEDIA_TYPE)
public Response updateTaxonomy(String body, @Context HttpHeaders headers, @Context UriInfo ui, @PathParam("taxonomyName") String taxonomyName) throws CatalogException {
    AtlasPerfTracer perf = null;
    try {
        if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
            perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "TaxonomyService.updateTaxonomy(" + taxonomyName + ")");
        }
        Map<String, Object> queryProperties = new HashMap<>();
        queryProperties.put("name", taxonomyName);
        Map<String, Object> updateProperties = parsePayload(body);
        updateResource(taxonomyResourceProvider, new InstanceRequest(queryProperties, updateProperties));
        return Response.status(Response.Status.OK).entity(new Results(ui.getRequestUri().toString(), 200)).build();
    } finally {
        AtlasPerfTracer.log(perf);
    }
}
Also used : HashMap(java.util.HashMap) AtlasPerfTracer(org.apache.atlas.utils.AtlasPerfTracer) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT)

Aggregations

PUT (javax.ws.rs.PUT)203 Path (javax.ws.rs.Path)172 Consumes (javax.ws.rs.Consumes)108 Produces (javax.ws.rs.Produces)72 ApiOperation (io.swagger.annotations.ApiOperation)70 ApiResponses (io.swagger.annotations.ApiResponses)53 Timed (com.codahale.metrics.annotation.Timed)36 AuditEvent (org.graylog2.audit.jersey.AuditEvent)36 URI (java.net.URI)24 Response (javax.ws.rs.core.Response)23 AuditPolicy (co.cask.cdap.common.security.AuditPolicy)19 IOException (java.io.IOException)18 BeanWrapper (org.springframework.beans.BeanWrapper)16 BadRequestException (javax.ws.rs.BadRequestException)14 NotFoundException (javax.ws.rs.NotFoundException)14 WebApplicationException (javax.ws.rs.WebApplicationException)12 UriBuilder (javax.ws.rs.core.UriBuilder)12 UUID (java.util.UUID)11 GET (javax.ws.rs.GET)11 POST (javax.ws.rs.POST)11