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 2019/10/30 22:05:22 UTC

svn commit: r1869192 - in /uima/uima-ducc/trunk: src/main/resources/ src/main/scripts/ uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/ uima-ducc-orchestrator/src/main/java/org/apache/uima/ducc/orchestrator/factory/ uima-ducc-transport/src/main/ja...

Author: burn
Date: Wed Oct 30 22:05:22 2019
New Revision: 1869192

URL: http://svn.apache.org/viewvc?rev=1869192&view=rev
Log:
UIMA-6130 Added ducc_jed_submit cmd & DuccJedSubmit class that launches JED as an AP

Added:
    uima/uima-ducc/trunk/src/main/scripts/ducc_jed_submit   (with props)
    uima/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/DuccJedSubmit.java   (with props)
Modified:
    uima/uima-ducc/trunk/src/main/resources/default.ducc.properties
    uima/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/CliBase.java
    uima/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/IUiOptions.java
    uima/uima-ducc/trunk/uima-ducc-orchestrator/src/main/java/org/apache/uima/ducc/orchestrator/factory/JobFactory.java
    uima/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/event/cli/JobSpecificationProperties.java

Modified: uima/uima-ducc/trunk/src/main/resources/default.ducc.properties
URL: http://svn.apache.org/viewvc/uima/uima-ducc/trunk/src/main/resources/default.ducc.properties?rev=1869192&r1=1869191&r2=1869192&view=diff
==============================================================================
--- uima/uima-ducc/trunk/src/main/resources/default.ducc.properties (original)
+++ uima/uima-ducc/trunk/src/main/resources/default.ducc.properties Wed Oct 30 22:05:22 2019
@@ -342,6 +342,10 @@ ducc.ws.user.data.access = unrestricted
 #  change: effective immediately
 #ducc.ws.banner.message = Do not adjust your set.  This is a message from your DUCC administrator.
 
+# NOTE - Feature under devlopment
+# When set exposes the Experiments page and enables the ducc_jed_submit script
+ducc.experiments = false
+
 # +==================================================================================================+
 # | Job Driver                                                                                       |
 # +==================================================================================================+

Added: uima/uima-ducc/trunk/src/main/scripts/ducc_jed_submit
URL: http://svn.apache.org/viewvc/uima/uima-ducc/trunk/src/main/scripts/ducc_jed_submit?rev=1869192&view=auto
==============================================================================
--- uima/uima-ducc/trunk/src/main/scripts/ducc_jed_submit (added)
+++ uima/uima-ducc/trunk/src/main/scripts/ducc_jed_submit Wed Oct 30 22:05:22 2019
@@ -0,0 +1,37 @@
+#! /usr/bin/env python
+
+# -----------------------------------------------------------------------
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+# -----------------------------------------------------------------------
+
+# NOTE - this script will fail if the Experiments page is disabled (the default)
+
+import sys
+from ducc_base import DuccBase
+
+class DuccJedSubmit(DuccBase):
+
+    def main(self, argv):
+        self.spawn(self.java(), '-cp', self.DUCC_HOME + '/lib/uima-ducc-cli.jar', 'org.apache.uima.ducc.cli.DuccJedSubmit', ' '.join(self.mkargs(argv)))
+
+if __name__ == "__main__":
+    submit = DuccJedSubmit()
+    #for i in os.environ['CLASSPATH'].split(':'):
+    #    print i
+
+    submit.main(sys.argv[1:])

Propchange: uima/uima-ducc/trunk/src/main/scripts/ducc_jed_submit
------------------------------------------------------------------------------
    svn:executable = *

Modified: uima/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/CliBase.java
URL: http://svn.apache.org/viewvc/uima/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/CliBase.java?rev=1869192&r1=1869191&r2=1869192&view=diff
==============================================================================
--- uima/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/CliBase.java (original)
+++ uima/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/CliBase.java Wed Oct 30 22:05:22 2019
@@ -105,33 +105,31 @@ public abstract class CliBase implements
   }
 
   /*
-   * Make the log directory absolute if necessary and check that it is usable.
+   * Make the directory absolute if necessary and check that it is usable.
    * If not provided it will have been given a default value.
    * UIMA-4617 Make it relative to the run-time working directory, not HOME
    */
-  String getLogDirectory(String working_directory) throws IOException {
-    String log_directory = cli_props.getProperty(UiOption.LogDirectory.pname());
-    File f;
-    if (log_directory.startsWith(File.separator)) {
-      f = new File(log_directory);
-    } else {
-      f = new File(working_directory, log_directory); // Relative to working directory
-      log_directory = f.getCanonicalPath();
-      cli_props.setProperty(UiOption.LogDirectory.pname(), log_directory);
+  String getDirectory(IUiOption uiopt, String working_directory) throws IOException {
+    String directory = cli_props.getProperty(uiopt.pname());
+    File f = new File(directory);
+    if (!f.isAbsolute()) {
+      f = new File(working_directory, directory); // Relative to working directory
+      directory = f.getCanonicalPath();
+      cli_props.setProperty(uiopt.pname(), directory);
     }
 
     /*
-     * make sure the logdir is actually legal.
+     * make sure the directory is actually legal. 
      * JD may also be creating it so to reduce any race or NFS delay blindly create and then test
      */
     f.mkdirs();
     if (!f.isDirectory() || !f.canWrite()) {
-      throw new IllegalArgumentException("Specified log_directory is not a writable directory: " + log_directory);
+      throw new IllegalArgumentException("Specified directory is not a writable directory: " + directory);
     }
 
-    return log_directory;
+    return directory;
   }
-
+  
   /*
    * Ensure the working directory exists and is absolute
    */
@@ -441,7 +439,9 @@ public abstract class CliBase implements
       if (uiopt == UiOption.WorkingDirectory) {
         workingDir = getWorkingDirectory();
       } else if (uiopt == UiOption.LogDirectory) {
-        logDir = getLogDirectory(workingDir);
+        logDir = getDirectory(uiopt, workingDir);
+      } else if (uiopt == UiOption.OutputDirectory) {
+        getDirectory(uiopt, workingDir);
       } else if (uiopt == UiOption.Environment) {
         // If this request accepts the --environment option may need to augment it by
         // renaming LD_LIBRARY_PATH & propagating some user values

Added: uima/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/DuccJedSubmit.java
URL: http://svn.apache.org/viewvc/uima/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/DuccJedSubmit.java?rev=1869192&view=auto
==============================================================================
--- uima/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/DuccJedSubmit.java (added)
+++ uima/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/DuccJedSubmit.java Wed Oct 30 22:05:22 2019
@@ -0,0 +1,251 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+*/
+package org.apache.uima.ducc.cli;
+
+import java.util.ArrayList;
+import java.util.Map.Entry;
+import java.util.Properties;
+
+import org.apache.uima.ducc.common.utils.DuccPropertiesResolver;
+import org.apache.uima.ducc.common.utils.IllegalConfigurationException;
+import org.apache.uima.ducc.transport.event.IDuccContext.DuccContext;
+import org.apache.uima.ducc.transport.event.SubmitServiceDuccEvent;
+import org.apache.uima.ducc.transport.event.SubmitServiceReplyDuccEvent;
+import org.apache.uima.ducc.transport.event.cli.ServiceRequestProperties;
+
+/**
+ * Submit a DUCC Managed Reservation. A Managed Reservation is a single arbitray process running in a non-preemptable share.
+ */
+
+public class DuccJedSubmit extends CliBase {
+  private static String dt = "Jed";
+
+  private ServiceRequestProperties serviceRequestProperties;
+
+  private UiOption[] opts = new UiOption[] { 
+      UiOption.Help, 
+      UiOption.Debug, 
+      UiOption.Description, 
+      UiOption.WorkingDirectory, // Must precede LogDirecory
+      UiOption.LogDirectory,     // Must precede Environment
+      UiOption.OutputDirectory,  // JED output directory
+      UiOption.Environment, 
+      UiOption.ProcessExecutableArgsRequired, 
+      UiOption.ProcessMemorySize, 
+      UiOption.SchedulingClass,
+      UiOption.Specification, 
+      };
+
+  /**
+   * @param args
+   *          List of string arguments as described in the Command Line Interface section of the DuccBook
+   * @throws Exception
+   *           if request fails
+   */
+  public DuccJedSubmit(String[] args) throws Exception {
+    this(args, null);
+  }
+
+  /**
+   * @param args
+   *          Array of string arguments as described in the Command Line Interface section of the DuccBook
+   * @throws Exception
+   *           if request fails
+   */
+  public DuccJedSubmit(ArrayList<String> args) throws Exception {
+    this(args, null);
+  }
+
+  /**
+   * @param props
+   *          Properties file of arguments, as described in the Command Line Interface section of the DuccBook
+   * @throws Exception
+   *           if request fails
+   */
+  public DuccJedSubmit(Properties props) throws Exception {
+    this(props, null);
+  }
+
+  /**
+   * This form of the constructor allows the API user to capture messages, rather than directing them to stdout.
+   *
+   * @param args
+   *          Array of string arguments as described in the Command Line Interface section of the DuccBook
+   * @param consoleCb
+   *          If provided, messages are directed to it instead of stdout.
+   * @throws Exception
+   *           if request fails
+   */
+  public DuccJedSubmit(String[] args, IDuccCallback consoleCb) throws Exception {
+    serviceRequestProperties = new ServiceRequestProperties();
+    init(this.getClass().getName(), opts, args, serviceRequestProperties, consoleCb);
+  }
+
+  /**
+   * This form of the constructor allows the API user to capture messages, rather than directing them to stdout.
+   *
+   * @param args
+   *          List of string arguments as described in the Command Line Interface section of the DuccBook
+   * @param consoleCb
+   *          If provided, messages are directed to it instead of stdout.
+   * @throws Exception
+   *           if request fails
+   */
+  public DuccJedSubmit(ArrayList<String> args, IDuccCallback consoleCb) throws Exception {
+    String[] arg_array = args.toArray(new String[args.size()]);
+    serviceRequestProperties = new ServiceRequestProperties();
+    init(this.getClass().getName(), opts, arg_array, serviceRequestProperties, consoleCb);
+  }
+
+  /**
+   * This form of the constructor allows the API user to capture messages, rather than directing them to stdout.
+   *
+   * @param props
+   *          Properties file contianing string arguments as described in the Command Line Interface section of the DuccBook
+   * @param consoleCb
+   *          If provided, messages are directed to it instead of stdout.
+   * @throws Exception
+   *           if request fails
+   */
+  public DuccJedSubmit(Properties props, IDuccCallback consoleCb) throws Exception {
+    serviceRequestProperties = new ServiceRequestProperties();
+    init(this.getClass().getName(), opts, props, serviceRequestProperties, consoleCb);
+  }
+
+  /**
+   * Execute collects the job parameters, does basic error and correctness checking, and sends the job properties to the DUCC orchestrator for
+   * execution.
+   *
+   * @return True if the orchestrator accepts the job; false otherwise.
+   * @throws Exception
+   *           if request fails
+   */
+  public boolean execute() throws Exception {
+    
+    // Check if the experiments page is enabled
+    if (DuccPropertiesResolver.get("ducc.experiments", "false").equalsIgnoreCase("false")) {
+      throw new IllegalConfigurationException("JED experiments not enabled in ducc.properties");
+    }
+    
+    // Create a copy to be saved later without these 3 "ducclet" properties required by DUCC
+    ServiceRequestProperties userSpecifiedProperties = (ServiceRequestProperties) serviceRequestProperties.clone();
+    serviceRequestProperties.setProperty(UiOption.ProcessPipelineCount.pname(), "1");
+    serviceRequestProperties.setProperty(UiOption.ProcessDeploymentsMax.pname(), "1");
+    serviceRequestProperties.setProperty(UiOption.ServiceTypeOther.pname(), "");
+    
+    // Create the AP properties for the JED call
+    String javaHome = System.getProperty("java.home");
+    serviceRequestProperties.setProperty(UiOption.ProcessExecutable.pname(), javaHome + "/bin/java");
+    
+    String jedArgs = "-cp " +
+            ducc_home + "/lib/jed/*:" +
+            ducc_home + "/lib/google-gson/*:" +
+            ducc_home + "/apache-uima/lib/*:" +
+            ducc_home + "/lib/uima-ducc-cli.jar " + 
+            "com.ibm.watsonx.framework.jed.Driver ";
+    String userArgs = serviceRequestProperties.getProperty(UiOption.ProcessExecutableArgsRequired.pname());
+    String outputDir = serviceRequestProperties.getProperty(UiOption.OutputDirectory.pname());
+    String args = jedArgs + userArgs + " --outputBaseDirectory=" + outputDir;
+    serviceRequestProperties.setProperty(UiOption.ProcessExecutableArgsRequired.pname(), args);
+    
+    // Add the environment variable that tells the OR this is a JED AP
+    // Also add DUCC_HOME so the JED properties can reference it
+    String jedEnv = "DUCC_HOME="+ducc_home + " DUCC_JED_DIR="+outputDir + " ";
+    String userEnv = serviceRequestProperties.getProperty(UiOption.Environment.pname());
+    if (userEnv != null) {
+      jedEnv += userEnv;
+    }
+    serviceRequestProperties.setProperty(UiOption.Environment.pname(), jedEnv);
+    
+    // Create a description if none provided
+    String desc = serviceRequestProperties.getProperty(UiOption.Description.pname());
+    if (desc == null || desc.equals(UiOption.Description.deflt())) {
+      serviceRequestProperties.setProperty(UiOption.Description.pname(), "JED -- " + outputDir);
+    }
+
+    // Keep list of user provided properties for WS display: user vs. system
+    for (Entry<Object, Object> entry : userSpecifiedProperties.entrySet()) {
+      String key = (String) entry.getKey();
+      serviceRequestProperties.addUserProvided(key);
+    }
+
+    // Note: context is provided for system event logger to disambiguate Service from ManagedReservation
+    SubmitServiceDuccEvent ev = new SubmitServiceDuccEvent(serviceRequestProperties, DuccContext.ManagedReservation, CliVersion.getVersion());
+    SubmitServiceReplyDuccEvent reply = null;
+
+    try {
+      reply = (SubmitServiceReplyDuccEvent) dispatcher.dispatchAndWaitForDuccReply(ev);
+    } finally {
+      dispatcher.close();
+    }
+
+    /*
+     * process reply
+     */
+    boolean rc = extractReply(reply);
+    if (rc) {
+      saveSpec(DuccUiConstants.managed_reservation_properties, userSpecifiedProperties);
+      startMonitors(true, DuccContext.ManagedReservation); // starts conditionally, based on job spec and console listener present
+    }
+
+    return rc;
+  }
+
+  /**
+   * Main method, as used by the executable jar or direct java invocation.
+   * 
+   * @param args
+   *          arguments as described in the <a href="/doc/duccbook.html#DUCC_CLI_PROCESS_SUBMIT">DUCC CLI reference.</a>
+   */
+  public static void main(String[] args) {
+    int code = 1; // Assume the worst
+    try {
+      // Instantiate the object with args similar to the CLI, or a pre-built properties file
+      DuccJedSubmit ds = new DuccJedSubmit(args);
+
+      // Run the API. If process_attach_console was specified in the args, a console listener is
+      // started but this call does NOT block on it.
+      boolean rc = ds.execute();
+
+      // If the return is 'true' then as best the API can tell, the submit worked
+      if (rc) {
+        System.out.println(dt + " " + ds.getDuccId() + " submitted.");
+        code = ds.getReturnCode();
+      } else {
+        System.out.println(dt + " Could not submit ");
+      }
+    } catch (Throwable e) {
+      System.out.println(dt + " Cannot initialize: " + e);
+      Throwable t = e;
+      while ((t = t.getCause()) != null) {
+        System.out.println("  ... " + t);
+      }
+      for (String arg : args) {
+        if (arg.equals("--debug")) {
+          e.printStackTrace();
+          break;
+        }
+      }
+    } finally {
+      // Set the process exit code
+      System.exit(code);
+    }
+  }
+
+}

Propchange: uima/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/DuccJedSubmit.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: uima/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/IUiOptions.java
URL: http://svn.apache.org/viewvc/uima/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/IUiOptions.java?rev=1869192&r1=1869191&r2=1869192&view=diff
==============================================================================
--- uima/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/IUiOptions.java (original)
+++ uima/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/IUiOptions.java Wed Oct 30 22:05:22 2019
@@ -477,6 +477,14 @@ public interface IUiOptions
             public String example()     { return "-a -t -l"; }
         },            
 
+        ProcessExecutableArgsRequired { 
+            public String pname()       { return JobSpecificationProperties.key_process_executable_args; }
+            public String argname()     { return "argument list"; }
+            public String description() { return "Blank-delimited list of required arguments."; }
+            public String example()     { return "test.properties --arg1=value1 --arg2=value2"; }
+            public boolean required()   { return true; }
+        },            
+
         ProcessInitializationTimeMax { 
             public String pname()       { return JobSpecificationProperties.key_process_initialization_time_max; }
             public String description() { return DuccUiConstants.desc_process_initialization_time_max; }
@@ -673,7 +681,14 @@ public interface IUiOptions
             public String argname()     { return "path"; }
             public String description() { return "The working directory set in each process. Default to current directory."; }
             public String deflt()       { return "."; }
-        },            
+        },
+        
+        OutputDirectory { 
+            public String pname()       { return JobSpecificationProperties.key_output_directory; }
+            public String argname()     { return "path"; }
+            public String description() { return "The output directory for the experiment."; }
+            public boolean required()   { return true; }
+        },
         ;
 
         public String  argname()   { return null; }  // the type of argument, if any

Modified: uima/uima-ducc/trunk/uima-ducc-orchestrator/src/main/java/org/apache/uima/ducc/orchestrator/factory/JobFactory.java
URL: http://svn.apache.org/viewvc/uima/uima-ducc/trunk/uima-ducc-orchestrator/src/main/java/org/apache/uima/ducc/orchestrator/factory/JobFactory.java?rev=1869192&r1=1869191&r2=1869192&view=diff
==============================================================================
--- uima/uima-ducc/trunk/uima-ducc-orchestrator/src/main/java/org/apache/uima/ducc/orchestrator/factory/JobFactory.java (original)
+++ uima/uima-ducc/trunk/uima-ducc-orchestrator/src/main/java/org/apache/uima/ducc/orchestrator/factory/JobFactory.java Wed Oct 30 22:05:22 2019
@@ -524,13 +524,6 @@ public class JobFactory implements IJobF
 
 		if (job.getDuccType() == DuccType.Job){
 		    checkSchedulingLimits(job, schedulingInfo);
-		} else {
-		  // HACK - Check if a JED AP ... duccType is "service" !!!
-		  // HACK - experiment directory MUST = log directoery
-	    String args = jobRequestProperties.getProperty(JobSpecificationProperties.key_process_executable_args);
-	    if (args != null && args.contains(" com.ibm.watsonx.framework.jed.Driver ")) {
-	      standardInfo.setExperimentDirectory(standardInfo.getLogDirectory());
-	    }
 		}
 
 		// process_initialization_time_max (in minutes)
@@ -681,6 +674,12 @@ public class JobFactory implements IJobF
 			List<String> process_executable_arguments = QuotedOptions.tokenizeList(
 			        jobRequestProperties.getProperty(JobSpecificationProperties.key_process_executable_args), true);
 			executableProcessCommandLine.getArguments().addAll(process_executable_arguments);
+			
+			// JED check
+			String jedDir = executableProcessCommandLine.getEnvVar("DUCC_JED_DIR");
+			if (jedDir != null) {
+			  standardInfo.setExperimentDirectory(jedDir);
+			}
 		}
 		// process_initialization_failures_cap
 		// ?? These are not set for APs or SPs ??

Modified: uima/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/event/cli/JobSpecificationProperties.java
URL: http://svn.apache.org/viewvc/uima/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/event/cli/JobSpecificationProperties.java?rev=1869192&r1=1869191&r2=1869192&view=diff
==============================================================================
--- uima/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/event/cli/JobSpecificationProperties.java (original)
+++ uima/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/event/cli/JobSpecificationProperties.java Wed Oct 30 22:05:22 2019
@@ -32,6 +32,7 @@ public class JobSpecificationProperties
 	public static String key_notifications = "notifications";
 	public static String key_log_directory = "log_directory";
 	public static String key_working_directory = "working_directory";
+	public static String key_output_directory = "output_directory";
 	
 	public static String key_scheduling_priority = "scheduling_priority";
 	
@@ -93,6 +94,7 @@ public class JobSpecificationProperties
 		key_notifications,
 		key_log_directory,
 		key_working_directory,
+		key_output_directory,
 		key_scheduling_priority,
 		key_jvm,
 		key_driver_jvm_args,