Updated on 2024-08-10 GMT+08:00

Compiling and Running Applications

Scenario

IoTDB applications can run in a Linux environment where the Flink client is installed and in an environment where the Flink web UI is installed. After the application code is developed, you can upload the JAR file to the prepared environment.

Prerequisites

  • The Flink component has been installed in the cluster and the FlinkServer instance has been added.
  • The cluster client that contains the Flink service has been installed, for example, in the /opt/client directory.
  • If the host where the client is installed is not a node in the cluster, the mapping between the host name and the IP address must be set in the hosts file on the node where the client is located. The host names and IP addresses must be mapped one by one.

Procedure

  1. Build a JAR file.

    • In IntelliJ IDEA, configure Artifacts of the project before generating a JAR file.
      1. On the IDEA homepage, choose File > Project Structures... to go to the Project Structure page.
      2. On the Project Structure page, select Artifacts, click +, and select From modules with dependencies....
        Figure 1 Adding Artifacts
      3. Select extract to the target JAR and click OK.

      4. Set the name, type, and output path of the JAR file based on the site requirements.

        To avoid JAR file conflicts caused by unnecessary JAR files, you only need to load the following basic JAR files related to IoTDB:

        • flink-iotdb-connector-*
        • flink-tsfile-connector-*
        • hdoop-tsfile-*
        • influxdb-thrift-*
        • iotdb-antlr-
        • iotdb-session-*
        • iotdb-thrift-*
        • iotdb-thrift-commons-*
        • isession-*
        • libthrift-*
        • iotdb-session-*
        • iotdb-thrift-*
        • service-rpc-*
        • tsfile-*

        Click OK.

      5. On the IDEA home page, choose Build > Build Artifacts.... On the Build Artifact page that is displayed, choose Action > Build.

      6. After the build is successful, the message "Build completed successfully" is displayed in the lower right corner, and the corresponding JAR file is generated in the Output Directory directory.

  2. (Scenario 1) Run a Flink job on the Flink web UI.

    1. Log in to FusionInsight Manager of the cluster as a user who has the FlinkServer web UI management permission, choose Cluster > Services > Flink, and click the hyperlink next to Flink WebUI on the dashboard page to go to the FlinkServer web UI.
    2. On the FusionInsight Flink web UI, choose Job Management > Create Job to create a job.

    3. Set Type to Flink Jar, enter the name of the job to be created, select a task type, and click OK.

    4. Upload the JAR file generated in 1, set Main Class to Specify, enter the class to be executed in Class Parameter, and click Submit.

      For example, set Type to com.huawei.bigdata.iotdb.FlinkIoTDBSink (development program that executes FlinkIoTDBSink) or com.huawei.bigdata.iotdb.FlinkIoTDBSource (development program that executes FlinkIoTDBSource).

  3. (Scenario 2) Submit a Flink job on the Flink client in the Linux environment.

    • Save the JAR file generated in 1 to the Flink running environment (Flink client) in the Linux environment, for example, /opt/client.
    • Start the Flink cluster before running the Flink applications on Linux. Run the yarn session command on the Flink client to start the Flink cluster. The following is a command example:
      bin/yarn-session.sh -jm 1024 -tm 1024
    • Run the flink-example.jar sample application.

      Open another window on the terminal. Go to the Flink client directory and invoke the bin/flink run script to run code.

      bin/flink flink run --class com.huawei.bigdata.iotdb.FlinkIoTDBSink /opt/client/Flink/flink/flink-example.jar

      com.huawei.bigdata.iotdb.FlinkIoTDBSink is the application in FlinkIoTDBSink.