Working with routes from the IBM Bluemix CLI

Today I played with routes on IBM Bluemix. Routes are how you access the app on IBM Bluemix so basically they are hostnames mapped to apps. By default apps are assigned a hostname under mybluemix.net but once you’ve proved a domain belongs to you you may also may custom domain names to your apps. Of course you still need to create a CNAME record in DNS to make it map correctly but you get the point. Working with routes is possible from the GUI but the command line interface (CLI) is more efficient. Below are the commands I use to work with routes. All of the commands assumes you’re already logged in… Actual commands in bold.

Listing the routes (as you can see some routes are not bound to apps): cf routes

Getting routes as lekkim ...

space   host                                                domain            apps
dev     ontime-ibm-connected-2015-verse-demo-contribution   mybluemix.net     IBM ConnectED 2015 Verse Demo Contribution
dev     otgc-verse                                          mybluemix.net     IBM ConnectED 2015 Verse Demo Contribution
dev     mikkel-otgcms-test                                  mybluemix.net     Mikkel OTGCMS Test
dev     mikkel-otgcms-test                                  ontimesuite.com   Mikkel OTGCMS Test
dev     neodashboard-oauth                                  mybluemix.net     neodashboard-oauth
dev     spring-boot-demo-mikkel                             mybluemix.net     Spring-Boot-Demo-Mikkel
dev     engageugdemo                                        mybluemix.net     engageugdemo
dev     engagedemoapp1                                      mybluemix.net
dev     engagementdemo1                                     mybluemix.net
dev     engageugdemoapp                                     mybluemix.net

Map a route called myapp.ontimesuite.com to the engageugdemo app: cf map-route engageugdemo ontimesuite.com -n myapp

Creating route myapp.ontimesuite.com for org lekkim / space dev as lekkim...
OK

Unmap a route called myapp.ontimesuite.com from the engageugdemo app: cf unmap-route engageugdemo ontimesuite.com -n myapp

Removing route myapp.ontimesuite.com from app engageugdemo in org lekkim / space dev as lekkim...
OK

Permently delete the myapp.ontimesuite.com route from your account: cf delete-route ontimesuite.com -n myapp

Deleting route engageugdemo.ontimesuite.com...
OK

PaaS, Bluemix and controlling runtime costs with cron

Back at IBM ConnectED 2015 I created a small demo for IBM using the yet-to-be-released extensibility API of IBM Verse to show of third party extension of IBM Verse. Ever since IBM has been using the demo which is great. The app I wrote is running on Bluemix and I turn it on and off whenever they need it. Now with Bluemix being a Platform As A Service (PaaS) offering I pay for the resource I use and since IBM is still to own up and provider partners with a free plan or larger allowance the monthly allowance of free gigabyte hours is cherished. Simply having it run day in and day out is burning up this free allowance. What is a geek to do? Script it of couse…

Since Bluemix is controllable using the cf command line tool I wrote a small script to allow me to start and stop the app on Bluemix using a script (see below). Invoking it is as simple as doing “versedemo_ctrl.sh start” or “versedemo_ctrl.sh stop” allowing me to do this remotely.

#!/bin/sh
cf login -a https://api.ng.bluemix.net -u {username} -p {password}
cf $1 "IBM ConnectED 2015 Verse Demo Contribution"

Even better is that I’ve added it to an existing on-prem servers crontab so that it starts and stops on business days in the period of time I need it. The cronjob even attaches the log of the start/stop and forwards it to our scheduled job management console so I’m only notified if stuff goes wrong. Love it. Below is a sample crontab entry.

0 12 * 9-11 1-5 ~/versedemo_ctrl.sh start 2>&1 > ~/versedemo.log && mail -s "Verse Demo App Started"
     -a ~/versedemo.log ***XXX***@intravision.dk

The above job simply starts the app Mon-Fri at 12pm (Sept-Nov) and then emails the job logs to our Job Controller service as an attachment.