[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和 ...
随机推荐
- Linux 运维工程师的十个基本技能点
本人是linux运维工程师,对这方面有点心得,现在我说说要掌握哪方面的工具吧. 说到工具,在行外可以说是技能,在行内我们一般称为工具,就是运维必须要掌握的工具.我就大概列出这几方面,这样入门就基本没问 ...
- GMM及EM算法
GMM及EM算法 标签(空格分隔): 机器学习 前言: EM(Exception Maximizition) -- 期望最大化算法,用于含有隐变量的概率模型参数的极大似然估计: GMM(Gaussia ...
- installing a 3D printer
托公司的福,今天可以自己组装一台3D打印机.心里颇有一种开箱有益的兴奋. 落入手中的是一台Panowin F1,价格不贵,却同时拥有了3D打印功能和激光打印功能.颇有一种小型创客作坊的雏形. 硬件搭建 ...
- Codeforces Round #281 (Div. 2) D. Vasya and Chess 水
D. Vasya and Chess time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Intel微处理器学习笔记(五) 中断
▼ 中断是一个由硬件激发的过程,它中断当前正在执行的任何程序. ▼ 在Intel系列微处理器中,包括INTR和NMI(Non Maskable Interrupt)两个申请中断的引脚和一个响应INTR ...
- cocos2d-x 3.X (二)创建动起来的精灵
[参考文章]http://www.cnblogs.com/suguoqiang/archive/2013/04/03/2997316.html 在HelloWorldScene.h中声明void ro ...
- iOS - Swift NSNull 空值
前言 public class NSNull : NSObject, NSCopying, NSSecureCoding 作为占据空间的一个空值,如用在数组或字典中占据一个没有任何值的空间. 1.NS ...
- 在PC端或移动端应用中接入商业QQ的方法
今天看博友的博客学习了一种很有用的方法: 在页面中需要接入企业的QQ,访问网址:http://shang.qq.com/widget/consult.php.(就是API接口),然后你只需要登录你的Q ...
- Linux GDB Debug
http://blog.jobbole.com/107925/ gdb 调试入门,大牛写的高质量指南 http://blog.jobbole.com/107759/ gdb是the GNU Debug ...
- 对于syncedmen类的代码分析
对于数据在cpu与GPU之间同步的问题,caffe中用syncedMemory这个类来解 决:在GPU模式下,并且使用CUDA时,可以用CaffeMallocHost函数与CaffeFreeHost函 ...