
# schedule-tool工具使用示例
#### 操作场景
通过Loader WebUI或客户端工具Loader-tool创建好作业后，可使用schedule-tool工具执行作业。
#### 前提条件
完成了Loader客户端的安装与配置，具体操作请参见[使用客户端运行Loader作业](https://support.huaweicloud.com/cmpntguide-lts-mrs/mrs_01_1156.html)。
#### 操作步骤
1. 在SFTP服务器的"/opt/houjt/test03"路径中，创建多个以"table1"为前缀，".txt"为后缀，中间为yyyyMMdd的日期格式的文件。
   
   图1示例   
   ![](https://support.huaweicloud.com/cmpntguide-lts-mrs/zh-cn_image_0000001724866653.png "点击放大")
   
   
2. 创建一个从SFTP服务器导入数据到HDFS的Loader作业，具体操作请参见[使用Loader从SFTP服务器导入数据到HDFS/OBS](https://support.huaweicloud.com/cmpntguide-lts-mrs/mrs_01_1089.html)。
3. 使用安装客户端的用户登录客户端所在节点。
4. 执行以下命令，进入schedule-tool工具的conf目录。例如，Loader客户端安装目录为"/opt/client/Loader/"。 
   **cd /opt/client/Loader/loader-tools-1.99.3/schedule-tool/conf**
   
   
5. 执行以下命令，编辑schedule.properties文件，配置登录方式。 
   **vi schedule.properties**
   schedule-tool工具支持两种登录方式，两者只能选一。详细参数请参见[schedule-tool工具使用指导](https://support.huaweicloud.com/cmpntguide-lts-mrs/mrs_01_1159.html)。配置文件中包含认证密码信息可能存在安全风险，建议当前场景执行完毕后删除相关配置文件或加强安全管理。
   - 以密码方式登录，配置信息示例如下：
     ```
     [server.url = 10.10.26.187:21351,127.0.0.2:21351]
     [authentication.type = kerberos]
     [use.keytab = false]
     [authentication.user = admin]
     # 密码明文存储存在安全风险，建议在配置文件或者环境变量中密文存放，使用时解密，确保安全
     [authentication.password= xxx]
     ```
     
   
   - 以keytab文件方式登录，配置信息示例如下：
     ```
     [server.url = 10.10.26.187:21351,127.0.0.2:21351]
     [authentication.type = kerberos]
     [use.keytab = true]
     [client.principal = bar]
     [client.keytab = /opt/hadoopclient/Loader/loader-tools-1.99.3/loader-tool/hadoop-config/user.keytab]
     [krb5.conf.file = /opt/hadoopclient/Loader/loader-tools-1.99.3/loader-tool/hadoop-config/krb5.conf]
     ```
     
   
   
   
   
6. 执行以下命令，编辑job.properties文件，配置作业信息。 
   **vi job.properties**
   ```
   #job name
   job.jobName = sftp2hdfs-schedule-tool
   #Whether to update the loader configuration parameters(File filter)£?This parameter is used to match the import file name.Values are true or false.
   #false means update.the file name which is get by schedule tool will be updated to Loader configuration parameters (File filter).
   #false means no update.the file name which is get by schedule tool will be updated to Loader configuration parameters (import path).
   file.filter = false
   #File name = prefix + date + suffix
   #Need to import the file name prefix
   file.fileName.prefix=table1
   #Need to import the file name suffixes
   file.fileName.postfix=.txt
   #Date Days.Value is an integer.
   #According to the date and number of days to get the date of the import file.
   date.day = 1
   #Date Format.Import file name contains the date format.Format Type£ºyyyyMMdd,yyyyMMdd HHmmss,yyyy-MM-dd,yyyy-MM-dd HH:mm:ss
   file.date.format = yyyyMMdd
   #Date Format.Scheduling script execution. Enter the date format.
   parameter.date.format = yyyyMMdd
   #Whether the import file is a compressed format.Values ??are true or false.
   #true indicates that the file is a compressed format£?Execution scheduling tool will extract the files.false indicates that the file is an uncompressed.Execution scheduling tool does not unpack.
   file.format.iscompressed = false
   #Hadoop storage type.Values are HDFS or HBase.
   storage.type = HDFS
   ```
   根据[1]的所准备的数据，以文件table120160221.txt为例，过滤规则设置如下：
   - 文件名的前缀 file.fileName.prefix=table1
     
   
   - 文件名的后缀 file.fileName.postfix=.txt
     
   
   - 文件名中包含的日期格式 file.date.format = yyyyMMdd
     
   
   - 调用脚本输入的日期参数 parameter.date.format = yyyyMMdd
     
   
   - 顺延的天数 date.day = 1
     例如，脚本传入的日期参数是20160220，则通过加法计算，得到的结果是20160221。
     ![](https://support.huaweicloud.com/cmpntguide-lts-mrs/public_sys-resources/note_3.0-zh-cn.png)
     如果执行的命令是**./run.sh 20160220 /user/loader/schedule_01**时，以上过滤规则会拼凑出一个字符串："table1"+"20160221"+.txt = table120160221.txt
     
   
   
   
   
7. 根据file.filter的值，选择过滤规则。 
   - 精确匹配某一个文件，请执行[8]。
   
   - 模糊匹配一系列文件，请执行[9]。
   
   
   
   
8. 将job.properties文件中"file.filter"的值修改为"false"。
   
   执行以下命令，运行作业，任务结束。
   **cd /opt/client/Loader/loader-tools-1.99.3/schedule-tool**
   **./run.sh** *20160220* */user/loader/schedule_01*
   其中*20160220* 为输入的日期，*/user/loader/schedule_01*为输出的路径。
   ![](https://support.huaweicloud.com/cmpntguide-lts-mrs/public_sys-resources/note_3.0-zh-cn.png)
   通过以上过滤规则，拼凑得到的字符串"table120160221.txt"，会直接作为文件名，追加到作业配置的输入路径中。所以，作业只会处理唯一匹配到的文件"table120160221.txt"。
   
   
9. 将job.properties文件中"file.filter"的值修改为"true"，"file.fileName.prefix"设置为"\*"。
   
   执行以下命令，运行作业，任务结束。
   **cd /opt/client/Loader/loader-tools-1.99.3/schedule-tool**
   **./run.sh** *20160220* */user/loader/schedule_01*
   其中*20160220* 为输入的日期，*/user/loader/schedule_01*为输出的路径。
   ![](https://support.huaweicloud.com/cmpntguide-lts-mrs/public_sys-resources/note_3.0-zh-cn.png)
   通过以上过滤规则，拼凑到的字符串"\*20160221.txt"，会作为文件过滤器的模糊匹配模式，在作业配置的输入路径下，所有符合"\*20160221.txt"这个模式的文件都将被作业处理。
   
   
 
