You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by bu...@apache.org on 2016/05/09 20:52:55 UTC

svn commit: r1743049 - in /uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/aio: AllInOne.java CasGenerator.java CasPipeline.java

Author: burn
Date: Mon May  9 20:52:55 2016
New Revision: 1743049

URL: http://svn.apache.org/viewvc?rev=1743049&view=rev
Log:
UIMA-4909 Print stack trace before exiting on all_in_one errors.  Try to remove dependencies on other DUCC jars

Modified:
    uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/aio/AllInOne.java
    uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/aio/CasGenerator.java
    uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/aio/CasPipeline.java

Modified: uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/aio/AllInOne.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/aio/AllInOne.java?rev=1743049&r1=1743048&r2=1743049&view=diff
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/aio/AllInOne.java (original)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/aio/AllInOne.java Mon May  9 20:52:55 2016
@@ -18,16 +18,13 @@
 */
 package org.apache.uima.ducc.cli.aio;
 
+import java.util.Properties;
+
 import org.apache.uima.cas.CAS;
 import org.apache.uima.cas.impl.XmiSerializationSharedData;
-import org.apache.uima.ducc.cli.CliBase;
-import org.apache.uima.ducc.cli.DuccJobSubmit;
-import org.apache.uima.ducc.cli.aio.IMessageHandler.Level;
-import org.apache.uima.ducc.cli.aio.IMessageHandler.Toggle;
-import org.apache.uima.ducc.transport.event.cli.JobRequestProperties;
 import org.apache.uima.ducc.user.common.DuccUimaSerializer;
 
-public class AllInOne extends CliBase {
+public class AllInOne {
     
 	private static String cid = AllInOne.class.getSimpleName();
 	
@@ -35,66 +32,51 @@ public class AllInOne extends CliBase {
 	
 	private static XmiSerializationSharedData xmiSerializationSharedData = new XmiSerializationSharedData();
 	
-	private IMessageHandler mh = new MessageHandler();
-	
-	private JobRequestProperties jobRequestProperties = new JobRequestProperties(); 
-	
-	private boolean showStats = true;
-	
+    private MsgHandler mh = new MsgHandler();
+    
+    private Properties jobRequestProperties = new Properties();
+
+    private boolean showStats = true;
+
+	// Avoid a dependency on the CLI's UiOptions by duplicating these option nanes
+    static String DriverDescriptorCR = "driver_descriptor_CR";
+    static String DriverDescriptorCROverrides = "driver_descriptor_CR_overrides";
+    static String ProcessDD = "process_descriptor_DD";
+    static String ProcessDescriptorCM = "process_descriptor_CM";
+    static String ProcessDescriptorCMOverrides = "process_descriptor_CM_overrides";
+    static String ProcessDescriptorAE = "process_descriptor_AE";
+    static String ProcessDescriptorAEOverrides = "process_descriptor_AE_overrides";
+    static String ProcessDescriptorCC = "process_descriptor_CC";
+    static String ProcessDescriptorCCOverrides = "process_descriptor_CC_overrides";
+    static String Timestamp = "timestamp";
+    static String Debug = "debug";
+  
 	CasGenerator casGenerator;
 	CasPipeline casPipeline;
+
+    private boolean timestamp;
+
+    private boolean debug;
 	
 	public AllInOne(String[] args) throws Exception {
-		UiOption[] opts = DuccJobSubmit.opts;
-		init(this.getClass().getName(), opts, args, jobRequestProperties, consoleCb);
-	}
-	
-	private void examine_debug() {
-		String mid = "examine_debug";
-		debug = jobRequestProperties.containsKey(UiOption.Debug.pname());
-		if(debug) {
-			mh.setLevel(Level.FrameworkInfo, Toggle.On);
-			mh.setLevel(Level.FrameworkDebug, Toggle.On);
-			mh.setLevel(Level.FrameworkError, Toggle.On);
-			mh.setLevel(Level.FrameworkWarn, Toggle.On);
-			String message = "true";
-			mh.frameworkDebug(cid, mid, message);
-		}
-		else {
-			String message = "false";
-			mh.frameworkDebug(cid, mid, message);
-		}
+	    for (int i = 0; i < args.length; ++i) {
+	        if (i+1 < args.length && !args[i+1].startsWith("--")) {
+	            jobRequestProperties.put(args[i].substring(2), args[i+1]);
+	            ++i;
+	        } else {
+	            jobRequestProperties.put(args[i].substring(2), "");
+	        }
+	  }
+      // Properties will have been validated in AllInOneLauncher
+      timestamp = jobRequestProperties.containsKey(Timestamp);
+      debug = jobRequestProperties.containsKey(Debug);
 	}
 	
-	private void examine_timestamp() {
-		String mid = "examine_timestamp";
-		boolean timestamp = jobRequestProperties.containsKey(UiOption.Timestamp.pname());
-		if(timestamp) {
-			mh.setTimestamping(Toggle.On);
-			String message = "true";
-			mh.frameworkDebug(cid, mid, message);
-		}
-		else {
-			String message = "false";
-			mh.frameworkDebug(cid, mid, message);
-		}
-	}
-	
-	private void examine() throws IllegalArgumentException {
-		String mid = "examine";
-		mh.frameworkTrace(cid, mid, "enter");
-		examine_debug();
-		examine_timestamp();
-		mh.frameworkTrace(cid, mid, "exit");
-	}
-
 	private class NoWorkItems extends Exception {
 		private static final long serialVersionUID = 1L;
 	}
 	
 	private void initialize() throws Exception {
-		String mid = "initialize";
-		mh.frameworkTrace(cid, mid, "enter");
 		// Generator
 		casGenerator = new CasGenerator(jobRequestProperties, mh);
 		casGenerator.initialize();
@@ -107,12 +89,10 @@ public class AllInOne extends CliBase {
 		else {
 			throw new NoWorkItems();
 		}
-		mh.frameworkTrace(cid, mid, "exit");
 	}
 	
 	private void process() throws Exception {
 		String mid = "process";
-		mh.frameworkTrace(cid, mid, "enter");
 		int count = 0;
 		int total = casGenerator.getTotal();
 		mh.frameworkDebug(cid, mid, "total:"+total);
@@ -130,7 +110,6 @@ public class AllInOne extends CliBase {
 			count++;
 		}
 		casPipeline.destroy();
-		mh.frameworkTrace(cid, mid, "exit");
 	}
 	
 	private void statistics() {
@@ -140,19 +119,15 @@ public class AllInOne extends CliBase {
 	}
 	
 	public void go() throws Exception {
-		String mid = "go";
-		mh.frameworkTrace(cid, mid, "enter");
 		try {
-			examine();
 			initialize();
 			process();
 			statistics();
 		}
 		catch(NoWorkItems e) {
 			String message = "no work items";
-			mh.warn(cid, mid, message);
+			System.err.println("AllInOne.go " + message);
 		}
-		mh.frameworkTrace(cid, mid, "exit");
 	}
 	
 	
@@ -162,13 +137,17 @@ public class AllInOne extends CliBase {
 			allInOne.go();
 		} catch (Exception e) {
 			// Indicate that something went wrong
+		    e.printStackTrace();
 			System.exit(1);
 		}
 	}
 
-	@Override
-	public boolean execute() throws Exception {
-		return false;
+	class MsgHandler {
+	       public void frameworkInfo(String klass, String method, String message) {
+	            System.out.println(klass + "." + method + " " + message);
+	        }
+	    public void frameworkDebug(String klass, String method, String message) {
+	        if (debug) System.out.println(klass + "." + method + " " + message);
+	    }
 	}
-
 }

Modified: uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/aio/CasGenerator.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/aio/CasGenerator.java?rev=1743049&r1=1743048&r2=1743049&view=diff
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/aio/CasGenerator.java (original)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/aio/CasGenerator.java Mon May  9 20:52:55 2016
@@ -28,7 +28,6 @@ import org.apache.uima.UIMAFramework;
 import org.apache.uima.cas.CAS;
 import org.apache.uima.collection.CollectionException;
 import org.apache.uima.collection.CollectionReader;
-import org.apache.uima.ducc.cli.IUiOptions.UiOption;
 import org.apache.uima.ducc.common.utils.QuotedOptions;
 import org.apache.uima.ducc.user.common.UimaUtils;
 import org.apache.uima.resource.ResourceConfigurationException;
@@ -51,7 +50,7 @@ public class CasGenerator {
 
 	public static String cid = CasGenerator.class.getSimpleName();
 	
-	protected IMessageHandler mh = new MessageHandler();
+	protected AllInOne.MsgHandler mh;
 	protected Properties properties = new Properties();
 
 	private CollectionReader cr;
@@ -62,7 +61,7 @@ public class CasGenerator {
 	
 	private int total;
 	
-	public CasGenerator(Properties properties, IMessageHandler mh) {
+	public CasGenerator(Properties properties, AllInOne.MsgHandler mh) {
 		if(properties != null) {
 			this.properties = properties;
 		}
@@ -73,18 +72,10 @@ public class CasGenerator {
 	
 	public void initialize() throws InvalidXMLException, ResourceConfigurationException, ResourceInitializationException {
 		String mid = "initialize";
-		mh.frameworkTrace(cid, mid, "enter");
-		String crDescriptor = properties.getProperty(UiOption.DriverDescriptorCR.pname());
-		String crOverrides = properties.getProperty(UiOption.DriverDescriptorCROverrides.pname());
+		String crDescriptor = properties.getProperty(AllInOne.DriverDescriptorCR);
+		String crOverrides = properties.getProperty(AllInOne.DriverDescriptorCROverrides);
 		XMLParser xmlParser = UIMAFramework.getXMLParser();
-		XMLInputSource in = null;
-		try {
-			in = UimaUtils.getXMLInputSource(crDescriptor);
-		}
-		catch (InvalidXMLException e) {
-			mh.error(e);
-			throw e;
-		}
+		XMLInputSource in = UimaUtils.getXMLInputSource(crDescriptor);
 		ResourceSpecifier crrs = xmlParser.parseCollectionReaderDescription(in);
 		// CR overrides - throw up if trying to override an undefined parameter
         ResourceCreationSpecifier specifier = (ResourceCreationSpecifier) crrs;
@@ -119,53 +110,37 @@ public class CasGenerator {
         cr_fid = cr.getProcessingResourceMetaData().getFsIndexes();
         initTotal();
         mh.frameworkInfo(cid, mid, "total:"+getTotal());
-        mh.frameworkInfo("total:"+getTotal());
-		mh.frameworkTrace(cid, mid, "exit");
 	}
 	
 	public Progress[] getProgressArray() {
-		String mid = "getProgressArray";
-		mh.frameworkTrace(cid, mid, "enter");
 		Progress[] retVal;
 		synchronized(cr) {
 			retVal = cr.getProgress();
 		}
-		mh.frameworkTrace(cid, mid, "exit");
 		return retVal;
 	}
 	
 	public Progress getProgress() {
-		String mid = "getProgress";
-		mh.frameworkTrace(cid, mid, "enter");
 		Progress progress = null;
 		Progress[] progressArray = getProgressArray();
 		if(progressArray != null) {
 			progress = progressArray[0];
 		}
-		mh.frameworkTrace(cid, mid, "exit");
 		return progress;
 	}
 	
 	private void initTotal() {
-		String mid = "initTotal";
-		mh.frameworkTrace(cid, mid, "enter");
 		Progress progress = getProgress();
 		if(progress != null) {
 			total = (int)progress.getTotal();
 		}
-		mh.frameworkTrace(cid, mid, "exit");
 	}
 	
 	public int getTotal() {
-		String mid = "getTotal";
-		mh.frameworkTrace(cid, mid, "enter");
-		mh.frameworkTrace(cid, mid, "exit");
 		return total;
 	}
 	
 	private CAS getEmptyCas() throws ResourceInitializationException {
-		String mid = "getEmptyCas";
-		mh.frameworkTrace(cid, mid, "enter");
 		CAS cas = null;
 		while(cas == null) {
 			//	Use class level locking to serialize access to CasCreationUtils
@@ -176,25 +151,18 @@ public class CasGenerator {
 				cas = CasCreationUtils.createCas(cr_tsd, cr_tp, cr_fid, cr_properties);
 			}
 		}
-		mh.frameworkTrace(cid, mid, "exit");
 		return cas;
 	}
 	
 	private CAS getNewCas() throws ResourceInitializationException, CollectionException, IOException {
-		String mid = "getNewCas";
-		mh.frameworkTrace(cid, mid, "enter");
 		CAS cas = getEmptyCas();
 		cr.getNext(cas);
-		mh.frameworkTrace(cid, mid, "exit");
 		return cas;
 	}
 	
 	public CAS getUsedCas(CAS cas) throws CollectionException, IOException, ResourceInitializationException {
-		String mid = "getUsedCas";
-		mh.frameworkTrace(cid, mid, "enter");
 		cas.reset();
 		cr.getNext(cas);
-		mh.frameworkTrace(cid, mid, "exit");
 		return cas;
 	}
 	

Modified: uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/aio/CasPipeline.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/aio/CasPipeline.java?rev=1743049&r1=1743048&r2=1743049&view=diff
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/aio/CasPipeline.java (original)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/aio/CasPipeline.java Mon May  9 20:52:55 2016
@@ -33,7 +33,7 @@ import org.apache.uima.analysis_engine.A
 import org.apache.uima.analysis_engine.AnalysisEngineManagement;
 import org.apache.uima.analysis_engine.AnalysisEngineProcessException;
 import org.apache.uima.cas.CAS;
-import org.apache.uima.ducc.cli.IUiOptions.UiOption;
+import org.apache.uima.ducc.cli.aio.AllInOne.MsgHandler;
 import org.apache.uima.ducc.common.uima.UimaHelper;
 import org.apache.uima.ducc.common.utils.QuotedOptions;
 import org.apache.uima.resource.ResourceInitializationException;
@@ -48,7 +48,7 @@ public class CasPipeline {
 
 	public static String cid = CasPipeline.class.getSimpleName();
 	
-	protected IMessageHandler mh = new MessageHandler();
+	protected MsgHandler mh;
 	protected Properties properties = new Properties();
 	
 	private AnalysisEngineDescription aed = null;
@@ -56,21 +56,14 @@ public class CasPipeline {
 
 	private CAS cas = null;
 	
-	public CasPipeline(Properties properties, IMessageHandler mh) {
-		if(properties != null) {
-			this.properties = properties;
-		}
-		if(mh != null) {
-			this.mh = mh;
-		}
+	public CasPipeline(Properties properties, AllInOne.MsgHandler mh) {
+	    this.properties = properties;
+		this.mh = mh;
 	}
 	
 	private ArrayList<String> toArrayList(String overrides) {
-		String mid = "toArrayList";
-		mh.frameworkTrace(cid, mid, "enter");
 		// To match other lists tokenize on blanks & strip any quotes around values.
         ArrayList<String> list = QuotedOptions.tokenizeList(overrides, true);
-		mh.frameworkTrace(cid, mid, "exit");
 		return list;
 	}
 	
@@ -78,7 +71,7 @@ public class CasPipeline {
 		String mid = "getFile";
 		File file;
 		if(descriptor.endsWith(".xml")) {
-			mh.frameworkTrace(cid, mid, descriptor);
+			mh.frameworkDebug(cid, mid, descriptor);
 			file = new File(descriptor);
 		}
 		else {
@@ -87,7 +80,7 @@ public class CasPipeline {
 			if(url == null) {
 				throw new IllegalArgumentException(relativePath+" not found in classpath");
 			}
-			mh.frameworkTrace(cid, mid, url.getFile());
+			mh.frameworkDebug(cid, mid, url.getFile());
 			file = new File(url.getFile());
 		}
 		return file;
@@ -95,40 +88,36 @@ public class CasPipeline {
 	
 	private void initializeByDD() throws Exception {
 		String mid = "initializeByDD";
-		mh.frameworkTrace(cid, mid, "enter");
-		String dd = properties.getProperty(UiOption.ProcessDD.pname());
+		String dd = properties.getProperty(AllInOne.ProcessDD);
 		File ddFile = getFile(dd);
 		DDParser ddParser = new DDParser(ddFile);
 		String ddImport = ddParser.getDDImport();
-		mh.frameworkTrace(cid, mid, ddImport);
+		mh.frameworkDebug(cid, mid, ddImport);
 		File uimaFile = getFile(ddImport);
 		XMLInputSource xis = new XMLInputSource(uimaFile);
 		ResourceSpecifier specifier = UIMAFramework.getXMLParser().parseResourceSpecifier(xis);
 	    ae = UIMAFramework.produceAnalysisEngine(specifier);
-		mh.frameworkTrace(cid, mid, "exit");
 	}
 	
 	private void initializeByParts() throws Exception {
-		String mid = "initializeByParts";
-		mh.frameworkTrace(cid, mid, "enter");
 		ByteArrayOutputStream baos = new ByteArrayOutputStream();
 		List<List<String>> overrides = new ArrayList<List<String>>();
 		List<String> descriptors = new ArrayList<String>();
-		String cmDescriptor = properties.getProperty(UiOption.ProcessDescriptorCM.pname());
+		String cmDescriptor = properties.getProperty(AllInOne.ProcessDescriptorCM);
 		if(cmDescriptor != null) {
-			ArrayList<String> cmOverrides = toArrayList(properties.getProperty(UiOption.ProcessDescriptorCMOverrides.pname()));
+			ArrayList<String> cmOverrides = toArrayList(properties.getProperty(AllInOne.ProcessDescriptorCMOverrides));
 			overrides.add(cmOverrides);
 			descriptors.add(cmDescriptor);
 		}
-		String aeDescriptor = properties.getProperty(UiOption.ProcessDescriptorAE.pname());
+		String aeDescriptor = properties.getProperty(AllInOne.ProcessDescriptorAE);
 		if(aeDescriptor != null) {
-			ArrayList<String> aeOverrides = toArrayList(properties.getProperty(UiOption.ProcessDescriptorAEOverrides.pname()));
+			ArrayList<String> aeOverrides = toArrayList(properties.getProperty(AllInOne.ProcessDescriptorAEOverrides));
 			overrides.add(aeOverrides);
 			descriptors.add(aeDescriptor);
 		}
-		String ccDescriptor = properties.getProperty(UiOption.ProcessDescriptorCC.pname());
+		String ccDescriptor = properties.getProperty(AllInOne.ProcessDescriptorCC);
 		if(ccDescriptor != null) {
-			ArrayList<String> ccOverrides = toArrayList(properties.getProperty(UiOption.ProcessDescriptorCCOverrides.pname()));
+			ArrayList<String> ccOverrides = toArrayList(properties.getProperty(AllInOne.ProcessDescriptorCCOverrides));
 			overrides.add(ccOverrides);
 			descriptors.add(ccDescriptor);
 		}
@@ -150,20 +139,16 @@ public class CasPipeline {
 		XMLInputSource xis = new XMLInputSource(bais, file);
 		ResourceSpecifier specifier = UIMAFramework.getXMLParser().parseResourceSpecifier(xis);
 	    ae = UIMAFramework.produceAnalysisEngine(specifier);
-		mh.frameworkTrace(cid, mid, "exit");
 	}
 	
 	public void initialize() throws Exception {
-		String mid = "initialize";
-		mh.frameworkTrace(cid, mid, "enter");
-		String dd = properties.getProperty(UiOption.ProcessDD.pname());
+		String dd = properties.getProperty(AllInOne.ProcessDD);
 		if(dd != null) {
 			initializeByDD();
 		}
 		else {
 			initializeByParts();
 		}
-		mh.frameworkTrace(cid, mid, "exit");
 	}
 	
 	public CAS process(CAS cas) throws AnalysisEngineProcessException {