Building a Program

Download and use the source code and program package (including function dependencies) provided in this example for format conversion of DIS stream data.

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, change the proID (project ID) and clusID (cluster ID), and save the changes.

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

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. Set the function information, as shown in Figure 11.

    For Template, select Create from scratch.

    For Function Name, enter DISDemo.

    For App, select default.

    For Agency, select DISDemo created in Preparation.

    For Runtime, select Java 8.

    For Handler, enter com.huawei.cff.TableTester.MyHandler.

    For Code Entry Mode, select Upload ZIP file.

    Upload code package disdemo.zip created in Packaging the Code.

    Figure 11 Creating a function

  4. Click Create Function.

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 page, click the Configuration tab and modify the configuration information, as shown in Figure 12.

    For Memory, select 512.

    For Timeout, enter 15.

    Keep other parameters unchanged.

    Figure 12 Function configurations

  2. Click Save.