Updated on 2024-11-15 GMT+08:00

Building a Program

Download the source code and program package (including function dependencies) to create a function from scratch for converting DIS stream data formats.

Creating a Project

This example uses a Java function to convert the format of DIS stream data. For details about function development, see Developing Functions in Java. The service code is not described.

Download the sample source code package fss_examples_dis_cloudtable_src.zip, decompress the file, and import it to Eclipse, as shown in Figure 1.

Figure 1 Sample code

In the sample code, modify proID (project ID), clusID (cluster ID), and hostName (CloudTable endpoint), and save the modification.

To obtain the project ID, perform the following steps:

  1. Under the current login account in the upper right corner, choose My Credentials, as shown in Figure 2.
  2. Obtain the project ID in the project list, as shown in Figure 3.
Figure 2 My Credentials
Figure 3 Project ID

To obtain the cluster ID, perform the following steps:

  1. Log in to the CloudTable console.
  2. In the navigation pane, choose Cluster Management. Click cluster cloudtable-dis created in Creating a Cluster.
  3. On the cloudtable-dis page that is displayed, find the cluster ID, as shown in Figure 4.
Figure 4 Cluster ID

When creating a function on the FunctionGraph console, set a handler in the format of [package name].[file name].[function name], for example, com.huawei.cff.TableTester.MyHandler for the preceding code.

Packaging the Code

Use Eclipse to package the code into a JAR file named Table Tester.jar according to the following figures.

Figure 5 Exporting the code
Figure 6 Selecting a file type
Figure 7 Publishing the code file

Package the function dependencies by performing the following steps:

  1. Download program package fss_examples_dis_cloudtable.zip, and decompress it, as shown in Figure 8.
  2. Use Table Tester.jar to replace DIS Test.jar, as shown in Figure 9.
  3. Package all of the files into disdemo.zip, as shown in Figure 10.
Figure 8 File directory before replacement
Figure 9 File directory after replacement
Figure 10 Packaging the files in ZIP format

Creating a Function

When creating a function, specify an agency to delegate FunctionGraph to access DIS and CloudTable resources.

  1. Log in to the FunctionGraph console, and choose Functions > Function List in the navigation pane.
  2. Click Create Function.
  3. Select Create from scratch, set the function information, and click Create Function.

    • For Function Type, select Event Function.
    • For Function Name: Enter a function name, for example, DISDemo.
    • For Agency, select DISDemo created in Preparation.
    • For Runtime, select Java 8.

  4. On the function details page, configure the following information:

    • Choose Configuration > Basic Settings, change the handler to com.huawei.cff.TableTester.MyHandler, and click Save.
    • On the Code tab, choose Upload > Local ZIP, upload the disdemo.zip package generated in Packaging the Code.

Modifying Function Configurations

After the function is created, the default memory is 128 MB, and the default timeout is 3s, which are insufficient for the data processing. Perform the following steps to modify the configurations.

  1. On the DISDemo details page, choose Configuration > Basic Settings, and modify the following information as required:

    • For Memory, select 512.
    • For Execution Timeout, enter 15.
    • Keep other parameters unchanged.

  2. Click Save.