github.com/weaviate/weaviate@v1.24.6/adapters/handlers/rest/clusterapi/fakes_for_test.go (about) 1 // _ _ 2 // __ _____ __ ___ ___ __ _| |_ ___ 3 // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \ 4 // \ V V / __/ (_| |\ V /| | (_| | || __/ 5 // \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___| 6 // 7 // Copyright © 2016 - 2024 Weaviate B.V. All rights reserved. 8 // 9 // CONTACT: hello@weaviate.io 10 // 11 12 package clusterapi_test 13 14 import ( 15 "context" 16 17 "github.com/pkg/errors" 18 "github.com/weaviate/weaviate/entities/models" 19 schemaent "github.com/weaviate/weaviate/entities/schema" 20 ucs "github.com/weaviate/weaviate/usecases/schema" 21 "github.com/weaviate/weaviate/usecases/schema/migrate" 22 "github.com/weaviate/weaviate/usecases/sharding" 23 ) 24 25 type fakeRepo struct { 26 schema ucs.State 27 } 28 29 func newFakeRepo() *fakeRepo { 30 return &fakeRepo{ 31 schema: ucs.NewState(1), 32 } 33 } 34 35 func (f *fakeRepo) Save(ctx context.Context, schema ucs.State) error { 36 f.schema = schema 37 return nil 38 } 39 40 func (f *fakeRepo) Load(context.Context) (ucs.State, error) { 41 return f.schema, nil 42 } 43 44 func (f *fakeRepo) NewClass(context.Context, ucs.ClassPayload) error { 45 return nil 46 } 47 48 func (f *fakeRepo) UpdateClass(context.Context, ucs.ClassPayload) error { 49 return nil 50 } 51 52 func (f *fakeRepo) DeleteClass(ctx context.Context, class string) error { 53 return nil 54 } 55 56 func (f *fakeRepo) NewShards(ctx context.Context, class string, shards []ucs.KeyValuePair) error { 57 return nil 58 } 59 60 func (f *fakeRepo) UpdateShards(ctx context.Context, class string, shards []ucs.KeyValuePair) error { 61 return nil 62 } 63 64 func (f *fakeRepo) DeleteShards(ctx context.Context, class string, shards []string) error { 65 return nil 66 } 67 68 type fakeAuthorizer struct{} 69 70 func (f *fakeAuthorizer) Authorize(principal *models.Principal, verb, resource string) error { 71 return nil 72 } 73 74 type fakeVectorConfig map[string]interface{} 75 76 func (f fakeVectorConfig) IndexType() string { 77 return "fake" 78 } 79 80 func (f fakeVectorConfig) DistanceName() string { 81 return "fake" 82 } 83 84 func dummyParseVectorConfig(in interface{}, indexType string) (schemaent.VectorIndexConfig, error) { 85 return fakeVectorConfig(in.(map[string]interface{})), nil 86 } 87 88 func dummyValidateInvertedConfig(in *models.InvertedIndexConfig) error { 89 return nil 90 } 91 92 type fakeVectorizerValidator struct { 93 valid []string 94 } 95 96 func (f *fakeVectorizerValidator) ValidateVectorizer(moduleName string) error { 97 for _, valid := range f.valid { 98 if moduleName == valid { 99 return nil 100 } 101 } 102 103 return errors.Errorf("invalid vectorizer %q", moduleName) 104 } 105 106 type fakeModuleConfig struct{} 107 108 func (f *fakeModuleConfig) SetClassDefaults(class *models.Class) { 109 defaultConfig := map[string]interface{}{ 110 "my-module1": map[string]interface{}{ 111 "my-setting": "default-value", 112 }, 113 } 114 115 asMap, ok := class.ModuleConfig.(map[string]interface{}) 116 if !ok { 117 class.ModuleConfig = defaultConfig 118 return 119 } 120 121 module, ok := asMap["my-module1"] 122 if !ok { 123 class.ModuleConfig = defaultConfig 124 return 125 } 126 127 asMap, ok = module.(map[string]interface{}) 128 if !ok { 129 class.ModuleConfig = defaultConfig 130 return 131 } 132 133 if _, ok := asMap["my-setting"]; !ok { 134 asMap["my-setting"] = "default-value" 135 defaultConfig["my-module1"] = asMap 136 class.ModuleConfig = defaultConfig 137 } 138 } 139 140 func (f *fakeModuleConfig) SetSinglePropertyDefaults(class *models.Class, 141 prop *models.Property) { 142 } 143 144 func (f *fakeModuleConfig) ValidateClass(ctx context.Context, class *models.Class) error { 145 return nil 146 } 147 148 type fakeClusterState struct { 149 hosts []string 150 } 151 152 func (f *fakeClusterState) SchemaSyncIgnored() bool { 153 return false 154 } 155 156 func (f *fakeClusterState) SkipSchemaRepair() bool { 157 return false 158 } 159 160 func (f *fakeClusterState) Hostnames() []string { 161 return f.hosts 162 } 163 164 func (f *fakeClusterState) AllNames() []string { 165 return f.hosts 166 } 167 168 func (f *fakeClusterState) Candidates() []string { 169 return f.hosts 170 } 171 172 func (f *fakeClusterState) LocalName() string { 173 return f.hosts[0] 174 } 175 176 func (f *fakeClusterState) NodeCount() int { 177 return len(f.hosts) 178 } 179 180 func (f *fakeClusterState) ClusterHealthScore() int { 181 // 0 - healthy, >0 - unhealthy 182 return 0 183 } 184 185 func (f *fakeClusterState) ResolveParentNodes(string, string) (map[string]string, error) { 186 return nil, nil 187 } 188 189 func (f *fakeClusterState) NodeHostname(nodeName string) (string, bool) { 190 return "", false 191 } 192 193 type NilMigrator struct{} 194 195 func (n *NilMigrator) AddClass(ctx context.Context, class *models.Class, 196 shardingState *sharding.State, 197 ) error { 198 return nil 199 } 200 201 func (n *NilMigrator) DropClass(ctx context.Context, className string) error { 202 return nil 203 } 204 205 func (n *NilMigrator) UpdateClass(ctx context.Context, className string, newClassName *string) error { 206 return nil 207 } 208 209 func (n *NilMigrator) GetShardsQueueSize(ctx context.Context, className, tenant string) (map[string]int64, error) { 210 return nil, nil 211 } 212 213 func (n *NilMigrator) GetShardsStatus(ctx context.Context, className, tenant string) (map[string]string, error) { 214 return nil, nil 215 } 216 217 func (n *NilMigrator) UpdateShardStatus(ctx context.Context, className, shardName, targetStatus string) error { 218 return nil 219 } 220 221 func (n *NilMigrator) AddProperty(ctx context.Context, className string, prop *models.Property) error { 222 return nil 223 } 224 225 func (n *NilMigrator) NewTenants(ctx context.Context, class *models.Class, creates []*migrate.CreateTenantPayload) (commit func(success bool), err error) { 226 return nil, nil 227 } 228 229 func (n *NilMigrator) UpdateTenants(ctx context.Context, class *models.Class, updates []*migrate.UpdateTenantPayload) (commit func(success bool), err error) { 230 return nil, nil 231 } 232 233 func (n *NilMigrator) DeleteTenants(ctx context.Context, class *models.Class, partitions []string) (commit func(success bool), err error) { 234 return nil, nil 235 } 236 237 func (n *NilMigrator) UpdateProperty(ctx context.Context, className string, propName string, newName *string) error { 238 return nil 239 } 240 241 func (n *NilMigrator) UpdatePropertyAddDataType(ctx context.Context, className string, propName string, newDataType string) error { 242 return nil 243 } 244 245 func (n *NilMigrator) DropProperty(ctx context.Context, className string, propName string) error { 246 return nil 247 } 248 249 func (n *NilMigrator) ValidateVectorIndexConfigUpdate(ctx context.Context, old, updated schemaent.VectorIndexConfig) error { 250 return nil 251 } 252 253 func (n *NilMigrator) UpdateVectorIndexConfig(ctx context.Context, className string, updated schemaent.VectorIndexConfig) error { 254 return nil 255 } 256 257 func (n *NilMigrator) ValidateVectorIndexConfigsUpdate(ctx context.Context, 258 old, updated map[string]schemaent.VectorIndexConfig, 259 ) error { 260 return nil 261 } 262 263 func (n *NilMigrator) UpdateVectorIndexConfigs(ctx context.Context, className string, 264 updated map[string]schemaent.VectorIndexConfig, 265 ) error { 266 return nil 267 } 268 269 func (n *NilMigrator) ValidateInvertedIndexConfigUpdate(ctx context.Context, old, updated *models.InvertedIndexConfig) error { 270 return nil 271 } 272 273 func (n *NilMigrator) UpdateInvertedIndexConfig(ctx context.Context, className string, updated *models.InvertedIndexConfig) error { 274 return nil 275 } 276 277 func (n *NilMigrator) RecalculateVectorDimensions(ctx context.Context) error { 278 return nil 279 } 280 281 func (n *NilMigrator) RecountProperties(ctx context.Context) error { 282 return nil 283 } 284 285 func (n *NilMigrator) InvertedReindex(ctx context.Context, taskNames ...string) error { 286 return nil 287 } 288 289 func (n *NilMigrator) AdjustFilterablePropSettings(ctx context.Context) error { 290 return nil 291 }