org.graylog2.indexer.ranges.RebuildIndexRangesJob Maven / Gradle / Ivy
/**
* This file is part of Graylog.
*
* Graylog is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Graylog is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Graylog. If not, see .
*/
package org.graylog2.indexer.ranges;
import com.google.common.base.Stopwatch;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.inject.assistedinject.Assisted;
import com.google.inject.assistedinject.AssistedInject;
import org.elasticsearch.search.SearchHit;
import org.graylog2.indexer.Deflector;
import org.graylog2.indexer.EmptyIndexException;
import org.graylog2.indexer.searches.Searches;
import org.graylog2.plugin.Tools;
import org.graylog2.plugin.ServerStatus;
import org.graylog2.shared.system.activities.Activity;
import org.graylog2.shared.system.activities.ActivityWriter;
import org.graylog2.system.jobs.SystemJob;
import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
public class RebuildIndexRangesJob extends SystemJob {
public interface Factory {
public RebuildIndexRangesJob create(Deflector deflector);
}
private static final Logger LOG = LoggerFactory.getLogger(RebuildIndexRangesJob.class);
public static final int MAX_CONCURRENCY = 1;
private boolean cancelRequested = false;
private int indicesToCalculate = 0;
private int indicesCalculated = 0;
protected final Deflector deflector;
private final Searches searches;
private final ActivityWriter activityWriter;
protected final IndexRangeService indexRangeService;
@AssistedInject
public RebuildIndexRangesJob(@Assisted Deflector deflector,
ServerStatus serverStatus,
Searches searches,
ActivityWriter activityWriter,
IndexRangeService indexRangeService) {
super(serverStatus);
this.deflector = deflector;
this.searches = searches;
this.activityWriter = activityWriter;
this.indexRangeService = indexRangeService;
}
@Override
public void requestCancel() {
this.cancelRequested = true;
}
@Override
public int getProgress() {
if (indicesToCalculate <= 0) {
return 0;
}
// lolwtfbbqcasting
return (int) Math.floor(((float) indicesCalculated / (float) indicesToCalculate)*100);
}
@Override
public String getDescription() {
return "Rebuilds index range information.";
}
@Override
public void execute() {
List