Skip to content

Commit

Permalink
Changes to logging and pom dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
sathish.ks authored and sathish.ks committed Dec 19, 2016
1 parent 162c920 commit d84fa87
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 66 deletions.
38 changes: 12 additions & 26 deletions fabric-components/filter-processor/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,32 +51,23 @@
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-io</artifactId>
<version>1.3.2</version>
</dependency>
<!--<dependency>-->
<!--<groupId>org.apache.commons</groupId>-->
<!--<artifactId>commons-io</artifactId>-->
<!--<version>1.3.2</version>-->
<!--</dependency>-->

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.4.1.3</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
</dependency>
<!--<dependency>-->
<!--<groupId>com.fasterxml.jackson.core</groupId>-->
<!--<artifactId>jackson-databind</artifactId>-->
<!--<version>2.4.1.3</version>-->
<!--</dependency>-->
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
Expand All @@ -87,14 +78,9 @@
<artifactId>json-schema-validator</artifactId>
<version>2.2.6</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk</artifactId>
<version>${s3.version}</version>
</dependency>
</dependencies>
<build>

<build>
<sourceDirectory>src/main/java</sourceDirectory>
<testSourceDirectory>src/test/java</testSourceDirectory>
<resources>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@

package com.olacabs.fabric.jsonfilter.dsl;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.fge.jackson.JsonLoader;
Expand All @@ -28,9 +24,12 @@
import com.github.fge.jsonschema.main.JsonSchema;
import com.github.fge.jsonschema.main.JsonSchemaFactory;
import com.olacabs.fabric.jsonfilter.Filter;

import lombok.extern.slf4j.Slf4j;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

/**
* TODO javadoc.
*/
Expand All @@ -39,6 +38,8 @@ public final class BaseDslParser implements DslParser {

private static final String SCHEMAFILE = "dslSchema.json";

private static final ObjectMapper MAPPER = new ObjectMapper();

private JsonSchema schema = null;

private static class BaseDslParserHolder {
Expand Down Expand Up @@ -68,19 +69,16 @@ private BaseDslParser() throws IOException, ProcessingException {
public Filter parse(String dsl) throws IOException, ProcessingException {
Filter filter = null;
if (isValid(dsl)) {
ObjectMapper mapper = new ObjectMapper();
JsonNode jsonNode = mapper.readTree(dsl);
JsonNode jsonNode = MAPPER.readTree(dsl);
jsonNode = jsonNode.at("/filter");
filter = mapper.readValue(jsonNode.toString(), Filter.class);
filter = MAPPER.readValue(jsonNode.toString(), Filter.class);
}
log.debug(filter != null ? filter.toString() : null);
return filter;
}

private boolean isValid(String dsl) throws ProcessingException, IOException {

JsonNode jsonNode = JsonLoader.fromString(dsl);

ProcessingReport report;
report = schema.validate(jsonNode);

Expand All @@ -95,5 +93,4 @@ private JsonNode getSchemaFilezfromPath() throws IOException {
InputStream inputStream = classLoader.getResourceAsStream(SCHEMAFILE);
return JsonLoader.fromReader(new InputStreamReader(inputStream));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import com.fasterxml.jackson.annotation.JsonProperty;
import com.jayway.jsonpath.JsonPath;

import com.olacabs.fabric.jsonfilter.Filter;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
Expand Down Expand Up @@ -65,16 +64,13 @@ public boolean filter(String json) {
Object rhsValue = getRHS(document);
return evaluate(lhsValue, rhsValue, comparisonOperator);
} catch (Exception exception) {
log.debug(exception.getMessage());
System.err.println(exception.getMessage());
log.error("Error - {}", exception.getMessage(), exception);
}

return false;
}

private boolean evaluate(Comparable<Object> lhsValue, Object rhsValue, String comparisonOperatorLocal) {
if (null != rhsValue && null != lhsValue) {

int res = lhsValue.compareTo(rhsValue);
if (res == 0) {
if (comparisonOperatorLocal.equals(LTE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,19 @@
import com.jayway.jsonpath.Configuration;
import com.jayway.jsonpath.JsonPath;
import com.jayway.jsonpath.PathNotFoundException;

import com.olacabs.fabric.jsonfilter.Filter;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
import lombok.ToString;
import lombok.extern.slf4j.Slf4j;

/**
* TODO javadoc.
*/
@NoArgsConstructor
@AllArgsConstructor
@ToString
@Slf4j
public class ExistFilter implements Filter {

@JsonProperty("field")
Expand All @@ -42,7 +43,8 @@ public boolean filter(String json) {
Object document = Configuration.defaultConfiguration().jsonProvider().parse(json);
try {
JsonPath.read(document, this.field);
} catch (PathNotFoundException e) {
} catch (PathNotFoundException exception) {
log.error("Error - {}", exception.getMessage(), exception);
return false;
}
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,17 @@

package com.olacabs.fabric.jsonfilter.impl;

import java.util.List;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.jayway.jsonpath.Configuration;
import com.jayway.jsonpath.JsonPath;

import com.olacabs.fabric.jsonfilter.Filter;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
import lombok.ToString;
import lombok.extern.slf4j.Slf4j;

import java.util.List;

/**
* TODO javadoc.
*/
Expand All @@ -53,8 +52,7 @@ public boolean filter(String json) {
return true;
}
} catch (Exception exception) {
log.debug(exception.getMessage());
System.err.println(exception.getMessage());
log.error("Exception - {}", exception.getMessage(), exception);
}

return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public boolean filter(String json) {
return true;
}
} catch (Exception exception) {
log.debug(exception.getMessage());
log.error("Exception - {}", exception.getMessage(), exception);
}
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,6 @@

package com.olacabs.fabric.jsonfilter.processors.filters;

import java.util.List;
import java.util.Objects;
import java.util.Properties;
import java.util.stream.Collectors;

import org.apache.commons.lang.StringUtils;

import com.olacabs.fabric.compute.ProcessingContext;
import com.olacabs.fabric.compute.processor.InitializationException;
import com.olacabs.fabric.compute.processor.ProcessingException;
Expand All @@ -35,16 +28,21 @@
import com.olacabs.fabric.model.event.EventSet;
import com.olacabs.fabric.model.processor.Processor;
import com.olacabs.fabric.model.processor.ProcessorType;

import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;

import java.util.List;
import java.util.Objects;
import java.util.Properties;
import java.util.stream.Collectors;

/**
* TODO Add Javadoc.
*/
@Processor(namespace = "global", name = "json-filter-processor", version = "0.0.2",
@Processor(namespace = "global", name = "json-filter-processor", version = "1.0.0",
description = "A processor that filters json events",
cpu = 0.1, memory = 1, processorType = ProcessorType.EVENT_DRIVEN, requiredProperties = { "filterDsl" })
cpu = 0.1, memory = 128, processorType = ProcessorType.EVENT_DRIVEN, requiredProperties = {"filterDsl"})
@Slf4j
@Setter
public class JsonFilterProcessor extends StreamingProcessor {
Expand All @@ -59,7 +57,7 @@ public void initialize(String instanceId, Properties globalProperties,
globalProperties, "filterDsl", instanceId, componentMetadata);

if (null != filterDsl && StringUtils.isEmpty(filterDsl)) {
throw new RuntimeException("required Properties not found instanceId");
throw new InitializationException("required Properties not found instanceId");
}

try {
Expand All @@ -69,16 +67,14 @@ public void initialize(String instanceId, Properties globalProperties,
log.error(e.getMessage()
+ " unable to initialize processor instanceId: "
+ instanceId);
throw new RuntimeException(e);
throw new InitializationException(e);
}

}

@Override
protected EventSet consume(ProcessingContext context, EventSet eventSet) throws ProcessingException {

List<Event> events;
events = eventSet
List<Event> events = eventSet
.getEvents()
.parallelStream()
.filter(Objects::nonNull)
Expand All @@ -92,5 +88,4 @@ protected EventSet consume(ProcessingContext context, EventSet eventSet) throws
public void destroy() {

}

}

0 comments on commit d84fa87

Please sign in to comment.