Search in sources :

Example 1 with DataServiceExecutor

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

the class ExecutorQueryService method prepareQuery.

@Override
public Query prepareQuery(String sqlString, IDataServiceClientService.StreamingMode windowMode, long windowSize, long windowEvery, long windowLimit, final Map<String, String> parameters) throws KettleException {
    SQL sql = new SQL(sqlString);
    Query query;
    try {
        IMetaStore metaStore = metastoreLocator != null ? metastoreLocator.getMetastore() : null;
        DataServiceExecutor executor = resolver.createBuilder(sql).rowLimit(0).windowMode(windowMode).windowSize(windowSize).windowEvery(windowEvery).windowLimit(windowLimit).parameters(parameters).metastore(metaStore).build();
        query = new ExecutorQuery(executor);
    } catch (Exception e) {
        Throwables.propagateIfInstanceOf(e, KettleException.class);
        throw new KettleException(e);
    }
    return query;
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) DataServiceExecutor(org.pentaho.di.trans.dataservice.DataServiceExecutor) IMetaStore(org.pentaho.metastore.api.IMetaStore) KettleException(org.pentaho.di.core.exception.KettleException) IOException(java.io.IOException) SQL(org.pentaho.di.core.sql.SQL)

Example 2 with DataServiceExecutor

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

the class ExecutorQueryService method prepareQuery.

@Override
public Query prepareQuery(String sqlString, int maxRows, Map<String, String> parameters) throws KettleException {
    SQL sql = new SQL(sqlString);
    Query query;
    try {
        IMetaStore metaStore = metastoreLocator != null ? metastoreLocator.getMetastore() : null;
        DataServiceExecutor executor = resolver.createBuilder(sql).rowLimit(maxRows).parameters(parameters).metastore(metaStore).build();
        query = new ExecutorQuery(executor);
    } catch (Exception e) {
        Throwables.propagateIfInstanceOf(e, KettleException.class);
        throw new KettleException(e);
    }
    return query;
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) DataServiceExecutor(org.pentaho.di.trans.dataservice.DataServiceExecutor) IMetaStore(org.pentaho.metastore.api.IMetaStore) KettleException(org.pentaho.di.core.exception.KettleException) IOException(java.io.IOException) SQL(org.pentaho.di.core.sql.SQL)

Example 3 with DataServiceExecutor

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

the class TransientResolverTest method testBuilderPassesLogLevel.

@Test
public void testBuilderPassesLogLevel() throws Exception {
    File localFolder = temporaryFolder.newFolder("local");
    File localFile = new File(localFolder, "name.ktr");
    Files.write(transMeta.getXML().getBytes(StandardCharsets.UTF_8), localFile);
    String transientId = TransientResolver.buildTransient(localFile.getPath(), "OUTPUT");
    when(repository.getTransformationID(any(), eq(root))).thenThrow(new KettleException());
    DataServiceExecutor.Builder builder = transientResolver.createBuilder(new SQL("select * from " + transientId));
    DataServiceExecutor build = builder.build();
    assertEquals(LogLevel.DEBUG, build.getServiceTransMeta().getLogLevel());
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) DataServiceExecutor(org.pentaho.di.trans.dataservice.DataServiceExecutor) File(java.io.File) SQL(org.pentaho.di.core.sql.SQL) Test(org.junit.Test)

Example 4 with DataServiceExecutor

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

the class CachedServiceTest method testReplayFullCache.

@Test
public void testReplayFullCache() throws Exception {
    DataServiceExecutor executor = dataServiceExecutor(BASE_QUERY);
    CachedService cachedService = CachedService.complete(testData);
    RowProducer rowProducer = genTrans.addRowProducer(INJECTOR_STEP, 0);
    // Activate cachedServiceLoader
    Executor mockExecutor = mock(Executor.class);
    final CachedServiceLoader cachedServiceLoader = new CachedServiceLoader(cachedService, mockExecutor);
    ListenableFuture<Integer> replay = cachedServiceLoader.replay(executor);
    ArgumentCaptor<Runnable> replayRunnable = ArgumentCaptor.forClass(Runnable.class);
    verify(mockExecutor).execute(replayRunnable.capture());
    stepMetaDataCombi.step = inputStep;
    stepMetaDataCombi.meta = inputStepMetaInterface;
    stepMetaDataCombi.data = inputStepDataInterface;
    List<StepMetaDataCombi> stepMetaDataCombis = new ArrayList<>();
    stepMetaDataCombis.add(stepMetaDataCombi);
    when(serviceTrans.getSteps()).thenReturn(stepMetaDataCombis);
    // Simulate executing data service
    executor.executeListeners(DataServiceExecutor.ExecutionPoint.READY);
    executor.executeListeners(DataServiceExecutor.ExecutionPoint.START);
    // Verify that serviceTrans never started, genTrans is accepting rows
    verify(serviceTrans).stopAll();
    verify(inputStep).setOutputDone();
    verify(inputStep).dispose(inputStepMetaInterface, inputStepDataInterface);
    verify(inputStep).markStop();
    verify(serviceTrans, never()).startThreads();
    verify(genTrans).startThreads();
    when(rowProducer.putRowWait(any(RowMetaInterface.class), any(Object[].class), anyInt(), any(TimeUnit.class))).then(new Answer<Boolean>() {

        int calls = 0;

        @Override
        public Boolean answer(InvocationOnMock invocation) throws Throwable {
            // Simulate full row set on tenth call
            return ++calls != 10;
        }
    });
    when(genTrans.isRunning()).thenReturn(true);
    // Run cache loader (would be asynchronous)
    replayRunnable.getValue().run();
    assertThat(replay.get(1, TimeUnit.SECONDS), equalTo(testData.size()));
    InOrder rowsProduced = inOrder(rowProducer);
    for (int i = 0; i < testData.size(); i++) {
        RowMetaAndData metaAndData = testData.get(i);
        // Tenth row was called twice, since row set was full
        Object[] data = metaAndData.getData();
        rowsProduced.verify(rowProducer, times(i == 9 ? 2 : 1)).putRowWait(eq(metaAndData.getRowMeta()), and(eq(data), AdditionalMatchers.not(same(data))), anyInt(), any(TimeUnit.class));
    }
    rowsProduced.verify(rowProducer).finished();
    rowsProduced.verifyNoMoreInteractions();
}
Also used : RowProducer(org.pentaho.di.trans.RowProducer) InOrder(org.mockito.InOrder) DataServiceExecutor(org.pentaho.di.trans.dataservice.DataServiceExecutor) ArrayList(java.util.ArrayList) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) DataServiceExecutor(org.pentaho.di.trans.dataservice.DataServiceExecutor) Executor(java.util.concurrent.Executor) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) InvocationOnMock(org.mockito.invocation.InvocationOnMock) StepMetaDataCombi(org.pentaho.di.trans.step.StepMetaDataCombi) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.Test)

Example 5 with DataServiceExecutor

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

the class CachedServiceTest method testObserveCancelled.

@Test
public void testObserveCancelled() throws Exception {
    DataServiceExecutor executor = dataServiceExecutor(BASE_QUERY);
    ServiceObserver observer = new ServiceObserver(executor);
    observer.install();
    assertThat(executor.getListenerMap().get(DataServiceExecutor.ExecutionPoint.READY), hasItem(observer));
    ListenableFuture<CachedService> failedObserver = new ServiceObserver(executor).install();
    try {
        failedObserver.get(1, TimeUnit.SECONDS);
        fail("Expecting an IllegalStateException");
    } catch (ExecutionException e) {
        assertThat(e.getCause(), instanceOf(IllegalStateException.class));
    }
    assertThat(observer.isDone(), is(false));
    ArgumentCaptor<StepListener> stepListener = ArgumentCaptor.forClass(StepListener.class);
    observer.run();
    verify(serviceStep).addStepListener(stepListener.capture());
    when(genTrans.getErrors()).thenReturn(1);
    stepListener.getValue().stepFinished(serviceTrans, mock(StepMeta.class), serviceStep);
    try {
        observer.get(1, TimeUnit.SECONDS);
        fail("Expecting an KettleException");
    } catch (ExecutionException e) {
        assertThat(e.getCause(), instanceOf(KettleException.class));
    }
}
Also used : DataServiceExecutor(org.pentaho.di.trans.dataservice.DataServiceExecutor) StepListener(org.pentaho.di.trans.step.StepListener) ExecutionException(java.util.concurrent.ExecutionException) StepMeta(org.pentaho.di.trans.step.StepMeta) Test(org.junit.Test)

Aggregations

DataServiceExecutor (org.pentaho.di.trans.dataservice.DataServiceExecutor)23 Test (org.junit.Test)19 SQL (org.pentaho.di.core.sql.SQL)6 HashMap (java.util.HashMap)4 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)4 KettleException (org.pentaho.di.core.exception.KettleException)4 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)3 StepListener (org.pentaho.di.trans.step.StepListener)3 StepMeta (org.pentaho.di.trans.step.StepMeta)3 IMetaStore (org.pentaho.metastore.api.IMetaStore)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Executor (java.util.concurrent.Executor)2 TimeUnit (java.util.concurrent.TimeUnit)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)2 ValueMetaInteger (org.pentaho.di.core.row.value.ValueMetaInteger)2 RowProducer (org.pentaho.di.trans.RowProducer)2 DataServiceContext (org.pentaho.di.trans.dataservice.DataServiceContext)2