Code generalization: request db info from other source: remove unused constants

This commit is contained in:
Michael Hohn
2024-10-28 18:45:21 -07:00
committed by =Michael Hohn
parent 52aafd6fc9
commit e7d32861e5
5 changed files with 20 additions and 33 deletions

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -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