Updated on 2025-10-22 GMT+08:00

Creating a Component

Function

This API is used to create a component.

URI

POST /v1/{project_id}/cae/applications/{application_id}/components

Table 1 Path Parameters

Parameter

Mandatory

Type

Description

project_id

Yes

String

Project ID. See Obtaining a Project ID.

application_id

Yes

String

Application ID.

Request Parameters

Table 2 Request header parameters

Parameter

Mandatory

Type

Description

X-Auth-Token

Yes

String

User token.

  • Obtain the token. For details, see "Obtaining a User Token" in Identity and Access Management API Reference (https://support.huaweicloud.com/intl/en-us/api-iam/iam_30_0001.html).

  • The value of X-Subject-Token in the response header is the token value.

X-Enterprise-Project-ID

No

String

Enterprise project ID.

  • When an environment is created, it will be bound with an enterprise project ID.

  • Enter 0 or up to 36 characters in UUID format with hyphens (-).

  • If this parameter is not specified or set to 0, resources in the default enterprise project are queried.

NOTE:
For details about how to obtain enterprise project IDs and enterprise project features, see Enterprise Management User Guide.

X-Environment-ID

Yes

String

Environment ID.

Table 3 Request body parameters

Parameter

Mandatory

Type

Description

api_version

Yes

String

API version. Fixed value: v1.

kind

Yes

String

API type. Fixed value: Component.

metadata

Yes

metadata object

Request data.

spec

Yes

spec object

Component specifications.

Table 4 metadata

Parameter

Mandatory

Type

Description

name

Yes

String

Component name.

annotations

Yes

Map<String,String>

Additional parameter for creating a component. Only version is supported. This parameter is mandatory.

Table 5 spec

Parameter

Mandatory

Type

Description

runtime

Yes

String

Language or runtime.

replica

Yes

Integer

Number of instances.

build

No

Build object

Build information.

source

Yes

Source object

Source information.

resource_limit

Yes

ResourceLimit object

Instance specifications

image_url

No

String

Image address.

Table 6 Build

Parameter

Mandatory

Type

Description

archive

Yes

Archive object

Place where build products are archived for management.

parameters

Yes

Parameters object

Table 7 Archive

Parameter

Mandatory

Type

Description

artifact_namespace

No

String

SWR organization for product management.

Table 8 parameters

Parameter

Mandatory

Type

Description

{User defined key}

No

Map<String,String>

Additional parameters. Options:

  • base_image: base image address.

  • build_cmd: custom build command.

  • dockerfile_path: custom dockerfile path.

  • dockerfile_content: custom dockerfile content.

  • artifact_name: product to be run after the Java multi-module build. The value ends with .jar.

Table 9 Source

Parameter

Mandatory

Type

Description

code

No

Repo object

Source code repository information.

type

Yes

String

Source type.

sub_type

No

String

Source subtype.

  • If type is code, sub_type indicates a code repository, such as DevCloud (CodeArts), GitLab, GitHub, Gitee, or Bitbucket.

  • If type is softwarePackage, sub_type indicates a software package repository, such as BinObs or BinDevCloud (CodeArts Release Repo).

url

Yes

String

URL.

  • If type is image, url indicates an image address.

  • If type is code, url indicates a Git address.

  • If type is softwarePackage, url indicates a software package address.

Table 10 Repo

Parameter

Mandatory

Type

Description

auth_name

No

String

Authorization name.

branch

No

String

Branch.

namespace

No

String

Namespace, which must be Base64-encoded.

Table 11 ResourceLimit

Parameter

Mandatory

Type

Description

cpu_limit

Yes

String

CPU limit.

memory_limit

Yes

String

Memory limit.

Response Parameters

Status code: 200

Table 12 Response body parameters

Parameter

Type

Description

api_version

String

API version. Fixed value: v1.

kind

String

API type. Fixed value: Component.

metadata

MetadataResponse object

Response data.

spec

CreateComponentSpec object

Component specifications.

Table 13 MetadataResponse

Parameter

Type

Description

id

String

Component ID.

name

String

Component name.

annotations

Map<String,String>

Additional attributes of the component. Options:

  • log_group_id: ID of an LTS log group.

  • log_stream_id: ID of an LTS log stream.

  • version: component version.

created_at

String

Creation time.

updated_at

String

Update time.

Table 14 CreateComponentSpec

Parameter

Type

Description

runtime

String

Language or runtime.

env_id

String

Environment ID.

replica

Integer

Number of instances.

source

Source object

Source information.

build

Build object

Build information.

resource_limit

ResourceLimit object

Instance specifications

available_replica

Integer

Number of available instances.

status

String

Component status.

  • created: not deployed.

  • running

  • paused

  • notReady

Table 15 Source

Parameter

Type

Description

code

Repo object

Source code repository information.

type

String

Source type.

sub_type

String

Source subtype.

  • If type is code, sub_type indicates a code repository, such as DevCloud (CodeArts), GitLab, GitHub, Gitee, or Bitbucket.

  • If type is softwarePackage, sub_type indicates a software package repository, such as BinObs or BinDevCloud (CodeArts Release Repo).

url

String

URL.

  • If type is image, url indicates an image address.

  • If type is code, url indicates a Git address.

  • If type is softwarePackage, url indicates a software package address.

Table 16 Repo

Parameter

Type

Description

auth_name

String

Authorization name.

branch

String

Branch.

namespace

String

Namespace, which must be Base64-encoded.

Table 17 Build

Parameter

Type

Description

archive

Archive object

Place where build products are archived for management.

parameters

Parameters object

Table 18 Archive

Parameter

Type

Description

artifact_namespace

String

SWR organization for product management.

Table 19 parameters

Parameter

Type

Description

{User defined key}

Map<String,String>

Additional parameters. Options:

  • base_image: base image address.

  • build_cmd: custom build command.

  • dockerfile_path: custom dockerfile path.

  • dockerfile_content: custom dockerfile content.

  • artifact_name: product to be run after the Java multi-module build. The value ends with .jar.

Table 20 ResourceLimit

Parameter

Type

Description

cpu_limit

String

CPU limit.

memory_limit

String

Memory limit.

Example Requests

  • Create a component based on a source code repository: Set the component name to test-code, version to 1.0.0, and runtime to Java8, and select source code repository GitLab.

    POST https://{endpoint}/v1/{project_id}/cae/applications/{application_id}/components
    
    {
      "api_version" : "v1",
      "kind" : "Component",
      "metadata" : {
        "name" : "test-code",
        "annotations" : {
          "version" : "1.0.0"
        }
      },
      "spec" : {
        "runtime" : "Java8",
        "build" : {
          "archive" : {
            "artifact_namespace" : "xxx"
          },
          "parameters" : {
            "base_image" : "openjdk:8u181-jdk-alpine",
            "dockerfile_path" : "./Dockerfile"
          }
        },
        "source" : {
          "type" : "code",
          "sub_type" : "GitLab",
          "url" : "https://xxx:8090/xxx/cae-frontend.git",
          "code" : {
            "branch" : "master",
            "auth_name" : "gitlab-xxx",
            "namespace" : "em1n"
          }
        },
        "resource_limit" : {
          "cpu_limit" : "500m",
          "memory_limit" : "1Gi"
        },
        "replica" : 1
      }
    }
  • Create a component based on an image: Set the component name to test-image, version to 1.0.0, and runtime to Docker, and select image nginx.

    POST https://{endpoint}/v1/{project_id}/cae/applications/{application_id}/components
    
    {
      "api_version" : "v1",
      "kind" : "Component",
      "metadata" : {
        "name" : "test-image",
        "annotations" : {
          "version" : "1.0.0"
        }
      },
      "spec" : {
        "runtime" : "Docker",
        "source" : {
          "type" : "image",
          "url" : "nginx:stable-alpine-perl"
        },
        "resource_limit" : {
          "cpu_limit" : "500m",
          "memory_limit" : "1Gi"
        },
        "replica" : 1
      }
    }
  • Create a component based on a software package: Set the component name to test-jar, version to 1.0.0, and runtime to Java8, and select software package forecast-1.0.0.jar.

    POST https://{endpoint}/v1/{project_id}/cae/applications/{application_id}/components
    
    {
      "api_version" : "v1",
      "kind" : "Component",
      "metadata" : {
        "name" : "test-jar",
        "annotations" : {
          "version" : "1.0.0"
        }
      },
      "spec" : {
        "runtime" : "Java8",
        "build" : {
          "archive" : {
            "artifact_namespace" : "xxx"
          },
          "parameters" : {
            "base_image" : "openjdk:8u181-jdk-alpine",
            "dockerfile_content" : "FROM java:8 \\nADD forecast-1.0.0.jar \\nEXPOSE 8080 \\nENTRYPOINT [\"java\",\"-jar\",\"forecast-1.0.0.jar\"]"
          }
        },
        "source" : {
          "type" : "softwarePackage",
          "sub_type" : "BinObs",
          "url" : "https://xxx.obs.region.xxx.huawei.com/xxx/forecast-1.0.0.jar"
        },
        "resource_limit" : {
          "cpu_limit" : "500m",
          "memory_limit" : "1Gi"
        },
        "replica" : 1
      }
    }

Example Responses

Status code: 200

OK

{
  "api_version": "v1",
  "kind": "Component",
  "metadata": {
    "id": "cac09548-047f-46c4-abbd-a6a652305565",
    "name": "test-code",
    "annotations": {
      "log_group_id": "5b13213a-84f8-4b72-8ca5-530e15cc1402",
      "log_stream_id": "6ddf6c71-4767-46db-98a2-fe5fb301b366",
      "version": "1.0.0"
    },
    "created_at": "2023-02-13T02:38:22.689607114Z",
    "updated_at": "2023-02-13T02:38:22.689607114Z"
  },
  "spec": {
    "runtime": "Java8",
    "env_id": "9819b3f5-dd08-44ff-ba88-eb38e435594c",
    "replica": 1,
    "source": {
      "type": "code",
      "sub_type": "GitLab",
      "url": "http://xxx@cpe.gitlab.com:8090/xxx/cae-backend.git",
      "code": {
        "branch": "master",
        "auth_name": "gitlab-xxx",
        "namespace": "em1n"
      }
    },
    "build": {
      "archive": {
        "artifact_namespace": "xxx"
      },
      "parameters": {
        "base_image": "openjdk:8u181-jdk-alpine"
        "dockerfile_path": "./Dockerfile"
      }
    },
    "resource_limit": {
      "cpu_limit": "500m",
      "memory_limit": "1Gi"
    },
    "available_replica": 0,
    "status": "created"
  }
}

Status Codes

Status Code

Description

200

OK

Error Codes

See Error Codes.