1. 程式人生 > >Oozie workflow之Hive Action

Oozie workflow之Hive Action

1、將examples中的hive複製到oozie-apps目錄下,並重命名

/opt/cdh5.14.2/oozie-4.1.0/oozie-apps/hive-select
[[email protected] hive-select]# ll
total 20
-rw-r--r-- 1 root root 1000 Aug  4 13:52 job.properties
-rw-r--r-- 1 root root  110 Aug  4 13:52 README
-rw-r--r-- 1 root root  966 Aug  4 13:52 script.q
-rw-r--r-- 1 root root 2003 Aug  4 13:52 workflow.xml
-rw-r--r-- 1 root root 2398 Aug  4 13:52 workflow.xml.security

2、在hive-select目錄下建立目錄lib,並將mysql-connector-java-5.1.27-bin.jar放到lib目錄下

3、將hive中的配置hive-site.xml複製到hive-select目錄下

4、job.properties

#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
nameNode=hdfs://ns1
jobTracker=master.cdh.com:8032
queueName=default
oozieAppsRoot=user/root/oozie-apps
oozieDataRoot=user/root/oozie/datas

oozie.use.system.libpath=true

oozie.wf.application.path=${nameNode}/${oozieAppsRoot}/hive-select/workflow.xml
outputDir=hive-select/output

5、userinfo-script.sql

insert overwrite directory '${OUTPUT}'
select user_id,user_name from db_bbc.tb_user;

6、workflow.xml

<?xml version="1.0" encoding="UTF-8"?>
<!--
  Licensed to the Apache Software Foundation (ASF) under one
  or more contributor license agreements.  See the NOTICE file
  distributed with this work for additional information
  regarding copyright ownership.  The ASF licenses this file
  to you under the Apache License, Version 2.0 (the
  "License"); you may not use this file except in compliance
  with the License.  You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->
<workflow-app xmlns="uri:oozie:workflow:0.5" name="hive-select-wf">
    <start to="hive-select-node"/>

    <action name="hive-select-node">
        <hive xmlns="uri:oozie:hive-action:0.5">
            <job-tracker>${jobTracker}</job-tracker>
            <name-node>${nameNode}</name-node>
            <prepare>
                <delete path="${nameNode}/${oozieDataRoot}/${outputDir}"/>
            </prepare>
			<job-xml>${nameNode}/${oozieAppsRoot}/hive-select/hive-site.xml</job-xml>
            <configuration>
                <property>
                    <name>mapred.job.queue.name</name>
                    <value>${queueName}</value>
                </property>
            </configuration>
            <script>userinfo-script.sql</script>
            <param>OUTPUT=${nameNode}/${oozieDataRoot}/${outputDir}</param>
        </hive>
        <ok to="end"/>
        <error to="fail"/>
    </action>

    <kill name="fail">
        <message>Hive failed, error message[${wf:errorMessage(wf:lastErrorNode())}]</message>
    </kill>
    <end name="end"/>
</workflow-app>

8、將 hive-select上傳到hdfs

bin/hdfs dfs -put /opt/cdh5.14.2/oozie-4.1.0/oozie-apps/hive-select /user/root/oozie-apps

9、啟動ozzie任務:

[[email protected] oozie-4.1.0]# bin/oozie job -oozie http://master.cdh.com:11000/oozie/ -config oozie-apps/hive-select/job.properties -run
job: 0000002-180805230543527-oozie-root-W

 10、任務結束以及結果:

[[email protected] hadoop-2.6.0]# bin/hdfs dfs -text /user/root/oozie/datas/hive-select/output/0*
18/08/06 05:22:25 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable