From e7d32861e582d427e10d51e2e4512d1f945a91b2 Mon Sep 17 00:00:00 2001 From: Michael Hohn Date: Mon, 28 Oct 2024 18:45:21 -0700 Subject: [PATCH] Code generalization: request db info from other source: remove unused constants --- pkg/artifactstore/common.go | 12 +++--------- pkg/artifactstore/store_memory.go | 17 +++++++---------- pkg/artifactstore/store_minio.go | 21 +++++++++------------ pkg/qldbstore/qldbstore_minio.go | 2 -- pkg/server/server.go | 1 + 5 files changed, 20 insertions(+), 33 deletions(-) diff --git a/pkg/artifactstore/common.go b/pkg/artifactstore/common.go index 9c65089..7bc971b 100644 --- a/pkg/artifactstore/common.go +++ b/pkg/artifactstore/common.go @@ -5,22 +5,16 @@ import ( "mrvacommander/pkg/common" ) +// xx: afl use // XX: static types: split by type? // Restrict the keys / values for ArtifactLocation and centralize the common ones // here const ( - AF_VAL_BUCKET_RESULTS = "results" - AF_VAL_BUCKET_PACKS = "packs" - AF_KEY_BUCKET = "bucket" - AF_KEY_KEY = "key" + AF_BUCKETNAME_RESULTS = "results" + AF_BUCKETNAME_PACKS = "packs" ) type ArtifactLocation struct { - // Data is a map of key-value pairs that describe the location of the artifact. - // For example, a simple key-value pair could be "path" -> "/path/to/artifact.tgz". - // Alternatively, a more complex example could be "bucket" -> "example", "key" -> "UNIQUE_ARTIFACT_IDENTIFIER". - // XX: static types - // Data map[string]string `json:"data"` Key string // location in bucket Bucket string // which bucket: packs or results } diff --git a/pkg/artifactstore/store_memory.go b/pkg/artifactstore/store_memory.go index dd3b1cf..e56e700 100644 --- a/pkg/artifactstore/store_memory.go +++ b/pkg/artifactstore/store_memory.go @@ -25,6 +25,7 @@ func (store *InMemoryArtifactStore) GetQueryPack(location ArtifactLocation) ([]b store.mu.Lock() defer store.mu.Unlock() + // xx: afl use // XX: static types // key := location.Data[AF_KEY_KEY] key := location.Key @@ -44,13 +45,10 @@ func (store *InMemoryArtifactStore) SaveQueryPack(sessionId int, data []byte) (A store.packs[key] = data // XX: static types + // xx: afl use location := ArtifactLocation{ - Bucket: AF_VAL_BUCKET_PACKS, + Bucket: AF_BUCKETNAME_PACKS, Key: key, - // Data: map[string]string{ - // AF_KEY_BUCKET: AF_VAL_BUCKET_PACKS, - // AF_KEY_KEY: key, - // }, } return location, nil } @@ -60,6 +58,7 @@ func (store *InMemoryArtifactStore) GetResult(location ArtifactLocation) ([]byte store.mu.Lock() defer store.mu.Unlock() + // xx: afl use // key := location.Data[AF_KEY_KEY] key := location.Key data, exists := store.results[key] @@ -75,6 +74,7 @@ func (store *InMemoryArtifactStore) GetResultSize(location ArtifactLocation) (in defer store.mu.Unlock() // key := location.Data[AF_KEY_KEY] + // xx: afl use key := location.Key data, exists := store.results[key] if !exists { @@ -92,13 +92,10 @@ func (store *InMemoryArtifactStore) SaveResult(jobSpec common.JobSpec, data []by store.results[key] = data // XX: static types + // xx: afl use location := ArtifactLocation{ - Bucket: AF_VAL_BUCKET_RESULTS, + Bucket: AF_BUCKETNAME_RESULTS, Key: key, - // Data: map[string]string{ - // AF_KEY_BUCKET: AF_VAL_BUCKET_RESULTS, - // AF_KEY_KEY: key, - // }, } return location, nil } diff --git a/pkg/artifactstore/store_minio.go b/pkg/artifactstore/store_minio.go index 99f310c..221a30f 100644 --- a/pkg/artifactstore/store_minio.go +++ b/pkg/artifactstore/store_minio.go @@ -29,12 +29,12 @@ func NewMinIOArtifactStore(endpoint, id, secret string) (*MinIOArtifactStore, er slog.Info("Connected to MinIO artifact store server") // Create "results" bucket - if err := common.CreateMinIOBucketIfNotExists(minioClient, AF_VAL_BUCKET_RESULTS); err != nil { + if err := common.CreateMinIOBucketIfNotExists(minioClient, AF_BUCKETNAME_RESULTS); err != nil { return nil, fmt.Errorf("could not create results bucket: %v", err) } // Create "packs" bucket - if err := common.CreateMinIOBucketIfNotExists(minioClient, AF_VAL_BUCKET_PACKS); err != nil { + if err := common.CreateMinIOBucketIfNotExists(minioClient, AF_BUCKETNAME_PACKS); err != nil { return nil, fmt.Errorf("could not create packs bucket: %v", err) } @@ -48,7 +48,8 @@ func (store *MinIOArtifactStore) GetQueryPack(location ArtifactLocation) ([]byte } func (store *MinIOArtifactStore) SaveQueryPack(jobId int, data []byte) (ArtifactLocation, error) { - return store.saveArtifact(AF_VAL_BUCKET_PACKS, deriveKeyFromSessionId(jobId), data, "application/gzip") + // xx: afl use + return store.saveArtifact(AF_BUCKETNAME_PACKS, deriveKeyFromSessionId(jobId), data, "application/gzip") } func (store *MinIOArtifactStore) GetResult(location ArtifactLocation) ([]byte, error) { @@ -56,8 +57,7 @@ func (store *MinIOArtifactStore) GetResult(location ArtifactLocation) ([]byte, e } func (store *MinIOArtifactStore) GetResultSize(location ArtifactLocation) (int, error) { - // bucket := location.Data[AF_KEY_BUCKET] - // key := location.Data[AF_KEY_KEY] + // xx: afl use bucket := location.Bucket key := location.Key @@ -74,14 +74,14 @@ func (store *MinIOArtifactStore) GetResultSize(location ArtifactLocation) (int, } func (store *MinIOArtifactStore) SaveResult(jobSpec common.JobSpec, data []byte) (ArtifactLocation, error) { - return store.saveArtifact(AF_VAL_BUCKET_RESULTS, deriveKeyFromJobSpec(jobSpec), data, "application/zip") + // xx: afl use + return store.saveArtifact(AF_BUCKETNAME_RESULTS, deriveKeyFromJobSpec(jobSpec), data, "application/zip") } func (store *MinIOArtifactStore) getArtifact(location ArtifactLocation) ([]byte, error) { + // xx: afl use bucket := location.Bucket key := location.Key - // bucket := location.Data[AF_KEY_BUCKET] - // key := location.Data[AF_KEY_KEY] object, err := store.client.GetObject(context.Background(), bucket, key, minio.GetObjectOptions{}) if err != nil { @@ -107,14 +107,11 @@ func (store *MinIOArtifactStore) saveArtifact(bucket, key string, data []byte, return ArtifactLocation{}, err } + // XX: afl use // XX: static types location := ArtifactLocation{ Bucket: bucket, Key: key, - // Data: map[string]string{ - // AF_KEY_BUCKET: bucket, - // AF_KEY_KEY: key, - // }, } return location, nil diff --git a/pkg/qldbstore/qldbstore_minio.go b/pkg/qldbstore/qldbstore_minio.go index 7c426bf..0045610 100644 --- a/pkg/qldbstore/qldbstore_minio.go +++ b/pkg/qldbstore/qldbstore_minio.go @@ -15,8 +15,6 @@ import ( // Restrict the keys / values and centralize the common ones here const ( QL_DB_BUCKETNAME = "qldb" - QL_KEY_BUCKET = "bucket" - QL_KEY_KEY = "key" ) type MinIOCodeQLDatabaseStore struct { diff --git a/pkg/server/server.go b/pkg/server/server.go index 25a49c8..4ee4aa6 100644 --- a/pkg/server/server.go +++ b/pkg/server/server.go @@ -791,6 +791,7 @@ func (c *CommanderSingle) decodeAndSaveBase64QueryPack(qp string, sessionId int) return artifactstore.ArtifactLocation{}, err } + // XX: afl use artifactLocation, err := c.v.Artifacts.SaveQueryPack(sessionId, tgz) if err != nil { slog.Error("Failed to save query pack", "err", err)