use of org.graylog2.indexer.IndexSet in project graylog2-server by Graylog2.
the class IndexRotationThreadTest method testDoNotPerformRotation.
@Test
public void testDoNotPerformRotation() throws NoTargetIndexException {
final Provider<RotationStrategy> provider = new RotationStrategyProvider();
final IndexRotationThread rotationThread = new IndexRotationThread(notificationService, indices, indexSetRegistry, cluster, new NullActivityWriter(), nodeId, ImmutableMap.<String, Provider<RotationStrategy>>builder().put("strategy", provider).build());
when(indexSetConfig.rotationStrategyClass()).thenReturn("strategy");
rotationThread.checkForRotation(indexSet);
verify(indexSet, never()).cycle();
}
use of org.graylog2.indexer.IndexSet in project graylog2-server by Graylog2.
the class V20161116172200_CreateDefaultStreamMigrationTest method upgradePostsStreamsChangedEvent.
@Test
public void upgradePostsStreamsChangedEvent() throws Exception {
when(indexSetRegistry.getDefault()).thenReturn(indexSet);
when(streamService.load("000000000000000000000001")).thenThrow(NotFoundException.class);
final ArgumentCaptor<StreamsChangedEvent> argumentCaptor = ArgumentCaptor.forClass(StreamsChangedEvent.class);
migration.upgrade();
verify(clusterEventBus).post(argumentCaptor.capture());
final StreamsChangedEvent streamsChangedEvent = argumentCaptor.getValue();
assertThat(streamsChangedEvent.streamIds()).containsOnly(Stream.DEFAULT_STREAM_ID);
}
use of org.graylog2.indexer.IndexSet in project graylog2-server by Graylog2.
the class Indices method deleteIndexTemplate.
public void deleteIndexTemplate(IndexSet indexSet) {
final String templateName = indexSet.getConfig().indexTemplateName();
final DeleteIndexTemplateRequest deleteRequest = c.admin().indices().prepareDeleteTemplate(templateName).request();
try {
final boolean acknowledged = c.admin().indices().deleteTemplate(deleteRequest).actionGet().isAcknowledged();
if (acknowledged) {
LOG.info("Deleted Graylog index template \"{}\" in Elasticsearch.", templateName);
}
} catch (Exception e) {
LOG.error("Unable to delete the Graylog index template: " + templateName, e);
}
}
use of org.graylog2.indexer.IndexSet in project graylog2-server by Graylog2.
the class TimeBasedRotationStrategy method shouldRotate.
@Nullable
@Override
protected Result shouldRotate(String index, IndexSet indexSet) {
final IndexSetConfig indexSetConfig = requireNonNull(indexSet.getConfig(), "Index set configuration must not be null");
final String indexSetId = indexSetConfig.id();
checkState(!isNullOrEmpty(index), "Index name must not be null or empty");
checkState(!isNullOrEmpty(indexSetId), "Index set ID must not be null or empty");
checkState(indexSetConfig.rotationStrategy() instanceof TimeBasedRotationStrategyConfig, "Invalid rotation strategy config <" + indexSetConfig.rotationStrategy().getClass().getCanonicalName() + "> for index set <" + indexSetId + ">");
final TimeBasedRotationStrategyConfig config = (TimeBasedRotationStrategyConfig) indexSetConfig.rotationStrategy();
final Period rotationPeriod = config.rotationPeriod().normalizedStandard();
final DateTime now = Tools.nowUTC();
// when first started, we might not know the last rotation time, look up the creation time of the index instead.
if (!lastRotation.containsKey(indexSetId)) {
final DateTime creationDate = indices.indexCreationDate(index);
if (creationDate != null) {
final DateTime currentAnchor = determineRotationPeriodAnchor(creationDate, rotationPeriod);
anchor.put(indexSetId, currentAnchor);
lastRotation.put(indexSetId, creationDate);
}
// still not able to figure out the last rotation time, we'll rotate forcibly
if (!lastRotation.containsKey(indexSetId)) {
return new SimpleResult(true, "No known previous rotation time, forcing index rotation now.");
}
}
final DateTime currentAnchor = anchor.get(indexSetId);
final DateTime nextRotation = currentAnchor.plus(rotationPeriod);
if (nextRotation.isAfter(now)) {
final String message = new MessageFormat("Next rotation at {0}", Locale.ENGLISH).format(new Object[] { nextRotation });
return new SimpleResult(false, message);
}
// determine new anchor (push it to within less then one period before now) in case we missed one or more periods
DateTime tmpAnchor;
int multiplicator = 0;
do {
tmpAnchor = currentAnchor.withPeriodAdded(rotationPeriod, ++multiplicator);
} while (tmpAnchor.isBefore(now));
final DateTime nextAnchor = currentAnchor.withPeriodAdded(rotationPeriod, multiplicator - 1);
anchor.put(indexSetId, nextAnchor);
lastRotation.put(indexSetId, now);
final String message = new MessageFormat("Rotation period {0} elapsed, next rotation at {1}", Locale.ENGLISH).format(new Object[] { now, nextAnchor });
return new SimpleResult(true, message);
}
use of org.graylog2.indexer.IndexSet in project graylog2-server by Graylog2.
the class Searches method determineAffectedIndicesWithRanges.
public Set<IndexRange> determineAffectedIndicesWithRanges(TimeRange range, @Nullable String filter) {
final Optional<String> streamId = extractStreamId(filter);
IndexSet indexSet = null;
// a stream has changed: a stream only knows about its currently configured index set, no the history
if (streamId.isPresent()) {
try {
final Stream stream = streamService.load(streamId.get());
indexSet = stream.getIndexSet();
} catch (NotFoundException ignored) {
}
}
final ImmutableSortedSet.Builder<IndexRange> indices = ImmutableSortedSet.orderedBy(IndexRange.COMPARATOR);
final SortedSet<IndexRange> indexRanges = indexRangeService.find(range.getFrom(), range.getTo());
for (IndexRange indexRange : indexRanges) {
// if we aren't in a stream search, we look at all the ranges matching the time range.
if (indexSet == null && filter == null) {
indices.add(indexRange);
continue;
}
// A range applies to this search if either: the current index set of the stream matches or a previous index set matched.
final boolean streamInIndexRange = streamId.isPresent() && indexRange.streamIds() != null && indexRange.streamIds().contains(streamId.get());
final boolean streamInCurrentIndexSet = indexSet != null && indexSet.isManagedIndex(indexRange.indexName());
if (streamInIndexRange) {
indices.add(indexRange);
}
if (streamInCurrentIndexSet) {
indices.add(indexRange);
}
}
return indices.build();
}
Aggregations