use of io.mantisrx.runtime.parameter.SinkParameters in project mantis by Netflix.
the class JobSource method call.
@Override
public Observable<Observable<MantisServerSentEvent>> call(Context context, Index index) {
if (targets.isEmpty()) {
targets = parseInputParameters(context);
}
Observable<Observable<MantisServerSentEvent>> sourceObs = null;
int workerNo = context.getWorkerInfo().getWorkerNumber();
targets = enforceClientIdConsistency(targets, context.getJobId());
for (TargetInfo targetInfo : targets) {
MantisSSEJob job;
String sourceJobName = targetInfo.sourceJobName;
String criterion = targetInfo.criterion;
int samplePerSec = targetInfo.samplePerSec;
boolean enableMetaMessages = targetInfo.enableMetaMessages;
LOGGER.info("Processing job " + sourceJobName);
boolean singleton = false;
SinkConnectionStatusObserver obs = DefaultSinkConnectionStatusObserver.getInstance(singleton);
MultiSinkConnectionStatusObserver.INSTANCE.addSinkConnectionObserver(sourceJobName, obs);
String clientId = targetInfo.clientId;
if (targetInfo.isBroadcastMode) {
clientId = clientId + "_" + workerNo;
}
boolean enableCompressedBinary = targetInfo.enableCompressedBinary;
job = getSourceJob(sourceJobName, criterion, clientId, samplePerSec, enableMetaMessages, enableCompressedBinary, obs, Optional.<SinkParameters>empty());
if (sourceObs == null) {
sourceObs = job.connectAndGet();
} else {
if (job != null) {
Observable<Observable<MantisServerSentEvent>> clientObs = job.connectAndGet();
if (clientObs != null) {
sourceObs = sourceObs.mergeWith(clientObs);
} else {
LOGGER.error("Could not connect to job " + sourceJobName);
}
} else {
LOGGER.error("Could not connect to job " + sourceJobName);
}
}
}
return sourceObs;
}
use of io.mantisrx.runtime.parameter.SinkParameters in project mantis by Netflix.
the class MantisSourceJobConnector method main.
public static void main(String[] args) {
try {
SinkParameters params = new SinkParameters.Builder().withParameter("subscriptionId", "id1").withParameter("criterion", "select * where true").build();
Args.parse(MantisSourceJobConnector.class, args);
final CountDownLatch latch = new CountDownLatch(20);
MantisSourceJobConnector sourceJobConnector = new MantisSourceJobConnector();
MantisSSEJob job = sourceJobConnector.connectToJob("TestSourceJob", params);
Subscription subscription = job.connectAndGetObservable().doOnNext(o -> {
LOGGER.info("Got event: data: " + o.getEventAsString());
latch.countDown();
}).subscribe();
Subscription s2 = job.connectAndGetObservable().doOnNext(event -> {
LOGGER.info(" 2nd: Got event: data: " + event.getEventAsString());
latch.countDown();
}).subscribe();
try {
boolean await = latch.await(300, TimeUnit.SECONDS);
if (await)
System.out.println("PASSED");
else
System.err.println("FAILED!");
} catch (InterruptedException e) {
e.printStackTrace();
}
subscription.unsubscribe();
System.out.println("Unsubscribed");
} catch (IllegalArgumentException e) {
Args.usage(SubmitEphemeralJob.class);
System.exit(1);
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
}
use of io.mantisrx.runtime.parameter.SinkParameters in project mantis by Netflix.
the class AbstractJobSource method getJob.
public MantisSSEJob getJob(String jobName, String clientId, int samplePerSec, Observer<SinkConnectionsStatus> sinkConnObs, Optional<SinkParameters> sinkParamsO) {
LOGGER.info("Connecting to job " + jobName + " obs " + sinkConnObs);
boolean enableMetaMessages = false;
boolean enableCompressedBinaryInput = false;
MantisSourceJobConnector connector = MantisSourceJobConnectorFactory.getConnector();
SinkParameters defaultParams = getDefaultSinkParams(clientId, samplePerSec, Optional.<String>empty(), Optional.<String>empty(), enableMetaMessages, enableCompressedBinaryInput, DEFAULT_META_MSG_INTERVAL_MSEC);
return connector.connectToJob(jobName, sinkParamsO.orElse(defaultParams), sinkConnObs);
}
use of io.mantisrx.runtime.parameter.SinkParameters in project mantis by Netflix.
the class AbstractSourceJobSource method connectToQueryBasedJob.
private MantisSSEJob connectToQueryBasedJob(MantisSourceJobConnector connector, String criterion, String jobName, String clientId, int samplePerSec, boolean enableMetaMessages, boolean enableCompressedBinaryInput, Observer<SinkConnectionsStatus> sinkConnObs, Optional<SinkParameters> sinkParamsO) {
LOGGER.info("Connecting to " + jobName);
if (criterion == null || criterion.isEmpty()) {
throw new RuntimeException("Criterion cannot be empty");
}
String subId = Integer.toString(criterion.hashCode());
SinkParameters defaultParams = getDefaultSinkParams(clientId, samplePerSec, Optional.of(criterion), Optional.of(subId), enableMetaMessages, enableCompressedBinaryInput, 500);
return connector.connectToJob(jobName, sinkParamsO.orElse(defaultParams), sinkConnObs);
}
Aggregations