Node ACS
Mauro Parra-Miranda
mauropm@gmail.com
Agenda

Introduction

NodeJS

Features

Examples
Introduction
Fixed set of features in the ACS: checkins, post in
social net works, user administration, etc.

Customers with needs out of that universe were a
kind of lost, since they have to provide their own
webservices for custom stuff.

Customers are not that good in setting up
webservices that escalate; or setup servers in
general.
Solution
ACS was already providing a nice escalating
infrastructure; the natural step was to extend that
ser vice to a custom small/micro programs.

Node JS was the selected technology to do the bridge
bet ween the customer and the ACS, with super
escalating power (vitamins added).

Think of ACS as a Meta Cloud Services Provider,
with zero server configuration time.
NodeJS
“Node.js is an evented I/O framework for the V8
JavaScript engine. It is intended for writing
scalable net work programs such as web servers.” -
Wikipedia.

Who uses NodeJS? - Yammer, Proxlet, Bocoup, Yahoo,
Walmart, Appcelerator :-)

Niceties: Parallel execution, event driven, mongodb
support, etc.
Features
Cluster, crypto, dns, events, file system, http, https,
modules, OS, Path, Process, readline, query strings,
mongodb, timers, strings, tls/ssl, udp/datagram,
utilities, zlib.

You can use modules from the nodejs world, such as:
http://blog.nodejitsu.com/6-must-have-nodejs-
modules

xml2js: if you are using old webservices, you can
easily transform xml responses into javascript
objects with this module. Think SOAP and stuff.
Setup

install (from terminal in mac):
$ sudo npm install -g acs

setup (from terminal in mac):
$ acs login

Create a new app (from terminal in mac):
$ acs new myapp
this will create a directory myapp w/ your new
app
Edit your app

Go to your directory myapp. Inside you will find
myapp.js. Edit and add this:
api.index = function(req, res) {
 res.text('Hello, world!');
 logger.info('This is an info message. ' + new Date());
}

Save it.
Running your app locally

   acs run -d myapp

   Go to http://localhost:8080 to see your app running
   locally.

   If you are running jenkins, your app will use other
   port (Jenkins uses 8080 by default), so you will
   likely end in 8081 port.
Running your app in ACS

   acs publish -d myapp

   You will see your app running at
   http://<appid>.cloudservices.appcelerator.com

   It’s like having a Heroku in appc.
Service
The app now has one service (or a single endpoint)
called api.index. The args are “Express framework”
Request and Response Objects

I.e. we are running express. Check more about it
here: http:/ /expressjs.com/

You can add more services, with “ add”.
                                acs

acs add <name>

You will expose this new service in t wo ways. One
public at: <app_url>/<name> and one in the code by
api.<name>
Modules
You can use any nodejs modules within your app,
using npm.

You will need to list the modules you are using
(dependencies) in the package.json file. So, when you
deploy the app (either locally or in the ACS
infrastructure), the modules will be installed in your
running instance.

Besides the Node modules, you will have the logger
function for log and the builtin ACS library for
calling the ACS services.
Big fat example

                 Check this call to the ACS
                     login - user level


                    Call to ACS Places


You can call any of the functions in ACS api!
Real problem - Escalate
   Escalate - This is the real issue. You will need
   something that will escalate properly and easily.

   Now, with NodeJS and ACS, you can escalate your
   webservices. Which, usually, will depend on a
   database.

   You now will have access to MongoDB - i.e., this
   next generation non-relational db.

   Think of mongodb as a db that will store objects
   instead of rows and columns - forget the excel type
   of order, get into a objects.
Setup mongodb

Create an app.

Add mongodb as dependency in the package.json:

"dependencies": {
   "mongodb": ">=1.1.6"
},
Open connection to
    mongodb
Insert a record
Query a record
Mongoose


Module to provide ORM-alike features to NodeJS.
This is, will abstract the objects from your
Javascript to MongoDB records easily.

https://github.com/learnboost/mongoose/
NodeJS - how we escale?
                   You have a service, with a single point of entry (like
                   url/ser vice).

                   In order to not block the server, you will need a
                   request handler (worker) that will actually do the
                   job, freeing the service to continue into listen mode.

                   the request handler will actually implement the
                   steps to do the processing - this is how you
                   escalate.

                               Forkity Fork!*
* sorry, i used to be a linux guy - fork processes
Resources
Node Beginner - http://www.nodebeginner.org

Appc Blog - http://developer.appcelerator.com/blog/
2012/09/node-js-for-acs-public-developer-
preview.html

Appc Custom code tutorial - http://
cloud.appcelerator.com/docs/nodejs/
custom_code_tutorial

NodeJS @ ACS

  • 1.
  • 2.
  • 3.
    Introduction Fixed set offeatures in the ACS: checkins, post in social net works, user administration, etc. Customers with needs out of that universe were a kind of lost, since they have to provide their own webservices for custom stuff. Customers are not that good in setting up webservices that escalate; or setup servers in general.
  • 4.
    Solution ACS was alreadyproviding a nice escalating infrastructure; the natural step was to extend that ser vice to a custom small/micro programs. Node JS was the selected technology to do the bridge bet ween the customer and the ACS, with super escalating power (vitamins added). Think of ACS as a Meta Cloud Services Provider, with zero server configuration time.
  • 5.
    NodeJS “Node.js is anevented I/O framework for the V8 JavaScript engine. It is intended for writing scalable net work programs such as web servers.” - Wikipedia. Who uses NodeJS? - Yammer, Proxlet, Bocoup, Yahoo, Walmart, Appcelerator :-) Niceties: Parallel execution, event driven, mongodb support, etc.
  • 6.
    Features Cluster, crypto, dns,events, file system, http, https, modules, OS, Path, Process, readline, query strings, mongodb, timers, strings, tls/ssl, udp/datagram, utilities, zlib. You can use modules from the nodejs world, such as: http://blog.nodejitsu.com/6-must-have-nodejs- modules xml2js: if you are using old webservices, you can easily transform xml responses into javascript objects with this module. Think SOAP and stuff.
  • 7.
    Setup install (from terminalin mac): $ sudo npm install -g acs setup (from terminal in mac): $ acs login Create a new app (from terminal in mac): $ acs new myapp this will create a directory myapp w/ your new app
  • 8.
    Edit your app Goto your directory myapp. Inside you will find myapp.js. Edit and add this: api.index = function(req, res) { res.text('Hello, world!'); logger.info('This is an info message. ' + new Date()); } Save it.
  • 9.
    Running your applocally acs run -d myapp Go to http://localhost:8080 to see your app running locally. If you are running jenkins, your app will use other port (Jenkins uses 8080 by default), so you will likely end in 8081 port.
  • 10.
    Running your appin ACS acs publish -d myapp You will see your app running at http://<appid>.cloudservices.appcelerator.com It’s like having a Heroku in appc.
  • 11.
    Service The app nowhas one service (or a single endpoint) called api.index. The args are “Express framework” Request and Response Objects I.e. we are running express. Check more about it here: http:/ /expressjs.com/ You can add more services, with “ add”. acs acs add <name> You will expose this new service in t wo ways. One public at: <app_url>/<name> and one in the code by api.<name>
  • 12.
    Modules You can useany nodejs modules within your app, using npm. You will need to list the modules you are using (dependencies) in the package.json file. So, when you deploy the app (either locally or in the ACS infrastructure), the modules will be installed in your running instance. Besides the Node modules, you will have the logger function for log and the builtin ACS library for calling the ACS services.
  • 13.
    Big fat example Check this call to the ACS login - user level Call to ACS Places You can call any of the functions in ACS api!
  • 14.
    Real problem -Escalate Escalate - This is the real issue. You will need something that will escalate properly and easily. Now, with NodeJS and ACS, you can escalate your webservices. Which, usually, will depend on a database. You now will have access to MongoDB - i.e., this next generation non-relational db. Think of mongodb as a db that will store objects instead of rows and columns - forget the excel type of order, get into a objects.
  • 15.
    Setup mongodb Create anapp. Add mongodb as dependency in the package.json: "dependencies": { "mongodb": ">=1.1.6" },
  • 16.
  • 17.
  • 18.
  • 19.
    Mongoose Module to provideORM-alike features to NodeJS. This is, will abstract the objects from your Javascript to MongoDB records easily. https://github.com/learnboost/mongoose/
  • 20.
    NodeJS - howwe escale? You have a service, with a single point of entry (like url/ser vice). In order to not block the server, you will need a request handler (worker) that will actually do the job, freeing the service to continue into listen mode. the request handler will actually implement the steps to do the processing - this is how you escalate. Forkity Fork!* * sorry, i used to be a linux guy - fork processes
  • 21.
    Resources Node Beginner -http://www.nodebeginner.org Appc Blog - http://developer.appcelerator.com/blog/ 2012/09/node-js-for-acs-public-developer- preview.html Appc Custom code tutorial - http:// cloud.appcelerator.com/docs/nodejs/ custom_code_tutorial