apereo oae - bootcamp

82
APEREO OAE Bootcamp, Miami 2014

Upload: nicolaas-matthijs

Post on 11-May-2015

391 views

Category:

Education


1 download

DESCRIPTION

The Apereo OAE Bootcamp offers an introduction into back-end and front-end development for the Apereo OAE project. The back-end development part focuses on learning the different extension points behind the scenes in the service layer of OAE. A back-end component for OAE that exposes a REST API is built from scratch. Back-end development topics include: - Node.js NPM module system - OAE back-end application life-cycle - Data-modelling with Apache Cassandra and writing CQL queries from Node.js - Using the OAE APIs to expose back-end functionality for the web VIA RESTful APIs - Writing back-end unit tests using Grunt and Mocha. If time permits, the following will also be covered: - Integrating with OAE's ElasticSearch query and index functionality - Integrating with OAE's Activity and Notifications functionality - Integration with OAE's Admin Configuration functionality The front-end development part focuses on writing a UI widget using the REST APIs developed in the back-end development part. Front-end development topics include: - Integrating with the OAE Widget loading system - Writing internationalizable templates with TrimPath and the widget i18n and l10n functionality - Interacting with the core OAE UI APIs - Using bootstrap 3 to design responsive UI layouts for your widgets - Writing front-end unit tests using Grunt and CasperJS

TRANSCRIPT

Page 1: Apereo OAE - Bootcamp

APEREO OAEBootcamp, Miami 2014

Page 2: Apereo OAE - Bootcamp

WHAT WOULD YOU LIKE TO LEARN?

Page 3: Apereo OAE - Bootcamp

OAE @ MIAMI• Sunday: Development Bootcamp

• Monday @ 10am: State of the Project

• Monday @ 11am: Project talks

• Monday @ 1pm: Architectural Overview

• Tuesday @ 1pm: The FOLD

• Tuesday @ 2pm: Stories from the Frontlines of innovation

• Wednesday @ 11.45am: Apereo & ESUP: Brothers in arms

Page 4: Apereo OAE - Bootcamp

TOPICS 1. OAE Project

2. Hilary System Architecture

3. Node.js Exercise

4. Back-end Exercise

5. UI Architecture

6. Front-end Exercise

Page 5: Apereo OAE - Bootcamp

Support for academic collaborationand networking

Page 6: Apereo OAE - Bootcamp

https://oae.oae-qa0.oaeproject.org

Page 7: Apereo OAE - Bootcamp

PROJECT GOALS• User-led

• Multi-tenant platform

• Cloud-ready

• SaaS

• Cross-institutional

• Used at large scale

Page 8: Apereo OAE - Bootcamp

INTEGRATION

• Integrate OAE with other systems

• Integrate other systems with OAE

Page 9: Apereo OAE - Bootcamp

MULTI-TENANCY• Support multiple institutions on same installation

• Easily created, maintained and configured

• Each institution has its own URL, branding, skinning and users

• Share infrastructure

• Institutions can share and collaborate with other institutions

Page 10: Apereo OAE - Bootcamp
Page 11: Apereo OAE - Bootcamp
Page 12: Apereo OAE - Bootcamp
Page 13: Apereo OAE - Bootcamp
Page 14: Apereo OAE - Bootcamp
Page 15: Apereo OAE - Bootcamp
Page 16: Apereo OAE - Bootcamp
Page 17: Apereo OAE - Bootcamp
Page 18: Apereo OAE - Bootcamp

TOPICS 1. Project Goals

2. Hilary System Architecture

3. Node.js Exercise

4. Back-end Exercise

5. UI Architecture

6. Front-end Exercise

Page 19: Apereo OAE - Bootcamp

OAE ARCHITECTUREThe Apereo OAE project is made up of 2 distinct source code platforms:

• “Hilary”

• Server-side RESTful web platform that exposes the OAE services

• Written entirely using server-side JavaScript in Node.js

• “3akai-ux”

• A client-side / browser platform that provides the HTML, JavaScript and CSS that make up the UI of the application

Page 20: Apereo OAE - Bootcamp

OAE ARCHITECTURE

Page 21: Apereo OAE - Bootcamp

APPLICATION SERVERS• Written in server-side JavaScript, run in Node.js

• Light-Weight

• Single-Threaded

• Event-Driven

• Non-Blocking

• Uses callbacks/promises and an event queue to stash work to be done after I/O or other heavy processes complete

• App servers can be configured into functional specialization:

• User Request Processor

• Activity Processor

• Search Indexer

• Preview Processor

Page 22: Apereo OAE - Bootcamp

APACHE CASSANDRA• Authoritative data source

• Provides high-availability and fault-tolerance without trading away performance

• Regarding CAP theorem, Cassandra favours Availability and Partition Tolerance over Consistency, however consistency is tunable on the connection-level (we always use “quorum”)

• Uses a ring topology to shard data across nodes, with configurable replication levels

• Used by: Netflix, eBay, Twitter

Page 23: Apereo OAE - Bootcamp

ELASTICSEARCH• Lucene-backed search platform

• Built for incremental scaling and high-availability

• Exposes HTTP RESTful APIs for indexing and querying documents

• RESTful query interface uses JSON-based Query DSL

• Powers all of Hilary search functions (Library Search, Members / Memberships Search)

• Used by: GitHub, FourSquare, StackOverflow, WordPress

Page 24: Apereo OAE - Bootcamp

RABBITMQ• Light-weight message queue platform written in

Erlang

• Used for distributing tasks to specialized application server instances

• Supports active-active queue mirroring for high availability

• Used by: Joyent

Page 25: Apereo OAE - Bootcamp

REDIS• REmote DIctionary Server

• Fills a variety of functionality in OAE:

• Broadcast messaging (could move to RabbitMQ)

• Locking

• Caching of basic user profiles

• Holds volatile activity aggregation data

• Comes with no managed clustering solution (yet), but has slave replication for active fail-over

• Some clients manage master-slave switching, and distributed reads for you

• Used by: Twitter, Instagram, StackOverflow, Flickr

Page 26: Apereo OAE - Bootcamp

ETHERPAD• Open Source collaborative editing application written

in Node.js

• Originally developed by Google and Mozilla

• Licensed under Apache License v2

• Powers collaborative document editing in OAE

• Collaborative documents sharded by ID to dedicated Etherpad instances

Page 27: Apereo OAE - Bootcamp

NGINX

• HTTP and reverse-proxy server

• Used to distribute load to application servers, etherpad servers and stream file downloads

• Useful rate-limiting features based on source IP

• Proxy web socket connections to Hilary and Etherpad

• Used by: Netflix, WordPress.com

Page 28: Apereo OAE - Bootcamp

TOPICS 1. Project Goals

2. Hilary System Architecture

3. Node.js Exercise

4. Back-end Exercise

5. UI Architecture

6. Front-end Exercise

Page 29: Apereo OAE - Bootcamp

IDE• OAE Team uses mostly Sublime Text 2 and Aptana Studio 3

• http://www.sublimetext.com/2 • http://www.aptana.com/products/studio3/download

• Useful things in an IDE:

• Syntax highlighting • Automatic “linting” • Variable assistance (don’t expect much from dynamic

scripting language) • File-system navigation

Page 30: Apereo OAE - Bootcamp

GITHUB• OAE Team uses it for :

• Version control • Issue Tracking • Code Integration Workflow (Pull Requests)

• TravisCI Integration for :

• Running unit tests on all commits and pull requests • Packaging up and uploading all commits to Amazon S3 so they can be easily pulled

down and deployed • Packaging up and uploading all tagged releases to Amazon S3 for production releases

• Coveralls Integration for :

• Reporting on trends in unit tests code coverage (e.g., indicates if test coverage drops from 90.2% to 90.15%)

Page 31: Apereo OAE - Bootcamp

TOPICS 1. Project Goals

2. Hilary System Architecture

3. Node.js Exercise

4. Back-end Exercise

5. UI Architecture

6. Front-end Exercise

Page 32: Apereo OAE - Bootcamp

GOAL

Page 33: Apereo OAE - Bootcamp

NPM• Used to download packages and manage versions

• Packages can be installed from:

• Central NPM repo: npm install oae-tasklist • Git: npm install git+https://github.com/oaeproject/oae-tasklist • File-system directory: npm install ../oae-tasklist

• package.json file describes metadata about a module and its dependencies

• When a package is installed, they are placed either locally in a ./node_modules directory or globally (npm install -g) in a shared location such as /usr/local/share/npm/lib/node_modules

Page 34: Apereo OAE - Bootcamp

EXTENDING OAE WITH NPM• NPM module represents a logical set of functionality (e.g., a

back-end REST API, or a set of related widgets)

• NPM modules in 3akai-ux are searched for custom widgets

• NPM modules in Hilary (that start with oae-) are searched for init.js and rest.js to integrate to the application container

• New dependencies can be added to package.json file and then fetched / installed running “npm install”

Page 35: Apereo OAE - Bootcamp

PACKAGE.JSON

• Describes metadata about a package:

• Version • Author • Unique package id

• Required for installing a package as a module

Page 36: Apereo OAE - Bootcamp

TOPICS 1. Project Goals

2. Hilary System Architecture

3. Node.js Exercise

4. Back-end Exercise

5. UI Architecture

6. Front-end Exercise

Page 37: Apereo OAE - Bootcamp

UI ARCHITECTURE

Page 38: Apereo OAE - Bootcamp

UI ARCHITECTURE

Page 39: Apereo OAE - Bootcamp

UI ARCHITECTURE

• In essence

• HTML • CSS • JavaScript

• Talks to Hilary via REST APIs

Page 40: Apereo OAE - Bootcamp

WIDGETS• Modular UI components

• HTML Fragment • JavaScript • CSS • I18n bundles • Manifest file

• Loaded into DOM

• Re-usable

Page 41: Apereo OAE - Bootcamp

WIDGETS

Page 42: Apereo OAE - Bootcamp

TOOLBOX

JS frameworks

CSS frameworks

3rd party plugins

OAE UI API

OAE CSS components

Page 43: Apereo OAE - Bootcamp

TOOLBOX

JS frameworks

CSS frameworks

3rd party plugins

OAE UI API

OAE CSS components

Page 44: Apereo OAE - Bootcamp

JS FRAMEWORKS

• jQuery

• RequireJS

• underscore.js

Page 45: Apereo OAE - Bootcamp

• DOM manipulation

• Cross-browser abstraction

• Events

• Pretty much everything

Page 46: Apereo OAE - Bootcamp

• Utility toolbelt

• Manipulate objects, arrays, etc.

Page 47: Apereo OAE - Bootcamp

• File and module loader

• Load files on the fly

• Necessity to keep things modular

• Optimisation built-in

Page 48: Apereo OAE - Bootcamp

TOOLBOX

JS frameworks

CSS frameworks

3rd party plugins

OAE UI API

OAE CSS components

Page 49: Apereo OAE - Bootcamp

CSS FRAMEWORKS

• Twitter Bootstrap

• Font Awesome

Page 50: Apereo OAE - Bootcamp

TWITTER BOOTSTRAP

Page 51: Apereo OAE - Bootcamp

TWITTER BOOTSTRAP

• Most popular CSS framework

• Responsive (!)

• Documentation

• Basic components, styles, etc.

• Override where necessary

Page 52: Apereo OAE - Bootcamp

BOOTSTRAP GRID• Predefined classes make up rows and columns

• 12 available columns to span

• e.g., 3 x `.col-xs-4` columns

• 4 media-queries

Device Class WidthPhones .col-xs- < 768pxtablets .col-sm- ≥ 768px

Desktops .col-md- ≥ 992pxDesktops .col-lg- ≥ 1200px

Page 53: Apereo OAE - Bootcamp

BOOTSTRAP GRID

Page 54: Apereo OAE - Bootcamp

FONT AWESOME

Page 55: Apereo OAE - Bootcamp

FONT AWESOME• Icon font

• No more images

• Style with CSS

• Skinning

• Easy

Page 56: Apereo OAE - Bootcamp

TOOLBOX

JS frameworks

CSS frameworks

3rd party plugins

OAE UI API

OAE CSS components

Page 57: Apereo OAE - Bootcamp

3RD PARTY PLUG-INS

• jQuery plug-ins

• Bootstrap plug-ins

Page 58: Apereo OAE - Bootcamp

3RD PARTY PLUG-INS• Autosuggest

• History.js

• Fileupload

• Validation

• Markdown

• etc.

Page 59: Apereo OAE - Bootcamp

INCLUDE YOUR OWN

Page 60: Apereo OAE - Bootcamp

TOOLBOX

JS frameworks

CSS frameworks

3rd party plugins

OAE UI API

OAE CSS components

Page 61: Apereo OAE - Bootcamp

OAE UI API• Wrapper for REST requests

• Authentication • Content • Comments • Discussions • Following • Groups • Users • Admin

Page 62: Apereo OAE - Bootcamp

OAE UI API• Utilities

• i18n • l10n • Template rendering • Widget loading • Notifications • XSS escaping • etc.

Page 63: Apereo OAE - Bootcamp

OAE UI API

Page 64: Apereo OAE - Bootcamp

TOOLBOX

JS frameworks

CSS frameworks

3rd party plugins

OAE UI API

OAE CSS components

Page 65: Apereo OAE - Bootcamp

OAE CSS COMPONENTS

• Re-usable HTML fragments

• Consistency

• Design guide

Page 66: Apereo OAE - Bootcamp

OAE CSS COMPONENTS• Clips

• Visibility icon

• Large options

• Thumbnails

• Clip

• Left hand navigation

• Tiles

• List items

• List header

• Skinnable Panel

Page 67: Apereo OAE - Bootcamp

WIDGET BEST PRACTICES

• Namespacing

• i18n

• UI Templating

Page 68: Apereo OAE - Bootcamp

NAMESPACING• Widgets share same container

• Avoid clashes

• Namespace:

• HTML IDs • CSS classes • jQuery selectors

Page 69: Apereo OAE - Bootcamp

I18N

• UI available in multiple languages

• Standard .properties files

• 2 types of bundles

• Core bundles • Widget bundles

Page 70: Apereo OAE - Bootcamp

I18N

Translation priority

1. Widget user language file

2. Widget default language file

3. Container user language file

4. Container user language file

Page 71: Apereo OAE - Bootcamp

I18N

__MSG__TRANSLATION_KEY__

Page 72: Apereo OAE - Bootcamp

I18N

Complete

Partial

Page 73: Apereo OAE - Bootcamp

I18N

Page 74: Apereo OAE - Bootcamp

L10N

• API methods for localizing:

• Number formatting • Date formatting

Page 75: Apereo OAE - Bootcamp

UI TEMPLATING

• TrimPath

• Avoids lots of DOM manipulation

• Pass in JSON data

• Supports if statements, for loops, etc.

Page 76: Apereo OAE - Bootcamp

UI TEMPLATING

• Templates are defined in between <!-- -->

• oae.api.util.template().render(...)

Page 77: Apereo OAE - Bootcamp

UI TEMPLATING• Template

<div id="example_template"><!--

<h4>Welcome {firstName}.</h4> You are ${profile.age} years old--></div>

• Input oae.api.util.template().render($("#example_template"), {

“firstName”: “John”,“profile”: {

“placeofbirth”: “Los Angeles”,“age”: 45

}});

• Result<h4>Welcome John.</h4> You are 45 years old.

Page 78: Apereo OAE - Bootcamp

UI TEMPLATING• Template

<div id="example_template"><!--

{if score >= 5}<h1>Congratulations, you have succeeded</h1>

{elseif score >= 0}<h1>Sorry, you have failed}

{else}<h1>You have cheated</h1>

{/if}--></div>

• Input oae.api.util.template().render($("#example_template"), {

“score”: 6});

• Result <h1>Congratulations, you have succeeded!</h1>

Page 79: Apereo OAE - Bootcamp

UI TEMPLATING• Template

<div id="example_template"><!--

{for conference in conferences}<div>${conference.name} (${conference.year})</div>

{forelse}<div>No conferences have been organized</div>

{/for}--></div>

• Input oae.api.util.template().renderTemplate($("#example_template"), {

“conferences”: [ {“name”: “Apereo Miami”, “year”: 2014}, {“name”: “Apereo San Diego”, “year”: 2013}, {“name”: “Sakai Atlanta”, “year”: 2012}]

});

• Result <div>Apereo Miami (2014)</div> <div>Apereo San Diego (2013)</div> <div>Sakai Atlanta (2012)</div>

Page 80: Apereo OAE - Bootcamp

UI RELEASE PROCESSES• Grunt

• Task-based build system implemented in JavaScript

• Similar in theory of operation to Make, Rake

• Rich ecosystem of plug-ins to do most tasks

• Easy to implement new task when a plugin doesn’t exist yet

• Used for running test suites, production builds, linting tools

Page 81: Apereo OAE - Bootcamp

UI RELEASE PROCESSES• Production Build

• Optimizes the static assets to reduce throughput, request frequency, and optimize caching across versions

• Require.js Optimization:

• Concatenate JavaScript dependencies (reduces number of web requests significantly) • Minify / Uglify JavaScript files (reduces payload sizes significantly, even when gzip enabled

on web server)

• Hash optimization:

• Hash the contents of static assets and append result to the filename, then cache them indefinitely on the browsers

• When the files change, the hash in the filename changes to force reloading of the updated asset

• If files never change across version, client never reloads file until their cache is cleared

Page 82: Apereo OAE - Bootcamp

TOPICS

1. Project Goals

2. Hilary System Architecture

3. Node.js Exercise

4. Back-end Exercise

5. UI Architecture

6. Front-end Exercise