Sunday, February 27, 2011

When smartness of the word processors overtake you.. ;)

There were two times smart completion features have overtaken me. I was unable to expose the first experience, as it would violate someone else's privacy; so here comes the second experience. But this time a pretty boring one. :D

I was trying get a description of a load balancer I created. I have all the commands written down in a file. I opened it using a word processor and copied it to the terminal.

pradeeban@pradeeban:~/pem$ elb-describe-lbs autoscalelb –headers -K KEY.pem -C CERT.pem
elb-describe-lbs:  Service error: LoadBalancer name cannot contain characters that are not
 letters, or digits or the dash.
 AWSRequestId:6634cf73-423d-11e0-97ad-fd607d01edca

I was confused, where did I use an invalid character in the name (which was indeed just "autoscalelb"). After a few minutes, I figured out, it was my smart word processor, which had replaced "--headers" with "–headers" (Smart hyphenation!). :D

Sunday, February 20, 2011

Translating is a fun kinda thingyy!!! ;)

We all may have used Google Translate or Yahoo Babel Fish to translate a block of English text to Spanish or French once in a while. I always use a loop or a workflow during the translation to make sure that I omit most of the translator errors, as you can see any of the translators hasn't reached 100% correctness yet (not even near to that).
Let's take the requirement as a translation of a block of English text into Spanish. 

* Get the Spanish translation from the translator (English -> Spanish).
* Swap the mode of translator (to Spanish -> English), and get the English translation of the Spanish translation.
* If the English translation and the original text are similar (obviously they won't be identical), we are good to go. Let's use the Spanish translated text.
* If not, just extract the correctly translated block, and change the incorrectly translated one a bit and put it back to English -> Spanish translator and continue the loop till they become the same.

Some tips..
* It's better to use simple and complete English in translation to get it translated correct.
* Avoid, 'Will do', and use 'I will do' instead. Most probably 'Will do' will be translated wrong, though it is pretty obvious in English that 'Will do' is similar to 'I will do'.
* Avoid idioms, confusing phrases/words, and peacock words those have no value. Give it simple and straight.

Anyway technology and tools can never replace a cute and adorable human translator. After all, you know.. translating is a fun! :D

Thursday, February 17, 2011

[Pidgin] Error Reading blist.xml

Pidgin 2.7.10 (libpurple 2.7.10) in one of my computers (Ubuntu 10.04) stopped loading my accounts, with the error "Error Reading blist.xml - An error was encountered reading your buddy list.  The file has not been loaded, and the old file has been renamed to /home/pradeeban/.purple/blist.xml~." Basically it is unable to find the account, hence asking to configure new user accounts. I found both blist.xml and accounts.xml being corrupted in the .purple folder. The backup files themselves (accounts.xml~ and blist.xml~) were corrupted. 

I easily fixed the issue by replacing the corrupted account.xml and blist.xml with the same files from my other computer. This solved the issue. Obviously a smart and stupid fix at the same time! Can't bother fixing it in a professional manner, finding the root cause blah blah blah. During this fix, I also noticed that passwords are saved as plain text in the above two files (oops!). On a side note, I always am fond of reading my previous chat logs from .purple.. haha.. ;)

Tuesday, February 15, 2011

8 Crazy Twitter Rules!

I am not a rule maker or a big-guy to create rules for Twitter. But the following are a collection of my random tweets tagged as 'Twitter rules', which I tweeted from 6th of May, 2010 till late 2011. It doesn't mean, I complete with these 8. I will create more rules later.. :P

Twitter Rule #8: If you want your tweet to be retweeted, avoid ending it with #fb

Twitter Rule #7: Keep ur acc. open, unless u have a valid reason to keep it as a closed acc. #Twitter is supposed to be open unlike facebook

Twitter Rule #6: Use @ and # often and wisely. # (#hashtag) gets u wider audience through #search. @ helps u reach the correct @audience.

Twitter Rule #5 I often search for your pic for a tweet. So better do RT@ instead of retweeting.. ;) <- Profile picture as online identity.

Twitter Rule #4: Don't make your followers to search your profile for the Twitter Rule #3 you tweeted a looong time ago..

Twitter Rule #3: hu sed tweets or its rules shud b in proper Engliz? sometimes RULES r like thizz too. twitter zn't an offize item! jajaja..

Twitter Rule #2: Take a break between two tweets to make sure your tweets are read. Replies & RTs are exceptions.

Twitter Rule #1: Do NOT follow stars and politicians. Their tweets won't be useful to u, and they will never follow u or listen to ur tweets

[Rule8's explanation: Tweets those end with #fb tag will become a Facebook status for the "selective tweet (ST)" users. so those who use ST, can't retweet freely.]

Pls tolerate the sms-style-English. The rules are copied directly from my own twitter account, hence the 140 characters limit.

Snapbird is a great tool to search the tweets.

http://www.idfromuser.com/ is a service that lets you find the user id from the twitter user name. Twitter ID might be useful in many cases, like getting the feed url.

Tuesday, February 8, 2011

Auto Scaling With Amazon EC2 - II

We created an Amazon ELB as discussed here. Let's see more of it now.

Appserver
The load balancer we have created listens on the port 80 and 443 and forwards requests to 9763 and 9443. Say now we need to delete the listeners.

elb-delete-lb-listeners autoscalelb --lb-ports 80 443 -K KEY.pem -C CERT.pem  
    Warning: Deleting a LoadBalancer listener can lead to service disruption to
    any customers connected to the LoadBalancer listener. Are you sure you want
    to delete this LoadBalancer listener? [Ny]N
elb-delete-lb-listeners:  User stopped the execution of elb-delete-lb-listeners.
(Providing 'N' stops the action. You can proceed deleting the listener, by giving 'y' as the response.)

You can also create more listeners
elb-create-lb-listeners autoscalelb --headers --listener "lb-port=8280,instance-port=9763,protocol=http" --listener "lb-port=8243,instance-port=9443,protocol=tcp" -K KEY.pem -C CERT.pem
OK-Creating LoadBalancer Listener

The load balancer now listens on the port 8280 and 8243 and forwards requests to 9763 and 9443.

Now what will happen if you forcefully try to kill the instances initiated by the ELB? It will create one more identical instance immediately, handling the failover case.


Fail over
pradeeban@pradeeban:~/pem$ as-describe-auto-scaling-groups autoscleasg -K KEY.pem -C CERT.pem

Initially,
AUTO-SCALING-GROUP  autoscleasg  autoscalelc  us-east-1c  autoscalelb  1  10  1
INSTANCE  i-xxxxxxxx  us-east-1c  InService  Healthy  autoscalelc

When we killed the instance.
AUTO-SCALING-GROUP  autoscleasg  autoscalelc  us-east-1c  autoscalelb  1  10  1
INSTANCE  i-xxxxxxxx  us-east-1c  Terminating  Unhealthy  autoscalelc
INSTANCE  i-yyyyyyyy  us-east-1c  Pending      Healthy    autoscalelc

After a few seconds,
AUTO-SCALING-GROUP  autoscleasg  autoscalelc  us-east-1c  autoscalelb  1  10  1
INSTANCE  i-yyyyyyyy  us-east-1c  InService  Healthy  autoscalelc

Sounds cool.. So how to terminate the instances that ELB creates?


Shall we try deleting?
pradeeban@pradeeban:~/pem$ as-delete-auto-scaling-group autoscleasg -K KEY.pem -C CERT.pem

    Are you sure you want to delete this AutoScalingGroup? [Ny]y
as-delete-auto-scaling-group:  Service error: You cannot delete an AutoScalingGroup while there are instances
 still in the group.  AWSRequestId:aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaa


Min = Max = 0
ok! So let's stop auto-scaling process by setting the minimum and maximum to zero.

pradeeban@pradeeban:~/pem$ as-update-auto-scaling-group autoscleasg --min-size 0 --max-size 0 -K KEY.pem -C CERT.pem
OK-Updated AutoScalingGroup
pradeeban@pradeeban:~/pem$ as-describe-auto-scaling-groups autoscleasg -K KEY.pem -C CERT.pem
AUTO-SCALING-GROUP  autoscleasg  autoscalelc  us-east-1c  autoscalelb  0  0  0
INSTANCE  i-yyyyyyyy  us-east-1c  InService  Healthy  autoscalelc


Delete
Now let's try to delete the auto-scaling group once more -- yes, as we have set it to zero, it should be possible now.
pradeeban@pradeeban:~/pem$ as-delete-auto-scaling-group autoscleasg -K KEY.pem -C CERT.pem
  
    Are you sure you want to delete this AutoScalingGroup? [Ny]y
as-delete-auto-scaling-group:  Service error: You cannot delete an AutoScalingGroup while there are scaling activities in progress for that group.
 AWSRequestId:bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbb

oh.. Let's wait a minute for that scaling down activity to finish!
Again!
pradeeban@pradeeban:~/pem$ as-delete-auto-scaling-group autoscleasg -K KEY.pem -C CERT.pem
          
    Are you sure you want to delete this AutoScalingGroup? [Ny]y
OK-Deleted AutoScalingGroup



Done!
Now, let's check once more whether we have deleted it properly.. ;)
pradeeban@pradeeban:~/pem$ as-describe-auto-scaling-groups autoscleasg -K KEY.pem -C CERT.pem
No AutoScalingGroups found

Yes, we have deleted the Amazon ELB along with the scaling group of nodes it created.  (We are sinners! ;))

Saturday, February 5, 2011

I concluded, my computer is asexual (or engaged with something else).

Just noticed the following as a friend's facebook status update.
Is Your Computer a Boy or a Girl?

It’s pretty easy to find out what gender your computer is.

Follow the instructions.
.........
1) Open your notepad
2) Type or copy paste: CreateObject("SAPI.SpVoice").Speak"I love you"
3) Save as computer_sex.vbs
4) Run the file. (just double click)

If you hear a male voice, congratulations, you have a boy if woman’s, well, it’s a girl.

I have a baby boy :)

What about you?

So I opened my gedit editor, and copy-pasted, and saved it in the desktop of my Ubuntu machine, and double clicked it. Instead of *saying* anything, it just opened the file in another gedit window with the warning header,
"This file (/home/pradeeban/Desktop/computer_sex.vbs) is already open in another gedit window. gedit opened this instance of the file in a non-editable way. Do you want to edit it anyway?"

I concluded, my computer is asexual or engaged with some other stuff (already open in another.. ;)).

Wait; at least you could have mentioned the fact that your sex-trick works only on a windows machine.. :D

Tuesday, February 1, 2011

Auto Scaling With Amazon EC2

Creating an auto scaled system using an Amazon load balancer is an interesting task that I did recently. We have an Amazon EC2 image with WSO2 Application Server installed. Creating an image with WSO2 WSAS installed is described here

Amazon EC2 API Tools
You will need Amazon EC2 API tools to create the image yourself. You can install it using "sudo apt-get install ec2-api-tools" in debian based operating systems, or you can download it from Amazon S3. These tools provide a client interface to the Amazon EC2 web service, to register and launch instance and more.

Configure
pradeeban@pradeeban:~/Downloads$ ec2-run-instances -K KEY.pem  -C CERT.pem

Instance Details
You can get the instance details using the InstanceID i-xxxxxxxx you get above.

ec2-describe-instances -K KEY.pem -C CERT.pem  i-xxxxxxxx or get the details of all the instances by,
ec2-describe-instances -K KEY.pem -C CERT.pem

[Providing the relevant public key and cert, KEY.pem and CERT.pem.]


Load Balancing with Auto Scaling
Now we come to the interesting part. That is auto scaling the Amazon EC2 Image with the load.

Download and set up Elastic Load Balancing API tools
Download it here, extract, and set the path up appropriately.
export AWS_ELB_HOME=/home/pradeeban/program/ElasticLoadBalancing-1.0.11.1
export PATH=$PATH:$AWS_ELB_HOME/bin

ELB Quick Reference Card
Downloading and setting up Auto Scaling API tools
Download it here, extract, and set the path up appropriately.

export AWS_AUTO_SCALING_HOME=/home/pradeeban/programs/AutoScaling-1.0.33.1
export PATH=$PATH:$AWS_AUTO_SCALING_HOME/bin



Creating a Load Balancer
pradeeban@pradeeban:~/Downloads$ elb-create-lb  autoscalelb --headers --listener "lb-port=80,instance-port=9763,protocol=http" --listener "lb-port=443,instance-port=9443,protocol=tcp" --availability-zones us-east-1c -K KEY.pem -C CERT.pem
DNS_NAME  DNS_NAME
DNS_NAME  autoscalelb-1316227031.us-east-1.elb.amazonaws.com

Describe ELB
elb-describe-lbs autoscalelb -K KEY.pem -C CERT.pem
LOAD_BALANCER  autoscalelb  autoscalelb-1316227031.us-east-1.elb.amazonaws.com  2011-01-28T09:40:54.750Z

Register instances with the load balancer
elb-register-instances-with-lb autoscalelb --instances i-xxxxxxxx -K KEY.pem -C CERT.pemINSTANCE_ID  i-xxxxxxxx

Configuring a health check
pradeeban@pradeeban:~/Downloads$ elb-configure-healthcheck  autoscalelb --headers --target "TCP:9763" --interval 5 --timeout 3 --unhealthy-threshold 2 --healthy-threshold 2 -K KEY.pem -C CERT.pem
HEALTH_CHECK  TARGET    INTERVAL  TIMEOUT  HEALTHY_THRESHOLD  UNHEALTHY_THRESHOLD
HEALTH_CHECK  TCP:9763  5         3        2                  2


 
Creating an AutoScaled System

Launching configuration for Amazon EC2 framework to launch new Amazon instances.
pradeeban@pradeeban:~/Downloads$ as-create-launch-config autoscalelc --image-id ami-xxxxxxxx --instance-type m1.large -K KEY.pem -C CERT.pem
OK-Created launch config



You can choose the instance type (m1.small, m1.large, and m1.xlarge) based on the requirements.

Creating Auto Scaling Group
pradeeban@pradeeban:~/Downloads$ as-create-auto-scaling-group autoscleasg --availability-zones us-east-1c --launch-configuration autoscalelc --min-size 1 --max-size 10 --load-balancers autoscalelb -K KEY.pem -C CERT.pem
OK-Created AutoScalingGroup


Describe auto scaling groups
pradeeban@pradeeban:~/Downloads$ as-describe-auto-scaling-groups autoscleasg -K KEY.pem -C CERT.pem
AUTO-SCALING-GROUP  autoscleasg  autoscalelc  us-east-1c  autoscalelb  1  10  1


Configuring a trigger with start actions according to the load.
pradeeban@pradeeban:~/Downloads$ as-create-or-update-trigger autoscaletrigger --auto-scaling-group autoscleasg --namespace "AWS/ELB" --measure Latency --statistic Average --dimensions "LoadBalancerName=autoscalelb" --period 60 --lower-threshold 0.5 --upper-threshold 1.2 --lower-breach-increment=-1 --upper-breach-increment 1 --breach-duration 120 -K KEY.pem -C CERT.pem
DEPRECATED: This command is deprecated and included only to facilitate migration to the new trigger mechanism.  You should use this command for migration purposes only.
OK-Created/Updated trigger



measure
You can choose the measure, based on your auto-scaling requirements. Let it be CPUUtilization, Latency, or Load. You will have to choose this wisely based on the application types, let them be CPU-intense applications, or huge applications, or applications that consume too much time. 

Now you notice as-create-or-update-trigger is depreciated. You can use scale up and scale down policies, along with the cloud-watch tools as described below instead!


Amazon CloudWatch API Tools
Downloading and Setting up 
Download it here, extract, and set the path up appropriately, to monitor the AWS cloud resources.

export AWS_CLOUDWATCH_HOME=/home/pradeeban/programs/CloudWatch-1.0.9.5
export PATH=$PATH:$AWS_CLOUDWATCH_HOME/bin

Now we have to define the scale up and scale down policies on scaling up and down the system based on the load, along with the monitoring.

Scale-up Policy
pradeeban@pradeeban:~/pem$ as-put-scaling-policy MyScaleUpPolicy1 --auto-scaling-group autoscleasg1 --adjustment=1 --type ChangeInCapacity --cooldown 300 -K KEY.pem -C CERT.pem
arn:aws:autoscaling:us-east-1:xxxxxxxxxxxxxx:scalingPolicy:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx:autoScalingGroupName/autoscleasg1:policyName/MyScaleUpPolicy1

pradeeban@pradeeban:~/pem$ mon-put-metric-alarm MyHighCPUAlarm1 --comparison-operator GreaterThanThreshold --evaluation-periods 1 --metric-name CPUUtilization --namespace "AWS/EC2" --period 600 --statistic Average --threshold 80 --alarm-actions arn:aws:autoscaling:us-east-1:xxxxxxxxxxxxxx:scalingPolicy:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx:autoScalingGroupName/autoscleasg1:policyName/MyScaleUpPolicy1 --dimensions "AutoScalingGroupName=autoscleasg" -K KEY.pem -C CERT.pem
OK-Created Alarm

Scale Down Policy
pradeeban@pradeeban:~/pem$ as-put-scaling-policy MyScaleDownPolicy1 --auto-scaling-group autoscleasg1 --adjustment=-1 --type ChangeInCapacity --cooldown 300 -K KEY.pem -C CERT.pem
arn:aws:autoscaling:us-east-1:xxxxxxxxxxxxxx:scalingPolicy:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx:autoScalingGroupName/autoscleasg1:policyName/MyScaleDownPolicy1

pradeeban@pradeeban:~/pem$ mon-put-metric-alarm MyLowCPUAlarm --comparison-operator LessThanThreshold --evaluation-periods 1 --metric-name CPUUtilization --namespace "AWS/EC2" --period 600 --statistic Average --threshold 40 --alarm-actions arn:aws:autoscaling:us-east-1:xxxxxxxxxxxxxx:scalingPolicy:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx:autoScalingGroupName/autoscleasg1:policyName/MyScaleDownPolicy1 --dimensions "AutoScalingGroupName=autoscleasg" -K KEY.pem -C CERT.pem
OK-Created Alarm

Now the auto scaling group gets an instance, as the minimum number of instances in the auto scaled system has been set to 1,
pradeeban@pradeeban:~/Downloads$ as-describe-auto-scaling-groups autoscleasg -K KEY.pem -C CERT.pem
AUTO-SCALING-GROUP  autoscleasg  autoscalelc  us-east-1c  autoscalelb  1  10  1
INSTANCE  i-xxxxxxxx  us-east-1c  InService  Healthy  autoscalelc

Once the elastic load balancer is set fine and triggered, it starts new nodes or remove the existing nodes according to the load. Following these steps, the system can be load balanced with autoscaling.


Load Balanced Instances' Health
Initially,
pradeeban@pradeeban:~/pem$ elb-describe-instance-health autoscalelb –headers -K KEY.pem -C CERT.pem
INSTANCE_ID  INSTANCE_ID  STATE      DESCRIPTION  REASON-CODE
INSTANCE_ID  i-xxxxxxxx   InService  N/A          N/A

Later with the load, you may see at least a new instance.
pradeeban@pradeeban:~/pem$ elb-describe-instance-health autoscalelb –headers -K KEY.pem -C CERT.pem
INSTANCE_ID  INSTANCE_ID  STATE      DESCRIPTION  REASON-CODE
INSTANCE_ID  i-xxxxxxxx   InService  N/A          N/A
INSTANCE_ID  i-yyyyyyyy   InService  Active Instance

After a few failed attempts, an instance will be marked as 'OutOfService' with the reason, 'Instance has failed at least the UnhealthyThreshold number of health checks consecutively.' or so.