Search in sources :

Example 1 with MondrianServer

use of mondrian.olap.MondrianServer in project mondrian by pentaho.

the class MonitorTest method testMe.

/**
 * Exercises as many fields of the monitoring stats classes as possible.
 * So that we can check that they are being populated.
 */
public void testMe() throws SQLException {
    String queryString = "WITH MEMBER [Measures].[Foo] AS\n" + " [Measures].[Unit Sales]" + " + case when [Measures].[Unit Sales] > 0\n" + "   then CInt( ([Measures].[Foo], [Time].PrevMember) )\n" + "   end\n" + "SELECT [Measures].[Foo] on 0\n" + "from [Sales]\n" + "where [Time].[1997].[Q3].[9]";
    final OlapStatement statement1 = getTestContext().getOlap4jConnection().createStatement();
    CellSet cellSet = statement1.executeOlapQuery(queryString);
    StringWriter stringWriter = new StringWriter();
    new RectangularCellSetFormatter(true).format(cellSet, new PrintWriter(stringWriter));
    statement1.close();
    println(stringWriter);
    final MondrianServer mondrianServer = MondrianServer.forConnection(getConnection());
    final Monitor monitor = mondrianServer.getMonitor();
    final ServerInfo server = monitor.getServer();
    println("# stmts open: " + server.getStatementCurrentlyOpenCount());
    println("# connections open: " + server.getConnectionCurrentlyOpenCount());
    println("# rows fetched: " + server.sqlStatementRowFetchCount);
    println("# sql stmts open: " + server.getSqlStatementCurrentlyOpenCount());
    // # sql stmts by category (cell query, member query, other)
    // -- if you want to do this, capture sql statement events
    // cell cache requests
    // cell cache misses
    // cell cache hits
    final List<ConnectionInfo> connections = monitor.getConnections();
    ConnectionInfo lastConnection = connections.get(connections.size() - 1);
    // Cannot reliably retrieve the last statement, since statements are
    // removed from the map on completion.
    // final List<StatementInfo> statements = monitor.getStatements();
    // StatementInfo lastStatement = statements.get(statements.size() - 1);
    println("# cell cache requests, misses, hits; " + "by server, connection, mdx statement: " + server.cellCacheRequestCount + ", " + server.getCellCacheMissCount() + ", " + server.cellCacheHitCount + "; " + lastConnection.cellCacheRequestCount + ", " + (lastConnection.cellCacheRequestCount - lastConnection.cellCacheHitCount) + ", " + lastConnection.cellCacheHitCount);
    // cache misses in the last minute
    // cache hits in the last minute
    // -- build a layer on top of monitor that polls say every 15 seconds,
    // and keeps results for a few minutes
    println("number of mdx statements currently open: " + server.getStatementCurrentlyOpenCount());
    println("number of mdx statements currently executing: " + server.getStatementCurrentlyExecutingCount());
    println("jvm memory: " + server.jvmHeapBytesUsed + ", max: " + server.jvmHeapBytesMax + ", committed: " + server.jvmHeapBytesCommitted);
    println("number of segments: " + server.segmentCount + ", ever created: " + server.segmentCreateCount + ", number of cells: " + server.cellCount + ", number of cell coordinates: " + server.cellCoordinateCount + ", average cell dimensionality: " + ((float) server.cellCoordinateCount / (float) server.cellCount));
    println("Connection: " + lastConnection);
    println("Server: " + server);
// number of mdx function calls cumulative
// how many operations have been evaluated in sql?
// number of members in cache
// number of cells in segments
// mdx query time
// sql query time
// sql rows
// olap4j connection pool size
// sql connection pool size
// thread count
// # schemas in schema cache
// cells fulfilled by sql statements
// mondrian server count (other stats relate to just one server)
// 
// Events:
// 
// SQL statement start
// SQL statment stop
// external cache call
// sort
// (other expensive operations similar to sort?)
}
Also used : OlapStatement(org.olap4j.OlapStatement) MondrianServer(mondrian.olap.MondrianServer) StringWriter(java.io.StringWriter) RectangularCellSetFormatter(org.olap4j.layout.RectangularCellSetFormatter) CellSet(org.olap4j.CellSet) PrintWriter(java.io.PrintWriter)

Example 2 with MondrianServer

use of mondrian.olap.MondrianServer in project mondrian by pentaho.

the class MondrianServerTest method testRepository.

/**
 * Tests a server that reads its repository from a file URL.
 */
public void testRepository() throws MalformedURLException, SQLException {
    final XmlaTestContext xmlaTestContext = new XmlaTestContext();
    final MondrianServer server = MondrianServer.createWithRepository(new UrlRepositoryContentFinder("inline:" + xmlaTestContext.getDataSourcesString()), null);
    final int id = server.getId();
    assertNotNull(id);
    OlapConnection connection = server.getConnection("FoodMart", "FoodMart", null);
    final NamedList<Catalog> catalogs = connection.getOlapCatalogs();
    assertEquals(1, catalogs.size());
    assertEquals("FoodMart", catalogs.get(0).getName());
    server.shutdown();
}
Also used : MondrianServer(mondrian.olap.MondrianServer) OlapConnection(org.olap4j.OlapConnection) UrlRepositoryContentFinder(mondrian.server.UrlRepositoryContentFinder) Catalog(org.olap4j.metadata.Catalog) XmlaTestContext(mondrian.xmla.test.XmlaTestContext)

Example 3 with MondrianServer

use of mondrian.olap.MondrianServer in project pentaho-platform by pentaho.

the class PentahoXmlaServlet method createConnectionFactory.

@Override
protected ConnectionFactory createConnectionFactory(final ServletConfig servletConfig) throws ServletException {
    final ConnectionFactory delegate = super.createConnectionFactory(servletConfig);
    /*
     * This wrapper for the connection factory allows us to
     * override the list of roles with the ones defined in
     * the IPentahoSession and filter it through the
     * IConnectionUserRoleMapper.
     */
    return new ConnectionFactory() {

        public Map<String, Object> getPreConfiguredDiscoverDatasourcesResponse() {
            return delegate.getPreConfiguredDiscoverDatasourcesResponse();
        }

        public OlapConnection getConnection(String databaseName, String catalogName, String roleName, Properties props) throws SQLException {
            // What we do here is to filter the role names with the mapper.
            // First, get a user role mapper, if one is configured.
            final IPentahoSession session = PentahoSessionHolder.getSession();
            final IConnectionUserRoleMapper mondrianUserRoleMapper = PentahoSystem.get(IConnectionUserRoleMapper.class, MDXConnection.MDX_CONNECTION_MAPPER_KEY, // Don't use the user session here yet.
            null);
            String[] effectiveRoles = new String[0];
            /*
         * If Catalog/Schema are null (this happens with high level metadata requests,
         * like DISCOVER_DATASOURCES) we can't use the role mapper, even if it
         * is present and configured.
         */
            if (mondrianUserRoleMapper != null && catalogName != null) {
                // Use the role mapper.
                try {
                    effectiveRoles = mondrianUserRoleMapper.mapConnectionRoles(session, catalogName);
                    if (effectiveRoles == null) {
                        effectiveRoles = new String[0];
                    }
                } catch (PentahoAccessControlException e) {
                    throw new SQLException(e);
                }
            }
            // Now we tokenize that list.
            boolean addComma = false;
            // $NON-NLS-1$
            roleName = "";
            for (String role : effectiveRoles) {
                if (addComma) {
                    // $NON-NLS-1$
                    roleName = roleName.concat(",");
                }
                roleName = roleName.concat(role);
                addComma = true;
            }
            // Now let the delegate connection factory do its magic.
            if (catalogName == null) {
                return delegate.getConnection(databaseName, catalogName, roleName.equals("") ? null : roleName, props);
            } else {
                // We create a connection differently so we can ensure that
                // the XMLA servlet shares the same MondrianServer instance as the rest
                // of the platform
                IMondrianCatalogService mcs = PentahoSystem.get(IMondrianCatalogService.class);
                MondrianCatalog mc = mcs.getCatalog(catalogName, PentahoSessionHolder.getSession());
                if (mc == null) {
                    throw new XmlaException(CLIENT_FAULT_FC, HSB_BAD_RESTRICTION_LIST_CODE, HSB_BAD_RESTRICTION_LIST_FAULT_FS, new MondrianException("No such catalog: " + catalogName));
                }
                Connection con = DriverManager.getConnection(mc.getDataSourceInfo() + ";Catalog=" + mc.getDefinition(), catalogLocator);
                try {
                    final MondrianServer server = MondrianServer.forConnection(con);
                    FileRepository fr = new FileRepository(makeContentFinder(makeDataSourcesUrl(servletConfig)), catalogLocator);
                    OlapConnection connection = fr.getConnection(server, databaseName, catalogName, roleName, props);
                    fr.shutdown();
                    return connection;
                } finally {
                    con.close();
                }
            }
        }
    };
}
Also used : FileRepository(mondrian.server.FileRepository) MondrianServer(mondrian.olap.MondrianServer) MondrianCatalog(org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalog) SQLException(java.sql.SQLException) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) IConnectionUserRoleMapper(org.pentaho.platform.api.engine.IConnectionUserRoleMapper) OlapConnection(org.olap4j.OlapConnection) OlapConnection(org.olap4j.OlapConnection) MDXConnection(org.pentaho.platform.plugin.services.connections.mondrian.MDXConnection) Connection(mondrian.olap.Connection) Properties(java.util.Properties) IMondrianCatalogService(org.pentaho.platform.plugin.action.mondrian.catalog.IMondrianCatalogService) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException) ConnectionFactory(mondrian.xmla.XmlaHandler.ConnectionFactory) SolutionRepositoryVfsFileObject(org.pentaho.platform.repository.solution.filebased.SolutionRepositoryVfsFileObject) XmlaException(mondrian.xmla.XmlaException) MondrianException(mondrian.olap.MondrianException)

Example 4 with MondrianServer

use of mondrian.olap.MondrianServer in project mondrian by pentaho.

the class MondrianServerTest method testRepositoryWithBadCatalog.

/**
 * Tests a server that reads its repository from a file URL.
 */
public void testRepositoryWithBadCatalog() throws Exception {
    final XmlaTestContext xmlaTestContext = new XmlaTestContext() {

        Util.PropertyList connectProperties = Util.parseConnectString(getConnectString());

        String catalogUrl = connectProperties.get(RolapConnectionProperties.Catalog.name());

        public String getDataSourcesString() {
            return super.getDataSourcesString().replace("</Catalog>", "</Catalog>\n" + "<Catalog name='__1'>\n" + "<DataSourceInfo>Provider=mondrian;Jdbc='jdbc:derby:non-existing-db'</DataSourceInfo>\n" + "<Definition>" + catalogUrl + "</Definition>\n" + "</Catalog>\n");
        }
    };
    final MondrianServer server = MondrianServer.createWithRepository(new UrlRepositoryContentFinder("inline:" + xmlaTestContext.getDataSourcesString()), null);
    final int id = server.getId();
    assertNotNull(id);
    OlapConnection connection = server.getConnection("FoodMart", "FoodMart", null);
    final NamedList<Catalog> catalogs = connection.getOlapCatalogs();
    assertEquals(1, catalogs.size());
    assertEquals("FoodMart", catalogs.get(0).getName());
    server.shutdown();
}
Also used : MondrianServer(mondrian.olap.MondrianServer) OlapConnection(org.olap4j.OlapConnection) UrlRepositoryContentFinder(mondrian.server.UrlRepositoryContentFinder) Catalog(org.olap4j.metadata.Catalog) XmlaTestContext(mondrian.xmla.test.XmlaTestContext)

Example 5 with MondrianServer

use of mondrian.olap.MondrianServer in project mondrian by pentaho.

the class MondrianServerTest method testStringRepository.

/**
 * Tests a server with its own repository.
 */
public void testStringRepository() throws MalformedURLException {
    final MondrianServer server = MondrianServer.createWithRepository(new StringRepositoryContentFinder("foo bar"), null);
    final int id = server.getId();
    assertNotNull(id);
    server.shutdown();
}
Also used : MondrianServer(mondrian.olap.MondrianServer) StringRepositoryContentFinder(mondrian.server.StringRepositoryContentFinder)

Aggregations

MondrianServer (mondrian.olap.MondrianServer)8 OlapConnection (org.olap4j.OlapConnection)4 XmlaTestContext (mondrian.xmla.test.XmlaTestContext)3 Properties (java.util.Properties)2 UrlRepositoryContentFinder (mondrian.server.UrlRepositoryContentFinder)2 Catalog (org.olap4j.metadata.Catalog)2 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Connection (mondrian.olap.Connection)1 MondrianException (mondrian.olap.MondrianException)1 PropertyList (mondrian.olap.Util.PropertyList)1 RolapConnection (mondrian.rolap.RolapConnection)1 FileRepository (mondrian.server.FileRepository)1 CatalogInfo (mondrian.server.FileRepository.CatalogInfo)1 StringRepositoryContentFinder (mondrian.server.StringRepositoryContentFinder)1 XmlaException (mondrian.xmla.XmlaException)1