~nchohan/appscale/zk3.3.4

« back to all changes in this revision

Viewing changes to AppController/lib/datastore_repo_on_app_engine.rb

  • Committer: Chris Bunch
  • Date: 2012-02-26 03:20:57 UTC
  • Revision ID: cgb@cs.ucsb.edu-20120226032057-ad0cy0zgx4we4exc
adding in repo over app engine support, and tests for most of datastore repo on appscale and s3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Programmer: Chris Bunch
 
2
 
 
3
 
 
4
require 'datastore_repo'
 
5
 
 
6
$:.unshift File.join(File.dirname(__FILE__), "..", "..", "Neptune")
 
7
require 'task_engine_google_app_engine'
 
8
 
 
9
 
 
10
# An implementation of the Repository app that assumes it is running
 
11
# within App Engine. Since App Engine is a remote service, we have to check
 
12
# to see if it's running or not, and upload it when it's not running.
 
13
class DatastoreRepoOnAppEngine < DatastoreRepo
 
14
 
 
15
  
 
16
  # The host (IP, colon, port) that the Repo app is hosted at.
 
17
  attr_accessor :host
 
18
 
 
19
 
 
20
  # The name of this datastore, which we call AppDB since Neptune jobs
 
21
  # basically use it as an interface to AppScale's database agnostic
 
22
  # layer.
 
23
  NAME = "repo-appengine"
 
24
 
 
25
  
 
26
  # Creates a new connection to the Repo running on Google App Engine.
 
27
  # Deployments take a non-trivial amount of time and can often be avoided, so
 
28
  # see if our app is running on App Engine before trying to re-upload it.
 
29
  def initialize(credentials)
 
30
    if credentials.class != Hash
 
31
      raise BadConfigurationException.new("Credentials was not a Hash")
 
32
    end
 
33
 
 
34
    if credentials['@appid'].nil?
 
35
      raise BadConfigurationException.new("No @appid was provided")
 
36
    end
 
37
 
 
38
    if credentials['@appcfg_cookies'].nil?
 
39
      raise BadConfigurationException.new("No @appcfg_cookies was provided")
 
40
    end
 
41
 
 
42
    appid = credentials['@appid']
 
43
    @host = "#{appid}.appspot.com"
 
44
 
 
45
    if !is_app_running?()
 
46
      app_location = "/root/appscale/AppServer/demos/therepo/"
 
47
      TaskEngineGoogleAppEngine.upload_app(credentials, app_location)
 
48
    end
 
49
  end
 
50
 
 
51
 
 
52
  # Sees if the Repo application is running at the @host we've set for it.
 
53
  def is_app_running?()
 
54
    result = do_http_get_for_get("/any-path", "any-type")
 
55
    if result
 
56
      Djinn.log_debug("App appears to be running")
 
57
      return true
 
58
    else
 
59
      Djinn.log_debug("App isn't running")
 
60
      return false
 
61
    end
 
62
  end
 
63
 
 
64
 
 
65
end