[saiku] olap数据源管理
一、应用场景
系统初始化的时候
如果没有创建olap数据源需要先创建olap数据源
否则直接获取所有的数据源存放在全局变量datasources里面以便于后续步骤中获取plap-connections
二、代码详细解析
1、olap数据源对象结构
(1) SaikuDatasource - org.saiku.datasources.datasource.SaikuDatasource
public SaikuDatasource( String name, Type type, Properties properties ) {
this.name = name;//数据源名称
this.type = type;//数据源类型
this.properties = properties;//数据源属性
}
public enum Type {
OLAP
}
(2) DataSource - org.saiku.datasources.datasource.SaikuDatasource.DataSource
public DataSource(SaikuDatasource datasource) {
this.type = datasource.getType().toString();
this.name = datasource.getName();
this.driver = datasource.getProperties().getProperty("driver");
this.location = datasource.getProperties().getProperty("location");
this.username = datasource.getProperties().getProperty("username");
this.password = datasource.getProperties().getProperty("password");
this.id = datasource.getProperties().getProperty("id");
this.encryptpassword =datasource.getProperties().getProperty("encrypt.password");
this.securityenabled =datasource.getProperties().getProperty("security.enabled");
this.securitytype = datasource.getProperties().getProperty("security.type");
this.securitymapping =datasource.getProperties().getProperty("security.mapping");
this.advanced = datasource.getProperties().getProperty("advanced");
}
2、新增OLAP数据源
(1)判断是否需要新增此OLAP数据源的代码如下:
代码结构
|-Database.loadLegacyDatasources()
|- LegacyImporterImpl.importDatasources()
详细代码LegacyImporterImpl.importDatasources()
关键代码:
1) 获取数据源配置文件所在文件夹
String repoURL = "";
FileSystemManager fileSystemManager = VFS.getManager();
fileObject fileObject = fileSystemManager.resolveFile("res:saiku-datasources");
repoURL = fileObject.getURL();
2)遍历该文件夹下所有文件
File[] files = new File(repoURL.getFile()).listFiles();
3)获取OLAP数据源的配置构造saiku-ds对象并判断是否存在,不存在才添加
for (File file : files) {
Properties props = new Properties();
props.load(new FileInputStream(file));
稍微处理下props的location属性之后创建saikuDs
SaikuDatasource ds = new SaikuDatasource(name, t, props);
//获取已加入JCR的ds
List<DataSource> dsList = irm.getAllDataSources();
//比对待添加的OLAP_DS和已存在的OLAP_DS的名字,如果不存在,才添加
boolean isExists = false;
for (DataSource dataSource : dsList) {
if(dataSource.getName().equals(ds.getName())){
isExists = true;
break;
}
}
if(!isExists){
dsm.addDatasource(ds);
}
}
(2)新增数据源具体步骤
第一步将ds加入JCR节点
第二步将ds加入全局datasources
RepositoryDatasourceManager.addDatasource(SaikuDatasource datasource)
//源代码
private Map<String, SaikuDatasource> datasources =
Collections.synchronizedMap(new HashMap<String, SaikuDatasource>());
IRepositoryManager irm = JackRabbitRepositoryManager.getJackRabbitRepositoryManager(configurationpath, datadir, repopassword,oldpassword); public SaikuDatasource addDatasource(SaikuDatasource datasource){
DataSource ds = new DataSource(datasource);
irm.saveDataSource(ds, "/datasources/" + ds.getName() + ".sds", "fixme");
datasources.put(datasource.getName(), datasource);
return datasource;
}
(3)详解第一步:将ds加入JCR节点
JackRabbitRepositoryManager.saveDataSource(DataSource ds, String path, String user)
//源代码
public void saveDataSource(DataSource ds, String path, String user) throws RepositoryException {
//定义字节输出流
ByteArrayOutputStream baos = new ByteArrayOutputStream();
//将DataSource对象转换成XML文件,存入baos中
try {
JAXBContext jaxbContext = JAXBContext.newInstance(DataSource.class);
Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
jaxbMarshaller.marshal(ds, baos);
} catch (JAXBException e) {
log.error("Could not read XML", e);
}
//获取文件名
int pos = path.lastIndexOf("/");
String filename = "./" + path.substring(pos + 1, path.length());//结果为./schema名
//获取数据源根节点/datadatasources
Node n = getFolder(path.substring(0, pos));
//在根节点下添加文件节点resNode: path = /datadatasources/filename
//指定node名字为filename,类型为file,属性为olap_ds,以便后续查询olap数据源能查询到
Node resNode = n.addNode(filename, "nt:file");
resNode.addMixin("nt:olapdatasource");
//在新创建的resNode节点下添加文件内容节点contentNode:
//path = /datadatasources/filename/jcr:content
//设置该内容节点的内容为转换的XML的内容
Node contentNode = resNode.addNode("jcr:content", "nt:resource");
contentNode.setProperty("jcr:data", baos.toString());
//至此,数据源属性节点和配置内容节点就加入到JCR结构中了
//最后,别忘了保存新增的节点
resNode.getSession().save();
}
3、获取所有OLAP数据源
(1) 初始化内容仓库管理器
private String configurationXml = projectPath + "saiku-repository/configuration.xml";
private String datadir = projectPath + "saiku-repository/data";
private String repopassword = "sa!kuanalyt!cs";
private String oldpassword = ""; IRepositoryManager irm = JackRabbitRepositoryManager.getJackRabbitRepositoryManager(configurationpath, datadir, repopassword,oldpassword);\
(2) 初始化JCR基本结构
irm.start(userService);
关键代码:
1)获得内容根节点
//根据configurationXml文件配置在datadir路径下创建JCR文件夹基本结构
//相当于创建MyRepo
RepositoryConfig config = RepositoryConfig.create(configurationXml, datadir);
//根据JCR文件夹基本结构生成repository对象
repository = RepositoryImpl.create(config);
//获取操作JCR的权限[也叫Ticket]
session = repository.login(
new SimpleCredentials("admin", password.toCharArray()));
//根据session获取JCR的根节点
JackrabbitSession js = (JackrabbitSession) session;
session = js;
root = session.getRootNode();
root.getSession().save();
2)为workspace注册Node的类型。四种类型:File/Folder/Schema/DataSource
createFiles();
createFolders();
createSchemas();
createDataSources();
//创建的大致步骤
NodeTypeManager manager = session.getWorkspace().getNodeTypeManager();//相同的代码
NodeTypeTemplate ntt = manager.createNodeTypeTemplate();//相同的代码
ntt.setName("nt:saikufiles");//依次nt:saikufiles/nt:saikufolders/nt:mondrianschema/nt:olapdatasource
String[] str = new String[]{"nt:file"};//依次nt:saikufiles/nt:folder/nt:file/nt:file
ntt.setDeclaredSuperTypeNames(str);
ntt.setMixin(true);
//创建pdt对象 name有几个值就创建几个
//File 创建五个:name分别为owner/type/roles/users/jcr:data
//Folder 创建四个:name分别为owner/type/roles/users
//Schema 创建四个:name分别为owner/schemaname/cubenames/jcr:data
///DataSource 创建三个:name分别为owner/enabled/jcr:data
PropertyDefinitionTemplate pdt = manager.createPropertyDefinitionTemplate();//相同的代码
pdt.setName("owner");
pdt.setRequiredType(PropertyType.STRING);//相同的代码
ntt.getPropertyDefinitionTemplates().add(创建pdt对象);//有几个pdt就添加几次
manager.registerNodeType(ntt, false);//注册新建的节点类型//相同的代码
3)为workspace注册命名空间
createNamespace();
NamespaceRegistry ns = session.getWorkspace().getNamespaceRegistry();
if (!Arrays.asList(ns.getPrefixes()).contains("home")) {
ns.registerNamespace("home", "http://www.meteorite.bi/namespaces/home");
}
4)构建repository结构
在root节点下新增如下文件夹节点结构,并赋予一定的ACL权限<略>
结构:
/homes
/datasources
/etc
/etc/legacyreports
/etc/theme
/etc/theme/legacyreports
Node n = JcrUtils.getOrAddFolder(root, "homes");
n.addMixin("nt:saikufolders");
n = JcrUtils.getOrAddFolder(root, "datasources");
n.addMixin("nt:saikufolders");
n = JcrUtils.getOrAddFolder(root, "etc");
n.addMixin("nt:saikufolders");
n = JcrUtils.getOrAddFolder(n, "legacyreports");
n.addMixin("nt:saikufolders");
n = JcrUtils.getOrAddFolder(root, "etc/theme");
n.addMixin("nt:saikufolders");
n = JcrUtils.getOrAddFolder(n, "legacyreports");
n.addMixin("nt:saikufolders");
session.save();
(3) 获取JCR结构中存在的数据源
List<DataSource> dslist = irm.getAllDataSources();
关键代码:
1)获取MDX查询管理器
QueryManager qm = session.getWorkspace().getQueryManager();
2)查询执行属性的数据,获得所有类型为Cube数据源的节点
//创建Cube数据源时dsNode.addMixin("nt:olapdatasource");
String sql = "SELECT * FROM [nt:olapdatasource]";
Query query = qm.createQuery(sql, Query.JCR_SQL2);
QueryResult res = query.execute();
NodeIterator node = res.getNodes();
3)遍历NodeIterator,解析获取每一个node的属性构造Datasource对象
Node n = node.nextNode();//结果为:node_path = /datadatasources/filename
4)获取cube数据源的schema配置
String schemaContent = n.getNodes("jcr:content").nextNode().getProperty("jcr:data").getString();
5)将XML文件内容数据流转换为DataSource对象
Unmarshaller jaxbMarshaller = jaxbContext != null ? jaxbContext.createUnmarshaller() : null;
JAXBContext jaxbContext = JAXBContext.newInstance(DataSource.class);
InputStream stream = new ByteArrayInputStream(schemaContent.getBytes());
DataSource d = (DataSource) (jaxbMarshaller != null ? jaxbMarshaller.unmarshal(stream) : null);
6)设置数据源的路径
d.setPath(n.getPath());
7)遍历完所有olapds_node以后,返回dsList
(4) 根据dsList拼凑saikuDsList
for (DataSource file : dslist) {
Properties props = new Properties();
根据file构建props
SaikuDatasource.Type t = SaikuDatasource.Type.valueOf(file.getType().toUpperCase());//OLAP
SaikuDatasource ds = new SaikuDatasource(file.getName(),t,props);
datasources.put(file.getName(), ds);//将saikuDs加入到全局变量datasources中
}
[saiku] olap数据源管理的更多相关文章
- 数据源管理 | OLAP查询引擎,ClickHouse集群化管理
本文源码:GitHub·点这里 || GitEE·点这里 一.列式库简介 ClickHouse是俄罗斯的Yandex公司于2016年开源的列式存储数据库(DBMS),主要用于OLAP在线分析处理查询, ...
- 数据源管理 | Kafka集群环境搭建,消息存储机制详解
本文源码:GitHub·点这里 || GitEE·点这里 一.Kafka集群环境 1.环境版本 版本:kafka2.11,zookeeper3.4 注意:这里zookeeper3.4也是基于集群模式部 ...
- 数据源管理 | 搜索引擎框架,ElasticSearch集群模式
本文源码:GitHub·点这里 || GitEE·点这里 一.集群环境搭建 1.环境概览 ES版本6.3.2,集群名称esmaster,虚拟机centos7. 服务群 角色划分 说明 en-maste ...
- 数据源管理 | 分布式NoSQL系统,Cassandra集群管理
本文源码:GitHub·点这里 || GitEE·点这里 一.Cassandra简介 1.基础描述 Cassandra是一套开源分布式NoSQL数据库系统.它最初由Facebook开发,用于储存收件箱 ...
- Spring AOP /代理模式/事务管理/读写分离/多数据源管理
参考文章: http://www.cnblogs.com/MOBIN/p/5597215.html http://www.cnblogs.com/fenglie/articles/4097759.ht ...
- ODBC数据源管理器-》系统DSN-》没有....Microsoft Access Driver(*mdb,*,accdb)
问题如标题: 解决方法:打开目录:“C:\Windows\SysWOW64”,双击该目录下的“odbcad32.exe”文件,就进去ODBC数据源管理界面了,现在这个界面中就有access的驱动了!
- 数据源管理 | 主从库动态路由,AOP模式读写分离
本文源码:GitHub·点这里 || GitEE·点这里 一.多数据源应用 1.基础描述 在相对复杂的应用服务中,配置多个数据源是常见现象,例如常见的:配置主从数据库用来写数据,再配置一个从库读数据, ...
- 数据源管理 | 基于JDBC模式,适配和管理动态数据源
本文源码:GitHub·点这里 || GitEE·点这里 一.关系型数据源 1.动态数据源 动态管理数据源的基本功能:数据源加载,容器维护,持久化管理. 2.关系型数据库 不同厂商的关系型数据库,提供 ...
- 数据源管理 | PostgreSQL环境整合,JSON类型应用
本文源码:GitHub·点这里 || GitEE·点这里 一.PostgreSQL简介 1.和MySQL的比较 PostgreSQL是一个功能强大的且开源关系型数据库系统,在网上PostgreSQL和 ...
随机推荐
- activiti学习总结
Activiti界面元素的使用总结 一.图形设计中元素的使用 1.SequenceFlow:连接线,可以连接两个任务,来管理流程实例的流向 -----General -----id:流程的id,用与程 ...
- MTK+高通方案商
1.德信无线通讯科技有限公司 点击打开链接 2.深圳优美科技
- GMT时间转换
/// <summary> /// GMT时间转成本地时间 /// </summary> /// <param name="gmt">字符串形式 ...
- iOS开发学习笔记:基础篇
iOS开发需要一台Mac电脑.Xcode以及iOS SDK.因为苹果设备都具有自己封闭的环境,所以iOS程序的开发必须在Mac设备上完成(当然,黑苹果应该也是可以的,但就需要花很多的精力去折腾基础环境 ...
- Java开发中经典的小实例-(if(参数){}else{})
import java.util.Scanner; public class Calculate { public static void main(String[] args) { ...
- Sencha Toucha之Ext.Ajax
Ext.Ajax是Ext.data.Connection的hi一个单实例,不需要使用new或者Ext.create方法创建实例后再使用. 类的继承关系为: Ext.Base Ext.data.Conn ...
- 线程入门之join方法
package com.thread; /** * <join:将某线程加入进来,相当于方法调用,也叫合并某个线程> * <功能详细描述> * * @author 95Yang ...
- HUD5423 Rikka with Tree(DFS)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5423 Rikka with Tree Time Limit: 2000/1000 MS (Java/O ...
- NSDate使用
//获取当前日期,时间 +(NSDate *)getCurrentDate{ NSDate *now = [NSDate date]; return now; } //将日期转换为字符 ...
- getAttribute()方法的使用小笔记
今天在某课网上复习js,突然卡在一个小例子上.反复做了几遍就是报错.终于查询w3c才找到错误的源头. 这里记录一下,谨防以后又忘了. 错误码: <body> <p id=" ...