diff --git a/kubernetes-manifests/emailservice.yaml b/kubernetes-manifests/emailservice.yaml index 83e9c77..7479c2e 100644 --- a/kubernetes-manifests/emailservice.yaml +++ b/kubernetes-manifests/emailservice.yaml @@ -30,12 +30,12 @@ spec: - containerPort: 8080 readinessProbe: periodSeconds: 5 - tcpSocket: - port: 8080 + exec: + command: ["/bin/grpc_health_probe", "-addr=:8080"] livenessProbe: periodSeconds: 5 - tcpSocket: - port: 8080 + exec: + command: ["/bin/grpc_health_probe", "-addr=:8080"] resources: requests: cpu: 100m diff --git a/kubernetes-manifests/recommendationservice.yaml b/kubernetes-manifests/recommendationservice.yaml index 18a7103..15be40f 100644 --- a/kubernetes-manifests/recommendationservice.yaml +++ b/kubernetes-manifests/recommendationservice.yaml @@ -30,12 +30,12 @@ spec: - containerPort: 8080 readinessProbe: periodSeconds: 5 - tcpSocket: - port: 8080 + exec: + command: ["/bin/grpc_health_probe", "-addr=:8080"] livenessProbe: periodSeconds: 5 - tcpSocket: - port: 8080 + exec: + command: ["/bin/grpc_health_probe", "-addr=:8080"] env: - name: PRODUCT_CATALOG_SERVICE_ADDR value: "productcatalogservice:3550" diff --git a/src/emailservice/Dockerfile b/src/emailservice/Dockerfile index e5c0bf3..8395949 100644 --- a/src/emailservice/Dockerfile +++ b/src/emailservice/Dockerfile @@ -1,6 +1,13 @@ + + # Use the grpc.io provided Python image as the base image FROM grpc/python:1.0 +# download the grpc health probe +RUN GRPC_HEALTH_PROBE_VERSION=v0.1.0-alpha.1 && \ + wget -qO/bin/grpc_health_probe https://github.com/grpc-ecosystem/grpc-health-probe/releases/download/${GRPC_HEALTH_PROBE_VERSION}/grpc_health_probe-linux-amd64 && \ + chmod +x /bin/grpc_health_probe + # show python logs as they occur ENV PYTHONUNBUFFERED=0 diff --git a/src/emailservice/email_server.py b/src/emailservice/email_server.py index 680591c..a2cb073 100644 --- a/src/emailservice/email_server.py +++ b/src/emailservice/email_server.py @@ -19,13 +19,14 @@ import argparse import os import sys import time - +import grpc from jinja2 import Environment, FileSystemLoader, select_autoescape, TemplateError from google.api_core.exceptions import GoogleAPICallError -import grpc import demo_pb2 import demo_pb2_grpc +from grpc_health.v1 import health_pb2 +from grpc_health.v1 import health_pb2_grpc # from opencensus.trace.ext.grpc import server_interceptor # from opencensus.trace.samplers import always_on @@ -56,7 +57,12 @@ env = Environment( ) template = env.get_template('confirmation.html') -class EmailService(demo_pb2_grpc.EmailServiceServicer): +class BaseEmailService(demo_pb2_grpc.EmailServiceServicer): + def Check(self, request, context): + return health_pb2.HealthCheckResponse( + status=health_pb2.HealthCheckResponse.SERVING) + +class EmailService(BaseEmailService): def __init__(self): raise Exception('cloud mail client not implemented') super().__init__() @@ -79,7 +85,6 @@ class EmailService(demo_pb2_grpc.EmailServiceServicer): "html_body": content } ) - print("Message sent: {}".format(response.rfc822_message_id)) def SendOrderConfirmation(self, request, context): @@ -104,18 +109,30 @@ class EmailService(demo_pb2_grpc.EmailServiceServicer): return demo_pb2.Empty() -class DummyEmailService(demo_pb2_grpc.EmailServiceServicer): +class DummyEmailService(BaseEmailService): def SendOrderConfirmation(self, request, context): print('A request to send order confirmation email to {} has been received.'.format(request.email)) return demo_pb2.Empty() +class HealthCheck(): + def Check(self, request, context): + return health_pb2.HealthCheckResponse( + status=health_pb2.HealthCheckResponse.SERVING) + def start(dummy_mode): server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))#, interceptors=(tracer_interceptor,)) + service = None if dummy_mode: - demo_pb2_grpc.add_EmailServiceServicer_to_server(DummyEmailService(), server) + service = DummyEmailService() else: - raise Exception('non-dummy mode not implemented') - server.add_insecure_port('[::]:8080') + raise Exception('non-dummy mode not implemented yet') + + demo_pb2_grpc.add_EmailServiceServicer_to_server(service, server) + health_pb2_grpc.add_HealthServicer_to_server(service, server) + + port = os.environ.get('PORT', "8080") + print("listening on port: "+port) + server.add_insecure_port('[::]:'+port) server.start() try: while True: @@ -125,5 +142,5 @@ def start(dummy_mode): if __name__ == '__main__': - print('Starting the email service in dummy mode.') + print('starting the email service in dummy mode.') start(dummy_mode = True) diff --git a/src/emailservice/requirements.txt b/src/emailservice/requirements.txt index 5c65c2b..de1567e 100644 --- a/src/emailservice/requirements.txt +++ b/src/emailservice/requirements.txt @@ -9,6 +9,7 @@ google-cloud-trace==0.19.0 googleapis-common-protos==1.5.3 grpc-google-iam-v1==0.11.4 grpcio==1.12.1 +grpcio-health-checking==1.14.1 grpcio-tools==1.12.1 idna==2.7 Jinja2==2.10 diff --git a/src/recommendationservice/Dockerfile b/src/recommendationservice/Dockerfile index 6616e73..1490261 100644 --- a/src/recommendationservice/Dockerfile +++ b/src/recommendationservice/Dockerfile @@ -3,6 +3,11 @@ FROM grpc/python:1.0 # show python logs as they occur ENV PYTHONUNBUFFERED=0 +# download the grpc health probe +RUN GRPC_HEALTH_PROBE_VERSION=v0.1.0-alpha.1 && \ + wget -qO/bin/grpc_health_probe https://github.com/grpc-ecosystem/grpc-health-probe/releases/download/${GRPC_HEALTH_PROBE_VERSION}/grpc_health_probe-linux-amd64 && \ + chmod +x /bin/grpc_health_probe + # get packages WORKDIR /recommendationservice COPY requirements.txt requirements.txt diff --git a/src/recommendationservice/demo_pb2.py b/src/recommendationservice/demo_pb2.py index d72a5e7..e662731 100644 --- a/src/recommendationservice/demo_pb2.py +++ b/src/recommendationservice/demo_pb2.py @@ -1,19 +1,3 @@ -#!/usr/bin/python -# -# Copyright 2018 Google LLC -# -# 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. - # Generated by the protocol buffer compiler. DO NOT EDIT! # source: demo.proto @@ -35,7 +19,7 @@ DESCRIPTOR = _descriptor.FileDescriptor( name='demo.proto', package='hipstershop', syntax='proto3', - serialized_pb=_b('\n\ndemo.proto\x12\x0bhipstershop\"0\n\x08\x43\x61rtItem\x12\x12\n\nproduct_id\x18\x01 \x01(\t\x12\x10\n\x08quantity\x18\x02 \x01(\x05\"F\n\x0e\x41\x64\x64ItemRequest\x12\x0f\n\x07user_id\x18\x01 \x01(\t\x12#\n\x04item\x18\x02 \x01(\x0b\x32\x15.hipstershop.CartItem\"#\n\x10\x45mptyCartRequest\x12\x0f\n\x07user_id\x18\x01 \x01(\t\"!\n\x0eGetCartRequest\x12\x0f\n\x07user_id\x18\x01 \x01(\t\"=\n\x04\x43\x61rt\x12\x0f\n\x07user_id\x18\x01 \x01(\t\x12$\n\x05items\x18\x02 \x03(\x0b\x32\x15.hipstershop.CartItem\"\x07\n\x05\x45mpty\"B\n\x1aListRecommendationsRequest\x12\x0f\n\x07user_id\x18\x01 \x01(\t\x12\x13\n\x0bproduct_ids\x18\x02 \x03(\t\"2\n\x1bListRecommendationsResponse\x12\x13\n\x0bproduct_ids\x18\x01 \x03(\t\"p\n\x07Product\x12\n\n\x02id\x18\x01 \x01(\t\x12\x0c\n\x04name\x18\x02 \x01(\t\x12\x13\n\x0b\x64\x65scription\x18\x03 \x01(\t\x12\x0f\n\x07picture\x18\x04 \x01(\t\x12%\n\tprice_usd\x18\x05 \x01(\x0b\x32\x12.hipstershop.Money\">\n\x14ListProductsResponse\x12&\n\x08products\x18\x01 \x03(\x0b\x32\x14.hipstershop.Product\"\x1f\n\x11GetProductRequest\x12\n\n\x02id\x18\x01 \x01(\t\"&\n\x15SearchProductsRequest\x12\r\n\x05query\x18\x01 \x01(\t\"?\n\x16SearchProductsResponse\x12%\n\x07results\x18\x01 \x03(\x0b\x32\x14.hipstershop.Product\"^\n\x0fGetQuoteRequest\x12%\n\x07\x61\x64\x64ress\x18\x01 \x01(\x0b\x32\x14.hipstershop.Address\x12$\n\x05items\x18\x02 \x03(\x0b\x32\x15.hipstershop.CartItem\"8\n\x10GetQuoteResponse\x12$\n\x08\x63ost_usd\x18\x01 \x01(\x0b\x32\x12.hipstershop.Money\"_\n\x10ShipOrderRequest\x12%\n\x07\x61\x64\x64ress\x18\x01 \x01(\x0b\x32\x14.hipstershop.Address\x12$\n\x05items\x18\x02 \x03(\x0b\x32\x15.hipstershop.CartItem\"(\n\x11ShipOrderResponse\x12\x13\n\x0btracking_id\x18\x01 \x01(\t\"n\n\x07\x41\x64\x64ress\x12\x18\n\x10street_address_1\x18\x01 \x01(\t\x12\x18\n\x10street_address_2\x18\x02 \x01(\t\x12\x0c\n\x04\x63ity\x18\x03 \x01(\t\x12\x0f\n\x07\x63ountry\x18\x04 \x01(\t\x12\x10\n\x08zip_code\x18\x05 \x01(\x05\"<\n\x05Money\x12\x15\n\rcurrency_code\x18\x01 \x01(\t\x12\r\n\x05units\x18\x02 \x01(\x03\x12\r\n\x05nanos\x18\x03 \x01(\x05\"8\n\x1eGetSupportedCurrenciesResponse\x12\x16\n\x0e\x63urrency_codes\x18\x01 \x03(\t\"N\n\x19\x43urrencyConversionRequest\x12 \n\x04\x66rom\x18\x01 \x01(\x0b\x32\x12.hipstershop.Money\x12\x0f\n\x07to_code\x18\x02 \x01(\t\"\x90\x01\n\x0e\x43reditCardInfo\x12\x1a\n\x12\x63redit_card_number\x18\x01 \x01(\t\x12\x17\n\x0f\x63redit_card_cvv\x18\x02 \x01(\x05\x12#\n\x1b\x63redit_card_expiration_year\x18\x03 \x01(\x05\x12$\n\x1c\x63redit_card_expiration_month\x18\x04 \x01(\x05\"e\n\rChargeRequest\x12\"\n\x06\x61mount\x18\x01 \x01(\x0b\x32\x12.hipstershop.Money\x12\x30\n\x0b\x63redit_card\x18\x02 \x01(\x0b\x32\x1b.hipstershop.CreditCardInfo\"(\n\x0e\x43hargeResponse\x12\x16\n\x0etransaction_id\x18\x01 \x01(\t\"R\n\tOrderItem\x12#\n\x04item\x18\x01 \x01(\x0b\x32\x15.hipstershop.CartItem\x12 \n\x04\x63ost\x18\x02 \x01(\x0b\x32\x12.hipstershop.Money\"\xbf\x01\n\x0bOrderResult\x12\x10\n\x08order_id\x18\x01 \x01(\t\x12\x1c\n\x14shipping_tracking_id\x18\x02 \x01(\t\x12)\n\rshipping_cost\x18\x03 \x01(\x0b\x32\x12.hipstershop.Money\x12.\n\x10shipping_address\x18\x04 \x01(\x0b\x32\x14.hipstershop.Address\x12%\n\x05items\x18\x05 \x03(\x0b\x32\x16.hipstershop.OrderItem\"V\n\x1cSendOrderConfirmationRequest\x12\r\n\x05\x65mail\x18\x01 \x01(\t\x12\'\n\x05order\x18\x02 \x01(\x0b\x32\x18.hipstershop.OrderResult\"c\n\x12\x43reateOrderRequest\x12\x0f\n\x07user_id\x18\x01 \x01(\t\x12\x15\n\ruser_currency\x18\x02 \x01(\t\x12%\n\x07\x61\x64\x64ress\x18\x03 \x01(\x0b\x32\x14.hipstershop.Address\"g\n\x13\x43reateOrderResponse\x12%\n\x05items\x18\x01 \x03(\x0b\x32\x16.hipstershop.OrderItem\x12)\n\rshipping_cost\x18\x02 \x01(\x0b\x32\x12.hipstershop.Money\"\xa3\x01\n\x11PlaceOrderRequest\x12\x0f\n\x07user_id\x18\x01 \x01(\t\x12\x15\n\ruser_currency\x18\x02 \x01(\t\x12%\n\x07\x61\x64\x64ress\x18\x03 \x01(\x0b\x32\x14.hipstershop.Address\x12\r\n\x05\x65mail\x18\x05 \x01(\t\x12\x30\n\x0b\x63redit_card\x18\x06 \x01(\x0b\x32\x1b.hipstershop.CreditCardInfo\"=\n\x12PlaceOrderResponse\x12\'\n\x05order\x18\x01 \x01(\x0b\x32\x18.hipstershop.OrderResult2\xca\x01\n\x0b\x43\x61rtService\x12<\n\x07\x41\x64\x64Item\x12\x1b.hipstershop.AddItemRequest\x1a\x12.hipstershop.Empty\"\x00\x12;\n\x07GetCart\x12\x1b.hipstershop.GetCartRequest\x1a\x11.hipstershop.Cart\"\x00\x12@\n\tEmptyCart\x12\x1d.hipstershop.EmptyCartRequest\x1a\x12.hipstershop.Empty\"\x00\x32\x83\x01\n\x15RecommendationService\x12j\n\x13ListRecommendations\x12\'.hipstershop.ListRecommendationsRequest\x1a(.hipstershop.ListRecommendationsResponse\"\x00\x32\x83\x02\n\x15ProductCatalogService\x12G\n\x0cListProducts\x12\x12.hipstershop.Empty\x1a!.hipstershop.ListProductsResponse\"\x00\x12\x44\n\nGetProduct\x12\x1e.hipstershop.GetProductRequest\x1a\x14.hipstershop.Product\"\x00\x12[\n\x0eSearchProducts\x12\".hipstershop.SearchProductsRequest\x1a#.hipstershop.SearchProductsResponse\"\x00\x32\xaa\x01\n\x0fShippingService\x12I\n\x08GetQuote\x12\x1c.hipstershop.GetQuoteRequest\x1a\x1d.hipstershop.GetQuoteResponse\"\x00\x12L\n\tShipOrder\x12\x1d.hipstershop.ShipOrderRequest\x1a\x1e.hipstershop.ShipOrderResponse\"\x00\x32\xb7\x01\n\x0f\x43urrencyService\x12[\n\x16GetSupportedCurrencies\x12\x12.hipstershop.Empty\x1a+.hipstershop.GetSupportedCurrenciesResponse\"\x00\x12G\n\x07\x43onvert\x12&.hipstershop.CurrencyConversionRequest\x1a\x12.hipstershop.Money\"\x00\x32U\n\x0ePaymentService\x12\x43\n\x06\x43harge\x12\x1a.hipstershop.ChargeRequest\x1a\x1b.hipstershop.ChargeResponse\"\x00\x32h\n\x0c\x45mailService\x12X\n\x15SendOrderConfirmation\x12).hipstershop.SendOrderConfirmationRequest\x1a\x12.hipstershop.Empty\"\x00\x32\xb6\x01\n\x0f\x43heckoutService\x12R\n\x0b\x43reateOrder\x12\x1f.hipstershop.CreateOrderRequest\x1a .hipstershop.CreateOrderResponse\"\x00\x12O\n\nPlaceOrder\x12\x1e.hipstershop.PlaceOrderRequest\x1a\x1f.hipstershop.PlaceOrderResponse\"\x00\x62\x06proto3') + serialized_pb=_b('\n\ndemo.proto\x12\x0bhipstershop\"0\n\x08\x43\x61rtItem\x12\x12\n\nproduct_id\x18\x01 \x01(\t\x12\x10\n\x08quantity\x18\x02 \x01(\x05\"F\n\x0e\x41\x64\x64ItemRequest\x12\x0f\n\x07user_id\x18\x01 \x01(\t\x12#\n\x04item\x18\x02 \x01(\x0b\x32\x15.hipstershop.CartItem\"#\n\x10\x45mptyCartRequest\x12\x0f\n\x07user_id\x18\x01 \x01(\t\"!\n\x0eGetCartRequest\x12\x0f\n\x07user_id\x18\x01 \x01(\t\"=\n\x04\x43\x61rt\x12\x0f\n\x07user_id\x18\x01 \x01(\t\x12$\n\x05items\x18\x02 \x03(\x0b\x32\x15.hipstershop.CartItem\"\x07\n\x05\x45mpty\"B\n\x1aListRecommendationsRequest\x12\x0f\n\x07user_id\x18\x01 \x01(\t\x12\x13\n\x0bproduct_ids\x18\x02 \x03(\t\"2\n\x1bListRecommendationsResponse\x12\x13\n\x0bproduct_ids\x18\x01 \x03(\t\"p\n\x07Product\x12\n\n\x02id\x18\x01 \x01(\t\x12\x0c\n\x04name\x18\x02 \x01(\t\x12\x13\n\x0b\x64\x65scription\x18\x03 \x01(\t\x12\x0f\n\x07picture\x18\x04 \x01(\t\x12%\n\tprice_usd\x18\x05 \x01(\x0b\x32\x12.hipstershop.Money\">\n\x14ListProductsResponse\x12&\n\x08products\x18\x01 \x03(\x0b\x32\x14.hipstershop.Product\"\x1f\n\x11GetProductRequest\x12\n\n\x02id\x18\x01 \x01(\t\"&\n\x15SearchProductsRequest\x12\r\n\x05query\x18\x01 \x01(\t\"?\n\x16SearchProductsResponse\x12%\n\x07results\x18\x01 \x03(\x0b\x32\x14.hipstershop.Product\"^\n\x0fGetQuoteRequest\x12%\n\x07\x61\x64\x64ress\x18\x01 \x01(\x0b\x32\x14.hipstershop.Address\x12$\n\x05items\x18\x02 \x03(\x0b\x32\x15.hipstershop.CartItem\"8\n\x10GetQuoteResponse\x12$\n\x08\x63ost_usd\x18\x01 \x01(\x0b\x32\x12.hipstershop.Money\"_\n\x10ShipOrderRequest\x12%\n\x07\x61\x64\x64ress\x18\x01 \x01(\x0b\x32\x14.hipstershop.Address\x12$\n\x05items\x18\x02 \x03(\x0b\x32\x15.hipstershop.CartItem\"(\n\x11ShipOrderResponse\x12\x13\n\x0btracking_id\x18\x01 \x01(\t\"a\n\x07\x41\x64\x64ress\x12\x16\n\x0estreet_address\x18\x01 \x01(\t\x12\x0c\n\x04\x63ity\x18\x02 \x01(\t\x12\r\n\x05state\x18\x03 \x01(\t\x12\x0f\n\x07\x63ountry\x18\x04 \x01(\t\x12\x10\n\x08zip_code\x18\x05 \x01(\x05\"<\n\x05Money\x12\x15\n\rcurrency_code\x18\x01 \x01(\t\x12\r\n\x05units\x18\x02 \x01(\x03\x12\r\n\x05nanos\x18\x03 \x01(\x05\"8\n\x1eGetSupportedCurrenciesResponse\x12\x16\n\x0e\x63urrency_codes\x18\x01 \x03(\t\"N\n\x19\x43urrencyConversionRequest\x12 \n\x04\x66rom\x18\x01 \x01(\x0b\x32\x12.hipstershop.Money\x12\x0f\n\x07to_code\x18\x02 \x01(\t\"\x90\x01\n\x0e\x43reditCardInfo\x12\x1a\n\x12\x63redit_card_number\x18\x01 \x01(\t\x12\x17\n\x0f\x63redit_card_cvv\x18\x02 \x01(\x05\x12#\n\x1b\x63redit_card_expiration_year\x18\x03 \x01(\x05\x12$\n\x1c\x63redit_card_expiration_month\x18\x04 \x01(\x05\"e\n\rChargeRequest\x12\"\n\x06\x61mount\x18\x01 \x01(\x0b\x32\x12.hipstershop.Money\x12\x30\n\x0b\x63redit_card\x18\x02 \x01(\x0b\x32\x1b.hipstershop.CreditCardInfo\"(\n\x0e\x43hargeResponse\x12\x16\n\x0etransaction_id\x18\x01 \x01(\t\"R\n\tOrderItem\x12#\n\x04item\x18\x01 \x01(\x0b\x32\x15.hipstershop.CartItem\x12 \n\x04\x63ost\x18\x02 \x01(\x0b\x32\x12.hipstershop.Money\"\xbf\x01\n\x0bOrderResult\x12\x10\n\x08order_id\x18\x01 \x01(\t\x12\x1c\n\x14shipping_tracking_id\x18\x02 \x01(\t\x12)\n\rshipping_cost\x18\x03 \x01(\x0b\x32\x12.hipstershop.Money\x12.\n\x10shipping_address\x18\x04 \x01(\x0b\x32\x14.hipstershop.Address\x12%\n\x05items\x18\x05 \x03(\x0b\x32\x16.hipstershop.OrderItem\"V\n\x1cSendOrderConfirmationRequest\x12\r\n\x05\x65mail\x18\x01 \x01(\t\x12\'\n\x05order\x18\x02 \x01(\x0b\x32\x18.hipstershop.OrderResult\"\xa3\x01\n\x11PlaceOrderRequest\x12\x0f\n\x07user_id\x18\x01 \x01(\t\x12\x15\n\ruser_currency\x18\x02 \x01(\t\x12%\n\x07\x61\x64\x64ress\x18\x03 \x01(\x0b\x32\x14.hipstershop.Address\x12\r\n\x05\x65mail\x18\x05 \x01(\t\x12\x30\n\x0b\x63redit_card\x18\x06 \x01(\x0b\x32\x1b.hipstershop.CreditCardInfo\"=\n\x12PlaceOrderResponse\x12\'\n\x05order\x18\x01 \x01(\x0b\x32\x18.hipstershop.OrderResult\"\"\n\nAdsRequest\x12\x14\n\x0c\x63ontext_keys\x18\x01 \x03(\t\"+\n\x0b\x41\x64sResponse\x12\x1c\n\x03\x61\x64s\x18\x01 \x03(\x0b\x32\x0f.hipstershop.Ad\"(\n\x02\x41\x64\x12\x14\n\x0credirect_url\x18\x01 \x01(\t\x12\x0c\n\x04text\x18\x02 \x01(\t2\xca\x01\n\x0b\x43\x61rtService\x12<\n\x07\x41\x64\x64Item\x12\x1b.hipstershop.AddItemRequest\x1a\x12.hipstershop.Empty\"\x00\x12;\n\x07GetCart\x12\x1b.hipstershop.GetCartRequest\x1a\x11.hipstershop.Cart\"\x00\x12@\n\tEmptyCart\x12\x1d.hipstershop.EmptyCartRequest\x1a\x12.hipstershop.Empty\"\x00\x32\x83\x01\n\x15RecommendationService\x12j\n\x13ListRecommendations\x12\'.hipstershop.ListRecommendationsRequest\x1a(.hipstershop.ListRecommendationsResponse\"\x00\x32\x83\x02\n\x15ProductCatalogService\x12G\n\x0cListProducts\x12\x12.hipstershop.Empty\x1a!.hipstershop.ListProductsResponse\"\x00\x12\x44\n\nGetProduct\x12\x1e.hipstershop.GetProductRequest\x1a\x14.hipstershop.Product\"\x00\x12[\n\x0eSearchProducts\x12\".hipstershop.SearchProductsRequest\x1a#.hipstershop.SearchProductsResponse\"\x00\x32\xaa\x01\n\x0fShippingService\x12I\n\x08GetQuote\x12\x1c.hipstershop.GetQuoteRequest\x1a\x1d.hipstershop.GetQuoteResponse\"\x00\x12L\n\tShipOrder\x12\x1d.hipstershop.ShipOrderRequest\x1a\x1e.hipstershop.ShipOrderResponse\"\x00\x32\xb7\x01\n\x0f\x43urrencyService\x12[\n\x16GetSupportedCurrencies\x12\x12.hipstershop.Empty\x1a+.hipstershop.GetSupportedCurrenciesResponse\"\x00\x12G\n\x07\x43onvert\x12&.hipstershop.CurrencyConversionRequest\x1a\x12.hipstershop.Money\"\x00\x32U\n\x0ePaymentService\x12\x43\n\x06\x43harge\x12\x1a.hipstershop.ChargeRequest\x1a\x1b.hipstershop.ChargeResponse\"\x00\x32h\n\x0c\x45mailService\x12X\n\x15SendOrderConfirmation\x12).hipstershop.SendOrderConfirmationRequest\x1a\x12.hipstershop.Empty\"\x00\x32\x62\n\x0f\x43heckoutService\x12O\n\nPlaceOrder\x12\x1e.hipstershop.PlaceOrderRequest\x1a\x1f.hipstershop.PlaceOrderResponse\"\x00\x32K\n\nAdsService\x12=\n\x06GetAds\x12\x17.hipstershop.AdsRequest\x1a\x18.hipstershop.AdsResponse\"\x00\x62\x06proto3') ) @@ -639,21 +623,21 @@ _ADDRESS = _descriptor.Descriptor( containing_type=None, fields=[ _descriptor.FieldDescriptor( - name='street_address_1', full_name='hipstershop.Address.street_address_1', index=0, + name='street_address', full_name='hipstershop.Address.street_address', index=0, number=1, type=9, cpp_type=9, label=1, has_default_value=False, default_value=_b("").decode('utf-8'), message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, options=None, file=DESCRIPTOR), _descriptor.FieldDescriptor( - name='street_address_2', full_name='hipstershop.Address.street_address_2', index=1, + name='city', full_name='hipstershop.Address.city', index=1, number=2, type=9, cpp_type=9, label=1, has_default_value=False, default_value=_b("").decode('utf-8'), message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, options=None, file=DESCRIPTOR), _descriptor.FieldDescriptor( - name='city', full_name='hipstershop.Address.city', index=2, + name='state', full_name='hipstershop.Address.state', index=2, number=3, type=9, cpp_type=9, label=1, has_default_value=False, default_value=_b("").decode('utf-8'), message_type=None, enum_type=None, containing_type=None, @@ -686,7 +670,7 @@ _ADDRESS = _descriptor.Descriptor( oneofs=[ ], serialized_start=1022, - serialized_end=1132, + serialized_end=1119, ) @@ -730,8 +714,8 @@ _MONEY = _descriptor.Descriptor( extension_ranges=[], oneofs=[ ], - serialized_start=1134, - serialized_end=1194, + serialized_start=1121, + serialized_end=1181, ) @@ -761,8 +745,8 @@ _GETSUPPORTEDCURRENCIESRESPONSE = _descriptor.Descriptor( extension_ranges=[], oneofs=[ ], - serialized_start=1196, - serialized_end=1252, + serialized_start=1183, + serialized_end=1239, ) @@ -799,8 +783,8 @@ _CURRENCYCONVERSIONREQUEST = _descriptor.Descriptor( extension_ranges=[], oneofs=[ ], - serialized_start=1254, - serialized_end=1332, + serialized_start=1241, + serialized_end=1319, ) @@ -851,8 +835,8 @@ _CREDITCARDINFO = _descriptor.Descriptor( extension_ranges=[], oneofs=[ ], - serialized_start=1335, - serialized_end=1479, + serialized_start=1322, + serialized_end=1466, ) @@ -889,8 +873,8 @@ _CHARGEREQUEST = _descriptor.Descriptor( extension_ranges=[], oneofs=[ ], - serialized_start=1481, - serialized_end=1582, + serialized_start=1468, + serialized_end=1569, ) @@ -920,8 +904,8 @@ _CHARGERESPONSE = _descriptor.Descriptor( extension_ranges=[], oneofs=[ ], - serialized_start=1584, - serialized_end=1624, + serialized_start=1571, + serialized_end=1611, ) @@ -958,8 +942,8 @@ _ORDERITEM = _descriptor.Descriptor( extension_ranges=[], oneofs=[ ], - serialized_start=1626, - serialized_end=1708, + serialized_start=1613, + serialized_end=1695, ) @@ -1017,8 +1001,8 @@ _ORDERRESULT = _descriptor.Descriptor( extension_ranges=[], oneofs=[ ], - serialized_start=1711, - serialized_end=1902, + serialized_start=1698, + serialized_end=1889, ) @@ -1055,91 +1039,8 @@ _SENDORDERCONFIRMATIONREQUEST = _descriptor.Descriptor( extension_ranges=[], oneofs=[ ], - serialized_start=1904, - serialized_end=1990, -) - - -_CREATEORDERREQUEST = _descriptor.Descriptor( - name='CreateOrderRequest', - full_name='hipstershop.CreateOrderRequest', - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name='user_id', full_name='hipstershop.CreateOrderRequest.user_id', index=0, - number=1, type=9, cpp_type=9, label=1, - has_default_value=False, default_value=_b("").decode('utf-8'), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='user_currency', full_name='hipstershop.CreateOrderRequest.user_currency', index=1, - number=2, type=9, cpp_type=9, label=1, - has_default_value=False, default_value=_b("").decode('utf-8'), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='address', full_name='hipstershop.CreateOrderRequest.address', index=2, - number=3, type=11, cpp_type=10, label=1, - has_default_value=False, default_value=None, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None, file=DESCRIPTOR), - ], - extensions=[ - ], - nested_types=[], - enum_types=[ - ], - options=None, - is_extendable=False, - syntax='proto3', - extension_ranges=[], - oneofs=[ - ], - serialized_start=1992, - serialized_end=2091, -) - - -_CREATEORDERRESPONSE = _descriptor.Descriptor( - name='CreateOrderResponse', - full_name='hipstershop.CreateOrderResponse', - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name='items', full_name='hipstershop.CreateOrderResponse.items', index=0, - number=1, type=11, cpp_type=10, label=3, - has_default_value=False, default_value=[], - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='shipping_cost', full_name='hipstershop.CreateOrderResponse.shipping_cost', index=1, - number=2, type=11, cpp_type=10, label=1, - has_default_value=False, default_value=None, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None, file=DESCRIPTOR), - ], - extensions=[ - ], - nested_types=[], - enum_types=[ - ], - options=None, - is_extendable=False, - syntax='proto3', - extension_ranges=[], - oneofs=[ - ], - serialized_start=2093, - serialized_end=2196, + serialized_start=1891, + serialized_end=1977, ) @@ -1197,8 +1098,8 @@ _PLACEORDERREQUEST = _descriptor.Descriptor( extension_ranges=[], oneofs=[ ], - serialized_start=2199, - serialized_end=2362, + serialized_start=1980, + serialized_end=2143, ) @@ -1228,8 +1129,108 @@ _PLACEORDERRESPONSE = _descriptor.Descriptor( extension_ranges=[], oneofs=[ ], - serialized_start=2364, - serialized_end=2425, + serialized_start=2145, + serialized_end=2206, +) + + +_ADSREQUEST = _descriptor.Descriptor( + name='AdsRequest', + full_name='hipstershop.AdsRequest', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='context_keys', full_name='hipstershop.AdsRequest.context_keys', index=0, + number=1, type=9, cpp_type=9, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None, file=DESCRIPTOR), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=2208, + serialized_end=2242, +) + + +_ADSRESPONSE = _descriptor.Descriptor( + name='AdsResponse', + full_name='hipstershop.AdsResponse', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='ads', full_name='hipstershop.AdsResponse.ads', index=0, + number=1, type=11, cpp_type=10, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None, file=DESCRIPTOR), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=2244, + serialized_end=2287, +) + + +_AD = _descriptor.Descriptor( + name='Ad', + full_name='hipstershop.Ad', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='redirect_url', full_name='hipstershop.Ad.redirect_url', index=0, + number=1, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=_b("").decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='text', full_name='hipstershop.Ad.text', index=1, + number=2, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=_b("").decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None, file=DESCRIPTOR), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=2289, + serialized_end=2329, ) _ADDITEMREQUEST.fields_by_name['item'].message_type = _CARTITEM @@ -1251,12 +1252,10 @@ _ORDERRESULT.fields_by_name['shipping_cost'].message_type = _MONEY _ORDERRESULT.fields_by_name['shipping_address'].message_type = _ADDRESS _ORDERRESULT.fields_by_name['items'].message_type = _ORDERITEM _SENDORDERCONFIRMATIONREQUEST.fields_by_name['order'].message_type = _ORDERRESULT -_CREATEORDERREQUEST.fields_by_name['address'].message_type = _ADDRESS -_CREATEORDERRESPONSE.fields_by_name['items'].message_type = _ORDERITEM -_CREATEORDERRESPONSE.fields_by_name['shipping_cost'].message_type = _MONEY _PLACEORDERREQUEST.fields_by_name['address'].message_type = _ADDRESS _PLACEORDERREQUEST.fields_by_name['credit_card'].message_type = _CREDITCARDINFO _PLACEORDERRESPONSE.fields_by_name['order'].message_type = _ORDERRESULT +_ADSRESPONSE.fields_by_name['ads'].message_type = _AD DESCRIPTOR.message_types_by_name['CartItem'] = _CARTITEM DESCRIPTOR.message_types_by_name['AddItemRequest'] = _ADDITEMREQUEST DESCRIPTOR.message_types_by_name['EmptyCartRequest'] = _EMPTYCARTREQUEST @@ -1284,10 +1283,11 @@ DESCRIPTOR.message_types_by_name['ChargeResponse'] = _CHARGERESPONSE DESCRIPTOR.message_types_by_name['OrderItem'] = _ORDERITEM DESCRIPTOR.message_types_by_name['OrderResult'] = _ORDERRESULT DESCRIPTOR.message_types_by_name['SendOrderConfirmationRequest'] = _SENDORDERCONFIRMATIONREQUEST -DESCRIPTOR.message_types_by_name['CreateOrderRequest'] = _CREATEORDERREQUEST -DESCRIPTOR.message_types_by_name['CreateOrderResponse'] = _CREATEORDERRESPONSE DESCRIPTOR.message_types_by_name['PlaceOrderRequest'] = _PLACEORDERREQUEST DESCRIPTOR.message_types_by_name['PlaceOrderResponse'] = _PLACEORDERRESPONSE +DESCRIPTOR.message_types_by_name['AdsRequest'] = _ADSREQUEST +DESCRIPTOR.message_types_by_name['AdsResponse'] = _ADSRESPONSE +DESCRIPTOR.message_types_by_name['Ad'] = _AD _sym_db.RegisterFileDescriptor(DESCRIPTOR) CartItem = _reflection.GeneratedProtocolMessageType('CartItem', (_message.Message,), dict( @@ -1479,20 +1479,6 @@ SendOrderConfirmationRequest = _reflection.GeneratedProtocolMessageType('SendOrd )) _sym_db.RegisterMessage(SendOrderConfirmationRequest) -CreateOrderRequest = _reflection.GeneratedProtocolMessageType('CreateOrderRequest', (_message.Message,), dict( - DESCRIPTOR = _CREATEORDERREQUEST, - __module__ = 'demo_pb2' - # @@protoc_insertion_point(class_scope:hipstershop.CreateOrderRequest) - )) -_sym_db.RegisterMessage(CreateOrderRequest) - -CreateOrderResponse = _reflection.GeneratedProtocolMessageType('CreateOrderResponse', (_message.Message,), dict( - DESCRIPTOR = _CREATEORDERRESPONSE, - __module__ = 'demo_pb2' - # @@protoc_insertion_point(class_scope:hipstershop.CreateOrderResponse) - )) -_sym_db.RegisterMessage(CreateOrderResponse) - PlaceOrderRequest = _reflection.GeneratedProtocolMessageType('PlaceOrderRequest', (_message.Message,), dict( DESCRIPTOR = _PLACEORDERREQUEST, __module__ = 'demo_pb2' @@ -1507,6 +1493,27 @@ PlaceOrderResponse = _reflection.GeneratedProtocolMessageType('PlaceOrderRespons )) _sym_db.RegisterMessage(PlaceOrderResponse) +AdsRequest = _reflection.GeneratedProtocolMessageType('AdsRequest', (_message.Message,), dict( + DESCRIPTOR = _ADSREQUEST, + __module__ = 'demo_pb2' + # @@protoc_insertion_point(class_scope:hipstershop.AdsRequest) + )) +_sym_db.RegisterMessage(AdsRequest) + +AdsResponse = _reflection.GeneratedProtocolMessageType('AdsResponse', (_message.Message,), dict( + DESCRIPTOR = _ADSRESPONSE, + __module__ = 'demo_pb2' + # @@protoc_insertion_point(class_scope:hipstershop.AdsResponse) + )) +_sym_db.RegisterMessage(AdsResponse) + +Ad = _reflection.GeneratedProtocolMessageType('Ad', (_message.Message,), dict( + DESCRIPTOR = _AD, + __module__ = 'demo_pb2' + # @@protoc_insertion_point(class_scope:hipstershop.Ad) + )) +_sym_db.RegisterMessage(Ad) + _CARTSERVICE = _descriptor.ServiceDescriptor( @@ -1515,8 +1522,8 @@ _CARTSERVICE = _descriptor.ServiceDescriptor( file=DESCRIPTOR, index=0, options=None, - serialized_start=2428, - serialized_end=2630, + serialized_start=2332, + serialized_end=2534, methods=[ _descriptor.MethodDescriptor( name='AddItem', @@ -1557,8 +1564,8 @@ _RECOMMENDATIONSERVICE = _descriptor.ServiceDescriptor( file=DESCRIPTOR, index=1, options=None, - serialized_start=2633, - serialized_end=2764, + serialized_start=2537, + serialized_end=2668, methods=[ _descriptor.MethodDescriptor( name='ListRecommendations', @@ -1581,8 +1588,8 @@ _PRODUCTCATALOGSERVICE = _descriptor.ServiceDescriptor( file=DESCRIPTOR, index=2, options=None, - serialized_start=2767, - serialized_end=3026, + serialized_start=2671, + serialized_end=2930, methods=[ _descriptor.MethodDescriptor( name='ListProducts', @@ -1623,8 +1630,8 @@ _SHIPPINGSERVICE = _descriptor.ServiceDescriptor( file=DESCRIPTOR, index=3, options=None, - serialized_start=3029, - serialized_end=3199, + serialized_start=2933, + serialized_end=3103, methods=[ _descriptor.MethodDescriptor( name='GetQuote', @@ -1656,8 +1663,8 @@ _CURRENCYSERVICE = _descriptor.ServiceDescriptor( file=DESCRIPTOR, index=4, options=None, - serialized_start=3202, - serialized_end=3385, + serialized_start=3106, + serialized_end=3289, methods=[ _descriptor.MethodDescriptor( name='GetSupportedCurrencies', @@ -1689,8 +1696,8 @@ _PAYMENTSERVICE = _descriptor.ServiceDescriptor( file=DESCRIPTOR, index=5, options=None, - serialized_start=3387, - serialized_end=3472, + serialized_start=3291, + serialized_end=3376, methods=[ _descriptor.MethodDescriptor( name='Charge', @@ -1713,8 +1720,8 @@ _EMAILSERVICE = _descriptor.ServiceDescriptor( file=DESCRIPTOR, index=6, options=None, - serialized_start=3474, - serialized_end=3578, + serialized_start=3378, + serialized_end=3482, methods=[ _descriptor.MethodDescriptor( name='SendOrderConfirmation', @@ -1737,22 +1744,13 @@ _CHECKOUTSERVICE = _descriptor.ServiceDescriptor( file=DESCRIPTOR, index=7, options=None, - serialized_start=3581, - serialized_end=3763, + serialized_start=3484, + serialized_end=3582, methods=[ - _descriptor.MethodDescriptor( - name='CreateOrder', - full_name='hipstershop.CheckoutService.CreateOrder', - index=0, - containing_service=None, - input_type=_CREATEORDERREQUEST, - output_type=_CREATEORDERRESPONSE, - options=None, - ), _descriptor.MethodDescriptor( name='PlaceOrder', full_name='hipstershop.CheckoutService.PlaceOrder', - index=1, + index=0, containing_service=None, input_type=_PLACEORDERREQUEST, output_type=_PLACEORDERRESPONSE, @@ -1763,4 +1761,28 @@ _sym_db.RegisterServiceDescriptor(_CHECKOUTSERVICE) DESCRIPTOR.services_by_name['CheckoutService'] = _CHECKOUTSERVICE + +_ADSSERVICE = _descriptor.ServiceDescriptor( + name='AdsService', + full_name='hipstershop.AdsService', + file=DESCRIPTOR, + index=8, + options=None, + serialized_start=3584, + serialized_end=3659, + methods=[ + _descriptor.MethodDescriptor( + name='GetAds', + full_name='hipstershop.AdsService.GetAds', + index=0, + containing_service=None, + input_type=_ADSREQUEST, + output_type=_ADSRESPONSE, + options=None, + ), +]) +_sym_db.RegisterServiceDescriptor(_ADSSERVICE) + +DESCRIPTOR.services_by_name['AdsService'] = _ADSSERVICE + # @@protoc_insertion_point(module_scope) diff --git a/src/recommendationservice/demo_pb2_grpc.py b/src/recommendationservice/demo_pb2_grpc.py index 7b567b1..e7842d7 100644 --- a/src/recommendationservice/demo_pb2_grpc.py +++ b/src/recommendationservice/demo_pb2_grpc.py @@ -1,19 +1,3 @@ -#!/usr/bin/python -# -# Copyright 2018 Google LLC -# -# 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. - # Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT! import grpc @@ -441,11 +425,6 @@ class CheckoutServiceStub(object): Args: channel: A grpc.Channel. """ - self.CreateOrder = channel.unary_unary( - '/hipstershop.CheckoutService/CreateOrder', - request_serializer=demo__pb2.CreateOrderRequest.SerializeToString, - response_deserializer=demo__pb2.CreateOrderResponse.FromString, - ) self.PlaceOrder = channel.unary_unary( '/hipstershop.CheckoutService/PlaceOrder', request_serializer=demo__pb2.PlaceOrderRequest.SerializeToString, @@ -458,13 +437,6 @@ class CheckoutServiceServicer(object): """ - def CreateOrder(self, request, context): - # missing associated documentation comment in .proto file - pass - context.set_code(grpc.StatusCode.UNIMPLEMENTED) - context.set_details('Method not implemented!') - raise NotImplementedError('Method not implemented!') - def PlaceOrder(self, request, context): # missing associated documentation comment in .proto file pass @@ -475,11 +447,6 @@ class CheckoutServiceServicer(object): def add_CheckoutServiceServicer_to_server(servicer, server): rpc_method_handlers = { - 'CreateOrder': grpc.unary_unary_rpc_method_handler( - servicer.CreateOrder, - request_deserializer=demo__pb2.CreateOrderRequest.FromString, - response_serializer=demo__pb2.CreateOrderResponse.SerializeToString, - ), 'PlaceOrder': grpc.unary_unary_rpc_method_handler( servicer.PlaceOrder, request_deserializer=demo__pb2.PlaceOrderRequest.FromString, @@ -489,3 +456,47 @@ def add_CheckoutServiceServicer_to_server(servicer, server): generic_handler = grpc.method_handlers_generic_handler( 'hipstershop.CheckoutService', rpc_method_handlers) server.add_generic_rpc_handlers((generic_handler,)) + + +class AdsServiceStub(object): + """------------Ads service------------------ + + """ + + def __init__(self, channel): + """Constructor. + + Args: + channel: A grpc.Channel. + """ + self.GetAds = channel.unary_unary( + '/hipstershop.AdsService/GetAds', + request_serializer=demo__pb2.AdsRequest.SerializeToString, + response_deserializer=demo__pb2.AdsResponse.FromString, + ) + + +class AdsServiceServicer(object): + """------------Ads service------------------ + + """ + + def GetAds(self, request, context): + # missing associated documentation comment in .proto file + pass + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details('Method not implemented!') + raise NotImplementedError('Method not implemented!') + + +def add_AdsServiceServicer_to_server(servicer, server): + rpc_method_handlers = { + 'GetAds': grpc.unary_unary_rpc_method_handler( + servicer.GetAds, + request_deserializer=demo__pb2.AdsRequest.FromString, + response_serializer=demo__pb2.AdsResponse.SerializeToString, + ), + } + generic_handler = grpc.method_handlers_generic_handler( + 'hipstershop.AdsService', rpc_method_handlers) + server.add_generic_rpc_handlers((generic_handler,)) diff --git a/src/recommendationservice/recommendation_server.py b/src/recommendationservice/recommendation_server.py index b1ec87e..b897f73 100644 --- a/src/recommendationservice/recommendation_server.py +++ b/src/recommendationservice/recommendation_server.py @@ -15,16 +15,19 @@ # limitations under the License. import grpc -import demo_pb2 -import demo_pb2_grpc from concurrent import futures import time import traceback import random import os - import googleclouddebugger +import demo_pb2 +import demo_pb2_grpc +from grpc_health.v1 import health_pb2 +from grpc_health.v1 import health_pb2_grpc + + # TODO(morganmclean,ahmetb) tracing currently disabled due to memory leak (see TODO below) # from opencensus.trace.ext.grpc import server_interceptor # from opencensus.trace.samplers import always_on @@ -35,7 +38,7 @@ class RecommendationService(demo_pb2_grpc.RecommendationServiceServicer): def ListRecommendations(self, request, context): max_responses = 5 # fetch list of products from product catalog stub - cat_response = stub.ListProducts(demo_pb2.Empty()) + cat_response = product_catalog_stub.ListProducts(demo_pb2.Empty()) product_ids = [x.id for x in cat_response.products] filtered_products = list(set(product_ids)-set(request.product_ids)) num_products = len(filtered_products) @@ -50,6 +53,11 @@ class RecommendationService(demo_pb2_grpc.RecommendationServiceServicer): response.product_ids.extend(prod_list) return response + def Check(self, request, context): + return health_pb2.HealthCheckResponse( + status=health_pb2.HealthCheckResponse.SERVING) + + if __name__ == "__main__": print("initializing recommendationservice") @@ -78,16 +86,16 @@ if __name__ == "__main__": if catalog_addr == "": raise Exception('PRODUCT_CATALOG_SERVICE_ADDR environment variable not set') print("product catalog address: " + catalog_addr) - - # stub for product catalog service channel = grpc.insecure_channel(catalog_addr) - stub = demo_pb2_grpc.ProductCatalogServiceStub(channel) - + product_catalog_stub = demo_pb2_grpc.ProductCatalogServiceStub(channel) + # create gRPC server server = grpc.server(futures.ThreadPoolExecutor(max_workers=10)) # ,interceptors=(tracer_interceptor,)) # add class to gRPC server - demo_pb2_grpc.add_RecommendationServiceServicer_to_server(RecommendationService(), server) + service = RecommendationService() + demo_pb2_grpc.add_RecommendationServiceServicer_to_server(service, server) + health_pb2_grpc.add_HealthServicer_to_server(service, server) # start server print("listening on port: " + port) diff --git a/src/recommendationservice/requirements.txt b/src/recommendationservice/requirements.txt index 0d062af..bbf9bcc 100644 --- a/src/recommendationservice/requirements.txt +++ b/src/recommendationservice/requirements.txt @@ -1,29 +1,30 @@ -cachetools==2.1.0 -certifi==2018.4.16 -chardet==3.0.4 -enum34==1.1.6 -futures==3.2.0 -google-api-core==1.2.1 -google-api-python-client==1.7.4 -google-auth==1.5.0 -google-auth-httplib2==0.0.3 -google-cloud-core==0.28.1 -google-cloud-trace==0.19.0 -google-python-cloud-debugger==2.8 -googleapis-common-protos==1.5.3 -grpcio==1.13.0 -grpcio-tools==1.0.0 -httplib2==0.11.3 -idna==2.7 -opencensus==0.1.5 -protobuf==3.5.2.post1 -pyasn1==0.4.3 -pyasn1-modules==0.2.2 -pytz==2018.5 -PyYAML==3.13 -requests==2.19.1 -rsa==3.4.2 -six==1.11.0 -uritemplate==3.0.0 -urllib3==1.23 -virtualenv==16.0.0 +cachetools==2.1.0 +certifi==2018.4.16 +chardet==3.0.4 +enum34==1.1.6 +futures==3.2.0 +google-api-core==1.2.1 +google-api-python-client==1.7.4 +google-auth==1.5.0 +google-auth-httplib2==0.0.3 +google-cloud-core==0.28.1 +google-cloud-trace==0.19.0 +google-python-cloud-debugger==2.8 +googleapis-common-protos==1.5.3 +grpcio==1.13.0 +grpcio-health-checking==1.14.1 +grpcio-tools==1.0.0 +httplib2==0.11.3 +idna==2.7 +opencensus==0.1.5 +protobuf==3.5.2.post1 +pyasn1==0.4.3 +pyasn1-modules==0.2.2 +pytz==2018.5 +PyYAML==3.13 +requests==2.19.1 +rsa==3.4.2 +six==1.11.0 +uritemplate==3.0.0 +urllib3==1.23 +virtualenv==16.0.0