Building and running step 2

Create the database keyspace, create the artist and track tables, populate the tables, and then build and run the Playlist example application.

You will now create the keyspace and tables in Cassandra, and then build and run Playlist, which has been enhanced with a music catalog and the ability to list tracks by artist.

Prerequisites

You must have set up your environment before starting this step.

Procedure

  1. In a terminal, go to the playlist workspace.
    cd playlist
  2. Check out the step2 branch using git.
    git checkout step2
  3. Run the cqlsh command.
    cqlsh
  4. Create a new keyspace called playlist with a SimpleStrategy replication strategy and the replication factor set to 1.
    create KEYSPACE playlist WITH replication = {'class':'SimpleStrategy', 'replication_factor': 1 };
    
  5. In cqlsh go to the playlist keyspace.
    use playlist;
  6. Create the artists_by_first_letter, track_by_artist, and track_by_genre tables.
    create table artists_by_first_letter (first_letter text, artist text, primary key (first_letter, artist));
    create table track_by_artist (track text, artist text, track_id UUID, track_length_in_seconds int, genre text,music_file text, primary key (artist, track, track_id));
    create table track_by_genre (track text, artist text, track_id UUID, track_length_in_seconds int, genre text,music_file text, primary key (genre, artist, track, track_id));
    
  7. Populate the tables with data from the songs.csv and artists.csv files located in playlist/scripts.
    copy artists_by_first_letter (first_letter, artist) from 'scripts/artists.csv' WITH DELIMITER = '|';
    copy track_by_artist (track_id, genre, artist, track, track_length_in_seconds, music_file) FROM 'scripts/songs.csv' WITH DELIMITER = '|'  AND HEADER=true;
    copy track_by_genre (track_id, genre, artist, track, track_length_in_seconds, music_file) FROM 'scripts/songs.csv' WITH DELIMITER = '|'  AND HEADER=true;
  8. Quit cqlsh.
    exit;
  9. Build and run Playlist using mvn.
    mvn verify cargo:run
  10. In a web browser, navigate to or reload: http://localhost:8080/playlist
  11. Click Visit the Song Database. You can also add tracks by clicking Add a Song and filling the in the form fields.

    You now have the ability to browse the music catalog by artist name and genre.

    Note that My Playlists and Statistics are not yet implemented.

  12. Stop the Jetty instance by pressing Ctrl+C in your terminal.
    [INFO] Press Ctrl-C to stop the container...
    ^C[INFO] [talledLocalContainer] Jetty 9.2.11.v20150529 is stopping...
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 34:26.970s
    [INFO] Finished at: Sat Jun 06 04:32:59 EDT 2015
    [INFO] Final Memory: 14M/183M
    [INFO] ------------------------------------------------------------------------
    ...

What's next

Proceed to Step 3: Adding hot tracks.