Search in sources :

Example 1 with NettyTextSink

use of edu.snu.mist.core.sinks.NettyTextSink in project mist by snuspl.

the class DefaultDagGeneratorImplTest method testPlanGenerator.

/**
 * Round-trip test of de-serializing AvroOperatorChainDag.
 * @throws org.apache.reef.tang.exceptions.InjectionException
 */
@Test
public void testPlanGenerator() throws InjectionException, IOException, URISyntaxException, ClassNotFoundException {
    // Generate a query
    final MISTQueryBuilder queryBuilder = new MISTQueryBuilder();
    queryBuilder.setApplicationId(TestParameters.SUPER_GROUP_ID);
    queryBuilder.socketTextStream(TestParameters.LOCAL_TEXT_SOCKET_SOURCE_CONF).flatMap(s -> Arrays.asList(s.split(" "))).filter(s -> s.startsWith("A")).map(s -> new Tuple2<>(s, 1)).reduceByKey(0, String.class, (Integer x, Integer y) -> x + y).textSocketOutput(TestParameters.HOST, TestParameters.SINK_PORT);
    final MISTQuery query = queryBuilder.build();
    // Generate avro operator chain dag
    final Tuple<List<AvroVertex>, List<Edge>> serializedDag = query.getAvroOperatorDag();
    final AvroDag.Builder avroDagBuilder = AvroDag.newBuilder();
    final AvroDag avroChainedDag = avroDagBuilder.setAppId(TestParameters.SUPER_GROUP_ID).setQueryId(TestParameters.QUERY_ID).setJarPaths(new ArrayList<>()).setAvroVertices(serializedDag.getKey()).setEdges(serializedDag.getValue()).build();
    final JavaConfigurationBuilder jcb = Tang.Factory.getTang().newConfigurationBuilder();
    jcb.bindNamedParameter(TaskHostname.class, "127.0.0.1");
    final Injector injector = Tang.Factory.getTang().newInjector(jcb.build());
    final ConfigDagGenerator configDagGenerator = injector.getInstance(ConfigDagGenerator.class);
    final DagGenerator dagGenerator = injector.getInstance(DagGenerator.class);
    final Tuple<String, AvroDag> tuple = new Tuple<>("query-test", avroChainedDag);
    final DAG<ConfigVertex, MISTEdge> configDag = configDagGenerator.generate(tuple.getValue());
    final ExecutionDag executionDag = dagGenerator.generate(configDag, new LinkedList<>());
    // Test execution dag
    final DAG<ExecutionVertex, MISTEdge> dag = executionDag.getDag();
    final Set<ExecutionVertex> sources = dag.getRootVertices();
    Assert.assertEquals(1, sources.size());
    Assert.assertTrue(sources.iterator().next() instanceof PhysicalSource);
    final PhysicalSource source = (PhysicalSource) sources.iterator().next();
    final Map<ExecutionVertex, MISTEdge> nextOps = dag.getEdges(source);
    Assert.assertEquals(1, nextOps.size());
    final PhysicalOperator flatMapOp = (PhysicalOperator) nextOps.entrySet().iterator().next().getKey();
    final PhysicalOperator filterOp = (PhysicalOperator) dag.getEdges(flatMapOp).entrySet().iterator().next().getKey();
    final PhysicalOperator mapOp = (PhysicalOperator) dag.getEdges(filterOp).entrySet().iterator().next().getKey();
    final PhysicalOperator reduceByKeyOp = (PhysicalOperator) dag.getEdges(mapOp).entrySet().iterator().next().getKey();
    final PhysicalSink sink = (PhysicalSink) dag.getEdges(reduceByKeyOp).entrySet().iterator().next().getKey();
    Assert.assertTrue(flatMapOp.getOperator() instanceof FlatMapOperator);
    Assert.assertTrue(filterOp.getOperator() instanceof FilterOperator);
    Assert.assertTrue(mapOp.getOperator() instanceof MapOperator);
    Assert.assertTrue(reduceByKeyOp.getOperator() instanceof ReduceByKeyOperator);
    Assert.assertTrue(sink.getSink() instanceof NettyTextSink);
}
Also used : Injector(org.apache.reef.tang.Injector) java.util(java.util) NettyTextSink(edu.snu.mist.core.sinks.NettyTextSink) Tuple2(edu.snu.mist.common.types.Tuple2) URISyntaxException(java.net.URISyntaxException) MISTEdge(edu.snu.mist.common.graph.MISTEdge) AvroDag(edu.snu.mist.formats.avro.AvroDag) MISTQuery(edu.snu.mist.client.MISTQuery) ReduceByKeyOperator(edu.snu.mist.core.operators.ReduceByKeyOperator) ServerSocket(java.net.ServerSocket) DAG(edu.snu.mist.common.graph.DAG) MISTQueryBuilder(edu.snu.mist.client.MISTQueryBuilder) After(org.junit.After) MapOperator(edu.snu.mist.core.operators.MapOperator) Before(org.junit.Before) Tang(org.apache.reef.tang.Tang) Tuple(org.apache.reef.io.Tuple) Test(org.junit.Test) IOException(java.io.IOException) TestParameters(edu.snu.mist.core.utils.TestParameters) TaskHostname(edu.snu.mist.core.parameters.TaskHostname) FilterOperator(edu.snu.mist.core.operators.FilterOperator) Edge(edu.snu.mist.formats.avro.Edge) FlatMapOperator(edu.snu.mist.core.operators.FlatMapOperator) JavaConfigurationBuilder(org.apache.reef.tang.JavaConfigurationBuilder) AvroVertex(edu.snu.mist.formats.avro.AvroVertex) InjectionException(org.apache.reef.tang.exceptions.InjectionException) Assert(org.junit.Assert) FlatMapOperator(edu.snu.mist.core.operators.FlatMapOperator) NettyTextSink(edu.snu.mist.core.sinks.NettyTextSink) AvroDag(edu.snu.mist.formats.avro.AvroDag) MapOperator(edu.snu.mist.core.operators.MapOperator) FlatMapOperator(edu.snu.mist.core.operators.FlatMapOperator) Injector(org.apache.reef.tang.Injector) JavaConfigurationBuilder(org.apache.reef.tang.JavaConfigurationBuilder) MISTEdge(edu.snu.mist.common.graph.MISTEdge) MISTQueryBuilder(edu.snu.mist.client.MISTQueryBuilder) FilterOperator(edu.snu.mist.core.operators.FilterOperator) ReduceByKeyOperator(edu.snu.mist.core.operators.ReduceByKeyOperator) MISTQuery(edu.snu.mist.client.MISTQuery) Tuple(org.apache.reef.io.Tuple) Test(org.junit.Test)

Example 2 with NettyTextSink

use of edu.snu.mist.core.sinks.NettyTextSink in project mist by snuspl.

the class PhysicalObjectGeneratorTest method testSuccessOfSink.

@Test
public void testSuccessOfSink() throws IOException, InjectionException {
    final int port = 13667;
    final ServerSocket socket = new ServerSocket(port);
    final Map<String, String> conf = new HashMap<String, String>() {

        {
            put(ConfKeys.SinkConf.SINK_TYPE.name(), ConfValues.SinkType.NETTY.name());
            put(ConfKeys.NettySink.SINK_ADDRESS.name(), "localhost");
            put(ConfKeys.NettySink.SINK_PORT.name(), String.valueOf(port));
        }
    };
    final Sink sink = generator.newSink(conf, classLoader);
    Assert.assertTrue(sink instanceof NettyTextSink);
    socket.close();
}
Also used : NettyTextSink(edu.snu.mist.core.sinks.NettyTextSink) Sink(edu.snu.mist.core.sinks.Sink) MqttSink(edu.snu.mist.core.sinks.MqttSink) HashMap(java.util.HashMap) NettyTextSink(edu.snu.mist.core.sinks.NettyTextSink) ServerSocket(java.net.ServerSocket) Test(org.junit.Test)

Example 3 with NettyTextSink

use of edu.snu.mist.core.sinks.NettyTextSink in project mist by snuspl.

the class PhysicalObjectGenerator method newSink.

/**
 * Get a new sink.
 * @param conf configuration
 * @param classLoader external class loader
 * @return new sink
 */
@SuppressWarnings("unchecked")
public <T> Sink<T> newSink(final Map<String, String> conf, final ClassLoader classLoader) throws IOException {
    final String type = conf.get(ConfKeys.SinkConf.SINK_TYPE.name());
    if (type.equals(ConfValues.SinkType.NETTY.name())) {
        final String serverAddress = conf.get(ConfKeys.NettySink.SINK_ADDRESS.name());
        final int serverPort = Integer.valueOf(conf.get(ConfKeys.NettySink.SINK_PORT.name()));
        return (Sink<T>) new NettyTextSink(serverAddress, serverPort, nettySharedResource, identifierFactory);
    } else if (type.equals(ConfValues.SinkType.MQTT.name())) {
        final String brokerURI = conf.get(ConfKeys.MqttSink.MQTT_SINK_BROKER_URI.name());
        final String topic = conf.get(ConfKeys.MqttSink.MQTT_SINK_TOPIC.name());
        try {
            return (Sink<T>) new MqttSink(brokerURI, topic, mqttSharedResource);
        } catch (final MqttException e) {
            e.printStackTrace();
            throw new IOException(e);
        }
    } else {
        throw new RuntimeException("Invalid sink type: " + type);
    }
}
Also used : MqttSink(edu.snu.mist.core.sinks.MqttSink) NettyTextSink(edu.snu.mist.core.sinks.NettyTextSink) Sink(edu.snu.mist.core.sinks.Sink) MqttSink(edu.snu.mist.core.sinks.MqttSink) MqttException(org.eclipse.paho.client.mqttv3.MqttException) NettyTextSink(edu.snu.mist.core.sinks.NettyTextSink) IOException(java.io.IOException)

Aggregations

NettyTextSink (edu.snu.mist.core.sinks.NettyTextSink)3 MqttSink (edu.snu.mist.core.sinks.MqttSink)2 Sink (edu.snu.mist.core.sinks.Sink)2 IOException (java.io.IOException)2 ServerSocket (java.net.ServerSocket)2 Test (org.junit.Test)2 MISTQuery (edu.snu.mist.client.MISTQuery)1 MISTQueryBuilder (edu.snu.mist.client.MISTQueryBuilder)1 DAG (edu.snu.mist.common.graph.DAG)1 MISTEdge (edu.snu.mist.common.graph.MISTEdge)1 Tuple2 (edu.snu.mist.common.types.Tuple2)1 FilterOperator (edu.snu.mist.core.operators.FilterOperator)1 FlatMapOperator (edu.snu.mist.core.operators.FlatMapOperator)1 MapOperator (edu.snu.mist.core.operators.MapOperator)1 ReduceByKeyOperator (edu.snu.mist.core.operators.ReduceByKeyOperator)1 TaskHostname (edu.snu.mist.core.parameters.TaskHostname)1 TestParameters (edu.snu.mist.core.utils.TestParameters)1 AvroDag (edu.snu.mist.formats.avro.AvroDag)1 AvroVertex (edu.snu.mist.formats.avro.AvroVertex)1 Edge (edu.snu.mist.formats.avro.Edge)1