Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Data Structure Design

by Tuna (Friar)
on Aug 17, 2001 at 05:24 UTC ( [id://105593]=note: print w/replies, xml ) Need Help??


in reply to Data Structure Design

Follow up:

Here's an example of the data, and routines that I am working with:

$config_files{ $cluster } = [ $config_file ]; This contains: Key = Cluster_1 Value: remap.config, origin.db, local_cluster.db remap.config.hosts, origin.db.hosts, local_cluster.db.hosts

I get my hostnames by parsing the above ".hosts" files. "TS" hostnames are contained in remap.config.hosts. "SA" hostnames (zone files) are contained in the two other ".hosts" files.

TS servers must be reactivated first, then we attempt to reactivate the SA server. Then, we move on to the next cluster, assuming that the first succeeds.

So, ultimately, what I need to do, is foreach host, in order:

#####################7 # # # PROCESS SEQUENCES # # # ##################### @taskSequence = ( 'establishSession~~connecting to $clusterHost', 'local_checksum~~calculating local checksums', 'transferFilesToStage~~transferring files to $clusterHost: $cluster +StageDirectory', 'verifyPerms~~verifying file permissions', ); @activateSequence = ( 'activateTS~~$clusterHost: restarting traffic server with new confi +guration', 'activateSADNS~~$clusterHost: restarting SADNS with new configurati +on' ); @rollBackSequence = ( 'revertToExistingFiles~~$clusterHost: restarting using existing con +fig files', 'terminateSession~~$clusterHost: disconnecting from host' ); @offLineSequence = ( 'logBogusFiles~~$clusterHost: encountered corrupted files moved to +$errorLogDir', 'transferFilesToWorking~~$clusterHost: transferring previous files +to $clusterWorkingDirectory', 'takeClusterOffLine~~ $clusterHost is offline.'# < nsctl stop > ); @transferFile = ( 'copyFile~~copying file from remote host' ); #################################### # # MAIN # "foreach cluster" "foreach host, beginning with TA, then SA" @cleanUpTaskSequence = ('terminateSession~~disconnecting from host'); $executionStatus = &executeTaskSequence($clusterHost, @taskSequenc +e) ; $activationStatus = &executeTaskSequence($clusterHost, @activateSe +quence); $cleanUpStatus = &executeTaskSequence ($clusterHost, @cleanUpTaskS +equence);

Replies are listed 'Best First'.
Re: Re: Data Structure Design
by tachyon (Chancellor) on Aug 17, 2001 at 08:44 UTC

    Using your existing data structure (a hash of array refs) and assuming that an alphabetic key sort gives the desired activation order (OK for cluster1-9 but breaks at cluster 10) this is quick and dirty:

    my %config_files = ( cluster1 => ['1h1', 'h2', 'h3', 'h4', 'h5', 'h6', '1h7'], cluster2 => ['2h1', 'h2', 'h3', 'h4', 'h5', 'h6', '2h7'], cluster3 => ['3h1', 'h2', 'h3', 'h4', 'h5', 'h6', '3h7'], cluster4 => ['4h1', 'h2', 'h3', 'h4', 'h5', 'h6', '4h7'], cluster5 => ['5h1', 'h2', 'h3', 'h4', 'h*5', 'h6', '5h7'], ); my @order = sort keys %config_files; print "Order will be @order\n"; for my $cluster (@order) { print "Cluster is $cluster\n"; my @machines = @{$config_files{$cluster}}; my $last = pop @machines; for my $box (@machines) { &start_up($box) or &failed($cluster, $box); } &special($last); } print "Done\n"; exit; sub start_up { my $box = shift; return 0 if $box eq 'h*5'; # test failed routine # do stuff, return 1 for success 0 or undef for failure print "\tStarted $box\n"; 1; } sub special { # do box 7 stuff my $box = shift; print "\tSpecial $box\n"; 1; } sub failed { my ($cluster, $box) = @_; # do whatever you want like retry until sucess # then you return to loop and continue my $tries = 5; my $delay = 2; while ($tries) { $tries--; sleep $delay; print "Retrying $box in $cluster\n"; return if &start_up($box); } die "Unable to start $box in $cluster\n"; }

    cheers

    tachyon

    s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://105593]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2024-05-27 06:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found