Skip to content

Commit

Permalink
add database and basic auth flow
Browse files Browse the repository at this point in the history
This will add an actual sqlite database backend to the server,
meaning that a register request will provide a cluster name,
a secret, and then get a token back that can be used for
subsequent requests. I will next work on the job submission
and then we can hook in an actual flux instance and give it
whirl by adding a poll command to get the jobspec

Signed-off-by: vsoch <vsoch@users.noreply.github.com>
  • Loading branch information
vsoch committed Feb 12, 2024
1 parent 25a7fdd commit da49f6a
Show file tree
Hide file tree
Showing 19 changed files with 543 additions and 371 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

# Go
vendor
rainbow.db

# Test binaries
*.test
Expand Down
34 changes: 21 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,19 @@ make server
```
```console
go run cmd/server/server.go
2024/02/11 15:36:19 creating server...
2024/02/11 15:36:19 starting server: server (development) vv0.0.1-default
2024/02/11 15:36:19 server listening: [::]:50051
2024/02/11 15:39:08 received register: type_url:"type.googleapis.com/google.protobuf.StringValue" value:"\n\x07keebler"
2024/02/11 18:06:57 creating 🌈️ server...
2024/02/11 18:06:57 🧹️ cleaning up rainbow.db...
2024/02/11 18:06:57 ✨️ creating rainbow.db...
2024/02/11 18:06:57 rainbow.db file created
2024/02/11 18:06:57 create jobs table...
2024/02/11 18:06:57 jobs table created
2024/02/11 18:06:57 create cluster table...
2024/02/11 18:06:57 cluster table created
2024/02/11 18:06:57 starting scheduler server: rainbow vv0.0.1-default
2024/02/11 18:06:57 server listening: [::]:50051
2024/02/11 18:06:59 📝️ received register: keebler
SELECT count(*) from clusters WHERE name LIKE "keebler": (0)
INSERT into clusters VALUES ("keebler", "2804a013-89df-433d-a904-4666a6415ad0"): (1)
```

And then mock a registration:
Expand All @@ -55,25 +64,24 @@ make register
```
```console
go run cmd/register/register.go
2024/02/11 15:46:53 creating client (v0.0.1-default)...
2024/02/11 15:46:53 starting client (localhost:50051)...
2024/02/11 15:46:53 registering cluster: keebler
request_id:"0f7a0e7d-c2ed-4a46-9eaa-3d554349244e"
2024/02/11 15:46:53 received response: register success
2024/02/11 18:06:59 creating client (v0.0.1-default)...
2024/02/11 18:06:59 🌈️ starting client (localhost:50051)...
2024/02/11 18:06:59 registering cluster: keebler
2024/02/11 18:06:59 status: REGISTER_SUCCESS
2024/02/11 18:06:59 token: 2804a013-89df-433d-a904-4666a6415ad0
```

Nothing meaningful is happening yet - I'm just creating a skeleton (and learning about servers / services in Go with grpc more) and am going to add meat to this. My plan is below in [TODO](#TODO).
In the above, we are providing a cluster name (keebler) and it is being registered to the database, and a token and status returned.
We would then use this token for subsequent requests to interact with the cluster.

## Container Images

**Coming soon**

## TODO

- Add an actual database (sqlite) to the server, which should init, create tables for clusters, jobs (ids and cluster assignment)
- When a registration is done, it should check against this database (and add a new cluster or determine already registered)
- Add a secret to validate that, and generation of a cluster-specific token to validate further responses.
- Write the job submission endpoint, which should take a cluster name and command, and return status (success, denied, etc.)
- Make a nicer (single UI entrypoint) for client with different functions

At this point we will have a dumb little database with jobs assigned to clusters. We can then modify the client to add a polling command (intended to be run on a flux instance) that will use the cluster-specific token to say "Do you have any jobs for me?" at some interval. This can run anywhere there is a Flux instance. It can receive the job, and run it. When it receives the job, the job will be deleted from the database, because we don't care anymore.

Expand Down
20 changes: 15 additions & 5 deletions api/v1/api.proto
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ option go_package = "github.com/converged-computing/rainbow/pkg/api/v1";
service Service {

// Register cluster - request to register a new cluster
rpc Register(Request) returns (RegisterResponse);
rpc Register(RegisterRequest) returns (RegisterResponse);

// Job Submission - request for submitting a job to a named cluster
rpc SubmitJob(Request) returns (SubmitJobResponse);
Expand Down Expand Up @@ -48,14 +48,21 @@ message Request {
google.protobuf.Timestamp sent = 2;
}

message RegisterRequest {
string name = 1;
string secret = 2;
google.protobuf.Timestamp sent = 3;
}


// Testing response - the server's response to a request.
message Response {

// Enum to represent the result types of the operation.
enum ResultType {
RESULT_TYPE_UNSPECIFIED = 0; // Default value, unspecified result type.
RESULT_TYPE_SUCCESS = 1; // Indicates successful processing.
RESULT_TYPE_ERROR = 2; // Indicates an error occurred.
RESULT_TYPE_UNSPECIFIED = 0;
RESULT_TYPE_SUCCESS = 1;
RESULT_TYPE_ERROR = 2;
}

// Unique identifier correlating to the request.
Expand All @@ -74,14 +81,17 @@ message Response {
// Register Response
message RegisterResponse {

// Enum to represent the result types of the operation.
// Registration statuses
enum ResultType {
REGISTER_UNSPECIFIED = 0;
REGISTER_SUCCESS = 1;
REGISTER_ERROR = 2;
REGISTER_DENIED = 3;
REGISTER_EXISTS = 4;
}
string request_id = 1;
string token = 2;
ResultType status = 3;
}

// Submit Job Response
Expand Down
13 changes: 8 additions & 5 deletions cmd/register/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ import (
var (
host string
clusterName string

// set at build time
version = "v0.0.1-default"
secret string
version = "v0.0.1-default"
)

func main() {
flag.StringVar(&host, "host", "localhost:50051", "Scheduler server address (host:port)")
flag.StringVar(&clusterName, "cluster", "keebler", "Name of cluster to register")
flag.StringVar(&secret, "secret", "chocolate-cookies", "Registration 'secret'")
flag.Parse()

log.Printf("creating client (%s)...", version)
Expand All @@ -31,9 +31,12 @@ func main() {
log.Printf("registering cluster: %s", clusterName)

// Last argument is secret, empty for now
m, err := c.Register(context.Background(), clusterName, "")
response, err := c.Register(context.Background(), clusterName, secret)
if err != nil {
log.Fatalf("error while running client: %v", err)
}
log.Printf("received response: %s", m)

// If we get here, success! Dump all the stuff.
log.Printf("status: %s", response.Status)
log.Printf(" token: %s", response.Token)
}
27 changes: 16 additions & 11 deletions cmd/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,37 @@ import (

var (
address string
name = "server"
name = "rainbow"
sqliteFile = "rainbow.db"
environment = "development"

// set at build time
version = "v0.0.1-default"
// Remove the previous database
skipCleanup = false
secret = "chocolate-cookies"
version = "v0.0.1-default"
)

func main() {
flag.StringVar(&address, "address", ":50051", "Server address (host:port)")
flag.StringVar(&name, "name", name, "Server name (default: server)")
flag.StringVar(&environment, "environment", environment, "Server environment (default: development)")
flag.StringVar(&name, "name", name, "Server name (default: rainbow)")
flag.StringVar(&sqliteFile, "db", sqliteFile, "sqlite3 database file (default: rainbow.db)")
flag.StringVar(&secret, "secret", secret, "secret to validate registration (default: chocolate-cookies)")
flag.StringVar(&environment, "environment", environment, "environment (default: development)")
flag.BoolVar(&skipCleanup, "skip-cleanup", skipCleanup, "skip cleanup of previous sqlite database (default: false)")
flag.Parse()

// create server
log.Print("creating server...")
s, err := server.NewServer(name, version, environment)
log.Print("creating 🌈️ server...")
s, err := server.NewServer(name, version, environment, sqliteFile, !skipCleanup, secret)
if err != nil {
log.Fatalf("error while creating server: %v", err)
}
defer s.Stop()

// run server
log.Printf("starting server: %s", s.String())
log.Printf("starting scheduler server: %s", s.String())
if err := s.Start(context.Background(), address); err != nil {
log.Fatalf("error while running server: %v", err)
log.Fatalf("error while running scheduler server: %v", err)
}

log.Printf("done")
log.Printf("🌈️ done 🌈️")
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.20

require (
github.com/google/uuid v1.6.0
github.com/mattn/go-sqlite3 v1.14.22
github.com/pkg/errors v0.9.1
github.com/stretchr/testify v1.8.4
google.golang.org/grpc v1.61.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/mattn/go-sqlite3 v1.14.22 h1:2gZY6PC6kBnID23Tichd1K+Z0oS6nE/XwU+Vz/5o4kU=
github.com/mattn/go-sqlite3 v1.14.22/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand Down
Loading

0 comments on commit da49f6a

Please sign in to comment.