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());
}
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());
}
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());
}
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;
}
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;
}
Aggregations