/[Sack]/trunk/lib/Sack/Server.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/lib/Sack/Server.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 253 by dpavlin, Fri Nov 27 13:48:54 2009 UTC revision 264 by dpavlin, Mon Feb 1 22:03:02 2010 UTC
# Line 74  foreach my $host ( @cloud ) { Line 74  foreach my $host ( @cloud ) {
74    
75  my $session;  my $session;
76    
77    sub all_ports { keys %{ $session->{port} } }
78    
79  sub to_all {  sub to_all {
80          my $data = shift;          my $data = shift;
81          foreach my $port ( keys %{ $session->{port} } ) {          foreach my $port ( all_ports ) {
82                  warn ">>>> [$port]\n" if $debug;                  warn ">>>> [$port]\n" if $debug;
83                  Storable::store_fd( $data, $session->{port}->{$port} );                  Storable::store_fd( $data, $session->{port}->{$port} );
84          }          }
# Line 88  sub load_shard { Line 90  sub load_shard {
90    
91          warn "# load_shard $shard\n";          warn "# load_shard $shard\n";
92    
93          my @shards = glob "$shard/*";          $shard .= '/*' if -d $shard;
94    
95            my @shards = glob $shard;
96    
97          if ( ! @shards ) {          if ( ! @shards ) {
98                  warn "no shards for $shard\n";                  warn "no shards for $shard\n";
# Line 96  sub load_shard { Line 100  sub load_shard {
100          }          }
101    
102          foreach my $s ( @shards ) {          foreach my $s ( @shards ) {
103                  next if $info->{shard}->{$s} =~ m{^\d+$};                  if ( my $node = $info->{shard}->{$s} ) {
104                            next if $node =~ m{^\d+$}; # not node number
105                    }
106                  $info->{shard}->{$s} = 'wait';                  $info->{shard}->{$s} = 'wait';
107                  push @shard_load_queue, $s;                  push @shard_load_queue, $s;
108                  warn "queued $s for loading\n";                  warn "queued $s for loading\n";
109          }          }
110          to_all { load => $shard };          to_all { load => $shard };
111            $info->{pending}->{$_} = 'load' foreach all_ports;
112  }  }
113    
114  sub run_view {  sub run_view {
# Line 115  sub run_view { Line 122  sub run_view {
122          delete( $info->{view} );          delete( $info->{view} );
123          delete( $info->{merge} );          delete( $info->{merge} );
124          delete( $info->{shard} );          delete( $info->{shard} );
125            $info->{pending}->{$_} = 'view' foreach all_ports;
126          to_all { code => $code, view => $path };          to_all { code => $code, view => $path };
127  };  };
128    
# Line 164  while (1) { Line 172  while (1) {
172                                          warn "ERROR: $@" if $@;                                          warn "ERROR: $@" if $@;
173                                  }                                  }
174    
175                                  print $send "HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n";                                  my $refresh = $param->{refresh};
176                                    $refresh = 1 if keys %{ $info->{pending} };
177    
178                                    print $send "HTTP/1.0 200 OK\r\nContent-Type: text/html"
179                                            , ( $refresh ? "\r\nRefresh: $refresh" : '' )
180                                            , "\r\n\r\n"
181                                            , ( $refresh ? qq|<span style="color: #888; float:right">$refresh</span>| : '' )
182                                    ;
183    
184                                  print $send qq|                                  print $send qq|
185    
# Line 176  while (1) { Line 191  while (1) {
191    
192    
193  .forked {  .forked {
194          color: #f00;  //      text-decoration: line-through;
195  }  }
196    
197  .ping {  .ping {
198            color: #ff0;
199    }
200    
201    .load {
202            color: #f00;
203    }
204    
205    .view {
206            color: #00f;
207    }
208    
209    .ready {
210          color: #0f0;          color: #0f0;
211  }  }
212    
# Line 202  while (1) { Line 229  while (1) {
229    
230  |;  |;
231    
232                                    my $out = Sack::Merge->out;    
233                                    if ( my $li = join("\n", map { qq|<li><input type=checkbox name=filter value="$_"><a href="/out/$_" target="$_">$_</a>| } keys %$out ) ) {
234                                            print $send qq|<h1>Results</h1><form method="get" target="gnuplot" action="/gnuplot/"><ul>$li</ul><input type=submit value="Show checked"></form><img src="/gnuplot/">\n|;
235                                    }
236    
237                                  print $send qq|<h1>Views</h1><ul>|                                  print $send qq|<h1>Views</h1><ul>|
238                                          , join("\n", map {                                          , join("\n", map {
239                                                  my $view = $_;                                                  my $view = $_;
# Line 233  while (1) { Line 265  while (1) {
265                                          , qq|</ul>|                                          , qq|</ul>|
266                                          ;                                          ;
267    
268                                  my $out = Sack::Merge->out;                                      print $send qq|<h1>Nodes</h1>|;
269                                  if ( my $li = join("\n", map { qq|<li><input type=checkbox name=filter value="$_"><a href="/out/$_" target="$_">$_</a>| } keys %$out ) ) {                                  foreach my $node ( keys %{ $info->{node} } ) {
270                                          print $send qq|<h1>Results</h1><form method="get" target="gnuplot" action="/gnuplot/"><ul>$li</ul><input type=submit value="Show checked"></form><img src="/gnuplot/">\n|;                                          my $class = join(' '
271                                                    , map { $_->[0] } @{ $info->{node}->{$node} }
272                                            );
273                                            $class .= ' ' . ( $info->{pending}->{$node} || 'ready' );
274                                            print $send qq|<tt class="$class">$node</tt>\n|;
275                                  }                                  }
276    
                                 print $send qq|<h1>Nodes</h1>  
                                 |, join("\n", map {  
                                         my $class = join(' ', map { $_->[0] } @{ $info->{node}->{$_} });  
                                         qq|<tt class="$class">$_</tt>|;  
                                 } sort keys %{ $info->{node} } );  
   
277                                  print $send qq|<h1>Shards</h1><ul>|;                                  print $send qq|<h1>Shards</h1><ul>|;
278                                  foreach my $path ( glob '/tmp/sack/*' ) {                                  foreach my $path ( glob '/tmp/sack/*' ) {
279                                          print $send qq|<li><a href="$path">$path</a><div class="shards">|;                                          print $send qq|<li><a href="$path">$path</a><div class="shards">|;
# Line 321  while (1) { Line 351  while (1) {
351                                                  Storable::store_fd( { path => $path, shard => $shard }, $sock );                                                  Storable::store_fd( { path => $path, shard => $shard }, $sock );
352                                          } else {                                          } else {
353                                                  warn "no more shards for [", $data->{port}, "]\n";                                                  warn "no more shards for [", $data->{port}, "]\n";
354                                                    delete $info->{pending}->{ $data->{port} };
355                                          }                                          }
356                                  } elsif ( exists $data->{out} ) {                                  } elsif ( exists $data->{out} ) {
357                                          my $added = Sack::Merge->add( $data->{out} ) if defined $data->{out};                                          my $added = Sack::Merge->add( $data->{out} ) if defined $data->{out};
# Line 328  while (1) { Line 359  while (1) {
359                                          $info->{view }->{ $data->{view} }->{ $data->{port} } = $data->{on_shard};                                          $info->{view }->{ $data->{view} }->{ $data->{port} } = $data->{on_shard};
360                                          # refresh shard allocation                                          # refresh shard allocation
361                                          $info->{shard}->{ $_ } = $data->{port} foreach keys %{ $data->{on_shard} };                                          $info->{shard}->{ $_ } = $data->{port} foreach keys %{ $data->{on_shard} };
362                                            delete $info->{pending}->{ $data->{port} };
363                                  } elsif ( exists $data->{port} ) {                                  } elsif ( exists $data->{port} ) {
364                                          push @responses, $data;                                          push @responses, $data;
365                                          warn "# ",dump($data),$/;                                          warn "# ",dump($data),$/;

Legend:
Removed from v.253  
changed lines
  Added in v.264

  ViewVC Help
Powered by ViewVC 1.1.26