use of org.graylog2.shared.system.activities.Activity in project graylog2-server by Graylog2.
the class MongoIndexSet method cycle.
@Override
public void cycle() {
if (!getConfig().isWritable()) {
LOG.debug("Not cycling non-writable index set <{}> ({})", getConfig().id(), getConfig().title());
return;
}
int oldTargetNumber;
try {
oldTargetNumber = getNewestIndexNumber();
} catch (NoTargetIndexException ex) {
oldTargetNumber = -1;
}
final int newTargetNumber = oldTargetNumber + 1;
final String newTarget = buildIndexName(newTargetNumber);
final String oldTarget = buildIndexName(oldTargetNumber);
if (oldTargetNumber == -1) {
LOG.info("Cycling from <none> to <{}>.", newTarget);
} else {
LOG.info("Cycling from <{}> to <{}>.", oldTarget, newTarget);
}
// Create new index.
LOG.info("Creating target index <{}>.", newTarget);
if (!indices.create(newTarget, this)) {
throw new RuntimeException("Could not create new target index <" + newTarget + ">.");
}
LOG.info("Waiting for allocation of index <{}>.", newTarget);
final HealthStatus healthStatus = indices.waitForRecovery(newTarget);
checkIfHealthy(healthStatus, (status) -> new RuntimeException("New target index did not become healthy (target index: <" + newTarget + ">)"));
LOG.debug("Health status of index <{}>: {}", newTarget, healthStatus);
addDeflectorIndexRange(newTarget);
LOG.info("Index <{}> has been successfully allocated.", newTarget);
// Point deflector to new index.
final String indexAlias = getWriteIndexAlias();
LOG.info("Pointing index alias <{}> to new index <{}>.", indexAlias, newTarget);
final Activity activity = new Activity(IndexSet.class);
if (oldTargetNumber == -1) {
// Only pointing, not cycling.
pointTo(newTarget);
activity.setMessage("Cycled index alias <" + indexAlias + "> from <none> to <" + newTarget + ">.");
} else {
// Re-pointing from existing old index to the new one.
LOG.debug("Switching over index alias <{}>.", indexAlias);
pointTo(newTarget, oldTarget);
setIndexReadOnlyAndCalculateRange(oldTarget);
activity.setMessage("Cycled index alias <" + indexAlias + "> from <" + oldTarget + "> to <" + newTarget + ">.");
}
LOG.info("Successfully pointed index alias <{}> to index <{}>.", indexAlias, newTarget);
activityWriter.write(activity);
auditEventSender.success(AuditActor.system(nodeId), ES_WRITE_INDEX_UPDATE, ImmutableMap.of("indexName", newTarget));
}
use of org.graylog2.shared.system.activities.Activity in project graylog2-server by Graylog2.
the class AbstractIndexCountBasedRetentionStrategy method runRetention.
private void runRetention(IndexSet indexSet, Map<String, Set<String>> deflectorIndices, int removeCount) {
final Set<String> orderedIndices = Arrays.stream(indexSet.getManagedIndices()).filter(indexName -> !indices.isReopened(indexName)).filter(indexName -> !(deflectorIndices.getOrDefault(indexName, Collections.emptySet()).contains(indexSet.getWriteIndexAlias()))).sorted((indexName1, indexName2) -> indexSet.extractIndexNumber(indexName2).orElse(0).compareTo(indexSet.extractIndexNumber(indexName1).orElse(0))).collect(Collectors.toCollection(LinkedHashSet::new));
LinkedList<String> orderedIndicesDescending = new LinkedList<>();
orderedIndices.stream().skip(orderedIndices.size() - removeCount).collect(Collectors.toCollection(LinkedList::new)).descendingIterator().forEachRemaining(orderedIndicesDescending::add);
String indexNamesAsString = String.join(", ", orderedIndicesDescending);
final String strategyName = this.getClass().getCanonicalName();
final String msg = "Running retention strategy [" + strategyName + "] for indices <" + indexNamesAsString + ">";
LOG.info(msg);
activityWriter.write(new Activity(msg, IndexRetentionThread.class));
retain(orderedIndicesDescending, indexSet);
}
use of org.graylog2.shared.system.activities.Activity in project graylog2-server by Graylog2.
the class AbstractIndexCountBasedRetentionStrategy method retain.
@Override
public void retain(IndexSet indexSet) {
final Map<String, Set<String>> deflectorIndices = indexSet.getAllIndexAliases();
final int indexCount = (int) deflectorIndices.keySet().stream().filter(indexName -> !indices.isReopened(indexName)).count();
final Optional<Integer> maxIndices = getMaxNumberOfIndices(indexSet);
if (!maxIndices.isPresent()) {
LOG.warn("No retention strategy configuration found, not running index retention!");
return;
}
// Do we have more indices than the configured maximum?
if (indexCount <= maxIndices.get()) {
LOG.debug("Number of indices ({}) lower than limit ({}). Not performing any retention actions.", indexCount, maxIndices.get());
return;
}
// We have more indices than the configured maximum! Remove as many as needed.
final int removeCount = indexCount - maxIndices.get();
final String msg = "Number of indices (" + indexCount + ") higher than limit (" + maxIndices.get() + "). " + "Running retention for " + removeCount + " indices.";
LOG.info(msg);
activityWriter.write(new Activity(msg, IndexRetentionThread.class));
runRetention(indexSet, deflectorIndices, removeCount);
}
use of org.graylog2.shared.system.activities.Activity in project graylog2-server by Graylog2.
the class InputStateListener method inputStateChanged.
@Subscribe
public void inputStateChanged(IOStateChangedEvent<MessageInput> event) {
final IOState<MessageInput> state = event.changedState();
final MessageInput input = state.getStoppable();
switch(event.newState()) {
case FAILED:
activityWriter.write(new Activity(state.getDetailedMessage(), InputRegistry.class));
Notification notification = notificationService.buildNow();
notification.addType(Notification.Type.INPUT_FAILED_TO_START).addSeverity(Notification.Severity.NORMAL);
notification.addNode(serverStatus.getNodeId().toString());
notification.addDetail("input_id", input.getId());
notification.addDetail("reason", state.getDetailedMessage());
notificationService.publishIfFirst(notification);
break;
case RUNNING:
notificationService.fixed(Notification.Type.NO_INPUT_RUNNING);
// fall through
default:
final String msg = "Input [" + input.getName() + "/" + input.getId() + "] is now " + event.newState().toString();
activityWriter.write(new Activity(msg, InputStateListener.class));
break;
}
LOG.debug("Input State of [{}/{}] changed: {} -> {}", input.getTitle(), input.getId(), event.oldState(), event.newState());
LOG.info("Input [{}/{}] is now {}", input.getName(), input.getId(), event.newState());
}
use of org.graylog2.shared.system.activities.Activity in project graylog2-server by Graylog2.
the class ServerBootstrap method startCommand.
@Override
protected void startCommand() {
final AuditEventSender auditEventSender = injector.getInstance(AuditEventSender.class);
final NodeId nodeId = injector.getInstance(NodeId.class);
final String systemInformation = Tools.getSystemInformation();
final Map<String, Object> auditEventContext = ImmutableMap.of("version", version.toString(), "java", systemInformation, "node_id", nodeId.toString());
auditEventSender.success(AuditActor.system(nodeId), NODE_STARTUP_INITIATE, auditEventContext);
final OS os = OS.getOs();
LOG.info("Graylog {} {} starting up", commandName, version);
LOG.info("JRE: {}", systemInformation);
LOG.info("Deployment: {}", configuration.getInstallationSource());
LOG.info("OS: {}", os.getPlatformName());
LOG.info("Arch: {}", os.getArch());
try {
if (configuration.isLeader() && configuration.runMigrations()) {
runMigrations();
}
} catch (Exception e) {
LOG.warn("Exception while running migrations", e);
System.exit(1);
}
final ServerStatus serverStatus = injector.getInstance(ServerStatus.class);
serverStatus.initialize();
startNodeRegistration(injector);
final ActivityWriter activityWriter;
final ServiceManager serviceManager;
final Service leaderElectionService;
try {
activityWriter = injector.getInstance(ActivityWriter.class);
serviceManager = injector.getInstance(ServiceManager.class);
leaderElectionService = injector.getInstance(Key.get(Service.class, Names.named("LeaderElectionService")));
} catch (ProvisionException e) {
LOG.error("Guice error", e);
annotateProvisionException(e);
auditEventSender.failure(AuditActor.system(nodeId), NODE_STARTUP_INITIATE, auditEventContext);
System.exit(-1);
return;
} catch (Exception e) {
LOG.error("Unexpected exception", e);
auditEventSender.failure(AuditActor.system(nodeId), NODE_STARTUP_INITIATE, auditEventContext);
System.exit(-1);
return;
}
Runtime.getRuntime().addShutdownHook(new Thread(injector.getInstance(shutdownHook())));
// propagate default size to input plugins
MessageInput.setDefaultRecvBufferSize(configuration.getUdpRecvBufferSizes());
// Start services.
final ServiceManagerListener serviceManagerListener = injector.getInstance(ServiceManagerListener.class);
serviceManager.addListener(serviceManagerListener, MoreExecutors.directExecutor());
try {
leaderElectionService.startAsync().awaitRunning();
serviceManager.startAsync().awaitHealthy();
} catch (Exception e) {
try {
serviceManager.stopAsync().awaitStopped(configuration.getShutdownTimeout(), TimeUnit.MILLISECONDS);
} catch (TimeoutException timeoutException) {
LOG.error("Unable to shutdown properly on time. {}", serviceManager.servicesByState());
}
LOG.error("Graylog startup failed. Exiting. Exception was:", e);
auditEventSender.failure(AuditActor.system(nodeId), NODE_STARTUP_INITIATE, auditEventContext);
System.exit(-1);
}
LOG.info("Services started, startup times in ms: {}", serviceManager.startupTimes());
activityWriter.write(new Activity("Started up.", Main.class));
LOG.info("Graylog " + commandName + " up and running.");
auditEventSender.success(AuditActor.system(nodeId), NODE_STARTUP_COMPLETE, auditEventContext);
// Block forever.
try {
Thread.currentThread().join();
} catch (InterruptedException e) {
return;
}
}
Aggregations