/beer-api

Primary LanguageJavaApache License 2.0Apache-2.0

Spring-Boot and Camel XML QuickStart

This example demonstrates a Spring Boot example running a Camel REST route connecting to a PostgreSQL database.

The application utilizes the Spring @ImportResource annotation to load a Camel Context definition via a camel-context.xml file on the classpath.

Building

The example can be built with

mvn clean install

Running the example in OpenShift

It is assumed that:

Login as developer

~/Projects/git/beer-api on master*

$ oc login -u developer -p developer
Login successful.

You don't have any projects. You can try to create a new project, by running

oc new-project <projectname>    

Create project beer

$ oc new-project beer
Now using project "beer" on server "https://192.168.64.29:8443".

You can add applications to this project with the 'new-app' command. For example, try:

    oc new-app centos/ruby-22-centos7~https://github.com/openshift/ruby-ex.git

to build a new example application in Ruby.

Setup PostgreSQL database

  • Go to the OpenShift Web Console

  • Select the beer project previously created

  • Add a PostgreSQL database with the following settings:

    • Database service name: postgresql
    • PostgreSQL Connection Username: beeruser
    • PostgreSQL Connection Password: beerpw
    • PostgreSQL Database Name: beerdb

Grep the running postgresql pod with:

$ oc get pods | grep postgresql

postgresql-1-qjq75   1/1       Running   0          1m
  • Copy data files into the pod

To create the tables and load data into the table use the following steps:

$ oc cp postgres/breweries.csv postgresql-1-qjq75:/tmp/

$ oc cp postgres/beers.csv postgresql-1-qjq75:/tmp/

$ oc cp postgres/*.sql postgresql-1-qjq75:/tmp/
 
$ oc rsh postgresql-1-qjq75
sh-4.2$ ls /tmp

beers.csv  breweries.csv  ks-script-hE5IPf  openbeer-psql.sql  yum.log

sh-4.2$ psql -d beerdb -f /tmp/openbeer-psql.sql -W
Password: postgres
CREATE TABLE
COPY 1414
CREATE TABLE
COPY 5901

sh-4.2$ psql -d beerdb
beerdb=# grant all privileges on all tables in schema public to beeruser;
GRANT

beerdb=# \q

sh-4.2$ exit

SpringBoot Application

The example can be built and run on OpenShift using a single goal:

mvn -s settings.xml fabric8:deploy

To list all the running pods:

oc get pods

Then find the name of the pod that runs this quickstart, and output the logs from the running pods with:

oc logs <name of pod>

You can also use the OpenShift web console to manage the running pods, and view logs and much more.

Using the beer API

You can use the following URLs (replace api-route with the correct URL as mentioned in the OpenShift Web Console) to test out the API we just implemented and is running on Red Hat OpenShift and waiting to be consumed.