Search in sources :

Example 11 with MondrianException

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

the class PentahoXmlaServletTest method testInvalidDataSourceInfo.

@Test
public void testInvalidDataSourceInfo() throws Exception {
    ISecurityHelper securityHelper = mock(ISecurityHelper.class);
    SecurityHelper.setMockInstance(securityHelper);
    when(securityHelper.runAsSystem(any((Callable.class)))).thenReturn("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<DataSources>\n" + "<DataSource>\n" + "<DataSourceName>Pentaho</DataSourceName>\n" + "<DataSourceDescription>Pentaho BI Platform Datasources</DataSourceDescription>\n" + "<URL>http://localhost:8080/pentaho/Xmla</URL>\n" + "<DataSourceInfo>Provider=mondrian</DataSourceInfo>\n" + "<ProviderName>PentahoXMLA</ProviderName>\n" + "<ProviderType>MDP</ProviderType>\n" + "<AuthenticationMode>Unauthenticated</AuthenticationMode>\n" + "<Catalogs>\n" + "<Catalog name=\"SampleData\">\n" + "<DataSourceInfo></DataSourceInfo>\n" + "<Definition>mondrian:/SampleData</Definition>\n" + "</Catalog>\n" + "</Catalogs>\n" + "</DataSource>\n" + "</DataSources>\n");
    try {
        // should throw
        new PentahoXmlaServlet().makeContentFinder("fakeurl").getContent();
    } catch (MondrianException e) {
        assertTrue(e.getCause().getCause().getMessage().contains("DataSourceInfo not defined for SampleData"));
        return;
    }
    fail("Did not throw expected exception.");
}
Also used : ISecurityHelper(org.pentaho.platform.api.engine.ISecurityHelper) MondrianException(mondrian.olap.MondrianException) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 12 with MondrianException

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

the class MondrianModelComponent method getInitialQuery.

public static String getInitialQuery(final Properties properties, final String cubeName, IPentahoSession session) throws Throwable {
    // Apply any properties for this catalog specified in datasource.xml
    IMondrianCatalogService mondrianCatalogService = PentahoSystem.get(IMondrianCatalogService.class, "IMondrianCatalogService", PentahoSessionHolder.getSession());
    List<MondrianCatalog> catalogs = mondrianCatalogService.listCatalogs(PentahoSessionHolder.getSession(), true);
    String propCat = properties.getProperty(RolapConnectionProperties.Catalog.name());
    for (MondrianCatalog cat : catalogs) {
        if (cat.getDefinition().equalsIgnoreCase(propCat)) {
            Util.PropertyList connectProperties = Util.parseConnectString(cat.getDataSourceInfo());
            Iterator<Pair<String, String>> iter = connectProperties.iterator();
            while (iter.hasNext()) {
                Pair<String, String> pair = iter.next();
                if (// Only set if not set already
                !properties.containsKey(pair.getKey())) {
                    properties.put(pair.getKey(), pair.getValue());
                }
            }
            break;
        }
    }
    MDXConnection mdxConnection = (MDXConnection) PentahoConnectionFactory.getConnection(IPentahoConnection.MDX_DATASOURCE, properties, session, null);
    // mdxConnection.setProperties( properties );
    Connection connection = mdxConnection.getConnection();
    if (connection == null) {
        Logger.error("MondrianModelComponent", Messages.getInstance().getErrorString("MondrianModel.ERROR_0001_INVALID_CONNECTION", // $NON-NLS-1$ //$NON-NLS-2$
        properties.toString()));
        return null;
    }
    try {
        return MondrianModelComponent.getInitialQuery(connection, cubeName);
    } catch (Throwable t) {
        if (t instanceof MondrianException) {
            // pull the cause out, otherwise it never gets logged
            Throwable cause = ((MondrianException) t).getCause();
            if (cause != null) {
                throw cause;
            } else {
                throw t;
            }
        } else {
            throw t;
        }
    }
}
Also used : MondrianCatalog(org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalog) SQLConnection(org.pentaho.platform.plugin.services.connections.sql.SQLConnection) MDXConnection(org.pentaho.platform.plugin.services.connections.mondrian.MDXConnection) IPentahoConnection(org.pentaho.commons.connection.IPentahoConnection) Connection(mondrian.olap.Connection) RolapConnection(mondrian.rolap.RolapConnection) Util(mondrian.olap.Util) IMondrianCatalogService(org.pentaho.platform.plugin.action.mondrian.catalog.IMondrianCatalogService) MDXConnection(org.pentaho.platform.plugin.services.connections.mondrian.MDXConnection) MondrianException(mondrian.olap.MondrianException) Pair(mondrian.util.Pair)

Example 13 with MondrianException

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

the class MondrianCatalogHelper method addCatalog.

/**
 * new method to pass the input stream directly from data access put and post schema
 *
 * @param schemaInputStream
 * @param catalog
 * @param overwrite
 * @param acl               catalog ACL
 * @param pentahoSession
 * @throws MondrianCatalogServiceException
 */
@Override
public synchronized void addCatalog(InputStream schemaInputStream, final MondrianCatalog catalog, final boolean overwrite, RepositoryFileAcl acl, final IPentahoSession pentahoSession) throws MondrianCatalogServiceException {
    if (MondrianCatalogHelper.logger.isDebugEnabled()) {
        // $NON-NLS-1$
        MondrianCatalogHelper.logger.debug("addCatalog");
    }
    init(pentahoSession);
    // check for existing dataSourceInfo+catalog
    final boolean catalogExistsWithSameDatasource = catalogExists(catalog, pentahoSession);
    if (catalogExistsWithSameDatasource && !overwrite) {
        throw new MondrianCatalogServiceException(Messages.getInstance().getErrorString("MondrianCatalogHelper.ERROR_0004_ALREADY_EXISTS"), // $NON-NLS-1$
        Reason.ALREADY_EXISTS);
    }
    // Checks if a catalog of the same name but with a different file
    // path exists.
    MondrianCatalog fileLocationCatalogTest = null;
    for (MondrianCatalog currentCatalogCheck : getCatalogs(pentahoSession)) {
        if (currentCatalogCheck.getName().equals(catalog.getName())) {
            fileLocationCatalogTest = currentCatalogCheck;
            break;
        }
    }
    // compare the catalog names and throw exception if same and NOT ovewrite
    final boolean catalogExistsWithDifferentDatasource;
    try {
        catalogExistsWithDifferentDatasource = fileLocationCatalogTest != null && definitionEquals(fileLocationCatalogTest.getDefinition(), "mondrian:/" + URLEncoder.encode(catalog.getName(), "UTF-8"));
    } catch (UnsupportedEncodingException e) {
        throw new MondrianCatalogServiceException(e);
    }
    if (catalogExistsWithDifferentDatasource && !overwrite) {
        throw new MondrianCatalogServiceException(Messages.getInstance().getErrorString(// $NON-NLS-1$
        "MondrianCatalogHelper.ERROR_0004_ALREADY_EXISTS"), Reason.XMLA_SCHEMA_NAME_EXISTS);
    }
    MondrianCatalogRepositoryHelper helper = getMondrianCatalogRepositoryHelper();
    try {
        helper.addHostedCatalog(schemaInputStream, catalog.getName(), catalog.getDataSourceInfo());
    } catch (Exception e) {
        throw new MondrianCatalogServiceException(Messages.getInstance().getErrorString(// $NON-NLS-1$
        "MondrianCatalogHelper.ERROR_0008_ERROR_OCCURRED"), Reason.valueOf(e.getMessage()));
    }
    if (MondrianCatalogHelper.logger.isDebugEnabled()) {
        MondrianCatalogHelper.logger.debug(// $NON-NLS-1$ //$NON-NLS-2$
        "refreshing from dataSourcesConfig (" + dataSourcesConfig + ")");
    }
    try {
        reInit(pentahoSession);
        setAclFor(catalog.getName(), acl);
        if (catalogExistsWithSameDatasource || catalogExistsWithDifferentDatasource) {
            flushCacheForCatalog(catalog.getName(), pentahoSession);
        }
    } catch (MondrianException e) {
        helper.deleteHostedCatalog(catalog.getName());
        reInit(pentahoSession);
        throw e;
    }
}
Also used : UnsupportedEncodingException(java.io.UnsupportedEncodingException) MondrianCatalogRepositoryHelper(org.pentaho.platform.plugin.services.importexport.legacy.MondrianCatalogRepositoryHelper) MondrianException(mondrian.olap.MondrianException) XOMException(org.eigenbase.xom.XOMException) FileSystemException(org.apache.commons.vfs2.FileSystemException) FileNotFoundException(java.io.FileNotFoundException) ObjectFactoryException(org.pentaho.platform.api.engine.ObjectFactoryException) XmlParseException(org.pentaho.platform.api.util.XmlParseException) SAXException(org.xml.sax.SAXException) MondrianException(mondrian.olap.MondrianException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) DBDatasourceServiceException(org.pentaho.platform.api.data.DBDatasourceServiceException) IOException(java.io.IOException) SAXParseException(org.xml.sax.SAXParseException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Example 14 with MondrianException

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

the class MondrianCatalogHelperIT method testAddCatalogWithException.

@Test(expected = MondrianException.class)
public void testAddCatalogWithException() {
    initMondrianCatalogsCache();
    MondrianCatalogHelper helperSpy = spy(helper);
    doThrow(new MondrianException()).when(helperSpy).reInit(any(IPentahoSession.class));
    IPentahoSession session = mock(IPentahoSession.class);
    doNothing().when(helperSpy).init(session);
    MondrianCatalog cat = createTestCatalog();
    MondrianCatalogRepositoryHelper repositoryHelper = mock(MondrianCatalogRepositoryHelper.class);
    doReturn(repositoryHelper).when(helperSpy).getMondrianCatalogRepositoryHelper();
    try {
        helperSpy.addCatalog(new ByteArrayInputStream(new byte[0]), cat, true, null, session);
    } catch (MondrianException e) {
        // verifying the repository rolled back and the cache reinitialized
        verify(repositoryHelper, times(1)).deleteHostedCatalog(anyString());
        verify(helperSpy, times(2)).reInit(any(IPentahoSession.class));
    }
    helperSpy.addCatalog(new ByteArrayInputStream(new byte[0]), cat, true, null, session);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) MondrianCatalogRepositoryHelper(org.pentaho.platform.plugin.services.importexport.legacy.MondrianCatalogRepositoryHelper) MondrianException(mondrian.olap.MondrianException) Test(org.junit.Test)

Example 15 with MondrianException

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

the class SegmentLoader method loadImpl.

private Map<Segment, SegmentWithData> loadImpl(int cellRequestCount, List<GroupingSet> groupingSets, List<StarPredicate> compoundPredicateList) {
    SqlStatement stmt = null;
    GroupingSetsList groupingSetsList = new GroupingSetsList(groupingSets);
    RolapStar.Column[] defaultColumns = groupingSetsList.getDefaultColumns();
    final Map<Segment, SegmentWithData> segmentMap = new HashMap<Segment, SegmentWithData>();
    Throwable throwable = null;
    try {
        int arity = defaultColumns.length;
        SortedSet<Comparable>[] axisValueSets = getDistinctValueWorkspace(arity);
        stmt = createExecuteSql(cellRequestCount, groupingSetsList, compoundPredicateList);
        if (stmt == null) {
            // Nothing to do. We're done here.
            return segmentMap;
        }
        boolean[] axisContainsNull = new boolean[arity];
        RowList rows = processData(stmt, axisContainsNull, axisValueSets, groupingSetsList);
        boolean sparse = setAxisDataAndDecideSparseUse(axisValueSets, axisContainsNull, groupingSetsList, rows);
        final Map<BitKey, GroupingSetsList.Cohort> groupingDataSetsMap = createDataSetsForGroupingSets(groupingSetsList, sparse, rows.getTypes().subList(arity, rows.getTypes().size()));
        loadDataToDataSets(groupingSetsList, rows, groupingDataSetsMap);
        setDataToSegments(groupingSetsList, groupingDataSetsMap, segmentMap);
        return segmentMap;
    } catch (Throwable e) {
        throwable = e;
        if (stmt == null) {
            throw new MondrianException(e);
        }
        throw stmt.handle(e);
    } finally {
        if (stmt != null) {
            stmt.close();
        }
        setFailOnStillLoadingSegments(segmentMap, groupingSetsList, throwable);
    }
}
Also used : MondrianException(mondrian.olap.MondrianException)

Aggregations

MondrianException (mondrian.olap.MondrianException)23 Util (mondrian.olap.Util)5 PostgreSqlDialect (mondrian.spi.impl.PostgreSqlDialect)5 Connection (mondrian.olap.Connection)4 RolapConnection (mondrian.rolap.RolapConnection)4 SQLException (java.sql.SQLException)3 Test (org.junit.Test)3 IMondrianCatalogService (org.pentaho.platform.plugin.action.mondrian.catalog.IMondrianCatalogService)3 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 ArrayList (java.util.ArrayList)2 Properties (java.util.Properties)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 Query (mondrian.olap.Query)2 AbortException (mondrian.rolap.agg.SegmentCacheManager.AbortException)2 SegmentCacheIndex (mondrian.rolap.cache.SegmentCacheIndex)2 Locus (mondrian.server.Locus)2 FileSystemException (org.apache.commons.vfs2.FileSystemException)2 XOMException (org.eigenbase.xom.XOMException)2