Skip to content

Commit

Permalink
Merge pull request #1 from converged-computing/add-python-protos
Browse files Browse the repository at this point in the history
add python protos
  • Loading branch information
vsoch authored Feb 13, 2024
2 parents b454bf3 + 6cb4c12 commit c97b3c8
Show file tree
Hide file tree
Showing 22 changed files with 762 additions and 130 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ rainbow.db
*.test
tmp

# Python
__pycache__
rainbow_scheduler.egg-info
.eggs
env

# Coverage
*.out

Expand Down
11 changes: 10 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,16 @@ protoc: $(LOCALBIN)
.PHONY: proto
proto: protoc ## Generates the API code and documentation
mkdir -p pkg/api/v1
PATH=$(LOCALBIN):${PATH} protoc --proto_path=api/v1 --go_out=pkg/api/v1 --go_opt=paths=source_relative --go-grpc_out=pkg/api/v1 --go-grpc_opt=paths=source_relative api.proto
PATH=$(LOCALBIN):${PATH} protoc --proto_path=api/v1 --go_out=pkg/api/v1 --go_opt=paths=source_relative --go-grpc_out=pkg/api/v1 --go-grpc_opt=paths=source_relative api.proto

.PHONY: python
python: python ## Generate python proto files in python
pip freeze | grep grpcio-tools
mkdir -p python/v1/rainbow/protos
cd python/v1/rainbow/protos
python -m grpc_tools.protoc -I./api/v1 --python_out=./python/v1/rainbow/protos --pyi_out=./python/v1/rainbow/protos --grpc_python_out=./python/v1/rainbow/protos ./api/v1/api.proto
# Not great, but gets the job done
sed -i 's/import api_pb2 as api__pb2/from . import api_pb2 as api__pb2/' ./python/v1/rainbow/protos/api_pb2_grpc.py

.PHONY: version
version: ## Prints the current version
Expand Down
35 changes: 22 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ This is a prototype that will use a Go [gRPC](https://grpc.io/) server/client to
This will just be a prototype that demonstrates we can do a basic interaction from multiple places, and obviously will have a lot of room for improvement.
We can run the client alongside any flux instance that has access to this service (and is given some shared secret).

## Components

- The main server (and optionally, a client) are implemented in Go, here
- Under [python](python) we also have a client that is intended to run from a flux instance, another scheduler, or anywhere really. We haven't implemented the same server in entirety because it's assumed if you plan to run a server, Go is the better choice (and from a container we will provide). That said, the skeleton is there, but unimplemented for the most part.

## Development

### proto
Expand Down Expand Up @@ -42,19 +47,15 @@ make server
```
```console
go run cmd/server/server.go
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", "712747b7-b2a9-4bea-b630-056cd64856e6"): (1)
2024/02/12 19:38:58 creating 🌈️ server...
2024/02/12 19:38:58 ✨️ creating rainbow.db...
2024/02/12 19:38:58 rainbow.db file created
2024/02/12 19:38:58 create cluster table...
2024/02/12 19:38:58 cluster table created
2024/02/12 19:38:58 create jobs table...
2024/02/12 19:38:58 jobs table created
2024/02/12 19:38:58 starting scheduler server: rainbow v0.1.0-draft
2024/02/12 19:38:58 server listening: [::]:50051
```

And then mock a registration:
Expand All @@ -71,6 +72,14 @@ go run cmd/register/register.go
2024/02/11 18:06:59 token: 712747b7-b2a9-4bea-b630-056cd64856e6
```

You'll see this from the server:

```console
2024/02/11 18:06:59 📝️ received register: keebler
SELECT count(*) from clusters WHERE name LIKE "keebler": (0)
INSERT into clusters VALUES ("keebler", "712747b7-b2a9-4bea-b630-056cd64856e6"): (1)
```

In the above, we are providing a cluster name (keebler) and it is being registered to the database, and a token and status returned. Note that if we want to submit a job to the "keebler" cluster, from anywhere, we need this token! Let's try that next.

```bash
Expand Down
5 changes: 2 additions & 3 deletions api/v1/api.proto
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ import "google/protobuf/timestamp.proto";

option go_package = "github.com/converged-computing/rainbow/pkg/api/v1";

// Service provides API endpoints for interacting with the central scheduler
// service
service Service {
// RainbowSchedulerService provides API endpoints for interacting with the central scheduler service
service RainbowScheduler {

// Register cluster - request to register a new cluster
rpc Register(RegisterRequest) returns (RegisterResponse);
Expand Down
4 changes: 2 additions & 2 deletions cmd/stream/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"time"

"github.com/converged-computing/rainbow/pkg/client"
"github.com/converged-computing/rainbow/pkg/provider"
"github.com/converged-computing/rainbow/pkg/types"
)

var (
Expand Down Expand Up @@ -36,7 +36,7 @@ func main() {
defer cancel()

log.Printf("starting stream with %v timeout...", d)
if err := c.Stream(ctx, provider.MockedMessageProvider); err != nil {
if err := c.Stream(ctx, types.MockedMessageProvider); err != nil {
log.Fatalf("error: %v", err)
}

Expand Down
74 changes: 37 additions & 37 deletions pkg/api/v1/api.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit c97b3c8

Please sign in to comment.