@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) { 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> 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); } } }
@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 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); } } }
/** * The {@link DeserializedEvent} payload must be a {@link JsonObject}. * * @param ievent Event that contains a JSON object deserialized payload. * @return the original or new event */ public InternalEvent perform(InternalEvent ievent) { DeserializedEvent devent; if ((devent = ievent.getEventObj()) == null) { return null; } Object payload = devent.getPayload(); if (payload == null) { return null; } if (!(payload instanceof JsonObject)) { throw new OperationException("Payload data is not a JsonObject"); } perform((JsonObject) payload); return ievent; } }
/** * The {@link DeserializedEvent} payload must be a {@link JsonObject}. * * @param ievent Event that contains a JSON object deserialized payload. * @return the original or new event */ public InternalEvent perform(InternalEvent ievent) { DeserializedEvent devent; if ((devent = ievent.getEventObj()) == null) { return null; } Object payload = devent.getPayload(); if (payload == null) { return null; } if (!(payload instanceof JsonObject)) { throw new OperationException("Payload data is not a JsonObject"); } perform((JsonObject) payload); 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; } }
@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; } }
@Test public void testOperationException() throws HandlerException { BaseHandler.CONFIG_FILE = "/config/handler_config.json"; handler.skipWriteStats = true; List<DummyEvent> events = new ArrayList<DummyEvent>(1); events.add(new DummyEvent("foo", 0)); TestContext context = new TestContext(); context.setInvokedFunctionArn("arn:aws:lambda:us-east-1:123:function:test:tag"); handler.init(context); List<OperationProcessor> operationProcessors = handler.sources.get(0).getOperationProcessors(); for (OperationProcessor operationProcessor : operationProcessors) { EventOperation operation = (EventOperation) spy(operationProcessor.getOperation()); doThrow(new OperationException("expected")).when(operation).perform(any()); operationProcessor.setOperation(operation); } handler.handler(events, context); assertEquals(1, operationProcessors.get(0).getErrorCountStat().getValue()); }