[Swift-commit] r5966 - in trunk/src/org/griphyn/vdl: karajan/lib mapping

hategan at ci.uchicago.edu hategan at ci.uchicago.edu
Sun Oct 14 22:41:21 CDT 2012


Author: hategan
Date: 2012-10-14 22:41:21 -0500 (Sun, 14 Oct 2012)
New Revision: 5966

Modified:
   trunk/src/org/griphyn/vdl/karajan/lib/CreateArray.java
   trunk/src/org/griphyn/vdl/karajan/lib/New.java
   trunk/src/org/griphyn/vdl/mapping/AbstractDataNode.java
   trunk/src/org/griphyn/vdl/mapping/RootDataNode.java
Log:
don't log useless dataset ids if provenance is disabled; don't create dataset identifiers unless needed; fixed bogus logging level test

Modified: trunk/src/org/griphyn/vdl/karajan/lib/CreateArray.java
===================================================================
--- trunk/src/org/griphyn/vdl/karajan/lib/CreateArray.java	2012-10-15 03:37:49 UTC (rev 5965)
+++ trunk/src/org/griphyn/vdl/karajan/lib/CreateArray.java	2012-10-15 03:41:21 UTC (rev 5966)
@@ -17,15 +17,14 @@
 
 package org.griphyn.vdl.karajan.lib;
 
-import java.util.HashMap;
 import java.util.List;
-import java.util.Map;
 
 import org.apache.log4j.Logger;
 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.futures.FutureFault;
+import org.griphyn.vdl.mapping.AbstractDataNode;
 import org.griphyn.vdl.mapping.DSHandle;
 import org.griphyn.vdl.mapping.MappingParam;
 import org.griphyn.vdl.mapping.MappingParamSet;
@@ -44,7 +43,6 @@
 		setArguments(CreateArray.class, new Arg[] { PA_VALUE });
 	}
 
-	@SuppressWarnings("unchecked")
     public Object function(VariableStack stack) throws ExecutionException {
 		Object value = PA_VALUE.getValue(stack);
 		try {
@@ -61,7 +59,12 @@
 			    setMapper(handle);
 			}
 
-			if (logger.isInfoEnabled()) {
+			/*
+			 *  The reason this is disabled without provenance is that the identifier
+			 *  is essentially a random number plus a counter. It does not help
+			 *  in debugging problems.  
+			 */
+			if (AbstractDataNode.provenance && logger.isInfoEnabled()) {
 			    logger.info("CREATEARRAY START array=" + handle.getIdentifier());
 			}
 
@@ -78,7 +81,7 @@
 
 				SetFieldValue.deepCopy(dst, n, stack, 1);
 				
-				if (logger.isInfoEnabled()) {
+				if (AbstractDataNode.provenance && logger.isInfoEnabled()) {
 				    logger.info("CREATEARRAY MEMBER array=" + handle.getIdentifier() 
 				        + " index=" + index + " member=" + n.getIdentifier());
 				}
@@ -87,7 +90,7 @@
 			
 			handle.closeShallow();
 			
-			if (logger.isInfoEnabled()) {
+			if (AbstractDataNode.provenance && logger.isInfoEnabled()) {
 			    logger.info("CREATEARRAY COMPLETED array=" + handle.getIdentifier());
 			}
 

Modified: trunk/src/org/griphyn/vdl/karajan/lib/New.java
===================================================================
--- trunk/src/org/griphyn/vdl/karajan/lib/New.java	2012-10-15 03:37:49 UTC (rev 5965)
+++ trunk/src/org/griphyn/vdl/karajan/lib/New.java	2012-10-15 03:41:21 UTC (rev 5966)
@@ -29,6 +29,7 @@
 import org.globus.cog.karajan.stack.VariableStack;
 import org.globus.cog.karajan.util.TypeUtil;
 import org.globus.cog.karajan.workflow.ExecutionException;
+import org.griphyn.vdl.mapping.AbstractDataNode;
 import org.griphyn.vdl.mapping.DSHandle;
 import org.griphyn.vdl.mapping.ExternalDataNode;
 import org.griphyn.vdl.mapping.MappingParam;
@@ -75,8 +76,10 @@
 		if (line != null) {
 		    mps.set(MappingParam.SWIFT_LINE, line);
 		}
+		
+		String threadPrefix = getThreadPrefix(stack);
 
-		mps.set(MappingParam.SWIFT_RESTARTID, getThreadPrefix(stack) + ":" + dbgname);
+		mps.set(MappingParam.SWIFT_RESTARTID, threadPrefix + ":" + dbgname);
 
 		if (waitfor != null) {
 			mps.set(MappingParam.SWIFT_WAITFOR, waitfor);
@@ -88,7 +91,6 @@
 	
 		String mapper = (String) mps.get(MappingParam.SWIFT_DESCRIPTOR);
 		if ("concurrent_mapper".equals(mapper)) {
-		    String threadPrefix = getThreadPrefix(stack);
 		    mps.set(ConcurrentMapper.PARAM_THREAD_PREFIX, threadPrefix);
 		}
 		mps.set(MappingParam.SWIFT_BASEDIR, stack.getExecutionContext().getBasedir());
@@ -96,16 +98,16 @@
 		try {
 			Type type;
 			if (typename == null) {
-				throw new ExecutionException
-				("vdl:new requires a type specification for value: " + value);
+				throw new ExecutionException("vdl:new requires a type specification for value: " + value);
 			}
 			else {
 				type = Types.getType(typename);
 			}
 			DSHandle handle;
-			if(typename.equals("external")) {
+			if (typename.equals("external")) {
 				handle = new ExternalDataNode();
-			} else if (type.isArray()) {
+			}
+			else if (type.isArray()) {
 				// dealing with array variable
 				handle = new RootArrayDataNode(type);
 				if (value != null) {
@@ -114,9 +116,7 @@
 					}
 					else {
 						if (!(value instanceof List)) {
-							throw new ExecutionException
-							("An array variable can only be initialized " +
-							 "with a list of values");
+							throw new ExecutionException("An array variable can only be initialized with a list of values");
 						}
 						int index = 0;
 						Iterator<?> i = ((List<?>) value).iterator();
@@ -151,8 +151,8 @@
 				}
 			}
 			
-			if (logger.isDebugEnabled()) {
-			    logger.debug("NEW id="+handle.getIdentifier());
+			if (AbstractDataNode.provenance && logger.isDebugEnabled()) {
+			    logger.debug("NEW id=" + handle.getIdentifier());
 			}
 			return handle;
 		}

Modified: trunk/src/org/griphyn/vdl/mapping/AbstractDataNode.java
===================================================================
--- trunk/src/org/griphyn/vdl/mapping/AbstractDataNode.java	2012-10-15 03:37:49 UTC (rev 5965)
+++ trunk/src/org/griphyn/vdl/mapping/AbstractDataNode.java	2012-10-15 03:41:21 UTC (rev 5966)
@@ -20,6 +20,7 @@
  */
 package org.griphyn.vdl.mapping;
 
+import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
@@ -44,11 +45,9 @@
 
     static final String DATASET_URI_PREFIX = "dataset:";
 
-    public static final Logger logger = Logger
-    .getLogger(AbstractDataNode.class);
+    public static final Logger logger = Logger.getLogger(AbstractDataNode.class);
 
-    public static final MappingParam PARAM_PREFIX = new MappingParam("prefix",
-        null);
+    public static final MappingParam PARAM_PREFIX = new MappingParam("prefix", null);
 
     /**
      * Datasets are identified within a run by this sequence number and the
@@ -67,12 +66,21 @@
      * this value - it exists purely for making unique URIs.
      */
     private static final String datasetIDPartialID = Loader.getUUID();
+    
+    public static boolean provenance = false;
+    static {
+        try {
+        	provenance = VDL2Config.getConfig().getProvenanceLog();
+        }
+        catch (IOException e) {
+        }
+    }
 
     private Field field;
     private Map<Comparable<?>, DSHandle> handles;
     private Object value;
     private boolean closed;
-    final String identifierURI = makeIdentifierURIString();
+    private String identifier;
     private Path pathFromRoot;
     
     protected FutureWrapper wrapper;
@@ -222,8 +230,7 @@
             }
         }
         catch (NoSuchFieldException e) {
-            logger.warn("could not find variable: " + field.getId() + 
-                               " " + path);
+            logger.warn("could not find variable: " + field.getId() + " " + path);
             throw new InvalidPathException(path, this);
         }
     }
@@ -243,8 +250,7 @@
                 throw new InvalidPathException("getFields([*]) only applies to arrays");
             }
             try {
-                ((AbstractDataNode) getField(path.getFirst())).getFields(
-                    fields, path.butFirst());
+                ((AbstractDataNode) getField(path.getFirst())).getFields(fields, path.butFirst());
             }
             catch (NoSuchFieldException e) {
                 throw new InvalidPathException(path, this);
@@ -255,8 +261,7 @@
     public void set(DSHandle handle) {
         // TODO check type
         if (closed) {
-            throw new IllegalArgumentException(this.getDisplayableName()
-                + " is already assigned");
+            throw new IllegalArgumentException(this.getDisplayableName() + " is already assigned");
         }
         if (getParent() == null) {
             /*
@@ -292,8 +297,7 @@
     public DSHandle createField(Comparable<?> key)
     throws NoSuchFieldException {
         if (closed) {
-            throw new RuntimeException("Cannot write to closed handle: " + this
-                + " (" + key + ")");
+            throw new RuntimeException("Cannot write to closed handle: " + this + " (" + key + ")");
         }
         
         return addHandle(key, newNode(getChildField(key)));
@@ -302,9 +306,7 @@
     protected synchronized DSHandle addHandle(Comparable<?> id, DSHandle handle) {
         Object o = handles.put(id, handle);
         if (o != null) {
-            throw new RuntimeException(
-                "Trying to create a handle that already exists ("
-                + id + ") in " + this);
+            throw new RuntimeException("Trying to create a handle that already exists (" + id + ") in " + this);
         }
         return handle;
     }
@@ -366,12 +368,12 @@
 
     public void setValue(Object value) {
         if (this.closed) {
-            throw new IllegalArgumentException(this.getDisplayableName()
-                + " is closed with a value of " + this.value);
+            throw new IllegalArgumentException(this.getDisplayableName() 
+            		+ " is closed with a value of " + this.value);
         }
         if (this.value != null) {
-            throw new IllegalArgumentException(this.getDisplayableName()
-                + " is already assigned with a value of " + this.value);
+            throw new IllegalArgumentException(this.getDisplayableName() 
+            		+ " is already assigned with a value of " + this.value);
         }
         this.value = value;
         closeShallow();
@@ -397,15 +399,12 @@
                     child = (AbstractDataNode) this.getField(name);
                 }
                 catch (NoSuchFieldException e) {
-                    throw new RuntimeException
-                    ("Inconsistency between type declaration and " + 
+                    throw new RuntimeException("Inconsistency between type declaration and " + 
                         "handle for field '" + name + "'");
                 }
                 Path fullPath = parentPath.addLast(name);
                 Type type = child.getType(); 
-                if (!type.isPrimitive() &&
-                        !child.isArray() && 
-                        type.getFields().size() == 0) {
+                if (!type.isPrimitive() && !child.isArray() && type.getFields().size() == 0) {
                     list.add(fullPath);
                 }
                 else {
@@ -424,32 +423,27 @@
         }
         // closed
         notifyListeners();
-        if (logger.isInfoEnabled()) {
+        if (logger.isDebugEnabled()) {
             logger.debug("closed " + this.getIdentifyingString());
         }
         // so because its closed, we can dump the contents
 
         try {
-            if(VDL2Config.getConfig().getProvenanceLog()) {
+            if(provenance) {
                 logContent();
             }
         }
         catch (Exception e) {
-            logger.warn("Exception whilst logging dataset content for " + this,
-                e);
+            logger.warn("Exception whilst logging dataset content for " + this, e);
         }
-        // TODO record retrospective provenance information for this dataset
-        // here
+        // TODO record retrospective provenance information for this dataset here
         // we should do it at closing time because that's the point at which we
         // know the dataset has its values (all the way down the tree) assigned.
 
-        // provenance-id for this dataset should have been assigned at creation
-        // time,
-        // though, so that we can refer to this dataset elsewhere before it is
-        // closed.
+        // provenance-id for this dataset should have been assigned at creation time,
+        // though, so that we can refer to this dataset elsewhere before it is closed.
 
-        // is this method the only one called to set this.closed? or do
-        // subclasses
+        // is this method the only one called to set this.closed? or do subclasses
         // or other methods ever change it?
     }
 
@@ -458,11 +452,9 @@
         Path pathFromRoot = this.getPathFromRoot();
         if (this.getPathFromRoot() != null) {
             if (logger.isInfoEnabled()) {
-                logger.info("ROOTPATH dataset=" + identifier + " path="
-                    + pathFromRoot);
+                logger.info("ROOTPATH dataset=" + identifier + " path=" + pathFromRoot);
                 if (this.getType().isPrimitive()) {
-                    logger.info("VALUE dataset=" + identifier + " VALUE="
-                        + this.toString());
+                    logger.info("VALUE dataset=" + identifier + " VALUE=" + this.toString());
                 }
             }
 
@@ -498,8 +490,7 @@
                     if(filemapped) {
                         Object path = m.map(pathFromRoot);
                         if (logger.isInfoEnabled()) {
-                            logger.info("FILENAME dataset=" + identifier + " filename="
-                                + path);
+                            logger.info("FILENAME dataset=" + identifier + " filename=" + path);
                         }
                     }
                 }
@@ -518,8 +509,7 @@
             for (DSHandle handle : handles.values()) {
                 AbstractDataNode node = (AbstractDataNode) handle;
                 if (logger.isInfoEnabled()) {
-                    logger.info("CONTAINMENT parent=" + identifier + 
-                        " child=" + node.getIdentifier());
+                    logger.info("CONTAINMENT parent=" + identifier + " child=" + node.getIdentifier());
                 }
                 node.logContent();
             }
@@ -554,8 +544,7 @@
         synchronized (this) {
             for (DSHandle handle : handles.values()) {
                 AbstractDataNode child = (AbstractDataNode) handle;
-                if (child.getType().isArray() ||
-                                  child.getType().getFields().size() > 0) {
+                if (child.getType().isArray() || child.getType().getFields().size() > 0) {
                     child.closeArraySizes();
                 }
             }
@@ -568,8 +557,7 @@
             Path myPath;
             if (parent != null) {
                 myPath = parent.getPathFromRoot();
-                pathFromRoot = myPath.addLast(getField().getId(), parent
-                    .getField().getType().isArray());
+                pathFromRoot = myPath.addLast(getField().getId(), parent.getField().getType().isArray());
             }
             else {
                 pathFromRoot = Path.EMPTY_PATH;
@@ -586,8 +574,11 @@
         return handles;
     }
     
-    public String getIdentifier() {
-        return identifierURI;
+    public synchronized String getIdentifier() {
+    	if (identifier == null) {
+   		    identifier = makeIdentifierURIString();
+    	}
+        return identifier;
     }
 
     String makeIdentifierURIString() {

Modified: trunk/src/org/griphyn/vdl/mapping/RootDataNode.java
===================================================================
--- trunk/src/org/griphyn/vdl/mapping/RootDataNode.java	2012-10-15 03:37:49 UTC (rev 5965)
+++ trunk/src/org/griphyn/vdl/mapping/RootDataNode.java	2012-10-15 03:41:21 UTC (rev 5966)
@@ -20,8 +20,6 @@
  */
 package org.griphyn.vdl.mapping;
 
-import java.util.Map;
-
 import org.apache.log4j.Logger;
 import org.globus.cog.karajan.stack.VariableStack;
 import org.globus.cog.karajan.workflow.futures.Future;




More information about the Swift-commit mailing list