Viewing Data in AppScale (remote_api)

Chris Donati edited this page Mar 14, 2017 · 9 revisions

This document describes how to view data of your application in AppScale. AppScale uses the remote API shell in order to do this, so viewing data is actually just one of the many things that can be done. This feature is available as of 1.14.0. For more information see how to use the remote API shell in GAE here.

Application Requirements

Make sure that you have the remote_api builtins enabled in your app.yaml. Here is an example for the guestbook sample application:

application: guestbook
version: 1
runtime: python
api_version: 1
 
builtins:
- remote_api: on
 
handlers:
- url: /.*
  script: guestbook.py

If you are running a java application then you need to update your web.xml to contain the following in your web-app xml tags:

     <servlet>
        <display-name>Remote API Servlet</display-name>
        <servlet-name>RemoteApiServlet</servlet-name>
        <servlet-class>com.google.apphosting.utils.remoteapi.RemoteApiServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>RemoteApiServlet</servlet-name>
        <url-pattern>/_ah/remote_api</url-pattern>
    </servlet-mapping>

Connect to the Remote Shell

Log into an AppScale node. From where your AppScalefile is located you can do the following:

local# appscale ssh
appscale-image0# cd /root/appscale/AppServer/google/appengine/tools
appscale-image0# python remote_api_shell.py -s <head_node_ip>:<application_port>
# Log in as your AppScale user
app_id>

In Java

AppScale 2.1 and beyond has support for remote API on the Java client side. Use the appengine-remote-api.jar found in

appscale/AppServer_Java/appengine-java-sdk-repacked/lib/appengine-remote-api.jar

and replace the default on. This modified jar uses AppScale's authentication system, rather than Google's.

Add the following in your web.xml:

  <filter>
    <filter-name>_ah_DevSocketFilter</filter-name>
    <filter-class>
      com.google.appengine.api.socket.dev.DevSocketFilter
    </filter-class>
    <init-param>
      <param-name>use-native-sockets</param-name>
      <param-value>true</param-value>
    </init-param>
  </filter>

  <filter-mapping>
    <filter-name>_ah_DevSocketFilter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>

And then follow the directions given by Google here: https://cloud.google.com/appengine/docs/java/tools/remoteapi

Caveats

To query on certain entity kinds, the entity in question must be imported. You can import this into the shell directly, or import a file that has the Model definition. The following example explains this.

Example

root@appscale-image0:~/appscale/AppServer/google/appengine/tools# python remote_api_shell.py -s 192.168.33.10:8080
App Engine remote_api shell
Python 2.7.3 (default, Sep 26 2013, 20:03:06) 
[GCC 4.6.3]
The db, ndb, users, urlfetch, and memcache modules are imported.
guestbook27> class Greeting(ndb.Model):
...   author = ndb.UserProperty()
...   content = ndb.TextProperty()
...   date = ndb.DateTimeProperty(auto_now_add=True)
guestbook27> ndb.gql("SELECT * FROM Greeting")
Query(kind='Greeting', default_options=QueryOptions(offset=0))
guestbook27> query = ndb.gql("SELECT * FROM Greeting")
guestbook27> print query.fetch()
[Greeting(key=Key('Guestbook', 'default_guestbook', 'Greeting', 1), author=None, content=u'testtest', date=datetime.datetime(2014, 1, 22, 17, 21, 1, 13485))]
guestbook27> exit
Use exit() or Ctrl-D (i.e. EOF) to exit
guestbook27> exit()