Saiku多用户使用时数据同步刷新(十七)

时间:2023-03-09 05:42:33
Saiku多用户使用时数据同步刷新(十七)

Saiku多用户使用时数据同步刷新

这里我们需要了解一下关于saiku的刷新主要有两种数据需要刷新:

>1 刷新数据库的表中的数据,得到最新的表数据进行展示。

>2 刷新cube信息,得到最新的cube配置信息,避免 error loading page错误。

如果我们只使用admin用户登录saiku的话,是不存在任何问题的,直接点击saiku中刷新按钮即可达到刷新效果啦!

Saiku多用户使用时数据同步刷新(十七)

但是 如果我们配置了多用户使用saiku,且其它用户不是ROLE_ADMIN角色的话,是没有刷新按钮的,这时候就要靠我们的脚本刷新了。(而且总是去登录saiku点击按钮执行saiku也比较麻烦,所以还是比较推荐用脚本控制刷新哦)

首先我们得知道saiku刷新时会调用一个刷新接口,所以我们只要做到在脚本中请求对应用户的刷新接口即可。

刷新脚本内容如下:

saiku_refresh.sh

#!/bin/bash

dir=`pwd`
filename=/cookie.txt
filePath=${dir}${filename}
echo $filePath if [ -f $filePath ] ; then
echo 'cookie.txt exists'
rm -rf $filePath
echo 'The old cookie.txt is removed.'
fi
echo 'Begin to get new Cookie... ' curl -c ./cookie.txt -d "language=zh&password=admin&username=111" http://10.22.33.44:8080/saiku/rest/saiku/session
curl -b ./cookie.txt "http://10.22.33.44:8080/saiku/rest/saiku/admin/discover/refresh" 1>saiku_refresh_data.txt
echo 'admin refresh OK!!!' 1>>saiku_refresh_data.txt
echo 'admin refresh end!!!'
if [ -f $filePath ] ; then
echo 'cookie.txt exists'
rm -rf $filePath
echo 'The old cookie.txt is removed.'
fi curl -c ./cookie.txt -d "language=zh&password=111&username=test1" http://10.22.33.44:8080/saiku/rest/saiku/session
curl -b ./cookie.txt "http://10.22.33.44:8080/saiku/rest/saiku/test1/discover/refresh" 1>>saiku_refresh_data.txt
echo 'test1 refresh OK!!!' 1>>saiku_refresh_data.txt
echo 'test1 refresh end!!!' if [ -f $filePath ] ; then
echo 'cookie.txt exists'
rm -rf $filePath
echo 'The old cookie.txt is removed.'
fi curl -c ./cookie.txt -d "language=zh&password=111&username=test2" http://10.22.33.44:8080/saiku/rest/saiku/session
curl -b ./cookie.txt "http://10.22.33.44:8080/saiku/rest/saiku/test2/discover/refresh" 1>>saiku_refresh_data.txt
echo 'test2 refresh OK!!!' 1>>saiku_refresh_data.txt
echo 'test2 refresh end!!!' echo 'All refresh end!!!'

 

参数解析:

  password  参数指定需要被刷新的用户的密码

  username  参数指定需要被刷新的用户的用户名

  http://10.22.33.44:8080  指定saiku的访问地址

  /saiku/rest/saiku/username/discover/refresh :这便是被调用的刷新接口 ,username是根据用户变动的。

    eg:  需要刷新admin用户的数据信息,这里便需要改为 /saiku/rest/saiku/admin/discover/refresh

      需要刷新test1用户的数据信息,这里便需要改为 /saiku/rest/saiku/test1/discover/refresh

  

脚本解析:

1.得到当前脚本所在的目录,指定用来保存cookie信息的文件为cookie.txt

dir=`pwd`
filename=/cookie.txt
filePath=${dir}${filename}
echo $filePath

  

2.判断当前脚本同级目录是否已存在cookie.txt文件,如果已存在就删除,如果未存在就输出提示开始获取用户新的cookie信息。

if [ -f $filePath ] ; then
echo 'cookie.txt exists'
rm -rf $filePath
echo 'The old cookie.txt is removed.'
fi
echo 'Begin to get new Cookie... '

  

3. 将admin用户的验证信息存到cookie.txt文件中,并调用刷新接口,将刷新接口返回的数据信息存入 saiku_refresh_data.txt文件中,随后给出提示信息,admin用户的数据信息已刷新完成。

curl -c ./cookie.txt -d "language=zh&password=admin&username=111" http://10.22.33.44:8080/saiku/rest/saiku/session
curl -b ./cookie.txt "http://10.22.33.44:8080/saiku/rest/saiku/admin/discover/refresh" 1>saiku_refresh_data.txt
echo 'admin refresh OK!!!' 1>>saiku_refresh_data.txt
echo 'admin refresh end!!!'

 

4.开始进行下一个用户的数据刷新 test1, j继续判断cookie.txt文件是否存在,如果已存在就删除。

if [ -f $filePath ] ; then
echo 'cookie.txt exists'
rm -rf $filePath
echo 'The old cookie.txt is removed.'
fi

  

5.将test1用户的验证信息存到cookie.txt文件中,并调用刷新接口,将刷新接口返回的数据信息存入 saiku_refresh_data.txt文件中,随后给出提示信息,test1用户的数据信息已刷新完成。

curl -c ./cookie.txt -d "language=zh&password=111&username=test1" http://10.22.33.44:8080/saiku/rest/saiku/session
curl -b ./cookie.txt "http://10.22.33.44:8080/saiku/rest/saiku/test1/discover/refresh" 1>>saiku_refresh_data.txt
echo 'test1 refresh OK!!!' 1>>saiku_refresh_data.txt
echo 'test1 refresh end!!!'

  

6. test2用户刷新与test1用户刷新雷同,后面如果又给saiku添加其他用户也继续往后添加即可。(脚本参考test1 用户刷新)

切记需要对每个用户的数据都进行刷新哦,每个用户都要各调一遍刷新接口!!!  只刷新admin是不行的,其他用户获取不到最新的cube信息就会抛出异常!!! (error loading page)