Deplying a distributed applicatin with OpenStack Cntext and Prerequisites This labratry is t learn usage f OpenStack (OS) thrugh: 1. the hrizn graphical interface f OpenStack (Exercise 1), 2. the cmmand-line tl: OpenStack client, 3. the OpenStack SDK (Exercise 2) 4. the OpenStack bject strage service Swift (Exercise 3, Sessin 5: CC-STRG) The fllwing resurces and tls are required fr this labratry sessin: 1. An Ubuntu 14.04 machine, Mac OS r Windws machine (with putty) 2. An accunt n hepiaclud infrastructure Lab deliverables: Submit yur lab reprt t the Mdle space f the curse. Lab due date: See due date n the mdle web site 1
Intrductin This lab aims t deply a distributed applicatin n an OpenStack infrastructure (hepiaclud: lsds.hesge.ch/hepiaclud). The applicatin cllects and stre data frm several sensrs installed in a given building. Sensrs are used t measure temperature, humidity, brightness and physical presence. Figure 1 shws the lcatin f the sensrs in varius rms f hepia building. Figure 1: Lcatins f sensrs in 4 th and 5 th flrs f hepia building The system is cmpsed f fur layers (figure 2): 1. Sensr layer: it includes multi-functin sensrs that measure temperature, humidity, brightness and presence. Each sensr is cnnected (paired) t ne f the three Raspberries (pi1, pi2, pi3 in Figure 1): ne Raspberry Pi n the furth flr and tw Raspberries are n the fifth flr. 2. Raspberry Pi layer: Raspberries are used t cllect data received frm multiple sensrs. Each Raspberry Pi implements a REST server that stres the data received frm the sensrs cnnected t it. 3. Clud Layer: this layer is used t cllect data received frm the raspberries and stre them in a database. A REST Client is used t retrieve data frm the raspberries REST servers while a REST server is used t allw secured access t the data. 4. End user app. layer: This layer retrieves data frm the Clud layer (by means f the REST Server) and uses them fr the specific needs f end users applicatins. Figure 2: System architecture 2
We can als view the system as a set f instances. Each f them belngs t ne f the fur fllwing types f instances: Raspberry instances: They crrespnd t the raspberry layer. A raspberry instance is a REST server, which cllects data frm paired sensrs. This lab des nt deal with the raspberry instances. RESTClient instances: They are deplyed in the clud (clud layer), and are respnsible f: cllecting data frm Raspberry instances, string data n the MngDB instances. MngDB Server instances: They are deplyed in the clud (clud layer). These instances are used t manage a MngDB database. RESTServer instances: They are deplyed in the clud (clud layer). These instances retrieve data frm MngDB instances and prvide them t any end user applicatin The gal f this lab is t: deply n the hepiaclud infrastructure: ne MngDB Server instance, ne RESTServer instance and, ne RESTClient instance, visualise data stred in the MngDB database. The binaries f RESTServer and RESTClient instances are available n the mdle site f the curse. Exercise 1: Using hrizn t deply the system (manual deplyment) The gal f this exercise is t create the three instances MngDB instance, RESTServer instance and RESTClient instance by using the web interface prtal (hrizn) f hepiaclud. Hw t create instances? Read this URL t understand hw t create and cnnect t instances n hepiaclud: http://lsds.hesge.ch/hepiacludwebinterface/ Creatin f a MngDB instance Image: Ubuntu 14.04 Type: m1.small Access yur instance by ssh and install MngDB: sud apt-get install mngdb-server Cnfiguratin: Change the /etc/mngdb.cnf cnfiguratin file in rder t allw the database listen n the netwrk: change «bind_ip = 127.0.0.1» by «bind_ip = 0.0.0.0» rebt the machine: sud rebt T check whether the database listens n the netwrk: sud netstat --listen -a -p Create a snapsht f yur instance s as yu can use it later withut any reinstallatin and/r cnfiguratin. 3
Creatin f a RESTClient instance Create an m1.small instance using the image Ubuntu 14.04. This distributin includes pythn Versin 2.7.x. When the instance is created, access it by ssh and fllw these instructins: 1. sud apt-get install pythn-pip 2. sud pip install pymng 3. cpy the pythn REST client prgram: wget URL «lcatin f the restclient.py file» r use scp cmmand 4. Execute the prgram: pythn restclient.py IP MngDB instance & where IP MngDB instance is the address f the MngDB instance D nt frget that the MngDB database needs t be reached n these prts: 27017 and 28017 Create a snapsht f yur instance s as yu can use it later withut any reinstallatin and/r cnfiguratin. Creatin f a RESTServer instance Create an m1.small instance using the image Ubuntu 14.04. When the instance is created, access it by ssh and fllw these instructins: 1. Sud apt-get update 2. sud apt-get install pythn-pip 3. sud pip install pymng 4. sud pip install flask 5. cpy the pythn REST server prgram: wget «lcatin f the restserver.py file» r use scp cmmand 6. Execute the prgram: pythn restserver.py MngDB Instance IP & The REST server listens n prt 18000 Create a snapsht f yur instance s as yu can use it later withut any reinstallatin and/r cnfiguratin. Hw t check that the system is peratinal? T check that data are crrectly stred in the MngDB database, submit a http request t the REST server. Data cllected frm respberries are accessed using these three URLs: curl http://ip:18000/getlastsensrsvalues/pi1 curl http://ip:18000/getlastsensrsvalues/pi2 curl http://ip:18000/getlastsensrsvalues/pi3 where IP is the IP address f the RESTSever instance. The curl cmmand must be executed within hepiaclud. Deliverables (see due date n the mdle web site) In yur lab reprt: 4
1. In yur hepiaclud accunt, mve t Instances tab, create a screensht f the three instances yu have created, and insert it in yur dcument. 2. Add a screensht f the data retrieved frm ne f the three raspberries (Figure 3). Specify in yur dcument: a. The URL yu have used t cllect data b. the date and time (date, hur, minute) f the http request yu made t get this data. Figure 3: data retrieved frm MngDB At the end f the exercise, d nt frget de delete yur instances. Exercise 2: Using OpenStack SDK t deply the system (autmatic deplyment) The aim f this exercise is t develp a Pythn script which autmatically deplys the whle system (three instances). VMs must be created and mnitred by using OpenStack SDK: https://develper.penstack.rg/sdks/pythn/penstacksdk/ Hw t install OpenStack SDK? Type: pip install penstacksdk, n a fresh installed Ubuntu machine (yu can create a dedicated instance n hepiaclud): https://develper.penstack.rg/sdks/pythn/penstacksdk/users/index.html The Pythn script t develp is assumed t execute these peratins: 1. creates ne MngDB instance, 2. creates ne RESTClient instance and launch the prgram client.py, 3. creates ne RESTServer instance and launch the prgram server.py, 4. deletes the VMs when the user presses A (Abrd) Fr pints 1, 2 and 3, use snapshts already created in Exercise 1. Deliverable (see due date n the mdle web site): 1. Pythn script using OpenStack SDK. The cde must be dcumented Exercise 3: Using Swift (bject strage) t stre data The purpse f this exercise is t expand the REST Server prgram s that it can stre sensrs data in a swift bject strage. The versin f the REST Server used in exercises 1 and 2, supprts three rutes: 1. /getlastsensrvalue/<string:pi_id>/<int:sensr_id>. This rute retrieves all data cming frm sensr_id, cnnected t pi_id raspberry. 2. /getlastsensrsvalues/<string:pi_id>. This rute retrieves all data cllected by pi_id raspberry. 3. /getsensrvaluesinlasthurs/<string:pi_id>/<int:sensr_id>/<int:hurs>. This rute retrieves all data f sensr_id. This sensr is cnnected t pi_id raspberry. The gal f this exercises is t add a new rute: /getsensrvaluesbetweendates/<string:pi_id>/<int:sensr_id>/<string:date1>/<string:date2> This rute is assumed t create a swift cntainer and write in it a swift bject. The swift bject cntains data retrieved frm sensr_id, cnnected t pi_id, between date1 and date2. 5