Skip to content

Commit

Permalink
rename function to SupportsTransactions
Browse files Browse the repository at this point in the history
Signed-off-by: Patricia Reinoso <[email protected]>
  • Loading branch information
patriciareinoso committed Jan 14, 2025
1 parent 02e165e commit c470089
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 27 deletions.
25 changes: 13 additions & 12 deletions configapi/api_inventory.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,13 @@ func DeleteGnb(c *gin.Context) {
}
filter := bson.M{"name": gnbName}

isReplicaSet, err := dbadapter.CommonDBClient.IsReplicaSet()
supportsTransactions, err := dbadapter.CommonDBClient.SupportsTransactions()
if err != nil {
logger.DbLog.Warnw("could not verify replica set status; proceeding without transactions", "error", err)
isReplicaSet = false
logger.DbLog.Warnw("could not verify replica set or sharded status; proceeding without transactions", "error", err)
supportsTransactions = false
}
if isReplicaSet {
err = handleReplicaSetDeleteGnb(filter, gnbName)
if supportsTransactions {
err = handleDeleteGnbAsTransaction(filter, gnbName)
} else {
err = handleStandaloneDeleteGnb(filter, gnbName)
}
Expand All @@ -131,7 +131,7 @@ func DeleteGnb(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{})
}

func handleReplicaSetDeleteGnb(filter bson.M, gnbName string) error {
func handleDeleteGnbAsTransaction(filter bson.M, gnbName string) error {
session, err := dbadapter.CommonDBClient.StartSession()
if err != nil {
return fmt.Errorf("failed to initialize DB session: %w", err)
Expand Down Expand Up @@ -282,14 +282,15 @@ func DeleteUpf(c *gin.Context) {
return
}

isReplicaSet, err := dbadapter.CommonDBClient.IsReplicaSet()
supportsTransactions, err := dbadapter.CommonDBClient.SupportsTransactions()
logger.WebUILog.Errorw("PATTY", "supportsTransactions", supportsTransactions)
if err != nil {
logger.DbLog.Warnw("could not verify replica set status; proceeding without transactions", "error", err)
isReplicaSet = false
logger.DbLog.Warnw("could not verify replica set or sharded status; proceeding without transactions", "error", err)
supportsTransactions = false
}
filter := bson.M{"hostname": hostname}
if isReplicaSet {
err = handleReplicaSetDeleteUpf(filter, hostname)
if supportsTransactions {
err = handleDeleteUpfTransaction(filter, hostname)
} else {
err = handleStandaloneDeleteUpf(filter, hostname)
}
Expand All @@ -302,7 +303,7 @@ func DeleteUpf(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{})
}

func handleReplicaSetDeleteUpf(filter bson.M, hostname string) error {
func handleDeleteUpfTransaction(filter bson.M, hostname string) error {
session, err := dbadapter.CommonDBClient.StartSession()
if err != nil {
return fmt.Errorf("failed to initialize DB session: %w", err)
Expand Down
4 changes: 2 additions & 2 deletions configapi/api_inventory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,10 @@ func (db *MockMongoClientDBError) RestfulAPIJSONPatchWithContext(collName string
return errors.New("DB error")
}

func (db *MockMongoClientEmptyDB) IsReplicaSet() (bool, error) {
func (db *MockMongoClientEmptyDB) SupportsTransactions() (bool, error) {
return true, nil
}
func (db *MockMongoClientDBError) IsReplicaSet() (bool, error) {
func (db *MockMongoClientDBError) SupportsTransactions() (bool, error) {
return true, nil
}

Expand Down
26 changes: 13 additions & 13 deletions dbadapter/db_adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,18 @@ type DBInterface interface {
RestfulAPIPutOneNotUpdate(collName string, filter bson.M, putData map[string]interface{}) (bool, error)
RestfulAPIPutMany(collName string, filterArray []primitive.M, putDataArray []map[string]interface{}) error
RestfulAPIDeleteOne(collName string, filter bson.M) error
RestfulAPIDeleteOneWithContext(collName string, filter bson.M, context context.Context) error
RestfulAPIDeleteMany(collName string, filter bson.M) error
RestfulAPIMergePatch(collName string, filter bson.M, patchData map[string]interface{}) error
RestfulAPIJSONPatch(collName string, filter bson.M, patchJSON []byte) error
RestfulAPIJSONPatchWithContext(collName string, filter bson.M, patchJSON []byte, context context.Context) error
RestfulAPIJSONPatchExtend(collName string, filter bson.M, patchJSON []byte, dataName string) error
RestfulAPIPost(collName string, filter bson.M, postData map[string]interface{}) (bool, error)
RestfulAPIPostMany(collName string, filter bson.M, postDataArray []interface{}) error
RestfulAPICount(collName string, filter bson.M) (int64, error)
CreateIndex(collName string, keyField string) (bool, error)
StartSession() (mongo.Session, error)
RestfulAPIDeleteOneWithContext(collName string, filter bson.M, context context.Context) error
RestfulAPIJSONPatchWithContext(collName string, filter bson.M, patchJSON []byte, context context.Context) error
IsReplicaSet() (bool, error)
SupportsTransactions() (bool, error)
}

var (
Expand Down Expand Up @@ -106,6 +106,10 @@ func (db *MongoDBClient) RestfulAPIDeleteOne(collName string, filter bson.M) err
return db.MongoClient.RestfulAPIDeleteOne(collName, filter)
}

func (db *MongoDBClient) RestfulAPIDeleteOneWithContext(collName string, filter bson.M, context context.Context) error {
return db.MongoClient.RestfulAPIDeleteOneWithContext(collName, filter, context)

Check failure on line 110 in dbadapter/db_adapter.go

View workflow job for this annotation

GitHub Actions / build-ui

db.MongoClient.RestfulAPIDeleteOneWithContext undefined (type mongoapi.MongoClient has no field or method RestfulAPIDeleteOneWithContext)

Check failure on line 110 in dbadapter/db_adapter.go

View workflow job for this annotation

GitHub Actions / build

db.MongoClient.RestfulAPIDeleteOneWithContext undefined (type mongoapi.MongoClient has no field or method RestfulAPIDeleteOneWithContext)

Check failure on line 110 in dbadapter/db_adapter.go

View workflow job for this annotation

GitHub Actions / lint

db.MongoClient.RestfulAPIDeleteOneWithContext undefined (type mongoapi.MongoClient has no field or method RestfulAPIDeleteOneWithContext)

Check failure on line 110 in dbadapter/db_adapter.go

View workflow job for this annotation

GitHub Actions / lint

db.MongoClient.RestfulAPIDeleteOneWithContext undefined (type mongoapi.MongoClient has no field or method RestfulAPIDeleteOneWithContext)

Check failure on line 110 in dbadapter/db_adapter.go

View workflow job for this annotation

GitHub Actions / staticcheck

db.MongoClient.RestfulAPIDeleteOneWithContext undefined (type mongoapi.MongoClient has no field or method RestfulAPIDeleteOneWithContext)

Check failure on line 110 in dbadapter/db_adapter.go

View workflow job for this annotation

GitHub Actions / unit-tests

db.MongoClient.RestfulAPIDeleteOneWithContext undefined (type mongoapi.MongoClient has no field or method RestfulAPIDeleteOneWithContext)
}

func (db *MongoDBClient) RestfulAPIDeleteMany(collName string, filter bson.M) error {
return db.MongoClient.RestfulAPIDeleteMany(collName, filter)
}
Expand All @@ -118,6 +122,10 @@ func (db *MongoDBClient) RestfulAPIJSONPatch(collName string, filter bson.M, pat
return db.MongoClient.RestfulAPIJSONPatch(collName, filter, patchJSON)
}

func (db *MongoDBClient) RestfulAPIJSONPatchWithContext(collName string, filter bson.M, patchJSON []byte, context context.Context) error {
return db.MongoClient.RestfulAPIJSONPatchWithContext(collName, filter, patchJSON, context)

Check failure on line 126 in dbadapter/db_adapter.go

View workflow job for this annotation

GitHub Actions / build-ui

db.MongoClient.RestfulAPIJSONPatchWithContext undefined (type mongoapi.MongoClient has no field or method RestfulAPIJSONPatchWithContext)

Check failure on line 126 in dbadapter/db_adapter.go

View workflow job for this annotation

GitHub Actions / build

db.MongoClient.RestfulAPIJSONPatchWithContext undefined (type mongoapi.MongoClient has no field or method RestfulAPIJSONPatchWithContext)

Check failure on line 126 in dbadapter/db_adapter.go

View workflow job for this annotation

GitHub Actions / lint

db.MongoClient.RestfulAPIJSONPatchWithContext undefined (type mongoapi.MongoClient has no field or method RestfulAPIJSONPatchWithContext)

Check failure on line 126 in dbadapter/db_adapter.go

View workflow job for this annotation

GitHub Actions / lint

db.MongoClient.RestfulAPIJSONPatchWithContext undefined (type mongoapi.MongoClient has no field or method RestfulAPIJSONPatchWithContext)

Check failure on line 126 in dbadapter/db_adapter.go

View workflow job for this annotation

GitHub Actions / staticcheck

db.MongoClient.RestfulAPIJSONPatchWithContext undefined (type mongoapi.MongoClient has no field or method RestfulAPIJSONPatchWithContext)

Check failure on line 126 in dbadapter/db_adapter.go

View workflow job for this annotation

GitHub Actions / unit-tests

db.MongoClient.RestfulAPIJSONPatchWithContext undefined (type mongoapi.MongoClient has no field or method RestfulAPIJSONPatchWithContext)
}

func (db *MongoDBClient) RestfulAPIJSONPatchExtend(collName string, filter bson.M, patchJSON []byte, dataName string) error {
return db.MongoClient.RestfulAPIJSONPatchExtend(collName, filter, patchJSON, dataName)
}
Expand All @@ -142,14 +150,6 @@ func (db *MongoDBClient) StartSession() (mongo.Session, error) {
return db.MongoClient.StartSession()

Check failure on line 150 in dbadapter/db_adapter.go

View workflow job for this annotation

GitHub Actions / build-ui

db.MongoClient.StartSession undefined (type mongoapi.MongoClient has no field or method StartSession)

Check failure on line 150 in dbadapter/db_adapter.go

View workflow job for this annotation

GitHub Actions / build

db.MongoClient.StartSession undefined (type mongoapi.MongoClient has no field or method StartSession)

Check failure on line 150 in dbadapter/db_adapter.go

View workflow job for this annotation

GitHub Actions / lint

db.MongoClient.StartSession undefined (type mongoapi.MongoClient has no field or method StartSession)

Check failure on line 150 in dbadapter/db_adapter.go

View workflow job for this annotation

GitHub Actions / lint

db.MongoClient.StartSession undefined (type mongoapi.MongoClient has no field or method StartSession)

Check failure on line 150 in dbadapter/db_adapter.go

View workflow job for this annotation

GitHub Actions / staticcheck

db.MongoClient.StartSession undefined (type mongoapi.MongoClient has no field or method StartSession)

Check failure on line 150 in dbadapter/db_adapter.go

View workflow job for this annotation

GitHub Actions / unit-tests

db.MongoClient.StartSession undefined (type mongoapi.MongoClient has no field or method StartSession)
}

func (db *MongoDBClient) RestfulAPIDeleteOneWithContext(collName string, filter bson.M, context context.Context) error {
return db.MongoClient.RestfulAPIDeleteOneWithContext(collName, filter, context)
}

func (db *MongoDBClient) RestfulAPIJSONPatchWithContext(collName string, filter bson.M, patchJSON []byte, context context.Context) error {
return db.MongoClient.RestfulAPIJSONPatchWithContext(collName, filter, patchJSON, context)
}

func (db *MongoDBClient) IsReplicaSet() (bool, error) {
return db.MongoClient.IsReplicaSet()
func (db *MongoDBClient) SupportsTransactions() (bool, error) {
return db.MongoClient.SupportsTransactions()

Check failure on line 154 in dbadapter/db_adapter.go

View workflow job for this annotation

GitHub Actions / build-ui

db.MongoClient.SupportsTransactions undefined (type mongoapi.MongoClient has no field or method SupportsTransactions)

Check failure on line 154 in dbadapter/db_adapter.go

View workflow job for this annotation

GitHub Actions / build

db.MongoClient.SupportsTransactions undefined (type mongoapi.MongoClient has no field or method SupportsTransactions)

Check failure on line 154 in dbadapter/db_adapter.go

View workflow job for this annotation

GitHub Actions / lint

db.MongoClient.SupportsTransactions undefined (type mongoapi.MongoClient has no field or method SupportsTransactions) (typecheck)

Check failure on line 154 in dbadapter/db_adapter.go

View workflow job for this annotation

GitHub Actions / staticcheck

db.MongoClient.SupportsTransactions undefined (type mongoapi.MongoClient has no field or method SupportsTransactions) (compile)

Check failure on line 154 in dbadapter/db_adapter.go

View workflow job for this annotation

GitHub Actions / unit-tests

db.MongoClient.SupportsTransactions undefined (type mongoapi.MongoClient has no field or method SupportsTransactions)
}

0 comments on commit c470089

Please sign in to comment.