Typical Scenario: Exporting Data from HDFS or OBS to an SFTP Server
Scenario
This section describes how to use Loader to export data from HDFS or OBS to an SFTP server.
Prerequisites
- You have obtained the service username and password for creating a Loader job.
- You have had the permission to access the HDFS or OBS directories and data involved in job execution.
- You have obtained the username and password of the SFTP server and the user has the write permission of the data export directory on the SFTP server.
- No disk space alarm is reported, and the available disk space is sufficient for importing and exporting data.
- When using Loader to export data from HDFS or OBS, the input paths and input path subdirectories of the HDFS or OBS data source and the name of the files in these directories do not contain any of the following special characters: /\"':;,.
- If a configured task requires the Yarn queue function, the user must be authorized with related Yarn queue permission.
- The user who configures a task must obtain execution permission on the task and obtain usage permission on the related connection of the task.
Procedure
Configure basic job information.
- Access the Loader web UI.
- Log in to FusionInsight Manager.
- Choose Cluster > Services > Loader.
- Click LoaderServer(Node name, Active). The Loader web UI is displayed.
Figure 1 Loader web UI
- Click New Job. Configure basic job parameters on the Basic Information page displayed.
Figure 2 Basic Information page
- Enter a job name in Name.
- Set Type to Export.
- Set Group to the group to which the job belongs. There is no group created by default. Click Add, enter the group name, and click OK.
- Set Queue to the Yarn queue that executes the job. The default value is root.default.
- Set Priority to the priority of the Yarn queue that executes the job. The default value is NORMAL. The options are VERY_LOW, LOW, NORMAL, HIGH, and VERY_HIGH.
- In the Connection area, click Add to create a connection, set Connector to sftp-connector, click Add, set connection parameters, and click Test to verify whether the connection is available. When "Test Success" is displayed, click OK. Loader allows multiple SFTP servers to be configured. Click Add to add the configuration information of multiple SFTP servers.
Table 1 Connection parameters Parameter
Description
Example Value
Name
Specifies the name of the SFTP server connection.
sftpName
SFTP Server IP
Specifies the IP address of the SFTP server.
10.16.0.1
SFTP Server Port
Specifies the port number of the SFTP server.
22
SFTP Username
Specifies the user name for accessing the SFTP server.
root
SFTP Password
Specifies the password for accessing the SFTP server.
xxxx
SFTP Public Key
Specifies public key of the SFTP server.
OdDt/yn...etM
When multiple SFTP servers are configured, the data of HDFSor OBS will be divided into multiple parts and exported to the SFTP servers randomly.
Configure data source information.
- Click Next. On the displayed From page, set Source type to HDFS.
Table 2 Data source parameters Parameter
Description
Example Value
Input directory
Specifies the input path when data is exported from HDFS or OBS.
NOTE:You can use macros to define path parameters. For details, see Using Macro Definitions in Configuration Items.
/user/test
Path filter
Specifies the wildcard for filtering the directories in the input paths of the source files. Input directory is not used in filtering. If there are multiple filter conditions, use commas (,) to separate them. If the parameter is empty, the directory is not filtered. The regular expression filtering is not supported.
- ? matches a single character.
- * indicates multiple characters.
- Adding ^ before the condition indicates negated filtering, that is, file filtering.
*
File filter
Specifies the wildcard for filtering the file names of the source files. If there are multiple filter conditions, use commas (,) to separate them. The value cannot be left blank. The regular expression filtering is not supported.
- ? matches a single character.
- * indicates multiple characters.
- Adding ^ before the condition indicates negated filtering, that is, file filtering.
*
File Type
Specifies the file import type.
- TEXT_FILE: imports a text file and saves it as a text file.
- SEQUENCE_FILE: imports a text file and saves it as a sequence file.
- BINARY_FILE: imports files of any format using binary streams but not to process the files.
NOTE:When the file import type to TEXT_FILE or SEQUENCE_FILE, Loader automatically selects a decompression method based on the file name extension to decompress a file.
TEXT_FILE
File Split Type
Indicates whether to split source files by file name or size. The files obtained after the splitting are used as the input files of each map in the MapReduce task for data export.
- FILE: indicates that the source file is split by file. That is, each map processes one or multiple complete files, the same source file cannot be allocated to different maps, and the source file directory structure is retained after data import.
- SIZE: indicates that the source file is split by size. That is, each map processes input files of a certain size, and a source file can be divided and processed by multiple maps. After data is stored in the output directory, the number of saved files is the same as the number of maps. The file name format is import_part_xxxx, where xxxx is a unique random number generated by the system.
FILE
Extractors
Number of Maps that are started at the same time in a MapReduce task of a data configuration operation. This parameter cannot be set when Extractor Size is set. The value must be less than or equal to 3000. You are advised to set the parameter to the number of CPU cores on the SFTP server.
NOTE:To improve the data import speed, ensure that the following conditions are met:
- Each map connection is equivalent to a client connection. Therefore, you must ensure that the maximum number of connections of the SFTP server is greater than the number of maps.
- Ensure that the disk I/O or network bandwidth on the SFTP server does not reach the upper limit.
20
Extractor size
Specifies the size of data processed by maps that are started in a MapReduce job of a data configuration operation. The unit is MB. The value must be greater than or equal to 100. The recommended value is 1000. This parameter cannot be set when Extractors is set.
-
Configure data transformation.
- Click Next. On the displayed Transform page, set the transformation operations in the data transformation process. For details about how to select operators and set parameters, see Operator Help and Table 3.
Table 3 Input and output parameters of the operator Input Type
Output Type
CSV File Input
File Output
HTML File Input
File Output
Fixed File Input
File Output
In input, drag CSV File Input, HTML File Input, or Fixed File Input to the grid. In output, drag File Output to the grid. Use an arrow to connect CSV File Input, HTML File Input, or Fixed File Input to File Output.
Set data storage information and execute the job.
- Click Next. On the displayed To page, set the data storage mode.
Table 4 Parameter description Parameter
Description
Example Value
Output path
Specifies the path or file name of the exported file on an SFTP server. If multiple SFTP server IP addresses are configured for the connector, you can set this parameter to multiple paths or file names separated with semicolons (;). Ensure that the number of paths or file names is the same as the number of SFTP servers configured for the connector.
NOTE:You can use macros to define path parameters. For details, see Using Macro Definitions in Configuration Items.
/opt/tempfile
Operation
Specifies the action during data import. When all data is imported from the input path to the destination path, the data is stored in a temporary directory and then copied from the temporary directory to the destination path. After data import is complete, the data in the temporary directory is deleted. One of the following actions can be taken when there are duplicate file names during data transfer:
- OVERRIDE: overrides the old file.
- RENAME: renames the new file. For a file without a file name extension, a string is added to the file name as the extension; for a file with a file name extension, a string is added to the extension. The string is unique.
- APPEND: adds the content of the new file to the end of the old file. This action only adds content regardless of whether the file can be used. For example, a text file can be used after this action, while a compressed file cannot.
- IGNORE: reserves the old file and does not copy the new file.
- ERROR: stops the task and reports an error if there are duplicate file names. Transferred files are imported successfully, while files that have duplicate names and files that are not transferred fail to import.
OVERRIDE
Encode type
Specifies the exported file encoding format, for example, UTF-8. This parameter can be set only in text file export.
UTF-8
Compression
Indicates whether to enable the compressed transmission function when SFTP is used to export data.
- The value true indicates that compression is enabled.
- The value false indicates that compression is disabled.
true
- Click Save and Run to save and run the job.
View the job execution result.
- Go to the Loader web UI. When Status is Succeeded, the job is complete.
Figure 3 Viewing a job
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot