Updated on 2025-09-07 GMT+08:00

Resource Function

This section describes resource functions, including their syntax, parameters, and usage examples.

Function List

You must configure the advanced settings to obtain the target data when using the following resource functions.

Function

Description

res_local

Obtains the key information from the advanced settings of the current data processing task.

This function can be used together with other functions.

res_obs_file

Obtains files in a specified bucket from OBS and periodically updates data.

This function can be used together with other functions.

res_local

Use the res_local function to obtain the key information from the advanced settings of the current data processing task. This function can be used together with other functions.

  • Function format
    res_local(param, default=None, type="auto")
  • Parameter description

    Parameter

    Type

    Mandatory

    Description

    param

    String

    Yes

    Corresponds to Key in the advanced parameter configuration.

    default

    String

    No

    If the value of param does not exist, the value of this parameter is returned. The default value is None.

    type

    String

    No

    Data format of the output.

    • auto (default): The original value is converted to the JSON format. If the conversion fails, the original value is returned.
    • JSON: The original value is converted to the JSON format. If the conversion fails, the value of default is returned.
    • raw: The original value is returned.
  • Returned result

    JSON data or the original value.

    Table 1 Success examples

    Original Value

    Return Value

    Return Value Type

    1

    1

    Integer

    1.2

    1.2

    Floating-point number

    true

    true

    Boolean

    false

    false

    Boolean

    "123"

    123

    String

    null

    None

    None

    ["v1", "v2", "v3"]

    ["v1", "v2", "v3"]

    List

    ["v1", 3, 4.0]

    ["v1", 3, 4.0]

    List

    {"v1": 100, "v2": "good"}

    {"v1": 100, "v2": "good"}

    Dictionary

    {"v1": {"v11": 100, "v2": 200}, "v3": "good"}

    {"v1": {"v11": 100, "v2": 200}, "v3": "good"}

    Dictionary

    Table 2 Failure examples

    Original Value

    Return Value

    Description

    (1,2,3)

    "(1,2,3)"

    Tuples are not supported. Use a list.

    true

    "true"

    Only true and false (lowercase) are supported.

    {1: 2, 3: 4}

    "{1: 2, 3: 4}"

    The dictionary key can only be a string.

  • Function example

    Obtain information from the key parameter in advanced settings and assign the information to local. When adding a Key, set the key to endpoint and value to hangzhou.

    • Test data
      {
         "content": "1"
      }
    • Processing rule
      e_set("local", res_local('endpoint'))
    • Processing result
      content: 1
      local: hangzhou

res_obs_file

Use the res_obs_file function to obtain file content from the OBS bucket and periodically update the content. This function can be used together with other functions.

It is recommended that the LTS project and OBS bucket be in the same region and the Huawei Cloud intranet be used to obtain data.

  • Function format
    res_obs_file(endpoint,bucket,file)
  • Parameter description

    Parameter

    Type

    Mandatory

    Description

    endpoint

    String

    Yes

    Address of the file stored in OBS. Example: obs.cn-north-4.huawei.com

    bucket

    String

    Yes

    Bucket name used in OBS, for example, lts-dsl.

    file

    String

    Yes

    Path of the target OBS file. For example, test/data.txt. It cannot start with a slash (/).

  • Returned result

    File data in byte stream or text format.

  • Function example
    1. Example 1: Pull data in JSON format from OBS.
      • JSON content
        {
          "users": [
            {
                "name": "user1",
                "login_historys": [ 
                 { 
                   "date": "2019-10-10 0:0:0",
                    "login_ip": "203.0.113.10" 
                 }, 
                 { 
                   "date": "2019-10-10 1:0:0",
                    "login_ip": "203.0.113.10"
                  }
                ]
            },
            {   
             "name": "user2",
                "login_historys": [ 
                 { 
                   "date": "2019-10-11 0:0:0", 
                   "login_ip": "203.0.113.20" 
                 },
                  { 
                   "date": "2019-10-11 1:0:0", 
                   "login_ip": "203.0.113.30"
                  },
                  { 
                   "date": "2019-10-11 1:1:0", 
                   "login_ip": "203.0.113.50" 
                 } 
               ] 
           }
          ]
        }
      • Test data
        {
          "content":"123"
        }
      • Processing rule
        e_set(
            "json_parse", 
           json_parse( 
               res_obs_file(
                    "https://obs.test.ulanqab.huawei.com",
                    "lts-dsl",            
                    "als_dsl.json"
                )
             ),
         )
      • Processing result
        content: 123
            json_parse:
          '{
          "users": [
            {
                "name": "user1",
                "login_historys": [ 
                 {
                    "date": "2019-10-10 0:0:0",
                    "login_ip": "203.0.113.10" 
                 },
                  {
                    "date": "2019-10-10 1:0:0",
                    "login_ip": "203.0.113.10"
                  }
                ]
            },
            {
                "name": "user2",
                "login_historys": [ 
                 {
                    "date": "2019-10-11 0:0:0",
                    "login_ip": "203.0.113.20"
                  },
                  {
                    "date": "2019-10-11 1:0:0",
                    "login_ip": "203.0.113.30" 
                 }, 
                 { 
                   "date": "2019-10-11 1:1:0", 
                   "login_ip": "203.0.113.50" 
                 }
                ]
            }
          ]
        }'
    2. Example 2: Pull text content from OBS.
      • Text content
        Test bytes
      • Test data
        {
          "content": "123"
        }
      • Processing rule
        e_set(
            "test_txt", 
           res_obs_file(
                    "https://obs.test.ulanqab.huawei.com", 
                    "lts-dsl",
                    "als_dsl.json" 
               )
         )
      • Processing result
        content: 123
        test_txt: Test bytes