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();
}
Aggregations