Changeset 90

Show
Ignore:
Timestamp:
04/23/08 23:21:57 (7 months ago)
Author:
jweiss
Message:

finish UI work on excluded hosts

Location:
trunk
Files:
2 added
8 modified

Legend:

Unmodified
Added
Removed
  • trunk/CHANGELOG.txt

    r88 r90  
    11 
    22* SVN * 
     3 
     4* Ability to disable host per deloy. This way host that are down do not block a deployment 
    35 
    46* Check syntax of recipes. Provided by Mathias Meyer 
  • trunk/app/helpers/deployments_helper.rb

    r1 r90  
    88    end 
    99  end 
     10   
     11  def if_disabled_host?(host, text) 
     12    (@deployment.excluded_host_ids.include?(host.id) ? text : '' rescue '') 
     13  end 
     14   
     15  def if_enabled_host?(host, text) 
     16    (@deployment.excluded_host_ids.include?(host.id) ? '' : text rescue text) 
     17  end 
    1018end 
  • trunk/app/models/deployment.rb

    r89 r90  
    3333      end 
    3434       
     35      ensure_not_all_hosts_excluded 
    3536    end 
    3637  end 
     
    126127  # will deploy to. This computed out of the list 
    127128  # of given roles and the excluded hosts 
    128   def deploy_to_roles 
    129     self.roles.delete_if{|role| self.excluded_hosts.include?(role.host) } 
     129  def deploy_to_roles(base_roles=self.roles) 
     130    base_roles.dup.delete_if{|role| self.excluded_hosts.include?(role.host) } 
    130131  end 
    131132   
     
    146147  def excluded_host_ids=(val) 
    147148    val = [val] unless val.is_a?(Array) 
    148     self.write_attribute('excluded_host_ids', val) 
     149    self.write_attribute('excluded_host_ids', val.map(&:to_i)) 
     150  end 
     151   
     152  protected 
     153  def ensure_not_all_hosts_excluded 
     154    unless self.stage.blank? || self.excluded_host_ids.blank? 
     155      if deploy_to_roles(self.stage.roles).blank? 
     156        errors.add('base', "You cannot exclude all hosts.") 
     157      end 
     158    end 
    149159  end 
    150160end 
  • trunk/app/views/deployments/new.html.erb

    r73 r90  
    2525   
    2626  <p> 
     27    <b>Deployment Options</b><br /> 
     28    <a id="s_e_h" href="#" onclick="show_disable_hosts(); return false" class="arrow_link">Show Manage Deployed Hosts</a> 
     29    <a id="h_e_h" href="#" onclick="hide_disable_hosts(); return false" class="arrow_link" style="display:none;">Hide Manage Deployed Hosts</a> 
     30    <div id="excluded_hosts" style="display:none;"> 
     31      <% if @stage.roles.count > 0 %> 
     32        <table class="sortable" style="width: 410px;"> 
     33          <tr> 
     34            <th width="1%">Status</th> 
     35            <th width="99%">Host</th> 
     36          </tr> 
     37          <% for host in @stage.hosts %> 
     38            <tr class="<%= cycle :even, :odd, :name => 'hosts'  %> <%= if_disabled_host?(host,'disabled_host') %>"> 
     39              <td style="padding:3px 0px 0px 0px;" valign="middle" align="center"> 
     40                <%= image_tag('peritor_theme/host_on.png',  
     41                              :id => "host_#{host.id}_on",  
     42                              :class => 'exlcude_host_trigger_on', 
     43                              :style => if_disabled_host?(host,'display:none;') + 'cursor:pointer;')%> 
     44                <%= image_tag('peritor_theme/host_off.png',  
     45                              :id => "host_#{host.id}_off",  
     46                              :class => 'exlcude_host_trigger_off', 
     47                              :style => if_enabled_host?(host,'display:none;') + 'cursor:pointer;')%> 
     48                <input style="display:none;" type="checkbox" value="<%=h host.id %>" name="deployment[excluded_host_ids][]" id="deployment_excluded_host_ids_<%=h host.id %>" <%= (@deployment.excluded_host_ids.include?(host.id) ? 'checked="checked"' : ''  rescue '')%>/></td> 
     49              <td><%= link_to h(host.name), host_path(host) %></td> 
     50            </tr> 
     51          <% end %> 
     52        </table> 
     53 
     54      <% else %> 
     55       No hosts for this stage!<br /><br /> 
     56      <% end %> 
     57      <br /> 
     58    </div> 
     59  </p> 
     60  <p> 
    2761    <%= submit_tag "Start Deployment" %> 
    2862  </p> 
     
    3064 
    3165<%= link_to 'Back', project_stage_path(@project, @stage), :class => 'arrow_link'  %> 
     66 
     67<% content_for(:page_scripts) do %> 
     68  <script type="text/javascript"> 
     69  
     70    function show_disable_hosts(){ 
     71      $('h_e_h').show(); 
     72      $('s_e_h').hide(); 
     73      $('excluded_hosts').show(); 
     74    } 
     75    
     76    function hide_disable_hosts(){ 
     77      $('h_e_h').hide(); 
     78      $('s_e_h').show(); 
     79      $('excluded_hosts').hide(); 
     80    } 
     81     
     82    function disable_host(){ 
     83      var own_id = /host_(\d)_on/.exec(this.id)[1]; 
     84      var other_id = "host_" + own_id + '_off'; 
     85      console.log('in diable host ' + own_id + '. other: ' + other_id); 
     86      $(this).hide(); 
     87      $(other_id).show(); 
     88      $('deployment_excluded_host_ids_' + own_id).writeAttribute('checked', 'checked'); 
     89      $(this).up('tr').removeClassName('enabled_host'); 
     90      $(this).up('tr').addClassName('disabled_host'); 
     91    } 
     92     
     93    function enable_host(){ 
     94      var own_id = /host_(\d)_off/.exec(this.id)[1]; 
     95      var other_id = "host_" + own_id + '_on'; 
     96      console.log('in enable host ' + own_id + '. other: ' + other_id); 
     97      $(this).hide(); 
     98      $(other_id).show(); 
     99      $('deployment_excluded_host_ids_' + own_id).writeAttribute('checked', false); 
     100      $(this).up('tr').removeClassName('disabled_host'); 
     101      $(this).up('tr').addClassName('enabled_host'); 
     102    } 
     103     
     104    Event.observe(window, 'load', function(){ 
     105      <% unless @deployment.excluded_host_ids.blank? %> 
     106        show_disable_hosts(); 
     107      <% end %> 
     108       
     109      $$('img.exlcude_host_trigger_on').each(function(el){ 
     110        el.observe('click', disable_host); 
     111      }); 
     112       
     113      $$('img.exlcude_host_trigger_off').each(function(el){ 
     114        el.observe('click', enable_host); 
     115      }) 
     116    }); 
     117  </script> 
     118<% end %> 
  • trunk/app/views/stylesheets/application.html.erb

    r73 r90  
    604604.alt { 
    605605  background: #eef; 
     606} 
     607 
     608tr.disabled_host a{ 
     609        color: grey; 
    606610} 
    607611 
  • trunk/test/functional/deployments_controller_test.rb

    r42 r90  
    9393    assert_equal 1, Deployment.count 
    9494  end 
     95   
     96  def test_excluded_hosts 
     97    Deployment.delete_all 
     98    host_down = create_new_host 
     99    down_role = create_new_role(:stage => @stage, :name => 'foo', :host => host_down) 
     100     
     101    assert_equal 2, @stage.roles.count 
     102     
     103    post :create, :deployment => { :excluded_host_ids => [host_down.id],:task => 'deploy:default', :description => 'update to newest', :prompt_config => {} }, :project_id => @project.id, :stage_id => @stage.id 
     104     
     105    assert_equal 1, Deployment.count 
     106    deployment = Deployment.find(:first) 
     107    assert_equal [host_down], deployment.excluded_hosts 
     108    assert_equal [@role], deployment.deploy_to_roles 
     109  end 
    95110 
    96111end 
  • trunk/test/test_helper.rb

    r89 r90  
    6969  end 
    7070   
    71   def create_new_role(options = {}) 
    72     options = { 
    73       :stage => create_new_stage, 
    74       :host => create_new_host, 
    75       :name => random_string, 
    76       :primary => 0 
    77     }.update(options) 
    78      
    79     r = Role.new 
    80     r.name = options[:name] 
    81     r.stage = options[:stage] 
    82     r.host = options[:host] 
    83     r.primary = options[:primary] 
    84     r.save! 
    85      
    86     return r 
    87   end 
     71  # def create_new_role(options = {}) 
     72  #   options = { 
     73  #     :stage => create_new_stage, 
     74  #     :host => create_new_host, 
     75  #     :name => random_string, 
     76  #     :primary => 0 
     77  #   }.update(options) 
     78  #    
     79  #   r = Role.new 
     80  #   r.name = options[:name] 
     81  #   r.stage = options[:stage] 
     82  #   r.host = options[:host] 
     83  #   r.primary = options[:primary] 
     84  #   r.save! 
     85  #    
     86  #   return r 
     87  # end 
    8888   
    8989  def create_new_project_configuration(options = {}) 
  • trunk/test/unit/deployment_test.rb

    r89 r90  
    234234    assert_equal [host], deployment.excluded_hosts 
    235235     
    236     deployment.excluded_host_ids = host.id 
     236    deployment.excluded_host_ids = host.id.to_s 
    237237    assert_equal [host.id], deployment.excluded_host_ids 
    238238  end 
     
    246246    role_db = create_new_role(:name => 'db', :stage => stage, :host => host_2) 
    247247     
     248    stage.reload 
     249    assert_equal 3, stage.roles.count 
    248250    deployment = create_new_deployment( 
    249251                  :stage => stage,  
     
    257259  end 
    258260   
     261  def test_cannot_exclude_all_hosts 
     262    stage = create_new_stage 
     263    host = create_new_host 
     264    role_app = create_new_role(:name => 'app', :stage => stage, :host => host) 
     265     
     266    d = Deployment.new 
     267    d.task = 'foo' 
     268    d.stage = stage 
     269    d.description = 'foo bar' 
     270    d.excluded_host_ids = role_app.host.id 
     271    d.user = create_new_user 
     272 
     273    assert !d.valid? 
     274    assert d.errors.on('base') 
     275  end 
    259276   
    260277