-
Notifications
You must be signed in to change notification settings - Fork 834
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add debug logs for api Signed-off-by: Min Min <jamsman94@gmail.com> * add list revert event api Signed-off-by: Min Min <jamsman94@gmail.com> * change debug logs Signed-off-by: Min Min <jamsman94@gmail.com> * added list history api for revert Signed-off-by: Min Min <jamsman94@gmail.com> * added revert spec for frontend to show Signed-off-by: Min Min <jamsman94@gmail.com> * Added missing field in preview Signed-off-by: Min Min <jamsman94@gmail.com> * debug Signed-off-by: Min Min <jamsman94@gmail.com> * debug Signed-off-by: Min Min <jamsman94@gmail.com> * debug Signed-off-by: Min Min <jamsman94@gmail.com> * debug Signed-off-by: Min Min <jamsman94@gmail.com> * debug Signed-off-by: Min Min <jamsman94@gmail.com> * remove debug logs Signed-off-by: Min Min <jamsman94@gmail.com> --------- Signed-off-by: Min Min <jamsman94@gmail.com>
- Loading branch information
Showing
10 changed files
with
457 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
pkg/microservice/aslan/core/common/repository/models/workflow_task_revert.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright 2025 The KodeRover Authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package models | ||
|
||
import ( | ||
"github.com/koderover/zadig/v2/pkg/microservice/aslan/config" | ||
"go.mongodb.org/mongo-driver/bson/primitive" | ||
) | ||
|
||
type WorkflowTaskRevert struct { | ||
ID primitive.ObjectID `bson:"_id,omitempty" json:"id,omitempty"` | ||
TaskID int64 `bson:"task_id" json:"task_id"` | ||
WorkflowName string `bson:"workflow_name" json:"workflow_name"` | ||
JobName string `bson:"job_name" json:"job_name"` | ||
RevertSpec interface{} `bson:"revert_spec" json:"revert_spec"` | ||
CreateTime int64 `bson:"create_time" json:"create_time,omitempty"` | ||
TaskCreator string `bson:"creator" json:"creator,omitempty"` | ||
TaskCreatorID string `bson:"creator_id" json:"creator_id,omitempty"` | ||
Status config.Status `bson:"status" json:"status,omitempty"` | ||
} | ||
|
||
func (WorkflowTaskRevert) TableName() string { | ||
return "workflow_task_revert" | ||
} |
115 changes: 115 additions & 0 deletions
115
pkg/microservice/aslan/core/common/repository/mongodb/workflow_task_revert.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
/* | ||
Copyright 2025 The KodeRover Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package mongodb | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"go.mongodb.org/mongo-driver/bson" | ||
"go.mongodb.org/mongo-driver/bson/primitive" | ||
"go.mongodb.org/mongo-driver/mongo" | ||
"go.mongodb.org/mongo-driver/mongo/options" | ||
|
||
"github.com/koderover/zadig/v2/pkg/microservice/aslan/config" | ||
"github.com/koderover/zadig/v2/pkg/microservice/aslan/core/common/repository/models" | ||
mongotool "github.com/koderover/zadig/v2/pkg/tool/mongo" | ||
) | ||
|
||
type WorkflowTasKRevertColl struct { | ||
*mongo.Collection | ||
|
||
coll string | ||
} | ||
|
||
func NewWorkflowTaskRevertColl() *WorkflowTasKRevertColl { | ||
name := models.WorkflowTaskRevert{}.TableName() | ||
return &WorkflowTasKRevertColl{Collection: mongotool.Database(config.MongoDatabase()).Collection(name), coll: name} | ||
} | ||
|
||
func (c *WorkflowTasKRevertColl) GetCollectionName() string { | ||
return c.coll | ||
} | ||
|
||
func (c *WorkflowTasKRevertColl) EnsureIndex(ctx context.Context) error { | ||
mod := []mongo.IndexModel{ | ||
{ | ||
Keys: bson.D{ | ||
bson.E{Key: "workflow_name", Value: 1}, | ||
bson.E{Key: "task_id", Value: 1}, | ||
bson.E{Key: "job_name", Value: 1}, | ||
}, | ||
Options: options.Index().SetUnique(false), | ||
}, | ||
{ | ||
Keys: bson.M{"create_time": 1}, | ||
Options: options.Index().SetUnique(false), | ||
}, | ||
} | ||
|
||
_, err := c.Indexes().CreateMany(ctx, mod) | ||
|
||
return err | ||
} | ||
|
||
func (c *WorkflowTasKRevertColl) Create(obj *models.WorkflowTaskRevert) (string, error) { | ||
if obj == nil { | ||
return "", fmt.Errorf("nil object") | ||
} | ||
|
||
res, err := c.InsertOne(context.TODO(), obj) | ||
if err != nil { | ||
return "", err | ||
} | ||
ID, ok := res.InsertedID.(primitive.ObjectID) | ||
if !ok { | ||
return "", fmt.Errorf("failed to get object id from create") | ||
} | ||
return ID.Hex(), err | ||
} | ||
|
||
type ListWorkflowRevertOption struct { | ||
TaskID int64 | ||
WorkflowName string | ||
JobName string | ||
} | ||
|
||
func (c *WorkflowTasKRevertColl) List(opt *ListWorkflowRevertOption) ([]*models.WorkflowTaskRevert, error) { | ||
resp := make([]*models.WorkflowTaskRevert, 0) | ||
|
||
query := bson.M{} | ||
if opt.WorkflowName != "" { | ||
query["workflow_name"] = opt.WorkflowName | ||
} | ||
if opt.TaskID != 0 { | ||
query["task_id"] = opt.TaskID | ||
} | ||
if opt.JobName != "" { | ||
query["job_name"] = opt.JobName | ||
} | ||
|
||
findOption := options.Find() | ||
cursor, err := c.Collection.Find(context.TODO(), query, findOption) | ||
if err != nil { | ||
return nil, err | ||
} | ||
err = cursor.All(context.TODO(), &resp) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return resp, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.