Search in sources :

Example 1 with Topology

use of com.ibm.streamsx.topology.Topology in project streamsx.health by IBMStreams.

the class VinesAdapterService method main.

public static void main(String[] args) throws Exception {
    Option contextOption = Option.builder("c").longOpt("context-type").hasArg().argName("context type").required().build();
    Option hostOption = Option.builder("h").longOpt("host").hasArg().argName("host").required().build();
    Option portOption = Option.builder("p").longOpt("port").hasArg().argName("port").required().build();
    Option usernameOption = Option.builder("u").longOpt("username").hasArg().argName("username").required().build();
    Option passwordOption = Option.builder("P").longOpt("password").hasArg().argName("password").required().build();
    Option queueOption = Option.builder("q").longOpt("queue").hasArg().argName("queue").required().build();
    Option exchangeOption = Option.builder("e").longOpt("exchange").hasArg().argName("exchange name").required().build();
    Option debugOption = Option.builder("d").longOpt("debug").hasArg().argName("isDebugEnabled").required(false).type(Boolean.class).build();
    Option mappingEnabledOption = Option.builder("m").longOpt("mappingEnabled").hasArg().argName("isMappingEnabled").required().build();
    Options options = new Options();
    options.addOption(contextOption);
    options.addOption(hostOption);
    options.addOption(portOption);
    options.addOption(usernameOption);
    options.addOption(passwordOption);
    options.addOption(queueOption);
    options.addOption(exchangeOption);
    options.addOption(debugOption);
    options.addOption(mappingEnabledOption);
    CommandLineParser parser = new DefaultParser();
    CommandLine cmd = null;
    try {
        cmd = parser.parse(options, args);
    } catch (ParseException e) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("help", options);
        throw (e);
    }
    boolean isDebug = Boolean.valueOf(cmd.getOptionValue("d", Boolean.FALSE.toString()));
    HashMap<String, Object> params = new HashMap<String, Object>();
    params.put("hostAndPort", cmd.getOptionValue("h") + ":" + cmd.getOptionValue("p"));
    params.put("username", cmd.getOptionValue("u"));
    params.put("password", cmd.getOptionValue("P"));
    params.put("queueName", cmd.getOptionValue("q"));
    params.put("exchangeName", cmd.getOptionValue("e", ""));
    params.put("mappingEnabled", cmd.getOptionValue("m"));
    HashMap<String, Object> config = new HashMap<>();
    config.put(ContextProperties.SUBMISSION_PARAMS, params);
    if (isDebug) {
        config.put(ContextProperties.TRACING_LEVEL, TraceLevel.TRACE);
    }
    VinesAdapterService svc = new VinesAdapterService();
    svc.run(Type.valueOf(cmd.getOptionValue("c", "DISTRIBUTED")), config);
    if (isDebug) {
        // launch a debug service to print raw messages to the console
        Topology rawMsgTopo = new Topology("VinesRawMsgDebug");
        rawMsgTopo.subscribe(VinesAdapterService.VINES_DEBUG_TOPIC, String.class).print();
        StreamsContextFactory.getStreamsContext(Type.DISTRIBUTED).submit(rawMsgTopo).get();
        // launch a debug service to print Observation tuples to the console
        Topology obsTopo = new Topology("VinesObservationDebug");
        SubscribeConnector.subscribe(obsTopo, VinesAdapterService.VINES_TOPIC).print();
        StreamsContextFactory.getStreamsContext(Type.DISTRIBUTED).submit(obsTopo).get();
        // launch a debug service to print errors to the console
        Topology errTopo = new Topology("VinesErrorDebug");
        errTopo.subscribe(VinesAdapterService.VINES_ERROR_TOPIC, String.class).print();
        StreamsContextFactory.getStreamsContext(Type.DISTRIBUTED).submit(errTopo).get();
    }
}
Also used : Options(org.apache.commons.cli.Options) HashMap(java.util.HashMap) Topology(com.ibm.streamsx.topology.Topology) HelpFormatter(org.apache.commons.cli.HelpFormatter) CommandLine(org.apache.commons.cli.CommandLine) Option(org.apache.commons.cli.Option) JsonObject(com.google.gson.JsonObject) CommandLineParser(org.apache.commons.cli.CommandLineParser) ParseException(org.apache.commons.cli.ParseException) DefaultParser(org.apache.commons.cli.DefaultParser)

Example 2 with Topology

use of com.ibm.streamsx.topology.Topology in project streamsx.health by IBMStreams.

the class AdtIngest method run.

@Override
public void run() {
    Topology topology = new Topology("AdtIngest");
    AdtToModelMapper mapper = new AdtToModelMapper();
    addDependencies(topology);
    HapiMessageSupplier supplier = new HapiMessageSupplier(getPort());
    supplier.setMessageClass(ADT_AXX.class);
    TStream<Message> messages = topology.endlessSource(supplier);
    // transform message to ADTEvent object
    TStream<ADTEvent> adtEvents = messages.multiTransform(message -> {
        return mapper.messageToModel(message);
    });
    // publish data as JSON
    PublishAdtEvent.publish(adtEvents, getTopic());
    try {
        StreamsContextFactory.getStreamsContext(StreamsContext.Type.DISTRIBUTED).submit(topology);
    } catch (Exception e) {
        TRACE.error("Unable to submit topology", e);
    }
}
Also used : Message(ca.uhn.hl7v2.model.Message) AdtToModelMapper(com.ibm.streamsx.health.hapi.mapper.AdtToModelMapper) ADTEvent(com.ibm.streamsx.health.ingest.types.model.ADTEvent) Topology(com.ibm.streamsx.topology.Topology) HapiMessageSupplier(com.ibm.streamsx.health.hapi.internal.HapiMessageSupplier)

Example 3 with Topology

use of com.ibm.streamsx.topology.Topology in project streamsx.topology by IBMStreams.

the class StandaloneTester method preInvoke.

@Override
void preInvoke(AppEntity entity, File bundle) {
    Topology app = entity.app;
    if (app != null && app.hasTester()) {
        TupleCollection collector = (TupleCollection) app.getTester();
        collector.startLocalCollector();
    }
}
Also used : TupleCollection(com.ibm.streamsx.topology.internal.tester.TupleCollection) Topology(com.ibm.streamsx.topology.Topology)

Example 4 with Topology

use of com.ibm.streamsx.topology.Topology in project streamsx.topology by IBMStreams.

the class ParallelTest method testAdjacentParallel.

@Test
public void testAdjacentParallel() throws Exception {
    checkUdpSupported();
    List<String> stringList = getListOfUniqueStrings(800);
    String[] stringArray = new String[800];
    stringArray = stringList.toArray(stringArray);
    Topology topology = newTopology("testAdj");
    TStream<String> out0 = topology.strings(stringArray).parallel(of(20), TStream.Routing.HASH_PARTITIONED);
    out0 = out0.transform(randomStringProducer("region1")).endParallel();
    TStream<String> out2 = out0.parallel(of(5), TStream.Routing.HASH_PARTITIONED);
    out2 = out2.transform(randomStringProducer("region2")).endParallel();
    TStream<String> numRegions = out2.multiTransform(uniqueStringCounter(800, "region"));
    Tester tester = topology.getTester();
    Condition<List<String>> assertFinished = tester.stringContentsUnordered(numRegions, "20", "5");
    Condition<Long> expectedCount = tester.tupleCount(out2, 800);
    complete(tester, allConditions(assertFinished, expectedCount), 60, TimeUnit.SECONDS);
    assertTrue(expectedCount.valid());
    assertTrue(assertFinished.valid());
}
Also used : Tester(com.ibm.streamsx.topology.tester.Tester) ArrayList(java.util.ArrayList) List(java.util.List) Topology(com.ibm.streamsx.topology.Topology) TestTopology(com.ibm.streamsx.topology.test.TestTopology) Test(org.junit.Test)

Example 5 with Topology

use of com.ibm.streamsx.topology.Topology in project streamsx.topology by IBMStreams.

the class ParallelTest method fanoutEndParallelException.

/**
     * Currently a fan-out before an endParallel
     * is not supported. This is a limitation purely on
     * code generation.
     */
@Test(expected = IllegalStateException.class)
public void fanoutEndParallelException() throws Exception {
    checkUdpSupported();
    Topology topology = newTopology("testFanout");
    TStream<String> fanOut = topology.strings("hello").parallel(5).filter(new AllowAll<String>());
    fanOut.print();
    fanOut.endParallel();
    Tester tester = topology.getTester();
    Condition<Long> expectedCount = tester.tupleCount(fanOut, 1);
    complete(tester, expectedCount, 60, TimeUnit.SECONDS);
    assertTrue(expectedCount.valid());
}
Also used : Tester(com.ibm.streamsx.topology.tester.Tester) Topology(com.ibm.streamsx.topology.Topology) TestTopology(com.ibm.streamsx.topology.test.TestTopology) Test(org.junit.Test)

Aggregations

Topology (com.ibm.streamsx.topology.Topology)372 TestTopology (com.ibm.streamsx.topology.test.TestTopology)315 Test (org.junit.Test)301 List (java.util.List)116 Tester (com.ibm.streamsx.topology.tester.Tester)115 ArrayList (java.util.ArrayList)70 SPLStream (com.ibm.streamsx.topology.spl.SPLStream)68 HashMap (java.util.HashMap)49 TStream (com.ibm.streamsx.topology.TStream)42 Condition (com.ibm.streamsx.topology.tester.Condition)28 File (java.io.File)27 TimeUnit (java.util.concurrent.TimeUnit)27 StreamSchema (com.ibm.streams.operator.StreamSchema)26 Random (java.util.Random)26 JSONObject (com.ibm.json.java.JSONObject)23 HashSet (java.util.HashSet)23 RString (com.ibm.streams.operator.types.RString)21 StreamsContext (com.ibm.streamsx.topology.context.StreamsContext)21 Message (com.ibm.streamsx.topology.tuple.Message)20 SimpleMessage (com.ibm.streamsx.topology.tuple.SimpleMessage)20