Sunday, September 28, 2008
JQuery and MonoRail
I took this opportunity because, Ayende (http://ayende.com/blog/) released some code on the Castle project mailing list as well as being added to the Trunk that helps people who prefer JQuery as one of their Javascript library. Ayende shared a JQueryGenerator class and a JQueryElementGenerator class.
Side Note to avoid conflicts with other javascript libraries add this to you layout template wrapped in the script tag:
<script type="text/javascript">
{
var jQuery = jQuery.noConflict();
});
</script>
I starting using them and created a few personal Unit test classes to test them. These test classes at the moment do not have full coverage, but they are a start.
When targeting the .Net 2.0 framework I ran into an issue with JSGeneratorDispatcher when it called a the hide method on JSQueryGenerator class. The resolution ended up being to add a params attribute to the method signature of methods that have an array in the signature. (Important: This is now patched in the trunk)
For example changing:
public override void Hide(string[] ids)
{
SelectRelevantElements(ids);
CodeGenerator.Write(".hide();");
}
To:
public override void Hide(params string[] ids)
{
SelectRelevantElements(ids);
CodeGenerator.Write(".hide();");
}
Steps to use JQuery in MonoRail
I recommend:
1) Either commenting out the other javascript libraries referenced in your layout view, or adding an alias for JQuery and wrap this in script tag.
<script type="text/javascript">
{
var jQuery = jQuery.noConflict();
});
</script>
2) Add JQuery to you layout:
<script type="text/javascript" src="$siteroot/content/js/jquery-1.2.6.js"> </script>
3) Use the latest Monorail source code from the Trunk, to take advantage of Javascript Generation using JQuery as you default.
Update global.asax.cs , add :
using Castle.MonoRail.Framework.JSGeneration;
using Castle.MonoRail.Framework.JSGeneration.jQuery;
also add method To Your Global.asax:
public void Configure(IMonoRailConfiguration config)
{
config.JSGeneratorConfiguration.AddLibrary("jquery-1.2.6", typeof(JQueryGenerator))
.AddExtension(typeof(CommonJSExtension))
.SetAsDefault();
}
3) Create yourself a helper class for JQuery to make it easier to create Ajax calls, etc. via JQuery.
Thursday, August 28, 2008
Cloud Computing: Setup Postgresql to use Amazon Elastic Block Store (EBS)
Cloud Computing: Setup Postgresql to use Amazon Elastic Block Store (EBS)
Prerequisites: Familiar with creating and launching instances using Amazon EC2, and familiar with editing config files in linux. Also make sure that Postgresql is installed on your instance, see installation steps at http://endurotracker.blogspot.com .
Overview
We will follow the same initial steps as outlined on Amazon’s developer website ( http://developer.amazonwebservices.com ). The latter steps will be specific to Postgresql.
1) Creating an Amazon EBS Volume
In this example, the user calls the CreateVolume API, specifying an 10 GB volume.
$ ec2-create-volume --size 10 --availability-zone us-east-1a
VOLUME vol-4d826724 858993459200 creating 2008-02-14T00:00:00+0000
$ ec2-describe-volumes vol-4d826724
VOLUME vol-4d826724 858993459200 available 2008-02-14T00:00:00+0000
2) Attach the Amazon EBS Volume to an Instance
In this example, the user calls the AttachVolume API to attach the volume vol-4d826724 to the instance i-6058a509 and expose it as the device /dev/sdh.
$ ec2-attach-volume vol-4d826724 -i i-6058a509 -d /dev/sdh
ATTACHMENT vol-4d826724 i-6058a509 /dev/sdh attaching 2008-02-14T00:
3) Describing Volumes and Instances
After creating Amazon EBS volumes and attaching them to instances, you can list them using the DescribeVolumes and the DescribeInstances functions.
To list all volumes owned by the user, including their status, the user invokes the DescribeVolumes function.
$ ec2-describe-volumes
VOLUME vol-4d826724 858993459200 in-use 2008-02-14T00:
ATTACHMENT vol-4d826724 i-6058a509 /dev/sdh attached 2008-02-14T00:
VOLUME vol-50957039 13958643712 available 2008-02-091T00:
VOLUME vol-6682670f 1073741824 in-use 2008-02-11T12:
ATTACHMENT vol-6682670f i-69a54000 /dev/sdh attached 2008-02-11T13:56:00+0000
The function returns the volume ID, capacity, status (in-use or available) and creation time of each volume. If the volume is attached, an attachment line shows the volume ID, the instance ID to which the volume is attached, the device name exposed to the instance, its status (attaching, attached, detaching, detached) and when it was attached.
The user can also view volumes that are attached to running instances by using the DescribeInstances function.
$ ec2-describe-instances
RESERVATION r-e112fc88 416161254515 default
INSTANCE i-3b887c52 ami-3fd13456 ec2-67-202-27-216.compute-1.amazonaws.com domU-12-31-38-00-35-94.compute-1.internalrunning gsg-keypair 0 m1.small 2007-11-26T13:
RESERVATION r-e612fc8f 416161254515 default
INSTANCE i-21b63c22 ami-3fd13456 ec2-67-202-18-227.compute-1.amazonaws.com domU-12-31-38-00-39-28.compute-1.internalrunning gsg-keypair 0 m1.small 2007-11-26T13:
4) Create ext3 filesystem on persistence volume (Amazon EBS) and mount the volume
Command line: yes | mkfs -t ext3 /dev/sdh
Command line: mkdir /mnt/pgsql
Command Line: mount /dev/sdh /mnt/pgsql
5) Stop Postgresql if it is already running on your instance
Cmd line: service postgresql stop
6) Copy postgresql folders to /mnt/pgsql
On Fedora 8, the folder is /var/lib/pgsql, copy the contents of the folder to /mnt/pgsql.
7) Change the owner of /mnt/pgsql to postgres user, and initial db cluster
Command line: chown –R postgres /mnt/pgsql
su –postgres
initdb –D /mnt/pgsql/data
8) Edit postgresql startup script and change all entries from /var/lib/pgsql to /mnt/pgsql
command line: vi /etc/rc.d/init.d/postgresql
9) Configure postgres for local access (see previous postgres setup post) (you will need to edit /mnt/pgsql/data/pg_hba.conf and /mnt/pgsql/data/postgresql.conf)
command line: service postgresql start
10) Enjoy !
Wednesday, August 27, 2008
DB Cloud Computing: Postgresql Setup on Amazon EC2 using Fedora 8
Postgresql Setup on Amazon EC2 using Fedora 8
Prerequisites: Familiar with creating and launching instances using Amazon EC2, and familiar with editing config files in linux.
Links to documentation on Amazon EC2 and how to create and launch instances:
http://developer.amazonwebservices.com/connect/kbcategory.jspa?categoryID=84
click on Technical documentation link.
Thanks goes to this article: http://www.postgresonline.com/journal/index.php?/archives/45-An-Almost-Idiots-Guide-to-PostgreSQL-YUM.html
There are some things missing from that article that I have addressed here.
1) Create Ami instance from pre-existing instance and launch instance.
Use ami-0abe5a63 for example, see url: http://www.nonhostile.com/mono-on-amazon-ec2.asp
url: http://developer.amazonwebservices.com/connect/entry.jspa?externalID=1616&categoryID=101
2) Logon to your instance using an SSH client (in windows you can use Putty)
3) Login as root
4) Edit /etc/yum/pluginconf.d/fastestmirror.conf and add to the end: exclude=postgresql*
(differs from the instructions at http://yum.pgsqlrpms.org/howtoyum.php to prevent your YUM update from getting postgresql from other sources)
5) Select the appropriate repository config file for your OS and choose 8.3 from here and navigating thru: http://yum.pgsqlrpms.org/reporpms/repoview/letter_p.group.htmlNote the install file - should look something like http://yum.pgsqlrpms.org/reporpms/8.3/pgdg-fedora-8.3-4.noarch.rpm
6) Do a wget of the appropriate one: e.g.
wget http://yum.pgsqlrpms.org/reporpms/8.3/pgdg-fedora-8.3-4.noarch.rpm
7) Next install the rpm config file with:
rpm -ivh pgdg-fedora-8.4-1.noarch.rpm
8) Install the things that you want. These are the ones we tend to install
yum install postgresqlyum install postgresql-serveryum install postgisyum install pgadmin3 Note:On Fedora 8, postgresql default location is /var/lib/pgsql/data
9) Create a user postgres
Add command prompt : useradd postgres
10) Set new user’s password
Add command prompt: passwd postgres
11) Initialize postgreSql
At command prompt:
chown postgres /var/lib/pgsql/data
su postgres
initdb –D /var/lib/pgsql/data
12) Configure postgresql for local access
From command line ( start up vi and add the 2 entries):
vi /var/lib/pgsql/data/pg_hba.conf- add:local all all trusthost all all 127.0.0.1 255.255.255.255 trusthost all all 0.0.0.0 255.255.255.255 reject
13) To configure remote access, from command line, pass in range of external ips to allow access to:
vi /var/lib/pgsql/data/postgresql.conf
listen_addresses = ‘*’
vi /var/lib/pgsql/data/pg_hba.conf
host all all [start ip range] [end ip range] trust
14) Assuming you have the AMI tools installed on your desktop, from the command line authorize the default port of 5432, by doing the following:
c:\amitools\ec2-authorize default –p 5432
Note: Now you can use the Postgres Admin UI Tools (pgAdmin III) from the machines that you granted remote access to. PgAdmin III allows you to administer Postgresql via a GUI. You can get this tool by installing Postgresql on your Windows desktop(s). I recommend this since it makes administration much easier.
15) Restart Postgresql, from command line (logged in as root):
service postgresql restart
16) Create a db if you like, from command line:
su – postgres
createdb db_name
17) Create a postgresql username with password for new db.
From command line: (-U postgres , means username postgres)
createuser –P –U postgres
18) Restart postgresql
19) Test your connection
login as root, then from command line:
psql –U db_username db_name
Cloud Computing: Mono Setup on Amazon EC2
Mono Setup on Amazon EC2 with optional config for MonoRail
Prerequisites: Familiar with create and launching instances using Amazon EC2, and familiar with editing config files in linux.
Links to documentation on Amazon EC2 and how to create and launch instances:
http://developer.amazonwebservices.com/connect/kbcategory.jspa?categoryID=84
click on Technical documentation link.
For porting application to Mono see article:
http://www.mono-project.com/Guide:_Porting_ASP.NET_Applications
1) Create Ami instance from pre-existing instance and launch instance.
Use ami-0abe5a63, see url: http://www.nonhostile.com/mono-on-amazon-ec2.asp
url: http://developer.amazonwebservices.com/connect/entry.jspa?externalID=1616&categoryID=101
2) Update Apache on this instance. This instance is a Fedora 8 image with Apache
Edit /etc/httpd/conf/httpd.conf
Add these entries to the end to use test app from mono:
MonoServerPath default /opt/mono-1.9.1/bin/mod-mono-server2
Alias / “/opt/mono-1.9.1/lib/xsp/test”
AddMonoApplications default “/:/opt/mono-1.9.1/lib/xsp/test”
<Location /> MonoSetServerAlias default SetHandler mono <Location /> Here is other entry example (notice using MonoApplications instead of AddMonoApplications) (not sure why examples differ), but both syntax work: Alias hellomonoweb “/opt/mono-1.9.1/lib/xsp/hellomonoweb” MonoApplications “/hellomonoweb:/opt/mono-1.9.1/lib/xsp/hellomonoweb” <Location /> SetHandler mono </Location> Important to disable case sensitivity for files and file paths add this entry. This prevents issues like file not found due to differences between Linux and Windows handling of case sensitivity for files and file paths: MonoSetEnv MONO_IOMAP=all 3) Optionally, if you are using MonoRail, a .Net implementation of Ruby on Rails ( see castleproject.org), add the following entry to /etc/httpd/conf.d/mod_mono.conf: AddType applications/x-asp-net .rails