Creating HelloWorld for Node.js Application Template

All actions will be performed in Design Studio workplace.

Creating Prerequisites

Creating Application Category

  1. Click on Classification view and Application Categories tab.

  2. On Activities ribbon, click on Add Application Category and set the fields:

    • Name - Web Application
    • Description - Base application category for web applications
  3. Click on OK.

Adding an Endpoint Type

  1. Click on Classification view and Endpoint Types tab.

  2. On Activities ribbon, click on Add Endpoint Type.

  3. In the General section, click on Properties and set the fields:

    • Name - HttpEndpoint
    • Description - Generic http endpoint, that can be used to access particular web service by applications
  4. Click on Parameters section.

    • Click on Add Parameter and set the fields:

      • Name - put protocol
      • Default Value - put http
      • Description - leave the default value “String”.

      Click on OK.

    • Click on Add Parameter and set the fields:

      • Name - put host
      • Default Value - put ${runtime.cluster[primary-hosts].external-ip}
      • Description - leave the default value “String”.

      Click on OK.

    • Click on Add Parameter and set the fields:

      • Name - put port
      • Default Value - put 80
      • Description - leave the default value “String”.

      Click on OK.

    • Click on Add Parameter and set the fields:

      • Name - put path
      • Default Value - leave blank
      • Description - leave the default value “String”.
    • Click on Add Parameter and set the fields:

      • Name - put query
      • Default Value - leave blank
      • Description - leave the default value “String”.

    Click on OK.

  5. Set the Connection String value to ${protocol}://${host}:${port}/${path}${query}

  6. Click on OK.

Creating Service Type

  1. Click on Services view and Service Types tab.

  2. On the Activities ribbon, click on Add Service Type and enter the settings:

    • Name - put helloworld_app
    • Product Vendor - put vixtera
    • Category - click Browse and choose the application category Web Application
    • OS Family - click Browse and choose Linux
    • Description - put HelloWorld Web Application

Creating Application

  1. Create a folder package and a file named helloworld.js with the following content:
// Load configuration
var config = require('./config.json');

// Load the http module to create an http server.
var http = require(config.server.protocol);

// Configure our HTTP server to respond with Hello World to all requests.
var server = http.createServer(function (request, response) {
  response.writeHead(200, {"Content-Type": "text/plain"});
  response.end("Hello World\n");
});

server.listen(config.server.port);

// Configure graceful shutdown
process.on('SIGTERM', function () {
  server.close(function () {
    process.exit(0);
  });
});
  1. Compress package folder to archive helloworld_nodejs.tgz
  2. Create a folder application and put there the archive helloworld_nodejs.tgz.
  3. Compress application folder to archive helloworld_nodejs.zip

Creating Scripts

  1. Create a script named deploy_app_nodejs.sh with the following content:
#!/bin/bash
application=${service-parameter[application]}
appJs=$application.js
package=${MediaHome}/application/${service-parameter[package]}
path=/var/www
port=80

engine=${dependency[database].protocol}
user=${dependency[database].logininfo.username}
password=${dependency[database].logininfo.password}
host=${dependency[database].host}
dbPort=${dependency[database].port}
database=${dependency[database].database}

mkdir -p $path/$application
tar xf $package -C $path/$application
/bin/mv -f $path/$application/package/* $path/$application
rm -rf $path/$application/package

cat > $path/$application/config.json << __config__
{
  "database": {
    "scheme": "$engine",
    "user": "$user",
    "password": "$password",
    "host": "$host",
    "port": $dbPort,
    "name": "$database"
  },
  "server": {
    "protocol": "http",
    "port": "$port"
  }
}
__config__

cat > /etc/init.d/$application << __service__
#!/bin/sh
#
# Startup script for the NodeJS application
#
# chkconfig: - 85 15
# description: NodeJS application
# processname: $application
# pidfile: /var/run/$application.pid
# config:

# Source function library.
. /etc/rc.d/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ \${NETWORKING} = "no" ] && exit 0

# Set environment.
export PATH=$PATH:/usr/local/bin/
export application=$path/$application/$appJs

# See how we were called.
case "\$1" in
  start)
        # Start daemon
        echo "Starting $application: "
        forever start \$application >/dev/null
        RETVAL=\$?
        if [ "\$RETVAL" = "0" ]; then
                touch /var/lock/subsys/$application & echo "$application started"
        else
                echo "$application NOT started"
        fi
        ;;
  stop)
        # Stop daemon
		if [ -z "\$(forever list | grep \$application )" ]; then
			echo "$application is not started. Nothing to stop"
			exit 0
		fi
        echo "Shutting down $application: "
        forever stop \$application
        RETVAL=\$?
        if [ "\$RETVAL" = "0" ]; then
                rm -f /var/lock/subsys/$application & echo "$application stopped"
        else
                echo "$application NOT stopped"
        fi
        ;;
  restart)
        \$0 stop
        \$0 start
        ;;
  condrestart)
       [ -e /var/lock/subsys/$application ] && \$0 restart
       ;;
  status)
        NUM=\`ps aux | grep -v grep | grep -v forever/bin/monitor | grep \$application | wc -l\`
        if [ "\$NUM" = "1" ]; then
		echo "$application is running"
        else
                echo "$application is stopped"
        fi
        ;;
  *)
        echo "Usage: \$0 {start|stop|restart|status}"
        exit
esac

exit \$RETVAL
__service__

chmod 755 /etc/init.d/$application
chkconfig --add $application
chkconfig --level 345 $application on
/etc/init.d/$application start
/sbin/iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport $port -j ACCEPT
/sbin/iptables-save > /etc/sysconfig/iptables
/etc/init.d/iptables restart

echo "INFO: Node.js Application deployment finished"

Updating Service Template

  1. Click on Services view and Service Templates tab.

  2. Select the template nodejs 1.0.0.0. On the Actions ribbon, click on Edit Template.

  3. In the Media section, click on Media Folders, then click on Add Media Folder and enter the following:

    • Folder Name - put application
    • Supported Media Types - choose Customization Project
    • Description - put Contains customization application

    Click on OK.

  4. In the Media section, click on Media Files, then click on Add Media File, Upload Media File and specify the following:

    • Media Store - automatically set
    • File Name - click Browse and locate the file deploy_app_nodejs.sh
    • Source Folder - automatically set
    • Media Folder - click Browse and choose the folder nodejs
    • Media Type - click Browse and choose Script or Configuration
    • Description - put Script that performs deployment of Web Application for Node.js Runtime Environment

    Click on OK.

  5. In the Service Management section, click on Topology.

    • Click on Node.js 1.0.0.0 service box.

    • Click Add Endpoint and configure Properties:

      • Endpoint Name - put application
      • Endpoint Type - click Browse and select HttpEndpoint
      • Mark the Public checkbox
    • In the Endpoint Details section, click on Details and configure:

      • protocol - leave default value http
      • host - leave default value ${runtime.cluster[primary-hosts].external-ip}
      • port - leave default value 80

    Click on OK.

  6. In the Service Management section, click on Service Parameters.

    • Click on Add Parameter and configure the following:

      • Name - put application
      • Default Value - leave blank
      • Description - put Node.js application name

      Click OK.

    • Click on Add Parameter and configure the following:

      • Name - put package
      • Default Value - leave blank
      • Description - put Node.js application package name

      Click on OK.

  7. In the Service Management section, click on Operations. Click on Add Operation and configure the following:

    • In General section, click on Properties:

      • Operation Type - select Process Customization
      • Description - put Deploys Application using Node.js runtime environment
    • In Orchestration section, click on Execution section and Execute:

      • Script Name - put run_deploy_app_nodejs.sh
      • Script - put
    echo ${system-account[Service Owner].password} | sudo -S ${MediaHome}/nodejs/deploy_app_nodejs.sh || exit 1
    

    Click on OK.

Creating Application Template

  1. Click on Services view and Application Templates tab.

  2. On the Actions ribbon, click on Add Template and Add Template.

  3. In the General section configure Properties.

    • Version - click on Browse and specify the following:

      • Service Type - click on Browse and select the application type helloworld_app.
      • Major - put 1 and leave 0 for Minor, Maintenance ID, Build #
    • Display Name - put HelloWorld for Node.js 1.0.0.0

    • Description - put HelloWorld Web Application.

  4. In the Service Management section, click on Topology. From the Topology Components pane, from sections Application Servers > nodejs drag and drop Node.js 1.0.0.0 template to the topology workspace.

  5. In the Service Management section, click on Services. Select service Node.js 1.0.0.0 and click Customize Settings.

    • In the Service Management section, click on Service Parameters.

      • Click on Add Parameter and configure the following:

        • Name - put application
        • Default Value - put helloworld
        • Mark the Required checkbox
        • Description - put Node.js application name

        Click OK.

      • Click on Add Parameter and configure the following:

        • Name - put package
        • Default Value - put helloworld.tgz
        • Mark the Required checkbox
        • Description - put Node.js application package name

        Click on OK.

  6. In the Service Management section click on Deployment Profiles. Click on Add Deployment Profile and specify the following:

    • In the General section, click on Properties:

      • Name - put testing.
      • Environment Type - click on Browse and select Testing.
      • Description - put Deployment with minimal hardware resources.
    • In the General section, click on Deployment Diagram.

      • Drag and drop service Node.js 1.0.0.0 to the workspace. Ensure that Hardware Platform is Tiny and click on OK.
    • Click on OK.

  7. In the Media section, click on Customization Project. Click Upload near to Customization archive field and set:

    • File Name - click Browse and locate the file helloworld_nodejs.tgz
    • Source Folder - automatically set

    Click on OK.

  8. Click on OK.

Testing Service Template

  1. Click on Services view and Application Templates tab.

  2. Select template HelloWorld for Node.js 1.0.0.0 in the Service Templates grid.

  3. On the Actions ribbon, click on Test Template.

  4. In the Provisioning section, click on Properties and set:

    • Environment Type - click on Browse and choose Testing
    • Space, Deployment Profile and System Profile will be completed automatically
  5. Click on Provision.

  6. Click on OK.