Practice 9 - Starting with cloud
References
Referred documents and web sites contain supportive information for the practice:
- euca2tools User guide can be found in: Eucalyptus user guide
- OpenStack wiki
- Java Tutorial http://docs.oracle.com/javase/tutorial/java/
Introduction
Usually, when working with cloud infrastructure you follow this work flow:
- Select an appropriate virtual machine image to run
- Start an instance of the virtual machine image. Login as root to the instance and set it up to meet your requirements. I.e. install needed software, upload your own program, do any other configuration as you would do with the real machine.
- As you will lose all your work as instance will be terminated you have three options on how to persist your changes:
- Save all your configuration steps to a script that will launch and configure the instance automatically for you.
- Bundle a new image from your running instance and next time launch your custom image.
- Save the running instance as a snapshot, and next time launch new instances from there.
First option is more flexible as you can easily change the script than bundle a new image if something changes. Second and third option are simpler to use once you have stable configuration or when launching large number of instances.
Exercise 9.1. Creating a Snapshot Image
In Cloud part of the labs, you will work mostly with JAVA. The idea of this exercise is to show you how to create a new snapshot where JAVA is installed, which you can use in any future tasks.
- List the available images to you
- Use the OpenStack web interface
- Start a new instance of ubuntu 12.04 virtual machine
- Specify what KeyPair to use! It is under Access & Security TAB.
- use the one that you created in the last practical session. If you lose the file, you will have to create a new one!
- Specify what KeyPair to use! It is under Access & Security TAB.
- Log into the instance through ssh using the KeyPair
- ssh -i path_to_my_key_pair_file ubuntu@<instance public ip address>
- if you get an error, check that the path to the keyfile is correct and that it has correct rights (chmod 400 <filename>)
- Install Java JDK on the instance
- sudo aptitude search <name of the software>
- sudo aptitude install <name of the software>
- openjdk-7-jdk is a good choice
- Save the instance as a snapshot (Create Snapshot)
- When naming the snapshot, use your first and last name!
Exercise 9.2. Calculating PI in Java
- In this second exercise you will rewrite the calculating PI python script (Which you created in the exercise 1.3) in Java.
- If you did not take the basics of grid part, you can see the description of the exercise here
- It is suggested to use Eclipse IDE to write, debug, compile and run the program.
- The program has to print out the hostname of the machine!
- For example, use InetAddress.getLocalHost().getHostName()
Exercise 9.3. Running the PI Java program on an instance
- Start a new instance from the snapshot you created before.
- Export the Java code to the started instance
- if you use Eclipse, you can export the project as a runnable jar file, but be careful about the differences of Java versions in your machine and in cloud machine!
- Use scp to copy the .java file to the instance
- scp -i path_to_my_key_file myjavaprogram.java ubuntu@<instance public ip address>:
- Log into the machine through ssh
- Compile the Java program on the instance and run it
- javac myjavaprogram.java
- java myjavaprogram
- Save the output of your Java program in a text file
- Kill your running instance. Never leave your instances running once you are done with them!
Deliverables
- Snapshot created in the cloud with your name
- Java sourcecode (--1 point)
- Output of your java program stored in a text file.
- Has to include the hostname of the machine, when running the Java code inside your new instance!
- Do not leave your instances running! (-- 1 point)