Skip to content

Commit

Permalink
Remove the rails cache and use the DB, Option to give preference to t…
Browse files Browse the repository at this point in the history
…he purchased account, join RIs
  • Loading branch information
jros2300 committed Jun 3, 2016
1 parent ba3cd1c commit e43aaf7
Show file tree
Hide file tree
Showing 30 changed files with 634 additions and 239 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,14 +189,15 @@ Once in the tool you should configure it:
* Automatically apply recommendations each: If you set this to 0, then there is not going to be any automatic mofification of the RIs. If you set this to any other number (more than 30), the application is going to apply all the recommendations automatically periodically on that interval.
* Change Password: You can introduce a new password for the tool

The tool updates the information from the accounts using the API calls each 5 minutes (it can take up to 5 minutes until you're able to see the first analysis when you deploy the application).

In the tool there are several options:

* Instances: You can see all your running instances in all the accounts, you can search by any field
* Reserved Instances: You can see all your reserved instances in all the accounts
* Summary: You can see a summary of your instances and reserved instances. You can see where you have more instances than reserved instances (yellow), and where you have more RIs than instances (red)
* Recommendations: You can see all the recommended modifications in your RIs, you can select all the modifications or a subset of them and apply the modifications to your RIs from the tool
* Log: You'll see all the recommended modifications to your RIs applied by the tool, in the Recommendations option, or automatically by the periodic task
* Clear Cache: The tool create a cache of 20 minutes of all the API calls, if you want to get the latest data then you can clear the cache and then select any other option



Expand Down
2 changes: 1 addition & 1 deletion app/controllers/instances_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ class InstancesController < ApplicationController
include AwsCommon

def index
@instances = get_instances(Setup.get_regions, get_account_ids)
@instances = Instance.all
end
end
2 changes: 1 addition & 1 deletion app/controllers/reserved_instances_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ class ReservedInstancesController < ApplicationController
include AwsCommon

def index
@reserved_instances = get_reserved_instances(Setup.get_regions, get_account_ids)
@reserved_instances = ReservedInstance.all
end
end
7 changes: 4 additions & 3 deletions app/controllers/setup_controller.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
class SetupController < ApplicationController

#include AwsCommon
include AwsCommon

def index
@regions = Setup.get_regions
@minutes = Setup.get_minutes
@importdbr = Setup.get_importdbr
@s3bucket = Setup.get_s3bucket
@processed = Setup.get_processed
@affinity = Setup.get_affinity
end

def change
Expand All @@ -19,13 +20,13 @@ def change
end
Setup.put_password params[:password] if !params[:password].blank?
Setup.put_importdbr !params[:importdbr].blank?
Setup.put_affinity !params[:affinity].blank?
Setup.put_s3bucket params[:s3bucket]
Rails.cache.clear
redirect_to action: 'index'
end

def clear_cache
Rails.cache.clear
populatedb_data()
end

end
170 changes: 103 additions & 67 deletions app/controllers/summary_controller.rb

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions app/models/instance.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class Instance < ActiveRecord::Base
end
2 changes: 2 additions & 0 deletions app/models/modification.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class Modification < ActiveRecord::Base
end
2 changes: 2 additions & 0 deletions app/models/reserved_instance.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class ReservedInstance < ActiveRecord::Base
end
18 changes: 18 additions & 0 deletions app/models/setup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,23 @@ def self.put_password(password)
setup.password = BCrypt::Password.create(password)
setup.save
end

def self.get_affinity
setup = Setup.first
affinity = false
if !setup.nil? && !setup.affinity.nil?
affinity = setup.affinity
end
return affinity
end

def self.put_affinity(affinity)
setup = Setup.first
setup = Setup.new if setup.nil?

setup.affinity = affinity
setup.save
end

def self.get_importdbr
setup = Setup.first
Expand Down Expand Up @@ -108,6 +125,7 @@ def self.now_after_next
after_next = false
setup = Setup.first
if !setup.nil? && !setup.nextrun.nil?
return false if setup.minutes.nil? || setup.minutes==0
after_next = (setup.nextrun < Time.current)
end
return after_next
Expand Down
16 changes: 8 additions & 8 deletions app/views/instances/index.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
</tr>
</thead>
<tbody>
<% @instances.each do |instance_id, instance| %>
<% @instances.each do |instance| %>
<tr>
<td><%= instance[:account_id] %></td>
<td><%= instance_id %></td>
<td><%= instance[:type] %></td>
<td><%= instance[:az] %></td>
<td><%= instance[:tenancy] %></td>
<td><%= instance[:platform] %></td>
<td><%= instance[:vpc] %></td>
<td><%= instance.accountid %></td>
<td><%= instance.instanceid %></td>
<td><%= instance.instancetype %></td>
<td><%= instance.az %></td>
<td><%= instance.tenancy %></td>
<td><%= instance.platform %></td>
<td><%= instance.network %></td>
</tr>
<% end %>
</tbody>
Expand Down
2 changes: 1 addition & 1 deletion app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
<li><%= link_to "Recommendations", "/recommendations" %></li>
<li><%= link_to "Log", "/logrecommendations" %></li>
<li><%= link_to "Setup", "/setup" %></li>
<li><%= link_to "Clear Cache", "/clearcache" %></li>
<!-- <li><%= link_to "Clear Cache", "/clearcache" %></li> -->
</ul>
</div>
</div>
Expand Down
22 changes: 11 additions & 11 deletions app/views/reserved_instances/index.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@
</tr>
</thead>
<tbody>
<% @reserved_instances.each do |ri_id, ri| %>
<% @reserved_instances.each do |ri| %>
<tr>
<td><%= ri[:account_id] %></td>
<td><%= ri_id %></td>
<td><%= ri[:type] %></td>
<td><%= ri[:az] %></td>
<td><%= ri[:tenancy] %></td>
<td><%= ri[:platform] %></td>
<td><%= ri[:vpc] %></td>
<td><%= ri[:count] %></td>
<td><%= ri[:end] %></td>
<td><%= ri[:status] %></td>
<td><%= ri.accountid %></td>
<td><%= ri.reservationid %></td>
<td><%= ri.instancetype %></td>
<td><%= ri.az %></td>
<td><%= ri.tenancy %></td>
<td><%= ri.platform %></td>
<td><%= ri.network %></td>
<td><%= ri.count %></td>
<td><%= ri.enddate %></td>
<td><%= ri.status %></td>
</tr>
<% end %>
</tbody>
Expand Down
6 changes: 6 additions & 0 deletions app/views/setup/index.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
<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 class="checkbox-inline">
<%= check_box_tag "affinity", "affinity", @affinity %>
Use affinity (move Reserved instances to cover other instances in the same account first)
</label>
</div>
<div class="form-group">
<label>Change Password</label></br>
<%= password_field_tag 'password', nil, class: 'form-control' %>
Expand Down
4 changes: 2 additions & 2 deletions app/views/summary/log_recommendations.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
<tr>
<td><%= recommendation.accountid %></td>
<td><%= recommendation.rid %></td>
<td><%= recommendation.count %></td>
<td><%= recommendation.counts %></td>
<td><%= recommendation.instancetype %></td>
<td><%= recommendation.az %></td>
<td><%= recommendation.timestamp %></td>
<td><%= @failed_recommendations.include?(recommendation.rid) ? '<span class="glyphicon glyphicon-remove" style="color:red"></span>'.html_safe : '<span class="glyphicon glyphicon-ok" style="color:green"></span>'.html_safe %></td>
<td><%= @failed_recommendations.find_by(modificationid: recommendation.rid) ? '<span class="glyphicon glyphicon-remove" style="color:red"></span>'.html_safe : '<span class="glyphicon glyphicon-ok" style="color:green"></span>'.html_safe %></td>
</tr>
<% end %>
</tbody>
Expand Down
29 changes: 22 additions & 7 deletions app/views/summary/recommendations.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,39 @@
<th data-field="state" data-checkbox="true"></th>
<th>Change number</th>
<th>Reservation ID</th>
<th>Count</th>
<th>Orig Count</th>
<th>New Count</th>
<th>New type</th>
<th>New availability zone</th>
<th>New network</th>
</tr>
</thead>
<tbody>
<% i= 0 %>
<% @recommendations.each do |recommendation| %>
<% recommendation_ids = []
recommendation_counts = []
recommendation_orig_counts = []
recommendation_types = []
recommendation_azs = []
recommendation_vpcs = []
recommendation.each do |element|
recommendation_ids << "<a href='reservedinstances?search=#{element[:rid]}'>#{element[:rid]}</a>"
recommendation_counts << element[:count]
recommendation_orig_counts << element[:orig_count]
recommendation_types << element[:type]
recommendation_azs << element[:az]
recommendation_vpcs << element[:vpc]
end %>

<tr>
<td></td>
<td><%= i %></td>
<% i += 1 %>
<td><a href='reservedinstances?search=<%= recommendation[:rid] %>'><%= recommendation[:rid] %></a></td>
<td><%= recommendation[:count] %></td>
<td><%= recommendation[:type] %></td>
<td><%= recommendation[:az] %></td>
<td><%= recommendation[:vpc] %></td>
<td><%= recommendation_ids.join(",").html_safe() %></td>
<td><%= recommendation_orig_counts.join(",") %></td>
<td><%= recommendation_counts.join(",") %></td>
<td><%= recommendation_types.join(",") %></td>
<td><%= recommendation_azs.join(",") %></td>
</tr>
<% end %>
</tbody>
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

post '/periodicworker' => 'summary#periodic_worker'
post '/s3importer' => 'summary#s3importer'
post '/populatedb' => 'summary#populatedb'


# Example of regular route:
Expand Down
15 changes: 15 additions & 0 deletions db/migrate/20160531154327_create_instances.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class CreateInstances < ActiveRecord::Migration
def change
create_table :instances do |t|
t.string :accountid
t.string :instanceid
t.string :instancetype
t.string :az
t.string :tenancy
t.string :platform
t.string :network

t.timestamps null: false
end
end
end
19 changes: 19 additions & 0 deletions db/migrate/20160531154702_create_reserved_instances.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class CreateReservedInstances < ActiveRecord::Migration
def change
create_table :reserved_instances do |t|
t.string :accountid
t.string :reservationid
t.string :instancetype
t.string :az
t.string :tenancy
t.string :platform
t.string :network
t.integer :count
t.datetime :enddate
t.string :status
t.string :rolearn

t.timestamps null: false
end
end
end
10 changes: 10 additions & 0 deletions db/migrate/20160531155006_create_modifications.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class CreateModifications < ActiveRecord::Migration
def change
create_table :modifications do |t|
t.string :modificationid
t.string :status

t.timestamps null: false
end
end
end
5 changes: 5 additions & 0 deletions db/migrate/20160601070400_add_affinity_to_setup.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddAffinityToSetup < ActiveRecord::Migration
def change
add_column :setups, :affinity, :boolean
end
end
5 changes: 5 additions & 0 deletions db/migrate/20160601093449_add_counts_to_recommendation.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddCountsToRecommendation < ActiveRecord::Migration
def change
add_column :recommendations, :counts, :string
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class AddOfferingToReservedInstance < ActiveRecord::Migration
def change
add_column :reserved_instances, :offering, :string
add_column :reserved_instances, :duration, :integer
end
end
41 changes: 40 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,32 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20150930131716) do
ActiveRecord::Schema.define(version: 20160601145048) do

create_table "amis", force: :cascade do |t|
t.string "ami"
t.string "operation"
end

create_table "instances", force: :cascade do |t|
t.string "accountid"
t.string "instanceid"
t.string "instancetype"
t.string "az"
t.string "tenancy"
t.string "platform"
t.string "network"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end

create_table "modifications", force: :cascade do |t|
t.string "modificationid"
t.string "status"
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 All @@ -28,6 +47,25 @@
t.string "accountid"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "counts"
end

create_table "reserved_instances", force: :cascade do |t|
t.string "accountid"
t.string "reservationid"
t.string "instancetype"
t.string "az"
t.string "tenancy"
t.string "platform"
t.string "network"
t.integer "count"
t.datetime "enddate"
t.string "status"
t.string "rolearn"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "offering"
t.integer "duration"
end

create_table "setups", force: :cascade do |t|
Expand All @@ -40,6 +78,7 @@
t.boolean "importdbr"
t.string "s3bucket"
t.datetime "processed"
t.boolean "affinity"
end

end
Loading

0 comments on commit e43aaf7

Please sign in to comment.