Search in sources :

Example 21 with RowAdapter

use of org.pentaho.di.trans.step.RowAdapter in project pdi-dataservice-server-plugin by pentaho.

the class StreamingServiceTransExecutor method startService.

/**
 * Starts the Service transformation and its row event listener.
 */
private void startService() {
    try {
        lastCacheCleanupMillis = System.currentTimeMillis();
        serviceTrans.startThreads();
        StepInterface serviceStep = serviceTrans.findRunThread(serviceStepName);
        if (serviceStep == null) {
            throw Throwables.propagate(new KettleException("Service step is not accessible"));
        }
        serviceStep.addRowListener(new RowAdapter() {

            /**
             * Listener for the service transformation output rows.
             * If the stepStream has any valid registered listeners it writes the output row to the stepStream,
             * otherwise stops the service transformation and kills its running thread.
             *
             * @param rowMeta The metadata of the written row.
             * @param row The data of the written row.
             * @throws KettleStepException
             */
            @Override
            public void rowWrittenEvent(RowMetaInterface rowMeta, Object[] row) throws KettleStepException {
                // Simply pass along the row to the other transformation (to the Injector step)
                LogChannelInterface log = serviceTrans.getLogChannel();
                try {
                    if (log.isRowLevel()) {
                        log.logRowlevel(DataServiceConstants.PASSING_ALONG_ROW + rowMeta.getString(row));
                    }
                } catch (KettleValueException e) {
                // Ignore error
                }
                serviceCacheCleanup();
                if (serviceListeners.size() > 0) {
                    RowMetaAndData rowData = new RowMetaAndData();
                    rowData.setRowMeta(rowMeta);
                    rowData.setData(row);
                    stepStream.add(rowData);
                } else if (isRunning.compareAndSet(true, false)) {
                    serviceTrans.stopAll();
                    stepStream = null;
                    log.logDetailed(DataServiceConstants.STREAMING_TRANSFORMATION_STOPPED);
                }
            }
        });
    } catch (KettleException e) {
        throw Throwables.propagate(e);
    }
}
Also used : StepInterface(org.pentaho.di.trans.step.StepInterface) KettleException(org.pentaho.di.core.exception.KettleException) KettleStepException(org.pentaho.di.core.exception.KettleStepException) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) RowAdapter(org.pentaho.di.trans.step.RowAdapter) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) KettleValueException(org.pentaho.di.core.exception.KettleValueException) LogChannelInterface(org.pentaho.di.core.logging.LogChannelInterface)

Example 22 with RowAdapter

use of org.pentaho.di.trans.step.RowAdapter in project pdi-dataservice-server-plugin by pentaho.

the class ServiceObserverTest method cloneErrorIsPropogated.

@Test
public void cloneErrorIsPropogated() throws KettleValueException, ExecutionException, InterruptedException, KettleStepException {
    when(rowMeta.cloneRow(row)).thenThrow(exception);
    observer.run();
    verify(stepInterface).addRowListener(rowAdapterCaptor.capture());
    RowAdapter rowAdapter = rowAdapterCaptor.getValue();
    rowAdapter.rowWrittenEvent(rowMeta, row);
    try {
        observer.get();
        fail("Expected exception");
    } catch (Exception e) {
        assertThat(e.getCause(), is(exception));
    }
}
Also used : RowAdapter(org.pentaho.di.trans.step.RowAdapter) ExecutionException(java.util.concurrent.ExecutionException) KettleValueException(org.pentaho.di.core.exception.KettleValueException) KettleStepException(org.pentaho.di.core.exception.KettleStepException) Test(org.junit.Test)

Example 23 with RowAdapter

use of org.pentaho.di.trans.step.RowAdapter in project pdi-dataservice-server-plugin by pentaho.

the class DataServiceExecutor method executeQuery.

public DataServiceExecutor executeQuery(final DataOutputStream dos) throws IOException {
    writeMetadata(dos, getServiceName(), calculateTransname(getSql(), true), getServiceTrans().getContainerObjectId(), calculateTransname(getSql(), false), getGenTrans().getContainerObjectId());
    final AtomicBoolean rowMetaWritten = new AtomicBoolean(false);
    // When done, check if no row metadata was written.  The client is still going to expect it...
    // Since we know it, we'll pass it.
    // 
    getGenTrans().addTransListener(new TransAdapter() {

        @Override
        public void transFinished(Trans trans) throws KettleException {
            if (rowMetaWritten.compareAndSet(false, true)) {
                RowMetaInterface stepFields = trans.getTransMeta().getStepFields(getResultStepName());
                stepFields.writeMeta(dos);
            }
        }
    });
    // Now execute the query transformation(s) and pass the data to the output stream...
    return executeQuery(new RowAdapter() {

        @Override
        public void rowWrittenEvent(RowMetaInterface rowMeta, Object[] row) throws KettleStepException {
            // 
            try {
                if (rowMetaWritten.compareAndSet(false, true)) {
                    rowMeta.writeMeta(dos);
                }
                rowMeta.writeData(dos, row);
            } catch (Exception e) {
                if (!getServiceTrans().isStopped()) {
                    throw new KettleStepException(e);
                }
            }
        }
    });
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) KettleException(org.pentaho.di.core.exception.KettleException) KettleStepException(org.pentaho.di.core.exception.KettleStepException) RowAdapter(org.pentaho.di.trans.step.RowAdapter) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) Trans(org.pentaho.di.trans.Trans) TransAdapter(org.pentaho.di.trans.TransAdapter) KettleException(org.pentaho.di.core.exception.KettleException) IOException(java.io.IOException) KettleStepException(org.pentaho.di.core.exception.KettleStepException)

Example 24 with RowAdapter

use of org.pentaho.di.trans.step.RowAdapter in project pdi-dataservice-server-plugin by pentaho.

the class ServiceObserver method run.

@Override
public void run() {
    StepInterface serviceStep = executor.getServiceTrans().findRunThread(executor.getService().getStepname());
    serviceStep.addRowListener(new RowAdapter() {

        @Override
        public synchronized void rowWrittenEvent(RowMetaInterface rowMeta, Object[] row) {
            Object[] clonedRow;
            try {
                clonedRow = rowMeta.cloneRow(row);
            } catch (KettleValueException e) {
                setException(e);
                return;
            }
            rowMetaAndData.add(new RowMetaAndData(rowMeta, clonedRow));
            latch.countDown();
        }
    });
    serviceStep.addStepListener(new StepAdapter() {

        @Override
        public void stepFinished(Trans trans, StepMeta stepMeta, StepInterface step) {
            isRunning = false;
            if (executor.getGenTrans().getErrors() > 0) {
                setException(new KettleException("Dynamic transformation finished with errors, could not cache results"));
            } else if (step.isStopped()) {
                set(CachedService.partial(rowMetaAndData, executor));
            } else {
                set(CachedService.complete(rowMetaAndData));
            }
        }
    });
}
Also used : StepInterface(org.pentaho.di.trans.step.StepInterface) KettleException(org.pentaho.di.core.exception.KettleException) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) RowAdapter(org.pentaho.di.trans.step.RowAdapter) StepAdapter(org.pentaho.di.trans.step.StepAdapter) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) KettleValueException(org.pentaho.di.core.exception.KettleValueException) Trans(org.pentaho.di.trans.Trans) StepMeta(org.pentaho.di.trans.step.StepMeta)

Aggregations

RowAdapter (org.pentaho.di.trans.step.RowAdapter)24 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)22 KettleStepException (org.pentaho.di.core.exception.KettleStepException)21 KettleException (org.pentaho.di.core.exception.KettleException)16 RowSet (org.pentaho.di.core.RowSet)9 RowMeta (org.pentaho.di.core.row.RowMeta)9 Trans (org.pentaho.di.trans.Trans)7 StepInterface (org.pentaho.di.trans.step.StepInterface)7 ValueMetaNumber (org.pentaho.di.core.row.value.ValueMetaNumber)6 Test (org.junit.Test)5 ValueMetaInteger (org.pentaho.di.core.row.value.ValueMetaInteger)5 ArrayList (java.util.ArrayList)4 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)4 KettleValueException (org.pentaho.di.core.exception.KettleValueException)4 StepMeta (org.pentaho.di.trans.step.StepMeta)4 IOException (java.io.IOException)3 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)3 TransMeta (org.pentaho.di.trans.TransMeta)3 ParseException (java.text.ParseException)2 ValueMetaBigNumber (org.pentaho.di.core.row.value.ValueMetaBigNumber)2