Search in sources :

Example 1 with SinkParameters

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;
}
Also used : SinkParameters(io.mantisrx.runtime.parameter.SinkParameters) SinkConnectionStatusObserver(io.mantisrx.connector.job.core.SinkConnectionStatusObserver) MultiSinkConnectionStatusObserver(io.mantisrx.connector.job.core.MultiSinkConnectionStatusObserver) DefaultSinkConnectionStatusObserver(io.mantisrx.connector.job.core.DefaultSinkConnectionStatusObserver) Observable(rx.Observable) MantisSSEJob(io.mantisrx.client.MantisSSEJob)

Example 2 with SinkParameters

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);
    }
}
Also used : SubmitEphemeralJob(io.mantisrx.client.examples.SubmitEphemeralJob) Properties(java.util.Properties) Logger(org.slf4j.Logger) Args(com.sampullara.cli.Args) Argument(com.sampullara.cli.Argument) SinkParameters(io.mantisrx.runtime.parameter.SinkParameters) LoggerFactory(org.slf4j.LoggerFactory) Observer(rx.Observer) MantisSSEJob(io.mantisrx.client.MantisSSEJob) SinkConnectionsStatus(io.mantisrx.client.SinkConnectionsStatus) TimeUnit(java.util.concurrent.TimeUnit) CountDownLatch(java.util.concurrent.CountDownLatch) Map(java.util.Map) Subscription(rx.Subscription) SinkParameters(io.mantisrx.runtime.parameter.SinkParameters) CountDownLatch(java.util.concurrent.CountDownLatch) Subscription(rx.Subscription) SubmitEphemeralJob(io.mantisrx.client.examples.SubmitEphemeralJob) MantisSSEJob(io.mantisrx.client.MantisSSEJob)

Example 3 with SinkParameters

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);
}
Also used : SinkParameters(io.mantisrx.runtime.parameter.SinkParameters)

Example 4 with SinkParameters

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);
}
Also used : SinkParameters(io.mantisrx.runtime.parameter.SinkParameters)

Aggregations

SinkParameters (io.mantisrx.runtime.parameter.SinkParameters)4 MantisSSEJob (io.mantisrx.client.MantisSSEJob)2 Args (com.sampullara.cli.Args)1 Argument (com.sampullara.cli.Argument)1 SinkConnectionsStatus (io.mantisrx.client.SinkConnectionsStatus)1 SubmitEphemeralJob (io.mantisrx.client.examples.SubmitEphemeralJob)1 DefaultSinkConnectionStatusObserver (io.mantisrx.connector.job.core.DefaultSinkConnectionStatusObserver)1 MultiSinkConnectionStatusObserver (io.mantisrx.connector.job.core.MultiSinkConnectionStatusObserver)1 SinkConnectionStatusObserver (io.mantisrx.connector.job.core.SinkConnectionStatusObserver)1 Map (java.util.Map)1 Properties (java.util.Properties)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 TimeUnit (java.util.concurrent.TimeUnit)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1 Observable (rx.Observable)1 Observer (rx.Observer)1 Subscription (rx.Subscription)1