diff --git a/hotelReservation/cmd/attractions/db.go b/hotelReservation/cmd/attractions/db.go index ff5ae87a2..7d1da8cdf 100644 --- a/hotelReservation/cmd/attractions/db.go +++ b/hotelReservation/cmd/attractions/db.go @@ -1,28 +1,28 @@ package main import ( + "context" + "fmt" "github.com/rs/zerolog/log" "go.mongodb.org/mongo-driver/mongo" "go.mongodb.org/mongo-driver/mongo/options" - "fmt" - "context" ) type Restaurant struct { - RestaurantId string `bson:"restaurantId"` - RLat float64 `bson:"lat"` - RLon float64 `bson:"lon"` - RestaurantName string `bson:"restaurantName"` - Rating float32 `bson:"rating"` - Type string `bson:"type"` + RestaurantId string `bson:"restaurantId"` + RLat float64 `bson:"lat"` + RLon float64 `bson:"lon"` + RestaurantName string `bson:"restaurantName"` + Rating float32 `bson:"rating"` + Type string `bson:"type"` } type Museum struct { - MuseumId string `bson:"museumId"` - MLat float64 `bson:"lat"` - MLon float64 `bson:"lon"` - MuseumName string `bson:"museumName"` - Type string `bson:"type"` + MuseumId string `bson:"museumId"` + MLat float64 `bson:"lat"` + MLon float64 `bson:"lon"` + MuseumName string `bson:"museumName"` + Type string `bson:"type"` } type point struct { @@ -49,8 +49,8 @@ func initializeDatabase(url string) (*mongo.Client, func()) { &Restaurant{"4", 37.7862, -122.4212, "R4", 3.2, "sushi"}, &Restaurant{"5", 37.7839, -122.4052, "R5", 4.9, "fusion"}, &Restaurant{"6", 37.7831, -122.3812, "R6", 4.1, "american"}, - } - + } + newMuseums := []interface{}{ &Museum{"1", 35.7867, -122.4112, "M1", "history"}, &Museum{"2", 36.7867, -122.5112, "M2", "history"}, @@ -58,8 +58,8 @@ func initializeDatabase(url string) (*mongo.Client, func()) { &Museum{"4", 37.7867, -122.4912, "M4", "nature"}, &Museum{"5", 36.9867, -122.4212, "M5", "nature"}, &Museum{"6", 37.3867, -122.5012, "M6", "technology"}, - } - + } + uri := fmt.Sprintf("mongodb://%s", url) log.Info().Msgf("Attempting connection to %v", uri) @@ -98,4 +98,3 @@ func initializeDatabase(url string) (*mongo.Client, func()) { } } - diff --git a/hotelReservation/cmd/attractions/main.go b/hotelReservation/cmd/attractions/main.go index f57be879a..b63911c73 100644 --- a/hotelReservation/cmd/attractions/main.go +++ b/hotelReservation/cmd/attractions/main.go @@ -16,7 +16,6 @@ import ( "github.com/rs/zerolog/log" "time" - // "github.com/bradfitz/gomemcache/memcache" ) @@ -81,13 +80,12 @@ func main() { srv := attractions.Server{ Tracer: tracer, // Port: *port, - Registry: registry, - Port: serv_port, - IpAddr: serv_ip, + Registry: registry, + Port: serv_port, + IpAddr: serv_ip, MongoClient: mongo_session, } log.Info().Msg("Starting server...") log.Fatal().Msg(srv.Run().Error()) } - diff --git a/hotelReservation/cmd/review/db.go b/hotelReservation/cmd/review/db.go index 1e53d3ad9..918da433c 100644 --- a/hotelReservation/cmd/review/db.go +++ b/hotelReservation/cmd/review/db.go @@ -1,25 +1,25 @@ package main import ( + "context" + "fmt" "github.com/rs/zerolog/log" "go.mongodb.org/mongo-driver/mongo" "go.mongodb.org/mongo-driver/mongo/options" - "fmt" - "context" ) type Review struct { - ReviewId string `bson:"reviewId"` - HotelId string `bson:"hotelId"` - Name string `bson:"name"` - Rating float32 `bson:"rating"` - Description string `bson:"description"` - Image *Image `bson:"images"` + ReviewId string `bson:"reviewId"` + HotelId string `bson:"hotelId"` + Name string `bson:"name"` + Rating float32 `bson:"rating"` + Description string `bson:"description"` + Image *Image `bson:"images"` } type Image struct { - Url string `bson:"url"` - Default bool `bson:"default"` + Url string `bson:"url"` + Default bool `bson:"default"` } func initializeDatabase(url string) (*mongo.Client, func()) { @@ -79,8 +79,8 @@ func initializeDatabase(url string) (*mongo.Client, func()) { &Image{ "some url", false}}, - } - + } + uri := fmt.Sprintf("mongodb://%s", url) log.Info().Msgf("Attempting connection to %v", uri) diff --git a/hotelReservation/cmd/review/main.go b/hotelReservation/cmd/review/main.go index fd86f6f54..beb5b9ffa 100644 --- a/hotelReservation/cmd/review/main.go +++ b/hotelReservation/cmd/review/main.go @@ -16,7 +16,6 @@ import ( "github.com/rs/zerolog/log" "time" - // "github.com/bradfitz/gomemcache/memcache" ) @@ -81,11 +80,11 @@ func main() { srv := review.Server{ Tracer: tracer, // Port: *port, - Registry: registry, - Port: serv_port, - IpAddr: serv_ip, + Registry: registry, + Port: serv_port, + IpAddr: serv_ip, MongoClient: mongo_session, - MemcClient: memc_client, + MemcClient: memc_client, } log.Info().Msg("Starting server...") diff --git a/hotelReservation/services/attractions/server.go b/hotelReservation/services/attractions/server.go index 58bedcc94..72b2ef7e8 100644 --- a/hotelReservation/services/attractions/server.go +++ b/hotelReservation/services/attractions/server.go @@ -28,11 +28,13 @@ const ( // Server implements the attractions service type Server struct { + pb.UnimplementedRateServer + indexH *geoindex.ClusteringIndex indexR *geoindex.ClusteringIndex indexM *geoindex.ClusteringIndex indexC *geoindex.ClusteringIndex - uuid string + uuid string Registry *registry.Client Tracer opentracing.Tracer @@ -216,7 +218,6 @@ func (s *Server) NearbyCinema(ctx context.Context, req *pb.Request) (*pb.Result, return res, nil } - func (s *Server) getNearbyPointsHotel(ctx context.Context, lat, lon float64) []geoindex.Point { log.Trace().Msgf("In geo getNearbyPoints, lat = %f, lon = %f", lat, lon) @@ -401,12 +402,12 @@ func (p *point) Lon() float64 { return p.Plon } func (p *point) Id() string { return p.Pid } type Restaurant struct { - RestaurantId string `bson:"restaurantId"` - RLat float64 `bson:"lat"` - RLon float64 `bson:"lon"` - RestaurantName string `bson:"restaurantName"` - Rating float32 `bson:"rating"` - Type string `bson:"type"` + RestaurantId string `bson:"restaurantId"` + RLat float64 `bson:"lat"` + RLon float64 `bson:"lon"` + RestaurantName string `bson:"restaurantName"` + Rating float32 `bson:"rating"` + Type string `bson:"type"` } // Implement Restaurant interface @@ -415,11 +416,11 @@ func (r *Restaurant) Lon() float64 { return r.RLon } func (r *Restaurant) Id() string { return r.RestaurantId } type Museum struct { - MuseumId string `bson:"museumId"` - MLat float64 `bson:"lat"` - MLon float64 `bson:"lon"` - MuseumName string `bson:"museumName"` - Type string `bson:"type"` + MuseumId string `bson:"museumId"` + MLat float64 `bson:"lat"` + MLon float64 `bson:"lon"` + MuseumName string `bson:"museumName"` + Type string `bson:"type"` } // Implement Museum interface @@ -428,15 +429,14 @@ func (m *Museum) Lon() float64 { return m.MLon } func (m *Museum) Id() string { return m.MuseumId } type Cinema struct { - CinemaId string `bson:"cinemaId"` - CLat float64 `bson:"lat"` - CLon float64 `bson:"lon"` - CinemaName string `bson:"cinemaName"` - Type string `bson:"type"` + CinemaId string `bson:"cinemaId"` + CLat float64 `bson:"lat"` + CLon float64 `bson:"lon"` + CinemaName string `bson:"cinemaName"` + Type string `bson:"type"` } // Implement Cinema interface func (c *Cinema) Lat() float64 { return c.CLat } func (c *Cinema) Lon() float64 { return c.CLon } func (c *Cinema) Id() string { return c.CinemaId } - diff --git a/hotelReservation/services/frontend/server.go b/hotelReservation/services/frontend/server.go index 12886b57d..e22e9ff43 100644 --- a/hotelReservation/services/frontend/server.go +++ b/hotelReservation/services/frontend/server.go @@ -10,13 +10,13 @@ import ( "github.com/delimitrou/DeathStarBench/hotelreservation/dialer" "github.com/delimitrou/DeathStarBench/hotelreservation/registry" + attractions "github.com/delimitrou/DeathStarBench/hotelreservation/services/attractions/proto" profile "github.com/delimitrou/DeathStarBench/hotelreservation/services/profile/proto" recommendation "github.com/delimitrou/DeathStarBench/hotelreservation/services/recommendation/proto" reservation "github.com/delimitrou/DeathStarBench/hotelreservation/services/reservation/proto" + review "github.com/delimitrou/DeathStarBench/hotelreservation/services/review/proto" search "github.com/delimitrou/DeathStarBench/hotelreservation/services/search/proto" user "github.com/delimitrou/DeathStarBench/hotelreservation/services/user/proto" - review "github.com/delimitrou/DeathStarBench/hotelreservation/services/review/proto" - attractions "github.com/delimitrou/DeathStarBench/hotelreservation/services/attractions/proto" "github.com/delimitrou/DeathStarBench/hotelreservation/tls" "github.com/delimitrou/DeathStarBench/hotelreservation/tracing" _ "github.com/mbobakov/grpc-consul-resolver" @@ -342,7 +342,6 @@ func (s *Server) recommendHandler(w http.ResponseWriter, r *http.Request) { json.NewEncoder(w).Encode(geoJSONResponse(profileResp.Hotels)) } - func (s *Server) reviewHandler(w http.ResponseWriter, r *http.Request) { w.Header().Set("Access-Control-Allow-Origin", "*") ctx := r.Context() @@ -374,19 +373,19 @@ func (s *Server) reviewHandler(w http.ResponseWriter, r *http.Request) { return } - revInput := review.Request{HotelId:hotelId} + revInput := review.Request{HotelId: hotelId} revResp, err := s.reviewClient.GetReviews(ctx, &revInput) - str = "Have reviews = " + strconv.Itoa(len(revResp.Reviews)) - if len(revResp.Reviews) == 0 { - str = "Failed. No Reviews. " + str = "Have reviews = " + strconv.Itoa(len(revResp.Reviews)) + if len(revResp.Reviews) == 0 { + str = "Failed. No Reviews. " } if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } res := map[string]interface{}{ "message": str, @@ -395,7 +394,6 @@ func (s *Server) reviewHandler(w http.ResponseWriter, r *http.Request) { json.NewEncoder(w).Encode(res) } - func (s *Server) restaurantHandler(w http.ResponseWriter, r *http.Request) { w.Header().Set("Access-Control-Allow-Origin", "*") ctx := r.Context() @@ -427,19 +425,19 @@ func (s *Server) restaurantHandler(w http.ResponseWriter, r *http.Request) { return } - revInput := attractions.Request{HotelId:hotelId} + revInput := attractions.Request{HotelId: hotelId} revResp, err := s.attractionsClient.NearbyRest(ctx, &revInput) - str = "Have restaurants = " + strconv.Itoa(len(revResp.AttractionIds)) - if len(revResp.AttractionIds) == 0 { - str = "Failed. No Restaurants. " + str = "Have restaurants = " + strconv.Itoa(len(revResp.AttractionIds)) + if len(revResp.AttractionIds) == 0 { + str = "Failed. No Restaurants. " } if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } res := map[string]interface{}{ "message": str, @@ -448,7 +446,6 @@ func (s *Server) restaurantHandler(w http.ResponseWriter, r *http.Request) { json.NewEncoder(w).Encode(res) } - func (s *Server) museumHandler(w http.ResponseWriter, r *http.Request) { w.Header().Set("Access-Control-Allow-Origin", "*") ctx := r.Context() @@ -480,19 +477,19 @@ func (s *Server) museumHandler(w http.ResponseWriter, r *http.Request) { return } - revInput := attractions.Request{HotelId:hotelId} + revInput := attractions.Request{HotelId: hotelId} revResp, err := s.attractionsClient.NearbyMus(ctx, &revInput) - str = "Have museums = " + strconv.Itoa(len(revResp.AttractionIds)) - if len(revResp.AttractionIds) == 0 { - str = "Failed. No Museums. " + str = "Have museums = " + strconv.Itoa(len(revResp.AttractionIds)) + if len(revResp.AttractionIds) == 0 { + str = "Failed. No Museums. " } if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } res := map[string]interface{}{ "message": str, @@ -532,19 +529,19 @@ func (s *Server) cinemaHandler(w http.ResponseWriter, r *http.Request) { return } - revInput := attractions.Request{HotelId:hotelId} + revInput := attractions.Request{HotelId: hotelId} revResp, err := s.attractionsClient.NearbyCinema(ctx, &revInput) - str = "Have cinemas = " + strconv.Itoa(len(revResp.AttractionIds)) - if len(revResp.AttractionIds) == 0 { - str = "Failed. No Cinemas. " + str = "Have cinemas = " + strconv.Itoa(len(revResp.AttractionIds)) + if len(revResp.AttractionIds) == 0 { + str = "Failed. No Cinemas. " } if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } res := map[string]interface{}{ "message": str, @@ -708,4 +705,3 @@ func checkDataFormat(date string) bool { } return true } - diff --git a/hotelReservation/services/review/server.go b/hotelReservation/services/review/server.go index e58aa7adb..0d8a86006 100644 --- a/hotelReservation/services/review/server.go +++ b/hotelReservation/services/review/server.go @@ -16,11 +16,11 @@ import ( "github.com/rs/zerolog/log" - "github.com/google/uuid" - "github.com/grpc-ecosystem/grpc-opentracing/go/otgrpc" "github.com/delimitrou/DeathStarBench/hotelreservation/registry" pb "github.com/delimitrou/DeathStarBench/hotelreservation/services/review/proto" "github.com/delimitrou/DeathStarBench/hotelreservation/tls" + "github.com/google/uuid" + "github.com/grpc-ecosystem/grpc-opentracing/go/otgrpc" "github.com/opentracing/opentracing-go" "golang.org/x/net/context" "google.golang.org/grpc" @@ -35,13 +35,15 @@ const name = "srv-review" // Server implements the rate service type Server struct { - Tracer opentracing.Tracer - Port int - IpAddr string + pb.UnimplementedRateServer + + Tracer opentracing.Tracer + Port int + IpAddr string MongoClient *mongo.Client - Registry *registry.Client - MemcClient *memcache.Client - uuid string + Registry *registry.Client + MemcClient *memcache.Client + uuid string } // Run starts the server @@ -94,17 +96,17 @@ func (s *Server) Shutdown() { } type ReviewHelper struct { - ReviewId string `bson:"reviewId"` - HotelId string `bson:"hotelId"` - Name string `bson:"name"` - Rating float32 `bson:"rating"` - Description string `bson:"description"` - Image *pb.Image `bson:"images"` + ReviewId string `bson:"reviewId"` + HotelId string `bson:"hotelId"` + Name string `bson:"name"` + Rating float32 `bson:"rating"` + Description string `bson:"description"` + Image *pb.Image `bson:"images"` } type ImageHelper struct { - Url string `bson:"url"` - Default bool `bson:"default"` + Url string `bson:"url"` + Default bool `bson:"default"` } func (s *Server) GetReviews(ctx context.Context, req *pb.Request) (*pb.Result, error) { @@ -121,12 +123,12 @@ func (s *Server) GetReviews(ctx context.Context, req *pb.Request) (*pb.Result, e if err != nil && err != memcache.ErrCacheMiss { log.Panic().Msgf("Tried to get hotelId [%v], but got memmcached error = %s", hotelId, err) } else { - if err == memcache.ErrCacheMiss { + if err == memcache.ErrCacheMiss { mongoSpan, _ := opentracing.StartSpanFromContext(ctx, "mongo_review") mongoSpan.SetTag("span.kind", "client") - //session := s.MongoSession.Copy() - //defer session.Close() + //session := s.MongoSession.Copy() + //defer session.Close() //c := session.DB("review-db").C("reviews") c := s.MongoClient.Database("review-db").Collection("reviews") @@ -144,11 +146,11 @@ func (s *Server) GetReviews(ctx context.Context, req *pb.Request) (*pb.Result, e for _, reviewHelper := range reviewHelpers { revComm := pb.ReviewComm{ - ReviewId: reviewHelper.ReviewId, - Name: reviewHelper.Name, - Rating: reviewHelper.Rating, + ReviewId: reviewHelper.ReviewId, + Name: reviewHelper.Name, + Rating: reviewHelper.Rating, Description: reviewHelper.Description, - Images: reviewHelper.Image} + Images: reviewHelper.Image} reviews = append(reviews, &revComm) } @@ -159,13 +161,13 @@ func (s *Server) GetReviews(ctx context.Context, req *pb.Request) (*pb.Result, e memcStr := string(reviewJson) s.MemcClient.Set(&memcache.Item{Key: hotelId, Value: []byte(memcStr)}) - } else { - reviewsStr := string(item.Value) - log.Trace().Msgf("memc hit with %v", reviewsStr) - if err := json.Unmarshal([]byte(reviewsStr), &reviews); err != nil { - log.Panic().Msgf("Failed to unmarshal reviews: %s", err) - } - } + } else { + reviewsStr := string(item.Value) + log.Trace().Msgf("memc hit with %v", reviewsStr) + if err := json.Unmarshal([]byte(reviewsStr), &reviews); err != nil { + log.Panic().Msgf("Failed to unmarshal reviews: %s", err) + } + } } //reviewsEmpty := make([]*pb.ReviewComm, 0) @@ -173,4 +175,3 @@ func (s *Server) GetReviews(ctx context.Context, req *pb.Request) (*pb.Result, e res.Reviews = reviews return res, nil } -