Skip to content

Commit 7212f17

Browse files
committed
RHINENG-19230: rename kafka related functions to something generic
as they no more deal with baselines
1 parent 7d7f59d commit 7212f17

6 files changed

Lines changed: 9 additions & 65 deletions

File tree

manager/config/config.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ var (
2121
// Satellite systems can't be assigned to baselines/templates
2222
EnableSatelliteFunctionality = utils.PodConfig.GetBool("satellite_functionality", true)
2323

24-
// Send recalc message for systems which have been assigned to a different baseline
25-
EnableBaselineChangeEval = utils.PodConfig.GetBool("baseline_change_eval", true)
2624
// Send recalc message for systems which have been assigned to a different template
2725
EnableTemplateChangeEval = utils.PodConfig.GetBool("template_change_eval", true)
2826
// Honor rbac permissions (can be disabled for tests)

manager/controllers/template_subscribed_systems_update.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func TemplateSubscribedSystemsUpdateHandler(c *gin.Context) {
5959
// re-evaluate systems added/removed from templates
6060
if config.EnableTemplateChangeEval {
6161
inventoryAIDs := kafka.InventoryIDs2InventoryAIDs(account, systemList)
62-
kafka.EvaluateBaselineSystems(inventoryAIDs)
62+
kafka.RecalcSystems(inventoryAIDs)
6363
}
6464
c.Status(http.StatusOK)
6565
}

manager/controllers/template_systems_delete.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func TemplateSystemsDeleteHandler(c *gin.Context) {
5353
// re-evaluate systems removed from templates
5454
if config.EnableTemplateChangeEval {
5555
inventoryAIDs := kafka.InventoryIDs2InventoryAIDs(account, req.Systems)
56-
kafka.EvaluateBaselineSystems(inventoryAIDs)
56+
kafka.RecalcSystems(inventoryAIDs)
5757
}
5858
c.Status(http.StatusOK)
5959
}

manager/controllers/template_systems_update.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func TemplateSystemsUpdateHandler(c *gin.Context) {
8686
// re-evaluate systems added/removed from templates
8787
if config.EnableTemplateChangeEval {
8888
inventoryAIDs := kafka.InventoryIDs2InventoryAIDs(account, req.Systems)
89-
kafka.EvaluateBaselineSystems(inventoryAIDs)
89+
kafka.RecalcSystems(inventoryAIDs)
9090
}
9191
c.Status(http.StatusOK)
9292
}

manager/kafka/kafka.go

Lines changed: 4 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,8 @@ package kafka
22

33
import (
44
"app/base"
5-
"app/base/models"
65
"app/base/mqueue"
76
"app/base/utils"
8-
9-
"app/manager/config"
10-
11-
"gorm.io/gorm"
127
)
138

149
var (
@@ -21,44 +16,19 @@ type inventoryIDsBatch struct {
2116
}
2217

2318
func TryStartEvalQueue(createWriter mqueue.CreateWriter) {
24-
if !config.EnableBaselineChangeEval {
25-
return
26-
}
2719
evalTopic := utils.FailIfEmpty(utils.CoreCfg.EvalTopic, "EVAL_TOPIC")
2820
evalWriter = createWriter(evalTopic)
2921
inventoryIDsChan = make(chan inventoryIDsBatch)
30-
go runBaselineRecalcLoop()
22+
go runRecalcLoop()
3123
}
3224

33-
func runBaselineRecalcLoop() {
25+
func runRecalcLoop() {
3426
for {
3527
batch := <-inventoryIDsChan
3628
sendInventoryIDs(batch.InventoryIDs)
3729
}
3830
}
3931

40-
func GetInventoryIDsToEvaluate(db *gorm.DB, baselineID *int64, accountID int,
41-
configUpdated bool, updatedInventoryIDs []string) []mqueue.EvalData {
42-
if !config.EnableBaselineChangeEval {
43-
return nil
44-
}
45-
46-
if !configUpdated && updatedInventoryIDs == nil {
47-
return nil // no evaluation needed for no config and inventory IDs updates
48-
}
49-
50-
var inventoryAIDs []mqueue.EvalData
51-
if !configUpdated { // we just need to evaluate updated inventory IDs
52-
inventoryAIDs = InventoryIDs2InventoryAIDs(accountID, updatedInventoryIDs)
53-
} else { // config updated - we need to update all baseline inventory IDs and the added ones too
54-
inventoryAIDs = getInventoryIDs(db, baselineID, accountID, updatedInventoryIDs)
55-
}
56-
57-
utils.LogDebug("nInventoryIDs", len(inventoryAIDs), "accountID", accountID,
58-
"Loaded inventory IDs to evaluate")
59-
return inventoryAIDs
60-
}
61-
6232
func InventoryIDs2InventoryAIDs(accountID int, inventoryIDs []string) []mqueue.EvalData {
6333
inventoryAIDs := make([]mqueue.EvalData, 0, len(inventoryIDs))
6434
for _, v := range inventoryIDs {
@@ -67,25 +37,6 @@ func InventoryIDs2InventoryAIDs(accountID int, inventoryIDs []string) []mqueue.E
6737
return inventoryAIDs
6838
}
6939

70-
func getInventoryIDs(db *gorm.DB, baselineID *int64, accountID int, inventoryIDs []string) []mqueue.EvalData {
71-
var inventoryAIDs []mqueue.EvalData
72-
query := db.Model(&models.SystemPlatform{}).
73-
Select("inventory_id, rh_account_id").
74-
Where("rh_account_id = ? AND baseline_id = ?", accountID, baselineID)
75-
76-
if len(inventoryIDs) > 0 {
77-
query = query.Or("inventory_id IN (?) AND rh_account_id = ?", inventoryIDs, accountID)
78-
}
79-
80-
err := query.Order("inventory_id").
81-
Scan(&inventoryAIDs).Error
82-
if err != nil {
83-
utils.LogError("err", err.Error(),
84-
"Unable to load inventory IDs for baseline")
85-
}
86-
return inventoryAIDs
87-
}
88-
8940
func sendInventoryIDs(inventoryIDs mqueue.EvalDataSlice) {
9041
if len(inventoryIDs) == 0 {
9142
return
@@ -98,13 +49,8 @@ func sendInventoryIDs(inventoryIDs mqueue.EvalDataSlice) {
9849
}
9950
}
10051

101-
// Send all account systems of given baseline to evaluation.
102-
// Evaluate all account systems with no baseline if baselineID is nil (used for deleted baseline).
103-
func EvaluateBaselineSystems(inventoryAIDs []mqueue.EvalData) {
104-
if !config.EnableBaselineChangeEval {
105-
return
106-
}
107-
52+
// Send given systems to re-evaluation.
53+
func RecalcSystems(inventoryAIDs []mqueue.EvalData) {
10854
batch := inventoryIDsBatch{InventoryIDs: inventoryAIDs}
10955
inventoryIDsChan <- batch
11056
}

manager/kafka/kafka_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ func testEvaluateBaselineSystems(t *testing.T, baselineID *int64, accountID int,
1616
configUpdated bool, inventoryIDs []string) mqueue.PlatformEvent {
1717
utils.SkipWithoutDB(t)
1818
core.SetupTestEnvironment()
19-
config.EnableBaselineChangeEval = true
19+
config.EnableTemplateChangeEval = true
2020

2121
writerMock := mqueue.MockKafkaWriter{}
2222
TryStartEvalQueue(mqueue.MockCreateKafkaWriter(&writerMock))
2323
inventoryAIDs := GetInventoryIDsToEvaluate(database.DB, baselineID, accountID, configUpdated, inventoryIDs)
24-
EvaluateBaselineSystems(inventoryAIDs)
24+
RecalcSystems(inventoryAIDs)
2525
utils.AssertEqualWait(t, 1, func() (exp, act interface{}) {
2626
return 1, len(writerMock.Messages)
2727
})

0 commit comments

Comments
 (0)