Updated on 2023-06-26 GMT+08:00

Creating an Application Component

Function

A component implements a service feature of an application. It is in the form of code or software packages and can be deployed independently.

This API is used to create an application component.

URI

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

Table 1 Path parameters

Parameter

Type

Mandatory

Description

project_id

String

Yes

Tenant's project ID.

application_id

String

Yes

Application ID.

Request

Table 2 Request parameters

Parameter

Type

Mandatory

Description

name

String

Yes

Application component name.

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

runtime

String

Yes

Runtime. The value can be obtained from type_name returned by the API in Obtaining All Supported Runtimes of Application Components.

category

String

Yes

Application component type. Example: Webapp, MicroService, or Common.

sub_category

String

No

Application component sub-type.

Webapp sub-types include Web.

MicroService sub-types include Java Chassis, Go Chassis, Mesher, Spring Cloud, and Dubbo.

Common sub-type can be empty.

description

String

No

Description.

The value can contain up to 128 characters.

source

Object

No

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

build

Object

No

Component build. See Table 7.

Table 3 source parameters

Parameter

Type

Mandatory

Description

kind

String

No

Type. Option: source code or artifact software package.

spec

Object

No

For details about the source code, see Table 4. For details about the artifact software package, see Table 5.

Table 4 code spec parameters

Parameter

Type

Mandatory

Description

repo_type

String

Yes

Code repository. Value: GitHub, GitLab, Gitee, or Bitbucket.

repo_url

String

Yes

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

repo_ref

String

No

Code branch or tag. Default value: master.

repo_auth

String

Yes

Authorization name, which can be obtained from the authorization list.

Table 5 artifact spec parameters

Parameter

Type

Mandatory

Description

storage

String

Yes

Storage mode. Value: obs.

type

String

Yes

Type. Value: package.

url

String

Yes

Software package address.

auth

String

No

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

properties

Object

No

Other attributes of the software package. You need to add these attributes only when you set storage to obs. See Table 6.

Table 6 artifact spec properties parameters

Parameter

Type

Mandatory

Description

endpoint

String

No

OBS endpoint address. Example: https://obs.region_id.external_domain_name.com.

bucket

String

No

Name of the OBS bucket where the software package is stored.

key

String

No

Object in the OBS bucket, which is usually the name of the software package. If there is a folder, the path of the folder must be added. Example: test.jar or demo/test.jar.

Table 7 build parameters

Parameter

Type

Mandatory

Description

parameters

Map<String, Object>

No

See Table 8.

Table 8 parameters description

Parameter

Type

Mandatory

Description

build_cmd

String

No

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

    Nodejs: npm build

dockerfile_path

String

No

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

artifact_namespace

String

No

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

cluster_id

String

No

ID of the cluster to be built.

node_label_selector

Map<String, String>

No

key indicates the key of the tag, and value indicates the value of the tag.

Response

Table 9 Response parameters

Parameter

Type

Description

id

String

Application component ID.

name

String

Application component name.

status

Integer

Value: 0 or 1.

0: Normal.

1: Being deleted.

runtime

String

Runtime.

category

String

Application component type. Example: Webapp, MicroService, or Common.

sub_category

String

Application component sub-type.

Webapp sub-types include Web.

MicroService sub-types include Java Chassis, Go Chassis, Mesher, Spring Cloud, and Dubbo.

Common sub-type can be empty.

description

String

Description.

project_id

String

Project ID.

application_id

String

Application ID.

source

Object

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

build

Object

Build. See Table 14.

pipeline_ids

ID list

Pipeline ID list. A maximum of 10 pipeline IDs are supported.

create_time

Integer

Creation time.

update_time

Integer

Update time.

creator

String

Creator.

Table 10 source parameters

Parameter

Type

Description

kind

String

Type. Option: source code or artifact software package.

spec

Object

For details about the source code, see Table 11. For details about the artifact software package, see Table 12.

Table 11 code spec parameters

Parameter

Type

Description

repo_type

String

Code repository. Value: GitHub, GitLab, Gitee, or Bitbucket.

repo_url

String

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

repo_ref

String

Code branch or tag. Default value: master.

repo_auth

String

Authorization name, which can be obtained from the authorization list.

Table 12 artifact spec parameters

Parameter

Type

Description

storage

String

Storage mode.

type

String

Type.

url

String

Address of the software package or source code.

auth

String

Authentication mode.

properties

Object

Other attributes of the software package. You need to add these attributes only when you set storage to obs. See Table 13.

Table 13 artifact spec properties parameters

Parameter

Type

Mandatory

Description

endpoint

String

No

OBS endpoint address. Example: https://obs.region_id.external_domain_name.com.

bucket

String

No

Name of the OBS bucket where the software package is stored.

key

String

No

Object in the OBS bucket, which is usually the name of the software package. If there is a folder, the path of the folder must be added. Example: test.jar or demo/test.jar.

Table 14 build parameters

Parameter

Type

Description

ID

String

Type.

parameters

Map<String, Object>

See Table 15.

Table 15 parameters description

Parameter

Type

Description

build_cmd

String

Compilation command.

dockerfile_path

String

Address of the Docker file.

artifact_namespace

String

Build archive organization.

cluster_id

String

ID of the cluster to be built.

node_label_selector

Map<String, String>

key indicates the key of the tag, and value indicates the value of the tag.

Example

Example request

{
	"name": "mycomponent",
	"runtime": "Java8",
	"category": "MicroService",
	"sub_category": "Java Chassis",
	"description": "",
	"build": {
		"parameters": {
			"artifact_namespace": "ns"
		}
	},
        "source": {
		"kind": "artifact",
		"spec": {
			"storage": "obs",
			"type": "package",
			"url": "obs://myapp/demo.jar",
			"properties": {
				"bucket": "myapp",
				"key": "demo.jar",
				"endpoint": "https://obs.region_id.external_domain_name.com"
			}
		}
	}
}

Example response

{
	"id": "384eb8d4-c193-4d84-9558-6fda2366b536",
	"name": "mycomponent",
	"runtime": "Java8",
	"category": "MicroService",
	"sub_category": "Java Chassis",
	"description": "",
	"project_id": "384eb8d4-c193-4d84-9558-6fda23698536",
	"application_id": "a8f7eed5-0aa0-4251-9723-c9119a6bf56d",
        "source": {
		"kind": "artifact",
		"spec": {
			"storage": "obs",
			"type": "package",
			"url": "obs://myapp/demo.jar",
			"properties": {
				"bucket": "myapp",
				"key": "demo.jar",
				"endpoint": "https://obs.region_id.external_domain_name.com"
			}
		}
	},
	"build": {
		"id": "w3dpv7p0t1vpxvey5hjb22iuwxway1vupwx0nae1",
		"parameters": {
			"artifact_namespace": "ns",
			"use_public_cluster": true
		}
	},
	"pipeline_ids": null,
	"status": 0,
	"creator": "xxx",
	"create_time": 1610333934288,
	"update_time": 1610333934288
}

Status Code

Table 16 Status codes

Status Code

Description

200

OK

400

Bad Request

404

Not Found

500

Internal Server Error

Error Code

Error code must be in the format of SVCSTG.00100.[Error_ID]. Example: SVCSTG.00100400. See Error Codes of Application Management APIs.