Feat: change application to applicationplan (#2616)

* Feat: change application to applicationplan

* Feat: update swagger config

* Feat: change api spec

* Fix : fix e2e test case

Co-authored-by: barnettZQG <yiyun.pro>
This commit is contained in:
barnettZQG
2021-11-03 17:25:37 +08:00
committed by GitHub
co-authored by lnx01
parent 5f09faeff0
commit 8e874bc3a9
15 changed files with 1106 additions and 667 deletions
+823 -384
View File
File diff suppressed because it is too large Load Diff
+2 -2
View File
@@ -30,7 +30,7 @@ import (
var _ = Describe("Test new entity function", func() {
It("Test new application entity", func() {
var app model.Application
var app model.ApplicationPlan
new, err := NewEntity(&app)
Expect(err).To(BeNil())
json.Unmarshal([]byte(`{"name":"demo"}`), new)
@@ -40,7 +40,7 @@ var _ = Describe("Test new entity function", func() {
})
It("Test new multiple application entity", func() {
var app model.Application
var app model.ApplicationPlan
var list []Entity
var n = 3
for n > 0 {
+13 -13
View File
@@ -88,22 +88,22 @@ var _ = Describe("Test kubeapi datastore driver", func() {
Expect(kubeStore).ToNot(BeNil())
It("Test add funtion", func() {
err := kubeStore.Add(context.TODO(), &model.Application{Name: "kubevela-app", Description: "default"})
err := kubeStore.Add(context.TODO(), &model.ApplicationPlan{Name: "kubevela-app", Description: "default"})
Expect(err).ToNot(HaveOccurred())
})
It("Test batch add funtion", func() {
var datas = []datastore.Entity{
&model.Application{Name: "kubevela-app-2", Description: "this is demo 2"},
&model.Application{Namespace: "test-namespace", Name: "kubevela-app-3", Description: "this is demo 3"},
&model.Application{Namespace: "test-namespace2", Name: "kubevela-app-4", Description: "this is demo 4"},
&model.ApplicationPlan{Name: "kubevela-app-2", Description: "this is demo 2"},
&model.ApplicationPlan{Namespace: "test-namespace", Name: "kubevela-app-3", Description: "this is demo 3"},
&model.ApplicationPlan{Namespace: "test-namespace2", Name: "kubevela-app-4", Description: "this is demo 4"},
}
err := kubeStore.BatchAdd(context.TODO(), datas)
Expect(err).ToNot(HaveOccurred())
var datas2 = []datastore.Entity{
&model.Application{Namespace: "test-namespace", Name: "can-delete", Description: "this is demo can-delete"},
&model.Application{Name: "kubevela-app-2", Description: "this is demo 2"},
&model.ApplicationPlan{Namespace: "test-namespace", Name: "can-delete", Description: "this is demo can-delete"},
&model.ApplicationPlan{Name: "kubevela-app-2", Description: "this is demo 2"},
}
err = kubeStore.BatchAdd(context.TODO(), datas2)
equal := cmp.Diff(strings.Contains(err.Error(), "save components occur error"), true)
@@ -111,7 +111,7 @@ var _ = Describe("Test kubeapi datastore driver", func() {
})
It("Test get funtion", func() {
app := &model.Application{Name: "kubevela-app"}
app := &model.ApplicationPlan{Name: "kubevela-app"}
err := kubeStore.Get(context.TODO(), app)
Expect(err).Should(BeNil())
diff := cmp.Diff(app.Description, "default")
@@ -119,11 +119,11 @@ var _ = Describe("Test kubeapi datastore driver", func() {
})
It("Test put funtion", func() {
err := kubeStore.Put(context.TODO(), &model.Application{Name: "kubevela-app", Description: "this is demo"})
err := kubeStore.Put(context.TODO(), &model.ApplicationPlan{Name: "kubevela-app", Description: "this is demo"})
Expect(err).ToNot(HaveOccurred())
})
It("Test index", func() {
var app = model.Application{
var app = model.ApplicationPlan{
Namespace: "test",
}
selector, err := labels.Parse(fmt.Sprintf("table=%s", app.TableName()))
@@ -137,7 +137,7 @@ var _ = Describe("Test kubeapi datastore driver", func() {
Expect(cmp.Diff(selector.String(), "namespace=test,table=vela_application")).Should(BeEmpty())
})
It("Test list function", func() {
var app model.Application
var app model.ApplicationPlan
list, err := kubeStore.List(context.TODO(), &app, &datastore.ListOptions{Page: -1})
Expect(err).ShouldNot(HaveOccurred())
diff := cmp.Diff(len(list), 4)
@@ -166,7 +166,7 @@ var _ = Describe("Test kubeapi datastore driver", func() {
})
It("Test count function", func() {
var app model.Application
var app model.ApplicationPlan
count, err := kubeStore.Count(context.TODO(), &app)
Expect(err).ShouldNot(HaveOccurred())
Expect(count).Should(Equal(int64(4)))
@@ -178,7 +178,7 @@ var _ = Describe("Test kubeapi datastore driver", func() {
})
It("Test isExist function", func() {
var app model.Application
var app model.ApplicationPlan
app.Name = "kubevela-app-3"
exist, err := kubeStore.IsExist(context.TODO(), &app)
Expect(err).ShouldNot(HaveOccurred())
@@ -193,7 +193,7 @@ var _ = Describe("Test kubeapi datastore driver", func() {
})
It("Test delete funtion", func() {
var app model.Application
var app model.ApplicationPlan
app.Name = "kubevela-app"
err := kubeStore.Delete(context.TODO(), &app)
Expect(err).ShouldNot(HaveOccurred())
+12 -12
View File
@@ -56,22 +56,22 @@ var _ = BeforeSuite(func(done Done) {
var _ = Describe("Test mongodb datastore driver", func() {
It("Test add funtion", func() {
err := mongodbDriver.Add(context.TODO(), &model.Application{Name: "kubevela-app", Description: "default"})
err := mongodbDriver.Add(context.TODO(), &model.ApplicationPlan{Name: "kubevela-app", Description: "default"})
Expect(err).ToNot(HaveOccurred())
})
It("Test batch add funtion", func() {
var datas = []datastore.Entity{
&model.Application{Name: "kubevela-app-2", Description: "this is demo 2"},
&model.Application{Namespace: "test-namespace", Name: "kubevela-app-3", Description: "this is demo 3"},
&model.Application{Namespace: "test-namespace2", Name: "kubevela-app-4", Description: "this is demo 4"},
&model.ApplicationPlan{Name: "kubevela-app-2", Description: "this is demo 2"},
&model.ApplicationPlan{Namespace: "test-namespace", Name: "kubevela-app-3", Description: "this is demo 3"},
&model.ApplicationPlan{Namespace: "test-namespace2", Name: "kubevela-app-4", Description: "this is demo 4"},
}
err := mongodbDriver.BatchAdd(context.TODO(), datas)
Expect(err).ToNot(HaveOccurred())
var datas2 = []datastore.Entity{
&model.Application{Namespace: "test-namespace", Name: "can-delete", Description: "this is demo can-delete"},
&model.Application{Name: "kubevela-app-2", Description: "this is demo 2"},
&model.ApplicationPlan{Namespace: "test-namespace", Name: "can-delete", Description: "this is demo can-delete"},
&model.ApplicationPlan{Name: "kubevela-app-2", Description: "this is demo 2"},
}
err = mongodbDriver.BatchAdd(context.TODO(), datas2)
equal := cmp.Diff(strings.Contains(err.Error(), "save components occur error"), true)
@@ -79,7 +79,7 @@ var _ = Describe("Test mongodb datastore driver", func() {
})
It("Test get funtion", func() {
app := &model.Application{Name: "kubevela-app"}
app := &model.ApplicationPlan{Name: "kubevela-app"}
err := mongodbDriver.Get(context.TODO(), app)
Expect(err).Should(BeNil())
diff := cmp.Diff(app.Description, "default")
@@ -87,11 +87,11 @@ var _ = Describe("Test mongodb datastore driver", func() {
})
It("Test put funtion", func() {
err := mongodbDriver.Put(context.TODO(), &model.Application{Name: "kubevela-app", Description: "this is demo"})
err := mongodbDriver.Put(context.TODO(), &model.ApplicationPlan{Name: "kubevela-app", Description: "this is demo"})
Expect(err).ToNot(HaveOccurred())
})
It("Test list funtion", func() {
var app model.Application
var app model.ApplicationPlan
list, err := mongodbDriver.List(context.TODO(), &app, &datastore.ListOptions{Page: -1})
Expect(err).ShouldNot(HaveOccurred())
diff := cmp.Diff(len(list), 4)
@@ -120,7 +120,7 @@ var _ = Describe("Test mongodb datastore driver", func() {
})
It("Test count function", func() {
var app model.Application
var app model.ApplicationPlan
count, err := mongodbDriver.Count(context.TODO(), &app)
Expect(err).ShouldNot(HaveOccurred())
Expect(count).Should(Equal(int64(4)))
@@ -132,7 +132,7 @@ var _ = Describe("Test mongodb datastore driver", func() {
})
It("Test isExist funtion", func() {
var app model.Application
var app model.ApplicationPlan
app.Name = "kubevela-app-3"
exist, err := mongodbDriver.IsExist(context.TODO(), &app)
Expect(err).ShouldNot(HaveOccurred())
@@ -147,7 +147,7 @@ var _ = Describe("Test mongodb datastore driver", func() {
})
It("Test delete funtion", func() {
var app model.Application
var app model.ApplicationPlan
app.Name = "kubevela-app"
err := mongodbDriver.Delete(context.TODO(), &app)
Expect(err).ShouldNot(HaveOccurred())
+20 -20
View File
@@ -23,11 +23,11 @@ import (
)
func init() {
RegistModel(&ApplicationComponent{}, &ApplicationPolicy{}, &Application{}, &DeployEvent{})
RegistModel(&ApplicationComponentPlan{}, &ApplicationPolicyPlan{}, &ApplicationPlan{}, &DeployEvent{})
}
// Application database model
type Application struct {
// ApplicationPlan application delivery plan model
type ApplicationPlan struct {
Model
Name string `json:"name"`
Alias string `json:"alias"`
@@ -39,17 +39,17 @@ type Application struct {
}
// TableName return custom table name
func (a *Application) TableName() string {
func (a *ApplicationPlan) TableName() string {
return tableNamePrefix + "application"
}
// PrimaryKey return custom primary key
func (a *Application) PrimaryKey() string {
func (a *ApplicationPlan) PrimaryKey() string {
return a.Name
}
// Index return custom index
func (a *Application) Index() map[string]string {
func (a *ApplicationPlan) Index() map[string]string {
index := make(map[string]string)
if a.Name != "" {
index["name"] = a.Name
@@ -74,8 +74,8 @@ type ClusterSelector struct {
Namespace string `json:"namespace,omitempty"`
}
// ApplicationComponent component database model
type ApplicationComponent struct {
// ApplicationComponentPlan component database model
type ApplicationComponentPlan struct {
Model
AppPrimaryKey string `json:"appPrimaryKey"`
Description string `json:"description,omitempty"`
@@ -93,24 +93,24 @@ type ApplicationComponent struct {
Inputs common.StepInputs `json:"inputs,omitempty"`
Outputs common.StepOutputs `json:"outputs,omitempty"`
// Traits define the trait of one component, the type must be array to keep the order.
Traits []ApplicationTrait `json:"traits,omitempty"`
// scopes in ApplicationComponent defines the component-level scopes
Traits []ApplicationTraitPlan `json:"traits,omitempty"`
// scopes in ApplicationComponentPlan defines the component-level scopes
// the format is <scope-type:scope-instance-name> pairs, the key represents type of `ScopeDefinition` while the value represent the name of scope instance.
Scopes map[string]string `json:"scopes,omitempty"`
}
// TableName return custom table name
func (a *ApplicationComponent) TableName() string {
func (a *ApplicationComponentPlan) TableName() string {
return tableNamePrefix + "application_component"
}
// PrimaryKey return custom primary key
func (a *ApplicationComponent) PrimaryKey() string {
func (a *ApplicationComponentPlan) PrimaryKey() string {
return fmt.Sprintf("%s-%s", a.AppPrimaryKey, a.Name)
}
// Index return custom index
func (a *ApplicationComponent) Index() map[string]string {
func (a *ApplicationComponentPlan) Index() map[string]string {
index := make(map[string]string)
if a.Name != "" {
index["name"] = a.Name
@@ -124,8 +124,8 @@ func (a *ApplicationComponent) Index() map[string]string {
return index
}
// ApplicationPolicy app policy
type ApplicationPolicy struct {
// ApplicationPolicyPlan app policy
type ApplicationPolicyPlan struct {
Model
AppPrimaryKey string `json:"appPrimaryKey"`
Name string `json:"name"`
@@ -136,17 +136,17 @@ type ApplicationPolicy struct {
}
// TableName return custom table name
func (a *ApplicationPolicy) TableName() string {
func (a *ApplicationPolicyPlan) TableName() string {
return tableNamePrefix + "application_policy"
}
// PrimaryKey return custom primary key
func (a *ApplicationPolicy) PrimaryKey() string {
func (a *ApplicationPolicyPlan) PrimaryKey() string {
return fmt.Sprintf("%s-%s", a.AppPrimaryKey, a.Name)
}
// Index return custom index
func (a *ApplicationPolicy) Index() map[string]string {
func (a *ApplicationPolicyPlan) Index() map[string]string {
index := make(map[string]string)
if a.Name != "" {
index["name"] = a.Name
@@ -160,8 +160,8 @@ func (a *ApplicationPolicy) Index() map[string]string {
return index
}
// ApplicationTrait application trait
type ApplicationTrait struct {
// ApplicationTraitPlan application trait
type ApplicationTraitPlan struct {
Type string `json:"type"`
Properties *JSONStruct `json:"properties,omitempty"`
}
+6 -6
View File
@@ -24,12 +24,12 @@ import (
)
func init() {
RegistModel(&Workflow{})
RegistModel(&WorkflowPlan{})
RegistModel(&WorkflowRecord{})
}
// Workflow application delivery plan database model
type Workflow struct {
// WorkflowPlan application delivery plan database model
type WorkflowPlan struct {
Model
Name string `json:"name"`
Alias string `json:"alias"`
@@ -55,17 +55,17 @@ type WorkflowStep struct {
}
// TableName return custom table name
func (w *Workflow) TableName() string {
func (w *WorkflowPlan) TableName() string {
return tableNamePrefix + "workflow"
}
// PrimaryKey return custom primary key
func (w *Workflow) PrimaryKey() string {
func (w *WorkflowPlan) PrimaryKey() string {
return w.Name
}
// Index return custom primary key
func (w *Workflow) Index() map[string]string {
func (w *WorkflowPlan) Index() map[string]string {
index := make(map[string]string)
if w.Name != "" {
index["name"] = w.Name
+34 -34
View File
@@ -187,16 +187,16 @@ type ClusterBase struct {
Reason string `json:"reason"`
}
// ListApplicatioOptions list application query options
type ListApplicatioOptions struct {
// ListApplicatioPlanOptions list application plan query options
type ListApplicatioPlanOptions struct {
Namespace string `json:"namespace"`
Cluster string `json:"cluster"`
Query string `json:"query"`
}
// ListApplicationResponse list applications by query params
type ListApplicationResponse struct {
Applications []*ApplicationBase `json:"applications"`
// ListApplicationPlanResponse list applications by query params
type ListApplicationPlanResponse struct {
ApplicationPlans []*ApplicationPlanBase `json:"applicationplans"`
}
// EnvBindList env bind list
@@ -212,8 +212,8 @@ func (e EnvBindList) ContainCluster(name string) bool {
return false
}
// ApplicationBase application base model
type ApplicationBase struct {
// ApplicationPlanBase application base model
type ApplicationPlanBase struct {
Name string `json:"name"`
Alias string `json:"alias"`
Namespace string `json:"namespace"`
@@ -246,8 +246,8 @@ type GatewayRule struct {
ComponentPort int32 `json:"componentPort"`
}
// CreateApplicationRequest create application request body
type CreateApplicationRequest struct {
// CreateApplicationPlanRequest create application plan request body
type CreateApplicationPlanRequest struct {
Name string `json:"name" validate:"checkname"`
Alias string `json:"alias" validate:"checkalias"`
Namespace string `json:"namespace" validate:"checkname"`
@@ -274,9 +274,9 @@ type ClusterSelector struct {
Namespace string `json:"namespace,omitempty"`
}
// DetailApplicationResponse application detail
type DetailApplicationResponse struct {
ApplicationBase
// DetailApplicationPlanResponse application plan detail
type DetailApplicationPlanResponse struct {
ApplicationPlanBase
Policies []string `json:"policies"`
Status string `json:"status"`
ResourceInfo ApplicationResourceInfo `json:"resourceInfo"`
@@ -296,8 +296,8 @@ type ApplicationResourceInfo struct {
// Others, such as: Memory、CPU、GPU、Storage
}
// ComponentBase component base model
type ComponentBase struct {
// ComponentPlanBase component plan base model
type ComponentPlanBase struct {
Name string `json:"name"`
Alias string `json:"alias"`
Description string `json:"description"`
@@ -312,13 +312,13 @@ type ComponentBase struct {
UpdateTime time.Time `json:"updateTime"`
}
// ComponentListResponse list component
type ComponentListResponse struct {
Components []*ComponentBase `json:"components"`
// ComponentPlanListResponse list component plan
type ComponentPlanListResponse struct {
ComponentPlans []*ComponentPlanBase `json:"componentplans"`
}
// CreateComponentRequest create component request model
type CreateComponentRequest struct {
// CreateComponentPlanRequest create component plan request model
type CreateComponentPlanRequest struct {
Name string `json:"name" validate:"checkname"`
Alias string `json:"alias" validate:"checkalias"`
Description string `json:"description"`
@@ -330,9 +330,9 @@ type CreateComponentRequest struct {
DependsOn []string `json:"dependsOn"`
}
// DetailComponentResponse detail component model
type DetailComponentResponse struct {
model.ApplicationComponent
// DetailComponentPlanResponse detail component plan model
type DetailComponentPlanResponse struct {
model.ApplicationComponentPlan
//TODO: Status
}
@@ -452,8 +452,8 @@ type PolicyDefinition struct {
Parameters []types.Parameter `json:"parameters"`
}
// CreateWorkflowRequest create workflow request
type CreateWorkflowRequest struct {
// CreateWorkflowPlanRequest create workflow plan request
type CreateWorkflowPlanRequest struct {
AppName string `json:"appName" validate:"checkname"`
Name string `json:"name" validate:"checkname"`
Alias string `json:"alias" validate:"checkalias"`
@@ -463,8 +463,8 @@ type CreateWorkflowRequest struct {
Default bool `json:"default"`
}
// UpdateWorkflowRequest update or create application workflow
type UpdateWorkflowRequest struct {
// UpdateWorkflowPlanRequest update or create application workflow
type UpdateWorkflowPlanRequest struct {
Alias string `json:"alias" validate:"checkalias"`
Description string `json:"description"`
Steps []WorkflowStep `json:"steps,omitempty"`
@@ -483,20 +483,20 @@ type WorkflowStep struct {
Outputs common.StepOutputs `json:"outputs,omitempty"`
}
// DetailWorkflowResponse detail workflow response
type DetailWorkflowResponse struct {
WorkflowBase
// DetailWorkflowPlanResponse detail workflow response
type DetailWorkflowPlanResponse struct {
WorkflowPlanBase
Steps []WorkflowStep `json:"steps,omitempty"`
LastRecord *WorkflowRecord `json:"workflowRecord"`
}
// ListWorkflowResponse list application workflows
type ListWorkflowResponse struct {
Workflows []*WorkflowBase `json:"workflows"`
// ListWorkflowPlanResponse list application workflows
type ListWorkflowPlanResponse struct {
WorkflowPlans []*WorkflowPlanBase `json:"workflowplans"`
}
// WorkflowBase workflow base model
type WorkflowBase struct {
// WorkflowPlanBase workflow base model
type WorkflowPlanBase struct {
Name string `json:"name"`
Alias string `json:"alias"`
Description string `json:"description"`
+79 -79
View File
@@ -53,22 +53,22 @@ const (
// ApplicationUsecase application usecase
type ApplicationUsecase interface {
ListApplications(ctx context.Context, listOptions apisv1.ListApplicatioOptions) ([]*apisv1.ApplicationBase, error)
GetApplication(ctx context.Context, appName string) (*model.Application, error)
DetailApplication(ctx context.Context, app *model.Application) (*apisv1.DetailApplicationResponse, error)
PublishApplicationTemplate(ctx context.Context, app *model.Application) (*apisv1.ApplicationTemplateBase, error)
CreateApplication(context.Context, apisv1.CreateApplicationRequest) (*apisv1.ApplicationBase, error)
DeleteApplication(ctx context.Context, app *model.Application) error
Deploy(ctx context.Context, app *model.Application, req apisv1.ApplicationDeployRequest) (*apisv1.ApplicationDeployResponse, error)
ListComponents(ctx context.Context, app *model.Application) ([]*apisv1.ComponentBase, error)
AddComponent(ctx context.Context, app *model.Application, com apisv1.CreateComponentRequest) (*apisv1.ComponentBase, error)
DetailComponent(ctx context.Context, app *model.Application, componentName string) (*apisv1.DetailComponentResponse, error)
DeleteComponent(ctx context.Context, app *model.Application, componentName string) error
ListPolicies(ctx context.Context, app *model.Application) ([]*apisv1.PolicyBase, error)
AddPolicy(ctx context.Context, app *model.Application, policy apisv1.CreatePolicyRequest) (*apisv1.PolicyBase, error)
DetailPolicy(ctx context.Context, app *model.Application, policyName string) (*apisv1.DetailPolicyResponse, error)
DeletePolicy(ctx context.Context, app *model.Application, policyName string) error
UpdatePolicy(ctx context.Context, app *model.Application, policyName string, policy apisv1.UpdatePolicyRequest) (*apisv1.DetailPolicyResponse, error)
ListApplications(ctx context.Context, listOptions apisv1.ListApplicatioPlanOptions) ([]*apisv1.ApplicationPlanBase, error)
GetApplication(ctx context.Context, appName string) (*model.ApplicationPlan, error)
DetailApplication(ctx context.Context, app *model.ApplicationPlan) (*apisv1.DetailApplicationPlanResponse, error)
PublishApplicationTemplate(ctx context.Context, app *model.ApplicationPlan) (*apisv1.ApplicationTemplateBase, error)
CreateApplication(context.Context, apisv1.CreateApplicationPlanRequest) (*apisv1.ApplicationPlanBase, error)
DeleteApplication(ctx context.Context, app *model.ApplicationPlan) error
Deploy(ctx context.Context, app *model.ApplicationPlan, req apisv1.ApplicationDeployRequest) (*apisv1.ApplicationDeployResponse, error)
ListComponents(ctx context.Context, app *model.ApplicationPlan) ([]*apisv1.ComponentPlanBase, error)
AddComponent(ctx context.Context, app *model.ApplicationPlan, com apisv1.CreateComponentPlanRequest) (*apisv1.ComponentPlanBase, error)
DetailComponent(ctx context.Context, app *model.ApplicationPlan, componentName string) (*apisv1.DetailComponentPlanResponse, error)
DeleteComponent(ctx context.Context, app *model.ApplicationPlan, componentName string) error
ListPolicies(ctx context.Context, app *model.ApplicationPlan) ([]*apisv1.PolicyBase, error)
AddPolicy(ctx context.Context, app *model.ApplicationPlan, policy apisv1.CreatePolicyRequest) (*apisv1.PolicyBase, error)
DetailPolicy(ctx context.Context, app *model.ApplicationPlan, policyName string) (*apisv1.DetailPolicyResponse, error)
DeletePolicy(ctx context.Context, app *model.ApplicationPlan, policyName string) error
UpdatePolicy(ctx context.Context, app *model.ApplicationPlan, policyName string, policy apisv1.UpdatePolicyRequest) (*apisv1.DetailPolicyResponse, error)
}
type applicationUsecaseImpl struct {
@@ -93,8 +93,8 @@ func NewApplicationUsecase(ds datastore.DataStore, workflowUsecase WorkflowUseca
}
// ListApplications list applications
func (c *applicationUsecaseImpl) ListApplications(ctx context.Context, listOptions apisv1.ListApplicatioOptions) ([]*apisv1.ApplicationBase, error) {
var app = model.Application{}
func (c *applicationUsecaseImpl) ListApplications(ctx context.Context, listOptions apisv1.ListApplicatioPlanOptions) ([]*apisv1.ApplicationPlanBase, error) {
var app = model.ApplicationPlan{}
if listOptions.Namespace != "" {
app.Namespace = listOptions.Namespace
}
@@ -102,9 +102,9 @@ func (c *applicationUsecaseImpl) ListApplications(ctx context.Context, listOptio
if err != nil {
return nil, err
}
var list []*apisv1.ApplicationBase
var list []*apisv1.ApplicationPlanBase
for _, entity := range entitys {
appBase := c.converAppModelToBase(ctx, entity.(*model.Application))
appBase := c.converAppModelToBase(ctx, entity.(*model.ApplicationPlan))
if listOptions.Query != "" &&
!(strings.Contains(appBase.Alias, listOptions.Query) ||
strings.Contains(appBase.Name, listOptions.Query) ||
@@ -120,8 +120,8 @@ func (c *applicationUsecaseImpl) ListApplications(ctx context.Context, listOptio
}
// GetApplication get application model
func (c *applicationUsecaseImpl) GetApplication(ctx context.Context, appName string) (*model.Application, error) {
var app = model.Application{
func (c *applicationUsecaseImpl) GetApplication(ctx context.Context, appName string) (*model.ApplicationPlan, error) {
var app = model.ApplicationPlan{
Name: appName,
}
if err := c.ds.Get(ctx, &app); err != nil {
@@ -131,7 +131,7 @@ func (c *applicationUsecaseImpl) GetApplication(ctx context.Context, appName str
}
// DetailApplication detail application info
func (c *applicationUsecaseImpl) DetailApplication(ctx context.Context, app *model.Application) (*apisv1.DetailApplicationResponse, error) {
func (c *applicationUsecaseImpl) DetailApplication(ctx context.Context, app *model.ApplicationPlan) (*apisv1.DetailApplicationPlanResponse, error) {
base := c.converAppModelToBase(ctx, app)
policys, err := c.queryApplicationPolicys(ctx, app)
if err != nil {
@@ -145,9 +145,9 @@ func (c *applicationUsecaseImpl) DetailApplication(ctx context.Context, app *mod
for _, p := range policys {
policyNames = append(policyNames, p.Name)
}
var detail = &apisv1.DetailApplicationResponse{
ApplicationBase: *base,
Policies: policyNames,
var detail = &apisv1.DetailApplicationPlanResponse{
ApplicationPlanBase: *base,
Policies: policyNames,
ResourceInfo: apisv1.ApplicationResourceInfo{
ComponentNum: len(components),
},
@@ -157,14 +157,14 @@ func (c *applicationUsecaseImpl) DetailApplication(ctx context.Context, app *mod
}
// PublishApplicationTemplate publish app template
func (c *applicationUsecaseImpl) PublishApplicationTemplate(ctx context.Context, app *model.Application) (*apisv1.ApplicationTemplateBase, error) {
func (c *applicationUsecaseImpl) PublishApplicationTemplate(ctx context.Context, app *model.ApplicationPlan) (*apisv1.ApplicationTemplateBase, error) {
//TODO:
return nil, nil
}
// CreateApplication create application
func (c *applicationUsecaseImpl) CreateApplication(ctx context.Context, req apisv1.CreateApplicationRequest) (*apisv1.ApplicationBase, error) {
application := model.Application{
func (c *applicationUsecaseImpl) CreateApplication(ctx context.Context, req apisv1.CreateApplicationPlanRequest) (*apisv1.ApplicationPlanBase, error) {
application := model.ApplicationPlan{
Name: req.Name,
Alias: req.Alias,
Description: req.Description,
@@ -222,7 +222,7 @@ func (c *applicationUsecaseImpl) CreateApplication(ctx context.Context, req apis
Outputs: step.Outputs,
})
}
_, err := c.workflowUsecase.CreateWorkflow(ctx, &application, apisv1.CreateWorkflowRequest{
_, err := c.workflowUsecase.CreateWorkflow(ctx, &application, apisv1.CreateWorkflowPlanRequest{
AppName: application.PrimaryKey(),
Name: application.Name,
Description: "Created automatically.",
@@ -240,7 +240,7 @@ func (c *applicationUsecaseImpl) CreateApplication(ctx context.Context, req apis
// build-in create env binding policy
if len(req.EnvBind) > 0 {
policy := model.ApplicationPolicy{
policy := model.ApplicationPolicyPlan{
AppPrimaryKey: application.PrimaryKey(),
Name: "env-binds",
Description: "build-in create",
@@ -297,18 +297,18 @@ func (c *applicationUsecaseImpl) CreateApplication(ctx context.Context, req apis
return base, nil
}
func (c *applicationUsecaseImpl) saveApplicationComponent(ctx context.Context, app *model.Application, components []common.ApplicationComponent) error {
func (c *applicationUsecaseImpl) saveApplicationComponent(ctx context.Context, app *model.ApplicationPlan, components []common.ApplicationComponent) error {
var componentModels []datastore.Entity
for _, component := range components {
// TODO: Check whether the component type is supported.
var traits []model.ApplicationTrait
var traits []model.ApplicationTraitPlan
for _, trait := range component.Traits {
properties, err := model.NewJSONStruct(trait.Properties)
if err != nil {
log.Logger.Errorf("parse trait properties failire %w", err)
return bcode.ErrInvalidProperties
}
traits = append(traits, model.ApplicationTrait{
traits = append(traits, model.ApplicationTraitPlan{
Type: trait.Type,
Properties: properties,
})
@@ -318,7 +318,7 @@ func (c *applicationUsecaseImpl) saveApplicationComponent(ctx context.Context, a
log.Logger.Errorf("parse component properties failire %w", err)
return bcode.ErrInvalidProperties
}
componentModel := model.ApplicationComponent{
componentModel := model.ApplicationComponentPlan{
AppPrimaryKey: app.PrimaryKey(),
Name: component.Name,
Type: component.Type,
@@ -336,18 +336,18 @@ func (c *applicationUsecaseImpl) saveApplicationComponent(ctx context.Context, a
return c.ds.BatchAdd(ctx, componentModels)
}
func (c *applicationUsecaseImpl) ListComponents(ctx context.Context, app *model.Application) ([]*apisv1.ComponentBase, error) {
var component = model.ApplicationComponent{
func (c *applicationUsecaseImpl) ListComponents(ctx context.Context, app *model.ApplicationPlan) ([]*apisv1.ComponentPlanBase, error) {
var component = model.ApplicationComponentPlan{
AppPrimaryKey: app.PrimaryKey(),
}
components, err := c.ds.List(ctx, &component, &datastore.ListOptions{})
if err != nil {
return nil, err
}
var list []*apisv1.ComponentBase
var list []*apisv1.ComponentPlanBase
for _, component := range components {
log.Logger.Infof("component name %s", component.PrimaryKey())
pm := component.(*model.ApplicationComponent)
pm := component.(*model.ApplicationComponentPlan)
list = append(list, c.converComponentModelToBase(pm))
}
return list, nil
@@ -355,8 +355,8 @@ func (c *applicationUsecaseImpl) ListComponents(ctx context.Context, app *model.
// DetailComponent detail app component
// TODO: Add status data about the component.
func (c *applicationUsecaseImpl) DetailComponent(ctx context.Context, app *model.Application, policyName string) (*apisv1.DetailComponentResponse, error) {
var component = model.ApplicationComponent{
func (c *applicationUsecaseImpl) DetailComponent(ctx context.Context, app *model.ApplicationPlan, policyName string) (*apisv1.DetailComponentPlanResponse, error) {
var component = model.ApplicationComponentPlan{
AppPrimaryKey: app.PrimaryKey(),
Name: policyName,
}
@@ -364,13 +364,13 @@ func (c *applicationUsecaseImpl) DetailComponent(ctx context.Context, app *model
if err != nil {
return nil, err
}
return &apisv1.DetailComponentResponse{
ApplicationComponent: component,
return &apisv1.DetailComponentPlanResponse{
ApplicationComponentPlan: component,
}, nil
}
func (c *applicationUsecaseImpl) converComponentModelToBase(m *model.ApplicationComponent) *apisv1.ComponentBase {
return &apisv1.ComponentBase{
func (c *applicationUsecaseImpl) converComponentModelToBase(m *model.ApplicationComponentPlan) *apisv1.ComponentPlanBase {
return &apisv1.ComponentPlanBase{
Name: m.Name,
Alias: m.Alias,
Description: m.Description,
@@ -385,7 +385,7 @@ func (c *applicationUsecaseImpl) converComponentModelToBase(m *model.Application
}
// ListPolicies list application policies
func (c *applicationUsecaseImpl) ListPolicies(ctx context.Context, app *model.Application) ([]*apisv1.PolicyBase, error) {
func (c *applicationUsecaseImpl) ListPolicies(ctx context.Context, app *model.ApplicationPlan) ([]*apisv1.PolicyBase, error) {
policies, err := c.queryApplicationPolicys(ctx, app)
if err != nil {
return nil, err
@@ -397,7 +397,7 @@ func (c *applicationUsecaseImpl) ListPolicies(ctx context.Context, app *model.Ap
return list, nil
}
func (c *applicationUsecaseImpl) converPolicyModelToBase(policy *model.ApplicationPolicy) *apisv1.PolicyBase {
func (c *applicationUsecaseImpl) converPolicyModelToBase(policy *model.ApplicationPolicyPlan) *apisv1.PolicyBase {
pb := &apisv1.PolicyBase{
Name: policy.Name,
Type: policy.Type,
@@ -410,7 +410,7 @@ func (c *applicationUsecaseImpl) converPolicyModelToBase(policy *model.Applicati
return pb
}
func (c *applicationUsecaseImpl) saveApplicationPolicy(ctx context.Context, app *model.Application, policys []v1beta1.AppPolicy) error {
func (c *applicationUsecaseImpl) saveApplicationPolicy(ctx context.Context, app *model.ApplicationPlan, policys []v1beta1.AppPolicy) error {
var policyModels []datastore.Entity
for _, policy := range policys {
properties, err := model.NewJSONStruct(policy.Properties)
@@ -418,7 +418,7 @@ func (c *applicationUsecaseImpl) saveApplicationPolicy(ctx context.Context, app
log.Logger.Errorf("parse trait properties failire %w", err)
return bcode.ErrInvalidProperties
}
policyModels = append(policyModels, &model.ApplicationPolicy{
policyModels = append(policyModels, &model.ApplicationPolicyPlan{
AppPrimaryKey: app.PrimaryKey(),
Name: policy.Name,
Type: policy.Type,
@@ -428,8 +428,8 @@ func (c *applicationUsecaseImpl) saveApplicationPolicy(ctx context.Context, app
return c.ds.BatchAdd(ctx, policyModels)
}
func (c *applicationUsecaseImpl) queryApplicationPolicys(ctx context.Context, app *model.Application) (list []*model.ApplicationPolicy, err error) {
var policy = model.ApplicationPolicy{
func (c *applicationUsecaseImpl) queryApplicationPolicys(ctx context.Context, app *model.ApplicationPlan) (list []*model.ApplicationPolicyPlan, err error) {
var policy = model.ApplicationPolicyPlan{
AppPrimaryKey: app.PrimaryKey(),
}
policys, err := c.ds.List(ctx, &policy, &datastore.ListOptions{})
@@ -437,7 +437,7 @@ func (c *applicationUsecaseImpl) queryApplicationPolicys(ctx context.Context, ap
return nil, err
}
for _, policy := range policys {
pm := policy.(*model.ApplicationPolicy)
pm := policy.(*model.ApplicationPolicyPlan)
list = append(list, pm)
}
return
@@ -445,8 +445,8 @@ func (c *applicationUsecaseImpl) queryApplicationPolicys(ctx context.Context, ap
// DetailPolicy detail app policy
// TODO: Add status data about the policy.
func (c *applicationUsecaseImpl) DetailPolicy(ctx context.Context, app *model.Application, policyName string) (*apisv1.DetailPolicyResponse, error) {
var policy = model.ApplicationPolicy{
func (c *applicationUsecaseImpl) DetailPolicy(ctx context.Context, app *model.ApplicationPlan, policyName string) (*apisv1.DetailPolicyResponse, error) {
var policy = model.ApplicationPolicyPlan{
AppPrimaryKey: app.PrimaryKey(),
Name: policyName,
}
@@ -462,7 +462,7 @@ func (c *applicationUsecaseImpl) DetailPolicy(ctx context.Context, app *model.Ap
// Deploy deploy app to cluster
// means to render oam application config and apply to cluster.
// An event record is generated for each deploy.
func (c *applicationUsecaseImpl) Deploy(ctx context.Context, app *model.Application, req apisv1.ApplicationDeployRequest) (*apisv1.ApplicationDeployResponse, error) {
func (c *applicationUsecaseImpl) Deploy(ctx context.Context, app *model.ApplicationPlan, req apisv1.ApplicationDeployRequest) (*apisv1.ApplicationDeployResponse, error) {
// step1: Render oam application
version := utils.GenerateVersion("")
oamApp, err := c.renderOAMApplication(ctx, app, req.WorkflowName, version)
@@ -536,7 +536,7 @@ func (c *applicationUsecaseImpl) Deploy(ctx context.Context, app *model.Applicat
}, nil
}
func (c *applicationUsecaseImpl) renderOAMApplication(ctx context.Context, appMoel *model.Application, reqWorkflowName, version string) (*v1beta1.Application, error) {
func (c *applicationUsecaseImpl) renderOAMApplication(ctx context.Context, appMoel *model.ApplicationPlan, reqWorkflowName, version string) (*v1beta1.Application, error) {
var app = &v1beta1.Application{
TypeMeta: metav1.TypeMeta{
Kind: "Application",
@@ -551,7 +551,7 @@ func (c *applicationUsecaseImpl) renderOAMApplication(ctx context.Context, appMo
},
},
}
var component = model.ApplicationComponent{
var component = model.ApplicationComponentPlan{
AppPrimaryKey: appMoel.PrimaryKey(),
}
components, err := c.ds.List(ctx, &component, &datastore.ListOptions{})
@@ -562,7 +562,7 @@ func (c *applicationUsecaseImpl) renderOAMApplication(ctx context.Context, appMo
return nil, bcode.ErrNoComponent
}
var policy = model.ApplicationPolicy{
var policy = model.ApplicationPolicyPlan{
AppPrimaryKey: appMoel.PrimaryKey(),
}
policies, err := c.ds.List(ctx, &policy, &datastore.ListOptions{})
@@ -571,7 +571,7 @@ func (c *applicationUsecaseImpl) renderOAMApplication(ctx context.Context, appMo
}
for _, entity := range components {
component := entity.(*model.ApplicationComponent)
component := entity.(*model.ApplicationComponentPlan)
var traits []common.ApplicationTrait
for _, trait := range component.Traits {
aTrait := common.ApplicationTrait{
@@ -595,7 +595,7 @@ func (c *applicationUsecaseImpl) renderOAMApplication(ctx context.Context, appMo
}
for _, entity := range policies {
policy := entity.(*model.ApplicationPolicy)
policy := entity.(*model.ApplicationPolicyPlan)
apolicy := v1beta1.AppPolicy{
Name: policy.Name,
Type: policy.Type,
@@ -608,7 +608,7 @@ func (c *applicationUsecaseImpl) renderOAMApplication(ctx context.Context, appMo
// Priority 1 uses the requested workflow as release plan.
// Priority 2 uses the default workflow as release plan.
var workflow *model.Workflow
var workflow *model.WorkflowPlan
if reqWorkflowName != "" {
workflow, err = c.workflowUsecase.GetWorkflow(ctx, reqWorkflowName)
if err != nil {
@@ -642,8 +642,8 @@ func (c *applicationUsecaseImpl) renderOAMApplication(ctx context.Context, appMo
return app, nil
}
func (c *applicationUsecaseImpl) converAppModelToBase(ctx context.Context, app *model.Application) *apisv1.ApplicationBase {
appBeas := &apisv1.ApplicationBase{
func (c *applicationUsecaseImpl) converAppModelToBase(ctx context.Context, app *model.ApplicationPlan) *apisv1.ApplicationPlanBase {
appBeas := &apisv1.ApplicationPlanBase{
Name: app.Name,
Alias: app.Alias,
Namespace: app.Namespace,
@@ -653,7 +653,7 @@ func (c *applicationUsecaseImpl) converAppModelToBase(ctx context.Context, app *
Icon: app.Icon,
Labels: app.Labels,
}
var policy = model.ApplicationPolicy{
var policy = model.ApplicationPolicyPlan{
AppPrimaryKey: app.PrimaryKey(),
Type: string(EnvBindPolicy),
}
@@ -662,7 +662,7 @@ func (c *applicationUsecaseImpl) converAppModelToBase(ctx context.Context, app *
log.Logger.Errorf("query application env binding policy failure %s", err.Error())
}
for _, policyEntity := range policys {
policy := policyEntity.(*model.ApplicationPolicy)
policy := policyEntity.(*model.ApplicationPolicyPlan)
if policy.Properties != nil {
var envBindingSpec v1alpha1.EnvBindingSpec
if err := json.Unmarshal([]byte(policy.Properties.JSON()), &envBindingSpec); err != nil {
@@ -691,7 +691,7 @@ func (c *applicationUsecaseImpl) converAppModelToBase(ctx context.Context, app *
}
// DeleteApplication delete application
func (c *applicationUsecaseImpl) DeleteApplication(ctx context.Context, app *model.Application) error {
func (c *applicationUsecaseImpl) DeleteApplication(ctx context.Context, app *model.ApplicationPlan) error {
// TODO: check app can be deleted
// query all components to deleted
@@ -710,14 +710,14 @@ func (c *applicationUsecaseImpl) DeleteApplication(ctx context.Context, app *mod
}
for _, component := range components {
err := c.ds.Delete(ctx, &model.ApplicationComponent{AppPrimaryKey: app.PrimaryKey(), Name: component.Name})
err := c.ds.Delete(ctx, &model.ApplicationComponentPlan{AppPrimaryKey: app.PrimaryKey(), Name: component.Name})
if err != nil && !errors.Is(err, datastore.ErrRecordNotExist) {
log.Logger.Errorf("delete component %s in app %s failure %s", component.Name, app.Name, err.Error())
}
}
for _, policy := range policies {
err := c.ds.Delete(ctx, &model.ApplicationPolicy{AppPrimaryKey: app.PrimaryKey(), Name: policy.Name})
err := c.ds.Delete(ctx, &model.ApplicationPolicyPlan{AppPrimaryKey: app.PrimaryKey(), Name: policy.Name})
if err != nil && errors.Is(err, datastore.ErrRecordNotExist) {
log.Logger.Errorf("delete policy %s in app %s failure %s", policy.Name, app.Name, err.Error())
}
@@ -726,8 +726,8 @@ func (c *applicationUsecaseImpl) DeleteApplication(ctx context.Context, app *mod
return c.ds.Delete(ctx, app)
}
func (c *applicationUsecaseImpl) AddComponent(ctx context.Context, app *model.Application, com apisv1.CreateComponentRequest) (*apisv1.ComponentBase, error) {
componentModel := model.ApplicationComponent{
func (c *applicationUsecaseImpl) AddComponent(ctx context.Context, app *model.ApplicationPlan, com apisv1.CreateComponentPlanRequest) (*apisv1.ComponentPlanBase, error) {
componentModel := model.ApplicationComponentPlan{
AppPrimaryKey: app.PrimaryKey(),
Description: com.Description,
Labels: com.Labels,
@@ -751,7 +751,7 @@ func (c *applicationUsecaseImpl) AddComponent(ctx context.Context, app *model.Ap
log.Logger.Warnf("add component for app %s failure %s", app.PrimaryKey(), err.Error())
return nil, err
}
return &apisv1.ComponentBase{
return &apisv1.ComponentPlanBase{
Name: componentModel.Name,
Description: componentModel.Description,
Labels: componentModel.Labels,
@@ -764,8 +764,8 @@ func (c *applicationUsecaseImpl) AddComponent(ctx context.Context, app *model.Ap
}, nil
}
func (c *applicationUsecaseImpl) DeleteComponent(ctx context.Context, app *model.Application, componentName string) error {
var component = model.ApplicationComponent{
func (c *applicationUsecaseImpl) DeleteComponent(ctx context.Context, app *model.ApplicationPlan, componentName string) error {
var component = model.ApplicationComponentPlan{
AppPrimaryKey: app.PrimaryKey(),
Name: componentName,
}
@@ -779,8 +779,8 @@ func (c *applicationUsecaseImpl) DeleteComponent(ctx context.Context, app *model
return nil
}
func (c *applicationUsecaseImpl) AddPolicy(ctx context.Context, app *model.Application, createpolicy apisv1.CreatePolicyRequest) (*apisv1.PolicyBase, error) {
policyModel := model.ApplicationPolicy{
func (c *applicationUsecaseImpl) AddPolicy(ctx context.Context, app *model.ApplicationPlan, createpolicy apisv1.CreatePolicyRequest) (*apisv1.PolicyBase, error) {
policyModel := model.ApplicationPolicyPlan{
AppPrimaryKey: app.PrimaryKey(),
Description: createpolicy.Description,
// TODO: Get user information from ctx and assign a value.
@@ -811,8 +811,8 @@ func (c *applicationUsecaseImpl) AddPolicy(ctx context.Context, app *model.Appli
}, nil
}
func (c *applicationUsecaseImpl) DeletePolicy(ctx context.Context, app *model.Application, policyName string) error {
var policy = model.ApplicationPolicy{
func (c *applicationUsecaseImpl) DeletePolicy(ctx context.Context, app *model.ApplicationPlan, policyName string) error {
var policy = model.ApplicationPolicyPlan{
AppPrimaryKey: app.PrimaryKey(),
Name: policyName,
}
@@ -826,8 +826,8 @@ func (c *applicationUsecaseImpl) DeletePolicy(ctx context.Context, app *model.Ap
return nil
}
func (c *applicationUsecaseImpl) UpdatePolicy(ctx context.Context, app *model.Application, policyName string, policyUpdate apisv1.UpdatePolicyRequest) (*apisv1.DetailPolicyResponse, error) {
var policy = model.ApplicationPolicy{
func (c *applicationUsecaseImpl) UpdatePolicy(ctx context.Context, app *model.ApplicationPlan, policyName string, policyUpdate apisv1.UpdatePolicyRequest) (*apisv1.DetailPolicyResponse, error) {
var policy = model.ApplicationPolicyPlan{
AppPrimaryKey: app.PrimaryKey(),
Name: policyName,
}
@@ -50,7 +50,7 @@ var _ = Describe("Test application usecase function", func() {
})
It("Test CreateApplication function", func() {
By("test sample create")
req := v1.CreateApplicationRequest{
req := v1.CreateApplicationPlanRequest{
Name: "test-app",
Namespace: "test-app-namespace",
Description: "this is a test app",
@@ -66,7 +66,7 @@ var _ = Describe("Test application usecase function", func() {
By("test with oam yaml config create")
bs, err := ioutil.ReadFile("./testdata/example-app.yaml")
Expect(err).Should(Succeed())
req = v1.CreateApplicationRequest{
req = v1.CreateApplicationPlanRequest{
Name: "test-app-sadasd",
Namespace: "test-app-namespace",
Description: "this is a test app",
@@ -78,7 +78,7 @@ var _ = Describe("Test application usecase function", func() {
Expect(err).Should(BeNil())
Expect(cmp.Diff(base.Description, req.Description)).Should(BeEmpty())
req = v1.CreateApplicationRequest{
req = v1.CreateApplicationPlanRequest{
Name: "test-app-sadasd2",
Namespace: "test-app-namespace",
Description: "this is a test app",
@@ -93,7 +93,7 @@ var _ = Describe("Test application usecase function", func() {
bs, err = ioutil.ReadFile("./testdata/example-app-error.yaml")
Expect(err).Should(Succeed())
req = v1.CreateApplicationRequest{
req = v1.CreateApplicationPlanRequest{
Name: "test-app-sadasd3",
Namespace: "test-app-namespace",
Description: "this is a test app",
@@ -106,7 +106,7 @@ var _ = Describe("Test application usecase function", func() {
Expect(equal).Should(BeTrue())
By("Test create app with env binding")
req = v1.CreateApplicationRequest{
req = v1.CreateApplicationPlanRequest{
Name: "test-app-sadasd4",
Namespace: "test-app-namespace",
Description: "this is a test app",
@@ -140,7 +140,7 @@ var _ = Describe("Test application usecase function", func() {
})
It("Test ListApplications function", func() {
apps, err := appUsecase.ListApplications(context.TODO(), v1.ListApplicatioOptions{})
apps, err := appUsecase.ListApplications(context.TODO(), v1.ListApplicatioPlanOptions{})
Expect(err).Should(BeNil())
Expect(cmp.Diff(len(apps), 3)).Should(BeEmpty())
})
@@ -217,7 +217,7 @@ var _ = Describe("Test application usecase function", func() {
appModel, err := appUsecase.GetApplication(context.TODO(), "test-app-sadasd")
Expect(err).Should(BeNil())
Expect(cmp.Diff(appModel.Namespace, "test-app-namespace")).Should(BeEmpty())
base, err := appUsecase.AddComponent(context.TODO(), appModel, v1.CreateComponentRequest{
base, err := appUsecase.AddComponent(context.TODO(), appModel, v1.CreateComponentPlanRequest{
Name: "test2",
Description: "this is a test2 component",
Labels: map[string]string{},
+23 -23
View File
@@ -35,13 +35,13 @@ import (
// WorkflowUsecase workflow manage api
type WorkflowUsecase interface {
ListApplicationWorkflow(ctx context.Context, app *model.Application, enable *bool) ([]*apisv1.WorkflowBase, error)
GetWorkflow(ctx context.Context, workflowName string) (*model.Workflow, error)
DetailWorkflow(ctx context.Context, workflow *model.Workflow) (*apisv1.DetailWorkflowResponse, error)
GetApplicationDefaultWorkflow(ctx context.Context, app *model.Application) (*model.Workflow, error)
ListApplicationWorkflow(ctx context.Context, app *model.ApplicationPlan, enable *bool) ([]*apisv1.WorkflowPlanBase, error)
GetWorkflow(ctx context.Context, workflowName string) (*model.WorkflowPlan, error)
DetailWorkflow(ctx context.Context, workflow *model.WorkflowPlan) (*apisv1.DetailWorkflowPlanResponse, error)
GetApplicationDefaultWorkflow(ctx context.Context, app *model.ApplicationPlan) (*model.WorkflowPlan, error)
DeleteWorkflow(ctx context.Context, workflowName string) error
CreateWorkflow(ctx context.Context, app *model.Application, req apisv1.CreateWorkflowRequest) (*apisv1.DetailWorkflowResponse, error)
UpdateWorkflow(ctx context.Context, workflow *model.Workflow, req apisv1.UpdateWorkflowRequest) (*apisv1.DetailWorkflowResponse, error)
CreateWorkflow(ctx context.Context, app *model.ApplicationPlan, req apisv1.CreateWorkflowPlanRequest) (*apisv1.DetailWorkflowPlanResponse, error)
UpdateWorkflow(ctx context.Context, workflow *model.WorkflowPlan, req apisv1.UpdateWorkflowPlanRequest) (*apisv1.DetailWorkflowPlanResponse, error)
ListWorkflowRecords(ctx context.Context, workflowName string, page, pageSize int) (*apisv1.ListWorkflowRecordsResponse, error)
DetailWorkflowRecord(ctx context.Context, workflowName, recordName string) (*apisv1.DetailWorkflowRecordResponse, error)
}
@@ -57,7 +57,7 @@ type workflowUsecaseImpl struct {
// DeleteWorkflow delete application workflow
func (w *workflowUsecaseImpl) DeleteWorkflow(ctx context.Context, workflowName string) error {
var workflow = &model.Workflow{
var workflow = &model.WorkflowPlan{
Name: workflowName,
}
if err := w.ds.Delete(ctx, workflow); err != nil {
@@ -69,7 +69,7 @@ func (w *workflowUsecaseImpl) DeleteWorkflow(ctx context.Context, workflowName s
return nil
}
func (w *workflowUsecaseImpl) CreateWorkflow(ctx context.Context, app *model.Application, req apisv1.CreateWorkflowRequest) (*apisv1.DetailWorkflowResponse, error) {
func (w *workflowUsecaseImpl) CreateWorkflow(ctx context.Context, app *model.ApplicationPlan, req apisv1.CreateWorkflowPlanRequest) (*apisv1.DetailWorkflowPlanResponse, error) {
var steps []model.WorkflowStep
for _, step := range req.Steps {
properties, err := model.NewJSONStructByString(step.Properties)
@@ -86,7 +86,7 @@ func (w *workflowUsecaseImpl) CreateWorkflow(ctx context.Context, app *model.App
})
}
// It is allowed to set multiple workflows as default, and only one takes effect.
var workflow = model.Workflow{
var workflow = model.WorkflowPlan{
Steps: steps,
Name: req.Name,
Enable: req.Enable,
@@ -100,7 +100,7 @@ func (w *workflowUsecaseImpl) CreateWorkflow(ctx context.Context, app *model.App
return w.DetailWorkflow(ctx, &workflow)
}
func (w *workflowUsecaseImpl) UpdateWorkflow(ctx context.Context, workflow *model.Workflow, req apisv1.UpdateWorkflowRequest) (*apisv1.DetailWorkflowResponse, error) {
func (w *workflowUsecaseImpl) UpdateWorkflow(ctx context.Context, workflow *model.WorkflowPlan, req apisv1.UpdateWorkflowPlanRequest) (*apisv1.DetailWorkflowPlanResponse, error) {
var steps []model.WorkflowStep
for _, step := range req.Steps {
properties, err := model.NewJSONStructByString(step.Properties)
@@ -128,7 +128,7 @@ func (w *workflowUsecaseImpl) UpdateWorkflow(ctx context.Context, workflow *mode
}
// DetailWorkflow detail workflow
func (w *workflowUsecaseImpl) DetailWorkflow(ctx context.Context, workflow *model.Workflow) (*apisv1.DetailWorkflowResponse, error) {
func (w *workflowUsecaseImpl) DetailWorkflow(ctx context.Context, workflow *model.WorkflowPlan) (*apisv1.DetailWorkflowPlanResponse, error) {
var steps []apisv1.WorkflowStep
for _, step := range workflow.Steps {
apiStep := apisv1.WorkflowStep{
@@ -143,8 +143,8 @@ func (w *workflowUsecaseImpl) DetailWorkflow(ctx context.Context, workflow *mode
}
steps = append(steps, apiStep)
}
return &apisv1.DetailWorkflowResponse{
WorkflowBase: apisv1.WorkflowBase{
return &apisv1.DetailWorkflowPlanResponse{
WorkflowPlanBase: apisv1.WorkflowPlanBase{
Name: workflow.Name,
Description: workflow.Description,
Enable: workflow.Enable,
@@ -157,8 +157,8 @@ func (w *workflowUsecaseImpl) DetailWorkflow(ctx context.Context, workflow *mode
}
// GetWorkflow get workflow model
func (w *workflowUsecaseImpl) GetWorkflow(ctx context.Context, workflowName string) (*model.Workflow, error) {
var workflow = model.Workflow{
func (w *workflowUsecaseImpl) GetWorkflow(ctx context.Context, workflowName string) (*model.WorkflowPlan, error) {
var workflow = model.WorkflowPlan{
Name: workflowName,
}
if err := w.ds.Get(ctx, &workflow); err != nil {
@@ -168,8 +168,8 @@ func (w *workflowUsecaseImpl) GetWorkflow(ctx context.Context, workflowName stri
}
// ListApplicationWorkflow list application workflows
func (w *workflowUsecaseImpl) ListApplicationWorkflow(ctx context.Context, app *model.Application, enable *bool) ([]*apisv1.WorkflowBase, error) {
var workflow = model.Workflow{
func (w *workflowUsecaseImpl) ListApplicationWorkflow(ctx context.Context, app *model.ApplicationPlan, enable *bool) ([]*apisv1.WorkflowPlanBase, error) {
var workflow = model.WorkflowPlan{
AppPrimaryKey: app.PrimaryKey(),
}
if enable != nil {
@@ -179,10 +179,10 @@ func (w *workflowUsecaseImpl) ListApplicationWorkflow(ctx context.Context, app *
if err != nil {
return nil, err
}
var list []*apisv1.WorkflowBase
var list []*apisv1.WorkflowPlanBase
for _, workflow := range workflows {
wm := workflow.(*model.Workflow)
list = append(list, &apisv1.WorkflowBase{
wm := workflow.(*model.WorkflowPlan)
list = append(list, &apisv1.WorkflowPlanBase{
Name: wm.Name,
Description: wm.Description,
Enable: wm.Enable,
@@ -195,8 +195,8 @@ func (w *workflowUsecaseImpl) ListApplicationWorkflow(ctx context.Context, app *
}
// GetApplicationDefaultWorkflow get application default workflow
func (w *workflowUsecaseImpl) GetApplicationDefaultWorkflow(ctx context.Context, app *model.Application) (*model.Workflow, error) {
var workflow = model.Workflow{
func (w *workflowUsecaseImpl) GetApplicationDefaultWorkflow(ctx context.Context, app *model.ApplicationPlan) (*model.WorkflowPlan, error) {
var workflow = model.WorkflowPlan{
AppPrimaryKey: app.PrimaryKey(),
Default: true,
}
@@ -205,7 +205,7 @@ func (w *workflowUsecaseImpl) GetApplicationDefaultWorkflow(ctx context.Context,
return nil, err
}
if len(workflows) > 0 {
return workflows[0].(*model.Workflow), nil
return workflows[0].(*model.WorkflowPlan), nil
}
return nil, bcode.ErrWorkflowNoDefault
}
+5 -5
View File
@@ -40,22 +40,22 @@ var _ = Describe("Test workflow usecase functions", func() {
workflowUsecase = &workflowUsecaseImpl{ds: ds}
})
It("Test CreateWorkflow function", func() {
req := apisv1.CreateWorkflowRequest{
req := apisv1.CreateWorkflowPlanRequest{
Name: "test-workflow-1",
Description: "this is a workflow",
}
base, err := workflowUsecase.CreateWorkflow(context.TODO(), &model.Application{
base, err := workflowUsecase.CreateWorkflow(context.TODO(), &model.ApplicationPlan{
Name: "test-app",
}, req)
Expect(err).Should(BeNil())
Expect(cmp.Diff(base.Name, req.Name)).Should(BeEmpty())
req = apisv1.CreateWorkflowRequest{
req = apisv1.CreateWorkflowPlanRequest{
Name: "test-workflow-2",
Description: "this is test workflow",
Default: true,
}
base, err = workflowUsecase.CreateWorkflow(context.TODO(), &model.Application{
base, err = workflowUsecase.CreateWorkflow(context.TODO(), &model.ApplicationPlan{
Name: "test-app",
}, req)
Expect(err).Should(BeNil())
@@ -63,7 +63,7 @@ var _ = Describe("Test workflow usecase functions", func() {
})
It("Test GetApplicationDefaultWorkflow function", func() {
workflow, err := workflowUsecase.GetApplicationDefaultWorkflow(context.TODO(), &model.Application{
workflow, err := workflowUsecase.GetApplicationDefaultWorkflow(context.TODO(), &model.ApplicationPlan{
Name: "test-app",
})
Expect(err).Should(BeNil())
+39 -39
View File
@@ -42,7 +42,7 @@ func NewApplicationWebService(applicationUsecase usecase.ApplicationUsecase) Web
func (c *applicationWebService) GetWebService() *restful.WebService {
ws := new(restful.WebService)
ws.Path(versionPrefix+"/applications").
ws.Path(versionPrefix+"/applicationplans").
Consumes(restful.MIME_XML, restful.MIME_JSON).
Produces(restful.MIME_JSON, restful.MIME_XML).
Doc("api for application manage")
@@ -55,17 +55,17 @@ func (c *applicationWebService) GetWebService() *restful.WebService {
Param(ws.QueryParameter("query", "Fuzzy search based on name or description").DataType("string")).
Param(ws.QueryParameter("namespace", "Namespace-based search").DataType("string")).
Param(ws.QueryParameter("cluster", "Cluster-based search").DataType("string")).
Returns(200, "", apis.ListApplicationResponse{}).
Returns(200, "", apis.ListApplicationPlanResponse{}).
Returns(400, "", bcode.Bcode{}).
Writes(apis.ListApplicationResponse{}))
Writes(apis.ListApplicationPlanResponse{}))
ws.Route(ws.POST("/").To(c.createApplication).
Doc("create one application").
Metadata(restfulspec.KeyOpenAPITags, tags).
Reads(apis.CreateApplicationRequest{}).
Returns(200, "", apis.ApplicationBase{}).
Reads(apis.CreateApplicationPlanRequest{}).
Returns(200, "", apis.ApplicationPlanBase{}).
Returns(400, "", bcode.Bcode{}).
Writes(apis.ApplicationBase{}))
Writes(apis.ApplicationPlanBase{}))
ws.Route(ws.DELETE("/{name}").To(c.deleteApplication).
Doc("delete one application").
@@ -81,9 +81,9 @@ func (c *applicationWebService) GetWebService() *restful.WebService {
Metadata(restfulspec.KeyOpenAPITags, tags).
Filter(c.appCheckFilter).
Param(ws.PathParameter("name", "identifier of the application").DataType("string")).
Returns(200, "", apis.DetailApplicationResponse{}).
Returns(200, "", apis.DetailApplicationPlanResponse{}).
Returns(400, "", bcode.Bcode{}).
Writes(apis.DetailApplicationResponse{}))
Writes(apis.DetailApplicationPlanResponse{}))
ws.Route(ws.POST("/{name}/template").To(c.publishApplicationTemplate).
Doc("create one application template").
@@ -104,34 +104,34 @@ func (c *applicationWebService) GetWebService() *restful.WebService {
Returns(400, "", bcode.Bcode{}).
Writes(apis.ApplicationDeployResponse{}))
ws.Route(ws.GET("/{name}/components").To(c.listApplicationComponents).
Doc("gets the component topology of the application").
ws.Route(ws.GET("/{name}/componentplans").To(c.listApplicationComponents).
Doc("gets the componentplan topology of the application").
Filter(c.appCheckFilter).
Param(ws.PathParameter("name", "identifier of the application").DataType("string")).
Param(ws.PathParameter("cluster", "list components that deployed in define cluster").DataType("string")).
Param(ws.QueryParameter("envName", "list components that deployed in define env").DataType("string")).
Metadata(restfulspec.KeyOpenAPITags, tags).
Returns(200, "", apis.ComponentListResponse{}).
Returns(200, "", apis.ComponentPlanListResponse{}).
Returns(400, "", bcode.Bcode{}).
Writes(apis.ComponentListResponse{}))
Writes(apis.ComponentPlanListResponse{}))
ws.Route(ws.POST("/{name}/components").To(c.createComponent).
Doc("create component for application").
ws.Route(ws.POST("/{name}/componentplans").To(c.createComponent).
Doc("create component plan for application plan").
Filter(c.appCheckFilter).
Param(ws.PathParameter("name", "identifier of the application").DataType("string")).
Metadata(restfulspec.KeyOpenAPITags, tags).
Reads(apis.CreateComponentRequest{}).
Returns(200, "", apis.ComponentBase{}).
Reads(apis.CreateComponentPlanRequest{}).
Returns(200, "", apis.ComponentPlanBase{}).
Returns(400, "", bcode.Bcode{}).
Writes(apis.ComponentBase{}))
Writes(apis.ComponentPlanBase{}))
ws.Route(ws.GET("/{name}/components/{componentName}").To(c.detailComponent).
Doc("detail component for application").
ws.Route(ws.GET("/{name}/componentplans/{componentName}").To(c.detailComponent).
Doc("detail component plan for application plan").
Filter(c.appCheckFilter).
Param(ws.PathParameter("name", "identifier of the application").DataType("string")).
Metadata(restfulspec.KeyOpenAPITags, tags).
Returns(200, "", apis.DetailComponentResponse{}).
Returns(200, "", apis.DetailComponentPlanResponse{}).
Returns(400, "", bcode.Bcode{}).
Writes(apis.DetailComponentResponse{}))
Writes(apis.DetailComponentPlanResponse{}))
ws.Route(ws.GET("/{name}/policies").To(c.listApplicationPolicies).
Doc("list policy for application").
@@ -197,7 +197,7 @@ func (c *applicationWebService) appCheckFilter(req *restful.Request, res *restfu
func (c *applicationWebService) createApplication(req *restful.Request, res *restful.Response) {
// Verify the validity of parameters
var createReq apis.CreateApplicationRequest
var createReq apis.CreateApplicationPlanRequest
if err := req.ReadEntity(&createReq); err != nil {
bcode.ReturnError(req, res, err)
return
@@ -222,7 +222,7 @@ func (c *applicationWebService) createApplication(req *restful.Request, res *res
}
func (c *applicationWebService) listApplications(req *restful.Request, res *restful.Response) {
apps, err := c.applicationUsecase.ListApplications(req.Request.Context(), apis.ListApplicatioOptions{
apps, err := c.applicationUsecase.ListApplications(req.Request.Context(), apis.ListApplicatioPlanOptions{
Namespace: req.QueryParameter("namespace"),
Cluster: req.QueryParameter("cluster"),
Query: req.QueryParameter("query"),
@@ -231,14 +231,14 @@ func (c *applicationWebService) listApplications(req *restful.Request, res *rest
bcode.ReturnError(req, res, err)
return
}
if err := res.WriteEntity(apis.ListApplicationResponse{Applications: apps}); err != nil {
if err := res.WriteEntity(apis.ListApplicationPlanResponse{ApplicationPlans: apps}); err != nil {
bcode.ReturnError(req, res, err)
return
}
}
func (c *applicationWebService) detailApplication(req *restful.Request, res *restful.Response) {
app := req.Request.Context().Value(&apis.CtxKeyApplication).(*model.Application)
app := req.Request.Context().Value(&apis.CtxKeyApplication).(*model.ApplicationPlan)
detail, err := c.applicationUsecase.DetailApplication(req.Request.Context(), app)
if err != nil {
bcode.ReturnError(req, res, err)
@@ -251,7 +251,7 @@ func (c *applicationWebService) detailApplication(req *restful.Request, res *res
}
func (c *applicationWebService) publishApplicationTemplate(req *restful.Request, res *restful.Response) {
app := req.Request.Context().Value(&apis.CtxKeyApplication).(*model.Application)
app := req.Request.Context().Value(&apis.CtxKeyApplication).(*model.ApplicationPlan)
base, err := c.applicationUsecase.PublishApplicationTemplate(req.Request.Context(), app)
if err != nil {
bcode.ReturnError(req, res, err)
@@ -265,7 +265,7 @@ func (c *applicationWebService) publishApplicationTemplate(req *restful.Request,
// deployApplication TODO: return event model
func (c *applicationWebService) deployApplication(req *restful.Request, res *restful.Response) {
app := req.Request.Context().Value(&apis.CtxKeyApplication).(*model.Application)
app := req.Request.Context().Value(&apis.CtxKeyApplication).(*model.ApplicationPlan)
// Verify the validity of parameters
var createReq apis.ApplicationDeployRequest
if err := req.ReadEntity(&createReq); err != nil {
@@ -288,7 +288,7 @@ func (c *applicationWebService) deployApplication(req *restful.Request, res *res
}
func (c *applicationWebService) deleteApplication(req *restful.Request, res *restful.Response) {
app := req.Request.Context().Value(&apis.CtxKeyApplication).(*model.Application)
app := req.Request.Context().Value(&apis.CtxKeyApplication).(*model.ApplicationPlan)
err := c.applicationUsecase.DeleteApplication(req.Request.Context(), app)
if err != nil {
bcode.ReturnError(req, res, err)
@@ -301,22 +301,22 @@ func (c *applicationWebService) deleteApplication(req *restful.Request, res *res
}
func (c *applicationWebService) listApplicationComponents(req *restful.Request, res *restful.Response) {
app := req.Request.Context().Value(&apis.CtxKeyApplication).(*model.Application)
app := req.Request.Context().Value(&apis.CtxKeyApplication).(*model.ApplicationPlan)
components, err := c.applicationUsecase.ListComponents(req.Request.Context(), app)
if err != nil {
bcode.ReturnError(req, res, err)
return
}
if err := res.WriteEntity(apis.ComponentListResponse{Components: components}); err != nil {
if err := res.WriteEntity(apis.ComponentPlanListResponse{ComponentPlans: components}); err != nil {
bcode.ReturnError(req, res, err)
return
}
}
func (c *applicationWebService) createComponent(req *restful.Request, res *restful.Response) {
app := req.Request.Context().Value(&apis.CtxKeyApplication).(*model.Application)
app := req.Request.Context().Value(&apis.CtxKeyApplication).(*model.ApplicationPlan)
// Verify the validity of parameters
var createReq apis.CreateComponentRequest
var createReq apis.CreateComponentPlanRequest
if err := req.ReadEntity(&createReq); err != nil {
bcode.ReturnError(req, res, err)
return
@@ -337,7 +337,7 @@ func (c *applicationWebService) createComponent(req *restful.Request, res *restf
}
func (c *applicationWebService) detailComponent(req *restful.Request, res *restful.Response) {
app := req.Request.Context().Value(&apis.CtxKeyApplication).(*model.Application)
app := req.Request.Context().Value(&apis.CtxKeyApplication).(*model.ApplicationPlan)
detail, err := c.applicationUsecase.DetailComponent(req.Request.Context(), app, req.PathParameter("componentName"))
if err != nil {
bcode.ReturnError(req, res, err)
@@ -350,7 +350,7 @@ func (c *applicationWebService) detailComponent(req *restful.Request, res *restf
}
func (c *applicationWebService) createApplicationPolicy(req *restful.Request, res *restful.Response) {
app := req.Request.Context().Value(&apis.CtxKeyApplication).(*model.Application)
app := req.Request.Context().Value(&apis.CtxKeyApplication).(*model.ApplicationPlan)
// Verify the validity of parameters
var createReq apis.CreatePolicyRequest
if err := req.ReadEntity(&createReq); err != nil {
@@ -373,7 +373,7 @@ func (c *applicationWebService) createApplicationPolicy(req *restful.Request, re
}
func (c *applicationWebService) listApplicationPolicies(req *restful.Request, res *restful.Response) {
app := req.Request.Context().Value(&apis.CtxKeyApplication).(*model.Application)
app := req.Request.Context().Value(&apis.CtxKeyApplication).(*model.ApplicationPlan)
policies, err := c.applicationUsecase.ListPolicies(req.Request.Context(), app)
if err != nil {
bcode.ReturnError(req, res, err)
@@ -386,7 +386,7 @@ func (c *applicationWebService) listApplicationPolicies(req *restful.Request, re
}
func (c *applicationWebService) detailApplicationPolicy(req *restful.Request, res *restful.Response) {
app := req.Request.Context().Value(&apis.CtxKeyApplication).(*model.Application)
app := req.Request.Context().Value(&apis.CtxKeyApplication).(*model.ApplicationPlan)
detail, err := c.applicationUsecase.DetailPolicy(req.Request.Context(), app, req.PathParameter("policyName"))
if err != nil {
bcode.ReturnError(req, res, err)
@@ -399,7 +399,7 @@ func (c *applicationWebService) detailApplicationPolicy(req *restful.Request, re
}
func (c *applicationWebService) deleteApplicationPolicy(req *restful.Request, res *restful.Response) {
app := req.Request.Context().Value(&apis.CtxKeyApplication).(*model.Application)
app := req.Request.Context().Value(&apis.CtxKeyApplication).(*model.ApplicationPlan)
err := c.applicationUsecase.DeletePolicy(req.Request.Context(), app, req.PathParameter("policyName"))
if err != nil {
bcode.ReturnError(req, res, err)
@@ -412,7 +412,7 @@ func (c *applicationWebService) deleteApplicationPolicy(req *restful.Request, re
}
func (c *applicationWebService) updateApplicationPolicy(req *restful.Request, res *restful.Response) {
app := req.Request.Context().Value(&apis.CtxKeyApplication).(*model.Application)
app := req.Request.Context().Value(&apis.CtxKeyApplication).(*model.ApplicationPlan)
// Verify the validity of parameters
var updateReq apis.UpdatePolicyRequest
if err := req.ReadEntity(&updateReq); err != nil {
@@ -27,26 +27,26 @@ import (
var _ = Describe("Test validate function", func() {
It("Test check name validate ", func() {
Expect(cmp.Diff(nameRegexp.MatchString("///Asd asda "), false)).Should(BeEmpty())
var app0 = apisv1.CreateApplicationRequest{
var app0 = apisv1.CreateApplicationPlanRequest{
Name: "a",
Namespace: "namespace",
}
err := validate.Struct(&app0)
Expect(err).ShouldNot(BeNil())
var app1 = apisv1.CreateApplicationRequest{
var app1 = apisv1.CreateApplicationPlanRequest{
Name: "Asdasd",
Namespace: "namespace",
}
err = validate.Struct(&app1)
Expect(err).ShouldNot(BeNil())
var app2 = apisv1.CreateApplicationRequest{
var app2 = apisv1.CreateApplicationPlanRequest{
Name: "asdasd asdasd ++",
Namespace: "namespace",
}
err = validate.Struct(&app2)
Expect(err).ShouldNot(BeNil())
var app3 = apisv1.CreateApplicationRequest{
var app3 = apisv1.CreateApplicationPlanRequest{
Name: "asdasd",
Namespace: "namespace",
}
+14 -14
View File
@@ -46,7 +46,7 @@ type workflowWebService struct {
func (w *workflowWebService) GetWebService() *restful.WebService {
ws := new(restful.WebService)
ws.Path(versionPrefix+"/workflows").
ws.Path(versionPrefix+"/workflowplans").
Consumes(restful.MIME_XML, restful.MIME_JSON).
Produces(restful.MIME_JSON, restful.MIME_XML).
Doc("api for cluster manage")
@@ -58,31 +58,31 @@ func (w *workflowWebService) GetWebService() *restful.WebService {
Param(ws.QueryParameter("appName", "identifier of the application.").DataType("string")).
Param(ws.QueryParameter("enable", "query based on enable status").DataType("boolean")).
Metadata(restfulspec.KeyOpenAPITags, tags).
Writes(apis.ListWorkflowResponse{}).Do(returns200, returns500))
Writes(apis.ListWorkflowPlanResponse{}).Do(returns200, returns500))
ws.Route(ws.POST("/").To(w.createApplicationWorkflow).
Doc("create application workflow").
Metadata(restfulspec.KeyOpenAPITags, tags).
Reads(apis.CreateWorkflowRequest{}).
Returns(200, "create success", apis.DetailWorkflowResponse{}).
Reads(apis.CreateWorkflowPlanRequest{}).
Returns(200, "create success", apis.DetailWorkflowPlanResponse{}).
Returns(400, "create failure", bcode.Bcode{}).
Writes(apis.DetailWorkflowResponse{}).Do(returns200, returns500))
Writes(apis.DetailWorkflowPlanResponse{}).Do(returns200, returns500))
ws.Route(ws.GET("/{name}").To(w.detailWorkflow).
Doc("detail application workflow").
Param(ws.PathParameter("name", "identifier of the workflow.").DataType("string")).
Metadata(restfulspec.KeyOpenAPITags, tags).
Filter(w.workflowCheckFilter).
Returns(200, "create success", apis.DetailWorkflowResponse{}).
Writes(apis.DetailWorkflowResponse{}).Do(returns200, returns500))
Returns(200, "create success", apis.DetailWorkflowPlanResponse{}).
Writes(apis.DetailWorkflowPlanResponse{}).Do(returns200, returns500))
ws.Route(ws.PUT("/{name}").To(w.updateWorkflow).
Doc("update application workflow config").
Metadata(restfulspec.KeyOpenAPITags, tags).
Filter(w.workflowCheckFilter).
Param(ws.PathParameter("name", "identifier of the workflow").DataType("string")).
Reads(apis.UpdateWorkflowRequest{}).
Writes(apis.DetailWorkflowResponse{}).Do(returns200, returns500))
Reads(apis.UpdateWorkflowPlanRequest{}).
Writes(apis.DetailWorkflowPlanResponse{}).Do(returns200, returns500))
ws.Route(ws.DELETE("/{name}").To(w.deleteWorkflow).
Doc("deletet workflow").
@@ -140,7 +140,7 @@ func (w *workflowWebService) listApplicationWorkflows(req *restful.Request, res
bcode.ReturnError(req, res, err)
return
}
if err := res.WriteEntity(apis.ListWorkflowResponse{Workflows: workflows}); err != nil {
if err := res.WriteEntity(apis.ListWorkflowPlanResponse{WorkflowPlans: workflows}); err != nil {
bcode.ReturnError(req, res, err)
return
}
@@ -148,7 +148,7 @@ func (w *workflowWebService) listApplicationWorkflows(req *restful.Request, res
func (w *workflowWebService) createApplicationWorkflow(req *restful.Request, res *restful.Response) {
// Verify the validity of parameters
var createReq apis.CreateWorkflowRequest
var createReq apis.CreateWorkflowPlanRequest
if err := req.ReadEntity(&createReq); err != nil {
bcode.ReturnError(req, res, err)
return
@@ -178,7 +178,7 @@ func (w *workflowWebService) createApplicationWorkflow(req *restful.Request, res
}
func (w *workflowWebService) detailWorkflow(req *restful.Request, res *restful.Response) {
workflow := req.Request.Context().Value(&apis.CtxKeyWorkflow).(*model.Workflow)
workflow := req.Request.Context().Value(&apis.CtxKeyWorkflow).(*model.WorkflowPlan)
detail, err := w.workflowUsecase.DetailWorkflow(req.Request.Context(), workflow)
if err != nil {
bcode.ReturnError(req, res, err)
@@ -191,9 +191,9 @@ func (w *workflowWebService) detailWorkflow(req *restful.Request, res *restful.R
}
func (w *workflowWebService) updateWorkflow(req *restful.Request, res *restful.Response) {
workflow := req.Request.Context().Value(&apis.CtxKeyWorkflow).(*model.Workflow)
workflow := req.Request.Context().Value(&apis.CtxKeyWorkflow).(*model.WorkflowPlan)
// Verify the validity of parameters
var updateReq apis.UpdateWorkflowRequest
var updateReq apis.UpdateWorkflowPlanRequest
if err := req.ReadEntity(&updateReq); err != nil {
bcode.ReturnError(req, res, err)
return
+25 -25
View File
@@ -36,7 +36,7 @@ import (
var _ = Describe("Test application rest api", func() {
It("Test create app", func() {
defer GinkgoRecover()
var req = apisv1.CreateApplicationRequest{
var req = apisv1.CreateApplicationPlanRequest{
Name: "test-app-sadasd",
Namespace: "test-app-namespace",
Description: "this is a test app",
@@ -48,13 +48,13 @@ var _ = Describe("Test application rest api", func() {
}
bodyByte, err := json.Marshal(req)
Expect(err).ShouldNot(HaveOccurred())
res, err := http.Post("http://127.0.0.1:8000/api/v1/applications", "application/json", bytes.NewBuffer(bodyByte))
res, err := http.Post("http://127.0.0.1:8000/api/v1/applicationplans", "application/json", bytes.NewBuffer(bodyByte))
Expect(err).ShouldNot(HaveOccurred())
Expect(res).ShouldNot(BeNil())
Expect(cmp.Diff(res.StatusCode, 200)).Should(BeEmpty())
Expect(res.Body).ShouldNot(BeNil())
defer res.Body.Close()
var appBase apisv1.ApplicationBase
var appBase apisv1.ApplicationPlanBase
err = json.NewDecoder(res.Body).Decode(&appBase)
Expect(err).ShouldNot(HaveOccurred())
Expect(cmp.Diff(appBase.Name, req.Name)).Should(BeEmpty())
@@ -66,7 +66,7 @@ var _ = Describe("Test application rest api", func() {
It("Test delete app", func() {
defer GinkgoRecover()
req, err := http.NewRequest(http.MethodDelete, "http://127.0.0.1:8000/api/v1/applications/test-app-sadasd", nil)
req, err := http.NewRequest(http.MethodDelete, "http://127.0.0.1:8000/api/v1/applicationplans/test-app-sadasd", nil)
Expect(err).ShouldNot(HaveOccurred())
res, err := http.DefaultClient.Do(req)
Expect(err).ShouldNot(HaveOccurred())
@@ -78,7 +78,7 @@ var _ = Describe("Test application rest api", func() {
defer GinkgoRecover()
bs, err := ioutil.ReadFile("./testdata/example-app.yaml")
Expect(err).Should(Succeed())
var req = apisv1.CreateApplicationRequest{
var req = apisv1.CreateApplicationPlanRequest{
Name: "test-app-sadasd",
Namespace: "test-app-namespace",
Description: "this is a test app",
@@ -88,13 +88,13 @@ var _ = Describe("Test application rest api", func() {
}
bodyByte, err := json.Marshal(req)
Expect(err).ShouldNot(HaveOccurred())
res, err := http.Post("http://127.0.0.1:8000/api/v1/applications", "application/json", bytes.NewBuffer(bodyByte))
res, err := http.Post("http://127.0.0.1:8000/api/v1/applicationplans", "application/json", bytes.NewBuffer(bodyByte))
Expect(err).ShouldNot(HaveOccurred())
Expect(res).ShouldNot(BeNil())
Expect(cmp.Diff(res.StatusCode, 200)).Should(BeEmpty())
Expect(res.Body).ShouldNot(BeNil())
defer res.Body.Close()
var appBase apisv1.ApplicationBase
var appBase apisv1.ApplicationPlanBase
err = json.NewDecoder(res.Body).Decode(&appBase)
Expect(err).ShouldNot(HaveOccurred())
Expect(cmp.Diff(appBase.Name, req.Name)).Should(BeEmpty())
@@ -105,21 +105,21 @@ var _ = Describe("Test application rest api", func() {
It("Test list components", func() {
defer GinkgoRecover()
res, err := http.Get("http://127.0.0.1:8000/api/v1/applications/test-app-sadasd/components")
res, err := http.Get("http://127.0.0.1:8000/api/v1/applicationplans/test-app-sadasd/componentplans")
Expect(err).ShouldNot(HaveOccurred())
Expect(res).ShouldNot(BeNil())
Expect(cmp.Diff(res.StatusCode, 200)).Should(BeEmpty())
Expect(res.Body).ShouldNot(BeNil())
defer res.Body.Close()
var components apisv1.ComponentListResponse
var components apisv1.ComponentPlanListResponse
err = json.NewDecoder(res.Body).Decode(&components)
Expect(err).ShouldNot(HaveOccurred())
Expect(cmp.Diff(len(components.Components), 2)).Should(BeEmpty())
Expect(cmp.Diff(len(components.ComponentPlans), 2)).Should(BeEmpty())
})
It("Test list policies", func() {
defer GinkgoRecover()
res, err := http.Get("http://127.0.0.1:8000/api/v1/applications/test-app-sadasd/policies")
res, err := http.Get("http://127.0.0.1:8000/api/v1/applicationplans/test-app-sadasd/policies")
Expect(err).ShouldNot(HaveOccurred())
Expect(res).ShouldNot(BeNil())
Expect(cmp.Diff(res.StatusCode, 200)).Should(BeEmpty())
@@ -133,7 +133,7 @@ var _ = Describe("Test application rest api", func() {
It("Test get workflow", func() {
// defer GinkgoRecover()
// res, err := http.Get("http://127.0.0.1:8000/api/v1/applications/test-app-sadasd/policies")
// res, err := http.Get("http://127.0.0.1:8000/api/v1/applicationplans/test-app-sadasd/policies")
// Expect(err).ShouldNot(HaveOccurred())
// Expect(res).ShouldNot(BeNil())
// Expect(cmp.Diff(res.StatusCode, 200)).Should(BeEmpty())
@@ -147,13 +147,13 @@ var _ = Describe("Test application rest api", func() {
It("Test detail application", func() {
defer GinkgoRecover()
res, err := http.Get("http://127.0.0.1:8000/api/v1/applications/test-app-sadasd")
res, err := http.Get("http://127.0.0.1:8000/api/v1/applicationplans/test-app-sadasd")
Expect(err).ShouldNot(HaveOccurred())
Expect(res).ShouldNot(BeNil())
Expect(cmp.Diff(res.StatusCode, 200)).Should(BeEmpty())
Expect(res.Body).ShouldNot(BeNil())
defer res.Body.Close()
var detail apisv1.DetailApplicationResponse
var detail apisv1.DetailApplicationPlanResponse
err = json.NewDecoder(res.Body).Decode(&detail)
Expect(err).ShouldNot(HaveOccurred())
Expect(cmp.Diff(len(detail.Policies), 1)).Should(BeEmpty())
@@ -168,7 +168,7 @@ var _ = Describe("Test application rest api", func() {
}
bodyByte, err := json.Marshal(req)
Expect(err).ShouldNot(HaveOccurred())
res, err := http.Post("http://127.0.0.1:8000/api/v1/applications/test-app-sadasd/deploy", "application/json", bytes.NewBuffer(bodyByte))
res, err := http.Post("http://127.0.0.1:8000/api/v1/applicationplans/test-app-sadasd/deploy", "application/json", bytes.NewBuffer(bodyByte))
Expect(err).ShouldNot(HaveOccurred())
Expect(res).ShouldNot(BeNil())
Expect(cmp.Diff(res.StatusCode, 200)).Should(BeEmpty())
@@ -188,7 +188,7 @@ var _ = Describe("Test application rest api", func() {
It("Test create component", func() {
defer GinkgoRecover()
var req = apisv1.CreateComponentRequest{
var req = apisv1.CreateComponentPlanRequest{
Name: "test2",
Description: "this is a test2 component",
Labels: map[string]string{},
@@ -198,13 +198,13 @@ var _ = Describe("Test application rest api", func() {
}
bodyByte, err := json.Marshal(req)
Expect(err).ShouldNot(HaveOccurred())
res, err := http.Post("http://127.0.0.1:8000/api/v1/applications/test-app-sadasd/components", "application/json", bytes.NewBuffer(bodyByte))
res, err := http.Post("http://127.0.0.1:8000/api/v1/applicationplans/test-app-sadasd/componentplans", "application/json", bytes.NewBuffer(bodyByte))
Expect(err).ShouldNot(HaveOccurred())
Expect(res).ShouldNot(BeNil())
Expect(cmp.Diff(res.StatusCode, 200)).Should(BeEmpty())
Expect(res.Body).ShouldNot(BeNil())
defer res.Body.Close()
var response apisv1.ComponentBase
var response apisv1.ComponentPlanBase
err = json.NewDecoder(res.Body).Decode(&response)
Expect(err).ShouldNot(HaveOccurred())
Expect(cmp.Diff(response.ComponentType, "worker")).Should(BeEmpty())
@@ -212,13 +212,13 @@ var _ = Describe("Test application rest api", func() {
It("Test detail component", func() {
defer GinkgoRecover()
res, err := http.Get("http://127.0.0.1:8000/api/v1/applications/test-app-sadasd/components/test2")
res, err := http.Get("http://127.0.0.1:8000/api/v1/applicationplans/test-app-sadasd/componentplans/test2")
Expect(err).ShouldNot(HaveOccurred())
Expect(res).ShouldNot(BeNil())
Expect(cmp.Diff(res.StatusCode, 200)).Should(BeEmpty())
Expect(res.Body).ShouldNot(BeNil())
defer res.Body.Close()
var response apisv1.DetailComponentResponse
var response apisv1.DetailComponentPlanResponse
err = json.NewDecoder(res.Body).Decode(&response)
Expect(err).ShouldNot(HaveOccurred())
Expect(cmp.Diff(len(response.DependsOn), 1)).Should(BeEmpty())
@@ -233,7 +233,7 @@ var _ = Describe("Test application rest api", func() {
}
bodyByte, err := json.Marshal(req)
Expect(err).ShouldNot(HaveOccurred())
res, err := http.Post("http://127.0.0.1:8000/api/v1/applications/test-app-sadasd/policies", "application/json", bytes.NewBuffer(bodyByte))
res, err := http.Post("http://127.0.0.1:8000/api/v1/applicationplans/test-app-sadasd/policies", "application/json", bytes.NewBuffer(bodyByte))
Expect(err).ShouldNot(HaveOccurred())
Expect(res).ShouldNot(BeNil())
Expect(cmp.Diff(res.StatusCode, 400)).Should(BeEmpty())
@@ -245,7 +245,7 @@ var _ = Describe("Test application rest api", func() {
}
bodyByte2, err := json.Marshal(req2)
Expect(err).ShouldNot(HaveOccurred())
res, err = http.Post("http://127.0.0.1:8000/api/v1/applications/test-app-sadasd/policies", "application/json", bytes.NewBuffer(bodyByte2))
res, err = http.Post("http://127.0.0.1:8000/api/v1/applicationplans/test-app-sadasd/policies", "application/json", bytes.NewBuffer(bodyByte2))
Expect(err).ShouldNot(HaveOccurred())
Expect(res).ShouldNot(BeNil())
Expect(cmp.Diff(res.StatusCode, 200)).Should(BeEmpty())
@@ -260,7 +260,7 @@ var _ = Describe("Test application rest api", func() {
It("Test detail application policy", func() {
defer GinkgoRecover()
res, err := http.Get("http://127.0.0.1:8000/api/v1/applications/test-app-sadasd/policies/test2")
res, err := http.Get("http://127.0.0.1:8000/api/v1/applicationplans/test-app-sadasd/policies/test2")
Expect(err).ShouldNot(HaveOccurred())
Expect(res).ShouldNot(BeNil())
Expect(cmp.Diff(res.StatusCode, 200)).Should(BeEmpty())
@@ -280,7 +280,7 @@ var _ = Describe("Test application rest api", func() {
}
bodyByte2, err := json.Marshal(req2)
Expect(err).ShouldNot(HaveOccurred())
req, err := http.NewRequest(http.MethodPut, "http://127.0.0.1:8000/api/v1/applications/test-app-sadasd/policies/test2", bytes.NewBuffer(bodyByte2))
req, err := http.NewRequest(http.MethodPut, "http://127.0.0.1:8000/api/v1/applicationplans/test-app-sadasd/policies/test2", bytes.NewBuffer(bodyByte2))
Expect(err).ShouldNot(HaveOccurred())
req.Header.Set("Content-Type", "application/json")
res, err := http.DefaultClient.Do(req)
@@ -298,7 +298,7 @@ var _ = Describe("Test application rest api", func() {
It("Test delete application policy", func() {
defer GinkgoRecover()
req, err := http.NewRequest(http.MethodDelete, "http://127.0.0.1:8000/api/v1/applications/test-app-sadasd/policies/test2", nil)
req, err := http.NewRequest(http.MethodDelete, "http://127.0.0.1:8000/api/v1/applicationplans/test-app-sadasd/policies/test2", nil)
Expect(err).ShouldNot(HaveOccurred())
res, err := http.DefaultClient.Do(req)
Expect(err).ShouldNot(HaveOccurred())