Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/**
* 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.streams;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;
import com.mongodb.QueryBuilder;
import org.bson.types.ObjectId;
import org.graylog2.alarmcallbacks.AlarmCallbackConfiguration;
import org.graylog2.alarmcallbacks.AlarmCallbackConfigurationImpl;
import org.graylog2.alarmcallbacks.AlarmCallbackConfigurationService;
import org.graylog2.alarmcallbacks.EmailAlarmCallback;
import org.graylog2.alerts.Alert;
import org.graylog2.alerts.AlertService;
import org.graylog2.database.MongoConnection;
import org.graylog2.database.NotFoundException;
import org.graylog2.database.PersistedServiceImpl;
import org.graylog2.indexer.IndexSet;
import org.graylog2.indexer.MongoIndexSet;
import org.graylog2.indexer.indexset.IndexSetConfig;
import org.graylog2.indexer.indexset.IndexSetService;
import org.graylog2.notifications.Notification;
import org.graylog2.notifications.NotificationService;
import org.graylog2.plugin.Tools;
import org.graylog2.plugin.alarms.AlertCondition;
import org.graylog2.plugin.database.EmbeddedPersistable;
import org.graylog2.plugin.database.ValidationException;
import org.graylog2.plugin.streams.Output;
import org.graylog2.plugin.streams.Stream;
import org.graylog2.plugin.streams.StreamRule;
import org.graylog2.rest.resources.streams.requests.CreateStreamRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.annotation.Nullable;
import javax.inject.Inject;
import javax.ws.rs.BadRequestException;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Collectors;
import static com.google.common.base.Strings.isNullOrEmpty;
public class StreamServiceImpl extends PersistedServiceImpl implements StreamService {
private static final Logger LOG = LoggerFactory.getLogger(StreamServiceImpl.class);
private final StreamRuleService streamRuleService;
private final AlertService alertService;
private final OutputService outputService;
private final IndexSetService indexSetService;
private final MongoIndexSet.Factory indexSetFactory;
private final NotificationService notificationService;
private final AlarmCallbackConfigurationService alarmCallbackConfigurationService;
@Inject
public StreamServiceImpl(MongoConnection mongoConnection,
StreamRuleService streamRuleService,
AlertService alertService,
OutputService outputService,
IndexSetService indexSetService,
MongoIndexSet.Factory indexSetFactory,
NotificationService notificationService,
AlarmCallbackConfigurationService alarmCallbackConfigurationService) {
super(mongoConnection);
this.streamRuleService = streamRuleService;
this.alertService = alertService;
this.outputService = outputService;
this.indexSetService = indexSetService;
this.indexSetFactory = indexSetFactory;
this.notificationService = notificationService;
this.alarmCallbackConfigurationService = alarmCallbackConfigurationService;
}
@Nullable
private IndexSet getIndexSet(DBObject dbObject) {
return getIndexSet((String) dbObject.get(StreamImpl.FIELD_INDEX_SET_ID));
}
@Nullable
private IndexSet getIndexSet(String id) {
if (isNullOrEmpty(id)) {
return null;
}
final Optional indexSetConfig = indexSetService.get(id);
return indexSetConfig.flatMap(c -> Optional.of(indexSetFactory.create(c))).orElse(null);
}
public Stream load(ObjectId id) throws NotFoundException {
final DBObject o = get(StreamImpl.class, id);
if (o == null) {
throw new NotFoundException("Stream <" + id + "> not found!");
}
final List streamRules = streamRuleService.loadForStreamId(id.toHexString());
final Set