Search in sources :

Example 81 with JetInstance

use of com.hazelcast.jet.JetInstance in project hazelcast-jet-reference-manual by hazelcast.

the class Configuration method s1.

static void s1() {
    // tag::s1[]
    JetConfig config = new JetConfig();
    config.getInstanceConfig().setCooperativeThreadCount(2);
    JetInstance jet = Jet.newJetInstance(config);
// end::s1[]
}
Also used : JetInstance(com.hazelcast.jet.JetInstance) JetConfig(com.hazelcast.jet.config.JetConfig)

Example 82 with JetInstance

use of com.hazelcast.jet.JetInstance in project gora by apache.

the class LogAnalyticsJet method main.

/**
 * In the main method pageviews are fetched though the jet source connector.
 * Then those are grouped by url and day. Then a counting aggregator is
 * applied to calculate the aggregated daily pageviews. Then the result is
 * output through the jet sink connector to a gora compatible data store.
 */
public static void main(String[] args) throws Exception {
    Configuration conf = new Configuration();
    inStore = DataStoreFactory.getDataStore(Long.class, Pageview.class, conf);
    outStore = DataStoreFactory.getDataStore(String.class, MetricDatum.class, conf);
    Query<Long, Pageview> query = inStore.newQuery();
    JetEngine<Long, Pageview, String, MetricDatum> jetEngine = new JetEngine<>();
    Pipeline p = Pipeline.create();
    p.drawFrom(jetEngine.createDataSource(inStore, query)).groupingKey(e -> e.getValue().getUrl().toString()).aggregate(groupingBy(e -> getDay(e.getValue().getTimestamp()), counting())).map(e -> {
        MetricDatum metricDatum = new MetricDatum();
        String url = e.getKey();
        for (Map.Entry<Long, Long> item : e.getValue().entrySet()) {
            long timeStamp = item.getKey();
            long sum = item.getKey();
            metricDatum.setTimestamp(timeStamp);
            metricDatum.setMetric(sum);
        }
        metricDatum.setMetricDimension(url);
        return new JetInputOutputFormat<String, MetricDatum>(url + "_" + "ip", metricDatum);
    }).peek().drainTo(jetEngine.createDataSink(outStore));
    JetInstance jet = Jet.newJetInstance();
    try {
        jet.newJob(p).join();
    } finally {
        Jet.shutdownAll();
    }
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) JetInstance(com.hazelcast.jet.JetInstance) MetricDatum(org.apache.gora.tutorial.log.generated.MetricDatum) JetInputOutputFormat(org.apache.gora.jet.JetInputOutputFormat) Pipeline(com.hazelcast.jet.pipeline.Pipeline) Pageview(org.apache.gora.tutorial.log.generated.Pageview) JetEngine(org.apache.gora.jet.JetEngine) Map(java.util.Map)

Example 83 with JetInstance

use of com.hazelcast.jet.JetInstance in project gora by apache.

the class JetTest method jetWordCount.

@Test
public void jetWordCount() throws GoraException {
    dataStoreOut = DataStoreFactory.getDataStore(Long.class, ResultPageView.class, utility.getConfiguration());
    Query<Long, ResultPageView> query = dataStoreOut.newQuery();
    JetEngine<Long, ResultPageView, Long, ResultPageView> jetEngine = new JetEngine<>();
    Pattern delimiter = Pattern.compile("\\W+");
    Pipeline p = Pipeline.create();
    p.drawFrom(jetEngine.createDataSource(dataStoreOut, query)).flatMap(e -> traverseArray(delimiter.split(e.getValue().getUrl().toString()))).filter(word -> !word.isEmpty()).groupingKey(wholeItem()).aggregate(counting()).drainTo(Sinks.map("COUNTS"));
    JetInstance jet = Jet.newJetInstance();
    ;
    jet.newJob(p).join();
    IMap<String, Long> counts = jet.getMap("COUNTS");
    assertEquals(3L, (long) counts.get("the"));
}
Also used : AggregateOperations.counting(com.hazelcast.jet.aggregate.AggregateOperations.counting) JetInstance(com.hazelcast.jet.JetInstance) BatchSource(com.hazelcast.jet.pipeline.BatchSource) BeforeClass(org.junit.BeforeClass) Pipeline(com.hazelcast.jet.pipeline.Pipeline) DataStore(org.apache.gora.store.DataStore) Functions.wholeItem(com.hazelcast.jet.function.Functions.wholeItem) Sinks(com.hazelcast.jet.pipeline.Sinks) Test(org.junit.Test) Pageview(org.apache.gora.jet.generated.Pageview) ResultPageView(org.apache.gora.jet.generated.ResultPageView) Result(org.apache.gora.query.Result) DataStoreFactory(org.apache.gora.store.DataStoreFactory) IMap(com.hazelcast.core.IMap) HBaseTestingUtility(org.apache.hadoop.hbase.HBaseTestingUtility) Query(org.apache.gora.query.Query) Traversers.traverseArray(com.hazelcast.jet.Traversers.traverseArray) Jet(com.hazelcast.jet.Jet) Pattern(java.util.regex.Pattern) GoraException(org.apache.gora.util.GoraException) Assert.assertEquals(org.junit.Assert.assertEquals) Pattern(java.util.regex.Pattern) ResultPageView(org.apache.gora.jet.generated.ResultPageView) JetInstance(com.hazelcast.jet.JetInstance) Pipeline(com.hazelcast.jet.pipeline.Pipeline) Test(org.junit.Test)

Example 84 with JetInstance

use of com.hazelcast.jet.JetInstance in project beam by apache.

the class JetRunner method run.

private JetPipelineResult run(DAG dag) {
    startClusterIfNeeded(options);
    JetInstance jet = getJetInstance(// todo: we use single client for each job, it might be better to have a
    options);
    // shared client with refcount
    Job job = jet.newJob(dag, getJobConfig(options));
    IMap<String, MetricUpdates> metricsAccumulator = jet.getMap(JetMetricsContainer.getMetricsMapName(job.getId()));
    JetPipelineResult pipelineResult = new JetPipelineResult(job, metricsAccumulator);
    CompletableFuture<Void> completionFuture = job.getFuture().whenCompleteAsync((r, f) -> {
        pipelineResult.freeze(f);
        metricsAccumulator.destroy();
        jet.shutdown();
        stopClusterIfNeeded(options);
    });
    pipelineResult.setCompletionFuture(completionFuture);
    return pipelineResult;
}
Also used : MetricUpdates(org.apache.beam.runners.core.metrics.MetricUpdates) JetInstance(com.hazelcast.jet.JetInstance) Job(com.hazelcast.jet.Job)

Aggregations

JetInstance (com.hazelcast.jet.JetInstance)84 Test (org.junit.Test)45 Job (com.hazelcast.jet.Job)32 JetConfig (com.hazelcast.jet.config.JetConfig)22 MockPS (com.hazelcast.jet.core.TestProcessors.MockPS)14 Pipeline (com.hazelcast.jet.pipeline.Pipeline)14 JobConfig (com.hazelcast.jet.config.JobConfig)13 StuckProcessor (com.hazelcast.jet.core.TestProcessors.StuckProcessor)12 DAG (com.hazelcast.jet.core.DAG)10 ExpectedException (org.junit.rules.ExpectedException)10 Jet (com.hazelcast.jet.Jet)9 Assert.assertEquals (org.junit.Assert.assertEquals)9 JetService (com.hazelcast.jet.impl.JetService)8 Map (java.util.Map)8 CountDownLatch (java.util.concurrent.CountDownLatch)8 JobRepository (com.hazelcast.jet.impl.JobRepository)7 Sources (com.hazelcast.jet.pipeline.Sources)7 CancellationException (java.util.concurrent.CancellationException)7 Assert.assertNotNull (org.junit.Assert.assertNotNull)7 Before (org.junit.Before)7