@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); } } } }
@Test(expected = OperationException.class) public void testGetEvaluatedPartitionsFieldNotFoundException() throws FieldNotFoundException { List<PartitionSpec> partitionSpecs = new ArrayList<PartitionSpec>(1); List<String> sources = Arrays.asList("one"); PartitionSpec spec = new PartitionSpec("foo", sources, PartitionSpec.Interpreter.STRING); partitionSpecs.add(spec); PartitionOperation op = new PartitionOperation(partitionSpecs); InternalEvent ievent = new InternalEvent("foo", null, 1); DummyStringEvent devent = spy(new DummyStringEvent("baz")); ievent.setEventObj(devent); doThrow(FieldNotFoundException.class).when(devent).getFieldAsString(any()); try { op.perform(ievent); } catch (OperationException e) { assertEquals("unable to find value for partition 'foo'", e.getMessage()); throw e; } }
@Test(expected = OperationException.class) public void testGetEvaluatedPartitionsStringMultipleFieldsNull() throws FieldNotFoundException { List<PartitionSpec> partitionSpecs = new ArrayList<PartitionSpec>(1); List<String> sources = Arrays.asList("one", "two"); PartitionSpec spec = new PartitionSpec("foo", sources, PartitionSpec.Interpreter.STRING); partitionSpecs.add(spec); PartitionOperation op = new PartitionOperation(partitionSpecs); InternalEvent ievent = new InternalEvent("foo", null, 1); DummyStringEvent devent = spy(new DummyStringEvent("baz")); ievent.setEventObj(devent); doThrow(FieldNotFoundException.class).doThrow(FieldNotFoundException.class).when(devent).getFieldAsString(any()); try { op.perform(ievent); } catch (OperationException e) { assertEquals("unable to find value for partition 'foo'", e.getMessage()); throw e; } }
@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); } } } }
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 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; } }
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 protected void doSubstitution(InternalEvent ievent, DeserializedEvent devent) { Map<String, Object> innerNest = new HashMap<String, Object>(this.substitutions.size()); doSubstitution(ievent, devent, innerNest); try { devent.setField(this.key, innerNest); } catch (FieldNotFoundException e) { if (this.failDstNotFound) { throw new OperationException(e); } } } }
@Override protected void doSubstitution(InternalEvent ievent, DeserializedEvent devent) { Map<String, Object> innerNest = new HashMap<String, Object>(this.substitutions.size()); doSubstitution(ievent, devent, innerNest); try { devent.setField(this.key, innerNest); } catch (FieldNotFoundException e) { if (this.failDstNotFound) { throw new OperationException(e); } } } }
@Override protected void doSubstitution(InternalEvent ievent, DeserializedEvent devent, Map<String, Object> nested) { Pair<String, Map<String, Object>> kv; try { kv = getRegexMatches(devent); } catch (FieldNotFoundException e) { if (this.failSrcNotFound) { throw new OperationException(e); } return; } nested.putAll(kv.getValue()); /* * Remove source field */ if (this.removeSrcField) { try { devent.removeField(kv.getKey()); } catch (FieldNotFoundException e) { if (this.failSrcNotFound) { throw new OperationException(e); } } } }
/** * 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 protected void doSubstitution(InternalEvent ievent, DeserializedEvent devent, Map<String, Object> nested) { Pair<String, Map<String, Object>> kv; try { kv = getRegexMatches(devent); } catch (FieldNotFoundException e) { if (this.failSrcNotFound) { throw new OperationException(e); } return; } nested.putAll(kv.getValue()); /* * Remove source field */ if (this.removeSrcField) { try { devent.removeField(kv.getKey()); } catch (FieldNotFoundException e) { if (this.failSrcNotFound) { 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, Object> nested) { Pair<String, Object> kv; try { kv = getFieldAndSource(devent, srcFields, false); } catch (FieldNotFoundException e) { if (this.failSrcNotFound) { throw new OperationException(e); } return; } nested.put(this.key, kv.getValue()); /* * Remove source field */ if (this.removeSrcField) { devent.deleteField(kv.getKey()); } }
@Override protected void doSubstitution(InternalEvent ievent, DeserializedEvent devent, Map<String, Object> nested) { Pair<String, Object> kv; try { kv = getFieldAndSource(devent, srcFields, false); } catch (FieldNotFoundException e) { if (this.failSrcNotFound) { throw new OperationException(e); } return; } nested.put(this.key, kv.getValue()); /* * Remove source field */ if (this.removeSrcField) { devent.deleteField(kv.getKey()); } }
@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); } } }
} catch (FieldNotFoundException e) { if (this.failSrcNotFound) { throw new OperationException(e); } catch (FieldNotFoundException e) { if (this.failDstNotFound) { throw new OperationException(e); } catch (FieldNotFoundException e) { if (this.failSrcNotFound) { 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); } } }