public OperationProcessor(OperationFactory operationFactory) { super(operationFactory.getChildClass()); this.op = operationFactory.newInstance(); }
@Override protected void doSubstitution(InternalEvent ievent, DeserializedEvent devent) { Map<String, Object> metadata = getMetadata(ievent); try { devent.setField(this.key, metadata); } catch (FieldNotFoundException e) { if (this.failDstNotFound) { throw new OperationException(e); } } }
@Override protected void doSubstitution(InternalEvent ievent, DeserializedEvent devent) { Map<String, String> context = getContext(ievent); try { devent.setField(this.key, context); } catch (FieldNotFoundException e) { if (this.failDstNotFound) { throw new OperationException(e); } } }
@Override public void setConf(AbstractConfig config) { this.config = (ConditionalOperationConfig) config; List<Pair<FilterOperation, List<OperationProcessor>>> cases = new ArrayList<Pair<FilterOperation, List<OperationProcessor>>>(); OperationFactoryFactory off = new OperationFactoryFactory(); for (Condition caze : this.config.getConditions()) { List<OperationProcessor> processorsInCase = new ArrayList<OperationProcessor>(); /* * Create {@OperationProcessor}s from configs */ for (OperationConfig opConfig : caze.getOperations()) { try { processorsInCase.add(new OperationProcessor(off.getFactory(opConfig))); } catch (ClassNotFoundException e) { throw new RuntimeException(e); } } FilterOperation filter; try { filter = (FilterOperation) off.getFactory(caze.getCondition()).newInstance(); } catch (ClassNotFoundException e) { throw new RuntimeException(e); } cases.add( new ImmutablePair<FilterOperation, List<OperationProcessor>>(filter, processorsInCase)); } this.cases = cases; }
@Override public void setConf(AbstractConfig config) { this.config = (ForkOperationConfig) config; List<List<OperationProcessor>> processors = new ArrayList<List<OperationProcessor>>(); OperationFactoryFactory off = new OperationFactoryFactory(); for (Fork fork : this.config.getForks()) { List<OperationProcessor> processorsInFork = new ArrayList<OperationProcessor>(); for (OperationConfig opConfig : fork.getOperations()) { try { processorsInFork.add(new OperationProcessor(off.getFactory(opConfig))); } catch (ClassNotFoundException e) { throw new RuntimeException(e); } } processors.add(processorsInFork); } this.processors = processors; }
public Source(SourceConfig config) throws ClassNotFoundException { this.sourceRegex = Pattern.compile(config.getSourceRegex()); this.sourceName = config.getName(); DeserializerFactory dFactory = dff.getFactory(config.getDeserializerConfig()); this.deserProcessor = new DeserializerProcessor(dFactory.newInstance()); List<OperationConfig> operationConfigs = config.getOperationConfigs(); if (operationConfigs.size() > 0) { OperationFactoryFactory off = new OperationFactoryFactory(); for (OperationConfig operationConfig : operationConfigs) { this.operationProcessors.add(new OperationProcessor(off.getFactory(operationConfig))); } } this.containsStrings.addAll(config.getContainsStrings()); for (String strRegex : config.getRegexPatterns()) { this.regexPatterns.add(Pattern.compile(strRegex)); } }
@Override protected void doSubstitution(InternalEvent ievent, DeserializedEvent devent) { try { devent.setField(this.key, this.value); } catch (FieldNotFoundException e) { if (this.failDstNotFound) { throw new OperationException(e); } } } }
@Override public void setConf(AbstractConfig config) { this.config = (ForkOperationConfig) config; List<List<OperationProcessor>> processors = new ArrayList<List<OperationProcessor>>(); OperationFactoryFactory off = new OperationFactoryFactory(); for (Fork fork : this.config.getForks()) { List<OperationProcessor> processorsInFork = new ArrayList<OperationProcessor>(); for (OperationConfig opConfig : fork.getOperations()) { try { processorsInFork.add(new OperationProcessor(off.getFactory(opConfig))); } catch (ClassNotFoundException e) { throw new RuntimeException(e); } } processors.add(processorsInFork); } this.processors = processors; }
public Source(SourceConfig config) throws ClassNotFoundException { this.sourceRegex = Pattern.compile(config.getSourceRegex()); this.sourceName = config.getName(); DeserializerFactory dFactory = dff.getFactory(config.getDeserializerConfig()); this.deserProcessor = new DeserializerProcessor(dFactory.newInstance()); List<OperationConfig> operationConfigs = config.getOperationConfigs(); if (operationConfigs.size() > 0) { OperationFactoryFactory off = new OperationFactoryFactory(); for (OperationConfig operationConfig : operationConfigs) { this.operationProcessors.add(new OperationProcessor(off.getFactory(operationConfig))); } } this.containsStrings.addAll(config.getContainsStrings()); for (String strRegex : config.getRegexPatterns()) { this.regexPatterns.add(Pattern.compile(strRegex)); } }
@Override protected void doSubstitution(InternalEvent ievent, DeserializedEvent devent) { try { devent.setField(this.key, this.value); } catch (FieldNotFoundException e) { if (this.failDstNotFound) { throw new OperationException(e); } } } }
@Override protected void doSubstitution(InternalEvent ievent, DeserializedEvent devent) { Map<String, Object> metadata = getMetadata(ievent); try { devent.setField(this.key, metadata); } catch (FieldNotFoundException e) { if (this.failDstNotFound) { throw new OperationException(e); } } }
@Override protected void doSubstitution(InternalEvent ievent, DeserializedEvent devent) { Map<String, String> context = getContext(ievent); try { devent.setField(this.key, context); } catch (FieldNotFoundException e) { if (this.failDstNotFound) { throw new OperationException(e); } } }
public OperationProcessor(OperationFactory operationFactory) { super(operationFactory.getChildClass()); this.op = operationFactory.newInstance(); }
protected static long getTimestamp(String dvalue, TimeFieldType type) { long ts; switch (type) { case SECONDS: ts = (long) (Double.parseDouble(dvalue) * 1000); break; case MILLISECONDS: ts = (long) (Double.parseDouble(dvalue)); break; default: throw new OperationException("unsupported TimeFieldType"); } /* * Sanity Check */ try { return Time.toMilliseconds(ts); } catch (IllegalArgumentException e) { throw new OperationException(e); } }
protected String getFormattedString(String input) { if (input == null) { throw new OperationException("unable to find value for partition '" + this.getName() +"'"); } switch (this.stringFormat) { case NONE: return input; case TOUPPER: return input.toUpperCase(); case TOLOWER: return input.toLowerCase(); default: return input; } }
/** * The {@link DeserializedEvent} payload must be a {@link JsonObject}. * * @param event Event with payload to mutate. */ protected void mutateEvent(DeserializedEvent event) throws OperationException { Object payload = event.getPayload(); if (payload == null) { return; } if (!(payload instanceof JsonObject)) { throw new OperationException("Payload data is not a JsonObject"); } Object o; try { o = event.getField(path); } catch (FieldNotFoundException e) { throw new OperationException(e); } if (!(o instanceof JsonObject)) { throw new OperationException("specified node '" + path +"' is not an object"); } event.setPayload(o); }
protected String getFormattedString(String input) { if (input == null) { throw new OperationException("unable to find value for partition '" + this.getName() +"'"); } switch (this.stringFormat) { case NONE: return input; case TOUPPER: return input.toUpperCase(); case TOLOWER: return input.toLowerCase(); default: return input; } }
/** * The {@link DeserializedEvent} payload must be a {@link JsonObject}. * * @param event Event with payload to mutate. */ protected void mutateEvent(DeserializedEvent event) throws OperationException { Object payload = event.getPayload(); if (payload == null) { return; } if (!(payload instanceof JsonObject)) { throw new OperationException("Payload data is not a JsonObject"); } Object o; try { o = event.getField(path); } catch (FieldNotFoundException e) { throw new OperationException(e); } if (!(o instanceof JsonObject)) { throw new OperationException("specified node '" + path +"' is not an object"); } event.setPayload(o); }
@Override public InternalEvent perform(InternalEvent ievent) { String field; try { field = ievent.getEventObj().getFieldAsString(timeField); } catch (FieldNotFoundException e) { throw new OperationException( "time field " + timeField + " does not exist in " + ievent.getEventString()); } ievent.setEventTime(getTimestamp(field, timeFieldType)); return ievent; } }
@Override public InternalEvent perform(InternalEvent ievent) { String field; try { field = ievent.getEventObj().getFieldAsString(timeField); } catch (FieldNotFoundException e) { throw new OperationException( "time field " + timeField + " does not exist in " + ievent.getEventString()); } ievent.setEventTime(getTimestamp(field, timeFieldType)); return ievent; } }