ZK goes EC2 (Part 3)

The third part of the tutorial where I improve a few things. I will not walk through the complete code but highlight a few important points and give you the complete sourcecode at the end.

To recap, my requirements:

  • I want to allow users in my company to start and stop instances on their own without them login to AWS console.
  • Only specific instances are available to them.
  • Avoid using elastic IP’s (you pay for them if they are not assigned)
  • Make it configurable

The improvements in this version:

  • Remove the hardcoded access keys and place them encrypted in a properties file.
  • Only instances that are not protected can be started or stopped.
  • Update DynDNS entries from the application
  • Some cosmetic cleanup of the control panel

Continue reading

ZK goes EC2 (Part 2)

Part 1 of this tutorial we concluded with an web application that displays all our instances and their status. In this part we will add some more features to control our instances.

Prerequisites:

  • The project and environment from part 1

Tutorial (complete sourcecode at the end):

  • Display the region endpoints and allow to select different one
    We hardcoded our endpoint in the first version, if you run instances across the globe in the various AWS datacentres (US, Ireland, Singapore, Tokyo) we need to switch the endpoint easily.
    Lets add one more listbox, that we hide in a ZK popup (we could use a combo listbox, but for the sake of playing with all the available ZK components I use the popup). Same concept add a listbox in the zul and a EC2 region list and a list model with customer renderer in our controller. Continue reading

ZK goes EC2 (Part 1)

Certainly not a big deal to deploy a ZK web application to a Amazon EC2 instance, but I needed a simple application that allows my team to start/stop our EC2 instance that we use for testing and demo without logging into the AWS account or using the Firefox plugin (both giving too many rights and are too complex for some business users).
I created this app to give my users (tester and trainer) a chance to start the servers without logging into AWS. I share this because the are no samples in the SDK file that cover the EC2 instances in detail.

In part 1 of this tutorial we will create a ZK application that displays the status of our instances in a list.

In part 2 we will add the start-stop instance function, in part 3 we tinker with IP addresses and DynDNS domains and in part 4 we let our web application time scheduled (EJB Timer) control the instances automatically.

Pre-Requirements:

Tutorial Part 1:

Update DynDNS hosts with Java and HttpComponents

I was looking for a way to update the DynDNS hosts pointing to my EC2 instances that run only on demand (controlled by an web application). Yes, there are apps and tools to let the server itself update his DynDNS hosts, but I want to do it from a central application. The DynDNS API description you find here, unfortunately there are no samples. But if you familiar with REST calls, shouldn’t be a big issue. For those who to get running quick, here the key code. To experiment, just create a simple Java application with Netbeans (or any other IDE), download the HttpComponents from Apache and add the library files to your project.

Libraries

commons-codec-1.4.jar
commons-logging-1.1.1.jar
httpclient-4.1.1.jar
httpclient-cache-4.1.1.jar
httpcore-4.1.jar
httpmime-4.1.1.jar

Sourcecode to update an IP address

void updateDynDNS() {
...
// replace with your own data !
String hostName = "whateveryourdomainnameis.selfip.org";
String hostIP = "1.2.3.5";
String userName = "user";
String userPassword = "password";
int responseCode;

try {

// Encode username and password
BASE64Encoder enc = new sun.misc.BASE64Encoder();
String userpassword = userName + ":" + userPassword;
String encodedAuthorization = enc.encode(userpassword.getBytes());

// Connect to DynDNS
URL url = new URL("http://members.dyndns.org/nic/update?hostname=" + hostName + "&myip=" + hostIP);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.setRequestProperty("User-Agent", "Demo DynDNS Updater");
connection.setRequestProperty("Authorization", "Basic " + encodedAuthorization);

// Execute GET
responseCode = connection.getResponseCode();
System.out.println(responseCode + ":" + connection.getResponseMessage());

// Print feedback
String line;
InputStreamReader in = new InputStreamReader((InputStream) connection.getContent());
BufferedReader buff = new BufferedReader(in);
do {
line = buff.readLine();
System.out.println(line);
} while (line != null);

connection.disconnect();

} catch (Exception ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}

}
...

Up to you to embed into your application and do proper exception handling.

In a separate tutorial I will describe the basics of an EC2 controlling application using the AWS SDK for Java.

Android Samsung Galaxy Tab Alternative

I believe it makes no sense to buy a ~ 900.- SGD (3g, GPS), respectively a 500.- SGD (wifi only) device running Android 2.2 without any chance even to update to 2.3, such as the Galaxy Tab, the same time Galaxy is releasing already the new 3.0 based models. So how to find a cheap device that can compete with the Galaxy Tab ?
After buying one Android 10″ Tablet from DHGate.com without problems I decided to look for a second one, a 7″ device. Certainly not easy to find a good device among the many offers on the trading platform, but I was lucky enough to choose this PC-7006 1Ghz device for 223.- U$ (incl. shipping) from the dealer avatar2012:

Android MID 7"

Continue reading

Google released Android 3.0 SDK Preview

Finally we get a first hands-on experience with the latest version targeting the tablet market. All official info at here.

How to get it ? If you are running Eclipse and already develop for Android, no problem. Just open the SDK Manager and select the package:

Install honeycomb Preview

Create a new Virtual Device

Android Device

Create a  test application, start the emulator (which is significantly slower then the earlier Android versions!)

Honeycomp Test Application

Android Honeycomb Emulator

PS: I am still waiting for Android 2.3 for my Nexus One (supposed to be aired after a few weeks as of early December 2010). Instead we got a 2.2.2 fixing the SMS bug and others.

Google Android

I ordered the Google Android development phone today. I strongly believe in the open concept of hardware devices like the Pandora (link) or Sun Spot (link) other than iPhone or the MS XBOX as proprietary products  forcing you to join commercial membership and developer programs. I evaluate mobile devices in regards of business applications with RIA (aka REA) technology.

You need to join the Android Market Program (25 U$) in order to order the development phone for 399 U$ (shipment and duties to Singapore about 80 U$). The development unit is hardware unlocked, means you can make changes to the underlying OS and SIM-unlocked, to load with any SIM card.  The only other source for the phone is German T-Mobile, which offers the Android (SIM-, and hardware-locked) at a cheaper contract-lock-in price.

Google Android (copyright by android.brightstarcorp.com)

Google Android (copyright by android.brightstarcorp.com)

Some useful links:

  • The official Android Website (link)
  • The Dev Phone 1 specs (link)
  • SDK and Developer-Tools (link)
  • Youtube videos by the development team (link)
  • Netbeans plugin for Android Development (link)
  • Google Groups Beginner (link) and advanced developer (link)

Until the device arrives I will spend some time on getting started and using the SDK with Netbeans plugin.

Remark: Not sure if I also manage to get JavaFX running on the Android, we will see.

Update: Spending some time reading various documents and forums I understand the background. Android is executing Dalvik byte code (wiki-link) and as long JavaFX cannot be compiled as such, it wont run. Guess it is not a impossible task, waiting for someone to do it (rather a Android hardware manufacturers job to trigger it)