GithubHelp home page GithubHelp logo

rtclauss / portfolio Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ibmstocktrader/portfolio

0.0 0.0 0.0 52.22 MB

Microservice implemented with MicroProfile that persists stock portfolios to JDBC (such as DB2)

License: Apache License 2.0

Java 65.24% Dockerfile 2.14% HTML 32.62%

portfolio's Introduction

This microservice manages a stock portfolio. The data is backed by two relational database (such as DB2 or PostgreSQL) tables, communicated with via JDBC. The following operations are available:

GET / - gets summary data for all portfolios.

POST /{owner} - creates a new portfolio for the specified owner.

GET /{owner} - gets details for the specified owner.

PUT /{owner} - updates the portfolio for the specified owner (by adding a stock).

DELETE /{owner} - removes the portfolio for the specified owner.

GET /{owner}/returns - gets the return on investment for this portfolio.

POST /{owner}/feedback - submits feedback (to the Watson Tone Analyzer)

All operations return JSON. A portfolio object contains fields named owner, total, loyalty, balance, commissions, free, sentiment, and nextCommission, plus an array of stocks. A stock object contains fields named symbol, shares, commission, price, total, and date. The only operation that takes any query params is the PUT operation, which expects params named symbol and shares. Also, the feedback operation takes a JSON object in the http body, with a single field named text.

For example, doing a PUT http://localhost:9080/portfolio/John?symbol=IBM&shares=123 (against a freshly created portfolio for John) would return JSON like {"owner": "John", "total": 19120.35, "loyalty": "Bronze", "balance": 40.01, "commissions": 9.99, "free": 0, "sentiment": "Unknown", "nextCommission": 8.99, "stocks": [{"symbol": "IBM", "shares": 123, "commission": 9.99, "price": 155.45, "total": 19120.35, "date": "2017-06-26"}]}.

The above REST call would also add a row to the Stocks table via a SQL statement like INSERT INTO Stock (owner, symbol, shares, price, total, dateQuoted) VALUES ('John', 'IBM', 123, 155.45, 19120.35, '2017-06-26'), and would update the corresponding row in the Portfolio table via a SQL statement like UPDATE Portfolio SET total = 19120.35, loyalty = 'Bronze' WHERE owner = 'John'.

The code should work with any JDBC provider. It has been tested with DB2, PostgreSQL and with Derby. Changing providers simply means updating the Dockerfile to copy the JDBC jar file into the Docker image, and updating the server.xml to reference it and specify any database-specific settings. No Java code changes are necessary when changing JDBC providers. The database can either be another pod in the same Kubernetes environment, or it can be running on "bare metal" in a traditional on-premises environment. Endpoint and credential info is specified in the Kubernetes secret and made available as environment variables to the server.xml of WebSphere Liberty. See the manifests/portfolio-values.yaml for details.

Prerequisites for ICP Deployment

This project requires two secrets: jwt and db2. You can get the DB2 values from inspecting your DB2 secrets.

kubectl create secret generic jwt -n stock-trader --from-literal=audience=stock-trader --from-literal=issuer=http://stock-trader.ibm.com

kubectl create secret generic db2 --from-literal=id=<DB2_USERNAME> --from-literal=pwd=<DB2_PASSWORD> --from-literal=host=<DB2_SVC_NAME> --from-literal=port=50000 --from-literal=db=<TRADER_DB_NAME>

# Example db2:
kubectl create secret generic db2 --from-literal=id=db2inst1 --from-literal=pwd=db2inst1 --from-literal=host=trader-ibm-db2oltp-dev --from-literal=port=50000 --from-literal=db=trader

You'll also need to enable login to the IBM Cloud Private internal Docker registry by following [these steps] (https://www.ibm.com/support/knowledgecenter/en/SSBS6K_2.1.0/manage_images/configuring_docker_cli.html). Don't forget to restart Docker after adding your cert. On macOS you can restart Docker by running:

osascript -e 'quit app "Docker"'
open -a Docker

Build and Deploy to ICP

To build portfolio clone this repo and run:

mvn package
docker build -t portfolio:latest -t <ICP_CLUSTER>.icp:8500/stock-trader/portfolio:latest .
docker tag portfolio:latest <ICP_CLUSTER>.icp:8500/stock-trader/portfolio:latest
docker push <ICP_CLUSTER>.icp:8500/stock-trader/portfolio:latest

Use WebSphere Liberty helm chart to deploy Portfolio microservice to ICP:

helm repo add ibm-charts https://raw.githubusercontent.com/IBM/charts/master/repo/stable/
helm install ibm-charts/ibm-websphere-liberty -f <VALUES_YAML> -n <RELEASE_NAME> --tls

In practice this means you'll run something like:

docker build -t portfolio:latest -t mycluster.icp:8500/stock-trader/portfolio:latest .
docker tag portfolio:latest mycluster.icp:8500/stock-trader/portfolio:latest
docker push mycluster.icp:8500/stock-trader/portfolio:latest

helm repo add ibm-charts https://raw.githubusercontent.com/IBM/charts/master/repo/stable/
helm install ibm-charts/ibm-websphere-liberty -f manifests/portfolio-values.yaml -n portfolio --namespace stock-trader --tls

portfolio's People

Contributors

andrewdes avatar brutif avatar cvignola avatar dependabot[bot] avatar greghint avatar jwalcorn avatar karricar avatar kittysmithita avatar leochr avatar maxveit avatar raunak-s avatar rtclauss avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.