Updated on 2024-04-02 GMT+08:00

Configuring a Spring Boot Sample Project

This section applies to MRS 3.3.0 or later.

Scenarios

Run the sample code of the Spring Boot interface in FusionInsight MRS Hive. Currently, GaussDB(DWS) SpringBoot sample projects are supported.

In the following example, an application is developed in Linux to connect GaussDB(DWS) to Flink using Spring Boot.

Before run the GaussDB(DWS) sample, log in to the node where GaussDB(DWS) is deployed to create an empty table test_lzh1 for receiving data. The creation command is as follows:

create table test_lzh1 (id integer not null);

Procedure

  1. Install a client that contains the Flink service.

    The following example shows how to install the Flink client on a node in the cluster:

    1. Log in to FusionInsight Manager. On the home page, click Download Client. The Download Cluster Client dialog box is displayed.
    2. In the Download Cluster Client dialog box that is displayed, select Complete Client for Select Client Type, select the platform type that matches the architecture of the node where the client is to install, select Save to Path, and click OK.

      The generated file is stored in the /tmp/FusionInsight-Client directory on the active management node by default.

      The name of the client software package is in the following format: FusionInsight_Cluster_<Cluster ID>_Services_Client.tar. The following content uses the cluster ID 1 as an example.

    3. Log in to the server where the client is to be installed as the client installation user.
    4. Go to the directory where the installation package is stored and run the following commands to decompress the package:

      cd /tmp/FusionInsight-Client

      tar -xvf FusionInsight_Cluster_1_Services_Client.tar

    5. Run the following command to verify the decompressed file and check whether the command output is consistent with the information in the sha256 file:

      sha256sum -c FusionInsight_Cluster_1_Services_ClientConfig.tar.sha256

    6. Decompress the obtained installation file.

      tar -xvf FusionInsight_Cluster_1_Services_ClientConfig.tar

    7. Go to the directory where the installation package is stored, and run the following command to install the client to a specified directory (absolute path), for example, /opt/hadoopclient:

      cd /tmp/FusionInsight-Client/FusionInsight_Cluster_1_Services_ClientConfig

      ./install.sh /opt/hadoopclient

    8. Configure security authentication and encryption. For details, see "Using Flink from Scratch" in the Component Operation Guide.

  2. Obtain the sample project folder flink-dws-sink-example from src\springboot\flink-examples in the directory where the sample code is decompressed. For details, see Obtaining Sample Projects from Huawei Mirrors.
  3. Import the sample project to the IntelliJ IDEA development environment.

    1. On the menu bar of IntelliJ IDEA, choose File > Open....
    2. In the Open File or Project dialog box that is displayed, select the flink-dws-sink-example folder and click OK.

  4. Set the IntelliJ IDEA text file coding format to prevent garbled characters.

    1. On the menu bar of IntelliJ IDEA, choose File > Settings. The Settings window is displayed.
    2. In the left navigation pane, choose Editor > File Encodings. In the Project Encoding and Global Encoding areas, set the parameter to UTF-8. Click Apply and OK.
      Figure 1 Setting the IntelliJ IDEA coding format

  5. Set the JDK of the project.

    1. On the menu bar of IntelliJ IDEA, choose File > Settings. The Settings window is displayed.
    2. Choose Build, Execution, Deployment > Compiler > Java Compiler and select 8 from the Project bytecode version drop-down list box. Change the value of Target bytecode version in flink-dws-sink-example to 8.

    3. Click Apply then OK.
    4. On the menu bar of IntelliJ IDEA, choose File > Project Structure.... The Project Structure window is displayed.
    5. Choose SDKs, click the plus sign (+), and select JDK.

    6. On the Select Home Directory for JDK page that is displayed, select the JDK directory and click OK.
    7. Click Apply.
    8. Select Project, select the JDK added in SDKs from the SDK drop-down list box, and select 8 - Lambdas, type annotations etc. from the Language level drop-down list box.

    9. Click Apply.
    10. Choose Modules. On the Sources tab page, change the value of Language level to 8 - Lambdas, type annotations etc..

      On the Dependencies tab page, change the value of Module SDK to the JDK added in SDKs.

    11. Click Apply and then OK.

  6. Configure Maven.

    1. Add the configuration information such as the address of the open-source image repository to the setting.xml configuration file of the local Maven by referring to Configuring Huawei Open Source Mirrors.
    2. On the IntelliJ IDEA page, choose File > Settings > Build, Execution, Deployment > Build Tools > Maven, select Override next to User settings file, and change the value of User settings file to the directory where the settings.xml file is stored. Ensure that the directory is <Local Maven installation directory>\conf\settings.xml.
      Figure 2 Directory for storing the settings.xml file
    3. Click the drop-down list next to Maven home directory and select the Maven installation directory.
    4. Click Apply and then OK.

  7. Find the application.properties file in src\main\resources and add the following content to the file:

    • Run the GaussDB(DWS) sample
      spring.datasource.dws.url=jdbc:postgresql://IP address of the GaussDB(DWS) node:8000/postgres
      spring.datasource.dws.username=dbadmin
      spring.datasource.dws.password=Password of dbadmin
      spring.datasource.dws.driver=org.postgresql.Driver