Skip to content

Commit

Permalink
[Bherly/Tara] Add setup & app status
Browse files Browse the repository at this point in the history
  • Loading branch information
pushm0v committed May 7, 2018
1 parent ab2c14f commit bfa1637
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 6 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ gem 'execjs'
gem 'therubyracer'
gem 'berkshelf'
gem 'knife-solo'
gem 'enumerize'

group :development, :test do
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
Expand Down
3 changes: 3 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ GEM
devise (>= 1.2.0)
rubycas-client (>= 2.2.1)
diff-lcs (1.3)
enumerize (2.2.2)
activesupport (>= 3.2)
erubis (2.7.0)
execjs (2.7.0)
factory_bot (4.8.2)
Expand Down Expand Up @@ -406,6 +408,7 @@ DEPENDENCIES
byebug
devise
devise_cas_authenticatable
enumerize
execjs
factory_bot_rails
figaro
Expand Down
38 changes: 36 additions & 2 deletions app/models/app.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,25 @@
class App < ActiveRecord::Base
extend Enumerize
validates_presence_of :name

enumerize :app_status, in: %w(INACTIVE ACTIVE)
enumerize :setup_status, in: %w(
PENDING
BLUEPRINT_CREATION
BLUEPRINT_CREATION_ERROR
BLUEPRINT_EXECUTED
BLUEPRINT_EXECUTED_ERROR
PROVISIONING_STARTED
PROVISIONING_ERROR
CHEF_BOOTSTRAP_STARTED
CHEF_BOOTSTRAP_ERROR
FINISHED
)

belongs_to :app_group, required: true
belongs_to :log_template, required: true

after_create :generate_secret_key, :generate_receiver_end_point, :generate_kibana_address
after_create :generate_secret_key, :generate_receiver_end_point, :generate_kibana_address, :set_setup_status_pending, :set_app_status_inactive

def generate_secret_key
update_column(:secret_key, SecureRandom.base64)
Expand All @@ -16,5 +32,23 @@ def generate_receiver_end_point
def generate_kibana_address
update_column(:kibana_address, 'http://dummy.kibana-address/')
end


def set_setup_status_pending
set_setup_status('PENDING')
end

def set_app_status_inactive
set_app_status('INACTIVE')
end

private

def set_setup_status(status)
self.setup_status=status
end

def set_app_status(status)
self.app_status=status
end

end
8 changes: 8 additions & 0 deletions db/migrate/20180507062506_add_status_to_app.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class AddStatusToApp < ActiveRecord::Migration
def change
add_column :apps, :setup_status, :string, :default => "PENDING"
add_index :apps, :setup_status
add_column :apps, :app_status, :string, :default => "INACTIVE", :index => true
add_index :apps, :app_status
end
end
11 changes: 8 additions & 3 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20180507040330) do
ActiveRecord::Schema.define(version: 20180507062506) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand All @@ -26,13 +26,18 @@
t.string "name"
t.integer "log_template_id"
t.integer "app_group_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "secret_key"
t.string "kibana_address"
t.string "receiver_end_point"
t.string "setup_status", default: "PENDING"
t.string "app_status", default: "INACTIVE"
end

add_index "apps", ["app_status"], name: "index_apps_on_app_status", using: :btree
add_index "apps", ["setup_status"], name: "index_apps_on_setup_status", using: :btree

create_table "log_templates", force: :cascade do |t|
t.string "name"
t.integer "tps_limit"
Expand Down
4 changes: 3 additions & 1 deletion spec/factories/apps.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
FactoryBot.define do
factory :app do
name "app1"

setup_status "PENDING"
app_status "INACTIVE"

log_template
app_group
end
Expand Down
8 changes: 8 additions & 0 deletions spec/models/app_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,13 @@
app = FactoryBot.create(:app)
expect(app.kibana_address).to eq('http://dummy.kibana-address/')
end
it 'should has pending setup status' do
app = FactoryBot.create(:app)
expect(app.setup_status).to eq('PENDING')
end
it 'should has inactive app status' do
app = FactoryBot.create(:app)
expect(app.app_status).to eq('INACTIVE')
end
end
end

0 comments on commit bfa1637

Please sign in to comment.