[Swift-commit] r3426 - in usertools/swift/swiftconfig: bin etc

noreply at svn.ci.uchicago.edu noreply at svn.ci.uchicago.edu
Mon Jul 5 03:31:55 CDT 2010


Author: davidk
Date: 2010-07-05 03:31:54 -0500 (Mon, 05 Jul 2010)
New Revision: 3426

Modified:
   usertools/swift/swiftconfig/bin/swiftconfig
   usertools/swift/swiftconfig/etc/sites-template.xml
Log:
/home/david replacement in templates, site profiles, tc command removals

Modified: usertools/swift/swiftconfig/bin/swiftconfig
===================================================================
--- usertools/swift/swiftconfig/bin/swiftconfig	2010-07-02 15:57:21 UTC (rev 3425)
+++ usertools/swift/swiftconfig/bin/swiftconfig	2010-07-05 08:31:54 UTC (rev 3426)
@@ -1,223 +1,255 @@
 #!/usr/bin/perl
 
 # Find swift configuration files and libraries
-if($ENV{'SWIFT_HOME'})
-{
-	$swifthome = $ENV{'SWIFT_HOME'};
+if ( $ENV{'SWIFT_HOME'} ) {
+    $swifthome = $ENV{'SWIFT_HOME'};
 }
-else
-{
-	@path = split('/', which("swift"));
-	@path = splice(@path, 0, $#path-1);
-	$swifthome = join('/', @path);
+else {
+    @path = split( '/', which("swift") );
+    @path = splice( @path, 0, $#path - 1 );
+    $swifthome = join( '/', @path );
 }
 
-use FindBin;                 
-use lib "$FindBin::Bin/../lib/perl";  # Use libraries in $swifthome/lib/perl
+use FindBin;
+use lib "$FindBin::Bin/../lib/perl";    # Use libraries in $swifthome/lib/perl
 use Getopt::Long;
 use File::Which qw(which where);
 use XML::Simple;
 
-
 # Variables used for translation catalog
-my $host = 'localhost';			# Host name
-my $name = '';				# Translation name
-my $path = 'null';			# Full path of executable location
-my $status = 'INSTALLED';		# Installation status (not used)
-my $platform = 'INTEL32::LINUX';	# Platform (not used)
-my $profile = 'null';			# Profile entries
-my $tcfile = "$swifthome/etc/tc.data";	# Location of TC file
+my $host     = 'localhost';                 # Host name
+my $name     = '';                          # Translation name
+my $path     = "/usr/bin/$name";            # Full path of executable location
+my $status   = 'INSTALLED';                 # Installation status (not used)
+my $platform = 'INTEL32::LINUX';            # Platform (not used)
+my $profile  = 'null';                      # Profile entries
+my $tcfile   = "$swifthome/etc/tc.data";    # Location of TC file
 
 # Variables used for sites.xml
-my $templatefile = "$swifthome/etc/sites-template.xml";	# Template file 
-my $template = '';					# Use template entry
-my $templates = 0;					# List all templates
-my $sitesfile = "$swifthome/etc/sites.xml";		# Working sites.xml file
-my $entry = '';						# Name of new entry (pool handle)
-my $gridftp = '';					# Specify gridftp URL
-my $jobuniverse = '';					# Specify jobmanager universe
-my $joburl = '';					# Specify jobmanager URL
-my $jobmajor = '';					# Jobmanager major value
-my $jobminor = '';					# Jobmanager minor value
-my $directory = '';					# Work directory
-my $exprovider = '';					# Execution provider
-my $exmanager = '';					# Execution job manager
-my $exurl = '';						# Execution URL
-my $remove = '';					# Remove entry from sites.xml
-my $modify = '';					# Modify mode
+my $templatefile = "$swifthome/etc/sites-template.xml"; # Template file
+my $template     = '';                                  # Use template entry
+my $templates    = 0;                                   # List all templates
+my $sitesfile    = "$swifthome/etc/sites.xml";          # Working sites.xml file
+my $entry       = '';    # Name of new entry (pool handle)
+my $gridftp     = '';    # Specify gridftp URL
+my $jobuniverse = '';    # Specify jobmanager universe
+my $joburl      = '';    # Specify jobmanager URL
+my $jobmajor    = '';    # Jobmanager major value
+my $jobminor    = '';    # Jobmanager minor value
+my $directory   = '';    # Work directory
+my $exprovider  = '';    # Execution provider
+my $exmanager   = '';    # Execution job manager
+my $exurl       = '';    # Execution URL
+my $remove      = '';    # Remove entry from sites.xml
+my $modify      = '';    # Modify mode
 
 # Assign variables from command line options
 GetOptions(
-		'host=s' => \$host,
-		'name=s' => \$name,
-		'path=s' => \$path,
-		'status=s' => \$status,
-		'platform=s' => \$platform,
-		'profile=s' => \$profile,
-		'tcfile=s' => \$tcfile,
-		'overwrite' => \$overwrite,
-		'templatefile=s' => \$templatefile,
-		'add=s' => \$add,
-		'sitesfile=s' => \$sitesfile,
-		'gridftp=s' => \$gridftp,
-		'jobuniverse=s' => \$jobuniverse,
-		'joburl=s' => \$joburl,
-		'jobmajor=i' => \$jobmajor,
-		'jobminor=i' => \$jobminor,
-		'directory=s' => \$directory,
-		'exprovider=s' => \$exprovider,
-		'exmanager=s' => \$exmanager,
-		'exurl=s' => \$exurl,
-		'remove=s' => \$remove,
-		'templates' => \$templates,
-		'modify=s' => \$modify
+    'host=s'         => \$host,
+    'name=s'         => \$name,
+    'path=s'         => \$path,
+    'status=s'       => \$status,
+    'platform=s'     => \$platform,
+    'profile=s'      => \$profile,
+    'tcfile=s'       => \$tcfile,
+    'overwrite'      => \$overwrite,
+    'templatefile=s' => \$templatefile,
+    'add=s'          => \$add,
+    'sitesfile=s'    => \$sitesfile,
+    'gridftp=s'      => \$gridftp,
+    'jobuniverse=s'  => \$jobuniverse,
+    'joburl=s'       => \$joburl,
+    'jobmajor=i'     => \$jobmajor,
+    'jobminor=i'     => \$jobminor,
+    'directory=s'    => \$directory,
+    'exprovider=s'   => \$exprovider,
+    'exmanager=s'    => \$exmanager,
+    'exurl=s'        => \$exurl,
+    'remove=s'       => \$remove,
+    'templates'      => \$templates,
+    'modify=s'       => \$modify,
+    'profile=s'      => \$profile,
+    'key=s'          => \$key,
+    'namespace=s'    => \$namespace,
+    'value=s'        => \$value
 );
 
-$xml = new XML::Simple();
+# Prepare data
+$xml           = new XML::Simple();
+$template_data = $xml->XMLin(
+    "$templatefile",
+    ForceArray => [qw(workdirectory pool profile)],
+    KeyAttr    => []
+);
+$sites_data = $xml->XMLin(
+    "$sitesfile",
+    ForceArray => [qw(workdirectory pool profile)],
+    KeyAttr    => []
+);
+open( TCFILESTREAM, "$tcfile" ) or die("Unable to open tc file $tcfile!");
+ at tcdata = <TCFILESTREAM>;
+close(TCFILESTREAM);
 
 # Update XML hash with values from command line
-sub update_xml_entry
-{
-	my $xml_data = @_[0];
-	my $name = @_[1];
-	foreach my $e (@{$xml_data->{pool}})
-	{
-		if($name eq $e->{handle})
-		{ 
-			if($gridftp){ $e->{gridftp}{url} = $gridftp; }
-			if($jobuniverse){ $e->{jobmanager}{universe} = $jobuniverse; }
-			if($joburl){ $e->{jobmanager}{url} = $joburl; }
-			if($jobmajor){ $e->{jobmanager}{major} = $jobmajor; }
-			if($jobminor){ $e->{jobmanager}{minor} = $jobminor; }
-			if($directory){ $e->{workdirectory} = [$directory]; }
-			if($exprovider){ $e->{execution}{provider} = $exprovider; }
-			if($exmanager){ $e->{execution}{jobmanager} = $exmanager; }
-			if($exurl){ $e->{execution}{url} = $exurl; }		
-			return $e;
-		}
-	}
+sub update_xml_entry {
+    my $xml_data = @_[0];
+    my $name     = @_[1];
+    foreach my $e ( @{ $xml_data->{pool} } ) {
+        if ( $name eq $e->{handle} ) {
+            $e->{workdirectory}[0] =~ s/\$HOME/$ENV{'HOME'}/;
+            if ($gridftp)     { $e->{gridftp}{url}          = $gridftp; }
+            if ($jobuniverse) { $e->{jobmanager}{universe}  = $jobuniverse; }
+            if ($joburl)      { $e->{jobmanager}{url}       = $joburl; }
+            if ($jobmajor)    { $e->{jobmanager}{major}     = $jobmajor; }
+            if ($jobminor)    { $e->{jobmanager}{minor}     = $jobminor; }
+            if ($directory)   { $e->{workdirectory}         = [$directory]; }
+            if ($exprovider)  { $e->{execution}{provider}   = $exprovider; }
+            if ($exmanager)   { $e->{execution}{jobmanager} = $exmanager; }
+            if ($exurl)       { $e->{execution}{url}        = $exurl; }
+
+            if ( $key && $namespace && $value ) {
+                my $found = 0;
+                foreach my $profile ( @{ $e->{profile} } ) {
+                    if ( $profile->{key} eq $key ) {
+                        $profile->{key}       = $key;
+                        $profile->{namespace} = $namespace;
+                        $profile->{content}   = $value;
+                        $found                = 1;
+                    }
+                }
+                if ( !$found ) {
+                    push @{ $e->{profile} },
+                      {
+                        key       => $key,
+                        namespace => $namespace,
+                        content   => $value
+                      };
+                }
+            }
+            return $e;
+        }
+    }
 }
 
 # Write a file given variable and filename
-sub write_file
-{
-	my ($filename, @data) = @_;
-	open(TEMPFILESTREAM, ">$filename") or die("Unable to open $filename!\n");
-	print TEMPFILESTREAM @data;
-	close(TEMPFILESTREAM);
+sub write_file {
+    my ( $filename, @data ) = @_;
+    open( TEMPFILESTREAM, ">$filename" ) or die("Unable to open $filename!\n");
+    print TEMPFILESTREAM @data;
+    close(TEMPFILESTREAM);
 }
 
 # If a template is specified, find the correct one and modify as needed
-if($add)
-{
-	$data = $xml->XMLin("$templatefile", ForceArray => [qw(workdirectory pool)]);
-	$data = update_xml_entry($data, $add);
+if ($add) {
+    my $data = update_xml_entry( $template_data, $add );
 
-	# Modify entry if one already exists
-	$isfound = 0;	
-	$data2 = $xml->XMLin("$sitesfile", ForceArray => [qw(workdirectory pool)]);
-	foreach my $e (@{$data2->{pool}})
-	{
-		if($add eq $e->{handle})
-		{ 
-			$e = $data;
-			$isfound = 1;			
-		}
-	}
+    # Modify existing entry
+    my $isfound = 0;
+    foreach my $e ( @{ $sites_data->{pool} } ) {
+        if ( $add eq $e->{handle} ) {
+            $e       = $data;
+            $isfound = 1;
+        }
+    }
 
-	# Add a new entry if needed
-	if(!$isfound)
-	{
-		push @{$data2->{pool}}, $data;
-	}
+    # Add new entry
+    if ( !$isfound ) {
+        push @{ $sites_data->{pool} }, $data;
+    }
 
-	# Write to sites file
-	write_file($sitesfile, $xml->XMLout($data2, RootName => 'config'));
+    # Write to sites file
+    write_file( $sitesfile, $xml->XMLout( $sites_data, RootName => 'config' ) );
 }
 
 # Remove an entry
-if($remove)
-{
-	$isfound=0;
-	$data = $xml->XMLin("$sitesfile", ForceArray => [qw(workdirectory pool)], SuppressEmpty => 1);
-	
-	foreach my $e (@{$data->{pool}})
-	{
-		if($remove eq $e->{handle})
-		{ 
-			undef $e;
-			$isfound = 1;
-		}
-	}
+if ($remove) {
 
-	# Write to sites file
-	if($isfound)
-	{
-		write_file($sitesfile, $xml->XMLout($data, RootName => 'config', SuppressEmpty => 1));
-	}
+    # Look first for a site to remove
+    $isfound = 0;
+
+    foreach my $e ( @{ $sites_data->{pool} } ) {
+        if ( $remove eq $e->{handle} ) {
+            undef $e;
+            $isfound = 1;
+        }
+    }
+
+    # Write to sites file
+    if ($isfound) {
+        write_file(
+            $sitesfile,
+            $xml->XMLout(
+                $sites_data,
+                RootName      => 'config',
+                SuppressEmpty => 1
+            )
+        );
+    }
+
+    # If no site found, check for a TC entry
+    else {
+        foreach $line (@tcdata) {
+
+            # Ignore comments
+            if ( substr( $line, 0, 1 ) eq '#' ) {
+                next;
+            }
+            ( $tmphost, $tmpname, @junk ) = split( /\s+/, $line );
+
+            # Replace old entry with new entry
+            if ( $remove eq $tmpname ) {
+                $line = "";
+            }
+        }
+        write_file( $tcfile, @tcdata );
+    }
 }
 
 # List all available templates
-if($templates)
-{
-	$data = $xml->XMLin("$templatefile", ForceArray => [qw(workdirectory pool)]);
-	foreach my $e (@{$data->{pool}})
-	{
-		print $e->{handle} . "\n";
-	}
+if ($templates) {
+    foreach my $e ( @{ $template_data->{pool} } ) {
+        print $e->{handle} . "\n";
+    }
 }
 
-# Modify an entry
-if($modify)
-{
-	$data = $xml->XMLin("$sitesfile", ForceArray => [qw(workdirectory pool)]);
-	$data2 = update_xml_entry($data, $modify);
+# Modify a site entry
+if ($modify) {
+    my $data = update_xml_entry( $sites_data, $modify );
 
-	# Modify entry if one already exists
-	foreach my $e (@{$data->{pool}})
-	{
-		if($modify eq $e->{handle})
-		{ 
-			$e = $data2;
-			$isfound = 1;			
-		}
-	}
+    # Modify entry if one already exists
+    foreach my $e ( @{ $sites_data->{pool} } ) {
+        if ( $modify eq $e->{handle} ) {
+            $e = $data;
+        }
+    }
 
-	write_file($sitesfile, $xml->XMLout($data, RootName => 'config', SuppressEmpty => 1));
+    write_file( $sitesfile,
+        $xml->XMLout( $sites_data, RootName => 'config', SuppressEmpty => 1 ) );
 }
 
-# Add an entry to tc.data
-if($name)
-{
-	open(TCFILESTREAM, "$tcfile") or die("Unable to open tc file $tcfile!");
-	@TCDATA = <TCFILESTREAM>;
-	close(TCFILESTREAM);
+# Add or modify a TC entry
+if ($name) {
+    foreach $line (@tcdata) {
 
-	foreach $line (@TCDATA)
-	{
-		# Ignore comments
-		if(substr($line, 0, 1) eq '#')
-		{
-			$line = "";
-			next;
-		}
-		($tmphost, $tmpname, @junk) = split(/\s+/, $line);
-	
-		# Replace old entry with new entry
-		if($name eq $tmpname && $host eq $tmphost)
-		{
-			$isfound=1;
-			$line = "\n$host\t$name\t$path\t$status\t$platform\t$profile\n";
-		}
-	}
+        # Ignore comments
+        if ( substr( $line, 0, 1 ) eq '#' ) {
+            next;
+        }
+        ( $tmphost, $tmpname, @junk ) = split( /\s+/, $line );
 
-	# Add new entry
-	if(!$isfound)
-	{
-		push(@TCDATA, "\n$host\t$name\t$path\t$status\t$platform\t$profile\n")
-	}
+        # Replace old entry with new entry
+        if ( $name eq $tmpname && $host eq $tmphost ) {
+            $isfound = 1;
+            $line    = "$host\t$name\t$path\t$status\t$platform\t$profile\n";
+        }
+    }
 
-	# Write to tc.data
-	write_file($tcfile, @TCDATA);
+    # Add new entry
+    if ( !$isfound ) {
+        push( @tcdata, "$host\t$name\t$path\t$status\t$platform\t$profile\n" );
+    }
+
+    # Write to tc.data
+    write_file( $tcfile, @tcdata );
 }
 

Modified: usertools/swift/swiftconfig/etc/sites-template.xml
===================================================================
--- usertools/swift/swiftconfig/etc/sites-template.xml	2010-07-02 15:57:21 UTC (rev 3425)
+++ usertools/swift/swiftconfig/etc/sites-template.xml	2010-07-05 08:31:54 UTC (rev 3426)
@@ -2,14 +2,14 @@
   <pool handle="multisite-ssh">
     <filesystem provider="ssh" url="login1.pads.ci.uchicago.edu" />
     <execution provider="ssh" url="login1.pads.ci.uchicago.edu" />
-    <workdirectory>/home/arjun/swiftwork</workdirectory>
+    <workdirectory>$HOME/swiftwork</workdirectory>
     <profile namespace="karajan" key="jobThrottle">0</profile>
   </pool>
 
   <pool handle="teraport">
     <filesystem provider="ssh" url="tp-login2.ci.uchicago.edu" />
     <execution provider="ssh" url="tp-login2.ci.uchicago.edu"	/>
-    <workdirectory>/home/arjun/swiftwork</workdirectory>
+    <workdirectory>$HOME/swiftwork</workdirectory>
     <profile namespace="karajan" key="jobThrottle">0</profile>
   </pool>
 
@@ -24,7 +24,7 @@
    <profile namespace="karajan" key="jobThrottle">0.5</profile>
    <profile namespace="karajan" key="initialScore">10000</profile>
    <filesystem provider="ssh" url="login1.pads.ci.uchicago.edu"/>
-   <workdirectory>/home/arjun/swiftwork</workdirectory>
+   <workdirectory>$HOME/swiftwork</workdirectory>
  </pool>
 
   <pool handle="teraport-remote-pbs-coasters-ssh">
@@ -38,13 +38,13 @@
    <profile namespace="karajan" key="jobThrottle">0.5</profile>
    <profile namespace="karajan" key="initialScore">10000</profile>
    <filesystem provider="ssh" url="tp-login2.ci.uchicago.edu"/>
-   <workdirectory>/home/arjun/swiftwork</workdirectory>
+   <workdirectory>$HOME/swiftwork</workdirectory>
  </pool>
 
   <pool handle="teraport-local-pbs-coasters">
     <filesystem provider="local" url="none" />
     <execution provider="coaster" url="none" jobmanager="local:pbs" />
-    <workdirectory>/home/arjun/swiftwork</workdirectory>
+    <workdirectory>$HOME/swiftwork</workdirectory>
     <profile namespace="globus" key="maxtime">3000</profile>
     <profile namespace="globus" key="workersPerNode">8</profile>
     <profile namespace="globus" key="slots">1</profile>
@@ -58,7 +58,7 @@
   <pool handle="pads-local-pbs-coasters">
     <filesystem provider="local" url="none" />
     <execution provider="coaster" url="none" jobmanager="local:pbs" />
-    <workdirectory>/home/arjun/swiftwork</workdirectory>
+    <workdirectory>$HOME/swiftwork</workdirectory>
     <profile namespace="globus" key="maxtime">3000</profile>
     <profile namespace="globus" key="workersPerNode">8</profile>
     <profile namespace="globus" key="slots">1</profile>
@@ -72,28 +72,28 @@
   <pool handle="pads-remote-ssh">
     <filesystem url="login1.pads.ci.uchicago.edu" provider="ssh"/>
     <execution url="login1.pads.ci.uchicago.edu" provider="ssh"/>
-    <workdirectory >/home/arjun/swiftwork</workdirectory>
+    <workdirectory >$HOME/swiftwork</workdirectory>
     <profile namespace="karajan" key="jobThrottle">0</profile>
   </pool>
 
   <pool handle="teraport-remote-ssh">
     <filesystem url="tp-login2.ci.uchicago.edu" provider="ssh"/>
     <execution url="tp-login2.ci.uchicago.edu" provider="ssh"/>
-    <workdirectory >/home/arjun/swiftwork</workdirectory>
+    <workdirectory >$HOME/swiftwork</workdirectory>
     <profile namespace="karajan" key="jobThrottle">0</profile>
   </pool>
 
   <pool handle="pads-local-pbs">
     <filesystem provider="local" url="none" />
     <execution provider="local" url="none" jobmanager="local:pbs" />
-    <workdirectory>/home/arjun/swiftwork</workdirectory>
+    <workdirectory>$HOME/swiftwork</workdirectory>
     <profile namespace="karajan" key="jobThrottle">0</profile>
   </pool>
 
   <pool handle="teraport-local-pbs">
     <filesystem provider="local" url="none" />
     <execution provider="local" url="none" jobmanager="local:pbs" />
-    <workdirectory>/home/arjun/swiftwork</workdirectory>
+    <workdirectory>$HOME/swiftwork</workdirectory>
     <profile namespace="karajan" key="jobThrottle">0</profile>
   </pool>
 
@@ -108,7 +108,7 @@
     <profile namespace="karajan" key="jobThrottle">0.5</profile>
     <profile namespace="karajan" key="initialScore">10000</profile>
     <filesystem provider="ssh" url="login1.pads.ci.uchicago.edu"/>
-    <workdirectory>/home/arjun/swiftwork</workdirectory>
+    <workdirectory>$HOME/swiftwork</workdirectory>
   </pool>
 
   <pool handle="teraport-pbs-multisite-coasters">
@@ -122,6 +122,6 @@
     <profile namespace="karajan" key="jobThrottle">0.5</profile>
     <profile namespace="karajan" key="initialScore">10000</profile>
     <filesystem provider="ssh" url="tp-login2.ci.uchicago.edu"/>
-    <workdirectory>/home/arjun/swiftwork</workdirectory>
+    <workdirectory>$HOME/swiftwork</workdirectory>
   </pool>
 </config>




More information about the Swift-commit mailing list