###Scalable Web Application Example Implemented in Cloud Foundry
The messaging web application utilizes and demonstrates the Bluemix services Monitoring and Analytics, Autoscale, and Cloudant NoSQL DB.
A messaging web application has been created so you can deploy it into your personal space after signing up for Bluemix and the DevOps service. You will attach the Monitoring and Analytics, Auto-Scaling, and Cloudant NoSQL DB services to the application as well as learn how to begin using these services.
Sign up for Bluemix at https://console.ng.bluemix.net and DevOps Services at https://hub.jazz.net. When you sign up, you'll create an IBM ID, create an alias, and register with Bluemix.
The goal is to create a Node.js application through the Bluemix UI. You will use the initial Node.js application to add Bluemix services. You will create and bind a Cloudant NoSQL Database. This will be used to store messages that we send. We will then create and bind the Monitoring and Analytics and Autoscaling Services. Bluemix provides these services embedded in the Bluemix Service Catalog. Once we have created a Node.js application with these services, we will set out to fork (copy) the application's code and deploy it over the starter Node.js application.
-
Log into your Dashboard at https://console.ng.bluemix.net.
-
From the Dashboard page select CREATE AN APP. This will open a window to select either Web or Mobile.
-
Select Web.
-
In the next screen, select SDK for Node.js.
-
Now, where it says App Name, specify a name for your web application and take note for when you fork your project.
It may take a while for the application to be created and staged. Once it finishes staging, you will have succesfully created a starter Node.js application in Bluemix. You should now see the application in your Dashboard in the Applications category. We will now bind services to our starter Node.js application.
-
In the left sidebar, select Overview to take you into the application's dashboard where we can add/bind services.
-
Click ADD A SERVICE OR API. This directs you to the Services Catalog.
-
In the top search bar, type "cloudant."
-
From the Data Management category, select Cloudant NoSQL DB.
This will bring up a page where you will configure the Cloudant service.
-
Accept the default values.
-
Make note of your Service name that you will use later.
-
Click CREATE.
-
Restage your application when prompted.
You have successfully deployed and bound an instance of Cloudant NoSQL DB to your starter Node.js application.
At this point, we have our starter Node.js application with a binded instance of a Cloudant database. Using what you've learned, add the services Monitoring and Analytics and Auto-Scaling to your application.
Once you have successfully bound "Monitoring and Analytics" and "Auto-Scaling" services to your web application, your app's dashboard should appear like this:
Our next goal is to fork a publicly accessible repository hosted in http://hub.jazz.net into your personal DevOps space. Once we do this, we will be able to deploy the code to Bluemix and spin up instances of the Web Application.
- Navigate to the tutorial's repository.
- In top right of the page, click Fork Project
- A menu will pop up where you will need to provide infomation on where the code will be forked to.
- In Name your project, use the name you chose for your starter Node.js app.
- Choose the Space that your starter Node.js app was created in and click CREATE.
You have successfully forked this application code to your personal Jazz Hub space. To find more about Bluemix's DevOps features reference the docs at https://hub.jazz.net/docs.
You can now configure your application code for deployment to your own Bluemix environment. You will be overwriting the deployed starter Node application, taking advantage of the services you previously configured.
-
On your DevOps Services project page, click EDIT CODE at the top right. This opens your web IDE.
- In your web IDE you will see the a forked copy of this README.md.
-
Click the drop-down menu, found above the code files, and select the pencil symbol to edit launch configuration.
A window will pop up and you will be required to enter information about where the code will be deployed to.
-
In the Launch Config Name field, give a Config Name.
-
In the Target field, select your app's region.
-
In the Organization field, select your app's organization.
-
In the Space field, select your app's Bluemix space.
-
In the Manifest File field, leave the default of manifest.yml.
-
In the Application Name field, select the name of your starter Node.js application.
-
In the Host field, select the hostname you gave for your Node.js application.
-
In the Domain field, leave default at mybluemix.net.
-
Click Save.
-
To the right of the configuration dropdown, click the Play button to deploy your application to Bluemix.
-
Navigate to your Bluemix Dashboard and select your application to view its deployment status.
-
Once your application is finished deploying, click on the Routes link to be navigated to your new web app.
Your new web application is a simple web server that can recieve MQTT messages. The server will write the contents of each message it recieves to your Cloudant database. The purpose of the application is to allow you to experiment with workloads and the Bluemix services.
Looking at your deployed application, you will see a Messaging Rate dropdown where you specify the rate at which messages are sent to the database. In the Duration in Minutes dropdown, you can select how many minutes the automated messaging will persist. In the Message box, you can enter a message that will be sent to the database. The message is optional when sending messages using the Start button. At the bottom of the webpage you will see Start and Stop buttons that you use to initiate and stop the messaging.
- In the Message box put any message you would like to send.
- You may send individual messages by clicking Send a Message.
- Set the rate to Medium.
- Set your duration to 5 minutes.
- Click Start.
You have just succesfully started sending messages to your web server. To see the messages populated, click on your Cloudant service in the application's dashboard. Navigate to the Monitoring and Analytics service in your application's dashboard to view the effects of the new workload on your application.
For more information on Monitoring and Analytics see the getting started page.
We are now going to stress our application and monitor the Auto-Scaling service at work.
- From your application's Dashboard select the Auto-Scaling Service.
- Here you can utilize the Auto-Scaling service shown in the document referenced above.
- Create Auto-Scaling policy to do testing under the Policy-Configuration tab.
- Note that in the Advanced Configuration options you can adjust the time it takes to scale your app.
Once we start sending messages to stress the server, we can monitor auto-scaling from the Metric Statistics and Scaling History tabs.
For more information on the Auto-Scaling service please visit the documentation.
This section describes how to deploy updates to the app with zero downtime using the DevOps Pipeline. Once set up, any changes pushed to your repository will automatically be deployed to the production application. New instances of the application will be created to match the existing application. The appropriate services will then be bound to the new application and the applications workload will be switched to the new deployment. The old iteration of the application is then deleted. All of this this is done utilizing Cloud Foundry commands found in the deploy.sh script in the root directory of the web IDE.
-
Update your manifest.yml.
- In your web IDE, you'll find a manifest.yml file in your root directory. This contains information that your Build and Deploy pipeline will need.
- Update your host to be your application's hostname.
- Update your name to be your application's name.
-
Copy to clipboard the contents of deploy.sh.
- In your web IDE, you'll find a deploy.sh file in your root directory. This contains information that your zero downtime deployment will need.
- Highlight this entire script and right click twice and select copy to copy to clipboard. We will paste this information in the deploy script section of our pipeline later.
-
In your application's DevOps Services page, click on Build and Deploy in the top right. This will take you to the Build and Deploy Pipeline Welcome panel.
-
Add a build stage to your pipeline.
- Click ADD STAGE.
- Provide a name for the stage (Build) and select the SCM Repository for the Input Type.
- Under Stage Trigger select Run jobs whenever a change is pushed to GIT.
- In the Jobs tab, click ADD JOB and select Build.
- Click SAVE.
-
Add a deploy stage to your pipeline.
- Click ADD STAGE.
- Provide a name for the stage (Deploy) and select the Build Artifacts for the Input Type.
- Under Stage Trigger select ** Run jobs when the previous stage is completed**.
- In the Jobs tab, click ADD JOB and select Deploy.
- In the Deploy Script box, highlight everything and right click paste the contents of the deploy.sh file from earlier.
- In the ENVIRONMENT PROPERTIES tab, click +ADD PROPERTY and select Text Property.
- In the newly created field where it says Name, type ROUTES and in the Value box type the HOST:DOMAIN of your Blue Messenger application.
- Click ADD PROPERTY and select Text Property again.
- In the Name box type SERVICES and in the Value box list the name of the services attached to your current Blue Messenger application separated by commas. "no spaces" are allowed after the comma separating the services.
- Click SAVE.
-
Add a test stage to your pipline.
- Click ADD STAGE.
- Provide a name for the stage (Test).
- Under Stage Trigger select Run jobs when the previous stage is completed.
- In the Jobs tab, click ADD JOB and select Test.
- In the Test Command window, add a simple test for your application.
- For example:
curl http://<your hostname>.mybluemix.net/
- For example:
- Click SAVE.
-
Make change to application to show change after deployment.
-
Add the lines of code, found below, to the bottom of your /public/stylesheets/style.css in your web IDE. This change will make the corners of the buttons pointed and not curved.
.btn-lg{ border-radius: 0; }
-
-
To demonstrate zero downtime deployment press the play button on the Build stage. This will build, deploy, and test your application. Spam the database within your Blue-Messenger application, while the deployment stage is running. You can monitor the deployment stage by clicking View logs and history. Once the pipeline has completed refresh your application in the browser and you will see the change to the buttons' edges.