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