You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by cw...@apache.org on 2013/01/02 20:10:20 UTC

svn commit: r1427914 [4/6] - in /uima/sandbox/uima-ducc/trunk/uima-ducc-common: main/ main/java/ main/java/.settings/ main/java/org/ main/java/org/apache/ main/java/org/apache/uima/ main/java/org/apache/uima/ducc/ main/java/org/apache/uima/ducc/common/...

Added: uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/node/metrics/NodeInventory.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/node/metrics/NodeInventory.java?rev=1427914&view=auto
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/node/metrics/NodeInventory.java (added)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/node/metrics/NodeInventory.java Wed Jan  2 19:10:17 2013
@@ -0,0 +1,30 @@
+/*
+ * 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.common.node.metrics;
+
+import java.util.HashSet;
+public class NodeInventory {
+	private HashSet<Process> inventory;
+	public NodeInventory(HashSet<Process> inventory) {
+		this.inventory = inventory;
+	}
+	public HashSet<Process> getInventory() {
+		return inventory;
+	}
+}

Propchange: uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/node/metrics/NodeInventory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/node/metrics/NodeLoadAverage.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/node/metrics/NodeLoadAverage.java?rev=1427914&view=auto
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/node/metrics/NodeLoadAverage.java (added)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/node/metrics/NodeLoadAverage.java Wed Jan  2 19:10:17 2013
@@ -0,0 +1,27 @@
+/*
+ * 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.common.node.metrics;
+
+public interface NodeLoadAverage {
+	  public String getLoadAvg1();
+		  public String getLoadAvg5();
+		  public String getLoadAvg15();
+		  public String getCurrentRunnableProcessCount();
+		  public String getTotalProcessCount();
+}

Propchange: uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/node/metrics/NodeLoadAverage.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/node/metrics/NodeLoadAverageInfo.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/node/metrics/NodeLoadAverageInfo.java?rev=1427914&view=auto
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/node/metrics/NodeLoadAverageInfo.java (added)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/node/metrics/NodeLoadAverageInfo.java Wed Jan  2 19:10:17 2013
@@ -0,0 +1,54 @@
+/*
+ * 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.common.node.metrics;
+
+import java.io.Serializable;
+
+
+public class NodeLoadAverageInfo  extends ByteBufferParser 
+implements NodeLoadAverage, Serializable{
+
+  private static final long serialVersionUID = -8709992836807543890L;
+  private static final int LOADAVG1=0;
+  private static final int LOADAVG5=1;
+  private static final int LOADAVG15=2;
+  private static final int CURRENTRUNNABLECOUNT=3;
+  
+  public NodeLoadAverageInfo(byte[] buffer, int[] procLoadAvgFieldOffsets, int[]  procLoadAvgFieldLengths) {
+    super(buffer, procLoadAvgFieldOffsets, procLoadAvgFieldLengths);
+  }
+  public String getLoadAvg1() {
+    return super.getFieldAsString(LOADAVG1);
+  }
+  public String getLoadAvg5() {
+    return super.getFieldAsString(LOADAVG5);
+  }
+  public String getLoadAvg15() {
+    return super.getFieldAsString(LOADAVG15);
+  }
+  public String getCurrentRunnableProcessCount() {
+    String[] tokens = super.getFieldAsString(CURRENTRUNNABLECOUNT).split("/"); 
+    return tokens[0];
+  }
+  public String getTotalProcessCount() {
+    String[] tokens = super.getFieldAsString(CURRENTRUNNABLECOUNT).split("/"); 
+    return tokens[1];
+  }
+
+}

Propchange: uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/node/metrics/NodeLoadAverageInfo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/node/metrics/NodeMemoryInfo.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/node/metrics/NodeMemoryInfo.java?rev=1427914&view=auto
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/node/metrics/NodeMemoryInfo.java (added)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/node/metrics/NodeMemoryInfo.java Wed Jan  2 19:10:17 2013
@@ -0,0 +1,83 @@
+/*
+ * 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.common.node.metrics;
+
+import org.apache.uima.ducc.common.agent.metrics.memory.NodeMemory;
+
+
+public class NodeMemoryInfo 
+implements NodeMemory {
+  /**
+   * 
+   */
+  private static final long serialVersionUID = 4251234672684113872L;
+
+  //	holds fake total memory of a node. This is used for testing only Resource Manager
+  private long memTotal=-1;
+  private long memInfoValues[];
+  
+  public NodeMemoryInfo(long memInfoValues[], long fakeMemTotal) {
+	  this.memInfoValues = memInfoValues;
+	  memTotal = fakeMemTotal;
+  }
+  public long getMemTotal() {
+	  // memTotal is typically set to -1 unless the agent is run in a test mode and when
+	  // it is configured to use fake memory total
+	  if ( memTotal > 0 ) { // this should be true only for testing
+		  return memTotal;
+	  } 
+	  return memInfoValues[0]; 
+  }
+  public long getMemFree() {
+	  return memInfoValues[1]; 
+  }
+  public long getBuffers() {
+	  return -1;
+  }
+  public long getCached() {
+	  return -1;
+  }
+  public long getSwapCached() {
+	  return -1;
+  }
+  public long getActive() {
+	  return -1;
+  }
+  public long getInactive() {
+	  return -1;
+  }
+  public long getSwapTotal() {
+	  return memInfoValues[2]; 
+  }
+  public long getSwapFree() {
+	  return memInfoValues[3]; 
+  }
+
+  public long getHighTotal() {
+	  return -1;
+  }
+
+  public long getLowTotal() {
+	  return -1;
+  }
+
+  public long getLowFree() {
+	  return -1;
+  }
+}

Propchange: uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/node/metrics/NodeMemoryInfo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/node/metrics/NodeMetrics.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/node/metrics/NodeMetrics.java?rev=1427914&view=auto
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/node/metrics/NodeMetrics.java (added)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/node/metrics/NodeMetrics.java Wed Jan  2 19:10:17 2013
@@ -0,0 +1,70 @@
+/*
+ * 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.common.node.metrics;
+
+import java.io.Serializable;
+import java.util.TreeMap;
+
+import org.apache.uima.ducc.common.NodeIdentity;
+import org.apache.uima.ducc.common.agent.metrics.memory.NodeMemory;
+
+
+public class NodeMetrics implements Serializable {
+  private static final long serialVersionUID = 4646364817769237774L;
+  private NodeLoadAverage nodeLoadAverage;
+  private NodeMemory nodeMemory;
+  private NodeCpuInfo nodeCpu;
+  private NodeIdentity nodeIdentity;
+  TreeMap<String,NodeUsersInfo> nodeUsersMap;
+  
+  public NodeMetrics(NodeIdentity nodeIdentity, NodeMemory nodeMemory, NodeLoadAverage nodeLoadAverage , NodeCpuInfo nodeCpu, TreeMap<String,NodeUsersInfo> userProcessMap ) {
+    this.nodeIdentity = nodeIdentity;
+	  setNodeMemory(nodeMemory);
+    setNodeLoadAverage(nodeLoadAverage);
+    setNodeCpu(nodeCpu);
+    //setNodeUsersInfo(nodeUsersInfo);
+    this.nodeUsersMap = userProcessMap;
+  }
+  public TreeMap<String, NodeUsersInfo> getNodeUsersMap() {
+    return nodeUsersMap;
+  }
+
+  public NodeIdentity getNodeIdentity() {
+	  return nodeIdentity;
+  }
+  public NodeCpuInfo getNodeCpu() {
+    return nodeCpu;
+  }
+  public void setNodeCpu(NodeCpuInfo nodeCpu) {
+    this.nodeCpu = nodeCpu;
+  }
+  public NodeLoadAverage getNodeLoadAverage() {
+    return nodeLoadAverage;
+  }
+  public void setNodeLoadAverage(NodeLoadAverage nodeLoadAverage) {
+    this.nodeLoadAverage = nodeLoadAverage;
+  }
+  public NodeMemory getNodeMemory() {
+    return nodeMemory;
+  }
+  public void setNodeMemory(NodeMemory nodeMemory) {
+    this.nodeMemory = nodeMemory;
+  }
+
+}

Propchange: uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/node/metrics/NodeMetrics.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/node/metrics/NodeUsersInfo.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/node/metrics/NodeUsersInfo.java?rev=1427914&view=auto
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/node/metrics/NodeUsersInfo.java (added)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/node/metrics/NodeUsersInfo.java Wed Jan  2 19:10:17 2013
@@ -0,0 +1,142 @@
+/*
+ * 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.common.node.metrics;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.uima.ducc.common.utils.id.IDuccId;
+
+
+public class NodeUsersInfo implements Serializable {
+
+	private static final long serialVersionUID = 1L;
+
+	private String uid;
+  private List<NodeProcess> reserveProcesses = new ArrayList<NodeProcess>();
+	private transient List<IDuccId> reservations = new ArrayList<IDuccId>();
+	private List<NodeProcess> rogueProcesses = new ArrayList<NodeProcess>();
+  private AtomicInteger counter = new AtomicInteger(1);
+  
+	public NodeUsersInfo(String uid ) {
+	  this.uid = uid;
+	}
+
+	public boolean markAsRogue(int ceiling) {
+	  if ( counter.get() < ceiling ) {
+	    counter.addAndGet(1);
+	    return false;
+	  } else {
+	    return true;
+	  }
+	}
+  public String getUid() {
+    return uid;
+  }
+
+  public List<IDuccId> getReservations() {
+    return reservations;
+  }
+
+  public List<NodeProcess> getRogueProcesses() {
+    return rogueProcesses;
+  }
+	
+  public void addPid(String pid, boolean java) {
+    reserveProcesses.add(new NodeProcess(pid,java));
+
+  }
+  public void addReservation(IDuccId reservation) {
+    reservations.add(reservation);
+  }
+  public void addReservation(List<IDuccId> reservations) {
+    this.reservations = reservations;
+  }
+  public void addRogueProcess(String roguePID, boolean isJava ) {
+    rogueProcesses.add(new NodeProcess(roguePID, isJava));
+  }
+  public String toString() {
+    if ( reservations.size() == 0 && rogueProcesses.size() == 0 ) {
+      return "";
+    }
+    StringBuffer sb = new StringBuffer();
+    String reservation = ( reservations.size() > 0 ) ? "Y" : "N";
+    String userId = getUid();
+    String rogue = ( reservations.size() == 0 ) ? "Y" : "N";
+    
+    sb.append(String.format("\n%32s%20s%8s%12s%12s\n","UserID","Reservation","Rogue","Java","NonJava"));
+    sb.append(String.format("%32s%20s%8s%12s%12s\n",StringUtils.center("", 30, "-"),StringUtils.center("", 18, "-"),StringUtils.center("", 6, "-"),StringUtils.leftPad("", 10, "-"),StringUtils.leftPad("", 10, "-")));
+    if ( reservations.size() > 0 ) {
+      for( NodeProcess process : reserveProcesses) {
+        
+        if ( process.isJava()) {
+          sb.append(String.format("%32s%20s%8s%12s%12s\n",userId,reservation,rogue,process.getPid(),""));
+        } else {
+          sb.append(String.format("%32s%20s%8s%12s%12s\n",userId,reservation,rogue,"",process.getPid()));
+        }
+        userId = "";
+        reservation = "";
+      }
+    } else {
+      for( NodeProcess process : rogueProcesses) {
+        if ( process.isJava()) {
+          sb.append(String.format("%32s%20s%8s%12s%12s\n",userId,reservation,rogue,process.getPid(),""));
+        } else {
+          sb.append(String.format("%32s%20s%8s%12s%12s\n",userId,reservation,rogue,"",process.getPid()));
+        }
+        userId = "";
+        reservation = "";
+      }
+    }
+    sb.append("\n");
+
+    return sb.toString();
+  }
+  public class NodeProcess implements Serializable {
+    private static final long serialVersionUID = 1L;
+    boolean java;
+    String pid;
+    public NodeProcess(String pid, boolean isJava) {
+      this.pid = pid;
+      java = isJava;
+    }
+    public boolean isJava() {
+      return java;
+    }
+
+    public void setJava(boolean java) {
+      this.java = java;
+    }
+
+    public String getPid() {
+      return pid;
+    }
+
+    public void setPid(String pid) {
+      this.pid = pid;
+    }
+    
+  }
+  public List<NodeProcess> getReserveProcesses() {
+    return reserveProcesses;
+  }
+}

Propchange: uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/node/metrics/NodeUsersInfo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/node/metrics/ProcessGarbageCollectionStats.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/node/metrics/ProcessGarbageCollectionStats.java?rev=1427914&view=auto
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/node/metrics/ProcessGarbageCollectionStats.java (added)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/node/metrics/ProcessGarbageCollectionStats.java Wed Jan  2 19:10:17 2013
@@ -0,0 +1,46 @@
+/*
+ * 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.common.node.metrics;
+
+import java.io.Serializable;
+
+public class ProcessGarbageCollectionStats implements Serializable {
+	private static final long serialVersionUID = -8461978985826241714L;
+	String memoryManagerName;
+	long collectionCount;
+	long collectionTime;
+	public void setMemoryManagerName(String mmn) {
+		this.memoryManagerName = mmn;
+	}
+	public void setCollectionCount(long cc) {
+		this.collectionCount = cc;
+	}
+	public void setCollectionTime(long ct) {
+		this.collectionTime = ct;
+	}
+	public String getMemoryManagerName() {
+		return this.memoryManagerName;
+	}
+	public long getCollectionCount() {
+		return this.collectionCount;
+	}
+	public long getCollectionTime() {
+		return this.collectionTime;
+	}
+}

Propchange: uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/node/metrics/ProcessGarbageCollectionStats.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/node/metrics/ProcessResidentMemoryInfo.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/node/metrics/ProcessResidentMemoryInfo.java?rev=1427914&view=auto
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/node/metrics/ProcessResidentMemoryInfo.java (added)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/node/metrics/ProcessResidentMemoryInfo.java Wed Jan  2 19:10:17 2013
@@ -0,0 +1,23 @@
+/*
+ * 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.common.node.metrics;
+
+public class ProcessResidentMemoryInfo {
+
+}

Propchange: uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/node/metrics/ProcessResidentMemoryInfo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/persistence/IPropertiesFileManager.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/persistence/IPropertiesFileManager.java?rev=1427914&view=auto
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/persistence/IPropertiesFileManager.java (added)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/persistence/IPropertiesFileManager.java Wed Jan  2 19:10:17 2013
@@ -0,0 +1,23 @@
+/*
+ * 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.common.persistence;
+
+public interface IPropertiesFileManager {
+	public int increment(String key);
+}

Propchange: uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/persistence/IPropertiesFileManager.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/persistence/PropertiesFileManager.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/persistence/PropertiesFileManager.java?rev=1427914&view=auto
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/persistence/PropertiesFileManager.java (added)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/persistence/PropertiesFileManager.java Wed Jan  2 19:10:17 2013
@@ -0,0 +1,156 @@
+/*
+ * 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.common.persistence;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.Properties;
+
+import org.apache.uima.ducc.common.internationalization.Messages;
+import org.apache.uima.ducc.common.utils.DuccLogger;
+import org.apache.uima.ducc.common.utils.DuccLoggerComponents;
+
+
+public class PropertiesFileManager implements IPropertiesFileManager {
+	
+	private static Messages messages = Messages.getInstance();
+	
+	private DuccLogger logger = null;
+	private String basedir = null;
+	private String propertiesFileName = null;
+	private Properties properties = new Properties();
+	
+	private boolean loadOnGet = false;
+	private boolean storeOnSet = true;
+	
+	public PropertiesFileManager(String componentId, String basedir, String propertiesFileName) {
+		this.logger = DuccLoggerComponents.makeLogger(PropertiesFileManager.class.getName(),componentId);
+		this.basedir = basedir;
+		this.propertiesFileName = propertiesFileName;
+		init();
+	}
+	
+	public PropertiesFileManager(String componentId, String basedir, String propertiesFileName, boolean loadOnGet, boolean storeOnSet) {
+		this.logger = DuccLoggerComponents.makeLogger(PropertiesFileManager.class.getName(),componentId);
+		this.basedir = basedir;
+		this.propertiesFileName = propertiesFileName;
+		this.loadOnGet = loadOnGet;
+		this.storeOnSet = storeOnSet;
+		init();
+	}
+	
+	private String getFullFileName() {
+		return basedir+File.separator+propertiesFileName;
+	}
+	
+	private boolean mkdirs(String directory) {
+		boolean created = false;
+		File file = new File(directory);
+		if(!file.exists()) {
+			file.mkdirs();
+			created = true;
+		}
+		return created;
+	}
+	
+	private void init() {
+		String methodName = "init";
+		logger.trace(methodName, null, messages.fetch("enter"));
+		logger.debug(methodName, null, messages.fetchLabel("logger")+logger);
+		logger.debug(methodName, null, messages.fetchLabel("basedir")+basedir);
+		logger.debug(methodName, null, messages.fetchLabel("propertiesFileName")+propertiesFileName);
+		logger.debug(methodName, null, messages.fetchLabel("loadOnGet")+loadOnGet);
+		logger.debug(methodName, null, messages.fetchLabel("storeOnSet")+storeOnSet);
+		mkdirs(basedir);
+		load();
+		logger.info(methodName, null, getFullFileName());
+		logger.trace(methodName, null, messages.fetch("exit"));
+	}
+	
+	private void load() {
+		String methodName = "load";
+		logger.trace(methodName, null, messages.fetch("enter"));
+		try {
+			FileInputStream fis = new FileInputStream(getFullFileName());
+			properties.load(fis);
+			fis.close();
+		}
+		catch(IOException e) {
+			logger.warn(methodName, null, messages.fetchLabel("load_failed")+getFullFileName());
+		}
+		logger.trace(methodName, null, messages.fetch("exit"));
+	}
+	
+	private void store() {
+		String methodName = "store";
+		logger.trace(methodName, null, messages.fetch("enter"));
+		try {
+			FileOutputStream fos = new FileOutputStream(getFullFileName());
+			properties.store(fos, null);
+			fos.close();
+		}
+		catch(IOException e) {
+			logger.error(methodName, null, e);
+		}
+		logger.trace(methodName, null, messages.fetch("exit"));
+	}
+	
+	public String get(String key, String defaultValue) {
+		String methodName = "get";
+		synchronized(this) {
+			logger.trace(methodName, null, messages.fetch("enter"));
+			if(loadOnGet) {
+				load();
+			}
+			String value = properties.getProperty(key, defaultValue);
+			logger.debug(methodName, null, messages.fetchLabel("key")+key+" "+messages.fetchLabel("value")+value);
+			logger.trace(methodName, null, messages.fetch("exit"));
+			return value;
+		}
+	}
+	
+	public void set(String key, String value) {
+		String methodName = "set";
+		synchronized(this) {
+			logger.trace(methodName, null, messages.fetch("enter"));
+			properties.setProperty(key, value);
+			logger.debug(methodName, null, messages.fetchLabel("key")+key+" "+messages.fetchLabel("value")+value);
+			if(storeOnSet) {
+				store();
+			}
+			logger.trace(methodName, null, messages.fetch("exit"));
+		}
+	}
+	
+	public int increment(String key) {
+		String methodName = "increment";
+		synchronized(this) {
+			logger.trace(methodName, null, messages.fetch("enter"));
+			int retVal = Integer.valueOf(get(key,"-1"));
+			retVal++;
+			logger.debug(methodName, null, messages.fetchLabel("key")+key+" "+messages.fetchLabel("value")+retVal);
+			set(key,String.valueOf(retVal));
+			logger.trace(methodName, null, messages.fetch("exit"));
+			return retVal;
+		}
+	}
+	
+}

Propchange: uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/persistence/PropertiesFileManager.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/persistence/services/IStateServices.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/persistence/services/IStateServices.java?rev=1427914&view=auto
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/persistence/services/IStateServices.java (added)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/persistence/services/IStateServices.java Wed Jan  2 19:10:17 2013
@@ -0,0 +1,45 @@
+/*
+ * 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.common.persistence.services;
+
+import java.io.IOException;
+import java.util.ArrayList;
+
+import org.apache.uima.ducc.common.IDuccEnv;
+
+
+public interface IStateServices {
+
+	public static String directory_state_services = IDuccEnv.DUCC_STATE_SERVICES_DIR;
+
+	public static final String svc = "svc";
+	public static final String meta = "meta";
+	
+	public static final String endpoint = "endpoint";
+	public static final String instances = "instances";
+	public static final String user = "user";
+	public static final String scheduling_class = "scheduling_class";
+	public static final String process_memory_size = "process_memory_size";
+	public static final String description = "description";
+	
+	public ArrayList<String> getSvcList();
+	public ArrayList<String> getMetaList();
+	
+	public StateServicesDirectory getStateServicesDirectory() throws IOException;
+}

Propchange: uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/persistence/services/IStateServices.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/persistence/services/StateServices.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/persistence/services/StateServices.java?rev=1427914&view=auto
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/persistence/services/StateServices.java (added)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/persistence/services/StateServices.java Wed Jan  2 19:10:17 2013
@@ -0,0 +1,172 @@
+/*
+ * 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.common.persistence.services;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.Map.Entry;
+import java.util.NavigableSet;
+import java.util.Properties;
+
+import org.apache.uima.ducc.common.IDuccEnv;
+import org.apache.uima.ducc.common.utils.IOHelper;
+
+
+public class StateServices implements IStateServices {
+
+	private static StateServices instance = new StateServices();
+	
+	public static StateServices getInstance() {
+		return instance;
+	}
+	
+	/*
+	private static final DuccLogger logger = DuccLoggerComponents.getTrLogger(ServiceDefinitionsProperties.class.getName());
+	*/
+	
+	private String directory_state_services = IDuccEnv.DUCC_STATE_SERVICES_DIR;
+	
+	/*
+	private enum Verbosity {
+		QUIET,
+		SPEAK,
+	}
+	*/
+	
+	public StateServices() {
+		mkdirs();
+	}
+	
+	private void mkdirs() {
+		IOHelper.mkdirs(directory_state_services);
+	}
+	
+	private ArrayList<String> getList(String type) {
+		ArrayList<String> retVal = new ArrayList<String>();
+		File folder = new File(directory_state_services);
+		File[] listOfFiles = folder.listFiles();
+		if(listOfFiles != null) {
+			for (int i = 0; i < listOfFiles.length; i++) {
+				if (listOfFiles[i].isFile()) {
+					String name = listOfFiles[i].getName();
+					if(name.endsWith("."+type)) {
+						retVal.add(name);
+					}
+				}
+			}
+		}
+		return retVal;
+	}
+
+	@Override
+	public ArrayList<String> getSvcList() {
+		return getList(IStateServices.svc);
+	}
+
+	@Override
+	public ArrayList<String> getMetaList() {
+		return getList(IStateServices.meta);
+	}
+	
+	private Properties getProperties(String name) {
+		Properties properties = new Properties();
+		try {
+			FileInputStream fis = new FileInputStream(name);
+			try {
+				properties.load(fis);
+			}
+			finally {	
+				fis.close();
+			}
+		}
+		catch(Exception e) {	
+		}
+		return properties;
+	}
+	
+	@Override
+	public StateServicesDirectory getStateServicesDirectory() throws IOException {
+		StateServicesDirectory ssd = new StateServicesDirectory();
+		ArrayList<String> svcList = getSvcList();
+		for(String entry : svcList) {
+			try {
+				StateServicesSet sss = new StateServicesSet();
+				String num = entry.split("[.]")[0];
+				Integer i = new Integer(num);
+				String fnSvc = directory_state_services+num+"."+svc;
+				String fnMeta = directory_state_services+num+"."+meta;
+				Properties propertiesSvc = getProperties(fnSvc);
+				sss.put(svc, propertiesSvc);
+				Properties propertiesMeta = getProperties(fnMeta);
+				sss.put(meta, propertiesMeta);
+				ssd.put(i, sss);
+			}
+			catch(Exception e) {
+			}
+		}
+		return ssd;
+	}
+	
+	///// <test>
+	
+	public static void main(String[] args) throws IOException, ClassNotFoundException {
+		String ducc_home = System.getenv("DUCC_HOME");
+		if(ducc_home == null) {
+			System.out.println("DUCC_HOME not set in environment");
+			return;
+		}
+		if(ducc_home.trim() == "") {
+			System.out.println("DUCC_HOME not set in environment");
+			return;
+		}
+		StateServices ss = StateServices.getInstance();
+		ArrayList<String> svcList = ss.getSvcList();
+		for(String fname : svcList) {
+			System.out.println(fname);
+		}
+		ArrayList<String> metaList = ss.getMetaList();
+		for(String fname : metaList) {
+			System.out.println(fname);
+		}
+		StateServicesDirectory ssd = ss.getStateServicesDirectory();
+		NavigableSet<Integer> keySet = ssd.getDescendingKeySet();
+		Iterator<Integer> iterator = keySet.iterator();
+		while(iterator.hasNext()) {
+			Integer i = iterator.next();
+			StateServicesSet sss = ssd.get(i);
+			Properties propertiesSvc = sss.get(svc);
+			Iterator<Entry<Object, Object>> iteratorSvc = propertiesSvc.entrySet().iterator();
+			while(iteratorSvc.hasNext()) {
+				Entry<Object, Object> entrySvc = iteratorSvc.next();
+				System.out.println(svc+":"+entrySvc.getKey()+"="+entrySvc.getValue());
+			}
+			Properties propertiesMeta = sss.get(meta);
+			Iterator<Entry<Object, Object>> iteratorMeta = propertiesMeta.entrySet().iterator();
+			while(iteratorMeta.hasNext()) {
+				Entry<Object, Object> entryMeta = iteratorMeta.next();
+				System.out.println(meta+":"+entryMeta.getKey()+"="+entryMeta.getValue());
+			}
+		}
+	}
+
+	///// </test>
+}

Propchange: uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/persistence/services/StateServices.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/persistence/services/StateServicesDirectory.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/persistence/services/StateServicesDirectory.java?rev=1427914&view=auto
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/persistence/services/StateServicesDirectory.java (added)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/persistence/services/StateServicesDirectory.java Wed Jan  2 19:10:17 2013
@@ -0,0 +1,39 @@
+/*
+ * 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.common.persistence.services;
+
+import java.util.NavigableSet;
+import java.util.TreeMap;
+
+public class StateServicesDirectory {
+
+	private TreeMap<Integer,StateServicesSet> map = new TreeMap<Integer,StateServicesSet>();
+	
+	public void put(Integer key, StateServicesSet value) {
+		map.put(key, value);
+	}
+	
+	public StateServicesSet get(Integer key) {
+		return map.get(key);
+	}
+	
+	public NavigableSet<Integer> getDescendingKeySet() {
+		return map.descendingKeySet();
+	}
+}

Propchange: uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/persistence/services/StateServicesDirectory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/persistence/services/StateServicesSet.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/persistence/services/StateServicesSet.java?rev=1427914&view=auto
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/persistence/services/StateServicesSet.java (added)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/persistence/services/StateServicesSet.java Wed Jan  2 19:10:17 2013
@@ -0,0 +1,35 @@
+/*
+ * 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.common.persistence.services;
+
+import java.util.HashMap;
+import java.util.Properties;
+
+public class StateServicesSet {
+
+	private HashMap<String,Properties> map = new HashMap<String,Properties>();
+	
+	public void put(String key, Properties value) {
+		map.put(key, value);
+	}
+	
+	public Properties get(String key) {
+		return map.get(key);
+	}
+}

Propchange: uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/persistence/services/StateServicesSet.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/system/SystemState.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/system/SystemState.java?rev=1427914&view=auto
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/system/SystemState.java (added)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/system/SystemState.java Wed Jan  2 19:10:17 2013
@@ -0,0 +1,90 @@
+/*
+ * 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.common.system;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.OutputStreamWriter;
+import java.util.Properties;
+
+import org.apache.uima.ducc.common.IDuccEnv;
+import org.apache.uima.ducc.common.utils.DuccLogger;
+import org.apache.uima.ducc.common.utils.DuccLoggerComponents;
+import org.apache.uima.ducc.common.utils.id.DuccId;
+
+
+public class SystemState {
+	
+	private static final DuccLogger logger = DuccLoggerComponents.getOrLogger(SystemState.class.getName());
+	
+	private static SystemState instance = new SystemState();
+	
+	public static SystemState getInstance() {
+		return instance;
+	}
+	
+	private static String jobsStop = IDuccEnv.DUCC_STATE_DIR+"ducc.jobs.stop";
+	
+	private static DuccId jobid = null;
+	
+	public boolean isAcceptJobs() {
+		String location = "isAcceptJobs";
+		boolean retVal = true;
+		try {
+			File file = new File(jobsStop);
+			retVal = !file.exists();
+		}
+		catch(Throwable t) {
+			logger.error(location, jobid, t);
+		}
+		return retVal;
+	}
+	
+	public void resetAcceptJobs(String userid) {
+		String location = "resetAcceptJobs";
+		try {
+			Properties properties = new Properties();
+			properties.put("userid", userid);
+			String comments = null;
+			FileOutputStream fos = null;
+			OutputStreamWriter out = null;
+			fos = new FileOutputStream(jobsStop);
+			out = new OutputStreamWriter(fos);
+			properties.store(out, comments);
+			out.close();
+			fos.close();
+		}
+		catch(Throwable t) {
+			logger.error(location, jobid, t);
+		}
+	}
+	
+	public void setAcceptJobs() {
+		String location = "setAcceptJobs";
+		try {
+			File file = new File(jobsStop);
+			if(file.exists()) {
+				file.delete();
+			}
+		}
+		catch(Throwable t) {
+			logger.error(location, jobid, t);
+		}
+	}
+}

Propchange: uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/system/SystemState.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/test/DuccCamelSpringTestSupport.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/test/DuccCamelSpringTestSupport.java?rev=1427914&view=auto
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/test/DuccCamelSpringTestSupport.java (added)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/test/DuccCamelSpringTestSupport.java Wed Jan  2 19:10:17 2013
@@ -0,0 +1,148 @@
+/*
+ * 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.common.test;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.camel.dataformat.xstream.XStreamDataFormat;
+import org.apache.camel.impl.DefaultClassResolver;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.apache.uima.ducc.common.component.AbstractDuccComponent;
+import org.apache.uima.ducc.common.exception.DuccComponentInitializationException;
+import org.apache.uima.ducc.common.utils.DuccProperties;
+import org.springframework.context.annotation.AnnotationConfigApplicationContext;
+
+import com.thoughtworks.xstream.XStream;
+public abstract class DuccCamelSpringTestSupport extends CamelTestSupport  { //CamelSpringTestSupport {
+	public static final String DUCC_PROPERTY_FILE="ducc.deploy.configuration";
+	public static final String DUCC_DEPLOY_COMPONENTS="ducc.deploy.components";
+	
+	public String serialize(Object obj) throws Exception {
+		XStreamDataFormat xStreamDataFormat = new XStreamDataFormat();
+	        XStream xStream = xStreamDataFormat.getXStream(new DefaultClassResolver());
+	        
+	        return xStream.toXML(obj);
+	}
+	
+	public void loadProperties(String componentProperties) throws Exception {
+		DuccProperties duccProperties = new DuccProperties();
+		duccProperties.load((String) System.getProperty(componentProperties));
+		enrichSystemPropertiesWith(duccProperties);
+		adjustEndpointsForSelectedTransport();
+	}
+	public void enrichSystemPropertiesWith(DuccProperties duccProperties ) {
+		for( Map.Entry<Object,Object> entry : duccProperties.entrySet()) {
+			if ( !System.getProperties().containsKey((String)entry.getKey()) ) {
+				System.setProperty((String)entry.getKey(), (String)entry.getValue());
+			} 
+		}
+	}
+	private void adjustEndpointsForSelectedTransport() throws Exception {
+		for( Map.Entry<Object,Object> entry : System.getProperties().entrySet()) {
+			if ( ((String)entry.getKey()).endsWith("endpoint")) {
+				String endpointValue = (String)entry.getValue();
+				endpointValue = endpointValue.substring(endpointValue.lastIndexOf(":")+1, endpointValue.length());
+				String endpointType = (String)System.getProperty((String)entry.getKey()+".type");
+				
+				if ( endpointType == null ) {
+					throw new DuccComponentInitializationException("Endpoint type not specified in component properties. Specify vm, queue, or topic type value for endpoint: "+endpointValue);
+				} else if ( endpointType.equals("vm") ) {
+					if ( !endpointValue.startsWith("vm:")) {
+						endpointValue = "vm:"+endpointValue;
+						System.setProperty((String)entry.getKey(), endpointValue);
+					} else {
+						// ignore
+					}
+				} else if ( endpointType.equals("topic") ||  endpointType.equals("queue") ) {
+					if ( !endpointValue.startsWith("activemq:"+endpointType)) {
+						endpointValue = "activemq:"+endpointType+":"+endpointValue;
+						System.setProperty((String)entry.getKey(), endpointValue);
+					} else {
+						// ignore
+					}
+				} else {
+					throw new DuccComponentInitializationException("Provided Endpoint type is invalid:"+endpointType+". Specify vm, queue, or topic type value for endpoint: "+endpointValue);					
+				}
+			}
+		}
+	}
+	/**
+	 * Exits process if given configuration class is either null or not set (empty).
+	 *  
+	 * @param classToVerify - class name to check
+	 * @param reason - 
+	 */
+	private void exitIfInvalid( String componentName, String classToVerify, String reason) {
+		if ( classToVerify == null || classToVerify.trim().length() == 0) {
+			System.out.println("Unable to start Component: "+componentName+". Missing "+reason+".\nUsage: java -DServiceConfigurationClass=<Configuration.class> ...");
+			System.exit(-1);
+		}
+	}
+
+	/**
+	 * Extracts component configuration classes from System properties
+	 * 
+	 * @return - array of configuration classes
+	 * 
+	 * @throws DuccComponentInitializationException - if no components provided for loading
+	 */
+	private Class<?>[] getComponentsToLoad() throws Exception {
+		String[] componentsToLoad = System.getProperty(DUCC_DEPLOY_COMPONENTS).split(",");
+		if ( componentsToLoad == null || componentsToLoad.length == 0 ) {
+			throw new DuccComponentInitializationException("Ducc Component not specified. Provide Ducc Component(s) to Load via -D"+DUCC_DEPLOY_COMPONENTS+" System property");
+		}
+		List<Class<?>> components = new ArrayList<Class<?>>(); 
+		for( String componentToLoad : componentsToLoad ) {
+			String configurationClassName = System.getProperty("ducc."+componentToLoad+".configuration.class");
+			exitIfInvalid(componentToLoad, configurationClassName, "Configuration Class Name");
+			components.add(Class.forName(configurationClassName));
+		}
+		Class<?>[] configClasses = new Class[components.size()];
+		components.toArray(configClasses);
+		return configClasses;
+	}
+	@Override
+    public void setUp() throws Exception {
+    	super.setUp();
+    }
+
+    protected AnnotationConfigApplicationContext createApplicationContext() { 
+    	try {
+    		loadProperties(DUCC_PROPERTY_FILE);
+        	Class<?>[] configClasses = getComponentsToLoad();
+            AnnotationConfigApplicationContext context = 
+            	new AnnotationConfigApplicationContext(configClasses); 
+    		Map<String,AbstractDuccComponent> duccComponents = 
+    			context.getBeansOfType(AbstractDuccComponent.class);
+    		//	Start all components
+    		for(Map.Entry<String, AbstractDuccComponent> duccComponent: duccComponents.entrySet()) {
+    			System.out.println("... Starting Component:"+duccComponent.getKey());
+    			duccComponent.getValue().start(null);
+    		}
+
+            return context;
+    	} catch( Exception e) {
+    		e.printStackTrace();
+    	}
+    	return null;
+    }
+
+}

Propchange: uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/test/DuccCamelSpringTestSupport.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/test/DuccUnitTestDriver.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/test/DuccUnitTestDriver.java?rev=1427914&view=auto
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/test/DuccUnitTestDriver.java (added)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/test/DuccUnitTestDriver.java Wed Jan  2 19:10:17 2013
@@ -0,0 +1,340 @@
+/*
+ * 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.common.test;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.PrintStream;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.uima.UIMAFramework;
+import org.apache.uima.UIMARuntimeException;
+import org.apache.uima.analysis_engine.AnalysisEngine;
+import org.apache.uima.analysis_engine.AnalysisEngineDescription;
+import org.apache.uima.analysis_engine.AnalysisEngineManagement;
+import org.apache.uima.cas.CAS;
+import org.apache.uima.collection.CollectionReader;
+import org.apache.uima.ducc.common.uima.InvalidOverrideParameterException;
+import org.apache.uima.ducc.common.uima.UimaUtils;
+import org.apache.uima.resource.ResourceCreationSpecifier;
+import org.apache.uima.resource.ResourceSpecifier;
+import org.apache.uima.resource.metadata.ConfigurationParameter;
+import org.apache.uima.resource.metadata.ConfigurationParameterDeclarations;
+import org.apache.uima.resource.metadata.ConfigurationParameterSettings;
+import org.apache.uima.util.Progress;
+import org.apache.uima.util.XMLInputSource;
+
+
+public class DuccUnitTestDriver {
+  private String crDesc = null;
+  private List<String> crOverrides = new ArrayList<String>();
+  private List<String> cmOverrides = new ArrayList<String>();
+  private List<String> aeOverrides = new ArrayList<String>();
+  private List<String> ccOverrides = new ArrayList<String>();
+  private String cmDesc = null;
+  private String aeDesc = null;
+  private String ccDesc = null;
+  private String ddDesc = null;
+  boolean verbose = false;
+
+
+  public void RunJobComponents(String[] args) {
+
+    try {
+      if (!processCmdLineArgs(args)) {
+        printUsageMessage();
+        return;
+      }
+
+      File tempAEDescriptorFile = null;
+      if (aeDesc != null) {
+        if (cmDesc == null) {
+          System.out.println("No CM descriptor specified.\n"+
+                  "For Blade equivalent function use com.ibm.bluej.core.xmi_zip_reader.DuccXmiZipReaderCM");
+        }
+        if (ccDesc == null) {
+          System.out.println("No CC descriptor specified.\n"+
+                  "For Blade equivalent function use com.ibm.bluej.core.xmi_zip_writer.BlueJXmiZipWriter");
+        }
+
+        // create AE descriptor
+        List<List<String>> overrides = new ArrayList<List<String>>();
+        if (cmOverrides != null)
+          overrides.add(cmOverrides);
+        if (aeOverrides != null)
+          overrides.add(aeOverrides);
+        if (ccOverrides != null)
+          overrides.add(ccOverrides);
+        AnalysisEngineDescription aed = UimaUtils.createAggregateDescription(false, overrides, cmDesc,
+                aeDesc, ccDesc);
+
+        // and save it in /tmp directory
+        File duccTempDir = new File("/tmp");
+        tempAEDescriptorFile = File.createTempFile("UimaAEDescriptor", ".xml", duccTempDir);
+        tempAEDescriptorFile.deleteOnExit();
+        FileOutputStream fos = new FileOutputStream(tempAEDescriptorFile);
+        aed.toXML(fos);
+        aed.toXML(System.out);
+        fos.close();
+      }
+      else {
+        // find and parse the dd-aggregate descriptor
+        if (ddDesc.endsWith(".xml")) {
+          tempAEDescriptorFile = new File(ddDesc);
+        }
+        else {
+          String relativePath = ddDesc.replace('.', '/')+".xml";
+          URL url = getClass().getClassLoader().getResource(relativePath);
+          if (url == null) {
+            System.err.println(relativePath+" not found in classpath");
+            System.exit(1);
+          }
+          tempAEDescriptorFile = new File(url.getFile());
+        }
+      }
+
+      // find and parse the CR descriptor
+      File crDescFile = null;
+      if (crDesc.endsWith(".xml")) {
+        crDescFile = new File(crDesc);
+      }
+      else {
+        String relativePath = crDesc.replace('.', '/')+".xml";
+        URL url = getClass().getClassLoader().getResource(relativePath);
+        if (url == null) {
+          System.err.println(relativePath+" not found in classpath");
+          System.exit(1);
+        }
+        crDescFile = new File(url.getFile());
+      }
+      XMLInputSource in = new XMLInputSource(crDescFile);
+      ResourceSpecifier specifier = UIMAFramework.getXMLParser().parseResourceSpecifier(in);
+
+      // apply CR overrides, if any
+      if (!crOverrides.isEmpty()) {
+        ConfigurationParameterSettings cps = ((ResourceCreationSpecifier) specifier).getMetaData()
+            .getConfigurationParameterSettings();
+        for (String cmOverride : crOverrides) {
+          System.out.println(".... Processing Override:"+cmOverride);
+          // each override is expressed as <name>=<value> pair
+          String[] nvp = cmOverride.split("=",2);
+          ConfigurationParameterDeclarations componentParameterDeclarations = ((ResourceCreationSpecifier) specifier)
+              .getMetaData().getConfigurationParameterDeclarations();
+          boolean found = false;
+          for (ConfigurationParameter parameter : componentParameterDeclarations
+              .getConfigurationParameters()) {
+            if (nvp[0].equals(parameter.getName())) {
+              if (ConfigurationParameter.TYPE_STRING.equals(parameter.getType())) {
+                cps.setParameterValue(nvp[0], nvp[1]);
+              }
+              else if (ConfigurationParameter.TYPE_FLOAT.equals(parameter.getType())) {
+                cps.setParameterValue(nvp[0], new Float(nvp[1]));
+              }
+              else if (ConfigurationParameter.TYPE_INTEGER.equals(parameter.getType())) {
+                cps.setParameterValue(nvp[0], new Integer(nvp[1]));
+              }
+              else { //assume boolean
+                cps.setParameterValue(nvp[0], new Boolean(nvp[1]));
+              }
+              found = true;
+              break;
+            }
+          }
+          if (!found) {
+            throw new UIMARuntimeException(
+                new InvalidOverrideParameterException(
+                    "Override Parameter:"
+                        + nvp[0]
+                        + " is not defined for the specified collection reader: "
+                        + crDesc));
+          }
+        }
+      }
+
+      // instantiate the CR and AE
+      CollectionReader cr = UIMAFramework.produceCollectionReader(specifier);
+      in = new XMLInputSource(tempAEDescriptorFile);
+      specifier = UIMAFramework.getXMLParser().parseResourceSpecifier(in);
+      AnalysisEngine ae = UIMAFramework.produceAnalysisEngine(specifier);
+
+      //get the AE management objects that collect timing stats for each component
+      List<AnalysisEngineManagement> aeManagementObjects = new ArrayList<AnalysisEngineManagement>();
+      AnalysisEngineManagement rootAem = ae.getManagementInterface();
+      aeManagementObjects.add(rootAem);    
+      getLeafManagementObjects(rootAem, aeManagementObjects);
+      rootAem.resetStats();
+
+      // only one CAS needed for this single threaded process
+      CAS cas = ae.newCAS();
+      
+      Progress[] prog = cr.getProgress();
+      if (prog != null) {
+        long total = prog[0].getTotal();
+        System.out.println("\n"+total+" work items specified by collection reader\n");
+      }
+      else {
+        System.err.println("Warning: collection reader does not specify number of work items");
+      }
+
+      // process all work items
+      int numProc=0;
+      while (cr.hasNext()) {
+        cr.getNext(cas);
+        ae.process(cas);
+        cas.reset();
+        numProc++;
+        if (verbose){
+          System.out.print(".");
+          if (0 == numProc%100) {
+            System.out.println();
+          }
+        }
+      }
+      if (verbose){
+        System.out.println("\nProcessed "+numProc+" work items");
+        printStats(System.out, ae);
+      }
+      
+    } catch (Exception e) {
+      e.printStackTrace();
+    }
+  }
+
+  private void printUsageMessage() {
+    System.err.println("\nUnit test driver for components to be deployed by Ducc\n"
+            +" This test driver allows single threaded testing of a job collection reader\n"
+            +" plus a job process\n"
+            +"   assembled from [CM] + AE + [CC] descriptors, or\n"
+            +"   specified by an AE descriptor intended to be used via a Deployment Descriptor\n"
+            +"\nUsage:\n java " + this.getClass().getName()
+            +" --driver_descriptor_CR <desc>\n"
+            +" [--driver_descriptor_CR_overrides <list>]\n"
+            +" ...and then either...\n"
+            +" --process_descriptor_AE <desc>\n"
+            +" [--process_descriptor_AE_overrides <list>]\n" 
+            +" [--process_descriptor_CM <desc>]\n"
+            +" [--process_descriptor_CM_overrides <list>]\n" 
+            +" [--process_descriptor_CC <desc>]\n"
+            +" [--process_descriptor_CC_overrides <list>]\n"
+            +" ...or...\n"
+            +" --process_descriptor_4DD <desc>\n"
+            +" [-verbose]\n");
+  }
+  
+  private ArrayList<String> toArrayList(String overrides) {
+    ArrayList<String> list = new ArrayList<String>();
+    if(overrides != null) {
+      String[] items = overrides.split(",");
+      for(String item : items) {
+        list.add(item.trim());
+      }
+    }
+    return list;
+  }
+
+  private boolean processCmdLineArgs(String[] args) {
+    int index = 0;
+    if (args.length < 1) {
+      return false;
+    }
+    
+    while (index < args.length) {
+      String arg = args[index++];
+      if (arg.equals("--process_descriptor_AE")) {
+        aeDesc = args[index++];
+      } else if (arg.equals("--driver_descriptor_CR")) {
+        crDesc = args[index++];
+      } else if (arg.equals("--process_descriptor_CM")) {
+        cmDesc = args[index++];
+      } else if (arg.equals("--process_descriptor_CC")) {
+        ccDesc = args[index++];
+      } else if (arg.equals("--process_descriptor_4DD")) {
+        ddDesc = args[index++];
+      } else if (arg.equals("--driver_descriptor_CR_overrides")) {
+        crOverrides = toArrayList(args[index++]);
+      } else if (arg.equals("--process_descriptor_AE_overrides")) {
+        aeOverrides = toArrayList(args[index++]);
+      } else if (arg.equals("--process_descriptor_CM_overrides")) {
+        cmOverrides = toArrayList(args[index++]);
+      } else if (arg.equals("--process_descriptor_CC_overrides")) {
+        ccOverrides = toArrayList(args[index++]);
+      } else if (arg.equals("-verbose")) {
+        verbose=true;
+      } else {
+        System.out.println("Ignoring arg = "+args[index++]);
+      }
+    }
+    if (crDesc == null) {
+      System.err.println("\nNo CR descriptor specified.\n"+
+              "For Blade equivalent function use com.ibm.bluej.core.ducc.DuccXmiZipJobDriverCR");
+      return false;
+    }
+    if (aeDesc == null && ddDesc == null) {
+      System.err.println("\nNo AE or DD descriptor specified.");
+      return false;
+    }
+    if (ddDesc != null && (aeDesc != null || cmDesc != null || ccDesc != null)) {
+      System.err.println("\n4DD descriptor specified as well as one or more of {AE,CM,CC} descriptors, will not continue.");
+      return false;
+    }
+    return true;
+  }
+
+  public static void main(String[] args) {
+    DuccUnitTestDriver td = new DuccUnitTestDriver();
+    try {
+      td.RunJobComponents(args);
+    } catch (Throwable t) {
+      System.err.println("Ducc unit test driver caught exception:");
+      t.printStackTrace();
+    }
+  }
+
+  private static void getLeafManagementObjects(AnalysisEngineManagement aem, List<AnalysisEngineManagement> result) {
+    if (aem.getComponents().isEmpty()) {
+      if (!aem.getName().equals("Fixed Flow Controller")) {
+        result.add(aem);
+      }
+    } else {
+      for (AnalysisEngineManagement child : (Iterable<AnalysisEngineManagement>) aem.getComponents().values()) {
+        getLeafManagementObjects(child, result);
+      }
+    }
+  }
+
+  private static void printStats(PrintStream out, AnalysisEngine userAE ) {
+    AnalysisEngineManagement userAEM = userAE.getManagementInterface();
+
+    printComponentStats(out, 0, userAEM);
+  }
+
+  private static void printComponentStats(PrintStream out, int level, AnalysisEngineManagement aem) {
+    String indent = "";
+    for (int i = 0; i < level; i++)
+      indent += "  ";
+    out.println(indent + aem.getName() + ": " + aem.getAnalysisTime() + "ms, ");
+    for (AnalysisEngineManagement childAem : (Iterable<AnalysisEngineManagement>) (aem
+            .getComponents().values()))
+      printComponentStats(out, level + 1, childAem);
+
+  }
+
+}

Propchange: uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/test/DuccUnitTestDriver.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/uima/DuccJobProcessFC.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/uima/DuccJobProcessFC.java?rev=1427914&view=auto
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/uima/DuccJobProcessFC.java (added)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/uima/DuccJobProcessFC.java Wed Jan  2 19:10:17 2013
@@ -0,0 +1,143 @@
+/*
+ * 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.common.uima;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.uima.analysis_engine.AnalysisEngineProcessException;
+import org.apache.uima.analysis_engine.metadata.FixedFlow;
+import org.apache.uima.analysis_engine.metadata.FlowConstraints;
+import org.apache.uima.cas.CAS;
+import org.apache.uima.flow.CasFlowController_ImplBase;
+import org.apache.uima.flow.CasFlow_ImplBase;
+import org.apache.uima.flow.FinalStep;
+import org.apache.uima.flow.Flow;
+import org.apache.uima.flow.FlowControllerContext;
+import org.apache.uima.flow.SimpleStep;
+import org.apache.uima.flow.Step;
+import org.apache.uima.resource.ResourceInitializationException;
+
+/**
+ * Ducc FlowController for Job Processes assembled from user components
+ * If WI-Cas is sent to initial CM, it is then dropped
+ * All other parent CASes continue thru the flow
+ */
+public class DuccJobProcessFC extends CasFlowController_ImplBase {
+
+  /**
+   */
+  private String cmKey="DuccXmiZipReaderCM";
+  private List<String> mSequence;
+
+  public void initialize(FlowControllerContext aContext) throws ResourceInitializationException {
+    super.initialize(aContext);
+
+    FlowConstraints flowConstraints = aContext.getAggregateMetadata().getFlowConstraints();
+    mSequence = new ArrayList<String>();
+    if (flowConstraints instanceof FixedFlow) {
+      String[] sequence = ((FixedFlow) flowConstraints).getFixedFlow();
+		  mSequence.addAll(Arrays.asList(sequence));
+    } else {
+      throw new ResourceInitializationException(ResourceInitializationException.FLOW_CONTROLLER_REQUIRES_FLOW_CONSTRAINTS,
+              new Object[]{this.getClass().getName(), "fixedFlow", aContext.getAggregateMetadata().getSourceUrlString()});
+    }
+  }
+
+  /*
+   * (non-Javadoc)
+   * 
+   * @see org.apache.uima.flow.CasFlowController_ImplBase#computeFlow(org.apache.uima.cas.CAS)
+   */
+  public Flow computeFlow(CAS aCAS) throws AnalysisEngineProcessException {
+    return new FixedFlowObject(0);
+  }
+
+  class FixedFlowObject extends CasFlow_ImplBase {
+    private int currentStep;
+    private boolean hasBeenToDuccCM = false;
+    private boolean internallyCreatedCas = false;
+
+    /**
+     * Create a new fixed flow starting at step <code>startStep</code> of the fixed sequence.
+     * 
+     * @param startStep
+     *          index of mSequence to start at
+     */
+    public FixedFlowObject(int startStep) {
+      this(startStep, false);
+    }
+
+    /**
+     * Create a new fixed flow starting at step <code>startStep</code> of the fixed sequence.
+     * 
+     * @param startStep
+     *          index of mSequence to start at
+     * @param internallyCreatedCas
+     *          true to indicate that this Flow object is for a CAS that was produced by a
+     *          CasMultiplier within this aggregate.
+     * 
+     */
+    public FixedFlowObject(int startStep, boolean internallyCreatedCas) {
+      currentStep = startStep;
+      this.internallyCreatedCas = internallyCreatedCas;
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.uima.flow.Flow#next()
+     */
+    public Step next() throws AnalysisEngineProcessException {
+      // Drop the Work Item CAS after it has been to the Ducc CM
+      if (!internallyCreatedCas) {
+        if (hasBeenToDuccCM) {
+          return new FinalStep();
+        }
+      }
+
+      if (currentStep >= mSequence.size()) {
+        return new FinalStep(); // this CAS has finished the sequence
+      }
+
+      // Check if WI CAS is going to Ducc CM
+      if (!internallyCreatedCas && cmKey.equals(mSequence.get(currentStep))) {
+        // set flag for next time thru
+        hasBeenToDuccCM = true;
+      }
+
+      // now send the CAS to the next AE in sequence.
+      return new SimpleStep((String)mSequence.get(currentStep++));
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.uima.flow.CasFlow_ImplBase#newCasProduced(CAS, String)
+     */
+    public Flow newCasProduced(CAS newCas, String producedBy) throws AnalysisEngineProcessException {
+      // start the new output CAS from the next node after the CasMultiplier that produced it
+      int i = 0;
+      while (!mSequence.get(i).equals(producedBy))
+        i++;
+      return new FixedFlowObject(i + 1, true);
+    }
+  }
+}

Propchange: uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/uima/DuccJobProcessFC.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/uima/DuccJobProcessFC.xml
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/uima/DuccJobProcessFC.xml?rev=1427914&view=auto
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/uima/DuccJobProcessFC.xml (added)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/uima/DuccJobProcessFC.xml Wed Jan  2 19:10:17 2013
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  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.
+-->
+<flowControllerDescription xmlns="http://uima.apache.org/resourceSpecifier">
+  <frameworkImplementation>org.apache.uima.java</frameworkImplementation>
+  <implementationName>org.apache.uima.ducc.common.uima.DuccJobProcessFC</implementationName>
+  <processingResourceMetaData>
+    <name>Fixed Flow Controller</name>
+    <description>Ducc FlowController for Job Processes assembled from user components. If WI-Cas is sent to initial CM, it is then dropped. All other parent CASes continue thru the flow.</description>
+    <version>1.0</version>
+    <vendor>IBM</vendor>
+    <configurationParameters/>
+    <configurationParameterSettings/>
+    <capabilities>
+      <capability>
+        <inputs/>
+        <outputs/>
+	  </capability>	  
+    </capabilities>
+  </processingResourceMetaData>
+</flowControllerDescription>

Propchange: uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/uima/DuccJobProcessFC.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/uima/InitializationExceptionAE.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/uima/InitializationExceptionAE.java?rev=1427914&view=auto
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/uima/InitializationExceptionAE.java (added)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/uima/InitializationExceptionAE.java Wed Jan  2 19:10:17 2013
@@ -0,0 +1,48 @@
+/*
+ * 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.common.uima;
+
+import org.apache.uima.UimaContext;
+import org.apache.uima.analysis_component.CasAnnotator_ImplBase;
+import org.apache.uima.analysis_engine.AnalysisEngineProcessException;
+import org.apache.uima.cas.CAS;
+import org.apache.uima.resource.ResourceInitializationException;
+
+public class InitializationExceptionAE extends CasAnnotator_ImplBase {
+	
+	@Override
+	public void initialize(UimaContext uimaContext) throws ResourceInitializationException {
+		throw new ResourceInitializationException();
+	}
+	
+	@Override
+	public void process(CAS cas) throws AnalysisEngineProcessException {
+		String data = cas.getSofaDataString();
+		if(data == null) {
+		}
+		try {
+			int aeSleepSeconds = 60;
+			Thread.sleep(aeSleepSeconds*1000);
+		}
+		catch(Exception e) {
+			
+		}
+	}
+
+}

Propchange: uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/uima/InitializationExceptionAE.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/uima/InitializationExceptionPercentageAE.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/uima/InitializationExceptionPercentageAE.java?rev=1427914&view=auto
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/uima/InitializationExceptionPercentageAE.java (added)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/uima/InitializationExceptionPercentageAE.java Wed Jan  2 19:10:17 2013
@@ -0,0 +1,55 @@
+/*
+ * 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.common.uima;
+
+import java.util.Random;
+
+import org.apache.uima.UimaContext;
+import org.apache.uima.analysis_component.CasAnnotator_ImplBase;
+import org.apache.uima.analysis_engine.AnalysisEngineProcessException;
+import org.apache.uima.cas.CAS;
+import org.apache.uima.resource.ResourceInitializationException;
+
+public class InitializationExceptionPercentageAE extends CasAnnotator_ImplBase {
+	
+	private Random random = new Random();
+	private double percentage = 0.33;
+	
+	@Override
+	public void initialize(UimaContext uimaContext) throws ResourceInitializationException {
+		if(random.nextDouble() < percentage) {
+			throw new ResourceInitializationException();
+		}
+	}
+	
+	@Override
+	public void process(CAS cas) throws AnalysisEngineProcessException {
+		String data = cas.getSofaDataString();
+		if(data == null) {
+		}
+		try {
+			int aeSleepSeconds = 60;
+			Thread.sleep(aeSleepSeconds*1000);
+		}
+		catch(Exception e) {
+			
+		}
+	}
+
+}

Propchange: uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/uima/InitializationExceptionPercentageAE.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/uima/InvalidOverrideParameterException.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/uima/InvalidOverrideParameterException.java?rev=1427914&view=auto
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/uima/InvalidOverrideParameterException.java (added)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/uima/InvalidOverrideParameterException.java Wed Jan  2 19:10:17 2013
@@ -0,0 +1,31 @@
+/*
+ * 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.common.uima;
+
+public class InvalidOverrideParameterException extends Exception {
+
+	/**
+	 * 
+	 */
+	private static final long serialVersionUID = -4948849140814646049L;
+
+	public InvalidOverrideParameterException(String msg) {
+		super(msg);
+	}
+}

Propchange: uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/uima/InvalidOverrideParameterException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/uima/ProcessExceptionAE.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/uima/ProcessExceptionAE.java?rev=1427914&view=auto
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/uima/ProcessExceptionAE.java (added)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/uima/ProcessExceptionAE.java Wed Jan  2 19:10:17 2013
@@ -0,0 +1,57 @@
+/*
+ * 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.common.uima;
+
+import org.apache.uima.UimaContext;
+import org.apache.uima.analysis_component.CasAnnotator_ImplBase;
+import org.apache.uima.analysis_engine.AnalysisEngineProcessException;
+import org.apache.uima.cas.CAS;
+import org.apache.uima.resource.ResourceInitializationException;
+
+public class ProcessExceptionAE extends CasAnnotator_ImplBase {
+	
+	@Override
+	public void initialize(UimaContext uimaContext) throws ResourceInitializationException {
+		super.initialize(uimaContext);
+		try {
+			int aeSleepSeconds = 2;
+			Thread.sleep(aeSleepSeconds*1000);
+		}
+		catch(Exception e) {
+			
+		}
+		return;
+	}
+	
+	@Override
+	public void process(CAS cas) throws AnalysisEngineProcessException {
+		String data = cas.getSofaDataString();
+		if(data == null) {
+		}
+		try {
+			int aeSleepSeconds = 5;
+			Thread.sleep(aeSleepSeconds*1000);
+		}
+		catch(Exception e) {
+			
+		}
+		throw new AnalysisEngineProcessException();
+	}
+
+}

Propchange: uima/sandbox/uima-ducc/trunk/uima-ducc-common/main/java/org/apache/uima/ducc/common/uima/ProcessExceptionAE.java
------------------------------------------------------------------------------
    svn:eol-style = native