Apache Click on Google App Engine – Hello World Example

Posted by admin | Posted in Cloud Computing, General Programming | Posted on 19-02-2010

1

Hello World!
If this blog would run on App Engine and was build with Apache Click I could finish this tutorial right here :) .
But more seriously, I will describe short step by step tutorial on how to get started with Apache Click on Google App Engine.
I’m assuming that you have GAE plugin for eclipse installed already as well as the latest libraries for Apache Click downloaded somewhere on your machine. (If not look at my previous post on how to get started with Apache Click on Eclipse Galileo (here).

If all is set up, lets get started..

1. Add new GAE type ‘Web Application Project’ (the one with blue google icon)

2. Copy click-2.1.0.jar and click-extras-2.1.0.jar to the lib directory under war/WEB-INF/lib of your GAE project.

3. Click on the project and select ‘Properties’ when you will modify the ‘Java Build Path’.

When changing the build path, select the two libraries you have added to you lib folder in point 2.

4. Delete the auto-generated GAE project stuff, like servlet and index.html files.
5. Create new class called ‘Index’

package com.softwarepassion.clickgae;

import java.util.Date;
import org.apache.click.Page;

public class Index extends Page{
   
    private Date time = new Date();

    public Index() {
        addModel("time", time);
    }

}

Note the package you choose for you newly created class file, it will be needed when modifying config files later.

6. Create click.xml file in the same location where your web.xml file exists.
7. Modify your web.xml file to look similar to the one presented below:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <listener>
         <listener-class>org.apache.click.extras.gae.GoogleAppEngineListener</listener-class>
  </listener>
  <servlet>
    <servlet-name>ClickServlet</servlet-name>
    <servlet-class>org.apache.click.ClickServlet</servlet-class>
    <load-on-startup>0</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>ClickServlet</servlet-name>
    <url-pattern>*.htm</url-pattern>
  </servlet-mapping>
  <welcome-file-list>
    <welcome-file>index.htm</welcome-file>
  </welcome-file-list>
</web-app>

It looks like ordinary web.xml file with one important addition: the listener section.

8. Add content to your click.xml file:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<click-app charset="UTF-8">
  <pages>
    <page path="index.htm" classname="com.softwarepassion.clickgae.Index"></page>
  </pages>
  <mode value="development"/>
</click-app>

9. Add index.htm file to the war directory

<html>
  <body>

    <h2>Hello World</h2>

    Hello world from Click at $time

  </body>
</html>

10. Deploy your app to Google App Engine and go to the url: http://yourappname.appspot.com

You should see very simple website with current time printed.

Top 10 Things to Know About Amazon RDS

Posted by admin | Posted in Cloud Computing | Posted on 22-11-2009

0

amazon_rds_10_things_to_know
Top 10 Things to Know About Amazon RDS


Top 10 Things to Know About Amazon RDS

Launching your EC2 instances with AWS Management Console

Posted by admin | Posted in Cloud Computing | Posted on 29-04-2009

1

How easy this can get, when I was starting with Amazon Web Services the things were looking kind of scary but right now we have bunch of tools to help us using the amazon EC2 instances so easy that I just cannot belive that. I knew that AWS Management console existed for quite a bit now but never actually gave it a try. Today I will do just that, I have some experience with EC2 and I’m running constantly one server on it for over a half a year now but I guess this tutorial would be no brainer and you don’t have to have any knowledge or experience to start your own instances.
First of all, of course, I assume that you are already signed up for EC2. If not you can do that by visiting this link.
Once you have an account go to the console web application which you can find here. When you log in you should see a screen similar to this one:

amazon aws console

Next, click on the ‘Amazon EC2′ tab and you should see a dashboard describing your running instances and resources.

amazon aws console dashboard

If you are here, and all went well, we are ready to move forward.
Click on the big yellowish button called ‘Launch instances’ in the middle of the screen to start the journey into the cloud. Here you get a box with three tabs where you can look for specific instances you are interested in. You can choose between ‘Quick Start’ listing a few example AMIs, select your own instances created earlier (see my post on backup up the whole EC2 image), or simply search for already created community AMIs. We will choose the last option and search for ‘ubuntu’ but its really your choice and here the fun begins. I have choosen Debian 5.0 Lenny base install image but you can choose whatever you want. Its worth to have a look at the following site where you can browse AMIs, see a bit more information about them than on the AWS Management Console and see the discussion about them.
After you’ve decided which server you want to have, click ’select’. If you didn’t have any keypairs created earlier you would have to add at least one to be able to launch your instance.
Select number of instances you want to run (we choose ‘1′ for now), your keypair and security group on the following screen:

launch ec2 instance

Hit ‘Launch’, you will see the following screen if all went ok:

ec2 launched from AWS console

Close the window and go to your instances list by clicking ‘Instances’ on the left vertical menu.

capture6

From here you can reboot and shut down your instances.

But wait, the best part is still to come, when you are on your console ‘Overview’ tab, you can see the ‘Coming Soon’ part describing upcoming functionalites for AWS Console, those include:

  • Monitoring, Load balancing and auto scaling
  • SQS support
  • S3 Support
  • CloudFront Support
  • SimpleDB Support

Amazon AWS services are becoming more and more interesting and if you haven’t already done so, I assure you that its worth checking out.

How to backup your entire server from EC2 to S3

Posted by admin | Posted in Cloud Computing | Posted on 07-04-2009

4

Today I will describe in short how to create an AMI instance of EC2 and than upload it to S3 server. All you need to have is running instance of EC2 server (I’m using Debian) with EC2 tools preinstalled.
First of all, make sure that you don’t have any unnecessary files on your server filesystem which you don’t need to bundle in an image as it will only slow the process down and make your costs of storing backup images higher.
Once you are sure that your instance is fine and EC2 tools are in place you have to transfer your private key file and certificate file to the server. Lets put the files under /root directory.
If all is set up correctly, first of all, we create and image by running:

ec2-bundle-vol -d /mnt -k /root/PrivateKey.pem  --cert /root/Certificate.pem  -u 012345678901

The number after the -u flag is your Amazon account ID which you can find on the AWS website once logged in.
Running above command will take a bit and will create a number of files under /mnt directory.
Once we have the files and manifest ready (all happens auto-magically) we can start transferring the image onto S3 account.
In order to transfer your image on S3 you would have to create a bucket there first, for this you can use famous firefox plugin (S3 Organizer) or do it using Affirma’s library (previous post).

ec2-upload-bundle -b yourbucketname00404042009 -m /mnt/image.manifest.xml -a your_s3_access_key -s your_s3_secret_access_key

If for some reason you encouter any problems during upload but your bundling went ok, you can retry the upload using –retry flag:

ec2-upload-bundle -b yourbucketname00404042009 -m /mnt/image.manifest.xml -a your_s3_access_key -s your_s3_secret_access_key  --retry

Happy bundling!

Affirma S3 library for C#

Posted by admin | Posted in Cloud Computing, General Programming, Tools | Posted on 06-04-2009

0

Finally I have found S3 library that works in C#. The library was written by Joel Wetzel from Affirma Consulting and I just wanted to spread the word about it.
Once downloaded you are presented with the whole C# Visual Studio solution which contains the library project as well as some example on how to use it.
There is even a simple wrapper written which greatly simplyfies the use of the affirma’s library.
As an example:
1. Create wrapper object (constructor listed)

public ThreeSharpWrapper(String awsAccessKeyId, String awsSecretAccessKey)
        {
            this.config = new ThreeSharpConfig();
            this.config.AwsAccessKeyID = awsAccessKeyId;
            this.config.AwsSecretAccessKey = awsSecretAccessKey;

            this.service = new ThreeSharpQuery(this.config);
        }

and then use it having the following methods:

/// Adds a bucket to an S3 account
public void AddBucket(String bucketName);

 /// Returns a string of XML, describing the contents of a bucket
public String ListBucket(String bucketName);

/// Adds a string to a bucket, as an object
public void AddStringObject(String bucketName, String keyName, String data);

/// Streams a file to a bucket as an object
public void AddFileObject(String bucketName, String keyName, String localfile);

/// Streams a file to a bucket as an object, with encryption
public void AddEncryptFileObject(String bucketName, String keyName, String localfile, String encryptionKey, String encryptionIV);

/// Gets a string object from a bucket, and returns it as a String
public String GetStringObject(String bucketName, String keyName);

/// Gets a file object from a bucket, and streams it to disk
public void GetFileObject(String bucketName, String keyName, String localfile);

/// Gets a file object from a bucket, streaming it to disk, with decryption
public void GetDecryptFileObject(String bucketName, String keyName, String localfile, String encryptionKey, String encryptionIV);

/// Copies an object from a source location to a destination location
public void CopyObject(String sourceBucketName, String sourceKey, String destinationBucketName, String destinationKey);

/// Generates a URL to access an S3 object in a bucket
public String GetUrl(String bucketName, String keyName);

/// Deletes an object from a bucket
public void DeleteObject(String bucketName, String keyName);

/// Deletes a bucket from an S3 account
public void DeleteBucket(String bucketName);

/// Changes the request payer value for the specified bucket
public String PaymentChange(String bucketName, PaymentChangeRequest.Payer payer);

/// Gets the request payer value for the specified bucket
public String PaymentGet(String bucketName);

The library is dead easy to use and most importantly it works (comparing to other S3 libraries I’ve found). Great work Joel!
You can download the solution zip from here or directly from the codeplex hosting the project here

Spreading the word: Amazon Web Services.

Posted by admin | Posted in Cloud Computing | Posted on 03-09-2007

0

I’m slowly starting my third year of university and slowly preparing for my final year project. A few days ago, when doing some research on what to do exactly for my FYP I have found accidentally web page describing AWS. I have seen it before on other blogs here and there but actually never checked it out!
Simply, this is great, well, could be better, and by saying better I mean free :) but still, it’s great.
I didn’t have a chance to try them all but the one, which I think is the most popular, called S3 which stands for Simple Storage Service, is really good one!
You pay for almost everything but in my opinion the service is really really cheap even for a student like me! You have to pay for transfers in and out, for storage and for simple requests like LIST, DELETE etc. but for example 1000 of them cost 0.01$ which is really nice. Best of all, no setup fees, no fixed costs, it’s pure pay as you go service!

I will write here a very simple step by step tutorial on how to set everything up for S3 just to show more or less how simple it is but actually better and much more detailed tutorial is available on amazon web site. You can have a look at small video tutorial prepared by brightcove.com @ http://www.brightcove.com/title.jsp?title=769277068&channel=770166766

To get started you would need:
1. Good will
2. Some files to transfer
3. Credit card
4. Little time
5. Client application for managing your files somehow.

This tutorial will be very short as I will skip the first 4 steps :) .
After you register for any of the services on amazon web site you can have a look at tutorials and developer resources. There is a wide choice of languages and api’s to choose from and many examples on how to use them. I had a look at Java ones and I have to say that even writing your own client with a little programming experience cannot be difficult.
Of course you can write the client yourself to make the most of the amazon web services with your appication but for the purpose of this tutorial you can simply use firefox plugin and transfer your files in a simple way over http to or from the amazon servers.
You can find the plugin at: https://addons.mozilla.org/en-US/firefox/addon/3247
Install the plugin and restart firefox. When you are registered, amazon will send you an email with links to the web site with your special set of keys which you have to use to connect to your service. Enter this keys into the box after clicking ‘Manage Accounts’ button on your left hand side and you are ready to go!

For more details especially about the code examples and api’s check the amazon web site!
Highly recommended!
PS. I will get back to you if I realize that I have not read the terms carefully and I will have to pay for it more than I expect ;)