Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions app/broker/errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package broker

import (
"errors"
)

var (
// ErrMissingPayloadKey means that payload was missing from request headers.
ErrMissingPayloadKey = errors.New("missing payload")
// ErrJSONParsingFailed is used to mark any JSON unmarshal error during payload parsing.
ErrJSONParsingFailed = errors.New("json parsing error, expected an object")
)
11 changes: 3 additions & 8 deletions app/broker/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ import (
"go.opencensus.io/stats/view"
census_trace "go.opencensus.io/trace"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/metadata"
"google.golang.org/grpc/status"

"github.com/Syncano/codebox/app/common"
"github.com/Syncano/pkg-go/celery"
Expand Down Expand Up @@ -70,9 +68,6 @@ var DefaultOptions = &ServerOptions{
}

var (
// ErrInvalidArgument signals that there are no suitable workers at this moment.
ErrInvalidArgument = status.Error(codes.InvalidArgument, "invalid argument")

initOnce sync.Once
overheadDuration = stats.Float64(
"codebox/overhead/duration/seconds",
Expand Down Expand Up @@ -181,7 +176,7 @@ func (s *Server) Run(stream brokerpb.ScriptRunner_RunServer) error {
scriptMeta = v.ScriptMeta
default:
logger.Error("grpc:broker:Run error parsing input")
return ErrInvalidArgument
return common.ErrInvalidArgument
}

if meta != nil && lbMeta != nil && scriptMeta != nil {
Expand All @@ -197,7 +192,7 @@ func (s *Server) Run(stream brokerpb.ScriptRunner_RunServer) error {

chunk := req.GetScriptChunk()
if chunk == nil {
return nil, ErrInvalidArgument
return nil, common.ErrInvalidArgument
}

return chunk, nil
Expand All @@ -211,7 +206,7 @@ func (s *Server) processRun(ctx context.Context, logger logrus.FieldLogger,
stream StreamReponder) error {
if meta == nil || lbMeta == nil || scriptMeta == nil {
logger.Error("grpc:broker:Run error parsing input")
return ErrInvalidArgument
return common.ErrInvalidArgument
}

start := time.Now()
Expand Down
3 changes: 2 additions & 1 deletion app/broker/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"google.golang.org/grpc/grpclog"

"github.com/Syncano/codebox/app/broker/mocks"
"github.com/Syncano/codebox/app/common"
repomocks "github.com/Syncano/codebox/app/filerepo/mocks"
lbmocks "github.com/Syncano/codebox/app/lb/mocks"
"github.com/Syncano/pkg-go/celery"
Expand Down Expand Up @@ -82,7 +83,7 @@ func TestServerMethods(t *testing.T) {
Convey("Run returns error on invalid request", func() {
stream.On("Context").Return(context.Background())
e := s.SimpleRun(new(brokerpb.SimpleRunRequest), stream)
So(e, ShouldResemble, ErrInvalidArgument)
So(e, ShouldResemble, common.ErrInvalidArgument)
})
Convey("Run processes on valid request", func() {
sourceHash := "abc"
Expand Down
7 changes: 1 addition & 6 deletions app/broker/uwsgi.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package broker
import (
"context"
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"net/http"
Expand All @@ -22,11 +21,7 @@ import (
)

var (
// ErrMissingPayloadKey means that payload was missing from request headers.
ErrMissingPayloadKey = errors.New("missing payload")
// ErrJSONParsingFailed is used to mark any JSON unmarshal error during payload parsing.
ErrJSONParsingFailed = errors.New("json parsing error, expected an object")
statusToHTTPCode = map[string]int{
statusToHTTPCode = map[string]int{
failureStatus: http.StatusInternalServerError,
blockedStatus: http.StatusTooManyRequests,
timeoutStatus: http.StatusRequestTimeout,
Expand Down
13 changes: 13 additions & 0 deletions app/common/errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package common

import (
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)

var (
// ErrSourceNotAvailable signals that specified source hash was not found.
ErrSourceNotAvailable = status.Error(codes.FailedPrecondition, "source not available")

ErrInvalidArgument = status.Error(codes.InvalidArgument, "invalid argument")
)
6 changes: 6 additions & 0 deletions app/docker/errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package docker

import "errors"

// ErrReservedCPUTooHigh signals that too we are trying to reserve more cpu than we got.
var ErrReservedCPUTooHigh = errors.New("value of reserved cpu is higher than available")
4 changes: 0 additions & 4 deletions app/docker/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package docker

import (
"context"
"errors"
"io"
"io/ioutil"
"time"
Expand Down Expand Up @@ -45,9 +44,6 @@ var DefaultOptions = &Options{
DNS: []string{"208.67.222.222", "208.67.220.220"},
}

// ErrReservedCPUTooHigh signals that too we are trying to reserve more cpu than we got.
var ErrReservedCPUTooHigh = errors.New("value of reserved cpu is higher than available")

// Constraints defines limitations for docker container.
type Constraints struct {
CPULimit int64
Expand Down
20 changes: 20 additions & 0 deletions app/filerepo/errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package filerepo

import (
"errors"

"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)

var (
// ErrMissingMeta signals that there are upload format was invalid and was missing upload meta.
ErrMissingMeta = status.Error(codes.FailedPrecondition, "missing upload meta")

// ErrResourceNotFound signals that resource key was not found and it was a must.
ErrResourceNotFound = errors.New("resource not found")
// ErrVolumeNotFound signals that volume key was not found and it was a must.
ErrVolumeNotFound = errors.New("volume not found")
// ErrNotEnoughDiskSpace signals that there is not enough disk space available on storage path.
ErrNotEnoughDiskSpace = errors.New("not enough disk space")
)
10 changes: 0 additions & 10 deletions app/filerepo/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package filerepo

import (
"bufio"
"errors"
"io"
"os"
"path/filepath"
Expand Down Expand Up @@ -69,15 +68,6 @@ type Resource struct {
Path string
}

var (
// ErrResourceNotFound signals that resource key was not found and it was a must.
ErrResourceNotFound = errors.New("resource not found")
// ErrVolumeNotFound signals that volume key was not found and it was a must.
ErrVolumeNotFound = errors.New("volume not found")
// ErrNotEnoughDiskSpace signals that there is not enough disk space available on storage path.
ErrNotEnoughDiskSpace = errors.New("not enough disk space")
)

const (
fileStorageName = "files"
volumeStorageName = "volumes"
Expand Down
5 changes: 0 additions & 5 deletions app/filerepo/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ type Server struct {
// Assert that Server is compatible with proto interface.
var _ pb.RepoServer = (*Server)(nil)

var (
// ErrMissingMeta signals that there are upload format was invalid and was missing upload meta.
ErrMissingMeta = status.Error(codes.FailedPrecondition, "missing upload meta")
)

// Exists checks if file was defined in file repo.
func (s *Server) Exists(ctx context.Context, in *pb.ExistsRequest) (*pb.ExistsResponse, error) {
ctx, reqID := util.AddDefaultRequestID(ctx)
Expand Down
13 changes: 13 additions & 0 deletions app/lb/errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package lb

import (
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)

var (
// ErrUnknownWorkerID signals that we received a message for unknown worker.
ErrUnknownWorkerID = status.Error(codes.InvalidArgument, "unknown worker id")
// ErrNoWorkersAvailable signals that there are no suitable workers at this moment.
ErrNoWorkersAvailable = status.Error(codes.ResourceExhausted, "no workers available")
)
Loading