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

Creating an Application Component

Function

An application 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

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

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. Letters are case insensitive.

runtime

Yes

String

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

category

Yes

String

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

sub_category

No

String

Application component sub-category.

Webapp sub-categories include Web.

MicroService sub-categories include Java Chassis, and Spring Cloud.

Common sub-category can be empty.

description

No

String

Description.

The value can contain up to 128 characters.

source

No

Object

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

build

No

Object

Component build. See Table 8.

Table 4 source

Parameter

Mandatory

Type

Description

kind

Yes

String

Type. Option: source code or artifact software package.

spec

Yes

Object

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

Table 5 code spec

Parameter

Mandatory

Type

Description

repo_type

No

String

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

repo_url

No

String

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

repo_ref

No

String

Code branch or tag. Default value: master.

repo_auth

No

String

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

Table 6 artifact spec

Parameter

Mandatory

Type

Description

storage

No

String

Storage mode. Value: swr (software repository), swr (image), obs, or codearts.

type

No

String

Type.

  • VM-based deployment supports package.
  • Container-based deployment supports package and image.

url

No

String

Address of the software package or source code.

auth

No

String

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

properties

No

Object

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

webUrl

No

String

Address of a software repository.

Table 7 artifact spec properties

Parameter

Mandatory

Type

Description

endpoint

No

String

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

bucket

No

String

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

key

No

String

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 8 build

Parameter

Mandatory

Type

Description

parameters

No

Map<String, Object>

See Table 9.

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

Table 9 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

No

String

ID of the cluster to be built.

node_label_selector

No

Map<String, String>

key: label key. value: label value.

Response

Table 10 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 system.

category

String

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

sub_category

String

Application component sub-category.

Webapp sub-categories include Web.

MicroService sub-categories include Java Chassis, and Spring Cloud.

Common sub-category 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 11.

build

Object

Build. See Table 15.

create_time

Integer

Creation time.

update_time

Integer

Update time.

creator

String

Creator.

Table 11 source

Parameter

Type

Description

kind

String

Type. Option: source code or artifact software package.

spec

Object

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

Table 12 code spec

Parameter

Type

Description

repo_type

String

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

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 13 artifact spec

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 14.

Table 14 artifact spec properties

Parameter

Type

Description

endpoint

String

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

bucket

String

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

key

String

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 15 build

Parameter

Type

Description

id

String

Type.

parameters

Map<String, Object>

See Table 16.

Table 16 parameters

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: label key. value: label value.

Example Request

Create an application microservice component for software package deployment. Set runtime to Java8 and the component software package source to the demo.jar package in the myapp bucket of OBS.

{
	"name": "mycomponent",
	"runtime": "Java8",
	"category": "MicroService",
	"sub_category": "Java Chassis",
	"description": "",
	"build": {
		"parameters": {
			"artifact_namespace": "ns",
			"use_public_cluster": false,
			"cluster_id": "523498f1-36c4-11eb-ae36-0255ac1000c2",
			"cluster_name": "cce-test",
			"cluster_type": "VirtualMachine"
		}
	},
        "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",
			"dockerfile_path": "./"
		}
	},

	"status": 0,
	"creator": "test_user",
	"create_time": 1610333934288,
	"update_time": 1610333934288
}

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.