Search in sources :

Example 11 with IOlapServiceException

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.");
    }
}
Also used : RolapConnection(mondrian.rolap.RolapConnection) OlapConnection(org.olap4j.OlapConnection) IOlapServiceException(org.pentaho.platform.plugin.action.olap.IOlapServiceException) RolapConnectionProperties(mondrian.rolap.RolapConnectionProperties) Properties(java.util.Properties) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 12 with IOlapServiceException

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);
    }
}
Also used : IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) IOlapServiceException(org.pentaho.platform.plugin.action.olap.IOlapServiceException) IOlapServiceException(org.pentaho.platform.plugin.action.olap.IOlapServiceException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) RepositoryException(org.pentaho.platform.api.repository.RepositoryException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 13 with IOlapServiceException

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();
    }
}
Also used : IConnectionUserRoleMapper(org.pentaho.platform.api.engine.IConnectionUserRoleMapper) Messages(org.pentaho.platform.plugin.action.messages.Messages) Connection(java.sql.Connection) UserDetailsService(org.springframework.security.core.userdetails.UserDetailsService) Collections2(com.google.common.collect.Collections2) DefaultFileSystemManager(org.apache.commons.vfs2.impl.DefaultFileSystemManager) IOlapConnectionFilter(org.pentaho.platform.plugin.action.olap.IOlapConnectionFilter) RolapConnectionProperties(mondrian.rolap.RolapConnectionProperties) Locale(java.util.Locale) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException) XmlaHandler(mondrian.xmla.XmlaHandler) EnumSet(java.util.EnumSet) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) DynamicContentFinder(mondrian.server.DynamicContentFinder) MondrianCatalogRepositoryHelper(org.pentaho.platform.plugin.services.importexport.legacy.MondrianCatalogRepositoryHelper) Role(mondrian.olap.Role) Olap4jServerInfo(org.pentaho.platform.plugin.services.importexport.legacy.MondrianCatalogRepositoryHelper.Olap4jServerInfo) MondrianVfs(org.pentaho.platform.repository.solution.filebased.MondrianVfs) LocaleHelper(org.pentaho.platform.util.messages.LocaleHelper) Collection(java.util.Collection) FileSystemException(org.apache.commons.vfs2.FileSystemException) HostedCatalogInfo(org.pentaho.platform.plugin.services.importexport.legacy.MondrianCatalogRepositoryHelper.HostedCatalogInfo) Collectors(java.util.stream.Collectors) PentahoSessionHolder(org.pentaho.platform.engine.core.system.PentahoSessionHolder) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository) SecurityHelper(org.pentaho.platform.engine.security.SecurityHelper) List(java.util.List) Util(mondrian.olap.Util) Predicate(com.google.common.base.Predicate) RolapConnection(mondrian.rolap.RolapConnection) LogFactory(org.apache.commons.logging.LogFactory) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) RepositoryFilePermission(org.pentaho.platform.api.repository2.unified.RepositoryFilePermission) PlatformXmlaExtra(org.pentaho.platform.plugin.action.olap.PlatformXmlaExtra) Callable(java.util.concurrent.Callable) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) PentahoSystem(org.pentaho.platform.engine.core.system.PentahoSystem) ArrayList(java.util.ArrayList) MondrianServerRegistry(mondrian.server.MondrianServerRegistry) CatalogLocator(mondrian.spi.CatalogLocator) OlapException(org.olap4j.OlapException) SQLException(java.sql.SQLException) OlapConnection(org.olap4j.OlapConnection) ICacheManager(org.pentaho.platform.api.engine.ICacheManager) MDXConnection(org.pentaho.platform.plugin.services.connections.mondrian.MDXConnection) IOlapServiceException(org.pentaho.platform.plugin.action.olap.IOlapServiceException) VFS(org.apache.commons.vfs2.VFS) IOlapService(org.pentaho.platform.plugin.action.olap.IOlapService) MondrianServer(mondrian.olap.MondrianServer) Properties(java.util.Properties) Entry(mondrian.util.LockBox.Entry) Lock(java.util.concurrent.locks.Lock) Log(org.apache.commons.logging.Log) Comparator(java.util.Comparator) Collections(java.util.Collections) DriverManager(java.sql.DriverManager) InputStream(java.io.InputStream) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) Lock(java.util.concurrent.locks.Lock)

Example 14 with IOlapServiceException

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();
    }
}
Also used : IOlapServiceException(org.pentaho.platform.plugin.action.olap.IOlapServiceException) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException) FileSystemException(org.apache.commons.vfs2.FileSystemException) OlapException(org.olap4j.OlapException) SQLException(java.sql.SQLException) IOlapServiceException(org.pentaho.platform.plugin.action.olap.IOlapServiceException) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) Lock(java.util.concurrent.locks.Lock)

Example 15 with IOlapServiceException

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();
        }
    }
}
Also used : IOlapServiceException(org.pentaho.platform.plugin.action.olap.IOlapServiceException) Callable(java.util.concurrent.Callable) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) Lock(java.util.concurrent.locks.Lock)

Aggregations

IOlapServiceException (org.pentaho.platform.plugin.action.olap.IOlapServiceException)17 Test (org.junit.Test)8 SQLException (java.sql.SQLException)6 Matchers.anyString (org.mockito.Matchers.anyString)6 Properties (java.util.Properties)5 RolapConnectionProperties (mondrian.rolap.RolapConnectionProperties)5 FileSystemException (org.apache.commons.vfs2.FileSystemException)5 OlapException (org.olap4j.OlapException)5 PentahoAccessControlException (org.pentaho.platform.api.engine.PentahoAccessControlException)5 Lock (java.util.concurrent.locks.Lock)4 ReadWriteLock (java.util.concurrent.locks.ReadWriteLock)4 ReentrantReadWriteLock (java.util.concurrent.locks.ReentrantReadWriteLock)4 RolapConnection (mondrian.rolap.RolapConnection)4 OlapConnection (org.olap4j.OlapConnection)4 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)4 RepositoryFilePermission (org.pentaho.platform.api.repository2.unified.RepositoryFilePermission)3 InputStream (java.io.InputStream)2 Connection (java.sql.Connection)2 Callable (java.util.concurrent.Callable)2 IOlapConnectionFilter (org.pentaho.platform.plugin.action.olap.IOlapConnectionFilter)2