Hi Matt,
some minor notes inline, but overall this looks good.
On 05/17/2011 12:05 AM, Matt Wagner wrote:
Implements
https://www.aeolusproject.org/redmine/issues/1529
---
src/app/controllers/pools_controller.rb | 23 ++++++++++++-----------
src/app/models/deployment.rb | 3 +++
src/app/models/instance.rb | 9 ++++++++-
src/app/models/pool.rb | 16 ++++++++++++++++
src/app/views/deployments/_deployment.haml | 11 +++++++++++
src/app/views/deployments/_filter_view.haml | 15 +++++++++++++++
src/app/views/deployments/_pretty_view.haml | 1 +
src/app/views/pools/_statistics.haml | 21 +++++++++++++++++++++
src/app/views/pools/edit.haml | 2 +-
src/app/views/pools/show.haml | 10 ++++++----
10 files changed, 94 insertions(+), 17 deletions(-)
create mode 100644 src/app/views/deployments/_deployment.haml
create mode 100644 src/app/views/deployments/_filter_view.haml
create mode 100644 src/app/views/deployments/_pretty_view.haml
create mode 100644 src/app/views/pools/_statistics.haml
diff --git a/src/app/controllers/pools_controller.rb
b/src/app/controllers/pools_controller.rb
index 1402cca..93af54e 100644
--- a/src/app/controllers/pools_controller.rb
+++ b/src/app/controllers/pools_controller.rb
@@ -3,6 +3,7 @@ class PoolsController< ApplicationController
before_filter :set_params_and_header, :only => [:index, :show]
before_filter :load_pools, :only => [:show]
layout 'application'
+ helper DeploymentsHelper
It's better to move uptime helper method into application_helper, this
method is general and will probably used on other places.
def index
@search_term = params[:q]
@@ -20,18 +21,11 @@ class PoolsController< ApplicationController
def show
@pool = Pool.find(params[:id])
require_privilege(Privilege::VIEW, @pool)
- @url_params = params.clone
- load_instances
- @tab_captions = ['Properties', 'Deployments', 'Instances',
'History', 'Permissions']
- @details_tab = params[:details_tab].blank? ? 'properties' :
params[:details_tab]
+ @statistics = @pool.statistics
+ @view = params[:view] == 'filter' ? 'deployments/filter_view' :
'deployments/pretty_view'
respond_to do |format|
- format.js do
- if @url_params.delete :details_pane
- render :partial => 'layouts/details_pane' and return
- end
- render :partial => @details_tab and return
- end
- format.html { render :action => 'show'}
+ format.js { render :partial => @view, :locals => {:deployments =>
@pool.deployments} }
+ format.html { render :action => :show}
format.json { render :json => @pool }
end
end
@@ -165,6 +159,13 @@ class PoolsController< ApplicationController
{ :name => "Pool Family", :sort_attr =>
"pool_families.name" },
{ :name => "Enabled", :sort_attr => :enabled }
]
+ @deployments_header = [
+ { :name => "Deployment Name", :sort_attr => :name },
+ { :name => "Base Deployable", :sort_attr =>
'deployable.name' },
+ { :name => "Uptime", :sort_attr => :created_at },
+ { :name => "Instances", :sort_attr => 'instances.count'
},
+ { :name => "Provider", :sort_attr => :provider }
+ ]
end
def load_pools
diff --git a/src/app/models/deployment.rb b/src/app/models/deployment.rb
index 9f382c0..11e2b97 100644
--- a/src/app/models/deployment.rb
+++ b/src/app/models/deployment.rb
@@ -55,6 +55,9 @@ class Deployment< ActiveRecord::Base
:order => "permissions.id ASC"
belongs_to :owner, :class_name => "User", :foreign_key =>
"owner_id"
after_create "assign_owner_roles(owner)"
+ # TODO - Strictly, this should be a belongs_to, but :through seems to only work
one-way,
+ # and we don't much care about the inverse here.
+ has_one :provider, :through => :realm
This is OK, but realm association is not being set yet, deployment.realm
must be set in dbomatic but it's not implemented yet.
validates_presence_of :pool_id
validates_presence_of :deployable_id
diff --git a/src/app/models/instance.rb b/src/app/models/instance.rb
index ef38263..4d1c5c6 100644
--- a/src/app/models/instance.rb
+++ b/src/app/models/instance.rb
@@ -117,6 +117,13 @@ class Instance< ActiveRecord::Base
STATE_SHUTTING_DOWN, STATE_STOPPED, STATE_CREATE_FAILED,
STATE_ERROR]
+ named_scope :deployed, :conditions => { :state => [STATE_RUNNING,
STATE_SHUTTING_DOWN] }
+ # FIXME: "pending" is misleading as it doesn't just cover STATE_PENDING
+ named_scope :pending, :conditions => { :state => [STATE_NEW, STATE_PENDING]
}
+ # FIXME: "failed" is misleading too...
+ named_scope :failed, :conditions => { :state => [STATE_CREATE_FAILED,
STATE_ERROR] }
+
+
SEARCHABLE_COLUMNS = %w(name state)
validates_inclusion_of :state,
@@ -261,7 +268,7 @@ class Instance< ActiveRecord::Base
}
instances = []
- pools = Pool.list_for_user(user, Privilege::VIEW, Instance)
+ pools = Pool.list_for_user(user, Privilege::VIEW, :target_type => Instance)
pools.each{|pool| pool.instances.each {|i| instances<< i}}
instances.each do |i|
if i.state == Instance::STATE_RUNNING
diff --git a/src/app/models/pool.rb b/src/app/models/pool.rb
index 87f5c19..6a28794 100644
--- a/src/app/models/pool.rb
+++ b/src/app/models/pool.rb
@@ -60,6 +60,8 @@ class Pool< ActiveRecord::Base
:include => [:role],
:order => "permissions.id ASC"
+ has_many :deployments, :through => :instances
+
before_destroy :destroyable?
def cloud_accounts
@@ -75,4 +77,18 @@ class Pool< ActiveRecord::Base
instances.all? {|i| i.destroyable? }
end
+ # TODO: Implement Alerts, Updates, and Quotas
+ def statistics
+ # TODO - Need to set up cache invalidation before this is safe
+ #Rails.cache.fetch("pool-#{id}-statistics") do
+ {
+ :cloud_providers => instances.collect{|i| i.provider_account}.uniq.count,
+ :deployments => deployments.count,
+ :instances_deployed => instances.deployed.count,
+ :instances_pending => instances.pending.count,
+ :instances_failed => instances.failed.count
+ }
+ #end
+ end
+
end
diff --git a/src/app/views/deployments/_deployment.haml
b/src/app/views/deployments/_deployment.haml
new file mode 100644
index 0000000..669bbce
--- /dev/null
+++ b/src/app/views/deployments/_deployment.haml
@@ -0,0 +1,11 @@
+%div.deployment_pretty
+ %h3
+ = deployment.name
+ %ul
+ %li
+ = count_uptime(deployment.created_at)
+ %li
+ = deployment.instances.count
+ Instances
+ %p
+ = deployment.realm.provider.provider_type.name
deployment.realm can be nil (not implemented yet, but even if
implemented the realm will be nil until at least one instance of a
deployment is updated). I guess deployment.provider should be used here
as you added association deployment->provider :through => realm into model.
\ No newline at end of file
diff --git a/src/app/views/deployments/_filter_view.haml
b/src/app/views/deployments/_filter_view.haml
new file mode 100644
index 0000000..33d25d6
--- /dev/null
+++ b/src/app/views/deployments/_filter_view.haml
@@ -0,0 +1,15 @@
+%table
+ -# FIXME: sortable_table_header won't actually work as-is since it sorts on Pools,
not Deployments...
+ = sortable_table_header(@deployments_header)
+ - deployments.each do |deployment|
+ %tr
+ %td
+ = deployment.name
I would add checkbox box here too as before
+ %td
+ = deployment.deployable.name
+ %td
+ = count_uptime(deployment.created_at)
+ %td
+ = deployment.instances.count
+ %td
+ = deployment.provider.name
provider can be nil (if realm is nil)
\ No newline at end of file
diff --git a/src/app/views/deployments/_pretty_view.haml
b/src/app/views/deployments/_pretty_view.haml
new file mode 100644
index 0000000..5721367
--- /dev/null
+++ b/src/app/views/deployments/_pretty_view.haml
@@ -0,0 +1 @@
+= render :partial => deployments
\ No newline at end of file
diff --git a/src/app/views/pools/_statistics.haml b/src/app/views/pools/_statistics.haml
new file mode 100644
index 0000000..1d37026
--- /dev/null
+++ b/src/app/views/pools/_statistics.haml
@@ -0,0 +1,21 @@
+%h1
+ = @pool.name
+ Pool
+
+= link_to 'New Deployment', launch_new_deployments_path, :class =>
'button', :id => 'new_deployment_button'
+= link_to 'Edit', edit_pool_path(@pool), :class => 'button', :id
=> 'edit_pool_button'
+- form_tag do
+ = hidden_field(@pool, :id)
+ = restful_submit_tag('Delete', 'destroy', pool_url(@pool),
'DELETE')
+
+%div.statistics
+ Cloud Providers
+ = @statistics[:cloud_providers]
+%div.statistics
+ Deployments
+ = @statistics[:deployments]
+%div.instances
+ = @statistics[:instances_deployed]
+ = @statistics[:instances_pending]
+ = @statistics[:instances_failed]
+-# TODO: Implement alerts, updates, and quota overview
diff --git a/src/app/views/pools/edit.haml b/src/app/views/pools/edit.haml
index d4c511f..94e486f 100644
--- a/src/app/views/pools/edit.haml
+++ b/src/app/views/pools/edit.haml
@@ -3,7 +3,7 @@
Edit pool
= @pool.name
-- form_for [:resources, @pool] do |form|
+- form_for @pool do |form|
%fieldset
= form.label :name, "Name:", :class => "grid_2 alpha"
= form.text_field :name
diff --git a/src/app/views/pools/show.haml b/src/app/views/pools/show.haml
index 05eeedd..c411511 100644
--- a/src/app/views/pools/show.haml
+++ b/src/app/views/pools/show.haml
@@ -1,5 +1,7 @@
-- content_for :list do
- = render :partial => 'list'
+= render :partial => 'statistics'
-- content_for :details do
- = render :partial => 'layouts/details_pane'
+-# TODO - Alerts aren't implemented just yet
+-#= render :partial => 'alerts'
+
+-# TODO: %w(Deployments History Properties Permissions) links/tabs, plus filter
links/icons, go here
For now, jquery tabs plugin can be used as we used it till now.
+= render :partial => @view, :locals => {:deployments =>
@pool.deployments}
We should also keep writing tests/update existing, I know this is pretty
difficult at this point as new layout switch broke some tests and links.
I'm going to send patch which enables links to other sections (design,
administration) in new layout so it should be possible to have most cuke
tests green.