@SuppressWarnings({ "rawtypes", "unchecked" }) public VertexType(Vertex<? extends Oplet<?, ?>, ?, ?> value, IdMapper<String> ids) { this.id = (value instanceof ExecutableVertex) ? ids.add(value, ((ExecutableVertex) value).getInvocationId()) : // Can't get an id from the vertex, generate unique value ids.add(value); this.invocation = new InvocationType(value.getInstance()); }
@SuppressWarnings({ "rawtypes", "unchecked" }) public VertexType(Vertex<? extends Oplet<?, ?>, ?, ?> value, IdMapper<String> ids) { this.id = (value instanceof ExecutableVertex) ? ids.add(value, ((ExecutableVertex) value).getInvocationId()) : // Can't get an id from the vertex, generate unique value ids.add(value); this.invocation = new InvocationType(value.getInstance()); }
/** * Add counter metrics to all the topology's streams. * <p> * {@link CounterOp} oplets are inserted between every two graph * vertices with the following exceptions: * <ul> * <li>Oplets are only inserted upstream from a FanOut oplet.</li> * <li>If a chain of Peek oplets exists between oplets A and B, a Metric * oplet is inserted after the last Peek, right upstream from oplet B.</li> * <li>If a chain a Peek oplets is followed by a FanOut, a metric oplet is * inserted between the last Peek and the FanOut oplet.</li> * <li>Oplets are not inserted immediately downstream from another * {@code CounterOp} oplet (but they are inserted upstream from one.)</li> * </ul> * The implementation is not idempotent: Calling the method twice * will insert a new set of metric oplets into the graph. * @param t * The topology * @see org.apache.edgent.graph.Graph#peekAll(org.apache.edgent.function.Supplier, org.apache.edgent.function.Predicate) Graph.peekAll() */ public static void counter(Topology t) { // peekAll() embodies the above exclusion semantics t.graph().peekAll( () -> new CounterOp<>(), v -> !(v.getInstance() instanceof CounterOp) ); } }
@Test public void testMetricsEverywhere() throws Exception { Topology t = newTopology(); TStream<String> s = t.strings("a", "b", "c"); // Condition inserts a sink Condition<Long> tc = t.getTester().tupleCount(s, 3); Graph g = t.graph(); Collection<Vertex<? extends Oplet<?, ?>, ?, ?>> vertices = g.getVertices(); // Two vertices before submission assertEquals(2, vertices.size()); complete(t, tc); // At least three vertices after submission // (provide may have added other oplets as well) Collection<Vertex<? extends Oplet<?, ?>, ?, ?>> verticesAfterSubmit = g.getVertices(); assertTrue("size="+verticesAfterSubmit.size(), verticesAfterSubmit.size() >= 3); // There is exactly one vertex for a metric oplet int numOplets = 0; for (Vertex<? extends Oplet<?, ?>, ?, ?> v : verticesAfterSubmit) { Oplet<?,?> oplet = v.getInstance(); if (oplet instanceof CounterOp) { numOplets++; } } assertEquals(1, numOplets); }
Oplet<?,?> oplet = v.getInstance(); if (oplet instanceof StreamScope) { numOplets++;
PeriodicSource<?> src = null; for (Vertex<? extends Oplet<?, ?>, ?, ?> v : vertices) { Oplet<?,?> op = v.getInstance(); assertTrue(op instanceof PeriodicSource); src = (PeriodicSource<?>) op;
assertSame(op, v.getInstance());