Search in sources :

Example 46 with LogChannelInterface

use of org.pentaho.di.core.logging.LogChannelInterface in project pdi-dataservice-server-plugin by pentaho.

the class TransImportExtensionPointPluginTest method callExtensionPoint.

@Test
public void callExtensionPoint() throws Exception {
    DataServiceReferenceSynchronizer referenceSynchronizer = mock(DataServiceReferenceSynchronizer.class);
    TransMeta transMeta = mock(TransMeta.class);
    Repository transRepository = mock(Repository.class);
    IMetaStore transMetaStore = mock(IMetaStore.class);
    when(transRepository.getMetaStore()).thenReturn(transMetaStore);
    when(transMeta.getRepository()).thenReturn(transRepository);
    when(transMeta.getMetaStore()).thenReturn(transMetaStore);
    TransImportExtensionPointPlugin plugin = new TransImportExtensionPointPlugin(referenceSynchronizer);
    LogChannelInterface log = mock(LogChannelInterface.class);
    plugin.callExtensionPoint(log, null);
    verify(referenceSynchronizer, times(0)).sync(same(transMeta), any(Function.class), eq(true));
    plugin.callExtensionPoint(log, "Not TransMeta");
    verify(referenceSynchronizer, times(0)).sync(same(transMeta), any(Function.class), eq(true));
    plugin.callExtensionPoint(log, transMeta);
    ArgumentCaptor<Function> exceptionHandlerCaptor = ArgumentCaptor.forClass(Function.class);
    verify(referenceSynchronizer).sync(same(transMeta), exceptionHandlerCaptor.capture(), eq(true));
    Exception e = new Exception();
    exceptionHandlerCaptor.getValue().apply(e);
    verify(log).logError(anyString(), same(e));
    DataServiceMeta dsMeta = mock(DataServiceMeta.class);
    DataServiceAlreadyExistsException dsaee = new DataServiceAlreadyExistsException(dsMeta);
    exceptionHandlerCaptor.getValue().apply(dsaee);
    verify(log).logBasic(anyString());
}
Also used : Function(java.util.function.Function) Repository(org.pentaho.di.repository.Repository) DataServiceMeta(org.pentaho.di.trans.dataservice.DataServiceMeta) TransMeta(org.pentaho.di.trans.TransMeta) IMetaStore(org.pentaho.metastore.api.IMetaStore) LogChannelInterface(org.pentaho.di.core.logging.LogChannelInterface) Test(org.junit.Test)

Example 47 with LogChannelInterface

use of org.pentaho.di.core.logging.LogChannelInterface in project pdi-dataservice-server-plugin by pentaho.

the class DataServiceTestModelTest method testGetSetGenTransLogChannel.

@Test
public void testGetSetGenTransLogChannel() throws Exception {
    assertNull(model.getGenTransLogChannel());
    LogChannelInterface mockChannel = mock(LogChannelInterface.class);
    model.setGenTransLogChannel(mockChannel);
    assertEquals(mockChannel, model.getGenTransLogChannel());
}
Also used : LogChannelInterface(org.pentaho.di.core.logging.LogChannelInterface) Test(org.junit.Test)

Example 48 with LogChannelInterface

use of org.pentaho.di.core.logging.LogChannelInterface in project pdi-dataservice-server-plugin by pentaho.

the class DataServiceTestModelTest method testGetSetServiceTransLogChannel.

@Test
public void testGetSetServiceTransLogChannel() throws Exception {
    assertNull(model.getServiceTransLogChannel());
    LogChannelInterface mockChannel = mock(LogChannelInterface.class);
    model.setServiceTransLogChannel(mockChannel);
    assertEquals(mockChannel, model.getServiceTransLogChannel());
}
Also used : LogChannelInterface(org.pentaho.di.core.logging.LogChannelInterface) Test(org.junit.Test)

Example 49 with LogChannelInterface

use of org.pentaho.di.core.logging.LogChannelInterface in project pdi-dataservice-server-plugin by pentaho.

the class ServiceCache method activate.

@Override
public boolean activate(final DataServiceExecutor executor, StepInterface stepInterface) {
    final LogChannelInterface logChannel = executor.getGenTrans().getLogChannel();
    for (CachedService availableCache : getAvailableCache(executor).values()) {
        try {
            ListenableFuture<Integer> replay = factory.createCachedServiceLoader(availableCache).replay(executor);
            addReplayCallback(logChannel, replay);
            return true;
        } catch (Throwable e) {
            logChannel.logError("Unable to replay from cache", e);
        }
    }
    CachedService.CacheKey rootKey = createRootKey(executor);
    final Map<CachedService.CacheKey, ServiceObserver> runningServices = factory.getRunningServices();
    if (runningServices.containsKey(rootKey)) {
        try {
            ListenableFuture<Integer> replay = factory.createCachedServiceLoader(() -> runningServices.get(rootKey).rows()).replay(executor);
            addReplayCallback(logChannel, replay);
            return true;
        } catch (KettleException e) {
            logChannel.logError("Unable to replay from running service");
        }
    }
    ServiceObserver serviceObserver = factory.createObserver(executor);
    // only allow replay from this running trans if it's going to return all the rows
    if (CachedService.calculateRank(executor) == Integer.MAX_VALUE) {
        runningServices.put(rootKey, serviceObserver);
    }
    // Allow service transformation to run, observe rows
    Futures.addCallback(serviceObserver.install(), new FutureCallback<CachedService>() {

        @Override
        public void onSuccess(CachedService result) {
            if (executor.isStopped() || executor.hasErrors()) {
                runningServices.remove(rootKey);
                return;
            }
            Cache<CachedService.CacheKey, CachedService> cache = factory.getCache(ServiceCache.this, executor.getServiceName());
            CachedService.CacheKey key = createRootKey(executor);
            // If result set is complete, order is not important
            if (result.isComplete()) {
                key = key.withoutOrder();
            }
            if (cache.putIfAbsent(key, result)) {
                logChannel.logBasic("Service Transformation results cached", key);
            } else {
                try {
                    CachedService existing = checkNotNull(cache.get(key));
                    // If the existing result set can't answer this query, replace it
                    if (!existing.answersQuery(executor) && cache.replace(key, existing, result)) {
                        logChannel.logBasic("Service Transformation cache updated", key);
                    } else {
                        logChannel.logDetailed("Service Transformation cache was not updated", key);
                    }
                } catch (Throwable t) {
                    onFailure(t);
                }
            }
            runningServices.remove(rootKey);
        }

        @Override
        public void onFailure(Throwable t) {
            runningServices.remove(rootKey);
            logChannel.logError("Cache failed to observe service transformation", t);
        }
    }, factory.getExecutorService());
    return false;
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) LogChannelInterface(org.pentaho.di.core.logging.LogChannelInterface) Cache(javax.cache.Cache)

Example 50 with LogChannelInterface

use of org.pentaho.di.core.logging.LogChannelInterface in project pdi-dataservice-server-plugin by pentaho.

the class ServiceCache method maybeInvalidateCache.

/**
 * Checks whether cache configuration has changed in such a way that the existing cache is
 * no longer valid.  Will return the cache associated with the data service (if available) otherwise.
 */
private Cache<CachedService.CacheKey, CachedService> maybeInvalidateCache(DataServiceExecutor executor) {
    Optional<Cache<CachedService.CacheKey, CachedService>> cache = factory.getCache(executor.getServiceName());
    LogChannelInterface logChannel = executor.getServiceTrans().getLogChannel();
    if (cache.isPresent()) {
        if (!ttlMatches(cache.get(), logChannel)) {
            logChannel.logBasic("Dropping cache associated with " + executor.getServiceName());
            dropCache(cache.get());
        } else {
            logChannel.logDebug("Found cache associated with " + executor.getServiceName());
            return cache.get();
        }
    }
    return null;
}
Also used : LogChannelInterface(org.pentaho.di.core.logging.LogChannelInterface) Cache(javax.cache.Cache)

Aggregations

LogChannelInterface (org.pentaho.di.core.logging.LogChannelInterface)85 Test (org.junit.Test)53 PrintWriter (java.io.PrintWriter)29 TransMeta (org.pentaho.di.trans.TransMeta)29 HttpServletRequest (javax.servlet.http.HttpServletRequest)27 HttpServletResponse (javax.servlet.http.HttpServletResponse)27 StringWriter (java.io.StringWriter)26 Point (org.pentaho.di.core.gui.Point)26 Trans (org.pentaho.di.trans.Trans)23 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)19 Job (org.pentaho.di.job.Job)17 JobMeta (org.pentaho.di.job.JobMeta)15 KettleException (org.pentaho.di.core.exception.KettleException)12 ArrayList (java.util.ArrayList)9 Matchers.anyString (org.mockito.Matchers.anyString)7 LogChannel (org.pentaho.di.core.logging.LogChannel)6 AbstractMeta (org.pentaho.di.base.AbstractMeta)5 Repository (org.pentaho.di.repository.Repository)5 RepositoryDirectoryInterface (org.pentaho.di.repository.RepositoryDirectoryInterface)5 ExtensionPointWrapper (org.pentaho.di.ui.core.events.dialog.extension.ExtensionPointWrapper)5