Changed api runner id to use a UUID
This commit is contained in:
@@ -8,6 +8,7 @@ require (
|
|||||||
github.com/docker/docker v20.10.22+incompatible
|
github.com/docker/docker v20.10.22+incompatible
|
||||||
github.com/go-git/go-git/v5 v5.4.3-0.20220529141257-bc1f419cebcf
|
github.com/go-git/go-git/v5 v5.4.3-0.20220529141257-bc1f419cebcf
|
||||||
github.com/go-playground/webhooks/v6 v6.0.1
|
github.com/go-playground/webhooks/v6 v6.0.1
|
||||||
|
github.com/google/uuid v1.3.0
|
||||||
github.com/op/go-logging v0.0.0-20160315200505-970db520ece7
|
github.com/op/go-logging v0.0.0-20160315200505-970db520ece7
|
||||||
golang.org/x/net v0.2.0
|
golang.org/x/net v0.2.0
|
||||||
google.golang.org/protobuf v1.28.1
|
google.golang.org/protobuf v1.28.1
|
||||||
|
|||||||
@@ -668,6 +668,7 @@ github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+
|
|||||||
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||||
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||||
github.com/google/uuid v1.2.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
github.com/google/uuid v1.2.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||||
|
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
|
||||||
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||||
github.com/google/wire v0.3.0/go.mod h1:i1DMg/Lu8Sz5yYl25iOdmc5CT5qusaa+zmRWs16741s=
|
github.com/google/wire v0.3.0/go.mod h1:i1DMg/Lu8Sz5yYl25iOdmc5CT5qusaa+zmRWs16741s=
|
||||||
github.com/googleapis/enterprise-certificate-proxy v0.0.0-20220520183353-fd19c99a87aa/go.mod h1:17drOmN3MwGY7t0e+Ei9b45FFGA3fBs3x36SsCg1hq8=
|
github.com/googleapis/enterprise-certificate-proxy v0.0.0-20220520183353-fd19c99a87aa/go.mod h1:17drOmN3MwGY7t0e+Ei9b45FFGA3fBs3x36SsCg1hq8=
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import (
|
|||||||
"git.ohea.xyz/cursorius/server/proto/gen/api/v1/apiv1connect"
|
"git.ohea.xyz/cursorius/server/proto/gen/api/v1/apiv1connect"
|
||||||
"git.ohea.xyz/cursorius/server/runnermanager"
|
"git.ohea.xyz/cursorius/server/runnermanager"
|
||||||
"github.com/bufbuild/connect-go"
|
"github.com/bufbuild/connect-go"
|
||||||
|
"github.com/google/uuid"
|
||||||
"github.com/op/go-logging"
|
"github.com/op/go-logging"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -18,9 +19,7 @@ var log = logging.MustGetLogger("cursorius-server")
|
|||||||
|
|
||||||
type ApiServer struct {
|
type ApiServer struct {
|
||||||
getRunnerCh chan runnermanager.GetRunnerRequest
|
getRunnerCh chan runnermanager.GetRunnerRequest
|
||||||
allocatedRunners map[int64]RunnerWrapper
|
allocatedRunners map[uuid.UUID]RunnerWrapper
|
||||||
currentId int64
|
|
||||||
currentIdMutex sync.Mutex
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type RunnerWrapper struct {
|
type RunnerWrapper struct {
|
||||||
@@ -53,15 +52,12 @@ func (s *ApiServer) GetRunner(
|
|||||||
|
|
||||||
log.Info("Got runner with tags: %v", runnerTagsStr)
|
log.Info("Got runner with tags: %v", runnerTagsStr)
|
||||||
|
|
||||||
s.currentIdMutex.Lock()
|
runnerUuid := uuid.New()
|
||||||
runnerId := s.currentId
|
|
||||||
s.currentId++
|
|
||||||
s.currentIdMutex.Unlock()
|
|
||||||
|
|
||||||
s.allocatedRunners[runnerId] = RunnerWrapper{runner: response.Runner}
|
s.allocatedRunners[runnerUuid] = RunnerWrapper{runner: response.Runner}
|
||||||
|
|
||||||
res := connect.NewResponse(&apiv1.GetRunnerResponse{
|
res := connect.NewResponse(&apiv1.GetRunnerResponse{
|
||||||
RunnerId: runnerId,
|
Id: runnerUuid.String(),
|
||||||
})
|
})
|
||||||
res.Header().Set("GetRunner-Version", "v1")
|
res.Header().Set("GetRunner-Version", "v1")
|
||||||
return res, nil
|
return res, nil
|
||||||
@@ -84,8 +80,7 @@ func (s *ApiServer) RunCommand(
|
|||||||
func CreateHandler(mux *http.ServeMux, getRunnerCh chan runnermanager.GetRunnerRequest) {
|
func CreateHandler(mux *http.ServeMux, getRunnerCh chan runnermanager.GetRunnerRequest) {
|
||||||
api_server := &ApiServer{
|
api_server := &ApiServer{
|
||||||
getRunnerCh: getRunnerCh,
|
getRunnerCh: getRunnerCh,
|
||||||
allocatedRunners: make(map[int64]RunnerWrapper),
|
allocatedRunners: make(map[uuid.UUID]RunnerWrapper),
|
||||||
currentId: 0,
|
|
||||||
}
|
}
|
||||||
path, handler := apiv1connect.NewGetRunnerServiceHandler(api_server)
|
path, handler := apiv1connect.NewGetRunnerServiceHandler(api_server)
|
||||||
mux.Handle(path, handler)
|
mux.Handle(path, handler)
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ message GetRunnerRequest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
message GetRunnerResponse {
|
message GetRunnerResponse {
|
||||||
int64 runner_id = 1;
|
string id = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
service GetRunnerService {
|
service GetRunnerService {
|
||||||
|
|||||||
@@ -127,7 +127,7 @@ type GetRunnerResponse struct {
|
|||||||
sizeCache protoimpl.SizeCache
|
sizeCache protoimpl.SizeCache
|
||||||
unknownFields protoimpl.UnknownFields
|
unknownFields protoimpl.UnknownFields
|
||||||
|
|
||||||
RunnerId int64 `protobuf:"varint,1,opt,name=runner_id,json=runnerId,proto3" json:"runner_id,omitempty"`
|
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *GetRunnerResponse) Reset() {
|
func (x *GetRunnerResponse) Reset() {
|
||||||
@@ -162,11 +162,11 @@ func (*GetRunnerResponse) Descriptor() ([]byte, []int) {
|
|||||||
return file_api_v1_get_runner_proto_rawDescGZIP(), []int{2}
|
return file_api_v1_get_runner_proto_rawDescGZIP(), []int{2}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *GetRunnerResponse) GetRunnerId() int64 {
|
func (x *GetRunnerResponse) GetId() string {
|
||||||
if x != nil {
|
if x != nil {
|
||||||
return x.RunnerId
|
return x.Id
|
||||||
}
|
}
|
||||||
return 0
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
var File_api_v1_get_runner_proto protoreflect.FileDescriptor
|
var File_api_v1_get_runner_proto protoreflect.FileDescriptor
|
||||||
@@ -183,19 +183,19 @@ var file_api_v1_get_runner_proto_rawDesc = []byte{
|
|||||||
0x12, 0x32, 0x0a, 0x07, 0x6f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28,
|
0x12, 0x32, 0x0a, 0x07, 0x6f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28,
|
||||||
0x0b, 0x32, 0x18, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x31, 0x2e, 0x47, 0x65, 0x74, 0x52, 0x75,
|
0x0b, 0x32, 0x18, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x31, 0x2e, 0x47, 0x65, 0x74, 0x52, 0x75,
|
||||||
0x6e, 0x6e, 0x65, 0x72, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x52, 0x07, 0x6f, 0x70, 0x74,
|
0x6e, 0x6e, 0x65, 0x72, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x52, 0x07, 0x6f, 0x70, 0x74,
|
||||||
0x69, 0x6f, 0x6e, 0x73, 0x22, 0x30, 0x0a, 0x11, 0x47, 0x65, 0x74, 0x52, 0x75, 0x6e, 0x6e, 0x65,
|
0x69, 0x6f, 0x6e, 0x73, 0x22, 0x23, 0x0a, 0x11, 0x47, 0x65, 0x74, 0x52, 0x75, 0x6e, 0x6e, 0x65,
|
||||||
0x72, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x1b, 0x0a, 0x09, 0x72, 0x75, 0x6e,
|
0x72, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18,
|
||||||
0x6e, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x72, 0x75,
|
0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x32, 0x56, 0x0a, 0x10, 0x47, 0x65, 0x74,
|
||||||
0x6e, 0x6e, 0x65, 0x72, 0x49, 0x64, 0x32, 0x56, 0x0a, 0x10, 0x47, 0x65, 0x74, 0x52, 0x75, 0x6e,
|
0x52, 0x75, 0x6e, 0x6e, 0x65, 0x72, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x42, 0x0a,
|
||||||
0x6e, 0x65, 0x72, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x42, 0x0a, 0x09, 0x47, 0x65,
|
0x09, 0x47, 0x65, 0x74, 0x52, 0x75, 0x6e, 0x6e, 0x65, 0x72, 0x12, 0x18, 0x2e, 0x61, 0x70, 0x69,
|
||||||
0x74, 0x52, 0x75, 0x6e, 0x6e, 0x65, 0x72, 0x12, 0x18, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x31,
|
0x2e, 0x76, 0x31, 0x2e, 0x47, 0x65, 0x74, 0x52, 0x75, 0x6e, 0x6e, 0x65, 0x72, 0x52, 0x65, 0x71,
|
||||||
0x2e, 0x47, 0x65, 0x74, 0x52, 0x75, 0x6e, 0x6e, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73,
|
0x75, 0x65, 0x73, 0x74, 0x1a, 0x19, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x31, 0x2e, 0x47, 0x65,
|
||||||
0x74, 0x1a, 0x19, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x31, 0x2e, 0x47, 0x65, 0x74, 0x52, 0x75,
|
0x74, 0x52, 0x75, 0x6e, 0x6e, 0x65, 0x72, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22,
|
||||||
0x6e, 0x6e, 0x65, 0x72, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, 0x36,
|
0x00, 0x42, 0x36, 0x5a, 0x34, 0x67, 0x69, 0x74, 0x2e, 0x6f, 0x68, 0x65, 0x61, 0x2e, 0x78, 0x79,
|
||||||
0x5a, 0x34, 0x67, 0x69, 0x74, 0x2e, 0x6f, 0x68, 0x65, 0x61, 0x2e, 0x78, 0x79, 0x7a, 0x2f, 0x63,
|
0x7a, 0x2f, 0x63, 0x75, 0x72, 0x73, 0x6f, 0x72, 0x69, 0x75, 0x73, 0x2f, 0x73, 0x65, 0x72, 0x76,
|
||||||
0x75, 0x72, 0x73, 0x6f, 0x72, 0x69, 0x75, 0x73, 0x2f, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2f,
|
0x65, 0x72, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x67, 0x65, 0x6e, 0x2f, 0x61, 0x70, 0x69,
|
||||||
0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x67, 0x65, 0x6e, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x76, 0x31,
|
0x2f, 0x76, 0x31, 0x3b, 0x61, 0x70, 0x69, 0x76, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f,
|
||||||
0x3b, 0x61, 0x70, 0x69, 0x76, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
0x33,
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|||||||
Reference in New Issue
Block a user