Beispiel #1
0
 def __init__(self):
   webapp2.WSGIApplication.__init__(self, [('/', MainPage),
                                           ('/mydeck', DeckPage),
                                           ('/about', AboutPage),
                                           ('/addcard', AddCardPage),
                                           ('/deletecard', DeleteCardPage),
                                           ('/export', ExportDeckPage),
                                           ('/backend', BackendPage)],
                                           debug=True)
   try:
       get_url()
       logging.info('Starting backend')
       self.textProc = TextProcessor(getDataLoader())
   except InvalidBackendError:
       logging.info('Starting frontend')
Beispiel #2
0
def get_image(xmin, ymin, xsize, ysize, width, height):
    params = urllib.urlencode({
        'xmin': xmin,
        'ymin': ymin,
        'xsize': xsize,
        'ysize': ysize,
        'width': width,
        'height': height,
    })
    for i in range(3):  # Retries
        instance_id = hash(params) % NUM_BACKENDS
        url = urlparse.urljoin(
            backends.get_url('renderer', instance=instance_id),
            '/backend/render_tile?%s' % params)
        rpc = urlfetch.create_rpc(deadline=10.0)
        urlfetch.make_fetch_call(rpc, url)
        try:
            response = yield rpc
            if response.status_code not in (500, 0):
                break
        except (apiproxy_errors.DeadlineExceededError,
                urlfetch.DeadlineExceededError):
            pass
        logging.warn("Backend failed to render tile; retrying")
        # Wait a little before retrying
        time.sleep(0.2)
    assert response.status_code == 200, \
        "Expected status 200, got %s" % response.status_code
    raise tasklets.Return(response.content,
                          int(response.headers['X-Operation-Cost']))
Beispiel #3
0
 def post(self):
   logging.info('Received POST: %s', len(self.request.body))
   #data = simplejson.loads(self.request.body)
   userText = self.request.get('text')
   try:
       headers = { 'User-Agent' : 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)',
                   'Content-Type' : 'application/json' }
       values = {'text' : userText,
                 'word' : 1,
                 'definition' : 1,
                 'sentence' : 1 }
       logging.info('Received user text %d bytes', len(userText))
       #logging.debug('Received user text: %s', userText)
       data = simplejson.dumps(values)
       url = get_url(backend='sugoi-ideas') + '/backend'
       logging.info('send %d bytes text to %s', len(data), url)
       result = urlfetch.fetch(url=url,
                       payload=data,
                       method=urlfetch.POST,
                       headers={'Content-Type': 'application/json'},
                       deadline=8)
       logging.info('received %d byte text from BE', len(result.content))
       logging.info('received text from BE: %s', result.content[1:100])
       self.response.out.write(result.content)
   except Exception as ex:
       logging.error(str(ex))
       self.response.status = 502
       self.response.status_message = 'Time elapsed while processing the request'
Beispiel #4
0
def get_image(xmin, ymin, xsize, ysize, width, height):
  params = urllib.urlencode({
      'xmin': xmin,
      'ymin': ymin,
      'xsize': xsize,
      'ysize': ysize,
      'width': width,
      'height': height,
  })
  for i in range(3): # Retries
    instance_id = hash(params) % NUM_BACKENDS
    url = urlparse.urljoin(backends.get_url('renderer', instance=instance_id),
                           '/backend/render_tile?%s' % params)
    rpc = urlfetch.create_rpc(deadline=10.0)
    urlfetch.make_fetch_call(rpc, url)
    try:
      response = yield rpc
      if response.status_code not in (500, 0):
        break
    except (apiproxy_errors.DeadlineExceededError,
            urlfetch.DeadlineExceededError):
      pass
    logging.warn("Backend failed to render tile; retrying")
    # Wait a little before retrying
    time.sleep(0.2)
  assert response.status_code == 200, \
      "Expected status 200, got %s" % response.status_code
  raise tasklets.Return(
      response.content,
      int(response.headers['X-Operation-Cost']))
Beispiel #5
0
    def post(self):
        s = str(self.request.get('s'))
	try:
                payload='data'
		url = '%s/mega/tst' % backends.get_url('mega')
		urlfetch.fetch(url, method='POST', payload=payload)
	except Exception, e:
		pass
Beispiel #6
0
 def post(self):
     s = str(self.request.get('s'))
     try:
         payload = 'data'
         url = '%s/mega/tst' % backends.get_url('mega')
         urlfetch.fetch(url, method='POST', payload=payload)
     except Exception, e:
         pass
Beispiel #7
0
    def get(self):
        self.response.write("Hello world!\n")
        # r = requests.get('/_ah/start', auth=('user', 'pass'))
        # resp, content = httplib2.Http().request("/_ah/start")
        # r = self.request.get("/_ah/start")
        # self.response.write('alread sent a request to start the backend.\n')
        # self.response.write('response: [%s]'%(r))
        url = backends.get_url("backendthread") + "/backend"
        result = urlfetch.fetch(url)

        # taskqueue.add(url=url, target='backendthread')
        self.response.write("Response:%s" % (result.status_code))
Beispiel #8
0
    def get(self):
        self.response.write('Hello world!\n')
        #r = requests.get('/_ah/start', auth=('user', 'pass'))
        #resp, content = httplib2.Http().request("/_ah/start")
        #r = self.request.get("/_ah/start")
        #self.response.write('alread sent a request to start the backend.\n')
        #self.response.write('response: [%s]'%(r))
        url = backends.get_url('backendthread') + '/backend'
        result = urlfetch.fetch(url)

        #taskqueue.add(url=url, target='backendthread')
        self.response.write('Response:%s' % (result.status_code))
Beispiel #9
0
 def findGame(self, userID):
   # forward the request to the matcher backend
   url = '%s/find-game/%s' % (backends.get_url(backend='matcher', instance=None, protocol='HTTP'), userID)
   payload = '{}'
   resp = urlfetch.fetch(url=url,
                         payload=payload,
                         method=urlfetch.POST,
                         headers={'Content-Type': 'application/json'})
   self.response.set_status(resp.status_code)
   self.response.headers.update(resp.headers)
   self.response.write(resp.content)
   logging.info('%s -> %s -> %s' % (repr(payload), url, resp.content))
Beispiel #10
0
	def postBackendFlush(self):
		backendURL = backends.get_url(backend=_BACKEND_NAME, instance=None, protocol='HTTP')
		url = '%s/k/flush' % (backendURL)
			
		payload = "{}"
		#rpc = urlfetch.create_rpc()
		#urlfetch.make_fetch_call
		resp = urlfetch.fetch(url=url,
                          payload=payload,
                          method=urlfetch.POST,
						  deadline=60
                          #headers={'Content-Type': 'application/json'}
						  )
Beispiel #11
0
def _call_counter_method(method, name, delta='0'):
    """Call 'method' on the counter backend.

    Args:
      method: The method. One of 'inc', 'dec', 'get'.
      name: The counter to apply 'method' to.
      delta: The amount to increase/decrease the counter.

    Returns: An instance of urlfetch._URLFetchResult
    """
    payload = urllib.urlencode({'name': name, 'delta': delta})
    url = '%s/backend/counter/%s' % (backends.get_url('counter'), method)
    return urlfetch.fetch(url, method='POST', payload=payload)
Beispiel #12
0
def _call_counter_method(method, name, delta='0'):
    """Call 'method' on the counter backend.

    Args:
      method: The method. One of 'inc', 'dec', 'get'.
      name: The counter to apply 'method' to.
      delta: The amount to increase/decrease the counter.

    Returns: An instance of urlfetch._URLFetchResult
    """
    payload = urllib.urlencode({'name': name, 'delta': delta})
    url = '%s/backend/counter/%s' % (backends.get_url('counter'), method)
    return urlfetch.fetch(url, method='POST', payload=payload)
Beispiel #13
0
    def postBackendFlush(self):
        backendURL = backends.get_url(backend=_BACKEND_NAME,
                                      instance=None,
                                      protocol='HTTP')
        url = '%s/k/flush' % (backendURL)

        payload = "{}"
        #rpc = urlfetch.create_rpc()
        #urlfetch.make_fetch_call
        resp = urlfetch.fetch(url=url,
                              payload=payload,
                              method=urlfetch.POST,
                              deadline=60
                              #headers={'Content-Type': 'application/json'}
                              )
Beispiel #14
0
	def post(self,fcn):

		if(fcn == "add"):
			type = self.request.get('type',"unknown")
			name = self.request.get('name',"unknown")
			ip = self.request.remote_addr
			metadata = self.request.body
			backendURL = backends.get_url(backend=_BACKEND_NAME, instance=None, protocol='HTTP')
			url = '%s/k/add?type=%s&name=%s' % (backendURL, type,name)
			
			payload = metadata
			
			resp = urlfetch.fetch(url=url,
                          payload=payload,
                          method=urlfetch.POST,
						  deadline=60 #CLM is this OK practice?
                          #headers={'Content-Type': 'application/json'}
						  )
			self.response.set_status(resp.status_code)
			self.response.out.write(resp.content)
			logging.info('%s -> %s -> %s' % (repr(payload), url, resp.content))
Beispiel #15
0
	def post(self):
		qtype=cgi.escape(self.request.get('qtype'))
		if (qtype=='HTML'):
			self._print(cgi.escape(self.request.get('de_la')))
			self._print(cgi.escape(self.request.get('la')))
		elif (qtype=='JSON'):
			d={}
			d['de_la']=cgi.escape(self.request.get('de_la'))
			d['la']=cgi.escape(self.request.get('la'))
			self.response.out.write(json.dumps(d))
		elif (qtype=='Backend'):
			payload = urllib.urlencode({'de_la': cgi.escape(self.request.get('de_la')), 'la':cgi.escape(self.request.get('la'))})
			url = backends.get_url('primer') + '/backend/primer/mumu'
			self._print("Backend at "+url)
#			urlfetch.fetch(url, method='POST', payload=payload) # timesout
			q=taskqueue.Queue('MyQueue')
			q.purge()
			taskqueue.add(queue_name='MyQueue', url='/backend/primer/mumu',params=dict(de_la=cgi.escape(self.request.get('de_la')), la=cgi.escape(self.request.get('la')), transactional=False))
			qstats=q.fetch_statistics()
			self._print("{}: {} out of {} running tasks".format(qstats.queue,qstats.in_flight,qstats.tasks))
			self._print("Done!")
Beispiel #16
0
    def post(self, fcn):

        if (fcn == "add"):
            type = self.request.get('type', "unknown")
            name = self.request.get('name', "unknown")
            ip = self.request.remote_addr
            metadata = self.request.body
            backendURL = backends.get_url(backend=_BACKEND_NAME,
                                          instance=None,
                                          protocol='HTTP')
            url = '%s/k/add?type=%s&name=%s' % (backendURL, type, name)

            payload = metadata

            resp = urlfetch.fetch(
                url=url,
                payload=payload,
                method=urlfetch.POST,
                deadline=60  #CLM is this OK practice?
                #headers={'Content-Type': 'application/json'}
            )
            self.response.set_status(resp.status_code)
            self.response.out.write(resp.content)
            logging.info('%s -> %s -> %s' % (repr(payload), url, resp.content))
Beispiel #17
0
	def get(self):
		self.setVisInfo(self.request.remote_addr,self.user.nickname(),self.user.email())
		now=time.ctime(time.time())
		self._print('{} - Hello {} ({}) !'.format(now,self.user.nickname(),self.user.email()))
		self._hr()
		self._print("Your IP: "+self.request.remote_addr)
		self._print("Origin URL: "+self.request.url)
		self._print("uid: "+str(os.getuid()))
		self._print("pid: "+str(os.getpid()))
		self._print("cwd: "+os.getcwd())
		self._print(pl.system()+", "+pl.architecture()[0])
		self._print(pl.python_implementation()+", "+pl.python_version())
		self._print("Used mem: "+str(runtime.memory_usage().current())+" MB")
		self._print("Used mem last min: "+str(runtime.memory_usage().average1m())+" MB")
		self._print("CPU usage: "+str(runtime.cpu_usage().total())+" Mcycles")
		self._print("CPU usage last min: "+str(runtime.cpu_usage().rate1m())+" Mcycles")
		self._hr()
		self._form("/primez","de_la","la")
		self._hr()
		self.response.out.write("<a href='"+backends.get_url('primer')+"/backend/primer/mumu'>Primer</a>")
		self._hr()
		self.response.out.write("<a href='/logoff'>LogOut_1</a>")
		self._br()	
		self.response.out.write("<a href='"+users.create_logout_url("/")+"'>LogOut_2</a>")
#!/usr/bin/env python
#
# Copyright 2011 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# vim: set ts=4 sw=4 et tw=79:
"""The sample frontend that was shown in the backends talk."""

from google.appengine.api import backends
from google.appengine.api import urlfetch

url = '%s/backend/counter/inc' % (
        backends.get_url('counter'))

count = urlfetch.fetch(url, method='POST',
                       payload='name=visitor&delta=1').content

print 'Content-Type: text/plain'
print ''
print 'Welcome visitor %s' % count
Beispiel #19
0
class RunTask(webapp.RequestHandler):
    def post(self):
        if backends.get_backend() != "queue-issue" and settings.GOOGLE_APP_ENGINE_LIVE:
            logging.warn("Only the queue-issue backend can call /run_task/")
            return

        return self.response.out.write("OK")
# }}}

# init application {{{
application = webapp.WSGIApplication([
    ('/run_task/', RunTask), # login: admin
    ('/enqueue_tasks/', EnqueueTasks), # login: admin
], debug=True)

def main():
    run_wsgi_app(application)
# }}}

# init the events-logger backend {{{
if backends.get_backend() == "queue-issue":
    tools.debug("%s-backend" % backends.get_backend(), "%s-backend-initiated" % backends.get_backend(), \
            {"instance_id": backends.get_instance(), 
                "backend_instance_url": backends.get_url(instance=backends.get_instance()),
                "backend_load_balancer_url": backends.get_url()
            })
# }}}

if __name__ == '__main__':
    main()
Beispiel #20
0
def _backend_request(action, playlist_id, session_id, parameters):
    base_url = backends.get_url('playlist')
    action_url = ('%s/action/%s/%s/%s?%s' %
        (base_url, action, playlist_id, session_id, parameters))
    response = urlfetch.fetch(action_url, method=urlfetch.POST)
    return response.content
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.'''


from google.appengine.api import apiproxy_stub_map
from google.appengine.api import backends
from google.appengine.api import runtime

import datetime
import logging


_NAME = '{}.{} {} ({})'.format(backends.get_backend(),
                               backends.get_instance(),
                               backends.get_url(),
                               datetime.datetime.now())


def my_shutdown_hook():
  logging.warning('{} SHUTDOWN HOOK CALLED'.format(_NAME))
  apiproxy_stub_map.apiproxy.CancelApiCalls()
  # save_state()
  # May want to raise an exception

# register our shutdown hook, which is not guaranteed to be called
logging.info('{} REGISTERING SHUTDOWN HOOK'.format(_NAME))
runtime.set_shutdown_hook(my_shutdown_hook)
Beispiel #22
0
 def get(self):
   name = backends.get_url('backendone')
   self.response.write('Backend[%s]'%(name))
Beispiel #23
0
 def get(self):
   name = backends.get_url('backendone')
   logging.info('get resp ' + name+'/backend/summary_mail')
   respData = urlfetch.fetch(name+'/backend/summary_mail', method='POST')
   logging.info(respData.content)
Beispiel #24
0
	def get(self):
		if DEBUG: 
			taskqueue.add(url='/backends/update', method='GET')
		else:
			urlfetch.fetch(backends.get_url('update') + '/backends/update')
#!/usr/bin/env python
#
# Copyright 2011 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# vim: set ts=4 sw=4 et tw=79:

import random
from google.appengine.api import backends
from google.appengine.api import urlfetch

counters = ["counter-%d" % i for i in xrange(10)]

url = "%s/backend/counter/inc" % backends.get_url("counter")
while True:
    payload = "name=%s&delta=1" % random.choice(counters)
    urlfetch.fetch(url, method="POST", payload=payload)
#!/usr/bin/env python
#
# Copyright 2011 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# vim: set ts=4 sw=4 et tw=79:
"""The sample frontend that was shown in the backends talk."""

from google.appengine.api import backends
from google.appengine.api import urlfetch

url = '%s/backend/counter/inc' % (backends.get_url('counter'))

count = urlfetch.fetch(url, method='POST',
                       payload='name=visitor&delta=1').content

print 'Content-Type: text/plain'
print ''
print 'Welcome visitor %s' % count
Beispiel #27
0
 def inner(self, *args, **kwargs):
     if USE_BACKENDS and backends.get_backend() != BACKEND_NAME:
         return self.redirect(
             backends.get_url(BACKEND_NAME) + self.request.path_qs)
     return f(self, *args, **kwargs)
Beispiel #28
0
    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.'''

from google.appengine.api import apiproxy_stub_map
from google.appengine.api import backends
from google.appengine.api import runtime

import datetime
import logging

_NAME = '{}.{} {} ({})'.format(backends.get_backend(), backends.get_instance(),
                               backends.get_url(), datetime.datetime.now())


def my_shutdown_hook():
    logging.warning('{} SHUTDOWN HOOK CALLED'.format(_NAME))
    apiproxy_stub_map.apiproxy.CancelApiCalls()
    # save_state()
    # May want to raise an exception


# register our shutdown hook, which is not guaranteed to be called
logging.info('{} REGISTERING SHUTDOWN HOOK'.format(_NAME))
runtime.set_shutdown_hook(my_shutdown_hook)
Beispiel #29
0
from google.appengine.api import backends
from google.appengine.api import runtime
from google.appengine.api import users

from google.appengine.ext import webapp

from google.appengine.ext.webapp import template

import cgi
import datetime
import logging
import os
import urllib


my_name = '%s.%s (%s)' % (backends.get_backend(), backends.get_instance(), backends.get_url())


logging.info(my_name + ' is registering shutdown hook')


def my_shutdown_hook():
  logging.warning('shutdown hook called')
  apiproxy_stub_map.apiproxy.CancelApiCalls()
  # save_state()
  # May want to raise an exception

# register our shutdown hook, which is not guaranteed to be called
runtime.set_shutdown_hook(my_shutdown_hook)

Beispiel #30
0
 def inner(self, *args, **kwargs):
     if USE_BACKENDS and backends.get_backend() != BACKEND_NAME:
         return self.redirect(backends.get_url(BACKEND_NAME) + self.request.path_qs)
     return f(self, *args, **kwargs)