Changeset 9 for trunk/perl/lib/Cornea/RecallTable.pm
- Timestamp:
- 08/22/09 20:38:53 (4 years ago)
- Files:
-
- trunk/perl/lib/Cornea/RecallTable.pm (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/perl/lib/Cornea/RecallTable.pm
r8 r9 9 9 my $config = Cornea::Config->new(); 10 10 my $dbh; 11 my $failed_err = undef; 11 12 my $dsns = $config->get_list("DB::dsn"); 12 13 Cornea::Utils::shuffle($dsns); … … 19 20 ); 20 21 }; 21 last unless ($@); 22 die "$dsn: $@\n" if $@; 23 last unless $@; 22 24 } 23 $self->{dbh} = shift; 25 print STDERR "$failed_err\n" if $failed_err; 26 $self->{dbh} = $dbh; 24 27 } 25 28 sub __reconnect { … … 32 35 my $self = bless { }, $class; 33 36 $self->__connect; 37 $self; 34 38 } 35 39 … … 46 50 }; 47 51 if ($@) { 48 unless ($tried++) { $self-> {dbh}->__reconnect(); goto again; }52 unless ($tried++) { $self->__reconnect(); goto again; } 49 53 die $@ if $@; 50 54 } … … 68 72 }; 69 73 if ($@) { 70 unless ($tried++) { $self-> {dbh}->__reconnect(); goto again; }74 unless ($tried++) { $self->__reconnect(); goto again; } 71 75 die $@ if $@; 72 76 } … … 90 94 }; 91 95 if ($@) { 92 unless ($tried++) { $self-> {dbh}->__reconnect(); goto again; }96 unless ($tried++) { $self->__reconnect(); goto again; } 93 97 die $@ if $@; 94 98 } 95 99 return $snl; 100 } 101 102 sub updateNode { 103 my $self = shift; 104 my $fqdn = shift; 105 my $attr = shift; 106 die "bad state" 107 unless $attr->{state} =~ /^(?:open|closed|offline|decommissioned)$/; 108 die "storage must be a number" 109 unless $attr->{total_storage} =~ /^[1-9]\d*$/ and 110 $attr->{used_storage} =~ /^[1-9]\d*$/; 111 die "locaion must be dc/cage/row/rack/pdu" 112 unless !defined($attr->{location}) or 113 $attr->{location} =~ /^[^\/]+(?:\/[^\/]+){4}$/; 114 115 my $tried = 0; 116 again: 117 eval { 118 my $sth = $self->{dbh}->prepare("select storeCorneaNode(?,?,?,?,?)"); 119 $sth->execute($attr->{state}, 120 $attr->{total_storage}, $attr->{used_storage}, 121 $attr->{location}, $fqdn); 122 $sth->finish(); 123 }; 124 if ($@) { 125 die "location must be specified for first-time update\n" 126 if $@ =~ /null value in column "location"/; 127 unless ($tried++) { $self->__reconnect(); goto again; } 128 die $@ if $@; 129 } 130 return 0; 96 131 } 97 132 … … 109 144 }; 110 145 if ($@) { 111 unless ($tried++) { $self-> {dbh}->__reconnect(); goto again; }146 unless ($tried++) { $self->__reconnect(); goto again; } 112 147 die $@ if $@; 113 148 } … … 131 166 }; 132 167 if ($@) { 133 unless ($tried++) { $self-> {dbh}->__reconnect(); goto again; }168 unless ($tried++) { $self->__reconnect(); goto again; } 134 169 die $@ if $@; 135 170 }
