Updated on 2024-12-16 GMT+08:00

Creating an Application Component

Function

A component is a service feature implementation of an application. It is carried by code or software packages and can be independently deployed and run in an environment.

This API is used to create an application component.

URI

POST /v3/{project_id}/cas/applications/{application_id}/components

Table 1 Path parameters

Parameter

Mandatory

Type

Description

project_id

Yes

String

Tenant's project ID. See Obtaining a Project ID.

application_id

Yes

String

Application ID. See Obtaining All Applications.

Request

Table 2 Request header parameters

Parameter

Mandatory

Type

Description

Content-Type

Yes

String

Message body type (format). Default value: application/json;charset=utf8.

X-Auth-Token

Yes

String

API calling can be authenticated using a token or AK/SK. If you use a token, this parameter is mandatory and must be set to the token. For details about how to obtain a token, see Obtaining a User Token.

Table 3 Request body parameters

Parameter

Mandatory

Type

Description

name

Yes

String

Component name.

The value contains 2 to 64 characters consisting of letters, digits, hyphens (-), or underscores (_). It starts with a letter and ends with a letter or digit.

labels

No

Array of objects

Label.

For container-deployed components, you can query a workload by label. For VM-deployed components, you can configure a label of the corresponding microservice name to use graceful startup and shutdown. See Table 4.

NOTE:

Labels can be set in CN East2.

runtime_stack

Yes

Object

Runtime. See Table 30. The value can be obtained from the response of the API for Querying a Runtime System Stack.

environment_id

No

String

Environment ID, which can be obtained from the information returned by Obtaining All Environments.

description

No

String

Component description.

The value can contain up to 128 characters.

source

Yes

Object

Source of the code or software package. See Table 31.

build

No

Object

Component building. This parameter is mandatory when the component is deployed in containers and no image is used. For details, see Table 32.

limit_cpu

No

Number

Maximum CPU limit. Unit: core.

limit_memory

No

Number

Maximum memory size. Unit: GiB.

request_cpu

No

Number

Requested CPU resources. Unit: core.

request_memory

No

Number

Requested memory. Unit: GiB.

version

Yes

String

Component version number. The value can contain up to 32 characters. It needs to meet the following rule:

^([0-9]+)(.[0-9]+){2,3}$

envs

No

Array of objects

Environment variable list. See Table 28.

replica

Yes

Integer

Number of instances.

storages

No

Array of objects

Storage. See Table 5.

deploy_strategy

No

Object

Component deployment. See Table 8.

command

No

Object

Startup command. See Table 12.

post_start

No

Object

Post-start processing. See Table 13.

pre_stop

No

Object

Pre-stop processing. See Table 13.

mesher

No

Object

Multi-language access service mesh. This parameter is mandatory when Node.js is selected for the technology stack and the CSE engine is bound. See Table 14.

timezone

No

String

Time zone where the component runs. Example: Asia/Shanghai.

jvm_opts

No

String

JVM parameter. Example: -Xms256m -Xmx1024m. If there are multiple parameters, separate them by spaces. If the parameter is left blank, the default value is used.

tomcat_opts

No

Object

Tomcat parameter. This parameter is valid when you use the Tomcat technology stack. See Table 15.

host_aliases

No

Array of objects

Host alias. See Table 16.

dns_policy

No

String

DNS policy.

  • Default: inherits the domain name resolution configuration of the node where the pod is located.
  • ClusterFirst: adds the domain name resolution configuration.
  • ClusterFirstWithHostNet: takes effect only for pods running in hostNetWork mode.
  • None: replaces the domain name resolution policy.

dns_config

No

Object

DNS configuration. See Table 17.

workload_kind

No

String

Workload type.

  • deployment
  • statefulset

security_context

No

Object

Security policy. See Table 19.

logs

No

Array of objects

Log collection. See Table 21.

custom_metric

No

Object

Custom metrics. See Table 22.

affinity

No

Array of objects

Affinity. See Table 23.

anti_affinity

No

Array of objects

Anti-affinity. See Table 23.

liveness_probe

No

Object

Component liveness probe. See Table 25.

readiness_probe

No

Object

Component service probe. See Table 25.

refer_resources

Yes

Array of objects

Associated resource. See Table 26.

external_accesses

No

Array of objects

External access. See Table 34.

Table 4 labels

Parameter

Mandatory

Type

Description

key

Yes

String

Label name.

The value contains 1 to 36 characters, including digits, letters, underscores (_), or hyphens (-).

NOTICE:

The value of Key cannot be the built-in app, casid, or version of the system. Otherwise, an error will be reported during component creation and deployment.

value

Yes

String

Label value.

The value contains 0 to 43 characters, including digits, letters, underscores (_), periods (.), or hyphens (-).

Table 5 storages

Parameter

Mandatory

Type

Description

type

Yes

String

Data storage type.

  • HostPath: host path for local disk mounting.
  • EmptyDir: temporary directory for local disk mounting.
  • ConfigMap: configuration item for local disk mounting.
  • Secret: secrets for local disk mounting.
  • PersistentVolumeClaim: cloud storage mounting.

name

Yes

String

Name of the storage disk.

parameters

Yes

Object

For details about the parameters of each data storage type, see Table 6.

mounts

Yes

Array of objects

Mount path of data storage. See Table 7.

Table 6 component_storage_parameters

Parameter

Mandatory

Type

Description

path

No

String

Host path. This parameter is applicable to the HostPath storage type. This parameter is mandatory when type is set to HostPath.

name

No

String

Name of a configuration item, secret, or PVC, which is applicable to ConfigMap, Secret, or PersistentVolumeClaim storage, respectively. This parameter is mandatory when type is set to ConfigMap, Secret, or PersistentVolumeClaim.

default_mode

No

Integer

Mounting permission. The value is in decimal format. Example: 384. This parameter is applicable to ConfigMap and secret storage.

medium

No

String

This parameter is applicable to EmptyDir storage. If it is not specified, the default disk medium is used. If it is set to memory, memory storage is enabled.

Table 7 mounts

Parameter

Mandatory

Type

Description

path

Yes

String

Application path to which the data storage is mounted. Example: /tmp.

sub_path

Yes

String

Subpath of the mount path.

read_only

Yes

Boolean

Read-only or not.

  • true: read-only.
  • false: read and write. You can modify data volumes in the application path. To prevent data loss, newly written data will not be migrated during application migration.
Table 8 deploy_strategy

Parameter

Mandatory

Type

Description

type

Yes

String

Deployment type.

  • OneBatchRelease: single-batch upgrade.
  • RollingRelease: rolling deployment and upgrade.
  • GrayRelease: dark launch upgrade.

rolling_release

No

Object

Rolling deployment parameter, which is mandatory when type is set to RollingRelease. For details, see Table 9.

gray_release

No

Object

Dark launch upgrade parameter, which is mandatory when type is set to GrayRelease. For details, see Table 10.

Table 9 rolling_release

Parameter

Mandatory

Type

Description

batches

Yes

Integer

Deployment batches.

Table 10 gray_release

Parameter

Mandatory

Type

Description

type

Yes

String

Dark launch policy.

  • weight: dark launch by traffic.
  • content: dark launch by content.

first_batch_weight

Yes

Integer

Proportion of first-batch dark launch traffic. This parameter is mandatory when type is set to weight.

first_batch_replica

Yes

Integer

Number of first-batch dark launch instances. This parameter is mandatory when type is set to weight.

remaining_batch

Yes

Integer

Number of batches for remaining instance deployment. After the first batch is completed, the remaining instances will be deployed in specified batches.

Example: If there are 5 instances remaining to be deployed in 3 batches, these 5 instances will be upgraded based on 2:2:1.

This parameter is mandatory when type is set to weight.

deployment_mode

No

Integer

Deployment mode.

  • 1: The upstream is a microservice gateway.
  • 3: The upstream is a microservice.
  • 4: The upstream is a load balancer.

replica_surge_mode

No

String

Mode of adding a dark launch instance. This parameter is mandatory when type is set to content.

  • mirror: blue-green
  • extra: canary (increase, then decrease)
  • no_surge: canary (decrease, then increase)

rule_match_mode

No

String

Effective mode of a dark launch rule. This parameter is mandatory when type is set to content.

  • all: All conditions are met.
  • any: Any condition is met.

rules

No

Object

Dark launch rule. See Table 11. This parameter is mandatory when type is set to content.

Table 11 gray_rules

Parameter

Mandatory

Type

Description

type

Yes

String

Match type.

Currently, only header is supported.

key

Yes

String

Parameter name.

value

Yes

String

Condition value.

condition

Yes

String

Condition type.

  • equal
  • match
  • in: enumeration.
Table 12 command

Parameter

Mandatory

Type

Description

command

No

Array of String

Command for controlling container running.

args

No

Array of String

Parameter for controlling container running. Example: -port=8080. If there are multiple parameters, separate them by line breaks.

Table 13 component_lifecycle

Parameter

Mandatory

Type

Description

type

Yes

String

Processing method.

  • http
  • command

scheme

No

String

HTTP request type, which can be HTTP or HTTPS.

This parameter is valid only when type is set to http.

host

No

String

Custom IP address. If this parameter is left blank, the pod IP address is used.

This parameter is valid only when type is set to http.

port

No

Integer

Port number. This parameter is valid only when type is set to http.

path

No

String

Request path. This parameter is valid only when type is set to http.

command

No

Array of String

Command list. This parameter is valid only when type is set to command.

Table 14 mesher

Parameter

Mandatory

Type

Description

port

Yes

Integer

Process listening port.

Table 15 tomcat_opt

Parameter

Mandatory

Type

Description

server_xml

Yes

String

  1. Listening port in the server.xml file will take effect even if it has been configured in public network access.
  2. The custom Tomcat configuration may conflict with the existing port. Check whether the custom port is occupied.
Table 16 host_aliases

Parameter

Mandatory

Type

Description

ip

Yes

String

IP address.

hostnames

Yes

Array of String

Host alias.

Table 17 dns_config

Parameter

Mandatory

Type

Description

nameservers

No

Array of String

IP address list of the DNS server of the pod.

searches

No

Array of String

(Optional) List of DNS search domains used to search for host names in the pod.

options

No

Array of objects

(Optional) List of objects. Each object may have a name (mandatory) and a value (optional). The contents of the objects here will be merged into the options generated from the specified DNS policy. Duplicate entries will be deleted. See Table 18.

Table 18 options

Parameter

Mandatory

Type

Description

name

Yes

String

Operation name.

value

No

String

Operation value.

Table 19 security_context

Parameter

Mandatory

Type

Description

run_as_user

No

Integer

User for running containers. Example: To run containers as user root, set the user ID to 0.

run_as_group

No

Integer

Owner group specified for running container processes.

capabilities

No

Object

Capability set. See Table 20.

Table 20 capabilities

Parameter

Mandatory

Type

Description

add

No

Array of String

Grant the Linux permission to the running user.

drop

No

Array of String

Remove the Linux permission of the running user.

Table 21 logs

Parameter

Mandatory

Type

Description

log_path

Yes

String

Container log path.

rotate

Yes

String

Interval for dumping logs.

host_path

Yes

String

Mounted host path.

host_extend_path

Yes

String

Host extension path. By extending the host path, you can distinguish mounting from different containers in the same host path.

  • None: the extended path is not used.
  • PodUID: extend the host path based on the pod ID.
  • PodName: extend the host path based on the pod name.
  • PodUID/ContainerName: extend the host path based on the pod ID and container name.
  • PodName/ContainerName: extend the host path based on the pod name and container name.
Table 22 custom_metric

Parameter

Mandatory

Type

Description

path

Yes

String

Collection path. Example: /metrics.

port

Yes

Integer

Collection port. Example: 9090.

dimensions

Yes

String

Monitoring dimension. Example: cpu_usage,mem_usage.

Table 23 component_affinity

Parameter

Mandatory

Type

Description

condition

Yes

String

Whether the condition must be met.

  • required: The condition must be met.
  • preferred: The condition is met as much as possible.

kind

Yes

String

Affinity type.

  • node
  • pod

weight

No

Integer

Affinity weight. Value range: 0–100.

match_expressions

Yes

Array of objects

Match condition. See Table 24.

Table 24 match_expressions

Parameter

Mandatory

Type

Description

key

Yes

String

Key of the match tag.

operation

Yes

String

Match condition.

value

Yes

String

Value of the match tag.

Table 25 component_probe

Parameter

Mandatory

Type

Description

type

Yes

String

Type. Value: http, tcp, or command.

delay

Yes

Integer

Interval between the startup and detection.

timeout

Yes

Integer

Detection timeout interval.

scheme

No

String

Request type. Value: HTTP or HTTPS. This parameter is valid only when type is set to http.

host

No

String

Custom IP address. If this parameter is left blank, the pod IP address is used. This parameter is valid only when type is set to http.

port

No

Integer

Port number. This parameter is valid only when type is set to http or tcp.

path

No

String

Request path. This parameter is valid only when type is set to http.

command

No

Array of String

Command list. This parameter is valid only when type is set to command.

Table 26 refer_resources

Parameter

Mandatory

Type

Description

id

Yes

String

Resource ID.

type

Yes

String

Resource type.

  • vpc
  • eip
  • elb
  • cce
  • ecs
  • as
  • cse
  • dcs
  • rds

parameters

No

Object

Resource parameters. See Table 27.

Table 27 refer_resource_parameter

Parameter

Mandatory

Type

Description

namespace

No

String

Namespace.

Table 28 env

Parameter

Mandatory

Type

Description

name

Yes

String

Variable name.

value

No

String

Variable value.

value_from

No

Object

Variable reference. See Table 29.

Table 29 value_from

Parameter

Mandatory

Type

Description

reference_type

Yes

String

Reference type.

  • configMapKey
  • secretKey

name

Yes

String

Name of the configuration item or secret.

key

No

String

Key of the configuration item or secret.

optional

No

Boolean

Whether the key of the configuration item or secret is mandatory.

Table 30 runtime_stack

Parameter

Mandatory

Type

Description

name

Yes

String

Technology stack name.

type

Yes

String

Technology stack type. Value: Java, Tomcat, Nodejs, Php, Docker, or Python.

When deploy_mode is set to virtualmachine, only Java, Tomcat, and Node.js are supported. When deploy_mode is set to container, all of the preceding types are supported.

version

Yes

String

Technology stack version.

deploy_mode

Yes

String

Deployment mode.

  • container
  • virtualmachine
Table 31 source

Parameter

Mandatory

Type

Description

kind

Yes

String

Component source kind.

  • code
  • package
  • image

version

No

String

Version number.

url

No

String

Package address. This parameter is mandatory when kind is set to package or image.

storage

No

String

Storage mode. Value: swr (image), swr(software repository), codearts, or obs. This parameter is mandatory when kind is set to package or image.

auth

No

String

Authentication mode. Value: iam or none. Default value: iam.

repo_auth

No

String

Authorization name, which can be obtained from the authorization list. For details, see Obtaining a Git Repository Authorization List.

repo_namespace

No

String

Namespace of the code repository.

repo_ref

No

String

Code branch or tag. Default value: master.

repo_type

No

String

Code repository type. Value: GitHub, BitBucket, or GitLab.

web_url

No

String

Code redirection URL. Example: https://github.com/example/demo.git.

repo_url

No

String

Code repository URL. Example: https://github.com/example/demo.git.

commit_id

No

String

In the code repository, commit ID is the unique identifier of each commit and is used to identify and reference a commit.

The value contains 8 to 40 characters and starts with a lowercase letter or digit.

Table 32 build

Parameter

Mandatory

Type

Description

parameters

No

Map<String, Object>

This parameter is provided only when no ID is available during build creation. See Table 33.

Table 33 parameters

Parameter

Mandatory

Type

Description

build_cmd

No

String

Compilation command. By default:

  1. When build.sh exists in the root directory, the command is ./build.sh.
  2. When build.sh does not exist in the root directory, the command varies depending on the OS. Example:
    • Java and Tomcat: mvn clean package
    • Node.js: npm build

dockerfile_path

No

String

Address of the Docker file. By default, the Docker file is in the root directory (./).

artifact_namespace

No

String

Build archive organization. Default value: cas_{project_id}.

cluster_id

Yes

String

ID of the cluster to be built.

node_label_selector

No

Map<String, String>

key: label key. value: label value.

environment_id

No

String

Environment ID. See Obtaining All Environments.

Table 34 external_accesses

Parameter

Mandatory

Type

Description

protocol

No

String

External access type. Value: http or https.

address

No

String

External access address.

forward_port

No

Integer

External access port.

Response

Table 35 Response parameters

Parameter

Type

Description

job_id

String

Job ID.

component_id

String

Application component ID.

Example Request

  • Scenario 1: Create a component in the CCE container environment
    Create a component named mycomponent. The technology stack is Java 1.2.0. The component source is the weather-1.0.0.jar package stored in the bucket00001 bucket of OBS. The resource used for deployment is the CCE whose ID is fd92bfab-73b3-11ee-90f0-0255ac1001b3.
    {
        "name": "mycomponent",
        "description": "",
        "labels": [
            {
                "key": "com-key",
                "value": "com-value"
            }
        ],
        "version": "2023.1102.17105",
        "environment_id": "b489f7b4-2539-45a1-ba71-4728961434ca",
        "runtime_stack": {
            "name": "OpenJDK8",
            "version": "1.2.0",
            "type": "Java",
            "deploy_mode": "container"
        },
        "source": {
            "kind": "package",
            "url": "obs://bucket0001/weather-1.0.0.jar",
            "version": "",
            "storage": "obs"
        },
        "tomcat_opts": {
            "server_xml": ""
        },
        "refer_resources": [
            {
                "id": "fd92bfab-73b3-11ee-90f0-0255ac1001b3",
                "type": "cce",
            }
        ],
        "replica": 1,
        "limit_cpu": 0.25,
        "limit_memory": 0.5,
        "request_cpu": 0.25,
        "request_memory": 0.5
    }
  • Scenario 2: Create a component in the ECS VM environment

    Create a component named mycomponent. The technology stack is Java 1.2.0. The component source is the weather-1.0.0.jar package stored in the bucket00001 bucket of OBS. The resource used for deployment is the ECS whose ID is 67835bb3-1235-4cc9-be71-becbb2b4ca0d.

    {
        "name": "mycomponent",
        "description": "",
        "labels": [
            {
                "key": "com-key",
                "value": "com-value"
            }
        ],
        "version": "2023.1102.17540",
        "environment_id": "9a075df5-104f-4e21-9dbf-ffc3572effdf",
        "runtime_stack": {
            "name": "OpenJDK8",
            "version": "1.2.0",
            "type": "Java",
            "deploy_mode": "virtualmachine"
        },
        "source": {
            "kind": "package",
            "url": "obs://bucket0001/weather-1.0.0.jar",
            "version": "",
            "storage": "obs"
        },
        "tomcat_opts": {
            "server_xml": ""
        },
        "refer_resources": [
            {
                "id": "23598aa9-7a6b-43c7-a53a-39ca5e7290fb",
                "type": "ecs"
            }
        ],
        "replica": 1,
        "external_accesses": [
            {
                "protocol": "http",
                "address": "192.168.0.169",
                "forward_port": 80
            }
        ]
    }

Example Response

{
    "job_id": "JOB8be53b2a-af9a-4e2b-8505-096688a52237",
    "component_id": "b8702b0f-94d3-4822-98a1-56815632a0a0"
}

Status Code

Status Code

Description

200

OK

400

Bad Request

404

Not Found

500

Internal Server Error

Error Code

The error code format is SVCSTG.00100.[Error_ID], for example, SVCSTG.00100400. For details, see ServiceStage Error Codes.