add KeepDisk resource
authorTom Clegg <tom@clinicalfuture.com>
Thu, 25 Apr 2013 07:19:41 +0000 (00:19 -0700)
committerTom Clegg <tom@clinicalfuture.com>
Thu, 25 Apr 2013 07:21:30 +0000 (00:21 -0700)
12 files changed:
services/api/app/assets/javascripts/keep_disks.js.coffee [new file with mode: 0644]
services/api/app/assets/stylesheets/keep_disks.css.scss [new file with mode: 0644]
services/api/app/controllers/arvados/v1/keep_disks_controller.rb [new file with mode: 0644]
services/api/app/helpers/keep_disks_helper.rb [new file with mode: 0644]
services/api/app/models/keep_disk.rb [new file with mode: 0644]
services/api/config/routes.rb
services/api/db/migrate/20130425024459_create_keep_disks.rb [new file with mode: 0644]
services/api/db/schema.rb
services/api/test/fixtures/keep_disks.yml [new file with mode: 0644]
services/api/test/functional/keep_disks_controller_test.rb [new file with mode: 0644]
services/api/test/unit/helpers/keep_disks_helper_test.rb [new file with mode: 0644]
services/api/test/unit/keep_disk_test.rb [new file with mode: 0644]

diff --git a/services/api/app/assets/javascripts/keep_disks.js.coffee b/services/api/app/assets/javascripts/keep_disks.js.coffee
new file mode 100644 (file)
index 0000000..7615679
--- /dev/null
@@ -0,0 +1,3 @@
+# Place all the behaviors and hooks related to the matching controller here.
+# All this logic will automatically be available in application.js.
+# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
diff --git a/services/api/app/assets/stylesheets/keep_disks.css.scss b/services/api/app/assets/stylesheets/keep_disks.css.scss
new file mode 100644 (file)
index 0000000..1f7780b
--- /dev/null
@@ -0,0 +1,3 @@
+// Place all the styles related to the KeepDisks controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
diff --git a/services/api/app/controllers/arvados/v1/keep_disks_controller.rb b/services/api/app/controllers/arvados/v1/keep_disks_controller.rb
new file mode 100644 (file)
index 0000000..30ad035
--- /dev/null
@@ -0,0 +1,10 @@
+class Arvados::V1::KeepDisksController < ApplicationController
+  skip_before_filter :login_required, :only => :ping
+
+  def ping
+    @object.ping({ ip: params[:local_ipv4] || request.env['REMOTE_ADDR'],
+                   ping_secret: params[:ping_secret],
+                   ec2_instance_id: params[:instance_id] })
+    show
+  end
+end
diff --git a/services/api/app/helpers/keep_disks_helper.rb b/services/api/app/helpers/keep_disks_helper.rb
new file mode 100644 (file)
index 0000000..9cf6b4a
--- /dev/null
@@ -0,0 +1,2 @@
+module KeepDisksHelper
+end
diff --git a/services/api/app/models/keep_disk.rb b/services/api/app/models/keep_disk.rb
new file mode 100644 (file)
index 0000000..6ff6400
--- /dev/null
@@ -0,0 +1,47 @@
+class KeepDisk < ArvadosModel
+  include AssignUuid
+  include KindAndEtag
+  include CommonApiTemplate
+  before_validation :ensure_ping_secret
+
+  api_accessible :superuser, :extend => :common do |t|
+    t.add :node_uuid
+    t.add :filesystem_uuid
+    t.add :ping_secret
+    t.add :bytes_total
+    t.add :bytes_free
+    t.add :is_readable
+    t.add :is_writable
+    t.add :last_read_at
+    t.add :last_write_at
+    t.add :last_ping_at
+  end
+
+  def ping(o)
+    raise "must have :ip and :ping_secret" unless o[:ip] and o[:ping_secret]
+
+    if o[:ping_secret] != self.ping_secret
+      logger.info "Ping: secret mismatch: received \"#{o[:ping_secret]}\" != \"#{self.info[:ping_secret]}\""
+      return nil
+    end
+    self.last_ping_at = Time.now
+
+    @bypass_arvados_authorization = true
+
+    save!
+  end
+
+  protected
+
+  def ensure_ping_secret
+    self.ping_secret ||= rand(2**256).to_s(36)
+  end
+
+  def permission_to_update
+    @bypass_arvados_authorization or super
+  end
+
+  def permission_to_create
+    current_user and current_user.is_admin
+  end
+end
index 67f6a24646ac3664af4ebc5385629f1cd7367b25..c8d55df371205fd21ca20ded4dfeafb8a9ec24be 100644 (file)
@@ -1,8 +1,7 @@
 Server::Application.routes.draw do
+  resources :keep_disks
   resources :commit_ancestors
-
   resources :commits
-
   resources :job_tasks
   resources :jobs
   resources :api_client_authorizations
@@ -90,6 +89,7 @@ Server::Application.routes.draw do
       resources :users
       resources :jobs
       resources :job_tasks
+      resources :keep_disks
     end
   end
 
diff --git a/services/api/db/migrate/20130425024459_create_keep_disks.rb b/services/api/db/migrate/20130425024459_create_keep_disks.rb
new file mode 100644 (file)
index 0000000..7ad92c7
--- /dev/null
@@ -0,0 +1,27 @@
+class CreateKeepDisks < ActiveRecord::Migration
+  def change
+    create_table :keep_disks do |t|
+      t.string :uuid, :null => false
+      t.string :owner, :null => false
+      t.string :modified_by_client
+      t.string :modified_by_user
+      t.datetime :modified_at
+      t.string :ping_secret, :null => false
+      t.string :node_uuid
+      t.string :filesystem_uuid
+      t.integer :bytes_total
+      t.integer :bytes_free
+      t.boolean :is_readable, :null => false, :default => true
+      t.boolean :is_writable, :null => false, :default => true
+      t.datetime :last_read_at
+      t.datetime :last_write_at
+      t.datetime :last_ping_at
+
+      t.timestamps
+    end
+    add_index :keep_disks, :uuid, :unique => true
+    add_index :keep_disks, :filesystem_uuid
+    add_index :keep_disks, :node_uuid
+    add_index :keep_disks, :last_ping_at
+  end
+end
index f71fcaf354b638e2cec8e4a1b52e4e30c0f648ee..75b310366d5592a6df7452bc09a6dc94e0054612 100644 (file)
@@ -11,7 +11,7 @@
 #
 # It's strongly recommended to check this file into your version control system.
 
-ActiveRecord::Schema.define(:version => 20130415020241) do
+ActiveRecord::Schema.define(:version => 20130425024459) do
 
   create_table "api_client_authorizations", :force => true do |t|
     t.string   "api_token",               :null => false
@@ -165,6 +165,31 @@ ActiveRecord::Schema.define(:version => 20130415020241) do
   add_index "jobs", ["submit_id"], :name => "index_jobs_on_submit_id", :unique => true
   add_index "jobs", ["uuid"], :name => "index_jobs_on_uuid", :unique => true
 
+  create_table "keep_disks", :force => true do |t|
+    t.string   "uuid",                                 :null => false
+    t.string   "owner",                                :null => false
+    t.string   "modified_by_client"
+    t.string   "modified_by_user"
+    t.datetime "modified_at"
+    t.string   "ping_secret",                          :null => false
+    t.string   "node_uuid"
+    t.string   "filesystem_uuid"
+    t.integer  "bytes_total"
+    t.integer  "bytes_free"
+    t.boolean  "is_readable",        :default => true, :null => false
+    t.boolean  "is_writable",        :default => true, :null => false
+    t.datetime "last_read_at"
+    t.datetime "last_write_at"
+    t.datetime "last_ping_at"
+    t.datetime "created_at"
+    t.datetime "updated_at"
+  end
+
+  add_index "keep_disks", ["filesystem_uuid"], :name => "index_keep_disks_on_filesystem_uuid"
+  add_index "keep_disks", ["last_ping_at"], :name => "index_keep_disks_on_last_ping_at"
+  add_index "keep_disks", ["node_uuid"], :name => "index_keep_disks_on_node_uuid"
+  add_index "keep_disks", ["uuid"], :name => "index_keep_disks_on_uuid", :unique => true
+
   create_table "links", :force => true do |t|
     t.string   "uuid"
     t.string   "owner"
diff --git a/services/api/test/fixtures/keep_disks.yml b/services/api/test/fixtures/keep_disks.yml
new file mode 100644 (file)
index 0000000..c63aac0
--- /dev/null
@@ -0,0 +1,11 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
+
+# This model initially had no columns defined.  If you add columns to the
+# model remove the '{}' from the fixture names and add the columns immediately
+# below each fixture, per the syntax in the comments below
+#
+one: {}
+# column: value
+#
+two: {}
+#  column: value
diff --git a/services/api/test/functional/keep_disks_controller_test.rb b/services/api/test/functional/keep_disks_controller_test.rb
new file mode 100644 (file)
index 0000000..80795af
--- /dev/null
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class KeepDisksControllerTest < ActionController::TestCase
+  # test "the truth" do
+  #   assert true
+  # end
+end
diff --git a/services/api/test/unit/helpers/keep_disks_helper_test.rb b/services/api/test/unit/helpers/keep_disks_helper_test.rb
new file mode 100644 (file)
index 0000000..a3b064e
--- /dev/null
@@ -0,0 +1,4 @@
+require 'test_helper'
+
+class KeepDisksHelperTest < ActionView::TestCase
+end
diff --git a/services/api/test/unit/keep_disk_test.rb b/services/api/test/unit/keep_disk_test.rb
new file mode 100644 (file)
index 0000000..424c72b
--- /dev/null
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class KeepDiskTest < ActiveSupport::TestCase
+  # test "the truth" do
+  #   assert true
+  # end
+end