Skip to content

Commit

Permalink
Cache of Summary and Recommendations, and setup parameter for the ref…
Browse files Browse the repository at this point in the history
…resh of information
  • Loading branch information
jros2300 committed Jun 16, 2016
1 parent e43aaf7 commit 7119c08
Show file tree
Hide file tree
Showing 16 changed files with 444 additions and 332 deletions.
4 changes: 4 additions & 0 deletions app/controllers/setup_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class SetupController < ApplicationController
def index
@regions = Setup.get_regions
@minutes = Setup.get_minutes
@minutesrefresh = Setup.get_minutesrefresh
@importdbr = Setup.get_importdbr
@s3bucket = Setup.get_s3bucket
@processed = Setup.get_processed
Expand All @@ -18,6 +19,9 @@ def change
if !params[:minutes].blank?
Setup.put_minutes params[:minutes] if params[:minutes].to_i >= 30 || params[:minutes].to_i == 0
end
if !params[:minutesrefresh].blank?
Setup.put_minutesrefresh params[:minutesrefresh] if params[:minutesrefresh].to_i >= 5
end
Setup.put_password params[:password] if !params[:password].blank?
Setup.put_importdbr !params[:importdbr].blank?
Setup.put_affinity !params[:affinity].blank?
Expand Down
288 changes: 7 additions & 281 deletions app/controllers/summary_controller.rb

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions app/models/recommendation_cache.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class RecommendationCache < ActiveRecord::Base
end
42 changes: 42 additions & 0 deletions app/models/setup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,24 @@ def self.put_minutes(minutes)
update_next
end

def self.get_minutesrefresh
minutesrefresh = 5
setup = Setup.first
if !setup.nil?
minutesrefresh = setup.minutesrefresh if !setup.minutesrefresh.nil?
end
return minutesrefresh
end

def self.put_minutesrefresh(minutes)
setup = Setup.first
setup = Setup.new if setup.nil?

setup.minutesrefresh = minutes
setup.save
update_nextrefresh
end

def self.get_password
password = BCrypt::Password.create(ENV['DEFAULT_PASSWORD'])
setup = Setup.first
Expand Down Expand Up @@ -131,6 +149,30 @@ def self.now_after_next
return after_next
end

def self.update_nextrefresh
minutesrefresh = 5
setup = Setup.first
if !setup.nil?
minutesrefresh = setup.minutesrefresh if !setup.minutesrefresh.nil?
end

setup.nextrefresh = Time.current + minutesrefresh.minutes
setup.save
end

def self.now_after_nextrefresh
###### DELETE THIS #######
return true
###### DELETE THIS #######
after_nextrefresh = true
setup = Setup.first
if !setup.nil? && !setup.nextrefresh.nil?
after_nextrefresh = (setup.nextrefresh < Time.current)
end
return after_nextrefresh
end


def self.get_regions
regions = {"eu-west-1"=> false, "us-east-1"=> false, "eu-central-1"=> false, "us-west-1"=> false, "us-west-2"=> false, "ap-southeast-1"=> false, "ap-southeast-2"=> false, "ap-northeast-1"=> false, "sa-east-1"=> false}
setup = Setup.first
Expand Down
2 changes: 2 additions & 0 deletions app/models/summary.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class Summary < ActiveRecord::Base
end
4 changes: 4 additions & 0 deletions app/views/setup/index.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
<label>Automatically apply recommendations each</label></br>
<div class="col-xs-2"><%= number_field_tag "minutes", @minutes.to_s, min:0, id: 'minutestext', class: 'form-control' %></div><span id="helpBlock" class="help-block">minutes (0 to stop, minimum 30)</span>
</div>
<div class="form-group">
<label>Automatically refresh information from the accounts each</label></br>
<div class="col-xs-2"><%= number_field_tag "minutesrefresh", @minutesrefresh.to_s, min:5, id: 'minutesrefreshtext', class: 'form-control' %></div><span id="helpBlock" class="help-block">minutesrefresh (minimum 5)</span>
</div>
<div class="form-group">
<label class="checkbox-inline">
<%= check_box_tag "affinity", "affinity", @affinity %>
Expand Down
24 changes: 9 additions & 15 deletions app/views/summary/index.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,15 @@
</tr>
</thead>
<tbody>
<% @summary.each do |type, elem1| %>
<% elem1.each do |az, elem2| %>
<% elem2.each do |platform, elem3| %>
<% elem3.each do |tenancy, total| %>
<tr>
<td><%= type %></td>
<td><%= az %></td>
<td><%= platform %></td>
<td><%= tenancy %></td>
<td><%= total[0] %></td>
<td><%= total[1] %></td>
</tr>
<% end %>
<% end %>
<% end %>
<% @summary.each do |s| %>
<tr>
<td><%= s.instancetype %></td>
<td><%= s.az %></td>
<td><%= s.platform %></td>
<td><%= s.tenancy %></td>
<td><%= s.total %></td>
<td><%= s.reservations %></td>
</tr>
<% end %>
</tbody>
</table>
Expand Down
6 changes: 6 additions & 0 deletions db/migrate/20160616131916_add_refresh_to_setup.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class AddRefreshToSetup < ActiveRecord::Migration
def change
add_column :setups, :nextrefresh, :datetime
add_column :setups, :minutesrefresh, :integer
end
end
14 changes: 14 additions & 0 deletions db/migrate/20160616135351_create_summaries.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class CreateSummaries < ActiveRecord::Migration
def change
create_table :summaries do |t|
t.string :instancetype
t.string :az
t.string :tenancy
t.string :platform
t.integer :total
t.integer :reservations

t.timestamps null: false
end
end
end
9 changes: 9 additions & 0 deletions db/migrate/20160616142650_create_recommendation_caches.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class CreateRecommendationCaches < ActiveRecord::Migration
def change
create_table :recommendation_caches do |t|
t.text :object

t.timestamps null: false
end
end
end
25 changes: 22 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: 20160601145048) do
ActiveRecord::Schema.define(version: 20160616142650) do

create_table "amis", force: :cascade do |t|
t.string "ami"
Expand All @@ -37,6 +37,12 @@
t.datetime "updated_at", null: false
end

create_table "recommendation_caches", force: :cascade do |t|
t.text "object"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end

create_table "recommendations", force: :cascade do |t|
t.string "rid"
t.string "az"
Expand Down Expand Up @@ -70,15 +76,28 @@

create_table "setups", force: :cascade do |t|
t.text "regions"
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.integer "minutes"
t.datetime "nextrun"
t.string "password"
t.boolean "importdbr"
t.string "s3bucket"
t.datetime "processed"
t.boolean "affinity"
t.datetime "nextrefresh"
t.integer "minutesrefresh"
end

create_table "summaries", force: :cascade do |t|
t.string "instancetype"
t.string "az"
t.string "tenancy"
t.string "platform"
t.integer "total"
t.integer "reservations"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end

end
Loading

0 comments on commit 7119c08

Please sign in to comment.