Merge pull request #2 from NipunaMarcus/master

Update setup and recommendation service project
This commit is contained in:
Waruna Lakshitha 2019-11-14 16:40:05 +05:30 committed by GitHub
commit 6502039186
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 477 additions and 43 deletions

View file

@ -1,43 +0,0 @@
// Copyright 2015 The gRPC Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// The canonical version of this proto can be found at
// https://github.com/grpc/grpc-proto/blob/master/grpc/health/v1/health.proto
syntax = "proto3";
package grpc.health.v1;
option csharp_namespace = "Grpc.Health.V1";
option go_package = "google.golang.org/grpc/health/grpc_health_v1";
option java_multiple_files = true;
option java_outer_classname = "HealthProto";
option java_package = "io.grpc.health.v1";
message HealthCheckRequest {
string service = 1;
}
message HealthCheckResponse {
enum ServingStatus {
UNKNOWN = 0;
SERVING = 1;
NOT_SERVING = 2;
}
ServingStatus status = 1;
}
service Health {
rpc Check(HealthCheckRequest) returns (HealthCheckResponse);
}

View file

@ -0,0 +1,27 @@
syntax = "proto3";
package hipstershop;
// ------------Ad service------------------
service AdService {
rpc GetAds(AdRequest) returns (AdResponse) {}
}
message AdRequest {
// List of important key words from the current page describing the context.
repeated string context_keys = 1;
}
message AdResponse {
repeated Ad ads = 1;
}
message Ad {
// url to redirect to when an ad is clicked.
string redirect_url = 1;
// short advertisement text to display.
string text = 2;
}

View file

@ -0,0 +1,37 @@
syntax = "proto3";
package hipstershop;
// -----------------Cart service-----------------
service CartService {
rpc AddItem(AddItemRequest) returns (Empty) {}
rpc GetCart(GetCartRequest) returns (Cart) {}
rpc EmptyCart(EmptyCartRequest) returns (Empty) {}
}
message CartItem {
string product_id = 1;
int32 quantity = 2;
}
message AddItemRequest {
string user_id = 1;
CartItem item = 2;
}
message EmptyCartRequest {
string user_id = 1;
}
message GetCartRequest {
string user_id = 1;
}
message Cart {
string user_id = 1;
repeated CartItem items = 2;
}
message Empty {}

View file

@ -0,0 +1,24 @@
syntax = "proto3";
package hipstershop;
// -------------Checkout service-----------------
service CheckoutService {
rpc PlaceOrder(PlaceOrderRequest) returns (PlaceOrderResponse) {}
}
message PlaceOrderRequest {
string user_id = 1;
string user_currency = 2;
Address address = 3;
string email = 5;
CreditCardInfo credit_card = 6;
}
message PlaceOrderResponse {
OrderResult order = 1;
}

View file

@ -0,0 +1,42 @@
syntax = "proto3";
package hipstershop;
// -----------------Currency service-----------------
service CurrencyService {
rpc GetSupportedCurrencies(Empty) returns (GetSupportedCurrenciesResponse) {}
rpc Convert(CurrencyConversionRequest) returns (Money) {}
}
// Represents an amount of money with its currency type.
message Money {
// The 3-letter currency code defined in ISO 4217.
string currency_code = 1;
// The whole units of the amount.
// For example if `currencyCode` is `"USD"`, then 1 unit is one US dollar.
int64 units = 2;
// Number of nano (10^-9) units of the amount.
// The value must be between -999,999,999 and +999,999,999 inclusive.
// If `units` is positive, `nanos` must be positive or zero.
// If `units` is zero, `nanos` can be positive, zero, or negative.
// If `units` is negative, `nanos` must be negative or zero.
// For example $-1.75 is represented as `units`=-1 and `nanos`=-750,000,000.
int32 nanos = 3;
}
message GetSupportedCurrenciesResponse {
// The 3-letter currency code defined in ISO 4217.
repeated string currency_codes = 1;
}
message CurrencyConversionRequest {
Money from = 1;
// The 3-letter currency code defined in ISO 4217.
string to_code = 2;
}

View file

@ -0,0 +1,29 @@
syntax = "proto3";
package hipstershop;
// -------------Email service-----------------
service EmailService {
rpc SendOrderConfirmation(SendOrderConfirmationRequest) returns (Empty) {}
}
message OrderItem {
CartItem item = 1;
Money cost = 2;
}
message OrderResult {
string order_id = 1;
string shipping_tracking_id = 2;
Money shipping_cost = 3;
Address shipping_address = 4;
repeated OrderItem items = 5;
}
message SendOrderConfirmationRequest {
string email = 1;
OrderResult order = 2;
}

View file

@ -0,0 +1,26 @@
syntax = "proto3";
package hipstershop;
// -------------Payment service-----------------
service PaymentService {
rpc Charge(ChargeRequest) returns (ChargeResponse) {}
}
message CreditCardInfo {
string credit_card_number = 1;
int32 credit_card_cvv = 2;
int32 credit_card_expiration_year = 3;
int32 credit_card_expiration_month = 4;
}
message ChargeRequest {
Money amount = 1;
CreditCardInfo credit_card = 2;
}
message ChargeResponse {
string transaction_id = 1;
}

View file

@ -0,0 +1,61 @@
syntax = "proto3";
package hipstershop;
// ---------------Product Catalog----------------
service ProductCatalogService {
rpc ListProducts(Empty) returns (ListProductsResponse) {}
rpc GetProduct(GetProductRequest) returns (Product) {}
rpc SearchProducts(SearchProductsRequest) returns (SearchProductsResponse) {}
}
// Represents an amount of money with its currency type.
message Money {
// The 3-letter currency code defined in ISO 4217.
string currency_code = 1;
// The whole units of the amount.
// For example if `currencyCode` is `"USD"`, then 1 unit is one US dollar.
int64 units = 2;
// Number of nano (10^-9) units of the amount.
// The value must be between -999,999,999 and +999,999,999 inclusive.
// If `units` is positive, `nanos` must be positive or zero.
// If `units` is zero, `nanos` can be positive, zero, or negative.
// If `units` is negative, `nanos` must be negative or zero.
// For example $-1.75 is represented as `units`=-1 and `nanos`=-750,000,000.
int32 nanos = 3;
}
message Empty {}
message Product {
string id = 1;
string name = 2;
string description = 3;
string picture = 4;
Money price_usd = 5;
// Categories such as "vintage" or "gardening" that can be used to look up
// other related products.
repeated string categories = 6;
}
message ListProductsResponse {
repeated Product products = 1;
}
message GetProductRequest {
string id = 1;
}
message SearchProductsRequest {
string query = 1;
}
message SearchProductsResponse {
repeated Product results = 1;
}

View file

@ -0,0 +1,20 @@
syntax = "proto3";
package hipstershop;
// ---------------Recommendation service----------
service RecommendationService {
rpc ListRecommendations(ListRecommendationsRequest) returns (ListRecommendationsResponse){}
}
message ListRecommendationsRequest {
string user_id = 1;
repeated string product_ids = 2;
}
message ListRecommendationsResponse {
repeated string product_ids = 1;
}

View file

@ -0,0 +1,65 @@
syntax = "proto3";
package hipstershop;
// ---------------Shipping Service----------
service ShippingService {
rpc GetQuote(GetQuoteRequest) returns (GetQuoteResponse) {}
rpc ShipOrder(ShipOrderRequest) returns (ShipOrderResponse) {}
}
message GetQuoteRequest {
Address address = 1;
repeated CartItem items = 2;
}
message GetQuoteResponse {
Money cost_usd = 1;
}
message ShipOrderRequest {
Address address = 1;
repeated CartItem items = 2;
}
message ShipOrderResponse {
string tracking_id = 1;
}
message Address {
string street_address = 1;
string city = 2;
string state = 3;
string country = 4;
int32 zip_code = 5;
}
// Represents an amount of money with its currency type.
message Money {
// The 3-letter currency code defined in ISO 4217.
string currency_code = 1;
// The whole units of the amount.
// For example if `currencyCode` is `"USD"`, then 1 unit is one US dollar.
int64 units = 2;
// Number of nano (10^-9) units of the amount.
// The value must be between -999,999,999 and +999,999,999 inclusive.
// If `units` is positive, `nanos` must be positive or zero.
// If `units` is zero, `nanos` can be positive, zero, or negative.
// If `units` is negative, `nanos` must be negative or zero.
// For example $-1.75 is represented as `units`=-1 and `nanos`=-750,000,000.
int32 nanos = 3;
}
message CartItem {
string product_id = 1;
int32 quantity = 2;
}

44
setup.sh Normal file
View file

@ -0,0 +1,44 @@
kubectl apply -f HipsterShop/target/kubernetes/paymentservice
kubectl apply -f HipsterShop/target/kubernetes/shippingservice
kubectl apply -f HipsterShop/target/kubernetes/emailservice
kubectl apply -f k8s_manifests/frontend/frontend-kubernetes-manifests.yaml
ballerina build --sourceroot src/recommendationservice_ballerina --all --skip-tests
kubectl apply -f src/recommendationservice/target/kubernetes/recommendationservice
# Cart service
kubectl apply -f HipsterShop/target/kubernetes/adservice
# Replace above command with following command when you implemented the ad service in Ballerina.
# ballerina build --sourceroot src/adservice_ballerina --all --skip-tests
# kubectl apply -f src/adservice_ballerina/target/kubernetes/adservice
kubectl apply -f HipsterShop/target/kubernetes/currencyservice
# Replace above command with following command when you implemented the currency service in Ballerina.
# ballerina build --sourceroot src/currencyservice_ballerina --all --skip-tests
# kubectl apply -f src/currencyservice_ballerina/target/kubernetes/currencyservice
# Cart service
kubectl apply -f HipsterShop/target/kubernetes/cartservice
# Replace above command with following command when you implemented the cart service in Ballerina.
# ballerina build --sourceroot src/cartservice_ballerina --all --skip-tests
# kubectl apply -f src/cartservice_ballerina/target/kubernetes/cartservice
# Product Catalog Service
kubectl apply -f HipsterShop/target/kubernetes/productcatalogservice
# Replace above with following command when you implemented the product catalog service in Ballerina.
# ballerina build --sourceroot src/productcatalogservice_ballerina --all --skip-tests
# kubectl apply -f src/productcatalogservice_ballerina/target/kubernetes/productcatalogservice
# Checkout service
kubectl apply -f HipsterShop/target/kubernetes/checkoutservice
# Replace above with following command when you implemented the checkout service in Ballerina.
# ballerina build --sourceroot src/checkoutservice_ballerina --all --skip-tests
# kubectl apply -f src/checkoutservice_ballerina/target/kubernetes/checkoutservice
kubectl get services

0
shutdown.sh Normal file
View file

View file

@ -0,0 +1 @@
target

View file

@ -0,0 +1,5 @@
[project]
org-name= "recommendationservice"
version= "1.0"
[dependencies]

View file

@ -0,0 +1,13 @@
import ballerina/grpc;
listener grpc:Listener ep = new (9090);
service RecommendationService on ep {
resource function ListRecommendations(grpc:Caller caller, ListRecommendationsRequest value) {
// Implementation goes here.
// You should return a ListRecommendationsResponse
}
}

View file

@ -0,0 +1,83 @@
import ballerina/grpc;
public type RecommendationServiceBlockingClient client object {
*grpc:AbstractClientEndpoint;
private grpc:Client grpcClient;
public function __init(string url, grpc:ClientConfiguration? config = ()) {
// initialize client endpoint.
grpc:Client c = new(url, config);
grpc:Error? result = c.initStub(self, "blocking", ROOT_DESCRIPTOR, getDescriptorMap());
if (result is grpc:Error) {
error err = result;
panic err;
} else {
self.grpcClient = c;
}
}
public remote function ListRecommendations(ListRecommendationsRequest req, grpc:Headers? headers = ()) returns ([ListRecommendationsResponse, grpc:Headers]|grpc:Error) {
var payload = check self.grpcClient->blockingExecute("hipstershop.RecommendationService/ListRecommendations", req, headers);
grpc:Headers resHeaders = new;
anydata result = ();
[result, resHeaders] = payload;
var value = typedesc<ListRecommendationsResponse>.constructFrom(result);
if (value is ListRecommendationsResponse) {
return [value, resHeaders];
} else {
return grpc:prepareError(grpc:INTERNAL_ERROR, "Error while constructing the message", value);
}
}
};
public type RecommendationServiceClient client object {
*grpc:AbstractClientEndpoint;
private grpc:Client grpcClient;
public function __init(string url, grpc:ClientConfiguration? config = ()) {
// initialize client endpoint.
grpc:Client c = new(url, config);
grpc:Error? result = c.initStub(self, "non-blocking", ROOT_DESCRIPTOR, getDescriptorMap());
if (result is grpc:Error) {
error err = result;
panic err;
} else {
self.grpcClient = c;
}
}
public remote function ListRecommendations(ListRecommendationsRequest req, service msgListener, grpc:Headers? headers = ()) returns (grpc:Error?) {
return self.grpcClient->nonBlockingExecute("hipstershop.RecommendationService/ListRecommendations", req, msgListener, headers);
}
};
public type ListRecommendationsRequest record {|
string user_id;
string[] product_ids;
|};
public type ListRecommendationsResponse record {|
string[] product_ids;
|};
const string ROOT_DESCRIPTOR = "0A1B7265636F6D6D656E646174696F6E736572766963652E70726F746F120B6869707374657273686F7022560A1A4C6973745265636F6D6D656E646174696F6E735265717565737412170A07757365725F69641801200128095206757365724964121F0A0B70726F647563745F696473180220032809520A70726F64756374496473223E0A1B4C6973745265636F6D6D656E646174696F6E73526573706F6E7365121F0A0B70726F647563745F696473180120032809520A70726F647563744964733283010A155265636F6D6D656E646174696F6E53657276696365126A0A134C6973745265636F6D6D656E646174696F6E7312272E6869707374657273686F702E4C6973745265636F6D6D656E646174696F6E73526571756573741A282E6869707374657273686F702E4C6973745265636F6D6D656E646174696F6E73526573706F6E73652200620670726F746F33";
function getDescriptorMap() returns map<string> {
return {
"recommendationservice.proto":"0A1B7265636F6D6D656E646174696F6E736572766963652E70726F746F120B6869707374657273686F7022560A1A4C6973745265636F6D6D656E646174696F6E735265717565737412170A07757365725F69641801200128095206757365724964121F0A0B70726F647563745F696473180220032809520A70726F64756374496473223E0A1B4C6973745265636F6D6D656E646174696F6E73526573706F6E7365121F0A0B70726F647563745F696473180120032809520A70726F647563744964733283010A155265636F6D6D656E646174696F6E53657276696365126A0A134C6973745265636F6D6D656E646174696F6E7312272E6869707374657273686F702E4C6973745265636F6D6D656E646174696F6E73526571756573741A282E6869707374657273686F702E4C6973745265636F6D6D656E646174696F6E73526573706F6E73652200620670726F746F33"
};
}