Skip to content

Commit

Permalink
fix spright-parking protos
Browse files Browse the repository at this point in the history
Signed-off-by: lrq619 <[email protected]>
  • Loading branch information
jchua99 authored and lrq619 committed May 9, 2024
1 parent 4d80b74 commit 4de4e8a
Show file tree
Hide file tree
Showing 7 changed files with 499 additions and 0 deletions.
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

0 comments on commit 4de4e8a

Please sign in to comment.