Sunday, February 15, 2009
programming the app server
I wish I had done this earlier. While doing the app server, I had to change where my web server was posting to. I would go into my code and just change the url in all of the six or so places every time I needed to change where it was posting to. I decided later that in my user-data script, I would create a python file that would basically return the app server url that the other files in the web server could call to get the url. I wish I had done this earlier rather than later.
Saturday, February 7, 2009
simpledb queries
here's a helpful page on how to do simpledb queries the right way.
http://docs.amazonwebservices.com/AmazonSimpleDB/latest/DeveloperGuide/index.html?UsingQuerySampleDataset.html
http://docs.amazonwebservices.com/AmazonSimpleDB/latest/DeveloperGuide/index.html?UsingQuerySampleDataset.html
Thursday, February 5, 2009
some lab 3 stuff
OK.
Lab 3 is not documented very well. I'll try to correct some things here:
in forming your json, on the appserver page, it has SINGLE QUOTES around the keys in the json. in using simplejson, this is not correct. simplejson will not interpret it correctly if they're not DOUBLE QUOTES.
here are a line on how to get things from s3:
sdb = boto.connect_sdb(KEY, SECRET KEY)
imageDomain = sdb.get_domain('picture')
items = sdb.query('picture', "['ratesort' < '" + nextratesort + "'] sort 'ratesort' desc", 11)
for key in items:
item = imageDomain.get_item(key)
what the query returns back seems to be a list of the keys into the domain. you can use these keys to get individual items out as i've done above.
Edit: I'm not sure exactly which ones of the values of the json need to have quotes around them, but i got a few errors because at least a few didn't have quotes, so I put quotes around all of mine to avoid the error.
Lab 3 is not documented very well. I'll try to correct some things here:
in forming your json, on the appserver page, it has SINGLE QUOTES around the keys in the json. in using simplejson, this is not correct. simplejson will not interpret it correctly if they're not DOUBLE QUOTES.
here are a line on how to get things from s3:
sdb = boto.connect_sdb(KEY, SECRET KEY)
imageDomain = sdb.get_domain('picture')
items = sdb.query('picture', "['ratesort' < '" + nextratesort + "'] sort 'ratesort' desc", 11)
for key in items:
item = imageDomain.get_item(key)
what the query returns back seems to be a list of the keys into the domain. you can use these keys to get individual items out as i've done above.
Edit: I'm not sure exactly which ones of the values of the json need to have quotes around them, but i got a few errors because at least a few didn't have quotes, so I put quotes around all of mine to avoid the error.
Wednesday, February 4, 2009
A couple of things about project three
I know that one of the domains to access simpledb is "pictures" (case matters).
Here's some code that
sdb = boto.connect_sdb(ACCESS KEY, SECRET ACCESS KEY) # these keys may or may not be necessary... i saw some examples iwth them and some without them.
imageDomain = sdb.get_domain('picture')
with this, you can loop over all the keys in the domain and get information out.
Here's some code that
sdb = boto.connect_sdb(ACCESS KEY, SECRET ACCESS KEY) # these keys may or may not be necessary... i saw some examples iwth them and some without them.
imageDomain = sdb.get_domain('picture')
with this, you can loop over all the keys in the domain and get information out.
Tuesday, February 3, 2009
fix to the load balancer registration
I found out that my ami had to register itself automatically with the load balancer.
Basically, I found a web site that would tell me my public ip address, did a curl -s on this web site to get the response back, pipe that into grep and save that to a file. i do the same thing with ifconfig (the first the that comes back should be the private ip of the ami). i load these as strings into my program and do a wget on the address to register with the load balancer. my lines in my program look something like this:
os.system("curl -s http://www.ipaddress.org | egrep -m1 -o \'[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\' > /tmp/publicip.out")
then i load in the first line of /tmp/publicip.out into a variable in the program, concat that onto the end of a string and wget the loadbalancer url with that.
Basically, I found a web site that would tell me my public ip address, did a curl -s on this web site to get the response back, pipe that into grep and save that to a file. i do the same thing with ifconfig (the first the that comes back should be the private ip of the ami). i load these as strings into my program and do a wget on the address to register with the load balancer. my lines in my program look something like this:
os.system("curl -s http://www.ipaddress.org | egrep -m1 -o \'[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\' > /tmp/publicip.out")
then i load in the first line of /tmp/publicip.out into a variable in the program, concat that onto the end of a string and wget the loadbalancer url with that.
finding the public and private ip addresses
To find the public ip address, i took the number from the dns name, removed teh dashes adn inserted '.'s. ec2-75-101-229-61.compute-1.amazonaws.com became 75.101.229.61. to find the private ip address, i logged onto the box and typed ifconfig. the first address that looked like an ip address was my private ip address. mine started iwth a 10.
curl for the /submit file
I couldn't get the web server to work with urllib, and neither could I get it to work with pycurl. I kept on getting an invalid arguments error back from the server.
First, no matter what I did, I had to save my file to the server by using the following line of code:
open(randomimagename, 'wb').write(f['image'].file.read())
People that want to use pycurl should be able to send a response to teh server by using the following code. However, this code did not work on my server and will need to be changed in order to get it to work:
However, this approach did not work for me. I ended up just making a system call to the curl command. This command works about the same way. Here's what I did:
import os;
os.system('curl -ivvv -X POST -F submituser=DavidW -F description=coolness -F
tags=foo -F image=@yellow_corvette.jpg
http://imaj-app.lddi.org:8010/submitimage')
Of course, things may need to be changed in this line to make it work for the actual server, but I was able to change the variables and customize them to get tehm to work for my specific case.
First, no matter what I did, I had to save my file to the server by using the following line of code:
open(randomimagename, 'wb').write(f['image'].file.read())
People that want to use pycurl should be able to send a response to teh server by using the following code. However, this code did not work on my server and will need to be changed in order to get it to work:
import pycurl
pf = [('submituser', f['submituser']), ('tags', f['tags']), ('description', f['description']), ('image', (pycurl.FORM_FILE, randomimagename)) ]
c = pycurl.Curl()
c.setopt(c.URL, "http://www.python.org/")
c.setopt(c.POST, 1)
c.setopt(c.HTTPPOST
c.perform()
c.close()
You can get the response from pycurl by using the following code:
import StringIO
b = StringIO.StringIO()
c.setopt(pycurl.WRITEFUNCTION, b.write)
This code goes before you make the perform() call.
This line goes after you make the perform() call.
print b.getvalue()
However, this approach did not work for me. I ended up just making a system call to the curl command. This command works about the same way. Here's what I did:
import os;
os.system('curl -ivvv -X POST -F submituser=DavidW -F description=coolness -F
tags=foo -F image=@yellow_corvette.jpg
http://imaj-app.lddi.org:8010/submitimage')
Of course, things may need to be changed in this line to make it work for the actual server, but I was able to change the variables and customize them to get tehm to work for my specific case.
Monday, February 2, 2009
$('imagerater') is not a function
I got this error because I didn't include the .js files in the file. if you download these and make sure to include these, it'll work
another problem that i ran into was that my mod_python handler was not serving these with the default-handler. i needed to add the following lines in my http.conf file:
<Files *.js>
SetHandler default-handler
</Files>
another problem that i ran into was that my mod_python handler was not serving these with the default-handler. i needed to add the following lines in my http.conf file:
<Files *.js>
SetHandler default-handler
</Files>
second project
I've come up with a problem during the second project. whenever i try to use submitimage, it doesn't work. it gives me an invalidarguments error back whenever i try to use it. i have no clue why this happens. however, i consulted with a fellow class mate and he let me try his code on my server, but it doesn't help the problem even though he says that his code works. it's kind of a weird problem.
i had ap roblem that i fixed. i got it because i didn't copy over the .js files from the ta web site.
i had ap roblem that i fixed. i got it because i didn't copy over the .js files from the ta web site.
Subscribe to:
Posts (Atom)