change worker id to serial

This commit is contained in:
simon987
2019-01-29 19:24:12 -05:00
parent 64152bfc08
commit 3a88642c5c
10 changed files with 71 additions and 67 deletions

View File

@@ -3,7 +3,6 @@ package test
import (
"encoding/json"
"fmt"
"github.com/google/uuid"
"io/ioutil"
"src/task_tracker/api"
"src/task_tracker/storage"
@@ -66,9 +65,8 @@ func TestGetTaskInvalidWid(t *testing.T) {
func TestGetTaskInvalidWorker(t *testing.T) {
id := uuid.New()
resp := getTask(&storage.Worker{
Id: id,
Id: -1,
})
if resp.Ok != false {
@@ -82,9 +80,8 @@ func TestGetTaskInvalidWorker(t *testing.T) {
func TestGetTaskFromProjectInvalidWorker(t *testing.T) {
id := uuid.New()
resp := getTaskFromProject(1, &storage.Worker{
Id: id,
Id: 99999999,
})
if resp.Ok != false {
@@ -154,7 +151,7 @@ func TestCreateGetTask(t *testing.T) {
Priority: 9999,
}, worker)
taskResp := getTaskFromProject(resp.Id, genWid())
taskResp := getTaskFromProject(resp.Id, worker)
if taskResp.Ok != true {
t.Error()
@@ -314,8 +311,8 @@ func TestTaskNoAccess(t *testing.T) {
t.Error()
}
grantAccess(&worker.Id, pid)
removeAccess(&worker.Id, pid)
grantAccess(worker.Id, pid)
removeAccess(worker.Id, pid)
tResp := getTaskFromProject(pid, worker)
@@ -356,7 +353,7 @@ func TestTaskHasAccess(t *testing.T) {
t.Error()
}
grantAccess(&worker.Id, pid)
grantAccess(worker.Id, pid)
tResp := getTaskFromProject(pid, worker)

View File

@@ -3,7 +3,6 @@ package test
import (
"encoding/json"
"fmt"
"github.com/google/uuid"
"io/ioutil"
"net/http"
"src/task_tracker/api"
@@ -25,7 +24,7 @@ func TestCreateGetWorker(t *testing.T) {
t.Error()
}
getResp, r := getWorker(resp.Worker.Id.String())
getResp, r := getWorker(resp.Worker.Id)
if r.StatusCode != 200 {
t.Error()
@@ -47,7 +46,7 @@ func TestCreateGetWorker(t *testing.T) {
func TestGetWorkerNotFound(t *testing.T) {
resp, r := getWorker("8bfc0ccd-d5ce-4dc5-a235-3a7ae760d9c6")
resp, r := getWorker(99999999)
if r.StatusCode != 404 {
t.Error()
@@ -59,7 +58,7 @@ func TestGetWorkerNotFound(t *testing.T) {
func TestGetWorkerInvalid(t *testing.T) {
resp, r := getWorker("invalid-uuid")
resp, r := getWorker(-1)
if r.StatusCode != 400 {
t.Error()
@@ -76,7 +75,7 @@ func TestGrantAccessFailedProjectConstraint(t *testing.T) {
wid := genWid()
resp := grantAccess(&wid.Id, 38274593)
resp := grantAccess(wid.Id, 38274593)
if resp.Ok != false {
t.Error()
@@ -90,7 +89,7 @@ func TestRemoveAccessFailedProjectConstraint(t *testing.T) {
worker := genWid()
resp := removeAccess(&worker.Id, 38274593)
resp := removeAccess(worker.Id, 38274593)
if resp.Ok != false {
t.Error()
@@ -112,7 +111,7 @@ func TestRemoveAccessFailedWorkerConstraint(t *testing.T) {
Public: true,
}).Id
resp := removeAccess(&uuid.Nil, pid)
resp := removeAccess(0, pid)
if resp.Ok != false {
t.Error()
@@ -134,7 +133,7 @@ func TestGrantAccessFailedWorkerConstraint(t *testing.T) {
Public: true,
}).Id
resp := removeAccess(&uuid.Nil, pid)
resp := removeAccess(0, pid)
if resp.Ok != false {
t.Error()
@@ -156,7 +155,7 @@ func TestUpdateAliasValid(t *testing.T) {
t.Error()
}
w, _ := getWorker(wid.Id.String())
w, _ := getWorker(wid.Id)
if w.Worker.Alias != "new alias" {
t.Error()
@@ -190,9 +189,9 @@ func createWorker(req api.CreateWorkerRequest) (*api.CreateWorkerResponse, *http
return resp, r
}
func getWorker(id string) (*api.GetWorkerResponse, *http.Response) {
func getWorker(id int64) (*api.GetWorkerResponse, *http.Response) {
r := Get(fmt.Sprintf("/worker/get/%s", id), nil)
r := Get(fmt.Sprintf("/worker/get/%d", id), nil)
var resp *api.GetWorkerResponse
data, _ := ioutil.ReadAll(r.Body)
@@ -208,7 +207,7 @@ func genWid() *storage.Worker {
return resp.Worker
}
func grantAccess(wid *uuid.UUID, project int64) *api.WorkerAccessResponse {
func grantAccess(wid int64, project int64) *api.WorkerAccessResponse {
r := Post("/access/grant", api.WorkerAccessRequest{
WorkerId: wid,
@@ -223,7 +222,7 @@ func grantAccess(wid *uuid.UUID, project int64) *api.WorkerAccessResponse {
return resp
}
func removeAccess(wid *uuid.UUID, project int64) *api.WorkerAccessResponse {
func removeAccess(wid int64, project int64) *api.WorkerAccessResponse {
r := Post("/access/remove", api.WorkerAccessRequest{
WorkerId: wid,

View File

@@ -12,6 +12,7 @@ import (
"net/http"
"src/task_tracker/config"
"src/task_tracker/storage"
"strconv"
)
func Post(path string, x interface{}, worker *storage.Worker) *http.Response {
@@ -27,7 +28,7 @@ func Post(path string, x interface{}, worker *storage.Worker) *http.Response {
mac.Write(body)
sig := hex.EncodeToString(mac.Sum(nil))
req.Header.Add("X-Worker-Id", worker.Id.String())
req.Header.Add("X-Worker-Id", strconv.FormatInt(worker.Id, 10))
req.Header.Add("X-Signature", sig)
}
@@ -51,7 +52,8 @@ func Get(path string, worker *storage.Worker) *http.Response {
mac.Write([]byte(path))
sig := hex.EncodeToString(mac.Sum(nil))
req.Header.Add("X-Worker-Id", worker.Id.String())
fmt.Println(strconv.FormatInt(worker.Id, 10))
req.Header.Add("X-Worker-Id", strconv.FormatInt(worker.Id, 10))
req.Header.Add("X-Signature", sig)
}

View File

@@ -25,7 +25,7 @@ CREATE TABLE worker_identity
CREATE TABLE worker
(
id TEXT PRIMARY KEY,
id SERIAL PRIMARY KEY,
alias TEXT,
created INTEGER,
identity INTEGER REFERENCES worker_identity (id),
@@ -46,7 +46,7 @@ CREATE TABLE project
CREATE TABLE worker_has_access_to_project
(
worker TEXT REFERENCES worker (id),
worker INTEGER REFERENCES worker (id),
project INTEGER REFERENCES project (id),
primary key (worker, project)
);
@@ -56,14 +56,14 @@ CREATE TABLE task
id SERIAL PRIMARY KEY,
priority INTEGER DEFAULT 0,
project INTEGER REFERENCES project (id),
assignee TEXT REFERENCES worker (id),
assignee INTEGER REFERENCES worker (id),
retries INTEGER DEFAULT 0,
max_retries INTEGER,
status Status DEFAULT 'new',
recipe TEXT,
max_assign_time INTEGER DEFAULT 0,
assign_time INTEGER DEFAULT 0,
hash64 BIGINT UNIQUE
hash64 BIGINT DEFAULT NULL UNIQUE
);
CREATE TABLE log_entry