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 2013/05/08 00:42:51 UTC

svn commit: r1480123 [1/2] - in /uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli: DuccJobSubmit.java DuccMonitor.java IUiOptions.java aio/AllInOneLauncher.java

Author: burn
Date: Tue May  7 22:42:51 2013
New Revision: 1480123

URL: http://svn.apache.org/r1480123
Log:
UIMA-2879 First just remove tabs

Modified:
    uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/DuccJobSubmit.java
    uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/DuccMonitor.java
    uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/IUiOptions.java
    uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/aio/AllInOneLauncher.java

Modified: uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/DuccJobSubmit.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/DuccJobSubmit.java?rev=1480123&r1=1480122&r2=1480123&view=diff
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/DuccJobSubmit.java (original)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/DuccJobSubmit.java Tue May  7 22:42:51 2013
@@ -162,8 +162,8 @@ public class DuccJobSubmit 
     {
         this(args, null);
         if(isAllInOne()) {
-        	String[] aioArgs = args.toArray(new String[0]);
-        	allInOneLauncher = new AllInOneLauncher(aioArgs);
+            String[] aioArgs = args.toArray(new String[0]);
+            allInOneLauncher = new AllInOneLauncher(aioArgs);
         }
     }
 
@@ -172,8 +172,8 @@ public class DuccJobSubmit 
     {
         this(args, null);
         if(isAllInOne()) {
-        	String[] aioArgs = args;
-        	allInOneLauncher = new AllInOneLauncher(aioArgs);
+            String[] aioArgs = args;
+            allInOneLauncher = new AllInOneLauncher(aioArgs);
         }
     }
 
@@ -182,8 +182,8 @@ public class DuccJobSubmit 
     {
         this(props, null);
         if(isAllInOne()) {
-        	String[] aioArgs = mkArgs(props);
-        	allInOneLauncher = new AllInOneLauncher(aioArgs);
+            String[] aioArgs = mkArgs(props);
+            allInOneLauncher = new AllInOneLauncher(aioArgs);
         }
     }
 
@@ -197,8 +197,8 @@ public class DuccJobSubmit 
         }
         init(this.getClass().getName(), opts, arg_array, jobRequestProperties, or_host, or_port, "or", consoleCb, null);
         if(isAllInOne()) {
-        	String[] aioArgs = args.toArray(new String[0]);
-        	allInOneLauncher = new AllInOneLauncher(aioArgs, consoleCb);
+            String[] aioArgs = args.toArray(new String[0]);
+            allInOneLauncher = new AllInOneLauncher(aioArgs, consoleCb);
         }
     }
 
@@ -211,8 +211,8 @@ public class DuccJobSubmit 
         }
         init(this.getClass().getName(), opts, args, jobRequestProperties, or_host, or_port, "or", consoleCb, null);
         if(isAllInOne()) {
-        	String[] aioArgs = args;
-        	allInOneLauncher = new AllInOneLauncher(aioArgs, consoleCb);
+            String[] aioArgs = args;
+            allInOneLauncher = new AllInOneLauncher(aioArgs, consoleCb);
         }
     }
 
@@ -229,8 +229,8 @@ public class DuccJobSubmit 
         }
         init(this.getClass().getName(), opts, null, jobRequestProperties, or_host, or_port, "or", consoleCb, null);
         if(isAllInOne()) {
-        	String[] aioArgs = mkArgs(props);
-        	allInOneLauncher = new AllInOneLauncher(aioArgs, consoleCb);
+            String[] aioArgs = mkArgs(props);
+            allInOneLauncher = new AllInOneLauncher(aioArgs, consoleCb);
         }
     }
 
@@ -271,33 +271,33 @@ public class DuccJobSubmit 
                 String text = null;
                 String pname = UiOption.SchedulingClass.pname();
                 DuccSchedulerClasses duccSchedulerClasses = DuccSchedulerClasses.getInstance();
-    			if(jobRequestProperties.containsKey(pname)) {
-    				String user_scheduling_class = jobRequestProperties.getProperty(pname);
-    				if(duccSchedulerClasses.isPreemptable(user_scheduling_class)) {
-    					scheduling_class = duccSchedulerClasses.getDebugClassSpecificName(user_scheduling_class);
-    					if(scheduling_class != null) {
-    						text = pname+"="+scheduling_class+" [replacement, specific]";
-    					}
-    					else {
-    						scheduling_class = duccSchedulerClasses.getDebugClassDefaultName();
-    						text = pname+"="+scheduling_class+" [replacement, default]";
-    					}
-    				}
-    				else {
-    					scheduling_class = user_scheduling_class;
-    					text = pname+"="+scheduling_class+" [original]";
-    				}
-    			}
-    			else {
-    				scheduling_class = duccSchedulerClasses.getDebugClassDefaultName();
-    				text = pname+"="+scheduling_class+" [default]";
-    			}
-    			if(scheduling_class != null) {
-    				 props.setProperty(pname, scheduling_class);
-    				 if(text != null) {
-    					 message(text);
-    				 }
-    			}
+                if(jobRequestProperties.containsKey(pname)) {
+                    String user_scheduling_class = jobRequestProperties.getProperty(pname);
+                    if(duccSchedulerClasses.isPreemptable(user_scheduling_class)) {
+                        scheduling_class = duccSchedulerClasses.getDebugClassSpecificName(user_scheduling_class);
+                        if(scheduling_class != null) {
+                            text = pname+"="+scheduling_class+" [replacement, specific]";
+                        }
+                        else {
+                            scheduling_class = duccSchedulerClasses.getDebugClassDefaultName();
+                            text = pname+"="+scheduling_class+" [replacement, default]";
+                        }
+                    }
+                    else {
+                        scheduling_class = user_scheduling_class;
+                        text = pname+"="+scheduling_class+" [original]";
+                    }
+                }
+                else {
+                    scheduling_class = duccSchedulerClasses.getDebugClassDefaultName();
+                    text = pname+"="+scheduling_class+" [default]";
+                }
+                if(scheduling_class != null) {
+                     props.setProperty(pname, scheduling_class);
+                     if(text != null) {
+                         message(text);
+                     }
+                }
             }
 
             do_debug = UiOption.DriverDebug.pname();
@@ -410,14 +410,14 @@ public class DuccJobSubmit 
     //**********        
     
     public boolean execute() throws Exception {
-    	if(isAllInOne()) {
-    		return execute_aio();
-    	}
-    	return execute_job();
+        if(isAllInOne()) {
+            return execute_aio();
+        }
+        return execute_job();
     }
     
     private boolean execute_aio() throws Exception {
-    	return allInOneLauncher.execute();
+        return allInOneLauncher.execute();
     }
     
     private boolean execute_job() 

Modified: uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/DuccMonitor.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/DuccMonitor.java?rev=1480123&r1=1480122&r2=1480123&view=diff
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/DuccMonitor.java (original)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/DuccMonitor.java Tue May  7 22:42:51 2013
@@ -146,401 +146,401 @@ public abstract class DuccMonitor  {
 	
 	public String getPort() {
 		String port = duccPropertiesResolver.getFileProperty("ducc.ws.port");
-		return port;
-	}
-	
-	public String getId() {
-		return id;
-	}
-	
-	private void initialize(DuccContext context, boolean submit, IDuccCallback messageProcessor) {
-		// context
-		this.context = context;
-		// submit
-		if(context != null) {
-			switch(context) {
-			case Job:
-				if(submit) {
-					opts = optsSubmitJob;
-				}
-				else {
-					opts = optsMonitorJob;
-				}	
-				break;
-			case ManagedReservation:
-				if(submit) {
-					opts = optsSubmitManagedReservation;
-				}
-				else {
-					opts = optsMonitorManagedReservation;
-				}	
-				break;
-			default:
-				break;
-			}
-		}
-		options = makeOptions(opts,false);
-		// message processor
-		if(messageProcessor != null) {
-			this.messageProcessor = messageProcessor;
-		}
-	}
-	
-	protected Options makeOptions(UiOption[] optlist, boolean strict) {
-		Options opts = new Options();
-		for ( UiOption opt : optlist ) {
-			OptionBuilder.withDescription(opt.makeDesc());
-			OptionBuilder.withLongOpt   (opt.pname()); 
-			if ( opt.argname() == null ) { 
-				OptionBuilder.hasArg(false);
-			}
-			else {
-				OptionBuilder.withArgName(opt.argname());
-				if ( opt.multiargs() ) {
-					OptionBuilder.hasArgs();
-				}
-				else {
-					OptionBuilder.hasArgs(1);
-				}
-			}
-			if ( strict && opt.required() ) {
-				OptionBuilder.isRequired();
-			}
-			Option o = OptionBuilder.create();
-			opts.addOption(o);
-		}
-		return opts;
-	}
-	
-	protected void trace(String message) {
-		if(flag_trace.get()) {
-			messageProcessor.status(timestamp(message));
-		}
-	}
-	
-	protected void debug(String message) {
-		if(flag_debug.get()) {
-			messageProcessor.status(timestamp(message));
-		}
-	}
-	
-	protected void debug(Exception e) {
-		if(flag_debug.get()) {
-			messageProcessor.status(e.toString());
-		}
-	}
-	
-	private void info(String message) {
-		if(flag_info.get()) {
-			messageProcessor.status(timestamp(message));
-		}
-	}
-	
-	private void error(String message) {
-		if(flag_error.get()) {
-			messageProcessor.status(timestamp(message));
-		}
-	}
-	
-	protected String timestamp(String message) {
-		String tMessage = message;
-		if(flag_timestamp.get()) {
-			String date = sdf.format(new java.util.Date());
-			tMessage = date+" "+message;
-		}
-		return tMessage;
-	}
-	
-	private String details(MonitorInfo monitorInfo) {
-		StringBuffer sb = new StringBuffer();
-		switch(context) {
-		case Job:
-			sb.append(" ");
-			sb.append("total:");
-			sb.append(monitorInfo.total);
-			sb.append(" ");
-			sb.append("done:");
-			sb.append(monitorInfo.done);
-			sb.append(" ");
-			sb.append("error:");
-			sb.append(monitorInfo.error);
-			sb.append(" ");
-			sb.append("retry:");
-			sb.append(monitorInfo.retry);
-			sb.append(" ");
-			sb.append("procs:");
-			sb.append(monitorInfo.procs);
-			break;
-		}
-		return sb.toString();
-	}
-	
-	private void adjustWakeupInterval() {
-		String rate = duccPropertiesResolver.getFileProperty("ducc.orchestrator.state.publish.rate");
-		try {
-			wakeupInterval = Integer.parseInt(rate);
-		}
-		catch(Exception e) {
-			debug(e);
-		}
-	}
-	
-	private int runInternal(String[] args) throws Exception {
-		// DUCC_HOME
-		String ducc_home = Utils.findDuccHome();
-		if(ducc_home == null) {
-			messageProcessor.status("Missing required environment variable: DUCC_HOME");
-			return RC_FAILURE;
-		}
-		// Ingest ducc.properties
-		duccPropertiesResolver = DuccPropertiesResolver.getInstance();
-		// Parse
-		synchronized(DuccMonitor.class) {
-			CommandLineParser parser = new PosixParser();
-			CommandLine commandLine = parser.parse(options, args);
-			if (commandLine.hasOption(DuccUiConstants.name_help)) {
-				help(options);
-				return RC_HELP;
-			}
-			if(commandLine.getOptions().length == 0) {
-				help(options);
-				return RC_HELP;
-			}
-			if (commandLine.hasOption(UiOption.Timestamp.pname())) {
-				flag_timestamp.set(true);
-			}
-			if (commandLine.hasOption(UiOption.Quiet.pname())) {
-				flag_info.set(false);
-				flag_error.set(false);
-			}
-			if (commandLine.hasOption(UiOption.Debug.pname())) {
-				flag_debug.set(true);
-			}
-			if (commandLine.hasOption(UiOption.CancelOnInterrupt.pname())) {
-				flag_cancel_on_interrupt.set(true);
-			}
-			if (commandLine.hasOption(UiOption.CancelJobOnInterrupt.pname())) {
-				flag_cancel_on_interrupt.set(true);
-			}
-			if (commandLine.hasOption(UiOption.CancelManagedReservationOnInterrupt.pname())) {
-				flag_cancel_on_interrupt.set(true);
-			}
-			if (commandLine.hasOption(UiOption.JobId.pname())) {
-				id = commandLine.getOptionValue(UiOption.JobId.pname());
-			}
-			else if (commandLine.hasOption(UiOption.ManagedReservationId.pname())) {
-				id = commandLine.getOptionValue(UiOption.ManagedReservationId.pname());
-			}
-			else {
-				HelpFormatter formatter = new HelpFormatter();
-				formatter.setWidth(110);
-				formatter.printHelp(DuccJobMonitor.class.getName(), options);
-				return RC_HELP;
-			}
-		}
-		// Handle Ctl-C
-		main = Thread.currentThread();	
-		Thread killer = new Killer(main);
-		Runtime.getRuntime().addShutdownHook(killer);
-		// Setup polling
-		adjustWakeupInterval();
-		String urlString = getUrl(id);
-		String lastMessage = "";
-		String thisMessage = "";
-		StringBuffer message = new StringBuffer();
-		message.append("id:"+id);
-		message.append(" ");
-		message.append("location:");
-		message.append(ManagementFactory.getRuntimeMXBean().getName());
-		info(message.toString());
-		// Poll until finished
-		while(flag_observer.get()) {
-			String json = getSingleLineStatus(urlString);
-			if(json != null) {
-				debug(json);
-				Gson gson = new Gson();
-				MonitorInfo monitorInfo = gson.fromJson(json, MonitorInfo.class);
-				int stateCount = monitorInfo.stateSequence.size();
-				debug("states:"+stateCount);
-				if(stateCount <= 0) {
-					message = new StringBuffer();
-					message.append("id:"+id);
-					message.append(" ");
-					message.append("state:"+NotFound);
-					thisMessage = message.toString();
-					info(thisMessage);
-					message = new StringBuffer();
-					message.append("id:"+id);
-					message.append(" ");
-					message.append("rc:"+RC_FAILURE);
-					thisMessage = message.toString();
-					info(thisMessage);
-					return RC_FAILURE;
-				}
-				String state = "";
-				Iterator<String> states = monitorInfo.stateSequence.iterator();
-				while(states.hasNext()) {
-					state = states.next();
-					debug("list:"+state);
-				}
-				message = new StringBuffer();
-				message.append("id:"+id);
-				message.append(" ");
-				message.append("state:"+state);
-				if(state.equals(StateRunning)) {
-					message.append(details(monitorInfo));
-				}
-				else if(state.equals(StateCompleting)) {
-					flag_cancel_on_interrupt.set(false);
-					message.append(details(monitorInfo));
-				}
-				else if(state.equals(StateCompleted)) {
-					flag_cancel_on_interrupt.set(false);
-					message.append(details(monitorInfo));
-				}
-				thisMessage = message.toString();
-				if(!thisMessage.equals(lastMessage)) {
-					info(thisMessage);
-					lastMessage = thisMessage;
-				}
-				if(state.equals(StateCompleted)) {
-					if(monitorInfo.procs.equals("0")) {
-						if(monitorInfo.total.equals(monitorInfo.done)) {
-							if(monitorInfo.code.equals("0")) {
-								message = new StringBuffer();
-								message.append("id:"+id);
-								message.append(" ");
-								message.append("code:"+monitorInfo.code);
-								thisMessage = message.toString();
-								info(thisMessage);
-								message = new StringBuffer();
-								message.append("id:"+id);
-								message.append(" ");
-								message.append("rc:"+RC_SUCCESS);
-								thisMessage = message.toString();
-								info(thisMessage);
-								return RC_SUCCESS;
-							}
-							else {
-								message = new StringBuffer();
-								message.append("id:"+id);
-								message.append(" ");
-								message.append("code:"+monitorInfo.code);
-								thisMessage = message.toString();
-								info(thisMessage);
-								message = new StringBuffer();
-								message.append("id:"+id);
-								message.append(" ");
-								message.append("rc:"+RC_FAILURE);
-								thisMessage = message.toString();
-								info(thisMessage);
-								return RC_FAILURE;
-							}
-						}
-						else {
-							if(!monitorInfo.errorLogs.isEmpty()) {
-								message = new StringBuffer();
-								message.append("id:"+id);
-								message.append(" ");
-								ArrayList<String> errorLogs = monitorInfo.errorLogs;
-								for(String errorLog : errorLogs) {
-									message.append("file:"+errorLog);
-								}
-								thisMessage = message.toString();
-								info(thisMessage);
-							}
-							message = new StringBuffer();
-							message.append("id:"+id);
-							message.append(" ");
-							message.append("rc:"+RC_FAILURE);
-							thisMessage = message.toString();
-							info(thisMessage);
-							return RC_FAILURE;
-						}
-					}
-				}
-			}
-			else {
-				error("error: accessing "+urlString);
-			}
-			long start = System.currentTimeMillis();
-			long end = start;
-			while(!isTimeExpired(start,end,wakeupInterval)) {
-				if(!flag_observer.get()) {
-					break;
-				}
-				try {
-					Thread.sleep(wakeupInterval);
-				} 
-				catch (InterruptedException e) {
-					debug(e);
-				}
-				end = System.currentTimeMillis();
-			}
-			
-		}
-		return RC_SUCCESS;
-	}
-	
-	private boolean isTimeExpired(long start, long end, long interval) {
-		boolean retVal = false;
-		long diff = end - start;
-		if(diff >= interval) {
-			retVal = true;
-		}
-		trace("start:"+start+" "+"end:"+end+" "+"diff:"+diff+" "+"interval:"+interval+" "+"result:"+retVal);
-		return retVal;
-	}
+        return port;
+    }
+    
+    public String getId() {
+        return id;
+    }
+    
+    private void initialize(DuccContext context, boolean submit, IDuccCallback messageProcessor) {
+        // context
+        this.context = context;
+        // submit
+        if(context != null) {
+            switch(context) {
+            case Job:
+                if(submit) {
+                    opts = optsSubmitJob;
+                }
+                else {
+                    opts = optsMonitorJob;
+                }   
+                break;
+            case ManagedReservation:
+                if(submit) {
+                    opts = optsSubmitManagedReservation;
+                }
+                else {
+                    opts = optsMonitorManagedReservation;
+                }   
+                break;
+            default:
+                break;
+            }
+        }
+        options = makeOptions(opts,false);
+        // message processor
+        if(messageProcessor != null) {
+            this.messageProcessor = messageProcessor;
+        }
+    }
+    
+    protected Options makeOptions(UiOption[] optlist, boolean strict) {
+        Options opts = new Options();
+        for ( UiOption opt : optlist ) {
+            OptionBuilder.withDescription(opt.makeDesc());
+            OptionBuilder.withLongOpt   (opt.pname()); 
+            if ( opt.argname() == null ) { 
+                OptionBuilder.hasArg(false);
+            }
+            else {
+                OptionBuilder.withArgName(opt.argname());
+                if ( opt.multiargs() ) {
+                    OptionBuilder.hasArgs();
+                }
+                else {
+                    OptionBuilder.hasArgs(1);
+                }
+            }
+            if ( strict && opt.required() ) {
+                OptionBuilder.isRequired();
+            }
+            Option o = OptionBuilder.create();
+            opts.addOption(o);
+        }
+        return opts;
+    }
+    
+    protected void trace(String message) {
+        if(flag_trace.get()) {
+            messageProcessor.status(timestamp(message));
+        }
+    }
+    
+    protected void debug(String message) {
+        if(flag_debug.get()) {
+            messageProcessor.status(timestamp(message));
+        }
+    }
+    
+    protected void debug(Exception e) {
+        if(flag_debug.get()) {
+            messageProcessor.status(e.toString());
+        }
+    }
+    
+    private void info(String message) {
+        if(flag_info.get()) {
+            messageProcessor.status(timestamp(message));
+        }
+    }
+    
+    private void error(String message) {
+        if(flag_error.get()) {
+            messageProcessor.status(timestamp(message));
+        }
+    }
+    
+    protected String timestamp(String message) {
+        String tMessage = message;
+        if(flag_timestamp.get()) {
+            String date = sdf.format(new java.util.Date());
+            tMessage = date+" "+message;
+        }
+        return tMessage;
+    }
+    
+    private String details(MonitorInfo monitorInfo) {
+        StringBuffer sb = new StringBuffer();
+        switch(context) {
+        case Job:
+            sb.append(" ");
+            sb.append("total:");
+            sb.append(monitorInfo.total);
+            sb.append(" ");
+            sb.append("done:");
+            sb.append(monitorInfo.done);
+            sb.append(" ");
+            sb.append("error:");
+            sb.append(monitorInfo.error);
+            sb.append(" ");
+            sb.append("retry:");
+            sb.append(monitorInfo.retry);
+            sb.append(" ");
+            sb.append("procs:");
+            sb.append(monitorInfo.procs);
+            break;
+        }
+        return sb.toString();
+    }
+    
+    private void adjustWakeupInterval() {
+        String rate = duccPropertiesResolver.getFileProperty("ducc.orchestrator.state.publish.rate");
+        try {
+            wakeupInterval = Integer.parseInt(rate);
+        }
+        catch(Exception e) {
+            debug(e);
+        }
+    }
+    
+    private int runInternal(String[] args) throws Exception {
+        // DUCC_HOME
+        String ducc_home = Utils.findDuccHome();
+        if(ducc_home == null) {
+            messageProcessor.status("Missing required environment variable: DUCC_HOME");
+            return RC_FAILURE;
+        }
+        // Ingest ducc.properties
+        duccPropertiesResolver = DuccPropertiesResolver.getInstance();
+        // Parse
+        synchronized(DuccMonitor.class) {
+            CommandLineParser parser = new PosixParser();
+            CommandLine commandLine = parser.parse(options, args);
+            if (commandLine.hasOption(DuccUiConstants.name_help)) {
+                help(options);
+                return RC_HELP;
+            }
+            if(commandLine.getOptions().length == 0) {
+                help(options);
+                return RC_HELP;
+            }
+            if (commandLine.hasOption(UiOption.Timestamp.pname())) {
+                flag_timestamp.set(true);
+            }
+            if (commandLine.hasOption(UiOption.Quiet.pname())) {
+                flag_info.set(false);
+                flag_error.set(false);
+            }
+            if (commandLine.hasOption(UiOption.Debug.pname())) {
+                flag_debug.set(true);
+            }
+            if (commandLine.hasOption(UiOption.CancelOnInterrupt.pname())) {
+                flag_cancel_on_interrupt.set(true);
+            }
+            if (commandLine.hasOption(UiOption.CancelJobOnInterrupt.pname())) {
+                flag_cancel_on_interrupt.set(true);
+            }
+            if (commandLine.hasOption(UiOption.CancelManagedReservationOnInterrupt.pname())) {
+                flag_cancel_on_interrupt.set(true);
+            }
+            if (commandLine.hasOption(UiOption.JobId.pname())) {
+                id = commandLine.getOptionValue(UiOption.JobId.pname());
+            }
+            else if (commandLine.hasOption(UiOption.ManagedReservationId.pname())) {
+                id = commandLine.getOptionValue(UiOption.ManagedReservationId.pname());
+            }
+            else {
+                HelpFormatter formatter = new HelpFormatter();
+                formatter.setWidth(110);
+                formatter.printHelp(DuccJobMonitor.class.getName(), options);
+                return RC_HELP;
+            }
+        }
+        // Handle Ctl-C
+        main = Thread.currentThread();  
+        Thread killer = new Killer(main);
+        Runtime.getRuntime().addShutdownHook(killer);
+        // Setup polling
+        adjustWakeupInterval();
+        String urlString = getUrl(id);
+        String lastMessage = "";
+        String thisMessage = "";
+        StringBuffer message = new StringBuffer();
+        message.append("id:"+id);
+        message.append(" ");
+        message.append("location:");
+        message.append(ManagementFactory.getRuntimeMXBean().getName());
+        info(message.toString());
+        // Poll until finished
+        while(flag_observer.get()) {
+            String json = getSingleLineStatus(urlString);
+            if(json != null) {
+                debug(json);
+                Gson gson = new Gson();
+                MonitorInfo monitorInfo = gson.fromJson(json, MonitorInfo.class);
+                int stateCount = monitorInfo.stateSequence.size();
+                debug("states:"+stateCount);
+                if(stateCount <= 0) {
+                    message = new StringBuffer();
+                    message.append("id:"+id);
+                    message.append(" ");
+                    message.append("state:"+NotFound);
+                    thisMessage = message.toString();
+                    info(thisMessage);
+                    message = new StringBuffer();
+                    message.append("id:"+id);
+                    message.append(" ");
+                    message.append("rc:"+RC_FAILURE);
+                    thisMessage = message.toString();
+                    info(thisMessage);
+                    return RC_FAILURE;
+                }
+                String state = "";
+                Iterator<String> states = monitorInfo.stateSequence.iterator();
+                while(states.hasNext()) {
+                    state = states.next();
+                    debug("list:"+state);
+                }
+                message = new StringBuffer();
+                message.append("id:"+id);
+                message.append(" ");
+                message.append("state:"+state);
+                if(state.equals(StateRunning)) {
+                    message.append(details(monitorInfo));
+                }
+                else if(state.equals(StateCompleting)) {
+                    flag_cancel_on_interrupt.set(false);
+                    message.append(details(monitorInfo));
+                }
+                else if(state.equals(StateCompleted)) {
+                    flag_cancel_on_interrupt.set(false);
+                    message.append(details(monitorInfo));
+                }
+                thisMessage = message.toString();
+                if(!thisMessage.equals(lastMessage)) {
+                    info(thisMessage);
+                    lastMessage = thisMessage;
+                }
+                if(state.equals(StateCompleted)) {
+                    if(monitorInfo.procs.equals("0")) {
+                        if(monitorInfo.total.equals(monitorInfo.done)) {
+                            if(monitorInfo.code.equals("0")) {
+                                message = new StringBuffer();
+                                message.append("id:"+id);
+                                message.append(" ");
+                                message.append("code:"+monitorInfo.code);
+                                thisMessage = message.toString();
+                                info(thisMessage);
+                                message = new StringBuffer();
+                                message.append("id:"+id);
+                                message.append(" ");
+                                message.append("rc:"+RC_SUCCESS);
+                                thisMessage = message.toString();
+                                info(thisMessage);
+                                return RC_SUCCESS;
+                            }
+                            else {
+                                message = new StringBuffer();
+                                message.append("id:"+id);
+                                message.append(" ");
+                                message.append("code:"+monitorInfo.code);
+                                thisMessage = message.toString();
+                                info(thisMessage);
+                                message = new StringBuffer();
+                                message.append("id:"+id);
+                                message.append(" ");
+                                message.append("rc:"+RC_FAILURE);
+                                thisMessage = message.toString();
+                                info(thisMessage);
+                                return RC_FAILURE;
+                            }
+                        }
+                        else {
+                            if(!monitorInfo.errorLogs.isEmpty()) {
+                                message = new StringBuffer();
+                                message.append("id:"+id);
+                                message.append(" ");
+                                ArrayList<String> errorLogs = monitorInfo.errorLogs;
+                                for(String errorLog : errorLogs) {
+                                    message.append("file:"+errorLog);
+                                }
+                                thisMessage = message.toString();
+                                info(thisMessage);
+                            }
+                            message = new StringBuffer();
+                            message.append("id:"+id);
+                            message.append(" ");
+                            message.append("rc:"+RC_FAILURE);
+                            thisMessage = message.toString();
+                            info(thisMessage);
+                            return RC_FAILURE;
+                        }
+                    }
+                }
+            }
+            else {
+                error("error: accessing "+urlString);
+            }
+            long start = System.currentTimeMillis();
+            long end = start;
+            while(!isTimeExpired(start,end,wakeupInterval)) {
+                if(!flag_observer.get()) {
+                    break;
+                }
+                try {
+                    Thread.sleep(wakeupInterval);
+                } 
+                catch (InterruptedException e) {
+                    debug(e);
+                }
+                end = System.currentTimeMillis();
+            }
+            
+        }
+        return RC_SUCCESS;
+    }
+    
+    private boolean isTimeExpired(long start, long end, long interval) {
+        boolean retVal = false;
+        long diff = end - start;
+        if(diff >= interval) {
+            retVal = true;
+        }
+        trace("start:"+start+" "+"end:"+end+" "+"diff:"+diff+" "+"interval:"+interval+" "+"result:"+retVal);
+        return retVal;
+    }
 
-	private String getSingleLineStatus(String urlString) {
-		String line = null;
-		URL url = null;
-		try {
-		    url = new URL(urlString);
-		    URLConnection uc = url.openConnection();
-		    uc.setReadTimeout(urlTimeout); 
-		    BufferedReader br = new BufferedReader(new InputStreamReader(uc.getInputStream()));
-		    line = br.readLine();
-		    br.close();
-		} 
-		catch (MalformedURLException e) {
-		    e.printStackTrace();
-		}
-		catch(IOException e) {
-			e.printStackTrace();
-		} 
-		return line;
-	}
-	
-	private class Killer extends Thread {
-		
-		public Killer(Thread thread) {
-		}
-		
-		public void run() {
-			StringBuffer message = new StringBuffer();
-			if(flag_cancel_on_interrupt.get()) {
-				message.append("killer: cancel");
-				cancel();
-			}
-			else {
-				message.append("killer: no cancel");
-			}
-			debug(message.toString());
-			flag_observer.set(false);
-		}
-	}
-	
-	public int run(String[] args) {
-		int code = RC_FAILURE;
-       	try {
-       		code = runInternal(args);
-    	} 
-       	catch (Exception e) {
-    		messageProcessor.status(e.toString());
-    	}
-       	debug("rc="+code);
-       	return code;
-	}
+    private String getSingleLineStatus(String urlString) {
+        String line = null;
+        URL url = null;
+        try {
+            url = new URL(urlString);
+            URLConnection uc = url.openConnection();
+            uc.setReadTimeout(urlTimeout); 
+            BufferedReader br = new BufferedReader(new InputStreamReader(uc.getInputStream()));
+            line = br.readLine();
+            br.close();
+        } 
+        catch (MalformedURLException e) {
+            e.printStackTrace();
+        }
+        catch(IOException e) {
+            e.printStackTrace();
+        } 
+        return line;
+    }
+    
+    private class Killer extends Thread {
+        
+        public Killer(Thread thread) {
+        }
+        
+        public void run() {
+            StringBuffer message = new StringBuffer();
+            if(flag_cancel_on_interrupt.get()) {
+                message.append("killer: cancel");
+                cancel();
+            }
+            else {
+                message.append("killer: no cancel");
+            }
+            debug(message.toString());
+            flag_observer.set(false);
+        }
+    }
+    
+    public int run(String[] args) {
+        int code = RC_FAILURE;
+        try {
+            code = runInternal(args);
+        } 
+        catch (Exception e) {
+            messageProcessor.status(e.toString());
+        }
+        debug("rc="+code);
+        return code;
+    }
 
 }

Modified: uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/IUiOptions.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/IUiOptions.java?rev=1480123&r1=1480122&r2=1480123&view=diff
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/IUiOptions.java (original)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/IUiOptions.java Tue May  7 22:42:51 2013
@@ -43,7 +43,7 @@ public interface IUiOptions
     // argname()     is a name for the argument for the usage() part of cli parser
     //
 
-	public static final int help_width = 120;
+    public static final int help_width = 120;
 
     public enum UiOption
     {
@@ -103,7 +103,7 @@ public interface IUiOptions
             public boolean required()   { return false; }
         },            
 
-		// Deprecated
+        // Deprecated
         CancelManagedReservationOnInterrupt { 
             public String pname()       { return ReservationSpecificationProperties.key_cancel_managed_reservation_on_interrupt; }
             public String argname()     { return null; }
@@ -985,41 +985,41 @@ public interface IUiOptions
         // Beta options helper functions
         
         public UiOption[] getBetaOptions() {
-        	UiOption[] list = { DriverClasspath, 
-        						DriverEnvironment,
-        						DriverJvmArgs,
-        						ProcessClasspath, 
-        						ProcessEnvironment,
-        						ProcessJvmArgs,
-        						};
-        	return list;
+            UiOption[] list = { DriverClasspath, 
+                                DriverEnvironment,
+                                DriverJvmArgs,
+                                ProcessClasspath, 
+                                ProcessEnvironment,
+                                ProcessJvmArgs,
+                                };
+            return list;
         }
         
         public boolean isBetaOption(String pname) {
-        	boolean retVal = false;
-        	if(pname != null) {
-        		UiOption[] list = getBetaOptions();
-            	for(UiOption option : list) {
-            		if(pname.equals(option.pname())) {
-            			retVal = true;
-            		}
-            	}
-        	}
-        	return retVal;
+            boolean retVal = false;
+            if(pname != null) {
+                UiOption[] list = getBetaOptions();
+                for(UiOption option : list) {
+                    if(pname.equals(option.pname())) {
+                        retVal = true;
+                    }
+                }
+            }
+            return retVal;
         }
         
         public boolean isBetaOption(UiOption option) {
-        	boolean retVal = false;
-        	if(option != null) {
-        		retVal = isBetaOption(option.pname());
-        	}
-        	return retVal;
+            boolean retVal = false;
+            if(option != null) {
+                retVal = isBetaOption(option.pname());
+            }
+            return retVal;
         }
         
     };
 
     public enum ClasspathOrderParms
-    {    	    	
+    {               
         UserBeforeDucc   { 
             public String pname()      { return DuccUiConstants.classpath_order_user_before_ducc; } 
             public String description() { return "Start process with user's classpath ahead of DUCC's"; }