Skip to content

Commit

Permalink
Remove Error handling
Browse files Browse the repository at this point in the history
Instead of failing right away the grpcclient
returns an empty message and the error.
Now the client (relay) that implements the
grpcclient is responsibe to handle the error

Signed-off-by: David Schall <[email protected]>
  • Loading branch information
dhschall committed Aug 2, 2023
1 parent d001f86 commit 762589e
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 69 deletions.
8 changes: 3 additions & 5 deletions grpcclient/aes_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"math/rand"

log "github.com/sirupsen/logrus"
pb "github.com/vhive-serverless/vSwarm-proto/proto/aes"
)

Expand Down Expand Up @@ -50,15 +49,14 @@ type AesClient struct {
}

func (c *AesClient) Init(ctx context.Context, ip, port string) {
log.Printf("Connect to: %s:%s\n", ip, port)
c.Connect(ctx, ip, port)
c.client = pb.NewAesClient(c.conn)
}

func (c *AesClient) Request(ctx context.Context, req Input) string {
func (c *AesClient) Request(ctx context.Context, req Input) (string, error) {
r, err := c.client.ShowEncryption(ctx, &pb.PlainTextMessage{PlaintextMessage: req.Value})
if err != nil {
log.Fatalf("could not greet: %v", err)
return "", err
}
return r.GetEncryptionInfo()
return r.GetEncryptionInfo(), nil
}
7 changes: 3 additions & 4 deletions grpcclient/auth_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"math/rand"

log "github.com/sirupsen/logrus"
pb "github.com/vhive-serverless/vSwarm-proto/proto/auth"
)

Expand Down Expand Up @@ -43,11 +42,11 @@ func (c *AuthClient) Init(ctx context.Context, ip, port string) {
c.client = pb.NewGreeterClient(c.conn)
}

func (c *AuthClient) Request(ctx context.Context, req Input) string {
func (c *AuthClient) Request(ctx context.Context, req Input) (string, error) {
var authMessage = req.Value
r, err := c.client.SayHello(ctx, &pb.HelloRequest{Name: authMessage})
if err != nil {
log.Fatalf("could not greet: %v", err)
return "", err
}
return r.GetMessage()
return r.GetMessage(), nil
}
7 changes: 3 additions & 4 deletions grpcclient/fibonacci_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"math/rand"

pb "github.com/vhive-serverless/vSwarm-proto/proto/fibonacci"
log "github.com/sirupsen/logrus"
)

type FibonacciGenerator struct {
Expand Down Expand Up @@ -42,11 +41,11 @@ func (c *FibonacciClient) Init(ctx context.Context, ip, port string) {
c.client = pb.NewGreeterClient(c.conn)
}

func (c *FibonacciClient) Request(ctx context.Context, req Input) string {
func (c *FibonacciClient) Request(ctx context.Context, req Input) (string, error) {
var fibonacciMessage = req.Value
r, err := c.client.SayHello(ctx, &pb.HelloRequest{Name: fibonacciMessage})
if err != nil {
log.Fatalf("could not greet: %v", err)
return "", err
}
return r.GetMessage()
return r.GetMessage(), nil
}
4 changes: 2 additions & 2 deletions grpcclient/grpcclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (s *GeneratorBase) Decrement() int {
// Every client must implement this interface
type GrpcClient interface {
Init(ctx context.Context, ip, port string)
Request(ctx context.Context, req Input) string
Request(ctx context.Context, req Input) (string, error)
Close()
GetGenerator() Generator
}
Expand All @@ -95,7 +95,7 @@ func (c *ClientBase) Connect(ctx context.Context, ip, port string) {
c.port = port
// Connect to the given address
address := fmt.Sprintf("%s:%s", c.ip, c.port)
log.Debug("Connect to ", address)
log.Println("Connect to ", address)
var conn *grpc.ClientConn
var err error
if tracing.IsTracingEnabled() {
Expand Down
7 changes: 3 additions & 4 deletions grpcclient/helloworld_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"

pb "github.com/vhive-serverless/vSwarm-proto/proto/helloworld"
log "github.com/sirupsen/logrus"
)

// type HelloWorldGenerator struct {
Expand Down Expand Up @@ -63,10 +62,10 @@ func (c *HelloWorldClient) Init(ctx context.Context, ip, port string) {
c.client = pb.NewGreeterClient(c.conn)
}

func (c *HelloWorldClient) Request(ctx context.Context, req Input) string {
func (c *HelloWorldClient) Request(ctx context.Context, req Input) (string, error) {
r, err := c.client.SayHello(ctx, &pb.HelloRequest{Name: req.Value})
if err != nil {
log.Fatalf("could not greet: %v", err)
return "", err
}
return r.GetMessage()
return r.GetMessage(), nil
}
57 changes: 28 additions & 29 deletions grpcclient/hipstershop_clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"fmt"
"strconv"

pb "github.com/vhive-serverless/vSwarm-proto/proto/hipstershop"
log "github.com/sirupsen/logrus"
pb "github.com/vhive-serverless/vSwarm-proto/proto/hipstershop"
)

var (
Expand Down Expand Up @@ -76,7 +76,7 @@ func (c *ShopAdServiceClient) Init(ctx context.Context, ip, port string) {
c.client = pb.NewAdServiceClient(c.conn)
}

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

payload := req.Value
// Create a default forward request
Expand All @@ -86,12 +86,12 @@ func (c *ShopAdServiceClient) Request(ctx context.Context, req Input) string {

fw_res, err := c.client.GetAds(ctx, &fw_req)
if err != nil {
log.Fatalf("Fail to invoke Ad service: %v", err)
return "", err
}

msg := fmt.Sprintf("%+v", fw_res)
// log.Println(msg)
return msg
return msg, nil
}

type ShopAdServiceGenerator struct {
Expand Down Expand Up @@ -119,7 +119,7 @@ func (c *ShopCartServiceClient) Init(ctx context.Context, ip, port string) {
c.client = pb.NewCartServiceClient(c.conn)
}

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

fw_method := req.Method
payload := req.Value
Expand Down Expand Up @@ -158,12 +158,12 @@ func (c *ShopCartServiceClient) Request(ctx context.Context, req Input) string {

}
if err != nil {
log.Fatalf("Fail to invoke Cart service: %v", err)
return "", err
}

msg = fmt.Sprintf("method: %s, %s", fw_method, msg)
// log.Println(msg)
return msg
return msg, nil
}

type ShopCartServiceGenerator struct {
Expand Down Expand Up @@ -191,7 +191,7 @@ func (c *ShopCheckoutServiceClient) Init(ctx context.Context, ip, port string) {
c.client = pb.NewCheckoutServiceClient(c.conn)
}

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

// Pass on to the real service function
payload := req.Value
Expand All @@ -207,12 +207,12 @@ func (c *ShopCheckoutServiceClient) Request(ctx context.Context, req Input) stri

fw_res, err := c.client.PlaceOrder(ctx, &fw_req)
if err != nil {
log.Fatalf("Fail to invoke Checkout service: %v", err)
return "", err
}

msg := fmt.Sprintf("%+v", fw_res)
// log.Println(msg)
return msg
return msg, nil
}

type ShopCheckoutServiceGenerator struct {
Expand Down Expand Up @@ -240,7 +240,7 @@ func (c *ShopCurrencyServiceClient) Init(ctx context.Context, ip, port string) {
c.client = pb.NewCurrencyServiceClient(c.conn)
}

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

fw_method, payload := req.Method, req.Value
// Pass on to the real service function
Expand Down Expand Up @@ -271,12 +271,12 @@ func (c *ShopCurrencyServiceClient) Request(ctx context.Context, req Input) stri
log.Fatalf("Failed to understand requested method: %s", fw_method)
}
if err != nil {
log.Fatalf("Fail to invoke Currency service: %v", err)
return "", err
}

msg = fmt.Sprintf("method: %s, %s", fw_method, msg)
// log.Println(msg)
return msg
return msg, nil
}

type ShopCurrencyServiceGenerator struct {
Expand Down Expand Up @@ -304,7 +304,7 @@ func (c *ShopEmailServiceClient) Init(ctx context.Context, ip, port string) {
c.client = pb.NewEmailServiceClient(c.conn)
}

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

// Pass on to the real service function
// _, payload := getMethodPayload(req)
Expand All @@ -317,12 +317,11 @@ func (c *ShopEmailServiceClient) Request(ctx context.Context, req Input) string

fw_res, err := c.client.SendOrderConfirmation(ctx, &fw_req)
if err != nil {
log.Fatalf("Fail to invoke Email service: %v", err)
return "", err
}

msg := fmt.Sprintf("%+v", fw_res)
// log.Println(msg)
return msg
return msg, nil

}

Expand Down Expand Up @@ -351,7 +350,7 @@ func (c *ShopPaymentServiceClient) Init(ctx context.Context, ip, port string) {
c.client = pb.NewPaymentServiceClient(c.conn)
}

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

payload := req.Value
// Create a default forward request
Expand All @@ -366,12 +365,12 @@ func (c *ShopPaymentServiceClient) Request(ctx context.Context, req Input) strin

fw_res, err := c.client.Charge(ctx, &fw_req)
if err != nil {
log.Fatalf("Fail to invoke Payment service: %v", err)
return "", err
}

msg := fmt.Sprintf("%+v", fw_res)
// log.Println(msg)
return msg
return msg, nil
}

type ShopPaymentServiceGenerator struct {
Expand Down Expand Up @@ -399,7 +398,7 @@ func (c *ShopProductCatalogServiceClient) Init(ctx context.Context, ip, port str
c.client = pb.NewProductCatalogServiceClient(c.conn)
}

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

fw_method := req.Method
payload := req.Value
Expand Down Expand Up @@ -435,12 +434,12 @@ func (c *ShopProductCatalogServiceClient) Request(ctx context.Context, req Input
log.Fatalf("Failed to understand requested method: %s", fw_method)
}
if err != nil {
log.Fatalf("Fail to invoke ProductCatalog service: %v", err)
return "", err
}

msg = fmt.Sprintf("method: %s, %s", fw_method, msg)
// log.Println(msg)
return msg
return msg, nil
}

type ShopProductCatalogServiceGenerator struct {
Expand Down Expand Up @@ -468,7 +467,7 @@ func (c *ShopRecommendationServiceClient) Init(ctx context.Context, ip, port str
c.client = pb.NewRecommendationServiceClient(c.conn)
}

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

payload := req.Value
// Create a default forward request
Expand All @@ -479,11 +478,11 @@ func (c *ShopRecommendationServiceClient) Request(ctx context.Context, req Input

fw_res, err := c.client.ListRecommendations(ctx, &fw_req)
if err != nil {
log.Fatalf("Fail to invoke Recommendation service: %v", err)
return "", err
}
msg := fmt.Sprintf("%+v", fw_res)
// log.Println(msg)
return msg
return msg, nil
}

type ShopRecommendationServiceGenerator struct {
Expand Down Expand Up @@ -511,7 +510,7 @@ func (c *ShopShippingServiceClient) Init(ctx context.Context, ip, port string) {
c.client = pb.NewShippingServiceClient(c.conn)
}

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

fw_method := req.Method

Expand Down Expand Up @@ -542,12 +541,12 @@ func (c *ShopShippingServiceClient) Request(ctx context.Context, req Input) stri
log.Fatalf("Failed to understand requested method: %s", fw_method)
}
if err != nil {
log.Fatalf("Fail to invoke Shipping service: %v", err)
return "", err
}

msg = fmt.Sprintf("method: %s, %s", fw_method, msg)
// log.Println(msg)
return msg
return msg, nil
}

type ShopShippingServiceGenerator struct {
Expand Down
Loading

0 comments on commit 762589e

Please sign in to comment.