Skip to content

Commit

Permalink
Consuming response objects in ExtractorService, deleting old classes.
Browse files Browse the repository at this point in the history
  • Loading branch information
dennisoelkers committed Mar 27, 2015
1 parent a696efe commit fb7f5ea
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 122 deletions.
Expand Up @@ -23,7 +23,6 @@
import com.google.inject.assistedinject.AssistedInject; import com.google.inject.assistedinject.AssistedInject;
import org.graylog2.rest.models.system.inputs.extractors.responses.ExtractorSummary; import org.graylog2.rest.models.system.inputs.extractors.responses.ExtractorSummary;
import org.graylog2.restclient.models.api.requests.CreateExtractorRequest; import org.graylog2.restclient.models.api.requests.CreateExtractorRequest;
import org.graylog2.restclient.models.api.responses.system.ExtractorSummaryResponse;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;


Expand All @@ -37,7 +36,6 @@ public class Extractor {
private static final Logger LOG = LoggerFactory.getLogger(Extractor.class); private static final Logger LOG = LoggerFactory.getLogger(Extractor.class);


public interface Factory { public interface Factory {
Extractor fromResponse(ExtractorSummaryResponse esr);
Extractor fromResponse(ExtractorSummary es); Extractor fromResponse(ExtractorSummary es);


Extractor forCreate(CursorStrategy cursorStrategy, Extractor forCreate(CursorStrategy cursorStrategy,
Expand Down Expand Up @@ -108,25 +106,6 @@ public static ConditionType fromString(String name) {


private long order; private long order;


@AssistedInject
private Extractor(UserService userService, @Assisted ExtractorSummaryResponse esr) {
this.id = esr.id;
this.title = esr.title;
this.cursorStrategy = CursorStrategy.fromString(esr.cursorStrategy);
this.sourceField = esr.sourceField;
this.targetField = esr.targetField;
this.extractorType = Type.fromString(esr.type);
this.creatorUser = userService.load(esr.creatorUserId);
this.extractorConfig = esr.extractorConfig;
this.converters = buildConverterList(esr.converters);
this.conditionType = ConditionType.fromString(esr.conditionType);
this.conditionValue = esr.conditionValue;
this.metrics = new ExtractorMetrics(esr.metrics.get("total"), esr.metrics.get("converters"));
this.exceptions = esr.exceptions;
this.converterExceptions = esr.converterExceptions;
this.order = esr.order;
}

@AssistedInject @AssistedInject
private Extractor(UserService userService, @Assisted ExtractorSummary es) { private Extractor(UserService userService, @Assisted ExtractorSummary es) {
this.id = es.id(); this.id = es.id();
Expand Down
Expand Up @@ -17,15 +17,15 @@
package org.graylog2.restclient.models; package org.graylog2.restclient.models;


import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import org.graylog2.rest.models.system.inputs.extractors.responses.ExtractorSummary;
import org.graylog2.rest.models.system.inputs.extractors.responses.ExtractorSummaryList;
import org.graylog2.rest.models.system.responses.GrokPatternSummary; import org.graylog2.rest.models.system.responses.GrokPatternSummary;
import org.graylog2.restclient.lib.APIException; import org.graylog2.restclient.lib.APIException;
import org.graylog2.restclient.lib.ApiClient; import org.graylog2.restclient.lib.ApiClient;
import org.graylog2.restclient.models.api.requests.CreateExtractorRequest; import org.graylog2.restclient.models.api.requests.CreateExtractorRequest;
import org.graylog2.restclient.models.api.requests.ExtractorOrderRequest; import org.graylog2.restclient.models.api.requests.ExtractorOrderRequest;
import org.graylog2.restclient.models.api.requests.GrokPatternUpdateRequest; import org.graylog2.restclient.models.api.requests.GrokPatternUpdateRequest;
import org.graylog2.restclient.models.api.responses.system.CreateExtractorResponse; import org.graylog2.restclient.models.api.responses.system.CreateExtractorResponse;
import org.graylog2.restclient.models.api.responses.system.ExtractorSummaryResponse;
import org.graylog2.restclient.models.api.responses.system.ExtractorsResponse;
import org.graylog2.restclient.models.api.responses.system.GrokPatternResponse; import org.graylog2.restclient.models.api.responses.system.GrokPatternResponse;
import org.graylog2.restroutes.generated.ExtractorsResource; import org.graylog2.restroutes.generated.ExtractorsResource;
import org.graylog2.restroutes.generated.routes; import org.graylog2.restroutes.generated.routes;
Expand Down Expand Up @@ -74,7 +74,7 @@ public void delete(Node node, Input input, String extractorId) throws IOExceptio
} }


public Extractor load(Node node, Input input, String extractorId) throws IOException, APIException { public Extractor load(Node node, Input input, String extractorId) throws IOException, APIException {
final ExtractorSummaryResponse extractorSummaryResponse = api.path(resource.single(input.getId(), extractorId), ExtractorSummaryResponse.class) final ExtractorSummary extractorSummaryResponse = api.path(resource.single(input.getId(), extractorId), ExtractorSummary.class)
.node(node) .node(node)
.execute(); .execute();


Expand All @@ -84,10 +84,10 @@ public Extractor load(Node node, Input input, String extractorId) throws IOExcep
public List<Extractor> all(Node node, Input input) throws IOException, APIException { public List<Extractor> all(Node node, Input input) throws IOException, APIException {
List<Extractor> extractors = Lists.newArrayList(); List<Extractor> extractors = Lists.newArrayList();


final ExtractorsResponse extractorsResponse = api.path(resource.list(input.getId()), ExtractorsResponse.class) final ExtractorSummaryList extractorsList = api.path(resource.list(input.getId()), ExtractorSummaryList.class)
.node(node) .node(node)
.execute(); .execute();
for (ExtractorSummaryResponse ex : extractorsResponse.extractors) { for (ExtractorSummary ex : extractorsList.extractors()) {
extractors.add(extractorFactory.fromResponse(ex)); extractors.add(extractorFactory.fromResponse(ex));
} }


Expand Down

This file was deleted.

This file was deleted.

Expand Up @@ -14,7 +14,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with Graylog. If not, see <http://www.gnu.org/licenses/>. * along with Graylog. If not, see <http://www.gnu.org/licenses/>.
*/ */
package org.graylog2.rest.models.system.inputs.requests; package org.graylog2.rest.models.system.inputs.extractors.requests;


import com.fasterxml.jackson.annotation.JsonAutoDetect; import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonCreator;
Expand Down
Expand Up @@ -14,7 +14,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with Graylog. If not, see <http://www.gnu.org/licenses/>. * along with Graylog. If not, see <http://www.gnu.org/licenses/>.
*/ */
package org.graylog2.rest.models.system.inputs.requests; package org.graylog2.rest.models.system.inputs.extractors.requests;


import com.fasterxml.jackson.annotation.JsonAutoDetect; import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonCreator;
Expand Down
Expand Up @@ -37,8 +37,8 @@
import org.graylog2.plugin.inputs.Converter; import org.graylog2.plugin.inputs.Converter;
import org.graylog2.plugin.inputs.Extractor; import org.graylog2.plugin.inputs.Extractor;
import org.graylog2.plugin.inputs.MessageInput; import org.graylog2.plugin.inputs.MessageInput;
import org.graylog2.rest.models.system.inputs.requests.CreateExtractorRequest; import org.graylog2.rest.models.system.inputs.extractors.requests.CreateExtractorRequest;
import org.graylog2.rest.models.system.inputs.requests.OrderExtractorsRequest; import org.graylog2.rest.models.system.inputs.extractors.requests.OrderExtractorsRequest;
import org.graylog2.shared.rest.resources.system.inputs.InputsResource; import org.graylog2.shared.rest.resources.system.inputs.InputsResource;
import org.graylog2.shared.security.RestPermissions; import org.graylog2.shared.security.RestPermissions;
import org.graylog2.shared.inputs.InputRegistry; import org.graylog2.shared.inputs.InputRegistry;
Expand Down Expand Up @@ -177,7 +177,7 @@ public ExtractorSummary update(@ApiParam(name = "inputId", required = true)
LOG.info(msg); LOG.info(msg);
activityWriter.write(new Activity(msg, ExtractorsResource.class)); activityWriter.write(new Activity(msg, ExtractorsResource.class));


return toMap(extractor); return toSummary(extractor);
} }


@GET @GET
Expand All @@ -199,7 +199,7 @@ public ExtractorSummaryList list(@ApiParam(name = "inputId", required = true)


final List<ExtractorSummary> extractors = Lists.newArrayList(); final List<ExtractorSummary> extractors = Lists.newArrayList();
for (Extractor extractor : inputService.getExtractors(input)) { for (Extractor extractor : inputService.getExtractors(input)) {
extractors.add(toMap(extractor)); extractors.add(toSummary(extractor));
} }


return ExtractorSummaryList.create(extractors); return ExtractorSummaryList.create(extractors);
Expand Down Expand Up @@ -230,7 +230,7 @@ public ExtractorSummary single(
final Input mongoInput = inputService.find(input.getPersistId()); final Input mongoInput = inputService.find(input.getPersistId());
final Extractor extractor = inputService.getExtractor(mongoInput, extractorId); final Extractor extractor = inputService.getExtractor(mongoInput, extractorId);


return toMap(extractor); return toSummary(extractor);
} }


@DELETE @DELETE
Expand Down Expand Up @@ -299,7 +299,7 @@ public void order(@ApiParam(name = "inputId", value = "Persist ID (!) of input."
LOG.info("Updated extractor ordering of input <persist:{}>.", inputPersistId); LOG.info("Updated extractor ordering of input <persist:{}>.", inputPersistId);
} }


private ExtractorSummary toMap(Extractor extractor) { private ExtractorSummary toSummary(Extractor extractor) {
final ExtractorMetrics metrics = ExtractorMetrics.create(MetricUtils.buildTimerMap(metricRegistry.getTimers().get(extractor.getTotalTimerName())), final ExtractorMetrics metrics = ExtractorMetrics.create(MetricUtils.buildTimerMap(metricRegistry.getTimers().get(extractor.getTotalTimerName())),
MetricUtils.buildTimerMap(metricRegistry.getTimers().get(extractor.getConverterTimerName()))); MetricUtils.buildTimerMap(metricRegistry.getTimers().get(extractor.getConverterTimerName())));


Expand Down

0 comments on commit fb7f5ea

Please sign in to comment.