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();
}
}
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);
}
}
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();
}
}
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());
}
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());
}
Aggregations