« blib/lib/Video/DVDRip/GUI/FormFactory/ClipImage.pm
↑ Summary
blib/lib/Video/DVDRip/GUI/Project/ClipZoom.pm »
| 1 | # $Id: Node.pm 2304 2007-04-13 11:24:24Z joern $ | ||
| 2 | |||
| 3 | #----------------------------------------------------------------------- | ||
| 4 | # Copyright (C) 2001-2006 Jörn Reder <joern AT zyn.de>. | ||
| 5 | # All Rights Reserved. See file COPYRIGHT for details. | ||
| 6 | # | ||
| 7 | # This module is part of Video::DVDRip, which is free software; you can | ||
| 8 | # redistribute it and/or modify it under the same terms as Perl itself. | ||
| 9 | #----------------------------------------------------------------------- | ||
| 10 | |||
| 11 | package Video::DVDRip::GUI::Cluster::Node; | ||
| 12 | use Locale::TextDomain qw (video.dvdrip); | ||
| 13 | |||
| 14 | use base Video::DVDRip::GUI::Base; | ||
| 15 | |||
| 16 | use strict; | ||
| 17 | use Carp; | ||
| 18 | |||
| 19 | use FileHandle; | ||
| 20 | |||
| 21 | sub master { shift->{master} } | ||
| 22 | sub node { shift->{node} } | ||
| 23 | sub cluster_ff { shift->{cluster_ff} } | ||
| 24 | sub node_ff { shift->{node_ff} } | ||
| 25 | sub just_added { shift->{just_added} } | ||
| 26 | sub test_node { shift->{test_node} } | ||
| 27 | sub node_test_timeout { shift->{node_test_timeout} } | ||
| 28 | |||
| 29 | sub set_master { shift->{master} = $_[1] } | ||
| 30 | sub set_node { shift->{node} = $_[1] } | ||
| 31 | sub set_cluster_ff { shift->{cluster_ff} = $_[1] } | ||
| 32 | sub set_node_ff { shift->{node_ff} = $_[1] } | ||
| 33 | sub set_just_added { shift->{just_added} = $_[1] } | ||
| 34 | sub set_test_node { shift->{test_node} = $_[1] } | ||
| 35 | sub set_node_test_timeout { shift->{node_test_timeout} = $_[1] } | ||
| 36 | |||
| 37 | sub res_ssh_connect { shift->{res_ssh_connect} } | ||
| 38 | sub res_ssh_connect_details { shift->{res_ssh_connect_details} } | ||
| 39 | sub res_data_dir { shift->{res_data_dir} } | ||
| 40 | sub res_data_dir_node { shift->{res_data_dir_node} } | ||
| 41 | sub res_data_dir_master { shift->{res_data_dir_master} } | ||
| 42 | sub res_write_access { shift->{res_write_access} } | ||
| 43 | sub res_write_access_details { shift->{res_write_access_details} } | ||
| 44 | sub res_transcode { shift->{res_transcode} } | ||
| 45 | sub res_transcode_node { shift->{res_transcode_node} } | ||
| 46 | sub res_transcode_master { shift->{res_transcode_master} } | ||
| 47 | |||
| 48 | sub set_res_ssh_connect { shift->{res_ssh_connect} = $_[1] } | ||
| 49 | sub set_res_ssh_connect_details { shift->{res_ssh_connect_details}= $_[1] } | ||
| 50 | sub set_res_data_dir { shift->{res_data_dir} = $_[1] } | ||
| 51 | sub set_res_data_dir_node { shift->{res_data_dir_node} = $_[1] } | ||
| 52 | sub set_res_data_dir_master { shift->{res_data_dir_master} = $_[1] } | ||
| 53 | sub set_res_write_access { shift->{res_write_access} = $_[1] } | ||
| 54 | sub set_res_write_access_details{ shift->{res_write_access_details}=$_[1]} | ||
| 55 | sub set_res_transcode { shift->{res_transcode} = $_[1] } | ||
| 56 | sub set_res_transcode_node { shift->{res_transcode_node} = $_[1] } | ||
| 57 | sub set_res_transcode_master { shift->{res_transcode_master} = $_[1] } | ||
| 58 | |||
| 59 | # GUI Stuff ---------------------------------------------------------- | ||
| 60 | |||
| 61 | sub new { | ||
| 62 | my $class = shift; | ||
| 63 | my %par = @_; | ||
| 64 | my ( $master, $cluster_ff, $just_added, $node ) | ||
| 65 | = @par{ 'master', 'cluster_ff', 'just_added', 'node' }; | ||
| 66 | |||
| 67 | my $self = $class->SUPER::new(@_); | ||
| 68 | |||
| 69 | $self->set_form_factory($cluster_ff); | ||
| 70 | $self->set_master($master); | ||
| 71 | $self->set_node($node); | ||
| 72 | $self->set_cluster_ff($cluster_ff); | ||
| 73 | $self->set_just_added($just_added); | ||
| 74 | |||
| 75 | $cluster_ff->get_form_factory->get_context->set_object( | ||
| 76 | cluster_node_edited => $node, ); | ||
| 77 | $cluster_ff->get_form_factory->get_context->set_object( | ||
| 78 | cluster_node_gui => $self, ); | ||
| 79 | |||
| 80 | $self->set_res_ssh_connect( __ "Not tested yet" ); | ||
| 81 | $self->set_res_data_dir( __ "Not tested yet" ); | ||
| 82 | $self->set_res_transcode( __ "Not tested yet" ); | ||
| 83 | $self->set_res_write_access( __ "Not tested yet" ); | ||
| 84 | |||
| 85 | return $self; | ||
| 86 | } | ||
| 87 | |||
| 88 | sub open_window { | ||
| 89 | my $self = shift; | ||
| 90 | |||
| 91 | my $cluster_gui | ||
| 92 | = $self->cluster_ff->get_form_factory->get_context->get_object( | ||
| 93 | "cluster_gui"); | ||
| 94 | |||
| 95 | my $node_ff = Gtk2::Ex::FormFactory->new( | ||
| 96 | parent_ff => $self->cluster_ff, | ||
| 97 | context => $self->cluster_ff->get_context, | ||
| 98 | sync => 1, | ||
| 99 | content => [ | ||
| 100 | Gtk2::Ex::FormFactory::Window->new( | ||
| 101 | title => __ "dvd::rip - Edit cluster node", | ||
| 102 | customize_hook => sub { | ||
| 103 | my ($gtk_window) = @_; | ||
| 104 | $_[0]->parent->set( | ||
| 105 | default_width => 640, | ||
| 106 | default_height => 500, | ||
| 107 | ); | ||
| 108 | 1; | ||
| 109 | }, | ||
| 110 | closed_hook => sub { | ||
| 111 | $self->close_window; | ||
| 112 | 1; | ||
| 113 | }, | ||
| 114 | properties => { modal => 1, }, | ||
| 115 | content => [ | ||
| 116 | $self->build_node_form, $self->build_node_test_result, | ||
| 117 | $self->build_buttons | ||
| 118 | ], | ||
| 119 | ), | ||
| 120 | ], | ||
| 121 | ); | ||
| 122 | |||
| 123 | $node_ff->build; | ||
| 124 | $node_ff->show; | ||
| 125 | $node_ff->update; | ||
| 126 | |||
| 127 | $self->set_node_ff($node_ff); | ||
| 128 | |||
| 129 | 1; | ||
| 130 | } | ||
| 131 | |||
| 132 | sub close_window { | ||
| 133 | my $self = shift; | ||
| 134 | |||
| 135 | my $cluster_gui | ||
| 136 | = $self->cluster_ff->get_form_factory->get_context->get_object( | ||
| 137 | "cluster_gui"); | ||
| 138 | |||
| 139 | my $node_ff = $self->node_ff; | ||
| 140 | $node_ff->close if $node_ff; | ||
| 141 | $self->set_node_ff(undef); | ||
| 142 | $self->set_master(undef); | ||
| 143 | $cluster_gui->set_node_gui(undef); | ||
| 144 | |||
| 145 | $self->cluster_ff->get_form_factory->get_context->set_object( | ||
| 146 | cluster_node_gui => undef, ); | ||
| 147 | |||
| 148 | $self->cluster_ff->get_form_factory->get_context->set_object( | ||
| 149 | cluster_node_edited => undef, ); | ||
| 150 | |||
| 151 | 1; | ||
| 152 | } | ||
| 153 | |||
| 154 | sub build_node_form { | ||
| 155 | my $self = shift; | ||
| 156 | |||
| 157 | return Gtk2::Ex::FormFactory::Form->new( | ||
| 158 | title => __ "Edit node properties", | ||
| 159 | content => [ | ||
| 160 | Gtk2::Ex::FormFactory::Entry->new( | ||
| 161 | attr => "cluster_node_edited.name", | ||
| 162 | label => __ "Name", | ||
| 163 | tip => "Unique dvd::rip internal name of this node", | ||
| 164 | rules => "alphanumeric", | ||
| 165 | ), | ||
| 166 | Gtk2::Ex::FormFactory::Entry->new( | ||
| 167 | attr => "cluster_node_edited.hostname", | ||
| 168 | label => __ "Hostname", | ||
| 169 | tip => __ | ||
| 170 | "Network hostname of this node. Defaults to node name.", | ||
| 171 | rules => sub { | ||
| 172 | $_[0] =~ /^[a-z0-9_.-]+$/i | ||
| 173 | ? undef | ||
| 174 | : __ "No valid hostname"; | ||
| 175 | } | ||
| 176 | ), | ||
| 177 | Gtk2::Ex::FormFactory::Entry->new( | ||
| 178 | attr => "cluster_node_edited.data_base_dir", | ||
| 179 | label => __ "Local data directory", | ||
| 180 | tip => __ "This is the mount point of the dvd::rip " | ||
| 181 | . "data master directory on this node, e.g. " | ||
| 182 | . "connected via NFS or Samba", | ||
| 183 | ), | ||
| 184 | Gtk2::Ex::FormFactory::Combo->new( | ||
| 185 | attr => "cluster_node_edited.speed_index", | ||
| 186 | label => __ "Speed index", | ||
| 187 | tip => __ | ||
| 188 | "Enter an integer value indicating the speed of " | ||
| 189 | . "this node. The higher the value the faster it is. " | ||
| 190 | . "Faster nodes are preferred over slower nodes.", | ||
| 191 | presets => [ 100, 90, 80, 70, 60, 50, 40, 30, 20, 10 ], | ||
| 192 | ), | ||
| 193 | Gtk2::Ex::FormFactory::Entry->new( | ||
| 194 | attr => "cluster_node_edited.tc_options", | ||
| 195 | label => __ "Additional transcode options", | ||
| 196 | tip => __ | ||
| 197 | "You can specify additional transcode options for this " | ||
| 198 | . "node, e.g. -u 4,2 to increase the performance on a " | ||
| 199 | . "two processor machine", | ||
| 200 | ), | ||
| 201 | Gtk2::Ex::FormFactory::YesNo->new( | ||
| 202 | attr => "cluster_node_edited.data_is_local", | ||
| 203 | label => __ "Node has dvd::rip data harddrive?", | ||
| 204 | tip => __ | ||
| 205 | "If this node has the dvd::rip data hardrive locally " | ||
| 206 | . "connected, I/O intensive jobs are executed on this node " | ||
| 207 | . "with higher priority", | ||
| 208 | true_label => __"Yes", | ||
| 209 | false_label => __"No", | ||
| 210 | ), | ||
| 211 | Gtk2::Ex::FormFactory::YesNo->new( | ||
| 212 | attr => "cluster_node_edited.is_master", | ||
| 213 | label => __ "Node runs Cluster Control Daemon?", | ||
| 214 | tip => __ "Specify whether on this node runs the cluster " | ||
| 215 | . "control daemon. In that case no ssh remote command " | ||
| 216 | . "execution is neccessary", | ||
| 217 | true_label => __"Yes", | ||
| 218 | false_label => __"No", | ||
| 219 | ), | ||
| 220 | Gtk2::Ex::FormFactory::Entry->new( | ||
| 221 | attr => "cluster_node_edited.username", | ||
| 222 | label => __ "Username to connect with ssh", | ||
| 223 | tip => __ "You need to setup passwordless authorization via " | ||
| 224 | . "~/.ssh/authorized_keys for this user from " | ||
| 225 | . "the master server to the node", | ||
| 226 | rules => "alphanumeric", | ||
| 227 | ), | ||
| 228 | Gtk2::Ex::FormFactory::Entry->new( | ||
| 229 | attr => "cluster_node_edited.ssh_cmd", | ||
| 230 | label => __ "SSH command and options", | ||
| 231 | tip => __ | ||
| 232 | "Usually you leave this empty (defaults to 'ssh -x'), " | ||
| 233 | . "but if your setup needs special ssh options you may " | ||
| 234 | . "edit them here" | ||
| 235 | ), | ||
| 236 | Gtk2::Ex::FormFactory::HBox->new( | ||
| 237 | content => [ | ||
| 238 | Gtk2::Ex::FormFactory::Button->new( | ||
| 239 | name => "node_test_button", | ||
| 240 | label => __ "Test settings", | ||
| 241 | stock => "gtk-network", | ||
| 242 | expand => 0, | ||
| 243 | tip => __ | ||
| 244 | "This triggers a simple test connection to the node, " | ||
| 245 | . "checking file permissions, transcode versions etc.", | ||
| 246 | clicked_hook => sub { $self->node_test }, | ||
| 247 | ), | ||
| 248 | Gtk2::Ex::FormFactory::ProgressBar->new( | ||
| 249 | name => "node_test_progress", | ||
| 250 | expand => 1, | ||
| 251 | inactive => "invisible", | ||
| 252 | active_cond => sub { $self->node_test_timeout }, | ||
| 253 | active_depends => | ||
| 254 | "cluster_node_gui.node_test_timeout", | ||
| 255 | ), | ||
| 256 | ], | ||
| 257 | ), | ||
| 258 | ], | ||
| 259 | ); | ||
| 260 | } | ||
| 261 | |||
| 262 | sub build_node_test_result { | ||
| 263 | return Gtk2::Ex::FormFactory::VBox->new( | ||
| 264 | expand => 1, | ||
| 265 | content => [ | ||
| 266 | Gtk2::Ex::FormFactory::Label->new( | ||
| 267 | label => "\n" . __ "Node test results", | ||
| 268 | bold => 1, | ||
| 269 | ), | ||
| 270 | Gtk2::Ex::FormFactory::Table->new( | ||
| 271 | scrollbars => [ "automatic", "automatic" ], | ||
| 272 | expand => 1, | ||
| 273 | properties => { | ||
| 274 | column_spacing => 15, | ||
| 275 | row_spacing => 5, | ||
| 276 | border_width => 5, | ||
| 277 | }, | ||
| 278 | layout => " | ||
| 279 | +----------------+--------+----------------------------+ | ||
| 280 | ' What ' Status | Details | | ||
| 281 | +----------------+--------+----------------------------+ | ||
| 282 | | Separator | | ||
| 283 | +----------------+--------+----------------------------+ | ||
| 284 | ' SSH Connect ' Result | Details | | ||
| 285 | +----------------+--------+-------------+--------------+ | ||
| 286 | ' Data Access ' Result ' Node dir ' Master dir | | ||
| 287 | +----------------+--------+-------------+--------------+ | ||
| 288 | ' Write Access ' Result ' Details | | ||
| 289 | +----------------+--------+-------------+--------------+ | ||
| 290 | ' transcode ' Result ' Node tc ' Master tc | | ||
| 291 | +----------------+--------+----------------------------+ | ||
| 292 | ", | ||
| 293 | content => [ | ||
| 294 | |||
| 295 | #-- Header | ||
| 296 | Gtk2::Ex::FormFactory::Label->new( | ||
| 297 | label => __ "Test", | ||
| 298 | bold => 1, | ||
| 299 | ), | ||
| 300 | Gtk2::Ex::FormFactory::Label->new( | ||
| 301 | label => __ "Result", | ||
| 302 | bold => 1, | ||
| 303 | ), | ||
| 304 | Gtk2::Ex::FormFactory::Label->new( | ||
| 305 | label => __ "Details", | ||
| 306 | bold => 1, | ||
| 307 | ), | ||
| 308 | Gtk2::Ex::FormFactory::HSeparator->new, | ||
| 309 | |||
| 310 | #-- SSH Connection | ||
| 311 | Gtk2::Ex::FormFactory::Label->new( | ||
| 312 | label => __ "SSH connection", | ||
| 313 | ), | ||
| 314 | Gtk2::Ex::FormFactory::Label->new( | ||
| 315 | attr => "cluster_node_gui.res_ssh_connect", | ||
| 316 | with_markup => 1, | ||
| 317 | ), | ||
| 318 | Gtk2::Ex::FormFactory::Label->new( | ||
| 319 | attr => "cluster_node_gui.res_ssh_connect_details", | ||
| 320 | ), | ||
| 321 | |||
| 322 | #-- Data access | ||
| 323 | Gtk2::Ex::FormFactory::Label->new( | ||
| 324 | label => __ "Data directory", | ||
| 325 | ), | ||
| 326 | Gtk2::Ex::FormFactory::Label->new( | ||
| 327 | attr => "cluster_node_gui.res_data_dir", | ||
| 328 | with_markup => 1, | ||
| 329 | ), | ||
| 330 | Gtk2::Ex::FormFactory::Label->new( | ||
| 331 | attr => "cluster_node_gui.res_data_dir_node", | ||
| 332 | with_markup => 1, | ||
| 333 | properties => { wrap => 1, }, | ||
| 334 | ), | ||
| 335 | Gtk2::Ex::FormFactory::Label->new( | ||
| 336 | attr => "cluster_node_gui.res_data_dir_master", | ||
| 337 | with_markup => 1, | ||
| 338 | properties => { wrap => 1, }, | ||
| 339 | ), | ||
| 340 | |||
| 341 | #-- Data access | ||
| 342 | Gtk2::Ex::FormFactory::Label->new( | ||
| 343 | label => __ "Write access", | ||
| 344 | ), | ||
| 345 | Gtk2::Ex::FormFactory::Label->new( | ||
| 346 | attr => "cluster_node_gui.res_write_access", | ||
| 347 | with_markup => 1, | ||
| 348 | ), | ||
| 349 | Gtk2::Ex::FormFactory::Label->new( | ||
| 350 | attr => "cluster_node_gui.res_write_access_details", | ||
| 351 | with_markup => 1, | ||
| 352 | properties => { wrap => 1, }, | ||
| 353 | ), | ||
| 354 | |||
| 355 | #-- transcode version | ||
| 356 | Gtk2::Ex::FormFactory::Label->new( | ||
| 357 | label => __ "Program versions", | ||
| 358 | ), | ||
| 359 | Gtk2::Ex::FormFactory::Label->new( | ||
| 360 | attr => "cluster_node_gui.res_transcode", | ||
| 361 | with_markup => 1, | ||
| 362 | ), | ||
| 363 | Gtk2::Ex::FormFactory::Label->new( | ||
| 364 | attr => "cluster_node_gui.res_transcode_node", | ||
| 365 | with_markup => 1, | ||
| 366 | properties => { wrap => 1, }, | ||
| 367 | ), | ||
| 368 | Gtk2::Ex::FormFactory::Label->new( | ||
| 369 | attr => "cluster_node_gui.res_transcode_master", | ||
| 370 | with_markup => 1, | ||
| 371 | properties => { wrap => 1, }, | ||
| 372 | ), | ||
| 373 | ], | ||
| 374 | ), | ||
| 375 | ], | ||
| 376 | ); | ||
| 377 | } | ||
| 378 | |||
| 379 | sub build_buttons { | ||
| 380 | my $self = shift; | ||
| 381 | |||
| 382 | return Gtk2::Ex::FormFactory::DialogButtons->new( | ||
| 383 | clicked_hook_before => sub { | ||
| 384 | my ($button) = @_; | ||
| 385 | if ( $button eq 'ok' ) { | ||
| 386 | $self->node_ff->apply; | ||
| 387 | $self->master->add_node( node => $self->node ) | ||
| 388 | if $self->just_added; | ||
| 389 | $self->node->save; | ||
| 390 | return 1; | ||
| 391 | } | ||
| 392 | |||
| 393 | #-- return TRUE to activate Cancel | ||
| 394 | #-- Button Default Handler | ||
| 395 | 1; | ||
| 396 | }, | ||
| 397 | ); | ||
| 398 | } | ||
| 399 | |||
| 400 | sub node_test { | ||
| 401 | my $self = shift; | ||
| 402 | |||
| 403 | return if $self->node_test_timeout; | ||
| 404 | |||
| 405 | my $context = $self->cluster_ff->get_context; | ||
| 406 | |||
| 407 | # make a backup copy of the node and apply the | ||
| 408 | # form values to it | ||
| 409 | my $node = $self->node->clone; | ||
| 410 | my $proxy = $context->get_proxy("cluster_node_edited"); | ||
| 411 | $proxy->{object} = $node; | ||
| 412 | $self->node_ff->apply; | ||
| 413 | $proxy->{object} = $self->node; | ||
| 414 | |||
| 415 | $self->set_test_node($node); | ||
| 416 | |||
| 417 | my $gtk_progress | ||
| 418 | = $self->node_ff->get_widget("node_test_progress")->get_gtk_widget; | ||
| 419 | |||
| 420 | my $timeout = Glib::Timeout->add( 100, sub { $gtk_progress->pulse; 1; } ); | ||
| 421 | |||
| 422 | $self->set_node_test_timeout($timeout); | ||
| 423 | |||
| 424 | $context->update_object_attr_widgets( | ||
| 425 | "cluster_node_gui.node_test_timeout"); | ||
| 426 | |||
| 427 | # trigger test | ||
| 428 | $self->master->node_test( node => $node ); | ||
| 429 | |||
| 430 | 1; | ||
| 431 | } | ||
| 432 | |||
| 433 | sub trunc { | ||
| 434 | my ($str) = @_; | ||
| 435 | $str =~ s/^\s+//mg; | ||
| 436 | $str =~ s/\s+$//; | ||
| 437 | return $str; | ||
| 438 | } | ||
| 439 | |||
| 440 | sub stop_node_test_progress { | ||
| 441 | my $self = shift; | ||
| 442 | |||
| 443 | my $context = $self->cluster_ff->get_context; | ||
| 444 | |||
| 445 | Glib::Source->remove( $self->node_test_timeout ); | ||
| 446 | |||
| 447 | $self->set_node_test_timeout(undef); | ||
| 448 | |||
| 449 | $context->update_object_attr_widgets( | ||
| 450 | "cluster_node_gui.node_test_timeout"); | ||
| 451 | |||
| 452 | 1; | ||
| 453 | } | ||
| 454 | |||
| 455 | sub node_test_finished { | ||
| 456 | my $self = shift; | ||
| 457 | |||
| 458 | my $node = $self->test_node; | ||
| 459 | my $node_result = $node->test_result; | ||
| 460 | my $master_node = $self->master->get_master_node; | ||
| 461 | my $master_result = $master_node ? $master_node->test_result : $node_result; | ||
| 462 | my $context = $self->cluster_ff->get_context; | ||
| 463 | my $proxy = $context->get_proxy("cluster_node_gui"); | ||
| 464 | |||
| 465 | $self->stop_node_test_progress; | ||
| 466 | |||
| 467 | my $no_details = __ "No details available"; | ||
| 468 | my $no_details_no_ssh = __ "Not tested, no SSH connection!"; | ||
| 469 | my $ok = "<b>" . __("OK") . "</b>"; | ||
| 470 | my $not_ok = "<b>" . __("NOT OK") . "</b>"; | ||
| 471 | |||
| 472 | if ( $node_result->{ssh_connect} =~ /Ok/ ) { | ||
| 473 | $proxy->set_attrs( | ||
| 474 | { "res_ssh_connect" => $ok, | ||
| 475 | "res_ssh_connect_details" => __ "Master can connect to node" | ||
| 476 | } | ||
| 477 | ); | ||
| 478 | } | ||
| 479 | else { | ||
| 480 | $proxy->set_attrs( | ||
| 481 | { "res_ssh_connect" => $not_ok, | ||
| 482 | "res_ssh_connect_details" => trunc( $node_result->{output} ), | ||
| 483 | "res_data_dir" => $not_ok, | ||
| 484 | "res_data_dir_node" => $no_details_no_ssh, | ||
| 485 | "res_data_dir_master" => "", | ||
| 486 | "res_write_access" => $not_ok, | ||
| 487 | "res_write_access_details" => $no_details_no_ssh, | ||
| 488 | "res_transcode" => $not_ok, | ||
| 489 | "res_transcode_node" => $no_details_no_ssh, | ||
| 490 | } | ||
| 491 | ); | ||
| 492 | return; | ||
| 493 | } | ||
| 494 | |||
| 495 | my $node_content = trunc( $node_result->{data_base_dir_content} ); | ||
| 496 | my $master_content = trunc( $master_result->{data_base_dir_content} ); | ||
| 497 | if ( $node_content ne $master_content ) { | ||
| 498 | if ( $node_content eq '*' ) { | ||
| 499 | $node_content = __ "Empty"; | ||
| 500 | } | ||
| 501 | $node_content = "<b><u>" | ||
| 502 | . __("Node's data directory") | ||
| 503 | . "</u></b>\n" | ||
| 504 | . $node_content; | ||
| 505 | $master_content = "<b><u>" | ||
| 506 | . __("Masters' data directory") | ||
| 507 | . "</u></b>\n" | ||
| 508 | . $master_content; | ||
| 509 | |||
| 510 | $proxy->set_attrs( | ||
| 511 | { "res_data_dir" => $not_ok, | ||
| 512 | "res_data_dir_node" => $node_content, | ||
| 513 | "res_data_dir_master" => $master_content, | ||
| 514 | } | ||
| 515 | ); | ||
| 516 | } | ||
| 517 | else { | ||
| 518 | $proxy->set_attrs( | ||
| 519 | { "res_data_dir" => $ok, | ||
| 520 | "res_data_dir_node" => __ "Content of data directory matches", | ||
| 521 | "res_data_dir_master" => "", | ||
| 522 | } | ||
| 523 | ); | ||
| 524 | } | ||
| 525 | |||
| 526 | my $node_tc = trunc( $node_result->{program_versions} ); | ||
| 527 | my $master_tc = trunc( $master_result->{program_versions} ); | ||
| 528 | |||
| 529 | if ( $node_tc ne $master_tc ) { | ||
| 530 | $node_tc | ||
| 531 | = "<b><u>" . __("Node's programs") . "</u></b>\n" . $node_tc; | ||
| 532 | $master_tc = "<b><u>" | ||
| 533 | . __("Masters's programs") | ||
| 534 | . "</u></b>\n" | ||
| 535 | . $master_tc; | ||
| 536 | $proxy->set_attrs( | ||
| 537 | { "res_transcode" => $not_ok, | ||
| 538 | "res_transcode_node" => $node_tc, | ||
| 539 | "res_transcode_master" => $master_tc | ||
| 540 | } | ||
| 541 | ); | ||
| 542 | } | ||
| 543 | else { | ||
| 544 | $proxy->set_attrs( | ||
| 545 | { "res_transcode" => $ok, | ||
| 546 | "res_transcode_node" => $node_tc | ||
| 547 | } | ||
| 548 | ); | ||
| 549 | } | ||
| 550 | |||
| 551 | if ( $node_result->{write_test} =~ /SUCCESS/ ) { | ||
| 552 | $proxy->set_attrs( | ||
| 553 | { "res_write_access" => $ok, | ||
| 554 | "res_write_access_details" => __ | ||
| 555 | "Node can write to data directory", | ||
| 556 | } | ||
| 557 | ); | ||
| 558 | } | ||
| 559 | else { | ||
| 560 | $proxy->set_attrs( | ||
| 561 | { "res_write_access" => $not_ok, | ||
| 562 | "res_write_access_details" => | ||
| 563 | trunc( $node_result->{write_test} ), | ||
| 564 | } | ||
| 565 | ); | ||
| 566 | } | ||
| 567 | |||
| 568 | 1; | ||
| 569 | } | ||
| 570 | |||
| 571 | sub add_line_to_text_view { | ||
| 572 | my $self = shift; | ||
| 573 | my %par = @_; | ||
| 574 | my ( $line, $text_widget ) = @par{ 'line', 'text_widget' }; | ||
| 575 | |||
| 576 | my $buffer = $text_widget->get("buffer"); | ||
| 577 | my $iter = $buffer->get_end_iter; | ||
| 578 | $buffer->insert( $iter, $line ); | ||
| 579 | |||
| 580 | 1; | ||
| 581 | } | ||
| 582 | |||
| 583 | sub test_node_show_result { | ||
| 584 | my $self = shift; | ||
| 585 | my %par = @_; | ||
| 586 | my ( $node, $test_file, $text_widget ) | ||
| 587 | = @par{ 'node', 'test_file', 'text_widget' }; | ||
| 588 | |||
| 589 | my $result = $node->test_result; | ||
| 590 | |||
| 591 | #--------------------------------------------------------------- | ||
| 592 | # $result is a scalar containing a fatal error message, or | ||
| 593 | # a hash reference with the following keys: | ||
| 594 | # | ||
| 595 | # data_base_dir_content sorted content of the data_base_dir, | ||
| 596 | # or error message | ||
| 597 | # write_test SUCCESS if write was succesfull, | ||
| 598 | # or error message otherwise | ||
| 599 | # program_versions full output of program version numbers | ||
| 600 | #--------------------------------------------------------------- | ||
| 601 | |||
| 602 | if ( not ref $result ) { | ||
| 603 | $self->add_line_to_text_view( | ||
| 604 | text_widget => $text_widget, | ||
| 605 | line => __("Can't execute tests:") . "\n\n" . $result | ||
| 606 | ); | ||
| 607 | unlink $test_file; | ||
| 608 | return 1; | ||
| 609 | } | ||
| 610 | |||
| 611 | # now execute the test command on this machine | ||
| 612 | my $base_project_dir = $self->config('base_project_dir'); | ||
| 613 | my $local_command | ||
| 614 | = $node->get_test_command( data_base_dir => $base_project_dir ); | ||
| 615 | |||
| 616 | my $local_output = qx[ ($local_command) 2>&1 ]; | ||
| 617 | |||
| 618 | my $local_result = $node->parse_test_output( output => $local_output ); | ||
| 619 | |||
| 620 | # remove test file | ||
| 621 | unlink $test_file; | ||
| 622 | |||
| 623 | # check if results are equal | ||
| 624 | my $report; | ||
| 625 | my $details; | ||
| 626 | |||
| 627 | my %desc = ( | ||
| 628 | ssh_connect => __"ssh connect", | ||
| 629 | data_base_dir_content => __"Content of project base directory", | ||
| 630 | write_test => __"Project base directory writable", | ||
| 631 | program_versions => __"transcode version match", | ||
| 632 | ); | ||
| 633 | |||
| 634 | foreach my $case ( | ||
| 635 | qw ( ssh_connect data_base_dir_content write_test program_versions )) | ||
| 636 | { | ||
| 637 | $report .= "Test case : $desc{$case}\n"; | ||
| 638 | $report .= "Result : "; | ||
| 639 | |||
| 640 | if ( $result->{$case} eq $local_result->{$case} ) { | ||
| 641 | $report .= "Ok\n\n"; | ||
| 642 | } | ||
| 643 | else { | ||
| 644 | $report .= "Not Ok!\n\n"; | ||
| 645 | $details .= "Test case : $desc{$case}\n"; | ||
| 646 | if ( $case eq 'ssh_connect' ) { | ||
| 647 | $details .= "Node output :\n$result->{output}\n\n"; | ||
| 648 | last; | ||
| 649 | } | ||
| 650 | else { | ||
| 651 | $details .= "Node output :\n$result->{$case}\n\n"; | ||
| 652 | } | ||
| 653 | $details .= "Local output :\n$local_result->{$case}\n\n"; | ||
| 654 | } | ||
| 655 | } | ||
| 656 | |||
| 657 | $self->add_line_to_text_view( | ||
| 658 | text_widget => $text_widget, | ||
| 659 | line => __("All tests successful") . "\n\n" | ||
| 660 | ) | ||
| 661 | unless $details; | ||
| 662 | |||
| 663 | $self->add_line_to_text_view( | ||
| 664 | text_widget => $text_widget, | ||
| 665 | line => __("Brief report") . ":\n\n" . $report | ||
| 666 | ) | ||
| 667 | unless $details; | ||
| 668 | |||
| 669 | if ($details) { | ||
| 670 | if ( $result->{output_rest} =~ /\S/ ) { | ||
| 671 | $details .= "Unrecognized output :\n$result->{output_rest}\n\n"; | ||
| 672 | } | ||
| 673 | $self->add_line_to_text_view( | ||
| 674 | text_widget => $text_widget, | ||
| 675 | line => __("Detailed report") . ":\n\n" . $details | ||
| 676 | ); | ||
| 677 | } | ||
| 678 | |||
| 679 | 1; | ||
| 680 | } | ||
| 681 | |||
| 682 | 1; |