梦翔儿在今天着手研究自已第一个云计算application
我的第一个云计算程序-Google App Engine 打造简单留言本的攻略
下面一起进入历史性时刻吧:
首先在这里注册:http://code.google.com/intl/zh-CN/appengine/ 需要用到+86手机号,收短信注册
并创新一个应用:jcqgood
参考了:http://code.google.com/intl/zh-CN/appengine/docs/python/gettingstarted/
开始我们的云计算之旅游:
1.安装开发环境:
(1)下载最新的activepython 2.7,安装:http://downloads.activestate.com/ActivePython/releases/2.7.0.2/ActivePython-2.7.0.2-win32-x86.msi 教程是基于2.5的,经测2.7最新版可以通过
(2)Google App Engine SDK: http://googleappengine.googlecode.com/files/GoogleAppEngine-1.3.6.msi
2.执行Google App Engine Launcher Ctrl+N新建一个应用:
Application Name就是我们刚才注册的jcqgood 设置好目录E:\googleapp\jcqgood
修改或创建几个文件:
app.yaml:
-----------
application: jcqgood
version: 1
runtime: python
api_version: 1
handlers:
- url: /stylesheets
static_dir: stylesheets
- url: /.*
script: helloworld.py
---------
helloworld.py 可以右键选择python win来编辑,当然记事本也行,不过经测试目前还不支持中文!但外站链接是可以的。
-------
import cgi
from google.appengine.api import users
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.ext import db
class Greeting(db.Model):
author = db.UserProperty()
content = db.StringProperty(multiline=True)
date = db.DateTimeProperty(auto_now_add=True)
class MainPage(webapp.RequestHandler):
def get(self):
self.response.out.write('<html><body>')
greetings = db.GqlQuery("SELECT * FROM Greeting ORDER BY date DESC LIMIT 10")
for greeting in greetings:
if greeting.author:
self.response.out.write('<b>%s</b> wrote:' % greeting.author.nickname())
else:
self.response.out.write('An anonymous person wrote:')
self.response.out.write('<blockquote>%s</blockquote>' %
cgi.escape(greeting.content))
# Write the submission form and the footer of the page
self.response.out.write("""
<form action="/sign" method="post">
<div>This is my first cloud computing!My Blog:<a href="http://www.dreamflier.net" target="_blank">Go<a></div>
<div><textarea name="content" rows="3" cols="60"></textarea></div>
<div><input type="submit" value="Sign Guestbook"></div>
</form>
</body>
</html>""")
class Guestbook(webapp.RequestHandler):
def post(self):
greeting = Greeting()
if users.get_current_user():
greeting.author = users.get_current_user()
greeting.content = self.request.get('content')
greeting.put()
self.redirect('/')
application = webapp.WSGIApplication(
[('/', MainPage),
('/sign', Guestbook)],
debug=True)
def main():
run_wsgi_app(application)
if __name__ == "__main__":
main()
-------
index.htm
--------
<html>
<head>
<link type="text/css" rel="stylesheet" href="/stylesheets/main.css"
/>
</head>
<body>
{% for greeting in greetings %}
{% if greeting.author %}
<b>{{ greeting.author.nickname }}</b> wrote:
{% else %}
An anonymous person wrote:
{% endif %}
<blockquote>{{ greeting.content|escape }}</blockquote>
{% endfor %}
<form action="/sign" method="post">
<div><textarea name="content" rows="3"
cols="60"></textarea></div>
<div><input type="submit" value="Sign Guestbook"></div>
</form>
<a href="{{ url }}">{{ url_linktext }}</a>
</body>
</html>
------
stylesheets/main.css
----------
body {
font-family: Verdana, Helvetica, sans-serif;
background-color: #DDDDDD;
}
----------
以上几段代码都是google的入门教程里的。
3.Google App Engine Launcher 中选择Run
http://localhost:8080
就会出现:
Hello, webapp World!
4.Google App Engine Launcher 选择Deploy,输入注册的google邮箱和密码。
等一会儿,那个Deployment for Google,出现:You can close this window now.
看起来这个过程在创建三个replica以及索引过程:
----------以下是运行监控,可以不看,跳过:
2010-08-27 21:03:24 Running command: "['D:\\Python27\\python.exe', '-u', 'D:\\Program Files\\Google\\google_appengine\\appcfg.py', '--no_cookies', u'--email=jcqgood@gmail.com', '--passin', 'update', u'E:\\googleapp\\jcqgood']"
Application: jcqgood; version: 1.
Server: appengine.google.com.
Scanning files on local disk.
Initiating update.
Password for XXX#gmail.com: Cloning 2 static files.
Cloning 2 application files.
Uploading 1 files and blobs.
Uploaded 1 files and blobs
Deploying new version.
Checking if new version is ready to serve.
Will check again in 1 seconds.
Checking if new version is ready to serve.
Will check again in 2 seconds.
Checking if new version is ready to serve.
Will check again in 4 seconds.
Checking if new version is ready to serve.
Will check again in 8 seconds.
Checking if new version is ready to serve.
Closing update: new version is ready to start serving.
Uploading index definitions.
2010-08-27 21:04:38 (Process exited with code 0)
You can close this window now.
------
现在就可以通过:http://jcqgood.appspot.com/ 来访问云计算网站了。。。
哈哈!
原来也不难嘛。。。