You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by de...@apache.org on 2016/02/17 21:02:09 UTC

svn commit: r1730930 - in /uima/sandbox/uima-ducc/trunk/uima-ducc-web/src: main/java/org/apache/uima/ducc/ws/server/ test/java/org/ test/java/org/apache/ test/java/org/apache/uima/ test/java/org/apache/uima/ducc/ test/java/org/apache/uima/ducc/ws/ test...

Author: degenaro
Date: Wed Feb 17 20:02:09 2016
New Revision: 1730930

URL: http://svn.apache.org/viewvc?rev=1730930&view=rev
Log: (empty)

Added:
    uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/test/java/org/
    uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/test/java/org/apache/
    uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/test/java/org/apache/uima/
    uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/test/java/org/apache/uima/ducc/
    uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/test/java/org/apache/uima/ducc/ws/
    uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/test/java/org/apache/uima/ducc/ws/test/
    uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/test/java/org/apache/uima/ducc/ws/test/TestSuite.java   (with props)
Modified:
    uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccHandlerClassic.java
    uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccHandlerJsonFormat.java
    uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccHandlerUtils.java

Modified: uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccHandlerClassic.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccHandlerClassic.java?rev=1730930&r1=1730929&r2=1730930&view=diff
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccHandlerClassic.java (original)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccHandlerClassic.java Wed Feb 17 20:02:09 2016
@@ -315,20 +315,22 @@ public class DuccHandlerClassic extends
 		sb.append("</span>");
 		sb.append("</td>");
 		// Swap
-		DecimalFormat formatter = new DecimalFormat("###0.0");
 		sb.append("<td valign=\"bottom\" align=\"right\">");
-		double swap = job.getSwapUsageGb();
-		if(job.isCompleted()) {
-			swap = job.getSwapUsageGbMax();
-		}
-		String displaySwapMax = formatter.format(swap);
-		if(swap > 0) {
-			sb.append("<span class=\"health_red\""+">");
+		String swapSizeDisplay = "";
+		String swapSizeHover = "";
+		title = "";
+		double swapBytes = 0;
+		swapBytes = DuccHandlerUtils.getSwapSizeBytes(job);
+		swapSizeDisplay = DuccHandlerUtils.getSwapSizeDisplay(swapBytes);
+		swapSizeHover = DuccHandlerUtils.getSwapSizeHover(swapBytes);
+		title = "title="+"\""+swapSizeHover+"\"";
+		if(swapBytes > 0) {
+			sb.append("<span "+title+" "+"class=\"health_red\""+">");
 		}
 		else {
-			sb.append("<span class=\"health_black\""+">");
+			sb.append("<span "+title+" "+"class=\"health_black\""+">");
 		}
-		sb.append(displaySwapMax);
+		sb.append(swapSizeDisplay);
 		sb.append("</span>");
 		sb.append("</td>");
 		// Memory
@@ -796,25 +798,25 @@ public class DuccHandlerClassic extends
 		}
 		sb.append("</td>");
 		// Swap
-		String swap = "";
-		double dswap = 0;
+		sb.append("<td align=\"right\">");
+		String swapSizeDisplay = "";
+		String swapSizeHover = "";
+		title = "";
+		double swapBytes = 0;
 		if(duccwork instanceof DuccWorkJob) {
-			DecimalFormat formatter = new DecimalFormat("###0.0");
 			DuccWorkJob job = (DuccWorkJob) duccwork;
-			dswap = job.getSwapUsageGb();
-			if(job.isCompleted()) {
-				dswap = job.getSwapUsageGbMax();
-			}
-			swap = formatter.format(dswap);
+			swapBytes = DuccHandlerUtils.getSwapSizeBytes(job);
+			swapSizeDisplay = DuccHandlerUtils.getSwapSizeDisplay(swapBytes);
+			swapSizeHover = DuccHandlerUtils.getSwapSizeHover(swapBytes);
+			title = "title="+"\""+swapSizeHover+"\"";
 		}
-		sb.append("<td align=\"right\">");
-		if(dswap > 0) {
-			sb.append("<span class=\"health_red\""+">");
+		if(swapBytes > 0) {
+			sb.append("<span "+title+" "+"class=\"health_red\""+">");
 		}
 		else {
-			sb.append("<span class=\"health_black\""+">");
+			sb.append("<span "+title+" "+"class=\"health_black\""+">");
 		}
-		sb.append(swap);
+		sb.append(swapSizeDisplay);
 		sb.append("</span>");
 		sb.append("</td>");
 		// Memory
@@ -949,8 +951,6 @@ public class DuccHandlerClassic extends
 		duccLogger.trace(methodName, jobid, messages.fetch("exit"));
 	}	
 	
-	private static DecimalFormat formatter = new DecimalFormat("##0.0");
-	
 	private void handleServletClassicServices(String target,Request baseRequest,HttpServletRequest request,HttpServletResponse response) 
 	throws IOException, ServletException
 	{
@@ -1105,21 +1105,21 @@ public class DuccHandlerClassic extends
 				sb.append("</td>");
 				// Swap
 				sb.append("<td align=\"right\">");
-				double rawSwap = service.getSwap();
-				rawSwap = rawSwap/Constants.GB;
-				String swap = formatter.format(rawSwap);
-				double rawSwapMax = service.getSwapMax();
-				rawSwapMax = rawSwapMax/Constants.GB;
-				String swapMax = formatter.format(rawSwap);
-				sb.append("<span title=\"max="+swapMax+"\" align=\"right\" "+">");
-				if(rawSwap > 0) {
-					sb.append("<span class=\"health_red\""+">");
+				String swapSizeDisplay = "";
+				String swapSizeHover = "";
+				String title = "";
+				double swapBytes = 0;
+				swapBytes = service.getSwap();
+				swapSizeDisplay = DuccHandlerUtils.getSwapSizeDisplay(swapBytes);
+				swapSizeHover = DuccHandlerUtils.getSwapSizeHover(swapBytes);
+				title = "title="+"\""+swapSizeHover+"\"";
+				if(swapBytes > 0) {
+					sb.append("<span "+title+" "+"class=\"health_red\""+">");
 				}
 				else {
-					sb.append("<span class=\"health_black\""+">");
+					sb.append("<span "+title+" "+"class=\"health_black\""+">");
 				}
-				sb.append(swap);
-				sb.append("</span>");
+				sb.append(swapSizeDisplay);
 				sb.append("</span>");
 				sb.append("</td>");
 				// Size

Modified: uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccHandlerJsonFormat.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccHandlerJsonFormat.java?rev=1730930&r1=1730929&r2=1730930&view=diff
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccHandlerJsonFormat.java (original)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccHandlerJsonFormat.java Wed Feb 17 20:02:09 2016
@@ -347,21 +347,23 @@ public class DuccHandlerJsonFormat exten
 		sb.append("</span>");
 		row.add(new JsonPrimitive(sb.toString()));
 		// Swap
-		DecimalFormat formatter = new DecimalFormat("###0.0");
 		sb = new StringBuffer();
 		sb.append("<span>");
-		double swap = job.getSwapUsageGb();
-		if(job.isCompleted()) {
-			swap = job.getSwapUsageGbMax();
-		}
-		String displaySwapMax = formatter.format(swap);
-		if(swap > 0) {
-			sb.append("<span class=\"health_red\""+">");
+		String swapSizeDisplay = "";
+		String swapSizeHover = "";
+		title = "";
+		double swapBytes = 0;
+		swapBytes = DuccHandlerUtils.getSwapSizeBytes(job);
+		swapSizeDisplay = DuccHandlerUtils.getSwapSizeDisplay(swapBytes);
+		swapSizeHover = DuccHandlerUtils.getSwapSizeHover(swapBytes);
+		title = "title="+"\""+swapSizeHover+"\"";
+		if(swapBytes > 0) {
+			sb.append("<span "+title+" "+"class=\"health_red\""+">");
 		}
 		else {
-			sb.append("<span class=\"health_black\""+">");
+			sb.append("<span "+title+" "+"class=\"health_black\""+">");
 		}
-		sb.append(displaySwapMax);
+		sb.append(swapSizeDisplay);
 		sb.append("</span>");
 		sb.append("</span>");
 		row.add(new JsonPrimitive(sb.toString()));
@@ -895,25 +897,25 @@ public class DuccHandlerJsonFormat exten
 		row.add(new JsonPrimitive(sb.toString()));
 		// Swap
 		sb = new StringBuffer();
-		String swap = "";
-		double dswap = 0;
+		sb.append("<span>");
+		String swapSizeDisplay = "";
+		String swapSizeHover = "";
+		title = "";
+		double swapBytes = 0;
 		if(duccwork instanceof DuccWorkJob) {
-			DecimalFormat formatter = new DecimalFormat("###0.0");
 			DuccWorkJob job = (DuccWorkJob) duccwork;
-			dswap = job.getSwapUsageGb();
-			if(job.isCompleted()) {
-				dswap = job.getSwapUsageGbMax();
-			}
-			swap = formatter.format(dswap);
+			swapBytes = DuccHandlerUtils.getSwapSizeBytes(job);
+			swapSizeDisplay = DuccHandlerUtils.getSwapSizeDisplay(swapBytes);
+			swapSizeHover = DuccHandlerUtils.getSwapSizeHover(swapBytes);
+			title = "title="+"\""+swapSizeHover+"\"";
 		}
-		sb.append("<span>");
-		if(dswap > 0) {
-			sb.append("<span class=\"health_red\""+">");
+		if(swapBytes > 0) {
+			sb.append("<span "+title+" "+"class=\"health_red\""+">");
 		}
 		else {
-			sb.append("<span class=\"health_black\""+">");
+			sb.append("<span "+title+" "+"class=\"health_black\""+">");
 		}
-		sb.append(swap);
+		sb.append(swapSizeDisplay);
 		sb.append("</span>");
 		sb.append("</span>");
 		row.add(new JsonPrimitive(sb.toString()));
@@ -1085,8 +1087,6 @@ public class DuccHandlerJsonFormat exten
 		duccLogger.trace(methodName, jobid, messages.fetch("exit"));
 	}	
 	
-	private static DecimalFormat formatter = new DecimalFormat("##0.0");
-	
 	private void handleServletJsonFormatServicesAaData(String target,Request baseRequest,HttpServletRequest request,HttpServletResponse response) 
 	throws IOException, ServletException
 	{
@@ -1244,20 +1244,22 @@ public class DuccHandlerJsonFormat exten
 				row.add(new JsonPrimitive(col.toString()));
 				// Swap
 				col = new StringBuffer();
-				double rawSwap = service.getSwap();
-				rawSwap = rawSwap/Constants.GB;
-				String swap = formatter.format(rawSwap);
-				double rawSwapMax = service.getSwapMax();
-				rawSwapMax = rawSwapMax/Constants.GB;
-				String swapMax = formatter.format(rawSwap);
-				col.append("<span title=\"max="+swapMax+"\" align=\"right\" "+">");
-				if(rawSwap > 0) {
-					col.append("<span class=\"health_red\""+">");
+				col.append("<span>");
+				String swapSizeDisplay = "";
+				String swapSizeHover = "";
+				String title = "";
+				double swapBytes = 0;
+				swapBytes = service.getSwap();
+				swapSizeDisplay = DuccHandlerUtils.getSwapSizeDisplay(swapBytes);
+				swapSizeHover = DuccHandlerUtils.getSwapSizeHover(swapBytes);
+				title = "title="+"\""+swapSizeHover+"\"";
+				if(swapBytes > 0) {
+					col.append("<span "+title+" "+"class=\"health_red\""+">");
 				}
 				else {
-					col.append("<span class=\"health_black\""+">");
+					col.append("<span "+title+" "+"class=\"health_black\""+">");
 				}
-				col.append(swap);
+				col.append(swapSizeDisplay);
 				col.append("</span>");
 				col.append("</span>");
 				row.add(new JsonPrimitive(col.toString()));

Modified: uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccHandlerUtils.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccHandlerUtils.java?rev=1730930&r1=1730929&r2=1730930&view=diff
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccHandlerUtils.java (original)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccHandlerUtils.java Wed Feb 17 20:02:09 2016
@@ -18,6 +18,10 @@
 */
 package org.apache.uima.ducc.ws.server;
 
+import java.text.DecimalFormat;
+
+import org.apache.uima.ducc.transport.event.common.IDuccWorkJob;
+
 
 public class DuccHandlerUtils {
 
@@ -69,4 +73,49 @@ public class DuccHandlerUtils {
 		return sb.toString();
 	}
 	
+	// *****
+	
+	public static double getSwapSizeBytes(IDuccWorkJob job) {
+		double swapBytes = job.getSwapUsageGb()*GB;
+		if(job.isCompleted()) {
+			swapBytes = job.getSwapUsageGbMax()*GB;
+		}
+		return swapBytes;
+	}
+	
+	private static DecimalFormat formatter = new DecimalFormat("###0.0");
+	
+	public static String getSwapSizeDisplay(double swapBytes) {
+		String retVal = formatter.format(swapBytes/GB);;
+		return retVal;
+	}
+	
+	private static double GB = Math.pow(10,9);
+	private static double MB = Math.pow(10,6);
+	private static double KB = Math.pow(10,3);
+
+	public static String getSwapSizeHover(double swapBytes) {
+		String retVal = null;
+		if(swapBytes == 0) {
+			retVal = formatter.format(swapBytes/GB)+" "+"GB";
+		}
+		else if(swapBytes >= GB/10) {
+			retVal = formatter.format(swapBytes/GB)+" "+"GB";
+		}
+		else if(swapBytes >= MB/10) {
+			retVal = formatter.format(swapBytes/MB)+" "+"MB";
+		}
+		else if(swapBytes >= KB/10) {
+			retVal = formatter.format(swapBytes/KB)+" "+"KB";
+		}
+		else {
+			retVal = formatter.format(swapBytes)+" "+"Bytes";
+		}
+		return retVal;
+	}
+	
+	
+	
+	
+	
 }

Added: uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/test/java/org/apache/uima/ducc/ws/test/TestSuite.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/test/java/org/apache/uima/ducc/ws/test/TestSuite.java?rev=1730930&view=auto
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/test/java/org/apache/uima/ducc/ws/test/TestSuite.java (added)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/test/java/org/apache/uima/ducc/ws/test/TestSuite.java Wed Feb 17 20:02:09 2016
@@ -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.ws.test;
+import static org.junit.Assert.*;
+
+import org.apache.uima.ducc.ws.server.DuccHandlerUtils;
+import org.junit.Test;
+
+
+public class TestSuite {
+
+	private void test(double v, String f) {
+		String r = DuccHandlerUtils.getSwapSizeHover(v);
+		//System.out.println(r);
+		assertTrue(f.equals(r));
+	}
+	
+	@Test
+	public void getDisplayableSize() {
+		test(Math.pow(10,12),"1000.0 GB");
+		test(Math.pow(10,11),"100.0 GB");
+		test(Math.pow(10,10),"10.0 GB");
+		test(Math.pow(10,9),"1.0 GB");
+		test(Math.pow(10,6),"1.0 MB");
+		test(Math.pow(10,3),"1.0 KB");
+		test(Math.pow(10,0),"1.0 Bytes");
+		test(Math.pow(10,9)/2,"0.5 GB");
+		test(Math.pow(10,6)/2,"0.5 MB");
+		test(Math.pow(10,3)/2,"0.5 KB");
+		test(Math.pow(10,9)/10,"0.1 GB");
+		test(Math.pow(10,6)/10,"0.1 MB");
+		test(Math.pow(10,3)/10,"0.1 KB");
+		test(Math.pow(10,9)/10-1,"100.0 MB");
+		test(Math.pow(10,6)/10-1,"100.0 KB");
+		test(Math.pow(10,3)/10-1,"99.0 Bytes");
+		test(0,"0.0 GB");
+	}
+
+}

Propchange: uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/test/java/org/apache/uima/ducc/ws/test/TestSuite.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/test/java/org/apache/uima/ducc/ws/test/TestSuite.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain