In this lab we will implement an ESB Mule project and deploy it on Amazon EC2 cloud. We will use multiple bus to integrate all the applications in the cloud.
The currency converter is a free webservice provided by www.webservicex.net (http://www.webservicex.net/currencyconvertor.asmx) that calculates the conversion rate from one currency to another currency. We are interesting on receiving notification when the exchange rate increases or variates based on a certain threshold/criteria. To achieve this, we will need to develop a component that invokes the service and detect when the exchange rate value is updated, if the new value is above our defined threshold the component will deliver a message with the exchange rate information to the local bus on a certain topic, and on two topics of an external bus using pub/sub messaging model. The external bus will contain all the topics and message produced by each students, receiving only messages when a interesting variation on the exchange rate occurs.
Local Bus:
topic : userdefined
External Bus (JMS provider):
brokerURL : tcp://184.73.173.127:61616 (available)
topic : currencyNews (in this topic all the students will produce messages)
topic : studentLastName
Defining our Service Component
The main component will contain the following inbound:
<inbound-endpoint address="http://www.webservicex.net/currencyconvertor.asmx/ConversionRate?FromCurrency=EUR&ToCurrency=PYG" connector-ref="PollingHttpConnector" transformer-refs="ToString XMLStringToCurrency" >
Here we are invoking the service using http GET request. In this example we are specifying that we are interested on getting the exchange rate from Euros to Guaranies. You are free to choose the currency you are more interesting on. In the inbound is also specified a polling-connector for http. This connector makes frequency request to the service, you can increase or decrease the polling frequency by changing the value on pollingFrequency.
<http:polling-connector name="PollingHttpConnector" pollingFrequency="5000" reuseAddress="true" />
The transformers we are using are:
<custom-transformer name="XMLStringToCurrency" class="rss.local.XMLStringToCurrency"/>
<object-to-string-transformer name="ToString"/>
The XMLStringToCurrency transform the string returned form the external service to a defined Currency class. You can also use XSLT in combination with XMLDecoder and XMLToObject if you want to uses standard xml transfomers.
After the data is transformed to our new data type, we send the message to a component that will set the variation value on the message and update the historical info (using global vars). For example, we can just save the latest value on the global var and check the variation with respect to the new incoming message. Finally the filter will decide to send the message or not based on the threshold defined.
For running your application on Amazon EC2, you have two options:
Option 1) You create an amazon ec2 account and you will get 100 US$ of credits. You only need a credit card to register (it could be a pre-pay card). With this option you will be able to use Amazon Web Console Tools in order to manage Amazon EC2 using a web browser.
Option 2) You can use an account that i have already setup, by using the certificate and keys that i will provide you. You will not be able to use the web console, instead you will manage your instances through the ec2 api tools.
If you go for the option 1, ask for the credit bonus.
Go to http://www.amazon.com
Create an Amazon Account
Go to http://aws.amazon.com :
Account->Account Activity Complete the form
Account-> Amazon EC2 console -> Sign Up For Amazon EC2 (you will need a credit card to register, could be a pre-pay credit card)
Add the credit coupon to your account:
Account->Payment Method: At the button of the page click on Redeem/View AWS Credits
Go to Account->Security Credentials
Create a new Certificate, download and store your private key and certificate
Go to Account->Security Groups
Create a new Security Group and set up the firewall rules for that group
Take into account that the instance that we will run uses the following ports: 80 (ssh), 8080(httpd), 8161 (activemq), 61616(activemq)
Launch an AMI instances
Go to Amazon EC2 Console->AMIs
Search for AMI-ID : ami-6120c908 (This AMI has Mule Server with ActiveMQ)
Launch the AMI. Save the new private key because you will need for connecting to the AMI
In this option, we do not have access to amazon web console, so we will manage our amazon ec2 by using the client API that interfaces AWS.
1) Download the Amazon EC2 Api Tools
http://developer.amazonwebservices.com/connect/entry.jspa?externalID=351&categoryID=251
2) Set up the variable environments
Note: New keys have been set up !
Get the keys and certificates form the svn repository: https://project-icebar.net/svn/trento/bpm/2010/group1-keys.zip
EC2_CERT= path/to/certificate/cert-#####.pem
EC2_HOME=path/to/ec2ApiTools
EC2_PRIVATE_KEY=path/to/privatekey/pk-####.pem
Add the bin directory of the EC2 API to the path.
3) Instance an Amazon AMI using the Command Line Tools
PLEASE terminate your instance after you finish working with it.
Run a new the instance. The first parameter is the AMI and the second is the keypair we will use.
> ec2-run-instances ami-6120c908 -k esb
The output should be similar to:
RESERVATION r-f25e64d2 999988564377 default
INSTANCE i-63765208 ami-0b2ec762 pending mule 0 m1.small 2010-05-17T08:01:36+0000 us-east-1a aki-94c527fd ari-96c527ff monitoring-disabled ebs
Write down the instance id which is in the second column. In this example is i-63765208
Note that your instance will be running in the cloud until we explicity terminate the instance. For terminating an instance, type the following command:
> ec2-terminate-instances <instance_id>
Example: ec2-terminate-instances i-10a64379
Proxy Problems
If you are having problem with the proxy, pass the proxy parameter to the JVM by setting the EC2_JVM_ARGS var. Science-wifi network uses proxy.science.unitn.it, while Unitn network uses proxy.unitn.it
Example using proxy.science.unitn.it
set EC2_JVM_ARGS=-DproxySet=true -DproxyHost=proxy.science.unitn.it -DproxyPort=3128 -Dhttps.proxySet=true -Dhttps.proxyHost=proxy.science.unitn.it -Dhttps.proxyPort=3128
Proxies
Unitn Network : proxy.unitn.it
science-wifi : proxy.science.unitn.it
2) Display the status of your instance
> ec2-describe-instances i-63765208
We should get something similar to:
RESERVATION r-f25e6f9a 999988887777 default
INSTANCE i-63765208 ami-0b2ec762 ec2-67-202-28-13.compute-1.amazonaws.com domU-12-31-39-00-78-93.compute-1.internal running gsg-keypair 0 m1.small 2010-03-30T08:01:36+0000 us-east-1a aki-94c527fd ari-96c527ff monitoring-disabled 67.202.28.13 10.254.127.97 ebs
BLOCKDEVICE /dev/sda1 vol-cf13b3a6 2010-03-30T08:01:44.000Z
The first DNS name is the external/public DNS for the instance. There might be a short time before it is accessible over the network
After a few minutes you should be able to see your instance at:
http://PUBLIC_DNS:8080
More info:
Amazon EC2: http://aws.amazon.com/ec2/
Amazon Elastic Compute Cloud User Guide: http://docs.amazonwebservices.com/AWSEC2/latest/UserGuide/index.html
Proxy problems: Set JVM parameters to use proxy for http and https
set EC2_JVM_ARGS=-DproxySet=true -DproxyHost=proxypac.unitn.it -DproxyPort=3128 -Dhttps.proxySet=true -Dhttps.proxyHost=proxypac.unitn.it -Dhttps.proxyPort=3128 -Dhttp.proxyUser=proxyuser-Dhttp.proxyPass=secret -Dhttps.proxyUser=proxyuser-Dhttps.proxyPass=secret
* SSH server is listening on port 80
* Apache httpd server is listening on port 8080
* Mule server is on /opt
* ActiveMQ server is on /opt
We need to provide the private key for loging into our instance. Here is a description how to do it in Linux and Windows.
Linux: ssh -p 80 -i <private-key-file.pem> root@PUBLIC_DNS:80
Windows (with putty):
* Open PUTTYgen (for transforming the private-key in the putty format)
Load an existing private key => my-private-key.pem
Save private key => my-private-key.ppk
* Load the private-key (my-private-ke.ppk):
Go to Connection->SSH->Auth and load the private key
Go to Session Enter the host Name (public dns of the instance) and change the port to 80
Open the connection and log in as root
If you prefer to connect your instance using FileZilla, here is a tutorial of how to autenticate using the private key with filezilla + putty
http://wiki.filezilla-project.org/Howto
For running our application in the ami instance, we need to copy our files into the instance.
Using SCP with private-key autentication
Linux
Make sure that the key cannot be accesible by others:
# chmod 600 <private_key.pem>
# scp -P <port> -i <private_key> <src_file> <root@AMI_PUBLIC_DNS:/path/to/folder>
Exmple
scp -i mule.pem muleProject.jar root@ec2-174-129-148-162.compute-1.amazonaws.com:/opt/Mule/mule-standalone-2.2.1/lib/user
Windows
Copy files using SCP from Windows (with putty)
1) Download the windows putty installer: http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html
2) Add the putty directory containing PSCP to your PATH environment variable. Example: set PATH=C:\path\to\putty\directory;%PATH%
3) From your windows console run the pscp command for copying files. The only different is that we use the private key in a format that putty can read, you can make the transformation using Puttygen. In this example i have already made it. The files is esb.ppk
> pscp -P <port> -i <private-key in ppk format>
Example:
> pscp -P 80 -i C:\Users\Alejandro\Desktop\AWSkeys\esb.ppk C:\Mule\output\rssBroker.jar root@ec2-204-236-221-138.compute-1-.amazonaws.com:/opt/Mule/mule-standalone-2.2.1/lib/user
Because the proxy does not allow to make ssh connections, we will use the icebar server which can be accesible inside the network and has a public ip. We will setup ssh tunnel for accesing all the services we need of our instances such as SSH, ActiveMQ administrator console, and the jms provider service (broker url).
The guide for setting up the tunnel on Windows/Linux is in the repository: https://project-icebar.net/svn/trento/bpm/2010/Creating-a-SSH-tunnel.pdf
Homework
Finish the exercise and let your application running in the cloud.