@@ -2,13 +2,8 @@ package kafka
22
33import (
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
149var (
@@ -21,44 +16,19 @@ type inventoryIDsBatch struct {
2116}
2217
2318func 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-
6232func 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-
8940func 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}
0 commit comments