-
Notifications
You must be signed in to change notification settings - Fork 92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce APIError for Sync Calls from CLI to Orchestrator Node #4366
Changes from 15 commits
b7edf08
c4e9ac8
62f9a2d
0f0fe07
7a22883
f5dc730
af77b2f
3548a73
3336679
4de9f18
6b8d0b3
c7a7dde
2df4031
7ec8f2c
65ffc35
af6557a
3f32999
c560b85
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ import ( | |
"github.com/bacalhau-project/bacalhau/pkg/lib/marshaller" | ||
"github.com/bacalhau-project/bacalhau/pkg/lib/math" | ||
"github.com/bacalhau-project/bacalhau/pkg/models" | ||
"github.com/bacalhau-project/bacalhau/pkg/publicapi/apimodels" | ||
"github.com/bacalhau-project/bacalhau/pkg/util" | ||
"github.com/bacalhau-project/bacalhau/pkg/util/idgen" | ||
) | ||
|
@@ -167,6 +168,7 @@ func (b *BoltJobStore) GetJob(ctx context.Context, id string) (models.Job, error | |
} | ||
|
||
func (b *BoltJobStore) getJob(tx *bolt.Tx, jobID string) (models.Job, error) { | ||
|
||
var job models.Job | ||
|
||
jobID, err := b.reifyJobID(tx, jobID) | ||
|
@@ -176,7 +178,7 @@ func (b *BoltJobStore) getJob(tx *bolt.Tx, jobID string) (models.Job, error) { | |
|
||
data := GetBucketData(tx, NewBucketPath(BucketJobs, jobID), SpecKey) | ||
if data == nil { | ||
return job, bacerrors.NewJobNotFound(jobID) | ||
return job, apimodels.NewJobNotFound(jobID) | ||
} | ||
|
||
err = b.marshaller.Unmarshal(data, &job) | ||
|
@@ -189,7 +191,7 @@ func (b *BoltJobStore) reifyJobID(tx *bolt.Tx, jobID string) (string, error) { | |
if idgen.ShortUUID(jobID) == jobID { | ||
bktJobs, err := NewBucketPath(BucketJobs).Get(tx, false) | ||
if err != nil { | ||
return "", err | ||
return "", jobstore.NewBoltDbError(err.Error()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: I would suggest to pass the actual error instead of just the string. This will allow NewBoltDbError to intercept the error and return different types or codes based on the actual error. My not be needed here or now, but I am just thinking ahead when we capture and throw errors for docker executor and s3 publisher for example. You might find this pattern useful to centralize intercepting errors per component There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
} | ||
|
||
found := make([]string, 0, 1) | ||
|
@@ -202,11 +204,11 @@ func (b *BoltJobStore) reifyJobID(tx *bolt.Tx, jobID string) (string, error) { | |
|
||
switch len(found) { | ||
case 0: | ||
return "", bacerrors.NewJobNotFound(jobID) | ||
return "", jobstore.NewErrJobNotFound(jobID) | ||
case 1: | ||
return found[0], nil | ||
default: | ||
return "", bacerrors.NewMultipleJobsFound(jobID, found) | ||
return "", jobstore.NewErrMultipleJobsFound(jobID) | ||
} | ||
} | ||
|
||
|
@@ -223,7 +225,7 @@ func (b *BoltJobStore) getExecution(tx *bolt.Tx, id string) (models.Execution, e | |
} | ||
|
||
if bkt, err := NewBucketPath(BucketJobs, key, BucketJobExecutions).Get(tx, false); err != nil { | ||
return exec, err | ||
return exec, jobstore.NewBoltDbError(err.Error()) | ||
} else { | ||
data := bkt.Get([]byte(id)) | ||
if data == nil { | ||
|
@@ -242,11 +244,11 @@ func (b *BoltJobStore) getExecution(tx *bolt.Tx, id string) (models.Execution, e | |
func (b *BoltJobStore) getExecutionJobID(tx *bolt.Tx, id string) (string, error) { | ||
keys, err := b.executionsIndex.List(tx, []byte(id)) | ||
if err != nil { | ||
return "", err | ||
return "", jobstore.NewBoltDbError(err.Error()) | ||
} | ||
|
||
if len(keys) != 1 { | ||
return "", fmt.Errorf("too many leaf nodes in execution index") | ||
return "", jobstore.NewJobStoreError("too many leaf nodes in execution index") | ||
} | ||
|
||
return string(keys[0]), nil | ||
|
@@ -297,7 +299,7 @@ func (b *BoltJobStore) getExecutions(tx *bolt.Tx, options jobstore.GetExecutions | |
|
||
bkt, err := NewBucketPath(BucketJobs, jobID, BucketJobExecutions).Get(tx, false) | ||
if err != nil { | ||
return nil, err | ||
return nil, jobstore.NewBoltDbError(err.Error()) | ||
} | ||
|
||
var execs []models.Execution | ||
|
@@ -421,20 +423,20 @@ func (b *BoltJobStore) getJobsInitialSet(tx *bolt.Tx, query jobstore.JobQuery) ( | |
if query.ReturnAll || query.Namespace == "" { | ||
bkt, err := NewBucketPath(BucketJobs).Get(tx, false) | ||
if err != nil { | ||
return nil, err | ||
return nil, jobstore.NewBoltDbError(err.Error()) | ||
} | ||
|
||
err = bkt.ForEachBucket(func(k []byte) error { | ||
jobSet[string(k)] = struct{}{} | ||
return nil | ||
}) | ||
if err != nil { | ||
return nil, err | ||
return nil, jobstore.NewBoltDbError(err.Error()) | ||
} | ||
} else { | ||
ids, err := b.namespacesIndex.List(tx, []byte(query.Namespace)) | ||
if err != nil { | ||
return nil, err | ||
return nil, jobstore.NewBoltDbError(err.Error()) | ||
} | ||
|
||
for _, k := range ids { | ||
|
@@ -455,7 +457,7 @@ func (b *BoltJobStore) getJobsIncludeTags(tx *bolt.Tx, jobSet map[string]struct{ | |
tagLabel := []byte(strings.ToLower(tag)) | ||
ids, err := b.tagsIndex.List(tx, tagLabel) | ||
if err != nil { | ||
return nil, err | ||
return nil, jobstore.NewBoltDbError(err.Error()) | ||
} | ||
|
||
for _, k := range ids { | ||
|
@@ -483,7 +485,7 @@ func (b *BoltJobStore) getJobsExcludeTags(tx *bolt.Tx, jobSet map[string]struct{ | |
tagLabel := []byte(strings.ToLower(tag)) | ||
ids, err := b.tagsIndex.List(tx, tagLabel) | ||
if err != nil { | ||
return nil, err | ||
return nil, jobstore.NewBoltDbError(err.Error()) | ||
} | ||
|
||
for _, k := range ids { | ||
|
@@ -584,7 +586,7 @@ func (b *BoltJobStore) getInProgressJobs(tx *bolt.Tx, jobType string) ([]models. | |
|
||
keys, err := b.inProgressIndex.List(tx) | ||
if err != nil { | ||
return nil, err | ||
return nil, jobstore.NewBoltDbError(err.Error()) | ||
} | ||
|
||
for _, jobIDKey := range keys { | ||
|
@@ -758,7 +760,7 @@ func (b *BoltJobStore) CreateJob(ctx context.Context, job models.Job) error { | |
job.Normalize() | ||
err := job.Validate() | ||
if err != nil { | ||
return err | ||
return jobstore.NewJobStoreError(err.Error()) | ||
} | ||
return b.update(ctx, func(tx *bolt.Tx) (err error) { | ||
return b.createJob(tx, job) | ||
|
@@ -777,7 +779,7 @@ func (b *BoltJobStore) update(ctx context.Context, update func(tx *bolt.Tx) erro | |
tx, externalTx = txFromContext(ctx) | ||
if externalTx { | ||
if !tx.Writable() { | ||
return fmt.Errorf("readonly transaction provided in context for update operation") | ||
return jobstore.NewBoltDbError("readonly transaction provided in context for update operation") | ||
} | ||
} else { | ||
tx, err = b.database.Begin(true) | ||
|
@@ -817,7 +819,7 @@ func (b *BoltJobStore) view(ctx context.Context, view func(tx *bolt.Tx) error) e | |
if !externalTx { | ||
tx, err = b.database.Begin(false) | ||
if err != nil { | ||
return err | ||
return jobstore.NewBoltDbError(err.Error()) | ||
} | ||
} | ||
|
||
|
@@ -844,21 +846,21 @@ func (b *BoltJobStore) createJob(tx *bolt.Tx, job models.Job) error { | |
|
||
jobIDKey := []byte(job.ID) | ||
if bkt, err := NewBucketPath(BucketJobs, job.ID).Get(tx, true); err != nil { | ||
return err | ||
return jobstore.NewBoltDbError(err.Error()) | ||
} else { | ||
// Create the evaluations and executions buckets and so forth | ||
if _, err := bkt.CreateBucketIfNotExists([]byte(BucketJobExecutions)); err != nil { | ||
return err | ||
} | ||
if _, err := bkt.CreateBucketIfNotExists([]byte(BucketJobEvaluations)); err != nil { | ||
return err | ||
return jobstore.NewBoltDbError(err.Error()) | ||
} | ||
if _, err := bkt.CreateBucketIfNotExists([]byte(BucketJobHistory)); err != nil { | ||
return err | ||
return jobstore.NewBoltDbError(err.Error()) | ||
} | ||
|
||
if _, err := bkt.CreateBucketIfNotExists([]byte(BucketExecutionHistory)); err != nil { | ||
return err | ||
return jobstore.NewBoltDbError(err.Error()) | ||
} | ||
} | ||
|
||
|
@@ -869,7 +871,7 @@ func (b *BoltJobStore) createJob(tx *bolt.Tx, job models.Job) error { | |
} | ||
|
||
if bkt, err := NewBucketPath(BucketJobs, job.ID).Get(tx, false); err != nil { | ||
return err | ||
return jobstore.NewBoltDbError(err.Error()) | ||
} else { | ||
if err = bkt.Put(SpecKey, jobData); err != nil { | ||
return err | ||
|
@@ -879,11 +881,11 @@ func (b *BoltJobStore) createJob(tx *bolt.Tx, job models.Job) error { | |
// Create a composite key for the in progress index | ||
jobkey := createInProgressIndexKey(&job) | ||
if err = b.inProgressIndex.Add(tx, []byte(jobkey)); err != nil { | ||
return err | ||
return jobstore.NewBoltDbError(err.Error()) | ||
} | ||
|
||
if err = b.namespacesIndex.Add(tx, jobIDKey, []byte(job.Namespace)); err != nil { | ||
return err | ||
return jobstore.NewBoltDbError(err.Error()) | ||
} | ||
|
||
// Write sentinels keys for specific tags | ||
|
@@ -909,7 +911,7 @@ func (b *BoltJobStore) deleteJob(tx *bolt.Tx, jobID string) error { | |
|
||
job, err := b.getJob(tx, jobID) | ||
if err != nil { | ||
return bacerrors.NewJobNotFound(jobID) | ||
apimodels.NewJobNotFound(jobID) | ||
} | ||
|
||
tx.OnCommit(func() { | ||
|
@@ -918,7 +920,7 @@ func (b *BoltJobStore) deleteJob(tx *bolt.Tx, jobID string) error { | |
|
||
// Delete the Job bucket (and everything within it) | ||
if bkt, err := NewBucketPath(BucketJobs).Get(tx, false); err != nil { | ||
return err | ||
return jobstore.NewBoltDbError(err.Error()) | ||
} else { | ||
if err = bkt.DeleteBucket([]byte(jobID)); err != nil { | ||
return err | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it doesn't sound right that internal and backend components depend on
apimodels
which are meant for the http API between frontend (api server) and clients.Some suggestions:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, please let me know your thoughts about it.