Search in sources :

Example 1 with TransStarter

use of org.pentaho.di.trans.dataservice.execution.TransStarter in project pdi-dataservice-server-plugin by pentaho.

the class DataServiceExecutor method prepareExecution.

protected void prepareExecution() throws KettleException {
    // Setup executor with streaming execution plan
    ImmutableMultimap.Builder<ExecutionPoint, Runnable> builder = ImmutableMultimap.builder();
    builder.putAll(ExecutionPoint.PREPARE, new CopyParameters(parameters, serviceTrans), new PrepareExecution(serviceTrans));
    if (!service.isStreaming()) {
        builder.put(ExecutionPoint.PREPARE, new PrepareExecution(genTrans));
        builder.putAll(ExecutionPoint.READY, new DefaultTransWiring(this));
        builder.putAll(ExecutionPoint.START, new TransStarter(genTrans), new TransStarter(serviceTrans));
    }
    listenerMap.putAll(builder.build());
}
Also used : CopyParameters(org.pentaho.di.trans.dataservice.execution.CopyParameters) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) PrepareExecution(org.pentaho.di.trans.dataservice.execution.PrepareExecution) DefaultTransWiring(org.pentaho.di.trans.dataservice.execution.DefaultTransWiring) TransStarter(org.pentaho.di.trans.dataservice.execution.TransStarter)

Example 2 with TransStarter

use of org.pentaho.di.trans.dataservice.execution.TransStarter in project pdi-dataservice-server-plugin by pentaho.

the class CachedServiceLoader method replay.

ListenableFuture<Integer> replay(DataServiceExecutor dataServiceExecutor) throws KettleException {
    final Trans serviceTrans = dataServiceExecutor.getServiceTrans(), genTrans = dataServiceExecutor.getGenTrans();
    final CountDownLatch startReplay = new CountDownLatch(1);
    final RowProducer rowProducer = dataServiceExecutor.addRowProducer();
    List<Runnable> startTrans = dataServiceExecutor.getListenerMap().get(DataServiceExecutor.ExecutionPoint.START), postOptimization = dataServiceExecutor.getListenerMap().get(DataServiceExecutor.ExecutionPoint.READY);
    Iterables.removeIf(postOptimization, Predicates.instanceOf(DefaultTransWiring.class));
    Iterables.removeIf(startTrans, new Predicate<Runnable>() {

        @Override
        public boolean apply(Runnable runnable) {
            return runnable instanceof TransStarter && ((TransStarter) runnable).getTrans().equals(serviceTrans);
        }
    });
    postOptimization.add(new Runnable() {

        @Override
        public void run() {
            serviceTrans.stopAll();
            for (StepMetaDataCombi stepMetaDataCombi : serviceTrans.getSteps()) {
                stepMetaDataCombi.step.setOutputDone();
                stepMetaDataCombi.step.dispose(stepMetaDataCombi.meta, stepMetaDataCombi.data);
                stepMetaDataCombi.step.markStop();
            }
        }
    });
    startTrans.add(new Runnable() {

        @Override
        public void run() {
            startReplay.countDown();
        }
    });
    ListenableFutureTask<Integer> replay = ListenableFutureTask.create(new Callable<Integer>() {

        @Override
        public Integer call() throws Exception {
            Preconditions.checkState(startReplay.await(30, TimeUnit.SECONDS), "Cache replay did not start");
            int rowCount = 0;
            for (Iterator<RowMetaAndData> iterator = rowSupplier.get(); iterator.hasNext() && genTrans.isRunning(); ) {
                RowMetaAndData metaAndData = iterator.next();
                boolean rowAdded = false;
                RowMetaInterface rowMeta = metaAndData.getRowMeta();
                Object[] rowData = rowMeta.cloneRow(metaAndData.getData());
                while (!rowAdded && genTrans.isRunning()) {
                    rowAdded = rowProducer.putRowWait(rowMeta, rowData, 10, TimeUnit.SECONDS);
                }
                if (rowAdded) {
                    rowCount += 1;
                }
            }
            rowProducer.finished();
            return rowCount;
        }
    });
    executor.execute(replay);
    return replay;
}
Also used : RowProducer(org.pentaho.di.trans.RowProducer) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) CountDownLatch(java.util.concurrent.CountDownLatch) KettleException(org.pentaho.di.core.exception.KettleException) TransStarter(org.pentaho.di.trans.dataservice.execution.TransStarter) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) StepMetaDataCombi(org.pentaho.di.trans.step.StepMetaDataCombi) Iterator(java.util.Iterator) Trans(org.pentaho.di.trans.Trans) DefaultTransWiring(org.pentaho.di.trans.dataservice.execution.DefaultTransWiring)

Aggregations

DefaultTransWiring (org.pentaho.di.trans.dataservice.execution.DefaultTransWiring)2 TransStarter (org.pentaho.di.trans.dataservice.execution.TransStarter)2 ImmutableMultimap (com.google.common.collect.ImmutableMultimap)1 Iterator (java.util.Iterator)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)1 KettleException (org.pentaho.di.core.exception.KettleException)1 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)1 RowProducer (org.pentaho.di.trans.RowProducer)1 Trans (org.pentaho.di.trans.Trans)1 CopyParameters (org.pentaho.di.trans.dataservice.execution.CopyParameters)1 PrepareExecution (org.pentaho.di.trans.dataservice.execution.PrepareExecution)1 StepMetaDataCombi (org.pentaho.di.trans.step.StepMetaDataCombi)1