use of org.graylog2.indexer.indices.Indices in project graylog2-server by Graylog2.
the class IndexRotationThread method checkAndRepair.
protected void checkAndRepair(IndexSet indexSet) {
if (!indexSet.isUp()) {
if (indices.exists(indexSet.getWriteIndexAlias())) {
// Publish a notification if there is an *index* called graylog2_deflector
Notification notification = notificationService.buildNow().addType(Notification.Type.DEFLECTOR_EXISTS_AS_INDEX).addSeverity(Notification.Severity.URGENT);
final boolean published = notificationService.publishIfFirst(notification);
if (published) {
LOG.warn("There is an index called [" + indexSet.getWriteIndexAlias() + "]. Cannot fix this automatically and published a notification.");
}
} else {
indexSet.setUp();
}
} else {
try {
String currentTarget;
try {
currentTarget = indexSet.getActiveWriteIndex();
} catch (TooManyAliasesException e) {
// If we get this exception, there are multiple indices which have the deflector alias set.
// We try to cleanup the alias and try again. This should not happen, but might under certain
// circumstances.
indexSet.cleanupAliases(e.getIndices());
try {
currentTarget = indexSet.getActiveWriteIndex();
} catch (TooManyAliasesException e1) {
throw new IllegalStateException(e1);
}
}
String shouldBeTarget = indexSet.getNewestIndex();
if (!shouldBeTarget.equals(currentTarget)) {
String msg = "Deflector is pointing to [" + currentTarget + "], not the newest one: [" + shouldBeTarget + "]. Re-pointing.";
LOG.warn(msg);
activityWriter.write(new Activity(msg, IndexRotationThread.class));
if (indices.waitForRecovery(shouldBeTarget) == HealthStatus.Red) {
LOG.error("New target index for deflector didn't get healthy within timeout. Skipping deflector update.");
} else {
indexSet.pointTo(shouldBeTarget, currentTarget);
}
}
} catch (NoTargetIndexException e) {
LOG.warn("Deflector is not up. Not trying to point to another index.");
}
}
}
use of org.graylog2.indexer.indices.Indices in project graylog2-server by Graylog2.
the class IndexRangesCleanupPeriodical method doRun.
@Override
public void doRun() {
if (!cluster.isConnected() || !cluster.isHealthy()) {
LOG.info("Skipping index range cleanup because the Elasticsearch cluster is unreachable or unhealthy");
return;
}
final Set<String> indexNames = ImmutableSet.copyOf(indexSetRegistry.getManagedIndices());
final SortedSet<IndexRange> indexRanges = indexRangeService.findAll();
final Set<String> removedIndices = new HashSet<>();
for (IndexRange indexRange : indexRanges) {
if (!indexNames.contains(indexRange.indexName())) {
removedIndices.add(indexRange.indexName());
}
}
if (!removedIndices.isEmpty()) {
LOG.info("Removing index range information for unavailable indices: {}", removedIndices);
eventBus.post(IndicesDeletedEvent.create(removedIndices));
}
}
use of org.graylog2.indexer.indices.Indices in project graylog2-server by Graylog2.
the class IndicesResource method getOpenIndicesInfo.
private OpenIndicesInfo getOpenIndicesInfo(Set<IndexStatistics> indicesStatistics) {
final Map<String, IndexInfo> indexInfos = new HashMap<>();
final Set<String> indices = indicesStatistics.stream().map(IndexStatistics::index).collect(Collectors.toSet());
final Map<String, Boolean> areReopened = this.indices.areReopened(indices);
for (IndexStatistics indexStatistics : indicesStatistics) {
final IndexInfo indexInfo = IndexInfo.create(indexStatistics.primaryShards(), indexStatistics.allShards(), fillShardRoutings(indexStatistics.routing()), areReopened.get(indexStatistics.index()));
indexInfos.put(indexStatistics.index(), indexInfo);
}
return OpenIndicesInfo.create(indexInfos);
}
use of org.graylog2.indexer.indices.Indices in project graylog2-server by Graylog2.
the class IndicesResource method indexSetOpen.
@GET
@Path("/{indexSetId}/open")
@Timed
@ApiOperation(value = "Get information of all open indices managed by Graylog and their shards.")
@RequiresPermissions(RestPermissions.INDICES_READ)
@Produces(MediaType.APPLICATION_JSON)
public OpenIndicesInfo indexSetOpen(@ApiParam(name = "indexSetId") @PathParam("indexSetId") String indexSetId) {
final IndexSet indexSet = getIndexSet(indexSetRegistry, indexSetId);
final Set<IndexStatistics> indicesInfos = indices.getIndicesStats(indexSet).stream().filter(indexStats -> isPermitted(RestPermissions.INDICES_READ, indexStats.index())).collect(Collectors.toSet());
return getOpenIndicesInfo(indicesInfos);
}
use of org.graylog2.indexer.indices.Indices in project graylog2-server by Graylog2.
the class IndexRangesResource method rebuildIndex.
@POST
@Timed
@Path("/{index: [a-z_0-9-]+}/rebuild")
@ApiOperation(value = "Rebuild/sync index range information.", notes = "This triggers a system job that scans an index and stores meta information " + "about what indices contain messages in what time ranges. It atomically overwrites " + "already existing meta information.")
@ApiResponses(value = { @ApiResponse(code = 202, message = "Rebuild/sync system job triggered.") })
@Produces(MediaType.APPLICATION_JSON)
@AuditEvent(type = AuditEventTypes.ES_INDEX_RANGE_UPDATE_JOB)
public Response rebuildIndex(@ApiParam(name = "index", value = "The name of the Graylog-managed Elasticsearch index", required = true) @PathParam("index") @NotEmpty String index) {
if (!indexSetRegistry.isManagedIndex(index)) {
throw new BadRequestException(index + " is not a Graylog-managed Elasticsearch index.");
}
checkPermission(RestPermissions.INDEXRANGES_REBUILD, index);
final SystemJob rebuildJob = singleIndexRangeJobFactory.create(indexSetRegistry.getAll(), index);
try {
this.systemJobManager.submit(rebuildJob);
} catch (SystemJobConcurrencyException e) {
final String msg = "Concurrency level of this job reached: " + e.getMessage();
LOG.error(msg);
throw new ForbiddenException(msg, e);
}
return Response.accepted().build();
}
Aggregations