Search in sources :

Example 1 with RegistrationResponse

use of org.graylog.plugins.sidecar.rest.responses.RegistrationResponse in project graylog2-server by Graylog2.

the class SidecarResource method register.

@PUT
@Timed
@Path("/{sidecarId}")
@ApiOperation(value = "Create/update a Sidecar registration", notes = "This is a stateless method which upserts a Sidecar registration")
@ApiResponses(value = { @ApiResponse(code = 400, message = "The supplied request is not valid.") })
@RequiresPermissions(SidecarRestPermissions.SIDECARS_UPDATE)
@NoAuditEvent("this is only a ping from Sidecars, and would overflow the audit log")
public Response register(@ApiParam(name = "sidecarId", value = "The id this Sidecar is registering as.", required = true) @PathParam("sidecarId") @NotEmpty String sidecarId, @ApiParam(name = "JSON body", required = true) @Valid @NotNull RegistrationRequest request, @HeaderParam(value = "X-Graylog-Sidecar-Version") @NotEmpty String sidecarVersion) {
    final Sidecar newSidecar;
    final Sidecar oldSidecar = sidecarService.findByNodeId(sidecarId);
    List<ConfigurationAssignment> assignments = null;
    if (oldSidecar != null) {
        assignments = oldSidecar.assignments();
        newSidecar = oldSidecar.toBuilder().nodeName(request.nodeName()).nodeDetails(request.nodeDetails()).sidecarVersion(sidecarVersion).lastSeen(DateTime.now(DateTimeZone.UTC)).build();
    } else {
        newSidecar = sidecarService.fromRequest(sidecarId, request, sidecarVersion);
    }
    sidecarService.save(newSidecar);
    final CollectorActions collectorActions = actionService.findActionBySidecar(sidecarId, true);
    List<CollectorAction> collectorAction = null;
    if (collectorActions != null) {
        collectorAction = collectorActions.action();
    }
    RegistrationResponse sidecarRegistrationResponse = RegistrationResponse.create(SidecarRegistrationConfiguration.create(this.sidecarConfiguration.sidecarUpdateInterval().toStandardDuration().getStandardSeconds(), this.sidecarConfiguration.sidecarSendStatus()), this.sidecarConfiguration.sidecarConfigurationOverride(), collectorAction, assignments);
    return Response.accepted(sidecarRegistrationResponse).build();
}
Also used : CollectorActions(org.graylog.plugins.sidecar.rest.models.CollectorActions) ConfigurationAssignment(org.graylog.plugins.sidecar.rest.requests.ConfigurationAssignment) CollectorAction(org.graylog.plugins.sidecar.rest.models.CollectorAction) RegistrationResponse(org.graylog.plugins.sidecar.rest.responses.RegistrationResponse) Sidecar(org.graylog.plugins.sidecar.rest.models.Sidecar) Path(javax.ws.rs.Path) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) 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)

Aggregations

Timed (com.codahale.metrics.annotation.Timed)1 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponses (io.swagger.annotations.ApiResponses)1 PUT (javax.ws.rs.PUT)1 Path (javax.ws.rs.Path)1 RequiresPermissions (org.apache.shiro.authz.annotation.RequiresPermissions)1 CollectorAction (org.graylog.plugins.sidecar.rest.models.CollectorAction)1 CollectorActions (org.graylog.plugins.sidecar.rest.models.CollectorActions)1 Sidecar (org.graylog.plugins.sidecar.rest.models.Sidecar)1 ConfigurationAssignment (org.graylog.plugins.sidecar.rest.requests.ConfigurationAssignment)1 RegistrationResponse (org.graylog.plugins.sidecar.rest.responses.RegistrationResponse)1 NoAuditEvent (org.graylog2.audit.jersey.NoAuditEvent)1