From a3ff0b5978de5820ce35c237f583b9671068e38f Mon Sep 17 00:00:00 2001 From: Tom Clegg Date: Sun, 3 Feb 2013 03:30:33 -0800 Subject: [PATCH] add Job and JobStep resources --- app/assets/javascripts/job_steps.js.coffee | 3 ++ app/assets/javascripts/jobs.js.coffee | 3 ++ app/assets/stylesheets/job_steps.css.scss | 3 ++ app/assets/stylesheets/jobs.css.scss | 3 ++ .../orvos/v1/job_steps_controller.rb | 2 + app/controllers/orvos/v1/jobs_controller.rb | 2 + app/helpers/job_steps_helper.rb | 2 + app/helpers/jobs_helper.rb | 2 + app/models/job.rb | 36 +++++++++++++ app/models/job_step.rb | 8 +++ config/routes.rb | 5 +- db/migrate/20130203104818_create_jobs.rb | 31 +++++++++++ db/migrate/20130203104824_create_job_steps.rb | 23 ++++++++ db/schema.rb | 52 ++++++++++++++++++- test/fixtures/job_steps.yml | 11 ++++ test/fixtures/jobs.yml | 11 ++++ test/functional/job_steps_controller_test.rb | 7 +++ test/functional/jobs_controller_test.rb | 7 +++ test/unit/helpers/job_steps_helper_test.rb | 4 ++ test/unit/helpers/jobs_helper_test.rb | 4 ++ test/unit/job_step_test.rb | 7 +++ test/unit/job_test.rb | 7 +++ 22 files changed, 231 insertions(+), 2 deletions(-) create mode 100644 app/assets/javascripts/job_steps.js.coffee create mode 100644 app/assets/javascripts/jobs.js.coffee create mode 100644 app/assets/stylesheets/job_steps.css.scss create mode 100644 app/assets/stylesheets/jobs.css.scss create mode 100644 app/controllers/orvos/v1/job_steps_controller.rb create mode 100644 app/controllers/orvos/v1/jobs_controller.rb create mode 100644 app/helpers/job_steps_helper.rb create mode 100644 app/helpers/jobs_helper.rb create mode 100644 app/models/job.rb create mode 100644 app/models/job_step.rb create mode 100644 db/migrate/20130203104818_create_jobs.rb create mode 100644 db/migrate/20130203104824_create_job_steps.rb create mode 100644 test/fixtures/job_steps.yml create mode 100644 test/fixtures/jobs.yml create mode 100644 test/functional/job_steps_controller_test.rb create mode 100644 test/functional/jobs_controller_test.rb create mode 100644 test/unit/helpers/job_steps_helper_test.rb create mode 100644 test/unit/helpers/jobs_helper_test.rb create mode 100644 test/unit/job_step_test.rb create mode 100644 test/unit/job_test.rb diff --git a/app/assets/javascripts/job_steps.js.coffee b/app/assets/javascripts/job_steps.js.coffee new file mode 100644 index 0000000000..761567942f --- /dev/null +++ b/app/assets/javascripts/job_steps.js.coffee @@ -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/app/assets/javascripts/jobs.js.coffee b/app/assets/javascripts/jobs.js.coffee new file mode 100644 index 0000000000..761567942f --- /dev/null +++ b/app/assets/javascripts/jobs.js.coffee @@ -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/app/assets/stylesheets/job_steps.css.scss b/app/assets/stylesheets/job_steps.css.scss new file mode 100644 index 0000000000..9c2639b7ea --- /dev/null +++ b/app/assets/stylesheets/job_steps.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the JobSteps controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/jobs.css.scss b/app/assets/stylesheets/jobs.css.scss new file mode 100644 index 0000000000..e485745b3f --- /dev/null +++ b/app/assets/stylesheets/jobs.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Jobs controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/orvos/v1/job_steps_controller.rb b/app/controllers/orvos/v1/job_steps_controller.rb new file mode 100644 index 0000000000..6d177f35e9 --- /dev/null +++ b/app/controllers/orvos/v1/job_steps_controller.rb @@ -0,0 +1,2 @@ +class Orvos::V1::JobStepsController < ApplicationController +end diff --git a/app/controllers/orvos/v1/jobs_controller.rb b/app/controllers/orvos/v1/jobs_controller.rb new file mode 100644 index 0000000000..33425eb5d5 --- /dev/null +++ b/app/controllers/orvos/v1/jobs_controller.rb @@ -0,0 +1,2 @@ +class Orvos::V1::JobsController < ApplicationController +end diff --git a/app/helpers/job_steps_helper.rb b/app/helpers/job_steps_helper.rb new file mode 100644 index 0000000000..47ff614e6c --- /dev/null +++ b/app/helpers/job_steps_helper.rb @@ -0,0 +1,2 @@ +module JobStepsHelper +end diff --git a/app/helpers/jobs_helper.rb b/app/helpers/jobs_helper.rb new file mode 100644 index 0000000000..44c7bf621c --- /dev/null +++ b/app/helpers/jobs_helper.rb @@ -0,0 +1,2 @@ +module JobsHelper +end diff --git a/app/models/job.rb b/app/models/job.rb new file mode 100644 index 0000000000..a4b0d1ce2d --- /dev/null +++ b/app/models/job.rb @@ -0,0 +1,36 @@ +class Job < OrvosModel + include AssignUuid + include KindAndEtag + include CommonApiTemplate + serialize :command_parameters, Hash + before_create :ensure_unique_submit_id + + class SubmitIdReused < StandardError + end + + api_accessible :superuser, :extend => :common do |t| + t.add :submit_id + t.add :priority + t.add :command + t.add :command_parameters + t.add :command_version + t.add :cancelled_at + t.add :cancelled_by_client + t.add :cancelled_by_user + t.add :started_at + t.add :finished_at + t.add :success + t.add :running + end + + protected + + def ensure_unique_submit_id + if !submit_id.nil? + if Job.where('submit_id=?',self.submit_id).first + raise SubmitIdReused.new + end + end + true + end +end diff --git a/app/models/job_step.rb b/app/models/job_step.rb new file mode 100644 index 0000000000..4fb714b2eb --- /dev/null +++ b/app/models/job_step.rb @@ -0,0 +1,8 @@ +class JobStep < OrvosModel + include AssignUuid + include KindAndEtag + include CommonApiTemplate + + api_accessible :superuser, :extend => :common do |t| + end +end diff --git a/config/routes.rb b/config/routes.rb index a25f86373f..b41af15f53 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,6 @@ Server::Application.routes.draw do + resources :job_steps + resources :jobs resources :api_client_authorizations resources :api_clients resources :logs @@ -78,11 +80,12 @@ Server::Application.routes.draw do resources :nodes resources :pipelines resources :pipeline_invocations - resources :pipelineInvocations resources :specimens resources :projects resources :logs resources :users + resources :jobs + resources :job_steps end end diff --git a/db/migrate/20130203104818_create_jobs.rb b/db/migrate/20130203104818_create_jobs.rb new file mode 100644 index 0000000000..f99bf88bbe --- /dev/null +++ b/db/migrate/20130203104818_create_jobs.rb @@ -0,0 +1,31 @@ +class CreateJobs < ActiveRecord::Migration + def change + create_table :jobs do |t| + t.string :uuid + t.string :owner + t.string :modified_by_client + t.string :modified_by_user + t.datetime :modified_at + t.string :submit_id + t.string :command + t.string :command_version + t.text :command_parameters + t.string :cancelled_by_client + t.string :cancelled_by_user + t.datetime :cancelled_at + t.datetime :started_at + t.datetime :finished_at + t.boolean :running + t.boolean :success + t.string :output + + t.timestamps + end + add_index :jobs, :uuid, :unique => true + add_index :jobs, :submit_id, :unique => true + add_index :jobs, :command + add_index :jobs, :finished_at + add_index :jobs, :started_at + add_index :jobs, :output + end +end diff --git a/db/migrate/20130203104824_create_job_steps.rb b/db/migrate/20130203104824_create_job_steps.rb new file mode 100644 index 0000000000..0636881bfb --- /dev/null +++ b/db/migrate/20130203104824_create_job_steps.rb @@ -0,0 +1,23 @@ +class CreateJobSteps < ActiveRecord::Migration + def change + create_table :job_steps do |t| + t.string :uuid + t.string :owner + t.string :modified_by_client + t.string :modified_by_user + t.datetime :modified_at + t.string :job_uuid + t.integer :sequence + t.text :parameters + t.text :output + t.float :progress + t.boolean :success + + t.timestamps + end + add_index :job_steps, :uuid, :unique => true + add_index :job_steps, :job_uuid + add_index :job_steps, :sequence + add_index :job_steps, :success + end +end diff --git a/db/schema.rb b/db/schema.rb index f2deccbb2a..d5cd05d3f6 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20130130205749) do +ActiveRecord::Schema.define(:version => 20130203104824) do create_table "api_client_authorizations", :force => true do |t| t.string "api_token", :null => false @@ -64,6 +64,56 @@ ActiveRecord::Schema.define(:version => 20130130205749) do add_index "collections", ["uuid"], :name => "index_collections_on_uuid", :unique => true + create_table "job_steps", :force => true do |t| + t.string "uuid" + t.string "owner" + t.string "modified_by_client" + t.string "modified_by_user" + t.datetime "modified_at" + t.string "job_uuid" + t.integer "sequence" + t.text "parameters" + t.text "output" + t.float "progress" + t.boolean "success" + t.datetime "created_at" + t.datetime "updated_at" + end + + add_index "job_steps", ["job_uuid"], :name => "index_job_steps_on_job_uuid" + add_index "job_steps", ["sequence"], :name => "index_job_steps_on_sequence" + add_index "job_steps", ["success"], :name => "index_job_steps_on_success" + add_index "job_steps", ["uuid"], :name => "index_job_steps_on_uuid", :unique => true + + create_table "jobs", :force => true do |t| + t.string "uuid" + t.string "owner" + t.string "modified_by_client" + t.string "modified_by_user" + t.datetime "modified_at" + t.string "submit_id" + t.string "command" + t.string "command_version" + t.text "command_parameters" + t.string "cancelled_by_client" + t.string "cancelled_by_user" + t.datetime "cancelled_at" + t.datetime "started_at" + t.datetime "finished_at" + t.boolean "running" + t.boolean "success" + t.string "output" + t.datetime "created_at" + t.datetime "updated_at" + end + + add_index "jobs", ["command"], :name => "index_jobs_on_command" + add_index "jobs", ["finished_at"], :name => "index_jobs_on_finished_at" + add_index "jobs", ["output"], :name => "index_jobs_on_output" + add_index "jobs", ["started_at"], :name => "index_jobs_on_started_at" + 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 "links", :force => true do |t| t.string "uuid" t.string "owner" diff --git a/test/fixtures/job_steps.yml b/test/fixtures/job_steps.yml new file mode 100644 index 0000000000..c63aac0b60 --- /dev/null +++ b/test/fixtures/job_steps.yml @@ -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/test/fixtures/jobs.yml b/test/fixtures/jobs.yml new file mode 100644 index 0000000000..c63aac0b60 --- /dev/null +++ b/test/fixtures/jobs.yml @@ -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/test/functional/job_steps_controller_test.rb b/test/functional/job_steps_controller_test.rb new file mode 100644 index 0000000000..5a9198bf56 --- /dev/null +++ b/test/functional/job_steps_controller_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class JobStepsControllerTest < ActionController::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/functional/jobs_controller_test.rb b/test/functional/jobs_controller_test.rb new file mode 100644 index 0000000000..ac43b3d40d --- /dev/null +++ b/test/functional/jobs_controller_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class JobsControllerTest < ActionController::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/unit/helpers/job_steps_helper_test.rb b/test/unit/helpers/job_steps_helper_test.rb new file mode 100644 index 0000000000..8ba4f82d9f --- /dev/null +++ b/test/unit/helpers/job_steps_helper_test.rb @@ -0,0 +1,4 @@ +require 'test_helper' + +class JobStepsHelperTest < ActionView::TestCase +end diff --git a/test/unit/helpers/jobs_helper_test.rb b/test/unit/helpers/jobs_helper_test.rb new file mode 100644 index 0000000000..7c4a3fdda3 --- /dev/null +++ b/test/unit/helpers/jobs_helper_test.rb @@ -0,0 +1,4 @@ +require 'test_helper' + +class JobsHelperTest < ActionView::TestCase +end diff --git a/test/unit/job_step_test.rb b/test/unit/job_step_test.rb new file mode 100644 index 0000000000..c87035abf0 --- /dev/null +++ b/test/unit/job_step_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class JobStepTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/unit/job_test.rb b/test/unit/job_test.rb new file mode 100644 index 0000000000..5079316934 --- /dev/null +++ b/test/unit/job_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class JobTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end -- 2.30.2