8000 deployment status by RaviKhandavilli · Pull Request #262 · cisco-open/flame · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

deployment status #262

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 5 additions & 20 deletions api/computes_components.partials.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,26 +92,10 @@ AgentKVs:
additionalProperties:
type: string

########################################
# Deployment status within a compute cluster
########################################
DeploymentStatus:
description: Deployment status within a compute cluster
type: object
properties:
jobId:
type: string
agentStatuses:
type: array
items:
$ref: '#/components/schemas/AgentStatus'
required:
- jobId

########################################
# Status for an agent within a deployment
########################################
AgentStatus:
DeploymentStatus:
description: Status for an agent within a deployment
type: object
additionalProperties:
Expand All @@ -122,6 +106,7 @@ AgentStatus:
########################################
AgentState:
enum:
- agentDeployed
- agentRevoked
- agentFailed
- agentDeploySuccess
- agentDeployFailed
- agentRevokeSuccess
- agentRevokeFailed
2 changes: 2 additions & 0 deletions cmd/controller/app/database/db_interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,6 @@ type ComputeService interface {
RegisterCompute(openapi.ComputeSpec) (openapi.ComputeStatus, error)
GetComputeIdsByRegion(string) ([]string, error)
10000 GetComputeById(string) (openapi.ComputeSpec, error)
// UpdateDeploymentStatus call replaces existing agent statuses with received statuses in collection.
UpdateDeploymentStatus(computeId string, jobId string, agentStatuses map[string]openapi.AgentState) error
}
29 changes: 29 additions & 0 deletions cmd/controller/app/database/mongodb/compute.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,32 @@ func (db *MongoService) GetComputeById(computeId string) (openapi.ComputeSpec, e
}
return currentDocument, nil
}

func (db *MongoService) UpdateDeploymentStatus(computeId string, jobId string, agentStatuses map[string]openapi.AgentState) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this handle stale record issue correctly? If not, do you want to make it as a separate PR? If so, can you create a TODO comment in this function?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This overwrites the existing records , we are making sure to send status of all the tasks every time we put the deployment status.
instead of deleting existing records and creating new records we are sending status of all the new records in one batch. here we are simply rewriting existing record with the new data.

filter := bson.M{util.DBFieldJobId: jobId, util.DBFieldComputeId: computeId}
result := db.deploymentCollection.FindOne(context.TODO(), filter)
// update fields if document is already present
if result.Err() == nil {
result = db.deploymentCollection.FindOneAndUpdate(context.TODO(),
filter,
bson.M{"$set": bson.M{util.DBFieldAgentStatuses: agentStatuses}})
if err := result.Err(); err != nil {
err = ErrorCheck(err)
zap.S().Errorf("Failed to update new deployment status: %v", err)
return err
}
} else {
_, err := db.deploymentCollection.InsertOne(context.TODO(),
bson.M{util.DBFieldJobId: jobId,
util.DBFieldComputeId: computeId,
util.DBFieldAgentStatuses: agentStatuses,
})
if err != nil {
err = ErrorCheck(err)
zap.S().Errorf("Failed to create new deployment status: %v", err)
return err
}
}
zap.S().Debugf("New deployment status for jobid: %s inserted", jobId)
return nil
}
37 changes: 37 additions & 0 deletions cmd/controller/app/database/mongodb/compute_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package mongodb

import (
"testing"

"github.com/stretchr/testify/assert"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo/integration/mtest"

"github.com/cisco-open/flame/pkg/openapi"
)

func TestMongoService_UpdateDeploymentStatus(t *testing.T) {
mt := mtest.New(t, mtest.NewOptions().ClientType(mtest.Mock))
defer mt.Close()
mt.Run("success", func(mt *mtest.T) {
db := &MongoService{
deploymentCollection: mt.Coll,
}
mt.AddMockResponses(mtest.CreateSuccessResponse(), mtest.CreateCursorResponse(1, "flame.deployment", mtest.FirstBatch, bson.D{}))
err := db.UpdateDeploymentStatus("test jobid","test compute id",
map[string]openapi.AgentState{"test task id": openapi.AGENT_DEPLOY_SUCCESS,
})
assert.Nil(t, err)
})
mt.Run("status update failure", func(mt *mtest.T) {
db := &MongoService{
deploymentCollection: mt.Coll,
}
mt.AddMockResponses(
mtest.CreateCursorResponse(1, "flame.deployment", mtest.FirstBatch, bson.D{{"_id", "1"}}))
err := db.UpdateDeploymentStatus("test jobid", "test compute id",
map[string]openapi.AgentState{"test task id": openapi.AGENT_DEPLOY_SUCCESS},
)
assert.NotNil(t, err)
})
}
51 changes: 30 additions & 21 deletions cmd/controller/app/database/mongodb/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,19 @@ import (
"go.mongodb.org/mongo-driver/mongo/readpref"
"go.mongodb.org/mongo-driver/x/bsonx"
"go.uber.org/zap"

"github.com/cisco-open/flame/pkg/util"
)

const (
DatabaseName = "flame"

ComputeCollection = "t_compute"
DatasetCollection = "t_dataset"
DesignCollection = "t_design"
JobCollection = "t_job"
TaskCollection = "t_task"
ComputeCollection = "t_compute"
DatasetCollection = "t_dataset"
DesignCollection = "t_design"
JobCollection = "t_job"
TaskCollection = "t_task"
DeploymentCollection = "t_deployment"

orderAscend int32 = 1
orderDescend int32 = -1
Expand All @@ -44,11 +47,12 @@ type MongoService struct {
client *mongo.Client
database *mongo.Database

computeCollection *mongo.Collection
datasetCollection *mongo.Collection
designCollection *mongo.Collection
jobCollection *mongo.Collection
taskCollection *mongo.Collection
computeCollection *mongo.Collection
datasetCollection *mongo.Collection
designCollection *mongo.Collection
jobCollection *mongo.Collection
taskCollection *mongo.Collection
deploymentCollection *mongo.Collection
}

type uniqueIndexInfo struct {
Expand Down Expand Up @@ -91,31 +95,36 @@ func NewMongoService(uri string) (*MongoService, error) {

db := client.Database(DatabaseName)
mongoDB := &MongoService{
client: client,
database: db,
computeCollection: db.Collection(ComputeCollection),
datasetCollection: db.Collection(DatasetCollection),
designCollection: db.Collection(DesignCollection),
jobCollection: db.Collection(JobCollection),
taskCollection: db.Collection(TaskCollection),
client: client,
database: db,
computeCollection: db.Collection(ComputeCollection),
datasetCollection: db.Collection(DatasetCollection),
designCollection: db.Collection(DesignCollection),
jobCollection: db.Collection(JobCollection),
taskCollection: db.Collection(TaskCollection),
deploymentCollection: db.Collection(DeploymentCollection),
}

uiiList := []uniqueIndexInfo{
{
mongoDB.computeCollection,
map[string]int32{"computeid": orderAscend, "region": orderAscend},
map[string]int32{util.DBFieldComputeId: orderAscend, util.DBFieldComputeRegion: orderAscend},
},
{
mongoDB.datasetCollection,
map[string]int32{"userid": orderAscend, "url": orderAscend},
map[string]int32{util.DBFieldUserId: orderAscend, util.DBFieldURL: orderAscend},
},
{
mongoDB.designCollection,
map[string]int32{"userid": orderAscend, "id": orderAscend},
map[string]int32{util.DBFieldUserId: orderAscend, util.DBFieldId: orderAscend},
},
{
mongoDB.taskCollection,
map[string]int32{"jobid": orderAscend, "taskid": orderAscend},
map[string]int32{util.DBFieldJobId: orderAscend, util.DBFieldTaskId: orderAscend},
},
{
mongoDB.deploymentCollection,
map[string]int32{util.DBFieldComputeId: orderAscend, util.DBFieldJobId: orderAscend},
},
}
for _, uii := range uiiList {
Expand Down
3 changes: 3 additions & 0 deletions cmd/deployer/app/deployer/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ func (deployer *K8sDeployer) Install(releaseName string, chartPath string) error
installObj.ReleaseName = releaseName
release, err := installObj.Run(chart, nil)
if err != nil {
if release != nil && release.Info != nil {
zap.S().Errorf("Release %s failed with status : %v", releaseName, release.Info.Status)
}
return err
}

Expand Down
Loading
0