Skip to content

ssahadevan-pivotal/stockAnalyzer-java-v3

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Cassandra Demo - StockAnalyzerV3

This is a demo application that:

  • uses Spring Boot

  • implements a spring-cloud-connector for the Pivotal CF DataStax Enterprise Service

  • History of the stock tickers is persisted in a table in Cassandra

This application requires a DataStax Cassandra DB service bound to it.

Verify that the DataStax tile is installed:

$ cf marketplace Getting services from marketplace in org OrgA / space development as admin…​ OK

service plans description app-autoscaler bronze, gold Scales bound applications in response to load p-cassandra multi-tenant Cassandra service for application development and testing

Tip
Use 'cf marketplace -s SERVICE' to view descriptions of individual plans of a given se

Create the Service:

$ cf cs p-cassandra multi-tenant StockAnalyzerDb

The name of the service instance should match what is there in the manifest.yml Note: The Datastax Enterprise for PCF tile has to be installed in your instance for the create service command to work.

To Deploy:

cd /Users/ssahadevan/Downloads/code/stockAnalyzer-java-v3/ <<< Change This is the directory you installed this on your computer >>>

cf push

To Test:

Enter a stock ticker at:

An entry will be added to the tickerHistory table:

Code Changes made:

In stockAnalyzer-java-v3/src/main/java/io/pivotal/cf/cassandra/demo/Application.java:

  1. Add any new tables

    cql = "create table if not exists tickerHistory (id text , name text , ticker text , price text , pe text , recommendation text , yield text , primary key(id))";
    cassandraTemplate.execute(cql);
  2. Add Models:

    stockAnalyzer-java-v3/src/main/java/io/pivotal/cf/cassandra/demo/models/TickerHistory.java
    This contains the elements of the table
  3. Add repositories:

    stockAnalyzer-java-v3/src/main/java/io/pivotal/cf/cassandra/demo/repositories/TickerHistoryRepository.java
  4. Add controllers:

stockAnalyzer-java-v3/src/main/java/io/pivotal/cf/cassandra/demo/controllers/TickerHistoryController.java

@RequestMapping("/history")
  public String history(@RequestParam(value="name", required=false, defaultValue="World") String name, Model model) {
      model.addAttribute("name", name);
System.out.println("tickers found with findAll():");
System.out.println("-------------------------------");
try {
                model.addAttribute("tickerHistoryList", tickerHistoryRepository.findAll());
                for  ( TickerHistory tickerHistory : tickerHistoryRepository.findAll() )
                {
                  System.out.println("history: Recommendation for  " + tickerHistory.getName() + ", @ " + tickerHistory.getPrice() + ", is " +  tickerHistory.getRecommendation());
                    }
            } catch (Exception e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
            }
    return "historyresults";
}

To compile with gradle:

gradlew build

About

Stock Analyzer on Pivotal CF with DataStax Cassandra DB

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published