Skip to content

ibm-garage-ref-storefront/catalog-ms-openliberty

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

catalog-ms-openliberty: Openliberty Microservice with Elasticsearch

Table of Contents

Pre-requisites:

git clone https://github.com/ibm-garage-ref-storefront/inventory-ms-openliberty.git
cd inventory-ms-openliberty
  • Run the MySQL Docker Container

Run the below command to get MySQL running via a Docker container.

# Start a MySQL Container with a database user, a password, and create a new database
docker run --name inventorymysql \
    -e MYSQL_ROOT_PASSWORD=admin123 \
    -e MYSQL_USER=dbuser \
    -e MYSQL_PASSWORD=password \
    -e MYSQL_DATABASE=inventorydb \
    -p 3306:3306 \
    -d mysql:5.7.14

If it is successfully deployed, you will see something like below.

$ docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
c082aa55767c        mysql:5.7.14        "docker-entrypoint.s…"   9 seconds ago       Up 9 seconds        0.0.0.0:3306->3306/tcp   inventorymysql
  • Populate the MySQL Database

Now let us populate the MySQL with data.

  • Firstly ssh into the MySQL container.
docker exec -it inventorymysql bash
  • Now, run the below command for table creation.
mysql -udbuser -ppassword
  • This will take you to something like below.
root@d88a6e5973de:/# mysql -udbuser -ppassword
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.14 MySQL Community Server (GPL)

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>
  • Go to scripts > mysql_data.sql. Copy the contents from mysql_data.sql and paste the contents in the console.

  • You can exit from the console using exit.

mysql> exit
Bye
  • To come out of the container, enter exit.
root@d88a6e5973de:/# exit
  • Run the Inventory application as follows.
# Build inventory docker image
appsody build

# Run the inventory
docker run --name inventory \
    -e jdbcURL=jdbc:mysql://<docker_host>:3306/inventorydb?useSSL=true \
    -e dbuser=dbuser \
    -e dbpassword=password \
    -p 9081:9080 \
    -d dev.local/inventory-ms-openliberty

For instance <docker_host>, if it is docker-for-mac it will be docker.for.mac.localhost.

  • You can also verify it as follows.
$ docker ps
CONTAINER ID        IMAGE                                COMMAND                  CREATED             STATUS              PORTS                              NAMES
53cee568be06        dev.local/inventory-ms-openliberty   "/opt/ol/helpers/run…"   10 seconds ago      Up 9 seconds        9443/tcp, 0.0.0.0:9081->9080/tcp   inventory
c082aa55767c        mysql:5.7.14                         "docker-entrypoint.s…"   4 minutes ago       Up 4 minutes        0.0.0.0:3306->3306/tcp             inventorymysql

Run Locally

To run this microservice locally, run the following commands

  1. Clone repository:
git clone https://github.com/ibm-garage-ref-storefront/catalog-ms-openliberty.git
cd catalog-ms-openliberty
  1. Set up Elasticsearch container by running the following command:
docker run --name catalogelasticsearch \
  -e "discovery.type=single-node" \
  -p 9200:9200 \
  -p 9300:9300 \
  -d docker.elastic.co/elasticsearch/elasticsearch:6.3.2

You should have the following output:

$ docker ps
CONTAINER ID        IMAGE                                                 COMMAND                  CREATED              STATUS              PORTS                                            NAMES
2cd0209be1f4        docker.elastic.co/elasticsearch/elasticsearch:6.3.2   "/usr/local/bin/dock…"   7 seconds ago        Up 6 seconds        0.0.0.0:9200->9200/tcp, 0.0.0.0:9300->9300/tcp   catalogelasticsearch
  1. Set up Jaegar for opentracing. This is optional. If you want to enable distributed tracing your application, run this step.
 docker run -d --name jaeger   -e COLLECTOR_ZIPKIN_HTTP_PORT=9411   -p 5775:5775/udp   -p 6831:6831/udp   -p 6832:6832/udp   -p 5778:5778   -p 16686:16686   -p 14268:14268   -p 9411:9411   jaegertracing/all-in-one:1.11

You should have the following output:

$ docker ps
CONTAINER ID        IMAGE                                                 COMMAND                  CREATED             STATUS              PORTS                                                                                                                                                                     NAMES
d0600b983133        jaegertracing/all-in-one:1.11                         "/go/bin/all-in-one-…"   2 hours ago         Up 2 hours          0.0.0.0:5775->5775/udp, 0.0.0.0:5778->5778/tcp, 0.0.0.0:9411->9411/tcp, 0.0.0.0:14268->14268/tcp, 0.0.0.0:6831-6832->6831-6832/udp, 0.0.0.0:16686->16686/tcp, 14250/tcp   jaeger
  1. Run the application
appsody run --docker-options "-e elasticsearch_url=http://<docker_host>:9200 -e elasticsearch_index=micro -e elasticsearch_doc_type=items -e dev.appsody.application.client.InventoryServiceClient/mp-rest/url=http://<docker_host>:9081/micro/inventory -e inventory_health=http://<docker_host>:9081/health -e JAEGER_SERVICE_NAME=catalog-ms-openliberty -e JAEGER_AGENT_HOST=<docker_host> -e JAEGER_AGENT_PORT=6831 -e JAEGER_REPORTER_LOG_SPANS=true -e JAEGER_REPORTER_FLUSH_INTERVAL=2000 -e JAEGER_SAMPLER_TYPE=const -e JAEGER_SAMPLER_PARAM=1"

For instance <docker_host>, if it is docker-for-mac it will be docker.for.mac.localhost.

If not running Jaegar, run the below command.

appsody run --docker-options "-e elasticsearch_url=http://<docker_host>:9200 -e elasticsearch_index=micro -e elasticsearch_doc_type=items -e dev.appsody.application.client.InventoryServiceClient/mp-rest/url=http://<docker_host>:9081/micro/inventory -e inventory_health=http://<docker_host>:9081/health"

For instance <docker_host>, if it is docker-for-mac it will be docker.for.mac.localhost.

If this runs successfully, you will be able to see the below messages.

[Container] [INFO] [AUDIT   ] CWWKT0016I: Web application available (default_host): http://3abf214e654a:9080/micro/
[Container] [INFO] [AUDIT   ] CWWKZ0003I: The application catalog-ms-openliberty updated in 6.546 seconds.
[Container] [INFO] rows loaded
[Container] [INFO] Running it.dev.appsody.application.EndpointTest
[Container] [INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.417 s - in it.dev.appsody.application.EndpointTest
[Container] [INFO] Running it.dev.appsody.application.HealthEndpointTest
[Container] [INFO] Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.372 s - in it.dev.appsody.application.HealthEndpointTest
[Container] [INFO]
[Container] [INFO] Results:
[Container] [INFO]
[Container] [INFO] Tests run: 3, Failures: 0, Errors: 0, Skipped: 0
[Container] [INFO]
[Container] [INFO] Integration tests finished.
[Container] [INFO] Querying Inventory Service for all items ...
[Container] [INFO] rows loaded
  1. Validate the REST API by visiting the following links:

Visit http://localhost:9080/openapi/ui/ and test the rest end point /items as shown below:

Openapi UI

If enabled Jaegar, access it at http://localhost:16686/ and point the service to catalog-ms-openliberty to access the traces.

Jaegar UI

Jaegar traces

About

Openliberty (MicroProfile) version of Catalog microservice

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published