mirror of
https://github.com/kubevela/kubevela.git
synced 2026-04-22 10:37:04 +00:00
Feat: make the component list is in reverse order (#3350)
* Feat: update api doc Signed-off-by: barnettZQG <barnett.zqg@gmail.com> * Feat: make the component list is in reverse order. Signed-off-by: barnettZQG <barnett.zqg@gmail.com> * Feat: update swagger config Signed-off-by: barnettZQG <barnett.zqg@gmail.com>
This commit is contained in:
@@ -4279,9 +4279,6 @@
|
||||
"$ref": "#/definitions/common.PolicyStatus"
|
||||
}
|
||||
},
|
||||
"resourceTracker": {
|
||||
"$ref": "#/definitions/v1.ObjectReference"
|
||||
},
|
||||
"services": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
@@ -4680,8 +4677,8 @@
|
||||
},
|
||||
"model.ApplicationComponent": {
|
||||
"required": [
|
||||
"updateTime",
|
||||
"createTime",
|
||||
"updateTime",
|
||||
"appPrimaryKey",
|
||||
"creator",
|
||||
"name",
|
||||
@@ -4879,8 +4876,8 @@
|
||||
},
|
||||
"model.Cluster": {
|
||||
"required": [
|
||||
"createTime",
|
||||
"updateTime",
|
||||
"createTime",
|
||||
"name",
|
||||
"alias",
|
||||
"description",
|
||||
@@ -5518,12 +5515,12 @@
|
||||
},
|
||||
"v1.ApplicationDeployResponse": {
|
||||
"required": [
|
||||
"triggerType",
|
||||
"envName",
|
||||
"createTime",
|
||||
"version",
|
||||
"status",
|
||||
"note"
|
||||
"note",
|
||||
"envName",
|
||||
"triggerType",
|
||||
"version",
|
||||
"createTime"
|
||||
],
|
||||
"properties": {
|
||||
"codeInfo": {
|
||||
@@ -5753,7 +5750,6 @@
|
||||
},
|
||||
"v1.ApplicationTrait": {
|
||||
"required": [
|
||||
"name",
|
||||
"type",
|
||||
"properties",
|
||||
"createTime",
|
||||
@@ -5770,9 +5766,6 @@
|
||||
"description": {
|
||||
"type": "string"
|
||||
},
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"properties": {
|
||||
"$ref": "#/definitions/model.JSONStruct"
|
||||
},
|
||||
@@ -5955,11 +5948,11 @@
|
||||
"description",
|
||||
"componentType",
|
||||
"main",
|
||||
"envNames",
|
||||
"dependsOn",
|
||||
"deployVersion",
|
||||
"createTime",
|
||||
"updateTime"
|
||||
"updateTime",
|
||||
"traits"
|
||||
],
|
||||
"properties": {
|
||||
"alias": {
|
||||
@@ -5987,15 +5980,15 @@
|
||||
"description": {
|
||||
"type": "string"
|
||||
},
|
||||
"envNames": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"icon": {
|
||||
"type": "string"
|
||||
},
|
||||
"inputs": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/common.inputItem"
|
||||
}
|
||||
},
|
||||
"labels": {
|
||||
"type": "object",
|
||||
"additionalProperties": {
|
||||
@@ -6008,6 +6001,18 @@
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"outputs": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/common.outputItem"
|
||||
}
|
||||
},
|
||||
"traits": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/v1.ApplicationTrait"
|
||||
}
|
||||
},
|
||||
"updateTime": {
|
||||
"type": "string",
|
||||
"format": "date-time"
|
||||
@@ -6347,6 +6352,12 @@
|
||||
"icon": {
|
||||
"type": "string"
|
||||
},
|
||||
"inputs": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/common.inputItem"
|
||||
}
|
||||
},
|
||||
"labels": {
|
||||
"type": "object",
|
||||
"additionalProperties": {
|
||||
@@ -6356,6 +6367,12 @@
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"outputs": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/common.outputItem"
|
||||
}
|
||||
},
|
||||
"properties": {
|
||||
"type": "string"
|
||||
},
|
||||
@@ -6510,11 +6527,11 @@
|
||||
},
|
||||
"v1.DetailAddonResponse": {
|
||||
"required": [
|
||||
"description",
|
||||
"invisible",
|
||||
"version",
|
||||
"icon",
|
||||
"name",
|
||||
"invisible",
|
||||
"description",
|
||||
"schema",
|
||||
"uiSchema",
|
||||
"definitions"
|
||||
@@ -6587,13 +6604,13 @@
|
||||
},
|
||||
"v1.DetailApplicationResponse": {
|
||||
"required": [
|
||||
"project",
|
||||
"description",
|
||||
"createTime",
|
||||
"updateTime",
|
||||
"icon",
|
||||
"name",
|
||||
"alias",
|
||||
"project",
|
||||
"policies",
|
||||
"envBindings",
|
||||
"status",
|
||||
@@ -6655,20 +6672,20 @@
|
||||
},
|
||||
"v1.DetailClusterResponse": {
|
||||
"required": [
|
||||
"name",
|
||||
"description",
|
||||
"alias",
|
||||
"apiServerURL",
|
||||
"dashboardURL",
|
||||
"kubeConfigSecret",
|
||||
"createTime",
|
||||
"icon",
|
||||
"labels",
|
||||
"provider",
|
||||
"kubeConfig",
|
||||
"updateTime",
|
||||
"description",
|
||||
"icon",
|
||||
"status",
|
||||
"reason",
|
||||
"provider",
|
||||
"apiServerURL",
|
||||
"createTime",
|
||||
"name",
|
||||
"labels",
|
||||
"kubeConfigSecret",
|
||||
"resourceInfo"
|
||||
],
|
||||
"properties": {
|
||||
@@ -6726,14 +6743,14 @@
|
||||
},
|
||||
"v1.DetailComponentResponse": {
|
||||
"required": [
|
||||
"appPrimaryKey",
|
||||
"name",
|
||||
"updateTime",
|
||||
"appPrimaryKey",
|
||||
"type",
|
||||
"alias",
|
||||
"main",
|
||||
"createTime",
|
||||
"creator",
|
||||
"alias",
|
||||
"type"
|
||||
"name"
|
||||
],
|
||||
"properties": {
|
||||
"alias": {
|
||||
@@ -6831,13 +6848,13 @@
|
||||
},
|
||||
"v1.DetailPolicyResponse": {
|
||||
"required": [
|
||||
"updateTime",
|
||||
"name",
|
||||
"type",
|
||||
"description",
|
||||
"creator",
|
||||
"properties",
|
||||
"createTime",
|
||||
"updateTime",
|
||||
"name"
|
||||
"createTime"
|
||||
],
|
||||
"properties": {
|
||||
"createTime": {
|
||||
@@ -6867,17 +6884,17 @@
|
||||
},
|
||||
"v1.DetailRevisionResponse": {
|
||||
"required": [
|
||||
"deployUser",
|
||||
"workflowName",
|
||||
"updateTime",
|
||||
"version",
|
||||
"deployUser",
|
||||
"envName",
|
||||
"appPrimaryKey",
|
||||
"reason",
|
||||
"triggerType",
|
||||
"createTime",
|
||||
"status",
|
||||
"note",
|
||||
"version",
|
||||
"updateTime"
|
||||
"triggerType",
|
||||
"appPrimaryKey",
|
||||
"reason"
|
||||
],
|
||||
"properties": {
|
||||
"appPrimaryKey": {
|
||||
@@ -6931,9 +6948,9 @@
|
||||
},
|
||||
"v1.DetailTargetResponse": {
|
||||
"required": [
|
||||
"createTime",
|
||||
"updateTime",
|
||||
"name",
|
||||
"createTime"
|
||||
"name"
|
||||
],
|
||||
"properties": {
|
||||
"alias": {
|
||||
@@ -6970,12 +6987,12 @@
|
||||
},
|
||||
"v1.DetailWorkflowRecordResponse": {
|
||||
"required": [
|
||||
"applicationRevision",
|
||||
"status",
|
||||
"name",
|
||||
"namespace",
|
||||
"workflowName",
|
||||
"workflowAlias",
|
||||
"applicationRevision",
|
||||
"deployTime",
|
||||
"deployUser",
|
||||
"note",
|
||||
@@ -7027,14 +7044,14 @@
|
||||
},
|
||||
"v1.DetailWorkflowResponse": {
|
||||
"required": [
|
||||
"name",
|
||||
"description",
|
||||
"envName",
|
||||
"updateTime",
|
||||
"alias",
|
||||
"enable",
|
||||
"default",
|
||||
"updateTime",
|
||||
"name",
|
||||
"alias",
|
||||
"createTime",
|
||||
"description",
|
||||
"envName"
|
||||
"createTime"
|
||||
],
|
||||
"properties": {
|
||||
"alias": {
|
||||
@@ -7630,10 +7647,10 @@
|
||||
},
|
||||
"v1.SystemInfoResponse": {
|
||||
"required": [
|
||||
"enableCollection",
|
||||
"createTime",
|
||||
"updateTime",
|
||||
"installID",
|
||||
"enableCollection",
|
||||
"systemVersion"
|
||||
],
|
||||
"properties": {
|
||||
@@ -8009,6 +8026,9 @@
|
||||
},
|
||||
"v1beta1.Workflow": {
|
||||
"properties": {
|
||||
"ref": {
|
||||
"type": "string"
|
||||
},
|
||||
"steps": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
|
||||
@@ -574,19 +574,21 @@ type ApplicationResourceInfo struct {
|
||||
|
||||
// ComponentBase component base model
|
||||
type ComponentBase struct {
|
||||
Name string `json:"name"`
|
||||
Alias string `json:"alias"`
|
||||
Description string `json:"description"`
|
||||
Labels map[string]string `json:"labels,omitempty"`
|
||||
ComponentType string `json:"componentType"`
|
||||
Main bool `json:"main"`
|
||||
EnvNames []string `json:"envNames"`
|
||||
Icon string `json:"icon,omitempty"`
|
||||
DependsOn []string `json:"dependsOn"`
|
||||
Creator string `json:"creator,omitempty"`
|
||||
DeployVersion string `json:"deployVersion"`
|
||||
CreateTime time.Time `json:"createTime"`
|
||||
UpdateTime time.Time `json:"updateTime"`
|
||||
Name string `json:"name"`
|
||||
Alias string `json:"alias"`
|
||||
Description string `json:"description"`
|
||||
Labels map[string]string `json:"labels,omitempty"`
|
||||
ComponentType string `json:"componentType"`
|
||||
Main bool `json:"main"`
|
||||
Icon string `json:"icon,omitempty"`
|
||||
DependsOn []string `json:"dependsOn"`
|
||||
Creator string `json:"creator,omitempty"`
|
||||
DeployVersion string `json:"deployVersion"`
|
||||
CreateTime time.Time `json:"createTime"`
|
||||
UpdateTime time.Time `json:"updateTime"`
|
||||
Inputs common.StepInputs `json:"inputs,omitempty"`
|
||||
Outputs common.StepOutputs `json:"outputs,omitempty"`
|
||||
Traits []*ApplicationTrait `json:"traits"`
|
||||
}
|
||||
|
||||
// ComponentListResponse list component
|
||||
@@ -604,6 +606,8 @@ type CreateComponentRequest struct {
|
||||
ComponentType string `json:"componentType" validate:"checkname"`
|
||||
Properties string `json:"properties,omitempty"`
|
||||
DependsOn []string `json:"dependsOn" optional:"true"`
|
||||
Inputs common.StepInputs `json:"inputs,omitempty" optional:"true"`
|
||||
Outputs common.StepOutputs `json:"outputs,omitempty" optional:"true"`
|
||||
Traits []*CreateApplicationTraitRequest `json:"traits,omitempty" optional:"true"`
|
||||
}
|
||||
|
||||
@@ -937,7 +941,7 @@ type CreateApplicationEnvbindingRequest struct {
|
||||
EnvBinding
|
||||
}
|
||||
|
||||
// CreateApplicationTraitRequest create application triat req
|
||||
// CreateApplicationTraitRequest create application trait request
|
||||
type CreateApplicationTraitRequest struct {
|
||||
Type string `json:"type" validate:"checkname"`
|
||||
Alias string `json:"alias,omitempty" validate:"checkalias" optional:"true"`
|
||||
@@ -954,7 +958,6 @@ type UpdateApplicationTraitRequest struct {
|
||||
|
||||
// ApplicationTrait application trait
|
||||
type ApplicationTrait struct {
|
||||
Name string `json:"name"`
|
||||
Type string `json:"type"`
|
||||
Alias string `json:"alias,omitempty"`
|
||||
Description string `json:"description,omitempty"`
|
||||
|
||||
@@ -544,36 +544,25 @@ func (c *applicationUsecaseImpl) ListComponents(ctx context.Context, app *model.
|
||||
var component = model.ApplicationComponent{
|
||||
AppPrimaryKey: app.PrimaryKey(),
|
||||
}
|
||||
components, err := c.ds.List(ctx, &component, &datastore.ListOptions{})
|
||||
components, err := c.ds.List(ctx, &component, &datastore.ListOptions{SortBy: []datastore.SortOption{{Key: "createTime", Order: datastore.SortOrderDescending}}})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
envComponents := map[string]bool{}
|
||||
componentSelectorDefine := false
|
||||
if op.EnvName != "" {
|
||||
envbindings, err := c.envBindingUsecase.GetEnvBindings(ctx, app)
|
||||
if err != nil && !errors.Is(err, bcode.ErrApplicationNotEnv) {
|
||||
log.Logger.Errorf("query app env binding policy config failure %s", err.Error())
|
||||
}
|
||||
if len(envbindings) > 0 {
|
||||
for _, env := range envbindings {
|
||||
if env != nil && env.Name == op.EnvName {
|
||||
componentSelectorDefine = true
|
||||
for _, componentName := range env.ComponentSelector.Components {
|
||||
envComponents[componentName] = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var list []*apisv1.ComponentBase
|
||||
var main *apisv1.ComponentBase
|
||||
for _, component := range components {
|
||||
pm := component.(*model.ApplicationComponent)
|
||||
if !componentSelectorDefine || envComponents[pm.Name] {
|
||||
list = append(list, c.converComponentModelToBase(pm))
|
||||
if !pm.Main {
|
||||
list = append(list, convertComponentModelToBase(pm))
|
||||
} else {
|
||||
main = convertComponentModelToBase(pm)
|
||||
}
|
||||
}
|
||||
// the main component must be first
|
||||
if main != nil {
|
||||
list = append([]*apisv1.ComponentBase{main}, list...)
|
||||
}
|
||||
return list, nil
|
||||
}
|
||||
|
||||
@@ -593,21 +582,6 @@ func (c *applicationUsecaseImpl) DetailComponent(ctx context.Context, app *model
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (c *applicationUsecaseImpl) converComponentModelToBase(m *model.ApplicationComponent) *apisv1.ComponentBase {
|
||||
return &apisv1.ComponentBase{
|
||||
Name: m.Name,
|
||||
Alias: m.Alias,
|
||||
Description: m.Description,
|
||||
Labels: m.Labels,
|
||||
ComponentType: m.Type,
|
||||
Icon: m.Icon,
|
||||
DependsOn: m.DependsOn,
|
||||
Creator: m.Creator,
|
||||
CreateTime: m.CreateTime,
|
||||
UpdateTime: m.UpdateTime,
|
||||
}
|
||||
}
|
||||
|
||||
// ListPolicies list application policies
|
||||
func (c *applicationUsecaseImpl) ListPolicies(ctx context.Context, app *model.Application) ([]*apisv1.PolicyBase, error) {
|
||||
policies, err := c.queryApplicationPolicies(ctx, app)
|
||||
@@ -1050,7 +1024,7 @@ func (c *applicationUsecaseImpl) UpdateComponent(ctx context.Context, app *model
|
||||
if err := c.ds.Put(ctx, component); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return converComponentModelToBase(component), nil
|
||||
return convertComponentModelToBase(component), nil
|
||||
}
|
||||
|
||||
func (c *applicationUsecaseImpl) createComponent(ctx context.Context, app *model.Application, com apisv1.CreateComponentRequest, main bool) (*apisv1.ComponentBase, error) {
|
||||
@@ -1063,6 +1037,8 @@ func (c *applicationUsecaseImpl) createComponent(ctx context.Context, app *model
|
||||
Name: com.Name,
|
||||
Type: com.ComponentType,
|
||||
DependsOn: com.DependsOn,
|
||||
Inputs: com.Inputs,
|
||||
Outputs: com.Outputs,
|
||||
Alias: com.Alias,
|
||||
Main: main,
|
||||
}
|
||||
@@ -1105,7 +1081,7 @@ func (c *applicationUsecaseImpl) createComponent(ctx context.Context, app *model
|
||||
log.Logger.Warnf("add component for app %s failure %s", utils2.Sanitize(app.PrimaryKey()), err.Error())
|
||||
return nil, err
|
||||
}
|
||||
return converComponentModelToBase(&componentModel), nil
|
||||
return convertComponentModelToBase(&componentModel), nil
|
||||
}
|
||||
|
||||
func (c *applicationUsecaseImpl) CreateComponent(ctx context.Context, app *model.Application, com apisv1.CreateComponentRequest) (*apisv1.ComponentBase, error) {
|
||||
@@ -1130,21 +1106,37 @@ func (c *applicationUsecaseImpl) initCreateDefaultTrait(component *model.Applica
|
||||
component.Traits = initTraits
|
||||
}
|
||||
|
||||
func converComponentModelToBase(componentModel *model.ApplicationComponent) *apisv1.ComponentBase {
|
||||
func convertComponentModelToBase(componentModel *model.ApplicationComponent) *apisv1.ComponentBase {
|
||||
if componentModel == nil {
|
||||
return nil
|
||||
}
|
||||
return &apisv1.ComponentBase{
|
||||
Name: componentModel.Name,
|
||||
Alias: componentModel.Alias,
|
||||
Description: componentModel.Description,
|
||||
Labels: componentModel.Labels,
|
||||
ComponentType: componentModel.Type,
|
||||
Icon: componentModel.Icon,
|
||||
DependsOn: componentModel.DependsOn,
|
||||
Inputs: componentModel.Inputs,
|
||||
Outputs: componentModel.Outputs,
|
||||
Creator: componentModel.Creator,
|
||||
Main: componentModel.Main,
|
||||
CreateTime: componentModel.CreateTime,
|
||||
UpdateTime: componentModel.UpdateTime,
|
||||
Traits: func() (traits []*apisv1.ApplicationTrait) {
|
||||
for _, trait := range componentModel.Traits {
|
||||
traits = append(traits, &apisv1.ApplicationTrait{
|
||||
Type: trait.Type,
|
||||
Properties: trait.Properties,
|
||||
Alias: trait.Alias,
|
||||
Description: trait.Description,
|
||||
CreateTime: trait.CreateTime,
|
||||
UpdateTime: trait.UpdateTime,
|
||||
})
|
||||
}
|
||||
return
|
||||
}(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1261,7 +1253,7 @@ func (c *applicationUsecaseImpl) CreateApplicationTrait(ctx context.Context, app
|
||||
if err := c.ds.Put(ctx, &comp); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &apisv1.ApplicationTrait{Type: trait.Type, Properties: properties, Alias: req.Alias, Description: req.Description, CreateTime: trait.CreateTime}, nil
|
||||
return &apisv1.ApplicationTrait{Type: trait.Type, Properties: properties, Alias: req.Alias, Description: req.Description, CreateTime: trait.CreateTime, UpdateTime: trait.UpdateTime}, nil
|
||||
}
|
||||
|
||||
func (c *applicationUsecaseImpl) DeleteApplicationTrait(ctx context.Context, app *model.Application, component *model.ApplicationComponent, traitType string) error {
|
||||
|
||||
Reference in New Issue
Block a user