use of org.pentaho.platform.plugin.action.olap.IOlapServiceException in project pentaho-platform by pentaho.
the class OlapServiceImplTest method testFlushProceedsOnException.
@Test
public void testFlushProceedsOnException() throws Exception {
stubHostedServer();
final Properties properties = new Properties();
properties.put(RolapConnectionProperties.Locale.name(), getLocale().toString());
OlapConnection conn = mock(OlapConnection.class);
when(server.getConnection("Pentaho", "myHostedServer", null, properties)).thenReturn(conn);
when(conn.isWrapperFor(any(Class.class))).thenReturn(true);
final RolapConnection rolapConn = mock(RolapConnection.class);
when(conn.unwrap(any(Class.class))).thenReturn(rolapConn);
when(rolapConn.getCacheControl(any(PrintWriter.class))).thenThrow(new RuntimeException("something happend"));
try {
olapService.flushAll(session);
} catch (IOlapServiceException e) {
fail("Exception shouldn't have made it this far.");
}
}
use of org.pentaho.platform.plugin.action.olap.IOlapServiceException in project pentaho-platform by pentaho.
the class MondrianCatalogRepositoryHelper method hasAccess.
public boolean hasAccess(final String catalogName, final EnumSet<RepositoryFilePermission> perms, IPentahoSession session) {
if (session == null) {
// No session is equivalent to root access.
return true;
}
// If the connection doesn't exist yet and we're trying to create it,
// we need to check the parent folder instead.
final String path;
if (!getHostedCatalogs().contains(catalogName) && !getOlap4jServers().contains(catalogName) && perms.contains(RepositoryFilePermission.WRITE)) {
path = isHosted(catalogName) ? ETC_MONDRIAN_JCR_FOLDER : ETC_OLAP_SERVERS_JCR_FOLDER;
} else {
path = makePath(catalogName);
}
final IPentahoSession origSession = PentahoSessionHolder.getSession();
PentahoSessionHolder.setSession(session);
try {
return repository.hasAccess(path, perms);
} catch (Exception e) {
throw new IOlapServiceException(e);
} finally {
PentahoSessionHolder.setSession(origSession);
}
}
use of org.pentaho.platform.plugin.action.olap.IOlapServiceException in project pentaho-platform by pentaho.
the class OlapServiceImpl method getCatalogs.
public List<IOlapService.Catalog> getCatalogs(IPentahoSession session) throws IOlapServiceException {
// Make sure the cache is initialized.
initCache(session);
final List<Catalog> cache = getCache(session);
final Lock readLock = cacheLock.readLock();
try {
readLock.lock();
return cache.stream().filter(catalog -> hasAccess(catalog.name, EnumSet.of(RepositoryFilePermission.READ), session)).collect(Collectors.toList());
} finally {
readLock.unlock();
}
}
use of org.pentaho.platform.plugin.action.olap.IOlapServiceException in project pentaho-platform by pentaho.
the class OlapServiceImpl method flushAll.
public void flushAll(IPentahoSession session) {
final Lock writeLock = cacheLock.writeLock();
try {
writeLock.lock();
// Start by flushing the local cache.
resetCache(session);
flushHostedCatalogs();
flushRemoteCatalogs(session);
} catch (Exception e) {
throw new IOlapServiceException(e);
} finally {
writeLock.unlock();
}
}
use of org.pentaho.platform.plugin.action.olap.IOlapServiceException in project pentaho-platform by pentaho.
the class OlapServiceImpl method initCache.
/**
* Initializes the cache. Only the cache specific to the sesison's locale
* will be populated.
*/
protected void initCache(IPentahoSession session) {
final List<Catalog> cache = getCache(session);
final boolean needUpdate;
final Lock readLock = cacheLock.readLock();
try {
readLock.lock();
// Check if the cache is empty.
if (cache.size() == 0) {
needUpdate = true;
} else {
needUpdate = false;
}
} finally {
readLock.unlock();
}
if (needUpdate) {
final Lock writeLock = cacheLock.writeLock();
try {
writeLock.lock();
// First clear the cache
cache.clear();
final Callable<Void> call = new Callable<Void>() {
public Void call() throws Exception {
// Now build the cache. Use the system session in the holder.
for (String name : getHelper().getHostedCatalogs()) {
try {
addCatalogToCache(PentahoSessionHolder.getSession(), name);
} catch (Throwable t) {
LOG.error("Failed to initialize the cache for OLAP connection " + name, t);
}
}
for (String name : getHelper().getOlap4jServers()) {
try {
addCatalogToCache(PentahoSessionHolder.getSession(), name);
} catch (Throwable t) {
LOG.error("Failed to initialize the cache for OLAP connection " + name, t);
}
}
return null;
}
};
if (isSecurityEnabled()) {
SecurityHelper.getInstance().runAsSystem(call);
} else {
call.call();
}
// Sort it all.
Collections.sort(cache, new Comparator<IOlapService.Catalog>() {
public int compare(Catalog o1, Catalog o2) {
return o1.name.compareTo(o2.name);
}
});
} catch (Throwable t) {
LOG.error("Failed to initialize the connection cache", t);
throw new IOlapServiceException(t);
} finally {
writeLock.unlock();
}
}
}
Aggregations