Author: cwiklik
Date: Wed Jan 23 19:57:01 2019
New Revision: 1851971

URL: http://svn.apache.org/viewvc?rev=1851971&view=rev
Log:
UIMA-5962 modified to check version of uima user specified and prepend correct 
version of workitem to the classpath

Removed:
    
uima/uima-ducc/trunk/uima-ducc-user/src/main/java/org/apache/uima/ducc/Workitem.java
    
uima/uima-ducc/trunk/uima-ducc-user/src/main/java/org/apache/uima/ducc/Workitem_Type.java
Modified:
    uima/uima-ducc/trunk/pom.xml
    uima/uima-ducc/trunk/src/main/assembly/bin.xml
    
uima/uima-ducc/trunk/uima-ducc-agent/src/main/java/org/apache/uima/ducc/agent/NodeAgent.java
    
uima/uima-ducc/trunk/uima-ducc-agent/src/main/java/org/apache/uima/ducc/agent/launcher/DuccCommandExecutor.java
    
uima/uima-ducc/trunk/uima-ducc-agent/src/main/java/org/apache/uima/ducc/agent/launcher/ManagedProcess.java
    uima/uima-ducc/trunk/uima-ducc-container/pom.xml
    uima/uima-ducc/trunk/uima-ducc-parent/pom.xml
    
uima/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/cmdline/JavaCommandLine.java
    uima/uima-ducc/trunk/uima-ducc-user/pom.xml

Modified: uima/uima-ducc/trunk/pom.xml
URL: 
http://svn.apache.org/viewvc/uima/uima-ducc/trunk/pom.xml?rev=1851971&r1=1851970&r2=1851971&view=diff
==============================================================================
--- uima/uima-ducc/trunk/pom.xml (original)
+++ uima/uima-ducc/trunk/pom.xml Wed Jan 23 19:57:01 2019
@@ -137,6 +137,16 @@
                </dependency>
                <dependency>
                        <groupId>org.apache.uima</groupId>
+                       <artifactId>uima-ducc-workitem-v2</artifactId>
+                       <version>${project.version}</version>
+               </dependency>
+               <dependency>
+                       <groupId>org.apache.uima</groupId>
+                       <artifactId>uima-ducc-workitem-v3</artifactId>
+                       <version>${project.version}</version>
+               </dependency>
+               <dependency>
+                       <groupId>org.apache.uima</groupId>
                        <artifactId>uima-ducc-container</artifactId>
                        <version>${project.version}</version>
                </dependency>
@@ -202,6 +212,15 @@
                </dependency>
                <dependency>
                        <groupId>org.apache.uima</groupId>
+                       <artifactId>uima-ducc-workitem-v2</artifactId>
+               </dependency>
+               <dependency>
+                       <groupId>org.apache.uima</groupId>
+                       <artifactId>uima-ducc-workitem-v3</artifactId>
+               </dependency>
+               
+               <dependency>
+                       <groupId>org.apache.uima</groupId>
                        <artifactId>uima-ducc-container</artifactId>
                </dependency>
        </dependencies>
@@ -576,6 +595,8 @@
                <module>uima-ducc-user</module>
                <!-- Note: uima-ducc-container has a test dependency on 
uima-ducc-user so must be built after it -->
                <module>uima-ducc-container</module>
-    <module>uima-ducc-pullservice</module>
+        <module>uima-ducc-pullservice</module>
+        <module>uima-ducc-workitem-v2</module>
+        <module>uima-ducc-workitem-v3</module>
   </modules>
 </project>

Modified: uima/uima-ducc/trunk/src/main/assembly/bin.xml
URL: 
http://svn.apache.org/viewvc/uima/uima-ducc/trunk/src/main/assembly/bin.xml?rev=1851971&r1=1851970&r2=1851971&view=diff
==============================================================================
--- uima/uima-ducc/trunk/src/main/assembly/bin.xml (original)
+++ uima/uima-ducc/trunk/src/main/assembly/bin.xml Wed Jan 23 19:57:01 2019
@@ -105,7 +105,19 @@ under the License.
       <fileMode>644</fileMode> 
       <directoryMode>755</directoryMode>        
     </dependencySet>
-    
+       
+    <dependencySet>
+      <useStrictFiltering>true</useStrictFiltering>
+      <includes>
+        <include>org.apache.uima:uima-ducc-workitem-v2:jar:</include>
+        <include>org.apache.uima:uima-ducc-workitem-v3:jar:</include>
+      </includes>      
+      <outputFileNameMapping>${artifact.artifactId}.jar</outputFileNameMapping>
+      <outputDirectory>lib/uima-ducc/workitem</outputDirectory>
+      <useProjectArtifact>false</useProjectArtifact>
+      <fileMode>644</fileMode> 
+      <directoryMode>755</directoryMode>        
+    </dependencySet>
    <!-- Google GSon -->   
     <dependencySet>
       <useStrictFiltering>true</useStrictFiltering>

Modified: 
uima/uima-ducc/trunk/uima-ducc-agent/src/main/java/org/apache/uima/ducc/agent/NodeAgent.java
URL: 
http://svn.apache.org/viewvc/uima/uima-ducc/trunk/uima-ducc-agent/src/main/java/org/apache/uima/ducc/agent/NodeAgent.java?rev=1851971&r1=1851970&r2=1851971&view=diff
==============================================================================
--- 
uima/uima-ducc/trunk/uima-ducc-agent/src/main/java/org/apache/uima/ducc/agent/NodeAgent.java
 (original)
+++ 
uima/uima-ducc/trunk/uima-ducc-agent/src/main/java/org/apache/uima/ducc/agent/NodeAgent.java
 Wed Jan 23 19:57:01 2019
@@ -1245,6 +1245,8 @@ public class NodeAgent extends AbstractD
     switch (state) {
       case FailedInitialization:
       case InitializationTimeout:
+      case Stopped:
+      case Stopping:
         return false;
       case Starting:
       case Started:
@@ -1349,8 +1351,10 @@ public class NodeAgent extends AbstractD
             // The process has already stopped, but managed to send
             // the last update before dying. Ignore the update
             return;
-          } else if (changeState(duccEvent.getState())) {
-            processEntry.getValue().setProcessState(duccEvent.getState());
+          } else if (changeState(processEntry.getValue().getProcessState())) {
+                 logger.info(methodName, null,"=============== 
PID:"+processEntry.getValue().getPID()+" Changing State - current 
state:"+processEntry.getValue().getProcessState()+" New 
State:"+duccEvent.getState());
+                 processEntry.getValue().setProcessState(duccEvent.getState());
+                 
             // if the process is Stopping, it must have hit an error threshold
           }
           // Check if MemoryCollector should be created for this

Modified: 
uima/uima-ducc/trunk/uima-ducc-agent/src/main/java/org/apache/uima/ducc/agent/launcher/DuccCommandExecutor.java
URL: 
http://svn.apache.org/viewvc/uima/uima-ducc/trunk/uima-ducc-agent/src/main/java/org/apache/uima/ducc/agent/launcher/DuccCommandExecutor.java?rev=1851971&r1=1851970&r2=1851971&view=diff
==============================================================================
--- 
uima/uima-ducc/trunk/uima-ducc-agent/src/main/java/org/apache/uima/ducc/agent/launcher/DuccCommandExecutor.java
 (original)
+++ 
uima/uima-ducc/trunk/uima-ducc-agent/src/main/java/org/apache/uima/ducc/agent/launcher/DuccCommandExecutor.java
 Wed Jan 23 19:57:01 2019
@@ -19,8 +19,13 @@
 package org.apache.uima.ducc.agent.launcher;
 
 import java.io.File;
+import java.io.IOException;
 import java.io.PrintWriter;
 import java.io.StringWriter;
+import java.lang.reflect.Method;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -34,6 +39,7 @@ import org.apache.uima.ducc.agent.NodeAg
 import org.apache.uima.ducc.agent.launcher.ManagedProcess.StopPriority;
 import org.apache.uima.ducc.common.IDuccUser;
 import org.apache.uima.ducc.common.container.FlagsHelper;
+import org.apache.uima.ducc.common.exception.DuccRuntimeException;
 import org.apache.uima.ducc.common.utils.DuccLogger;
 import org.apache.uima.ducc.common.utils.TimeStamp;
 import org.apache.uima.ducc.common.utils.Utils;
@@ -49,6 +55,7 @@ import org.apache.uima.ducc.transport.ev
 import org.apache.uima.ducc.transport.event.common.IProcessState.ProcessState;
 import org.apache.uima.ducc.transport.event.common.ITimeWindow;
 import org.apache.uima.ducc.transport.event.common.TimeWindow;
+import org.apache.uima.ducc.user.common.PrivateClassLoader;
 
 public class DuccCommandExecutor extends CommandExecutor {
        DuccLogger logger = DuccLogger.getLogger(this.getClass(),
@@ -788,9 +795,53 @@ public class DuccCommandExecutor extends
                                        executable = 
System.getProperty("java.home")
                                                        + File.separator + 
"bin" + File.separator + "java";
                                }
-
+                               boolean jd = ((ManagedProcess) 
super.managedProcess).isJd();
+                               
                                if (cmdLine instanceof JavaCommandLine) {
+                                       String classpath="";
+                                       if ( jd ) {
+                                               for( String option : 
((JavaCommandLine) cmdLine).getOptions() ) {
+                                                       
logger.info("getDeployableCommandLine",null,"+++++++++ "+option);
+                                                       if ( 
option.startsWith("-Dducc.deploy.UserClasspath") ) {
+                                                               classpath = 
option.split("=")[1];
+                                                               break;
+                                                       }
+                                               }
+                                               
logger.info("getDeployableCommandLine",null,">>>>>>>> User 
Classpath:"+classpath);
+                                       } else {
+                                               classpath = ((JavaCommandLine) 
cmdLine).getClasspath();
+                                       }
+                                       
+                                       
+                                       
                                        String duccHomePath = 
Utils.findDuccHome();
+                                       
+                                       String[] jars = classpath.split(":");
+                                       URLClassLoader clsLoader = 
newClassLoader(jars);
+                                       Class<?> cls = 
clsLoader.loadClass("org.apache.uima.impl.UimaVersion");
+                                       Method majorVersionMethod = 
cls.getMethod("getMajorVersion");
+                                       short majorVersion = 
(short)majorVersionMethod.invoke(null);
+                                       if ( !duccHomePath.trim().endsWith("/") 
) {
+                                               duccHomePath = 
duccHomePath.concat("/");
+                                       }
+                                       String workItemJarDir = 
duccHomePath+"lib/uima-ducc/workitem/uima-ducc-workitem-";
+                                       if ( majorVersion < 3 ) {
+                                               classpath = 
workItemJarDir+"v2.jar:"+classpath;
+                                       } else if ( majorVersion >= 3 ) {
+                                               classpath = 
workItemJarDir+"v3.jar:"+classpath;
+                                       } else {
+                                               throw new 
DuccRuntimeException("Unknown version of UIMA - majorVersion="+majorVersion);
+                                       }
+                                        
+                                       if ( jd ) {
+                                               
logger.info("getDeployableCommandLine",null,"............ JD 
UserClasspath:"+classpath);
+                                               // JD uses classloader 
separation to run user specified jars. 
+                                               ((JavaCommandLine) 
cmdLine).replaceOption("-Dducc.deploy.UserClasspath", classpath);
+                                       } else {
+                                               
logger.info("getDeployableCommandLine",null,"............ Not JD - 
Classpath:"+classpath);
+                                               ((JavaCommandLine) 
cmdLine).setClasspath(classpath);
+                                       }
+
                                        cmdLine.addOption("-DDUCC_HOME=" + 
duccHomePath);
                                        
cmdLine.addOption("-Dducc.deploy.configuration="
                                                                + 
System.getProperty("ducc.deploy.configuration"));
@@ -803,6 +854,7 @@ public class DuccCommandExecutor extends
                                        
cmdLine.addOption("-Dducc.process.log.dir="     + processLogDir);
                                        
cmdLine.addOption("-Dducc.process.log.basename=" + processLogFile);
                                        cmdLine.addOption("-Dducc.job.id=" + 
((ManagedProcess) super.managedProcess).getWorkDuccId());
+                                       
                                }
 
                                if (useDuccSpawn()) {
@@ -830,7 +882,8 @@ public class DuccCommandExecutor extends
                                           break;
                                        }
                                }
-                               boolean jd = ((ManagedProcess) 
super.managedProcess).isJd();
+
+                               
                                // Currently agent has two ports where it 
listens for process state updates. One is
                                // for JPs and the other is for APs and JDs. 
The latter use a simplified state update protocol
                                // which is String based. The JPs actually 
serialize a more complex state Object.
@@ -896,7 +949,29 @@ public class DuccCommandExecutor extends
                }
 
        }
-
+         public URLClassLoader newClassLoader(String[] classPathElements) 
throws IOException  {
+                   ArrayList<URL> urlList = new 
ArrayList<URL>(classPathElements.length);
+                   for (String element : classPathElements) {
+                     if (element.endsWith("*")) {
+                       File dir = new File(element.substring(0, 
element.length() - 1));
+                       File[] files = dir.listFiles();   // Will be null if 
missing or not a dir
+                       if (files != null) {
+                         for (File f : files) {
+                           if (f.getName().endsWith(".jar")) {
+                             urlList.add(f.getCanonicalFile().toURI().toURL());
+                           }
+                         }
+                       }
+                     } else {
+                       File f = new File(element);
+                       if (f.exists()) {
+                         urlList.add(f.getCanonicalFile().toURI().toURL());
+                       }
+                     }
+                   }
+                   URL[] urls = new URL[urlList.size()];
+                   return new URLClassLoader(urlList.toArray(urls), 
ClassLoader.getSystemClassLoader().getParent());
+                 }
        public void stop() {
        }
 }

Modified: 
uima/uima-ducc/trunk/uima-ducc-agent/src/main/java/org/apache/uima/ducc/agent/launcher/ManagedProcess.java
URL: 
http://svn.apache.org/viewvc/uima/uima-ducc/trunk/uima-ducc-agent/src/main/java/org/apache/uima/ducc/agent/launcher/ManagedProcess.java?rev=1851971&r1=1851970&r2=1851971&view=diff
==============================================================================
--- 
uima/uima-ducc/trunk/uima-ducc-agent/src/main/java/org/apache/uima/ducc/agent/launcher/ManagedProcess.java
 (original)
+++ 
uima/uima-ducc/trunk/uima-ducc-agent/src/main/java/org/apache/uima/ducc/agent/launcher/ManagedProcess.java
 Wed Jan 23 19:57:01 2019
@@ -397,7 +397,7 @@ public class ManagedProcess implements P
                                // state to Stopped
                                (reason != null && initError ) ) {
                    //getDuccProcess().setProcessState(ProcessState.Stopped);
-                       if ( !initError && ( exitcode - 128 == 9 || exitcode - 
128 == 15 ) ) {  // killed with -9?
+                       if ( !initError && ( exitcode - 128 == 9 || exitcode - 
128 == 15 ) ) {  
                                
getDuccProcess().setReasonForStoppingProcess(ReasonForStoppingProcess.KilledByDucc.toString());
                        }
 
@@ -432,12 +432,10 @@ public class ManagedProcess implements P
                                // default state to Stopped. If the process 
died unexpectadly the state
                                // will be changed to Failed
                                pstate = ProcessState.Stopped;
-
                                // check if the process died due to an external 
cause. If that
                                // was the case isstopping = false. The 
isstopping=true iff the Agent
                                // initiated process stop because the process 
was deallocated
                                if (!isstopping) {
-
                                        // fetch errors from stderr stream. If 
the process failed to
                                        // start due to misconfiguration
                                        // the reason for failure would be 
provided by the OS (wrong
@@ -454,7 +452,6 @@ public class ManagedProcess implements P
                                        // APs can stop for any reason. There 
is 
                                        // no way to determine why the AP 
terminated.
                                        if ( !isAP ) {
-
                                                // Unexpected process 
termination 
                                                pstate = ProcessState.Failed;
                                                // fetch errors from stderr 
stream. If the process failed to
@@ -495,7 +492,7 @@ public class ManagedProcess implements P
                                notifyProcessObserver(pstate);
                                log("ManagedProcess.drainProcessStreams",
                                                "************ Remote Process 
PID:" + getPid()
-                                                               + " Terminated 
***************");
+                                                               + " Terminated 
*************** State:"+getDuccProcess().getProcessState().toString());
                        }
                }
        }

Modified: uima/uima-ducc/trunk/uima-ducc-container/pom.xml
URL: 
http://svn.apache.org/viewvc/uima/uima-ducc/trunk/uima-ducc-container/pom.xml?rev=1851971&r1=1851970&r2=1851971&view=diff
==============================================================================
--- uima/uima-ducc/trunk/uima-ducc-container/pom.xml (original)
+++ uima/uima-ducc/trunk/uima-ducc-container/pom.xml Wed Jan 23 19:57:01 2019
@@ -52,6 +52,11 @@
                                <artifactId>uima-ducc-pullservice</artifactId>
                                <version>${project.version}</version>
                        </dependency>
+                       <dependency>
+                               <groupId>org.apache.uima</groupId>
+                               <artifactId>uima-ducc-workitem-v2</artifactId>
+                               <version>${project.version}</version>
+                       </dependency>
                </dependencies>
        </dependencyManagement>
 
@@ -73,7 +78,10 @@
                                <artifactId>uima-ducc-pullservice</artifactId>
                                
                        </dependency>
-                       
+               <dependency>
+                               <groupId>org.apache.uima</groupId>
+                               <artifactId>uima-ducc-workitem-v2</artifactId>
+               </dependency>   
        </dependencies>
     <profiles>
        <profile>
@@ -151,6 +159,11 @@
                             
<outputDirectory>${project.build.directory}/test-classes</outputDirectory>
                           </artifactItem>
                           <artifactItem>
+                                                       
<groupId>org.apache.uima</groupId>
+                                                       
<artifactId>uima-ducc-workitem-v2</artifactId>
+                            
<outputDirectory>${project.build.directory}/test-classes</outputDirectory>
+                          </artifactItem>
+                          <artifactItem>
                                                        
<groupId>org.apache.uima</groupId>
                                                        
<artifactId>uimaj-core</artifactId>
                             
<outputDirectory>${project.build.directory}/test-classes</outputDirectory>

Modified: uima/uima-ducc/trunk/uima-ducc-parent/pom.xml
URL: 
http://svn.apache.org/viewvc/uima/uima-ducc/trunk/uima-ducc-parent/pom.xml?rev=1851971&r1=1851970&r2=1851971&view=diff
==============================================================================
--- uima/uima-ducc/trunk/uima-ducc-parent/pom.xml (original)
+++ uima/uima-ducc/trunk/uima-ducc-parent/pom.xml Wed Jan 23 19:57:01 2019
@@ -299,7 +299,13 @@ ${uimaDUCCNoticeText}
                            <version>${project.version}</version>
                    </dependency>
 
-             <dependency>
+                   <dependency>
+                           <groupId>org.apache.uima</groupId>
+                           <artifactId>uima-ducc-workitem-v2</artifactId>
+                               <version>${project.version}</version>
+                   </dependency>
+                      
+            <dependency>
                            <groupId>org.apache.uima</groupId>
                            <artifactId>uima-ducc-sm</artifactId>
                            <version>${project.version}</version>
@@ -989,4 +995,6 @@ ${uimaDUCCNoticeText}
 
        </profiles>
 
+
+
 </project>

Modified: 
uima/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/cmdline/JavaCommandLine.java
URL: 
http://svn.apache.org/viewvc/uima/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/cmdline/JavaCommandLine.java?rev=1851971&r1=1851970&r2=1851971&view=diff
==============================================================================
--- 
uima/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/cmdline/JavaCommandLine.java
 (original)
+++ 
uima/uima-ducc/trunk/uima-ducc-transport/src/main/java/org/apache/uima/ducc/transport/cmdline/JavaCommandLine.java
 Wed Jan 23 19:57:01 2019
@@ -54,6 +54,24 @@ public class JavaCommandLine extends ACo
             options.add(option);
         }
        }
+    public void replaceOption(String key, String value) {
+       List<String> newOptions = new ArrayList<>();
+       boolean modified = false;
+       for( String option : getOptions() ) {
+               String[] keyValue = option.split("=");
+               if ( keyValue[0].equals(key)) {
+                       newOptions.add(key+"="+value);
+                       modified=true;
+               } else {
+                       newOptions.add(option);
+               }
+               
+       }
+       if ( modified ) {
+               options.clear();
+               options = newOptions;
+       }
+    }
        public List<String> getOptions() {
                return options;
        }

Modified: uima/uima-ducc/trunk/uima-ducc-user/pom.xml
URL: 
http://svn.apache.org/viewvc/uima/uima-ducc/trunk/uima-ducc-user/pom.xml?rev=1851971&r1=1851970&r2=1851971&view=diff
==============================================================================
--- uima/uima-ducc/trunk/uima-ducc-user/pom.xml (original)
+++ uima/uima-ducc/trunk/uima-ducc-user/pom.xml Wed Jan 23 19:57:01 2019
@@ -84,6 +84,11 @@
                        <groupId>org.apache.camel</groupId>
                        <artifactId>camel-xstream</artifactId>
                </dependency>
+                               
+               <dependency>
+                       <groupId>org.apache.uima</groupId>
+                       <artifactId>uima-ducc-workitem-v2</artifactId>
+               </dependency>
        </dependencies>
  
 </project>


Reply via email to