Creating MongoDB Service Template

All actions will be performed in Design Studio workplace.

Creating Prerequisites

Creating Service Category

  1. Click on Classification view and Service Categories tab.

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

    • Name - Database Server
    • Description - Base category for database servers
  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 - DatabaseEndpoint
    • Description - Generic database endpoint, that can be used to access particular database instance by applications.
  4. Click on Parameters section.

    • Click on Add Parameter and set the fields:

      • Name - put protocol
      • Default Value - leave blank
      • Description - leave the default value String.

      Click on OK.

    • Click on Add Parameter and set the fields:

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

      Click on OK.

    • Click on Add Parameter and set the fields:

      • Name - put port
      • Default Value - leave blank
      • Description - leave the default value String.

      Click on OK.

    • Click on Add Parameter and set the fields:

      • Name - put database
      • Default Value - leave blank
      • Description - leave the default value String.

      Click on OK.

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

  6. Click on Access Credentials and set the fields:

    • Username - put ${system-account[Endpoint User].name}
    • Password - put ${system-account[Endpoint User].password}
    • Domain - leave blank
  7. 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 mongodb
    • Product Vendor - put vixtera
    • Category - click Browse and choose the service category Database Server
    • OS Family - click Browse and choose Linux
    • Description - put MongoDB Database Server
  3. Click on OK.

Creating Scripts

Creating installation script

  1. Create a script named install_mongodb.sh with the following content:
#!/bin/bash
cat > /etc/yum.repos.d/mongodb-org-3.2.repo << ___end___
[mongodb-org-3.2]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/6/mongodb-org/3.2/x86_64/
gpgcheck=1
enabled=1
skip_if_unavailable=1
gpgkey=https://www.mongodb.org/static/pgp/server-3.2.asc
___end___
yum -q clean all
yum -y -q install mongodb-org
echo never > /sys/kernel/mm/transparent_hugepage/enabled
echo never > /sys/kernel/mm/transparent_hugepage/defrag
sed -i -e s/"bindIp:"/"#bindIp:"/g /etc/mongod.conf
/etc/init.d/mongod start
echo "db.createUser( { user: \"siteUserAdmin\", pwd: \"${service-parameter[root_password]}\", roles: [ { role: \"userAdminAnyDatabase\", db: \"admin\" } ] } )" | mongo admin 
echo "db.createUser( { user: \"superuser\", pwd: \"${service-parameter[root_password]}\", roles: [ \"root\" ] } )" | mongo admin
/sbin/iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 27017 -j ACCEPT
/sbin/iptables-save > /etc/sysconfig/iptables
/etc/init.d/iptables restart
echo "MongoDB Server installation finished"

Creating script to import data

  1. Create a script named deploy_script_mongodb.sh with the following content:
#!/bin/bash
user=${service-parameter[user]}
password=${service-parameter[password]}
database=${service-parameter[database]}
script=${MediaHome}/scripts/${service-parameter[script]}

if [ $(echo "db.system.users.find({user:\"$user\"}).count()" | mongo admin | grep -A 1 "connecting" | grep -v "connecting") -eq 0 ]; then
	echo "INFO: Creating user $userName"
	echo "db.createUser( { user: \"$user\", pwd: \"$password\", roles: [ { role: \"readWrite\", db: \"$database\" } ] } )" | mongo $database >/dev/null
fi
mongoimport --db $database --file $script
echo "INFO: Script deployment finished"

Creating Service Template

  1. Click on Services view and Service Templates tab.

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

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

    • Version - click on Browse, and specify the following:

      • Service Type - click on Browse and select the service type mongodb.
      • Major - put 1 and leave 0 for Minor, Maintenance ID, Build #
    • Display Name - put MongoDB 1.0.0.0

    • Description - MongoDB Database Server.

  4. In the Media section, click on Media Folders.

    • Click on Add Media Folder and enter the following:

      • Folder Name - put mongodb
      • Description - put Contains install scripts and distributives for MongoDB

      Click on OK.

    • Click on Add Media Folder and enter the following:

      • Folder Name - put scripts
      • Supported Media Types - choose Customization Project
      • Description - put Contains initialization scripts for MongoDB

      Click on OK.

  5. In the Media section, click on Media Files.

    • Click on Add Media File, Upload Media File and specify the following:

      • Media Store - automatically set
      • File Name - click Browse and locate the file install_mongodb.sh
      • Source Folder - automatically set
      • Media Folder - click on Browse and choose the folder mongodb
      • Media Type - click on Browse and choose Script or Configuration
      • Description - put Script that performs installation of MongoDB

      Click on OK.

    • 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_script_mongodb.sh
      • Source Folder - automatically set
      • Media Folder - click on Browse and choose the folder mongodb
      • Media Type - click on Browse and choose Script or Configuration
      • Description - put Script that performs data import to MongoDB

      Click on OK.

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

    • Click on MongoDB service box.

    • Click on Add Endpoint and configure Properties:

      • Endpoint Name - put mongodb
      • Endpoint Type - click on Browse and select DatabaseEndpoint
    • In the Endpoint Details section, click on Details and configure:

      • protocol - put mongodb
      • database - put ${service-parameter[database]}
      • port - put 27017
      • host - leave default value ${runtime.cluster[primary-hosts].internal-ip}
    • In the Endpoint Details section, click on Access Credentials and configure:

      • Username - leave default value ${service-parameter[user]}
      • Pasword - leave default value ${service-parameter[password]}

    Click on OK.

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

    • Click on Add Parameter and configure the following:

      • Name - put root_password
      • Default Value - put ${system-account[Service Owner].password}
      • Description - put MongoDB superuser account password

      Click on OK.

    • Click on Add Parameter and configure the following:

      • Name - put database
      • Default Value - put default
      • Description - put Name of the database that will be used by applications

      Click on OK.

    • Click on Add Parameter and configure the following:

      • Name - put user
      • Default Value - put ${system-account[Endpoint User].name}
      • Description - put User account name used to run scripts

      Click on OK.

    • Click on Add Parameter and configure the following:

      • Name - put password
      • Default Value - put ${system-account[Endpoint User].password}
      • Description - put User account password used to run scripts

      Click on OK.

    • Click on Add Parameter and configure the following:

      • Name - put script
      • Default Value - leave blank
      • Description - put Data file name

      Click on OK.

  8. In the Service Management section, click on Operations.

    • Click on Add Operation and configure the following:

      • In the General section, click on Properties:

        • Operation Type - select Install
        • Description - put Installs MongoDB
      • In the Orchestration | Execution section, click on Execute:

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

      Click on OK.

    • Click on Add Operation and configure the following:

      • In the General section, click on Properties:

        • Operation Type - select Process Customization
        • Description - put Deploys initialization scripts into MongoDB
      • In the Orchestration | Execution section, click on Execute:

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

      Click on OK.

  9. In the Service Management section, click on Deployment Profiles. Click on Add Deployment Profile and configure the following:

    • In the General section, click on Properties and enter the following:

      • Name - put testing
      • Environment Type - click on Browse and choose Testing
      • Description - put Deployment with minimal hardware resources
    • In the General section, click on Default Deployment Group and enter the following:

      • In Host Group Properties box:

        • Group Name - put MongoDB
        • Key - put mongodb
        • OS Platform - click on Browse and choose CentOS 6 x64
        • Hardware Platform - click on Browse and choose Tiny

    Click on OK.

  10. Click on OK.

Testing Service Template

  1. Click Services view and Service Templates tab.

  2. Select template MongoDB 1.0.0.0 in the Service Templates grid.

  3. On the Actions ribbon, click Test Template.

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

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

  6. Click OK.