Search in sources :

Example 1 with CollectorStatusList

use of org.graylog.plugins.sidecar.rest.models.CollectorStatusList in project graylog2-server by Graylog2.

the class SidecarService method markExpired.

public int markExpired(Period period, String message) {
    final DateTime threshold = DateTime.now(DateTimeZone.UTC).minus(period);
    int count;
    try (final Stream<Sidecar> collectorStream = streamAll()) {
        count = collectorStream.mapToInt(collector -> {
            if (collector.nodeDetails().statusList() == null) {
                return 0;
            }
            final CollectorStatusList sidecarStatus = collector.nodeDetails().statusList();
            if (collector.lastSeen().isBefore(threshold) && Sidecar.Status.RUNNING.equals(Sidecar.Status.fromStatusCode(sidecarStatus.status()))) {
                NodeDetails nodeDetails = collector.nodeDetails();
                ImmutableSet.Builder<CollectorStatus> collectorStatuses = ImmutableSet.builder();
                for (CollectorStatus collectorStatus : sidecarStatus.collectors()) {
                    collectorStatuses.add(CollectorStatus.create(collectorStatus.collectorId(), Sidecar.Status.UNKNOWN.getStatusCode(), message, ""));
                }
                CollectorStatusList statusListToSave = CollectorStatusList.create(Sidecar.Status.UNKNOWN.getStatusCode(), message, collectorStatuses.build());
                NodeDetails nodeDetailsToSave = NodeDetails.create(nodeDetails.operatingSystem(), nodeDetails.ip(), nodeDetails.metrics(), nodeDetails.logFileList(), statusListToSave);
                Sidecar toSave = collector.toBuilder().nodeDetails(nodeDetailsToSave).build();
                save(toSave);
                return 1;
            }
            return 0;
        }).sum();
    }
    return count;
}
Also used : CollectorStatus(org.graylog.plugins.sidecar.rest.models.CollectorStatus) ImmutableSet(com.google.common.collect.ImmutableSet) CollectorStatusList(org.graylog.plugins.sidecar.rest.models.CollectorStatusList) NodeDetails(org.graylog.plugins.sidecar.rest.models.NodeDetails) DateTime(org.joda.time.DateTime) Sidecar(org.graylog.plugins.sidecar.rest.models.Sidecar)

Aggregations

ImmutableSet (com.google.common.collect.ImmutableSet)1 CollectorStatus (org.graylog.plugins.sidecar.rest.models.CollectorStatus)1 CollectorStatusList (org.graylog.plugins.sidecar.rest.models.CollectorStatusList)1 NodeDetails (org.graylog.plugins.sidecar.rest.models.NodeDetails)1 Sidecar (org.graylog.plugins.sidecar.rest.models.Sidecar)1 DateTime (org.joda.time.DateTime)1