Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add spright-parking protobuf #101

Merged
merged 1 commit into from
May 9, 2024
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
7 changes: 7 additions & 0 deletions grpcclient/getclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ func FindServiceName(functionName string) string {
return "fibonacci"
case "gptj-python":
return "gptj"
case "spright-parking-python":
return "spright-parking"
default:
return functionName
}
Expand Down Expand Up @@ -91,6 +93,11 @@ func FindGrpcClient(service_name string) GrpcClient {
log.Debug("Found Shipping client for online shop")
return new(ShopShippingServiceClient)

// Spright parking ---
case "spright":
log.Debug("Found Spright client for spright parking")
return new(ParkingClient)

// Default ---------
default:
log.Warnf("Did not find a matching client for %s... Will use the default Hello world client. \n", service_name)
Expand Down
55 changes: 55 additions & 0 deletions grpcclient/parking_client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package grpcclient

import (
"context"
"log"

pb "github.com/vhive-serverless/vSwarm-proto/proto/parking"
)

type ParkingGenerator struct {
GeneratorBase
}

func (g *ParkingGenerator) Next() Input {
var pkt = g.defaultInput
switch g.GeneratorBase.generator {
case Unique:
pkt.Value = "A unique message"
case Linear:
// g.count = g.count + 1
// pkt.Value = fmt.Sprintf("%d", g.count)
pkt.Value = "A linear message"
case Random:
pkt.Value = "Let's do spright parking"
}
return pkt
}

func (c *ParkingClient) GetGenerator() Generator {
return new(ParkingGenerator)
}

type ParkingClient struct {
ClientBase
client pb.ParkingClient
}

func (c *ParkingClient) Init(ctx context.Context, ip, port string) error {
log.Printf("Connect to: %s:%s\n", ip, port)
err := c.Connect(ctx, ip, port)
if err != nil {
return err
}
c.client = pb.NewParkingClient(c.conn)
return nil
}

func (c *ParkingClient) Request(ctx context.Context, req Input) (string, error) {

r, err := c.client.DoParking(ctx, &pb.ParkingRequest{Name: req.Value})
if err != nil {
return "", err
}
return r.GetResult(), nil
}
214 changes: 214 additions & 0 deletions proto/parking/parking.pb.go

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

17 changes: 17 additions & 0 deletions proto/parking/parking.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
syntax = "proto3";

option go_package = "github.com/vhive-serverless/vSwarm-proto/proto/parking";

package parking;

service Parking {
rpc DoParking(ParkingRequest) returns (ParkingReply) {}
}

message ParkingRequest {
string name = 1;
}

message ParkingReply {
string result = 1;
}
Loading
Loading