Search in sources :

Example 16 with OlapConnection

use of org.olap4j.OlapConnection in project pentaho-platform by pentaho.

the class OlapServiceImplTest method setUp.

@Before
public void setUp() throws Exception {
    // Stub /etc/mondrian
    mondrianFolderPath = ClientRepositoryPaths.getEtcFolderPath() + RepositoryFile.SEPARATOR + "mondrian";
    stubGetFolder(repository, mondrianFolderPath);
    // Stub /etc/olap-servers
    olapFolderPath = ClientRepositoryPaths.getEtcFolderPath() + RepositoryFile.SEPARATOR + "olap-servers";
    stubGetFolder(repository, olapFolderPath);
    // Create a session as admin.
    session = new StandaloneSession("admin");
    doReturn(aggManager).when(server).getAggregationManager();
    doReturn(cacheControl).when(aggManager).getCacheControl(any(RolapConnection.class), any(PrintWriter.class));
    // Create the olap service. Make sure to override hasAccess with the
    // mock version.
    olapService = spy(new OlapServiceImpl(repository, server) {

        public boolean hasAccess(String path, EnumSet<RepositoryFilePermission> perms, IPentahoSession session) {
            return accessMock.hasAccess(path, perms, session);
        }

        @Override
        protected XmlaHandler.XmlaExtra getXmlaExtra(final OlapConnection connection) throws SQLException {
            return mockXmlaExtra;
        }
    });
}
Also used : RolapConnection(mondrian.rolap.RolapConnection) OlapServiceImpl(org.pentaho.platform.plugin.action.olap.impl.OlapServiceImpl) StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) OlapConnection(org.olap4j.OlapConnection) EnumSet(java.util.EnumSet) XmlaHandler(mondrian.xmla.XmlaHandler) Matchers.anyString(org.mockito.Matchers.anyString) PrintWriter(java.io.PrintWriter) Before(org.junit.Before)

Example 17 with OlapConnection

use of org.olap4j.OlapConnection in project pentaho-platform by pentaho.

the class OlapServiceImplTest method flushSingleSchemaCache.

@Test
public void flushSingleSchemaCache() throws Exception {
    OlapConnection connection = mock(OlapConnection.class);
    doReturn(connection).when(olapService).getConnection("schemaX", session);
    RolapConnection rc = mock(RolapConnection.class);
    doReturn(rc).when(connection).unwrap(RolapConnection.class);
    doReturn(cacheControl).when(rc).getCacheControl(any(PrintWriter.class));
    RolapSchema schema = mock(RolapSchema.class);
    doReturn(schema).when(rc).getSchema();
    olapService.flush(session, "schemaX");
    verify(cacheControl, times(1)).flushSchema(schema);
}
Also used : RolapConnection(mondrian.rolap.RolapConnection) RolapSchema(mondrian.rolap.RolapSchema) OlapConnection(org.olap4j.OlapConnection) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 18 with OlapConnection

use of org.olap4j.OlapConnection 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 19 with OlapConnection

use of org.olap4j.OlapConnection in project pentaho-platform by pentaho.

the class OlapServiceImpl method flushRemoteCatalogs.

/**
 * Flushes all remote catalogs accessible to session.
 * Unlike Hosted Catalogs, remote catalogs need to be
 * flushed individually since they each may be running
 * in separate instances.
 */
private void flushRemoteCatalogs(IPentahoSession session) throws SQLException {
    for (String name : getRemoteCatalogNames(session)) {
        OlapConnection connection = null;
        try {
            connection = getConnection(name, session);
            XmlaHandler.XmlaExtra xmlaExtra = getXmlaExtra(connection);
            if (xmlaExtra != null) {
                xmlaExtra.flushSchemaCache(connection);
            }
        } catch (Exception e) {
            LOG.warn(Messages.getInstance().getErrorString("MondrianCatalogHelper.ERROR_0019_FAILED_TO_FLUSH", name), e);
        } finally {
            if (connection != null) {
                connection.close();
            }
        }
    }
}
Also used : OlapConnection(org.olap4j.OlapConnection) XmlaHandler(mondrian.xmla.XmlaHandler) 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)

Example 20 with OlapConnection

use of org.olap4j.OlapConnection in project pentaho-platform by pentaho.

the class OlapServiceImpl method addCatalogToCache.

/**
 * Adds a catalog and its children to the cache.
 * Do not use directly. This must be called with a write lock
 * on the cache.
 *
 * @param catalogName The name of the catalog to load in cache.
 */
private void addCatalogToCache(IPentahoSession session, String catalogName) {
    final IOlapService.Catalog catalog = new Catalog(catalogName, new ArrayList<IOlapService.Schema>());
    OlapConnection connection = null;
    try {
        connection = getConnection(catalogName, session);
        for (org.olap4j.metadata.Schema schema4j : connection.getOlapSchemas()) {
            connection.setSchema(schema4j.getName());
            final IOlapService.Schema schema = new Schema(schema4j.getName(), catalog, new ArrayList<IOlapService.Cube>(), new ArrayList<String>(connection.getAvailableRoleNames()));
            for (org.olap4j.metadata.Cube cube4j : schema4j.getCubes()) {
                schema.cubes.add(new IOlapService.Cube(cube4j.getName(), cube4j.getCaption(), schema));
            }
            catalog.schemas.add(schema);
        }
        // We're done.
        getCache(session).add(catalog);
    } catch (OlapException e) {
        LOG.warn("Failed to initialize the olap connection cache for catalog " + catalogName, e);
    } finally {
        try {
            if (connection != null) {
                connection.close();
            }
        } catch (SQLException e) {
            LOG.warn("Failed to gracefully close an olap connection to catalog " + catalogName, e);
        }
    }
}
Also used : IOlapService(org.pentaho.platform.plugin.action.olap.IOlapService) SQLException(java.sql.SQLException) OlapConnection(org.olap4j.OlapConnection) OlapException(org.olap4j.OlapException)

Aggregations

OlapConnection (org.olap4j.OlapConnection)22 SQLException (java.sql.SQLException)8 RolapConnection (mondrian.rolap.RolapConnection)5 OlapException (org.olap4j.OlapException)5 Properties (java.util.Properties)4 MondrianServer (mondrian.olap.MondrianServer)4 IOlapServiceException (org.pentaho.platform.plugin.action.olap.IOlapServiceException)4 PrintWriter (java.io.PrintWriter)3 Connection (java.sql.Connection)3 Test (org.junit.Test)3 OlapWrapper (org.olap4j.OlapWrapper)3 PentahoAccessControlException (org.pentaho.platform.api.engine.PentahoAccessControlException)3 IOException (java.io.IOException)2 Connection (mondrian.olap.Connection)2 RolapConnectionProperties (mondrian.rolap.RolapConnectionProperties)2 UrlRepositoryContentFinder (mondrian.server.UrlRepositoryContentFinder)2 XmlaHandler (mondrian.xmla.XmlaHandler)2 XmlaTestContext (mondrian.xmla.test.XmlaTestContext)2 FileSystemException (org.apache.commons.vfs2.FileSystemException)2 OlapDataSource (org.olap4j.OlapDataSource)2