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.
Procedure
-
In a terminal, go to the playlist workspace.
-
Check out the
step2
branch using git.
-
Run the cqlsh command.
-
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 };
-
In cqlsh go to the
playlist
keyspace.
-
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));
-
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;
-
Quit cqlsh.
-
Build and run Playlist using mvn.
-
In a web browser, navigate to or reload:
http://localhost:8080/playlist
-
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.
-
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] ------------------------------------------------------------------------
...