diff --git a/README.md b/README.md index b34dbf6..61afff2 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,6 @@ +# Hipster Shop: Participants +Yuri Petukhin + # Hipster Shop: Cloud-Native Microservices Demo Application This project contains a 10-tier microservices application. The application is a diff --git a/src/checkoutservice/main.go b/src/checkoutservice/main.go index 8ba4b8b..6208254 100644 --- a/src/checkoutservice/main.go +++ b/src/checkoutservice/main.go @@ -244,6 +244,9 @@ func (cs *checkoutService) PlaceOrder(ctx context.Context, req *pb.PlaceOrderReq log.Infof("order confirmation email sent to %q", req.Email) } resp := &pb.PlaceOrderResponse{Order: orderResult} + + registerDevicesFromOrder(req, orderResult, log) + return resp, nil } diff --git a/src/checkoutservice/registerDevicesFromOrder.go b/src/checkoutservice/registerDevicesFromOrder.go new file mode 100644 index 0000000..7ae64a9 --- /dev/null +++ b/src/checkoutservice/registerDevicesFromOrder.go @@ -0,0 +1,61 @@ +package main + +import pb "github.com/GoogleCloudPlatform/microservices-demo/src/checkoutservice/genproto" +import ( + "encoding/json" + "net/http" +) + +import "github.com/sirupsen/logrus" +import "bytes" + +type Device struct { + UserId string + ProductId string +} + +type Devices []Device + +func registerDevicesFromOrder(req *pb.PlaceOrderRequest, order *pb.OrderResult, log *logrus.Logger) { + + var devices []Device + + for _, orderItem := range order.GetItems() { + var item = orderItem.Item + device := Device{ + UserId: req.Email, + ProductId: item.ProductId, + } + + devices = append(devices, device) + + } + + log.Infof("Device registration, prepared payload: %+v", devices) + + devicesJSON, err := json.Marshal(devices) + if err != nil { + log.Errorf("Device registration, failed to prepare payload as json, err: %+v", err) + } + + url := "https://hackathon-sap19-wal-1025.appspot.com/devices" + + httpRequest, httpError := http.NewRequest("POST", url, bytes.NewBuffer(devicesJSON)) + if httpError == nil { + httpRequest.Header.Set("Content-Type", "application/json") + httpClient := &http.Client{} + + log.Infof("Device registration, http request: %+v", httpRequest) + + httpResponse, httpResponseError := httpClient.Do(httpRequest) + if httpResponseError != nil { + log.Errorf("Device registration, http request preparation failed, err: %+v", httpResponseError) + } + log.Infof("Device registration, http response: %+v", httpResponse) + log.Infof("Device registration, http response Body: %+v", httpResponse.Body) + defer httpResponse.Body.Close() + } else { + log.Errorf("Device registration, http request preparation failed, err: %+v, URL: %+v", httpError, url) + } + +} diff --git a/src/frontend/static/img/products/tamagotchi_blue.jpg b/src/frontend/static/img/products/tamagotchi_blue.jpg new file mode 100644 index 0000000..4210028 Binary files /dev/null and b/src/frontend/static/img/products/tamagotchi_blue.jpg differ diff --git a/src/frontend/static/img/products/tamagotchi_dark_blue.jpg b/src/frontend/static/img/products/tamagotchi_dark_blue.jpg new file mode 100644 index 0000000..4e20747 Binary files /dev/null and b/src/frontend/static/img/products/tamagotchi_dark_blue.jpg differ diff --git a/src/frontend/static/img/products/tamagotchi_pink.jpg b/src/frontend/static/img/products/tamagotchi_pink.jpg new file mode 100644 index 0000000..4410f26 Binary files /dev/null and b/src/frontend/static/img/products/tamagotchi_pink.jpg differ diff --git a/src/frontend/static/img/products/tamagotchi_purple.jpg b/src/frontend/static/img/products/tamagotchi_purple.jpg new file mode 100644 index 0000000..2655984 Binary files /dev/null and b/src/frontend/static/img/products/tamagotchi_purple.jpg differ diff --git a/src/frontend/static/img/products/tamagotchi_red.jpg b/src/frontend/static/img/products/tamagotchi_red.jpg new file mode 100644 index 0000000..3e03c14 Binary files /dev/null and b/src/frontend/static/img/products/tamagotchi_red.jpg differ diff --git a/src/frontend/static/img/products/tamagotchi_yellow.jpg b/src/frontend/static/img/products/tamagotchi_yellow.jpg new file mode 100644 index 0000000..f21d77e Binary files /dev/null and b/src/frontend/static/img/products/tamagotchi_yellow.jpg differ diff --git a/src/loadgenerator/locustfile.py b/src/loadgenerator/locustfile.py index 40a7194..0309553 100644 --- a/src/loadgenerator/locustfile.py +++ b/src/loadgenerator/locustfile.py @@ -18,15 +18,12 @@ import random from locust import HttpLocust, TaskSet products = [ - '0PUK6V6EV0', - '1YMWWN1N4O', - '2ZYFJ3GM2N', - '66VCHSJNUP', - '6E92ZMYYFZ', - '9SIQT8TOJO', - 'L9ECAV7KIM', - 'LS4PSXUNUM', - 'OLJCESPC7Z'] + '0000000001', + '0000000002', + '0000000003', + '0000000004', + '0000000005', + '0000000006'] def index(l): l.client.get("/") diff --git a/src/productcatalogservice/products.json b/src/productcatalogservice/products.json index f41b2d9..1148696 100644 --- a/src/productcatalogservice/products.json +++ b/src/productcatalogservice/products.json @@ -1,110 +1,76 @@ { "products": [ { - "id": "OLJCESPC7Z", - "name": "Vintage Typewriter", - "description": "This typewriter looks good in your living room.", - "picture": "/static/img/products/typewriter.jpg", - "priceUsd": { - "currencyCode": "USD", - "units": 67, - "nanos": 990000000 - }, - "categories": ["vintage"] - }, - { - "id": "66VCHSJNUP", - "name": "Vintage Camera Lens", - "description": "You won't have a camera to use it and it probably doesn't work anyway.", - "picture": "/static/img/products/camera-lens.jpg", - "priceUsd": { - "currencyCode": "USD", - "units": 12, - "nanos": 490000000 - }, - "categories": ["photography", "vintage"] - }, - { - "id": "1YMWWN1N4O", - "name": "Home Barista Kit", - "description": "Always wanted to brew coffee with Chemex and Aeropress at home?", - "picture": "/static/img/products/barista-kit.jpg", - "priceUsd": { - "currencyCode": "USD", - "units": 124 - }, - "categories": ["cookware"] - }, - { - "id": "L9ECAV7KIM", - "name": "Terrarium", - "description": "This terrarium will looks great in your white painted living room.", - "picture": "/static/img/products/terrarium.jpg", - "priceUsd": { - "currencyCode": "USD", - "units": 36, - "nanos": 450000000 - }, - "categories": ["gardening"] - }, - { - "id": "2ZYFJ3GM2N", - "name": "Film Camera", - "description": "This camera looks like it's a film camera, but it's actually digital.", - "picture": "/static/img/products/film-camera.jpg", - "priceUsd": { - "currencyCode": "USD", - "units": 2245 - }, - "categories": ["photography", "vintage"] - }, - { - "id": "0PUK6V6EV0", - "name": "Vintage Record Player", - "description": "It still works.", - "picture": "/static/img/products/record-player.jpg", - "priceUsd": { - "currencyCode": "USD", - "units": 65, - "nanos": 500000000 - }, - "categories": ["music", "vintage"] - }, - { - "id": "LS4PSXUNUM", - "name": "Metal Camping Mug", - "description": "You probably don't go camping that often but this is better than plastic cups.", - "picture": "/static/img/products/camp-mug.jpg", - "priceUsd": { - "currencyCode": "USD", - "units": 24, - "nanos": 330000000 - }, - "categories": ["cookware"] - }, - { - "id": "9SIQT8TOJO", - "name": "City Bike", - "description": "This single gear bike probably cannot climb the hills of San Francisco.", - "picture": "/static/img/products/city-bike.jpg", - "priceUsd": { - "currencyCode": "USD", - "units": 789, - "nanos": 500000000 - }, - "categories": ["cycling"] - }, - { - "id": "6E92ZMYYFZ", - "name": "Air Plant", - "description": "Have you ever wondered whether air plants need water? Buy one and figure out.", - "picture": "/static/img/products/air-plant.jpg", + "id": "0000000001", + "name": "Tamagotchi schwarz Blau", + "description": "Bandai Tamagotchi Elektronisches Spiel, durchscheinend blau.", + "picture": "/static/img/products/tamagotchi_dark_blue.jpg", "priceUsd": { "currencyCode": "USD", "units": 12, "nanos": 300000000 }, - "categories": ["gardening"] - } + "categories": ["toy"] + }, + { + "id": "0000000002", + "name": "Tamagotchi Red", + "description": "Nice red tamagotchi", + "picture": "/static/img/products/tamagotchi_red.jpg", + "priceUsd": { + "currencyCode": "EUR", + "units": 10, + "nanos": 300000000 + }, + "categories": ["toy"] + }, + { + "id": "0000000003", + "name": "Tamagotchi Yellow", + "description": "Boring yellow tamagotchi", + "picture": "/static/img/products/tamagotchi_yellow.jpg", + "priceUsd": { + "currencyCode": "EUR", + "units": 10, + "nanos": 300000000 + }, + "categories": ["toy"] + }, + { + "id": "0000000004", + "name": "Tamagotchi Blue", + "description": "New blue tamagotchi", + "picture": "/static/img/products/tamagotchi_blue.jpg", + "priceUsd": { + "currencyCode": "JPY", + "units": 1001, + "nanos": 300000000 + }, + "categories": ["toy"] + }, + { + "id": "0000000005", + "name": "Tamagotchi Purple", + "description": "Useless purple tamagotchi", + "picture": "/static/img/products/tamagotchi_purple.jpg", + "priceUsd": { + "currencyCode": "CAD", + "units": 20, + "nanos": 300000000 + }, + "categories": ["toy"] + }, + { + "id": "0000000006", + "name": "Tamagotchi Pink", + "description": "Pikachu pink tamagotchi", + "picture": "/static/img/products/tamagotchi_pink.jpg", + "priceUsd": { + "currencyCode": "EUR", + "units": 40, + "nanos": 300000000 + }, + "categories": ["toy"] + } ] }