Skip to content

Commit

Permalink
Merge branch '1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
bernd committed Mar 5, 2015
2 parents 2dff3e6 + 44a2487 commit d713637
Show file tree
Hide file tree
Showing 26 changed files with 112 additions and 58 deletions.
6 changes: 4 additions & 2 deletions graylog2-radio/misc/graylog2-radio.conf
Expand Up @@ -16,8 +16,10 @@ rest_listen_uri = http://127.0.0.1:12950/

# REST API transport address. Defaults to the value of rest_listen_uri. Exception: If rest_listen_uri
# is set to a wildcard IP address (0.0.0.0) the first non-loopback IPv4 system address is used.
# This will be promoted in the cluster discovery APIs and other nodes may try to connect on this
# address. (see rest_listen_uri)
# If set, his will be promoted in the cluster discovery APIs, so other nodes may try to connect on
# this address and it is used to generate URLs addressing entities in the REST API. (see rest_listen_uri)
# You will need to define this, if your Graylog radio is running behind a HTTP proxy that is rewriting
# the scheme, host name or URI.
#rest_transport_uri = http://192.168.1.1:12950/

# Enable CORS headers for REST API. This is necessary for JS-clients accessing the server directly.
Expand Down
Expand Up @@ -130,8 +130,9 @@ public void deleteGrokPattern(GrokPattern pattern) throws APIException, IOExcept
api.path(routes.GrokResource().removePattern(pattern.id)).execute();
}

public void bulkLoadGrokPatterns(Collection<GrokPattern> patterns) throws APIException, IOException {
public void bulkLoadGrokPatterns(Collection<GrokPattern> patterns, boolean replace) throws APIException, IOException {
api.path(routes.GrokResource().bulkUpdatePatterns())
.queryParam("replace", String.valueOf(replace))
.body(new GrokPatternUpdateRequest(patterns))
.execute();

Expand Down
Expand Up @@ -16,7 +16,9 @@
*/
package org.graylog2.cluster;

public class NodeNotFoundException extends Exception {
import org.graylog2.database.NotFoundException;

public class NodeNotFoundException extends NotFoundException {
public NodeNotFoundException(String msg) {
super(msg);
}
Expand Down
Expand Up @@ -19,6 +19,7 @@
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import com.google.common.collect.Lists;
import org.graylog2.database.NotFoundException;
import org.graylog2.inputs.Input;
import org.graylog2.inputs.InputService;
import org.graylog2.plugin.Message;
Expand Down Expand Up @@ -75,17 +76,22 @@ private List<Extractor> loadExtractors(final String inputId) {
public List<Extractor> call() throws Exception {
LOG.debug("Re-loading extractors for input <{}> into cache.", inputId);

Input input = inputService.find(inputId);
try {
Input input = inputService.find(inputId);

List<Extractor> sorted = Lists.newArrayList(inputService.getExtractors(input));
List<Extractor> sorted = Lists.newArrayList(inputService.getExtractors(input));

Collections.sort(sorted, new Comparator<Extractor>() {
public int compare(Extractor e1, Extractor e2) {
return e1.getOrder().intValue() - e2.getOrder().intValue();
}
});
Collections.sort(sorted, new Comparator<Extractor>() {
public int compare(Extractor e1, Extractor e2) {
return e1.getOrder().intValue() - e2.getOrder().intValue();
}
});

return sorted;
return sorted;
} catch (NotFoundException e) {
LOG.warn("Unable to load input: {}", e.getMessage());
return Collections.emptyList();
}
}
});
} catch (ExecutionException e) {
Expand Down
Expand Up @@ -18,6 +18,7 @@

import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import org.graylog2.database.NotFoundException;
import org.graylog2.inputs.Input;
import org.graylog2.inputs.InputService;
import org.graylog2.plugin.Message;
Expand Down Expand Up @@ -75,8 +76,13 @@ private List<Map.Entry<String, String>> loadStaticFields(final String inputId) {
@Override
public List<Map.Entry<String, String>> call() throws Exception {
LOG.debug("Re-loading static fields for input <{}> into cache.", inputId);
final Input input = inputService.find(inputId);
return inputService.getStaticFields(input);
try {
final Input input = inputService.find(inputId);
return inputService.getStaticFields(input);
} catch (NotFoundException e) {
LOG.warn("Unable to load input: {}", e.getMessage());
return Collections.emptyList();
}
}
});
} catch (ExecutionException e) {
Expand Down
Expand Up @@ -20,6 +20,8 @@
import org.graylog2.database.NotFoundException;
import org.graylog2.plugin.database.ValidationException;

import java.util.Collection;
import java.util.List;
import java.util.Set;

@ImplementedBy(GrokPatternServiceImpl.class)
Expand All @@ -30,7 +32,11 @@ public interface GrokPatternService {

GrokPattern save(GrokPattern pattern) throws ValidationException;

List<GrokPattern> saveAll(Collection<GrokPattern> patterns, boolean replace) throws ValidationException;

boolean validate(GrokPattern pattern);

int delete(String patternName);

int deleteAll();
}
Expand Up @@ -17,6 +17,7 @@
package org.graylog2.grok;

import com.google.common.base.Strings;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
import com.google.common.collect.Sets;
import oi.thekraken.grok.api.Grok;
Expand All @@ -27,12 +28,15 @@
import org.graylog2.database.NotFoundException;
import org.graylog2.plugin.database.ValidationException;
import org.mongojack.DBCursor;
import org.mongojack.DBQuery;
import org.mongojack.JacksonDBCollection;
import org.mongojack.WriteResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.inject.Inject;
import java.util.Collection;
import java.util.List;
import java.util.Set;
import java.util.regex.PatternSyntaxException;

Expand Down Expand Up @@ -78,6 +82,21 @@ public GrokPattern save(GrokPattern pattern) throws ValidationException {
return result.getSavedObject();
}

@Override
public List<GrokPattern> saveAll(Collection<GrokPattern> patterns, boolean replace) throws ValidationException {
final ImmutableList.Builder<GrokPattern> savedPatterns = ImmutableList.builder();

if (replace) {
deleteAll();
}

for (final GrokPattern pattern : patterns) {
savedPatterns.add(save(pattern));
}

return savedPatterns.build();
}

@Override
public boolean validate(GrokPattern pattern) {
final boolean fieldsMissing = !(Strings.isNullOrEmpty(pattern.name) || Strings.isNullOrEmpty(pattern.pattern));
Expand All @@ -98,4 +117,9 @@ public boolean validate(GrokPattern pattern) {
public int delete(String patternId) {
return dbCollection.removeById(new ObjectId(patternId)).getN();
}

@Override
public int deleteAll() {
return dbCollection.remove(DBQuery.empty()).getN();
}
}
Expand Up @@ -51,7 +51,6 @@
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriBuilder;
import java.net.URI;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -139,7 +138,7 @@ public Response create(@ApiParam(name = "streamid", value = "The stream id this
}

final Map<String, String> result = ImmutableMap.of("alarmcallback_id", id);
final URI alarmCallbackUri = UriBuilder.fromResource(AlarmCallbackResource.class)
final URI alarmCallbackUri = getUriBuilderToSelf().path(AlarmCallbackResource.class)
.path("{alarmCallbackId}")
.build(streamid, id);

Expand Down
Expand Up @@ -66,7 +66,6 @@
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriBuilder;
import java.net.URI;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -122,7 +121,7 @@ public Response create(@ApiParam(name = "JSON body", required = true) CreateDash
dashboardRegistry.add(dashboard);

final Map<String, String> result = ImmutableMap.of("dashboard_id", id);
final URI dashboardUri = UriBuilder.fromResource(DashboardsResource.class)
final URI dashboardUri = getUriBuilderToSelf().path(DashboardsResource.class)
.path("{dashboardId}")
.build(id);

Expand Down Expand Up @@ -286,7 +285,7 @@ public Response addWidget(
}

final Map<String, String> result = ImmutableMap.of("widget_id", widget.getId());
final URI widgetUri = UriBuilder.fromResource(DashboardsResource.class)
final URI widgetUri = getUriBuilderToSelf().path(DashboardsResource.class)
.path("{dashboardId}/widgets/{widgetId}")
.build(dashboardId, widget.getId());

Expand Down
Expand Up @@ -46,7 +46,6 @@
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriBuilder;
import java.net.URI;
import java.util.Collections;
import java.util.Set;
Expand Down Expand Up @@ -83,7 +82,7 @@ public Response create(@ApiParam(name = "filterEntry", required = true)

final FilterDescription savedFilter = filterService.save(filterDescription);

final URI filterUri = UriBuilder.fromResource(BlacklistSourceResource.class)
final URI filterUri = getUriBuilderToSelf().path(BlacklistSourceResource.class)
.path("{filterId}")
.build(savedFilter._id);

Expand Down
Expand Up @@ -47,7 +47,6 @@
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriBuilder;
import java.net.URI;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -83,7 +82,7 @@ public Response create(@ApiParam(name = "JSON body", required = true)
final SavedSearch search = new SavedSearchImpl(searchData);
final String id = savedSearchService.save(search);

final URI searchUri = UriBuilder.fromResource(SavedSearchesResource.class)
final URI searchUri = getUriBuilderToSelf().path(SavedSearchesResource.class)
.path("{searchId}")
.build(id);

Expand Down
Expand Up @@ -66,7 +66,6 @@
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriBuilder;
import java.net.URI;
import java.util.ArrayList;
import java.util.Collections;
Expand Down Expand Up @@ -119,7 +118,7 @@ public Response create(@ApiParam(name = "JSON body", required = true) final Crea
}

final Map<String, String> result = ImmutableMap.of("stream_id", id);
final URI streamUri = UriBuilder.fromResource(StreamResource.class)
final URI streamUri = getUriBuilderToSelf().path(StreamResource.class)
.path("{streamId}")
.build(id);

Expand Down Expand Up @@ -337,7 +336,7 @@ public Response cloneStream(@ApiParam(name = "streamId", required = true) @PathP
}

final Map<String, String> result = ImmutableMap.of("stream_id", id);
final URI streamUri = UriBuilder.fromResource(StreamResource.class)
final URI streamUri = getUriBuilderToSelf().path(StreamResource.class)
.path("{streamId}")
.build(id);

Expand Down
Expand Up @@ -52,7 +52,6 @@
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriBuilder;
import java.net.URI;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -99,7 +98,7 @@ public Response create(@ApiParam(name = "streamId", value = "The stream id this
streamService.addAlertCondition(stream, alertCondition);

final Map<String, String> result = ImmutableMap.of("alert_condition_id", alertCondition.getId());
final URI alertConditionUri = UriBuilder.fromResource(StreamAlertConditionResource.class)
final URI alertConditionUri = getUriBuilderToSelf().path(StreamAlertConditionResource.class)
.path("{conditionId}")
.build(stream.getId(), alertCondition.getId());

Expand Down
Expand Up @@ -53,7 +53,6 @@
import javax.ws.rs.PathParam;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriBuilder;
import java.net.URI;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -106,7 +105,7 @@ public Response addReceiver(
final Stream stream = streamService.load(streamid);

// TODO What's the actual URI of the created resource?
final URI streamAlertUri = UriBuilder.fromResource(StreamAlertResource.class).build(streamid);
final URI streamAlertUri = getUriBuilderToSelf().path(StreamAlertResource.class).build(streamid);

// Maybe the list already contains this receiver?
if (stream.getAlertReceivers().containsKey(type) || stream.getAlertReceivers().get(type) != null) {
Expand Down
Expand Up @@ -51,7 +51,6 @@
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriBuilder;
import java.net.URI;
import java.util.List;

Expand Down Expand Up @@ -86,7 +85,7 @@ public Response create(@ApiParam(name = "streamid", value = "The stream id this

final SingleStreamRuleSummaryResponse response = SingleStreamRuleSummaryResponse.create(id);

final URI streamRuleUri = UriBuilder.fromResource(StreamRuleResource.class)
final URI streamRuleUri = getUriBuilderToSelf().path(StreamRuleResource.class)
.path("{streamRuleId}")
.build(streamId, id);

Expand Down
Expand Up @@ -34,14 +34,15 @@
import javax.validation.constraints.NotNull;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriBuilder;
import java.net.URI;


Expand Down Expand Up @@ -88,25 +89,27 @@ public Response createPattern(@ApiParam(name = "pattern", required = true)

final GrokPattern newPattern = grokPatternService.save(pattern);

final URI patternUri = UriBuilder.fromMethod(GrokResource.class, "listPattern").build(newPattern.id);
final URI patternUri = getUriBuilderToSelf().path(GrokResource.class, "listPattern").build(newPattern.id);

return Response.created(patternUri).entity(newPattern).build();
}

@PUT
@Timed
@ApiOperation("Add a list of new patterns")
public Response bulkUpdatePatterns(@ApiParam(name = "patterns", required = true) @NotNull GrokPatternList patternList) throws ValidationException {
public Response bulkUpdatePatterns(@ApiParam(name = "patterns", required = true) @NotNull GrokPatternList patternList,
@ApiParam(name = "replace", value = "Replace all patterns with the new ones.")
@QueryParam("replace") @DefaultValue("false") boolean replace) throws ValidationException {
checkPermission(RestPermissions.INPUTS_CREATE);

for (final GrokPattern pattern : patternList.patterns()) {
if (!grokPatternService.validate(pattern)) {
throw new ValidationException("Invalid pattern " + pattern + ". Did not save any patterns.");
}
}
for (final GrokPattern pattern : patternList.patterns()) {
grokPatternService.save(pattern);
}

grokPatternService.saveAll(patternList.patterns(), replace);

return Response.accepted().build();
}

Expand Down
Expand Up @@ -47,7 +47,6 @@
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriBuilder;
import java.net.URI;

@RequiresAuthentication
Expand Down Expand Up @@ -78,7 +77,7 @@ public Response createBundle(
final ConfigurationBundle configurationBundle) {
checkPermission(RestPermissions.BUNDLE_CREATE);
final ConfigurationBundle bundle = bundleService.insert(configurationBundle);
final URI bundleUri = UriBuilder.fromResource(BundleResource.class)
final URI bundleUri = getUriBuilderToSelf().path(BundleResource.class)
.path("{bundleId}")
.build(bundle.getId());

Expand Down

0 comments on commit d713637

Please sign in to comment.