[Swift-commit] r3231 - in trunk: . libexec src/org/globus/swift/data src/org/globus/swift/data/policy

noreply at svn.ci.uchicago.edu noreply at svn.ci.uchicago.edu
Fri Feb 5 17:02:18 CST 2010


Author: wozniak
Date: 2010-02-05 17:02:18 -0600 (Fri, 05 Feb 2010)
New Revision: 3231

Added:
   trunk/libexec/cdm_broadcast.sh
   trunk/src/org/globus/swift/data/Action.java
   trunk/src/org/globus/swift/data/policy/Broadcast.java
Modified:
   trunk/.project
   trunk/build.xml
   trunk/libexec/_swiftwrap
   trunk/libexec/vdl-int.k
   trunk/libexec/vdl-lib.xml
   trunk/src/org/globus/swift/data/Director.java
   trunk/src/org/globus/swift/data/policy/Direct.java
   trunk/src/org/globus/swift/data/policy/Policy.java
Log:
CDM BROADCAST framework with implementation for workstation. 


Modified: trunk/.project
===================================================================
--- trunk/.project	2010-02-05 22:58:42 UTC (rev 3230)
+++ trunk/.project	2010-02-05 23:02:18 UTC (rev 3231)
@@ -3,13 +3,30 @@
 	<name>swift</name>
 	<comment></comment>
 	<projects>
+		<project>abstraction-common</project>
+		<project>karajan</project>
 	</projects>
 	<buildSpec>
 		<buildCommand>
-			<name>org.eclipse.jdt.core.javabuilder</name>
+			<name>org.eclipse.ui.externaltools.ExternalToolBuilder</name>
+			<triggers>full,incremental,</triggers>
 			<arguments>
+				<dictionary>
+					<key>LaunchConfigHandle</key>
+					<value><project>/.externalToolBuilders/org.eclipse.jdt.core.javabuilder.launch</value>
+				</dictionary>
 			</arguments>
 		</buildCommand>
+		<buildCommand>
+			<name>org.eclipse.ui.externaltools.ExternalToolBuilder</name>
+			<triggers>full,incremental,</triggers>
+			<arguments>
+				<dictionary>
+					<key>LaunchConfigHandle</key>
+					<value><project>/.externalToolBuilders/Swift_Builder.launch</value>
+				</dictionary>
+			</arguments>
+		</buildCommand>
 	</buildSpec>
 	<natures>
 		<nature>org.eclipse.jdt.core.javanature</nature>

Modified: trunk/build.xml
===================================================================
--- trunk/build.xml	2010-02-05 22:58:42 UTC (rev 3230)
+++ trunk/build.xml	2010-02-05 23:02:18 UTC (rev 3231)
@@ -254,6 +254,7 @@
 		</replace>
 		<chmod perm="+x" file="${dist.dir}/bin/swift"/>
 		<chmod perm="+x" file="${dist.dir}/bin/swift-osg-ress-site-catalog"/>
+		<chmod perm="+x" file="${dist.dir}/libexec/cdm_broadcast.sh"/>
 	</target>
 
 	<target name="antlr">

Modified: trunk/libexec/_swiftwrap
===================================================================
--- trunk/libexec/_swiftwrap	2010-02-05 22:58:42 UTC (rev 3230)
+++ trunk/libexec/_swiftwrap	2010-02-05 23:02:18 UTC (rev 3231)
@@ -165,6 +165,18 @@
 				fail 254 "Unknown MODE: $MODE"
 			fi
 			;;
+		BROADCAST)
+			BROADCAST_DIR=${ARGS[0]}
+			log "CDM[BROADCAST]: Linking $JOBDIR/$FILE to $BROADCAST_DIR/$FILE"
+			if [ $MODE == "INPUT" ]; then 
+				[ -f "$BROADCAST_DIR/$FILE" ]
+				checkError 254 "CDM[BROADCAST]: $BROADCAST_DIR/$FILE does not exist!"
+				ln -s $BROADCAST_DIR/$FILE $JOBDIR/$FILE
+				checkError 254 "CDM[BROADCAST]: Linking to $BROADCAST_DIR/$FILE failed!"
+			else 
+				fail 254 "Cannot BROADCAST an output file!"
+			fi
+			;;
 	esac
 }
 

Added: trunk/libexec/cdm_broadcast.sh
===================================================================
--- trunk/libexec/cdm_broadcast.sh	                        (rev 0)
+++ trunk/libexec/cdm_broadcast.sh	2010-02-05 23:02:18 UTC (rev 3231)
@@ -0,0 +1,14 @@
+#!/bin/sh
+
+SWIFT_HOME=$( dirname $( dirname $0 ) )
+LOG=${SWIFT_HOME}/etc/cdm_broadcast.log
+{
+    set -x
+
+    FILE=$1
+    DIR=$2
+    DEST=$3
+    
+    cp -v ${DIR}/${FILE} ${DEST}
+
+} >> ${LOG} 2>&1


Property changes on: trunk/libexec/cdm_broadcast.sh
___________________________________________________________________
Name: svn:executable
   + *

Modified: trunk/libexec/vdl-int.k
===================================================================
--- trunk/libexec/vdl-int.k	2010-02-05 22:58:42 UTC (rev 3230)
+++ trunk/libexec/vdl-int.k	2010-02-05 23:02:18 UTC (rev 3231)
@@ -288,6 +288,9 @@
 				restartOnError(".*", 2
 					task:transfer(srcprovider=provider, srchost=srchost, srcfile=srcfile, 
 							srcdir=srcdir, desthost=desthost, destdir=destdir)))
+			    policy == "BROADCAST" then(
+				log(LOG:DEBUG, "FILE_STAGE_IN_BROADCAST file={srcfile} policy={policy}")
+				cdm:broadcast(srcfile=srcfile, srcdir=srcdir))
 			else(log(LOG:DEBUG, "FILE_STAGE_IN_SKIP file={srcfile} policy={policy}")))
 			log(LOG:DEBUG, "FILE_STAGE_IN_END file={srcfile} srchost={srchost} srcdir={srcdir} srcname={srcfile} ",
                                                "desthost={desthost} destdir={destdir} provider={provider}")

Modified: trunk/libexec/vdl-lib.xml
===================================================================
--- trunk/libexec/vdl-lib.xml	2010-02-05 22:58:42 UTC (rev 3230)
+++ trunk/libexec/vdl-lib.xml	2010-02-05 23:02:18 UTC (rev 3231)
@@ -101,6 +101,7 @@
   <namespace prefix="cdm">
   	<export name="query"><elementDef classname="org.globus.swift.data.Query"/></export>
   	<export name="file"><elementDef classname="org.globus.swift.data.Query"/></export>
+  	<export name="broadcast"><elementDef classname="org.globus.swift.data.Action"/></export>
   </namespace>
 
 </karajan>

Added: trunk/src/org/globus/swift/data/Action.java
===================================================================
--- trunk/src/org/globus/swift/data/Action.java	                        (rev 0)
+++ trunk/src/org/globus/swift/data/Action.java	2010-02-05 23:02:18 UTC (rev 3231)
@@ -0,0 +1,38 @@
+package org.globus.swift.data;
+
+import java.io.IOException;
+
+import org.globus.cog.karajan.arguments.Arg;
+import org.globus.cog.karajan.stack.VariableStack;
+import org.globus.cog.karajan.workflow.ExecutionException;
+import org.globus.cog.karajan.workflow.nodes.functions.FunctionsCollection;
+import org.globus.swift.data.policy.Broadcast;
+import org.globus.swift.data.policy.Policy;
+
+public class Action extends FunctionsCollection {
+
+    public static final Arg PA_FILE = new Arg.Positional("srcfile");
+    public static final Arg PA_DIR  = new Arg.Positional("srcdir");
+
+    static {
+        setArguments("cdm_broadcast", new Arg[]{ PA_FILE, PA_DIR });
+    }
+
+    public void cdm_broadcast(VariableStack stack) throws ExecutionException {
+        String srcfile = (String) PA_FILE.getValue(stack);
+        String srcdir  = (String) PA_DIR.getValue(stack);
+        
+        Policy policy = Director.lookup(srcfile);
+        
+        if (!(policy instanceof Broadcast)) {
+            throw new RuntimeException("Attempting to BROADCAST the wrong file");
+        }
+        
+        if (srcdir == "") { 
+            srcdir = ".";
+        }
+        
+        Broadcast broadcast   = (Broadcast) policy;
+        broadcast.action(srcfile, srcdir);
+    }
+}

Modified: trunk/src/org/globus/swift/data/Director.java
===================================================================
--- trunk/src/org/globus/swift/data/Director.java	2010-02-05 22:58:42 UTC (rev 3230)
+++ trunk/src/org/globus/swift/data/Director.java	2010-02-05 23:02:18 UTC (rev 3231)
@@ -3,10 +3,13 @@
 
 import java.io.File;
 import java.io.IOException;
+import java.util.Arrays;
+import java.util.HashSet;
 import java.util.Iterator;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
@@ -31,12 +34,13 @@
     /**
        Maps from Patterns to Policies
      */
-    static Map map;
+    static Map map = new LinkedHashMap();
 
-    static {
-    	map = new LinkedHashMap();
-    }
-
+    /** 
+       Remember the files we have broadcasted
+     */
+    static Set<String> broadcasted = new HashSet<String>();
+    
     public static void load(File policyFile) throws IOException {
         logger.info("loading: " + policyFile);
         Director.policyFile = policyFile;
@@ -52,6 +56,8 @@
         String[] tokens = LineReader.tokenize(s);
         Pattern pattern = Pattern.compile(tokens[0]);
         Policy policy = Policy.valueOf(tokens[1]);
+        List<String> tokenList = Arrays.asList(tokens);        
+        policy.settings(tokenList.subList(2,tokenList.size()));
         map.put(pattern, policy);
     }
 
@@ -65,6 +71,14 @@
     	return Policy.DEFAULT;
     }
     
+    public static boolean broadcasted(String file, String dir) {
+        return broadcasted.contains(dir+"/"+file);
+    }
+    
+    public static void broadcast(String file, String dir) {
+        broadcasted.add(dir+"/"+file);
+    }
+    
     /** 
      * Check the policy effect of name with respect to policy_file
      * @param args {name, policy_file} 

Added: trunk/src/org/globus/swift/data/policy/Broadcast.java
===================================================================
--- trunk/src/org/globus/swift/data/policy/Broadcast.java	                        (rev 0)
+++ trunk/src/org/globus/swift/data/policy/Broadcast.java	2010-02-05 23:02:18 UTC (rev 3231)
@@ -0,0 +1,50 @@
+package org.globus.swift.data.policy;
+
+import java.util.List;
+
+import org.globus.swift.data.Director;
+
+public class Broadcast extends Policy {
+    
+    String destination = null; 
+    
+    @Override
+    public void settings(List<String> settings) {
+        try {
+            destination = settings.get(0);
+        } 
+        catch (Exception e) { 
+            throw new RuntimeException("Incorrect settings for BROADCAST");
+        }
+    }
+    
+    public void action(String srcfile, String srcdir) {
+        if (! Director.broadcasted(srcfile, srcdir))
+            callScript(srcfile, srcdir, destination);
+    }
+    
+    void callScript(String srcfile, String srcdir, String destination) { 
+        String home = System.getProperties().getProperty("swift.home");
+        try {
+            String[] line = new String[4];
+            line[0] = home+"/libexec/cdm_broadcast.sh";
+            line[1] = srcfile; 
+            line[2] = srcdir; 
+            line[3] = destination;
+            Process process = Runtime.getRuntime().exec(line);
+            process.waitFor();
+        }
+        catch (Exception e) {
+            e.printStackTrace();
+            throw new RuntimeException("Could not launch external broadcast");
+        }
+    }   
+    
+    public String getDestination() {
+        return destination;
+    }
+    
+    public String toString() {
+        return "BROADCAST";
+    }
+}

Modified: trunk/src/org/globus/swift/data/policy/Direct.java
===================================================================
--- trunk/src/org/globus/swift/data/policy/Direct.java	2010-02-05 22:58:42 UTC (rev 3230)
+++ trunk/src/org/globus/swift/data/policy/Direct.java	2010-02-05 23:02:18 UTC (rev 3231)
@@ -1,8 +1,14 @@
 package org.globus.swift.data.policy;
 
+import java.util.List;
+
 public class Direct extends Policy {
 
     public String toString() {
         return "DIRECT";
     }
+
+    @Override
+    public void settings(List<String> tokens) {
+    }
 }

Modified: trunk/src/org/globus/swift/data/policy/Policy.java
===================================================================
--- trunk/src/org/globus/swift/data/policy/Policy.java	2010-02-05 22:58:42 UTC (rev 3230)
+++ trunk/src/org/globus/swift/data/policy/Policy.java	2010-02-05 23:02:18 UTC (rev 3231)
@@ -3,19 +3,22 @@
 
 import java.util.List;
 
-public class Policy {
+public abstract class Policy {
 
 	public static Policy DEFAULT = valueOf("default");
 	
     public Policy()
     {}
 
+    public abstract void settings(List<String> tokens);
+    
     public static Policy valueOf(String token) {
         if (token.compareToIgnoreCase("default") == 0)
             return new Default();
         else if (token.compareToIgnoreCase("direct") == 0)
             return new Direct();
-
+        else if (token.compareToIgnoreCase("broadcast") == 0)
+            return new Broadcast();
         return null;
     }
 }




More information about the Swift-commit mailing list