Search in sources :

Example 71 with PUT

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

the class StreamAlarmCallbackResource method update.

@PUT
@Path("/{alarmCallbackId}")
@Timed
@ApiOperation(value = "Update an alarm callback")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@AuditEvent(type = AuditEventTypes.ALARM_CALLBACK_UPDATE)
public void update(@ApiParam(name = "streamid", value = "The stream id this alarm callback belongs to.", required = true) @PathParam("streamid") String streamid, @ApiParam(name = "alarmCallbackId", required = true) @PathParam("alarmCallbackId") String alarmCallbackId, @ApiParam(name = "JSON body", required = true) CreateAlarmCallbackRequest alarmCallbackRequest) throws NotFoundException {
    checkPermission(RestPermissions.STREAMS_EDIT, streamid);
    final AlarmCallbackConfiguration callbackConfiguration = alarmCallbackConfigurationService.load(alarmCallbackId);
    if (callbackConfiguration == null) {
        throw new NotFoundException("Unable to find alarm callback configuration " + alarmCallbackId);
    }
    final Map<String, Object> configuration = convertConfigurationValues(alarmCallbackRequest);
    final AlarmCallbackConfiguration updatedConfig = ((AlarmCallbackConfigurationImpl) callbackConfiguration).toBuilder().setTitle(alarmCallbackRequest.title()).setConfiguration(configuration).build();
    try {
        alarmCallbackFactory.create(updatedConfig).checkConfiguration();
        alarmCallbackConfigurationService.save(updatedConfig);
    } catch (ValidationException | AlarmCallbackConfigurationException | ConfigurationException e) {
        LOG.error("Invalid alarm callback configuration.", e);
        throw new BadRequestException(e.getMessage(), e);
    } catch (ClassNotFoundException e) {
        LOG.error("Invalid alarm callback type.", e);
        throw new BadRequestException("Invalid alarm callback type.", e);
    }
}
Also used : ValidationException(org.graylog2.plugin.database.ValidationException) AlarmCallbackConfigurationException(org.graylog2.plugin.alarms.callbacks.AlarmCallbackConfigurationException) ConfigurationException(org.graylog2.plugin.configuration.ConfigurationException) NotFoundException(org.graylog2.database.NotFoundException) BadRequestException(javax.ws.rs.BadRequestException) AlarmCallbackConfiguration(org.graylog2.alarmcallbacks.AlarmCallbackConfiguration) AlarmCallbackConfigurationException(org.graylog2.plugin.alarms.callbacks.AlarmCallbackConfigurationException) 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)

Example 72 with PUT

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

the class ClusterLoggersResource method setSubsystemLoggerLevel.

@PUT
@Timed
@Path("/{nodeId}/subsystems/{subsystem}/level/{level}")
@ApiOperation(value = "Set the loglevel of a whole subsystem", notes = "Provided level is falling back to DEBUG if it does not exist")
@ApiResponses(value = { @ApiResponse(code = 404, message = "No such subsystem.") })
@NoAuditEvent("proxy resource, audit event will be emitted on target nodes")
public void setSubsystemLoggerLevel(@ApiParam(name = "nodeId", required = true) @PathParam("nodeId") @NotEmpty String nodeId, @ApiParam(name = "subsystem", required = true) @PathParam("subsystem") @NotEmpty String subsystemTitle, @ApiParam(name = "level", required = true) @PathParam("level") @NotEmpty String level) throws NodeNotFoundException, IOException {
    final Node node = this.nodeService.byNodeId(nodeId);
    final RemoteLoggersResource remoteLoggersResource = this.remoteInterfaceProvider.get(node, this.authenticationToken, RemoteLoggersResource.class);
    remoteLoggersResource.setSubsystemLoggerLevel(subsystemTitle, level).execute();
}
Also used : Node(org.graylog2.cluster.Node) RemoteLoggersResource(org.graylog2.rest.resources.system.logs.RemoteLoggersResource) Path(javax.ws.rs.Path) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) PUT(javax.ws.rs.PUT) ApiResponses(io.swagger.annotations.ApiResponses) NoAuditEvent(org.graylog2.audit.jersey.NoAuditEvent)

Example 73 with PUT

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

the class IndexSetsResource method update.

@PUT
@Path("{id}")
@Timed
@ApiOperation(value = "Update index set")
@AuditEvent(type = AuditEventTypes.INDEX_SET_UPDATE)
@ApiResponses(value = { @ApiResponse(code = 403, message = "Unauthorized"), @ApiResponse(code = 409, message = "Mismatch of IDs in URI path and payload") })
public IndexSetSummary update(@ApiParam(name = "id", required = true) @PathParam("id") String id, @ApiParam(name = "Index set configuration", required = true) @Valid @NotNull IndexSetUpdateRequest updateRequest) {
    checkPermission(RestPermissions.INDEXSETS_EDIT, id);
    final IndexSetConfig oldConfig = indexSetService.get(id).orElseThrow(() -> new NotFoundException("Index set <" + id + "> not found"));
    final IndexSetConfig defaultIndexSet = indexSetService.getDefault();
    final boolean isDefaultSet = oldConfig.equals(defaultIndexSet);
    if (isDefaultSet && !updateRequest.isWritable()) {
        throw new ClientErrorException("Default index set must be writable.", Response.Status.CONFLICT);
    }
    final IndexSetConfig savedObject = indexSetService.save(updateRequest.toIndexSetConfig(id, oldConfig));
    return IndexSetSummary.fromIndexSetConfig(savedObject, isDefaultSet);
}
Also used : IndexSetConfig(org.graylog2.indexer.indexset.IndexSetConfig) DefaultIndexSetConfig(org.graylog2.indexer.indexset.DefaultIndexSetConfig) NotFoundException(javax.ws.rs.NotFoundException) ClientErrorException(javax.ws.rs.ClientErrorException) Path(javax.ws.rs.Path) 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 74 with PUT

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

the class IndexSetsResource method setDefault.

@PUT
@Path("{id}/default")
@Timed
@ApiOperation(value = "Set default index set")
@AuditEvent(type = AuditEventTypes.INDEX_SET_UPDATE)
@ApiResponses(value = { @ApiResponse(code = 403, message = "Unauthorized") })
public IndexSetSummary setDefault(@ApiParam(name = "id", required = true) @PathParam("id") String id) {
    checkPermission(RestPermissions.INDEXSETS_EDIT, id);
    final IndexSetConfig indexSet = indexSetService.get(id).orElseThrow(() -> new NotFoundException("Index set <" + id + "> does not exist"));
    if (!indexSet.isWritable()) {
        throw new ClientErrorException("Default index set must be writable.", Response.Status.CONFLICT);
    }
    clusterConfigService.write(DefaultIndexSetConfig.create(indexSet.id()));
    final IndexSetConfig defaultIndexSet = indexSetService.getDefault();
    return IndexSetSummary.fromIndexSetConfig(indexSet, indexSet.equals(defaultIndexSet));
}
Also used : IndexSetConfig(org.graylog2.indexer.indexset.IndexSetConfig) DefaultIndexSetConfig(org.graylog2.indexer.indexset.DefaultIndexSetConfig) NotFoundException(javax.ws.rs.NotFoundException) ClientErrorException(javax.ws.rs.ClientErrorException) Path(javax.ws.rs.Path) 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 75 with PUT

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

the class LoggersResource method setSingleLoggerLevel.

@PUT
@Timed
@ApiOperation(value = "Set the loglevel of a single logger", notes = "Provided level is falling back to DEBUG if it does not exist")
@Path("/{loggerName}/level/{level}")
@AuditEvent(type = AuditEventTypes.LOG_LEVEL_UPDATE)
public void setSingleLoggerLevel(@ApiParam(name = "loggerName", required = true) @PathParam("loggerName") @NotEmpty String loggerName, @ApiParam(name = "level", required = true) @NotEmpty @PathParam("level") String level) {
    checkPermission(RestPermissions.LOGGERS_EDIT, loggerName);
    final Level newLevel = Level.toLevel(level.toUpperCase(Locale.ENGLISH));
    setLoggerLevel(loggerName, newLevel);
    LOG.debug("Successfully set log level for logger \"{}\" to \"{}\"", loggerName, newLevel);
}
Also used : Level(org.apache.logging.log4j.Level) Path(javax.ws.rs.Path) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) AuditEvent(org.graylog2.audit.jersey.AuditEvent) 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