/
noop_ocp_recommendations_storage.go
409 lines (345 loc) · 10.9 KB
/
noop_ocp_recommendations_storage.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
// Copyright 2020, 2021, 2022, 2023 Red Hat, Inc
//
// 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 storage
import (
"database/sql"
"time"
"github.com/Shopify/sarama"
ctypes "github.com/RedHatInsights/insights-results-types"
"github.com/RedHatInsights/insights-results-aggregator/migration"
"github.com/RedHatInsights/insights-results-aggregator/types"
)
// NoopOCPStorage represents a storage which does nothing (for benchmarking without a storage)
type NoopOCPStorage struct{}
// Init noop
func (*NoopOCPStorage) Init() error {
return nil
}
// Close noop
func (*NoopOCPStorage) Close() error {
return nil
}
// GetMigrations noop
func (*NoopOCPStorage) GetMigrations() []migration.Migration {
return nil
}
// GetDBSchema noop
func (*NoopOCPStorage) GetDBSchema() migration.Schema {
return migration.Schema("")
}
// GetMaxVersion noop
func (*NoopOCPStorage) GetMaxVersion() migration.Version {
return migration.Version(0)
}
// ListOfOrgs noop
func (*NoopOCPStorage) ListOfOrgs() ([]types.OrgID, error) {
return nil, nil
}
// ListOfClustersForOrg noop
func (*NoopOCPStorage) ListOfClustersForOrg(types.OrgID, time.Time) ([]types.ClusterName, error) {
return nil, nil
}
// ReadReportForCluster noop
func (*NoopOCPStorage) ReadReportForCluster(types.OrgID, types.ClusterName) ([]types.RuleOnReport, types.Timestamp, types.Timestamp, types.Timestamp, error) {
return []types.RuleOnReport{}, "", "", "", nil
}
// ReadReportInfoForCluster noop
func (*NoopOCPStorage) ReadReportInfoForCluster(types.OrgID, types.ClusterName) (types.Version, error) {
return "", nil
}
// ReadClusterVersionsForClusterList noop
func (*NoopOCPStorage) ReadClusterVersionsForClusterList(
types.OrgID, []string,
) (map[types.ClusterName]types.Version, error) {
return nil, nil
}
// ReadSingleRuleTemplateData noop
func (*NoopOCPStorage) ReadSingleRuleTemplateData(types.OrgID, types.ClusterName, types.RuleID, types.ErrorKey) (interface{}, error) {
return "", nil
}
// ReadReportForClusterByClusterName noop
func (*NoopOCPStorage) ReadReportForClusterByClusterName(
types.ClusterName,
) ([]types.RuleOnReport, types.Timestamp, error) {
return []types.RuleOnReport{}, "", nil
}
// WriteReportForCluster noop
func (*NoopOCPStorage) WriteReportForCluster(
types.OrgID, types.ClusterName, types.ClusterReport, []types.ReportItem, time.Time, time.Time, time.Time,
types.RequestID,
) error {
return nil
}
// WriteReportInfoForCluster noop
func (*NoopOCPStorage) WriteReportInfoForCluster(
_ types.OrgID,
_ types.ClusterName,
_ []types.InfoItem,
_ time.Time,
) error {
return nil
}
// WriteRecommendationsForCluster noop
func (*NoopOCPStorage) WriteRecommendationsForCluster(
types.OrgID, types.ClusterName, types.ClusterReport, types.Timestamp,
) error {
return nil
}
// ReportsCount noop
func (*NoopOCPStorage) ReportsCount() (int, error) {
return 0, nil
}
// VoteOnRule noop
func (*NoopOCPStorage) VoteOnRule(types.ClusterName, types.RuleID, types.ErrorKey, types.OrgID, types.UserID, types.UserVote, string) error {
return nil
}
// AddOrUpdateFeedbackOnRule noop
func (*NoopOCPStorage) AddOrUpdateFeedbackOnRule(
types.ClusterName, types.RuleID, types.ErrorKey, types.OrgID, types.UserID, string,
) error {
return nil
}
// AddFeedbackOnRuleDisable noop
func (*NoopOCPStorage) AddFeedbackOnRuleDisable(
types.ClusterName, types.RuleID, types.ErrorKey, types.OrgID, types.UserID, string,
) error {
return nil
}
// GetUserFeedbackOnRuleDisable noop
func (*NoopOCPStorage) GetUserFeedbackOnRuleDisable(
types.ClusterName, types.RuleID, types.ErrorKey, types.UserID,
) (*UserFeedbackOnRule, error) {
return nil, nil
}
// GetUserFeedbackOnRule noop
func (*NoopOCPStorage) GetUserFeedbackOnRule(
types.ClusterName, types.RuleID, types.ErrorKey, types.UserID,
) (*UserFeedbackOnRule, error) {
return nil, nil
}
// DeleteReportsForOrg noop
func (*NoopOCPStorage) DeleteReportsForOrg(types.OrgID) error {
return nil
}
// DeleteReportsForCluster noop
func (*NoopOCPStorage) DeleteReportsForCluster(types.ClusterName) error {
return nil
}
// GetRuleByID noop
func (*NoopOCPStorage) GetRuleByID(types.RuleID) (*types.Rule, error) {
return nil, nil
}
// GetOrgIDByClusterID noop
func (*NoopOCPStorage) GetOrgIDByClusterID(types.ClusterName) (types.OrgID, error) {
return 0, nil
}
// CreateRule noop
func (*NoopOCPStorage) CreateRule(types.Rule) error {
return nil
}
// DeleteRule noop
func (*NoopOCPStorage) DeleteRule(types.RuleID) error {
return nil
}
// CreateRuleErrorKey noop
func (*NoopOCPStorage) CreateRuleErrorKey(types.RuleErrorKey) error {
return nil
}
// DeleteRuleErrorKey noop
func (*NoopOCPStorage) DeleteRuleErrorKey(types.RuleID, types.ErrorKey) error {
return nil
}
// WriteConsumerError noop
func (*NoopOCPStorage) WriteConsumerError(*sarama.ConsumerMessage, error) error {
return nil
}
// ToggleRuleForCluster noop
func (*NoopOCPStorage) ToggleRuleForCluster(
types.ClusterName, types.RuleID, types.ErrorKey, types.OrgID, RuleToggle,
) error {
return nil
}
// DeleteFromRuleClusterToggle noop
func (*NoopOCPStorage) DeleteFromRuleClusterToggle(
types.ClusterName, types.RuleID) error {
return nil
}
// GetFromClusterRuleToggle noop
func (*NoopOCPStorage) GetFromClusterRuleToggle(
types.ClusterName,
types.RuleID,
) (*ClusterRuleToggle, error) {
return nil, nil
}
// GetTogglesForRules noop
func (*NoopOCPStorage) GetTogglesForRules(
types.ClusterName,
[]types.RuleOnReport,
types.OrgID,
) (map[types.RuleID]bool, error) {
return nil, nil
}
// GetUserFeedbackOnRules noop
func (*NoopOCPStorage) GetUserFeedbackOnRules(
types.ClusterName,
[]types.RuleOnReport,
types.UserID,
) (map[types.RuleID]types.UserVote, error) {
return nil, nil
}
// GetRuleWithContent noop
func (*NoopOCPStorage) GetRuleWithContent(
types.RuleID, types.ErrorKey,
) (*types.RuleWithContent, error) {
return nil, nil
}
// GetUserDisableFeedbackOnRules noop
func (*NoopOCPStorage) GetUserDisableFeedbackOnRules(
types.ClusterName, []types.RuleOnReport, types.UserID,
) (map[types.RuleID]UserFeedbackOnRule, error) {
return nil, nil
}
// DoesClusterExist noop
func (*NoopOCPStorage) DoesClusterExist(types.ClusterName) (bool, error) {
return false, nil
}
// ReadOrgIDsForClusters read organization IDs for given list of cluster names.
func (*NoopOCPStorage) ReadOrgIDsForClusters(_ []types.ClusterName) ([]types.OrgID, error) {
return nil, nil
}
// ReadReportsForClusters function reads reports for given list of cluster
// names.
func (*NoopOCPStorage) ReadReportsForClusters(_ []types.ClusterName) (map[types.ClusterName]types.ClusterReport, error) {
return nil, nil
}
// ListOfDisabledRules function returns list of all rules disabled from a
// specified account (noop).
func (*NoopOCPStorage) ListOfDisabledRules(_ types.OrgID) ([]ctypes.DisabledRule, error) {
return nil, nil
}
// ListOfReasons function returns list of reasons for all rules disabled from a
// specified account (noop).
func (*NoopOCPStorage) ListOfReasons(_ types.UserID) ([]DisabledRuleReason, error) {
return nil, nil
}
// ListOfDisabledClusters function returns list of all clusters disabled for a rule from a
// specified account (noop).
func (*NoopOCPStorage) ListOfDisabledClusters(
_ types.OrgID,
_ types.RuleID,
_ types.ErrorKey,
) ([]ctypes.DisabledClusterInfo, error) {
return nil, nil
}
// ListOfDisabledRulesForClusters function returns list of disabled rules for given clusters from a
// specified account (noop).
func (*NoopOCPStorage) ListOfDisabledRulesForClusters(
_ []string,
_ types.OrgID,
) ([]ctypes.DisabledRule, error) {
return nil, nil
}
// RateOnRule function stores the vote (rating) given by an user to a rule+error key
func (*NoopOCPStorage) RateOnRule(
types.OrgID,
types.RuleID,
types.ErrorKey,
types.UserVote,
) error {
return nil
}
// GetRuleRating retrieves rating for given rule and user
func (*NoopOCPStorage) GetRuleRating(
_ types.OrgID,
_ types.RuleSelector,
) (
ruleRating types.RuleRating,
err error,
) {
return
}
// DisableRuleSystemWide disables the selected rule for all clusters visible to
// given user
func (*NoopOCPStorage) DisableRuleSystemWide(
_ types.OrgID, _ types.RuleID,
_ types.ErrorKey, _ string,
) error {
return nil
}
// EnableRuleSystemWide enables the selected rule for all clusters visible to
// given user
func (*NoopOCPStorage) EnableRuleSystemWide(
_ types.OrgID, _ types.RuleID, _ types.ErrorKey,
) error {
return nil
}
// UpdateDisabledRuleJustification change justification for already disabled rule
func (*NoopOCPStorage) UpdateDisabledRuleJustification(
_ types.OrgID,
_ types.RuleID,
_ types.ErrorKey,
_ string,
) error {
return nil
}
// ReadDisabledRule function returns disabled rule (if disabled) from database
func (*NoopOCPStorage) ReadDisabledRule(
_ types.OrgID, _ types.RuleID, _ types.ErrorKey,
) (ctypes.SystemWideRuleDisable, bool, error) {
return ctypes.SystemWideRuleDisable{}, true, nil
}
// ListOfSystemWideDisabledRules function returns list of all rules that have been
// disabled for all clusters by given user
func (*NoopOCPStorage) ListOfSystemWideDisabledRules(
_ types.OrgID,
) ([]ctypes.SystemWideRuleDisable, error) {
return nil, nil
}
// ReadRecommendationsForClusters reads all recommendations from recommendation table for given organization
func (*NoopOCPStorage) ReadRecommendationsForClusters(
_ []string,
_ types.OrgID,
) (ctypes.RecommendationImpactedClusters, error) {
return nil, nil
}
// ListOfClustersForOrgSpecificRule returns list of all clusters for
// given organization that are affected by given rule
func (*NoopOCPStorage) ListOfClustersForOrgSpecificRule(
_ types.OrgID, _ types.RuleSelector, _ []string,
) ([]ctypes.HittingClustersData, error) {
return nil, nil
}
// ReadClusterListRecommendations retrieves cluster IDs and a list of hitting rules for each one
func (*NoopOCPStorage) ReadClusterListRecommendations(
_ []string, _ types.OrgID,
) (ctypes.ClusterRecommendationMap, error) {
return nil, nil
}
// MigrateToLatest migrates the database to the latest available
// migration version. This must be done before an Init() call.
func (*NoopOCPStorage) MigrateToLatest() error {
return nil
}
// GetConnection returns db connection(useful for testing)
func (*NoopOCPStorage) GetConnection() *sql.DB {
return nil
}
// PrintRuleDisableDebugInfo is a temporary helper function used to print form
// cluster rule toggle related tables
func (*NoopOCPStorage) PrintRuleDisableDebugInfo() {
}
// GetDBDriverType returns db driver type
func (*NoopOCPStorage) GetDBDriverType() types.DBDriver {
return types.DBDriverGeneral
}