Carte是kettle自带的监控及调度服务,是一种内置的轻量级的web服务,支持使用http的方式进行转换、作业的调度,以及web方式监控作业及转换的运行情况,运行日志等。

本文使用kettle版本为8.2版本,部署环境为redhat7.6,安装路径为/SoftWare/data-integration ,kettle的安装部署较为简单,不再赘述。

1、配置carte.sh

[root@test11013 data-integration]# vi /SoftWare/data-integration/carte.sh

按i进入编辑模式,在OPT后面添加如下代码

-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.port=9180 -Dcom.sun.management.jmxremote.ssl=false

 

按ESC,输入:wq  保存退出

2、配置服务参数

[root@test11013 data-integration]# cd /SoftWare/data-integration/pwd/

[root@test11013 pwd]# vi carte-config-master-8080.xml

配置参数如下(IP和端口号自行调整): 

 <slaveserver>

    <name>master1</name>

    <hostname>192.168.110.13</hostname>

<username>admin</username>

<password>admin</password>

    <port>8070</port>

    <master>Y</master>

  </slaveserver>

<Max_log_lines>2000</Max_log_lines>

<Max_log_timeout_minutes>800</Max_log_timeout_minutes>

<Object_timeout_minutes>800</Object_timeout_minutes>

 

 

按ESC,输入:wq  保存退出

3、启动服务

[root@test11013 pwd]# cd /SoftWare/data-integration/

[root@test11013 data-integration]# nohup ./carte.sh pwd/carte-config-master-8080.xml 2>&1 &

开启防火墙

[root@kettle data-integration]# firewall-cmd --add-port=8070/tcp

关闭服务:

ps -aux|grep carte查找进程,然后使用kill -9 进程号

4、登陆验证

 游览器输入(http://IP:8070) ,输入账号及密码(admin/admin)

CURL方式远程调用示例:

curl -u "admin:admin" "http://192.168.110.13:8070/kettle/executeJob/?rep=rep-test01&job=/test01_job&P1=test"

-u :指定用户名和密码

rep参数:指定配置的资料库

job参数:执行的job

P1参数:kettle的参数变量P1的值

 

C#代码调用示例

try
            {
                //前台参数信息获取
                string url = "";
                string objecttype = this.cb_ObjectType.Text.ToString();
                string carte_url = this.tb_Carte_Url.Text.ToString();
                string carte_user = this.tb_Carte_User.Text.ToString();
                string carte_pwd = this.tb_Carte_Pwd.Text.ToString();
                string kettle_res = this.tb_Kettle_Res.Text.ToString();
                string kettle_user = this.tb_Kettle_User.Text.ToString();
                string kettle_pwd = this.tb_Kettle_Pwd.Text.ToString();
                string objcetname = this.tb_objectname.Text.ToString();
                if (objecttype == "job")
                {
                    //JOB调用executeJob
                    url = carte_url + "/executeJob/?" + "rep=" + kettle_res + "&user=" + kettle_user + "&pass=" + kettle_pwd + "&job=" + objcetname;
                }
                else
                {
                    //TRANS调用executeTrans
                    url = carte_url + "/executeTrans/?" + "rep=" + kettle_res + "&user=" + kettle_user + "&pass=" + kettle_pwd + "&trans=" + objcetname;
                }
                //默认的账号密码为:cluster/cluster,具体可在carte-config-masterXXX.xml中配置
                string username = "admin";
                string password = "admin";
                //组合认证格式
                string usernamePassword = username + ":" + password;
                //创建HttpWebRequest
                HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create(url);
                //输入认证
                myReq.Credentials = new NetworkCredential(username, password);
                //定义Webd返回
                WebResponse wr = myReq.GetResponse();
                //定义返回流数据
                Stream receiveStream = wr.GetResponseStream();
                //定义流读取
                StreamReader reader = new StreamReader(receiveStream, new System.Text.UTF8Encoding(false));
                //读取返回结果
                string content = reader.ReadToEnd();
                //显示返回结果
                this.richTextBox1.Text = content;
            }
            catch (Exception ex)
            {
                this.richTextBox1.Text = ex.ToString();
            }

 

Logo

更多推荐