11package org .labkey .cluster .pipeline ;
22
33import org .apache .commons .lang3 .StringUtils ;
4- import org .apache .commons .lang3 .math .NumberUtils ;
54import org .apache .logging .log4j .LogManager ;
65import org .apache .logging .log4j .Logger ;
76import org .jetbrains .annotations .NotNull ;
1413import org .labkey .api .data .ContainerManager ;
1514import org .labkey .api .pipeline .PipelineJob ;
1615import org .labkey .api .pipeline .PipelineJobException ;
17- import org .labkey .api .pipeline .PipelineJobService ;
1816import org .labkey .api .pipeline .PipelineService ;
1917import org .labkey .api .pipeline .PipelineStatusFile ;
2018import org .labkey .api .util .FileUtil ;
@@ -312,8 +310,8 @@ else if (headerFound)
312310 String maxRSS = StringUtils .trimToNull (tokens [maxRssIdx ]);
313311 if (maxRSS != null )
314312 {
315- long bytes = FileSizeFormatter .convertStringRepresentationToBytes (maxRSS );
316- long requestInBytes = FileSizeFormatter .convertStringRepresentationToBytes (getConfig ().getRequestMemory () + "G" ); //request is always GB
313+ double bytes = FileSizeFormatter .convertStringRepresentationToBytes (maxRSS );
314+ double requestInBytes = FileSizeFormatter .convertStringRepresentationToBytes (getConfig ().getRequestMemory () + "G" ); //request is always GB
317315 if (bytes > requestInBytes )
318316 {
319317 info = "Job exceeded memory, max was: " + FileSizeFormatter .convertBytesToUnit (bytes , 'G' ) + "G, requested memory was: " + getConfig ().getRequestMemory () + "G" ;
@@ -780,13 +778,13 @@ private Pair<String, String> getStatusFromQueue(ClusterJob job)
780778 // Based on: https://stackoverflow.com/questions/3758606/how-can-i-convert-byte-size-into-a-human-readable-format-in-java
781779 private static class FileSizeFormatter
782780 {
783- public static long convertStringRepresentationToBytes (final String value )
781+ public static double convertStringRepresentationToBytes (final String value )
784782 {
785783 try
786784 {
787785 char unit = value .toUpperCase ().charAt (value .length () - 1 );
788786 long sizeFactor = getSizeFactor (unit );
789- long size = Long . parseLong (value .substring (0 , value .length () - 1 ));
787+ double size = Double . parseDouble (value .substring (0 , value .length () - 1 ));
790788
791789 return size * sizeFactor ;
792790 }
@@ -796,11 +794,11 @@ public static long convertStringRepresentationToBytes(final String value)
796794 }
797795 }
798796
799- public static long convertBytesToUnit (final long bytes , final char unit )
797+ public static double convertBytesToUnit (final double bytes , final char unit )
800798 {
801799 long sizeFactor = getSizeFactor (unit );
802800
803- return bytes / sizeFactor ;
801+ return bytes / ( double ) sizeFactor ;
804802 }
805803
806804 private static long getSizeFactor (char unit )
@@ -826,11 +824,11 @@ public static class TestCase
826824 @ Test
827825 public void testFileSizeFormatter ()
828826 {
829- long bytes = FileSizeFormatter .convertStringRepresentationToBytes ("1362624K" );
830- Assert .assertEquals ("Incorrect byte value" , 1395326976 , bytes );
827+ double bytes = FileSizeFormatter .convertStringRepresentationToBytes ("1362624K" );
828+ Assert .assertEquals ("Incorrect byte value" , 1395326976.0 , bytes , 0.0 );
831829
832- long val2 = FileSizeFormatter .convertBytesToUnit (bytes , 'K' );
833- Assert .assertEquals ("Incorrect string value" , 1362624 , val2 );
830+ double val2 = FileSizeFormatter .convertBytesToUnit (bytes , 'K' );
831+ Assert .assertEquals ("Incorrect string value" , 1362624.0 , val2 , 0.0 );
834832 }
835833 }
836834}
0 commit comments