<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Function to calculate new volume size - problem in Active IQ Unified Manager Discussions</title>
    <link>https://community.netapp.com/t5/Active-IQ-Unified-Manager-Discussions/Function-to-calculate-new-volume-size-problem/m-p/28765#M5977</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for looking into this. Attached is the full workflow.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 21 Oct 2013 11:36:43 GMT</pubDate>
    <dc:creator>willwalsh4</dc:creator>
    <dc:date>2013-10-21T11:36:43Z</dc:date>
    <item>
      <title>Function to calculate new volume size - problem</title>
      <link>https://community.netapp.com/t5/Active-IQ-Unified-Manager-Discussions/Function-to-calculate-new-volume-size-problem/m-p/28757#M5971</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am attempting to create a function that calculates correct volume size based on a desired percentage used. I am encountering what I believe to be a computational issue inside the MVEL where it doesn't behave consistently. Maybe this is a bug, or maybe the issue is between my ears? I need some help, though.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is the code:&lt;/P&gt;&lt;P&gt;def calculateTargetVolumeSize(vol_used,vol_avail,snap_percent,snap_used,target_percent) &lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; int percent_used = (vol_used / (vol_used + vol_avail)) * 100;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; if (percent_used &amp;lt; target_percent ) {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; throwException("Percent used " + percent_used + "% is already below designated percentage of " + target_percent + "%.\nThe following values were passed: " + vol_used + ", " + vol_avail + ", " + snap_percent + ", " + snap_used);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; int new_avail_size = (int)(vol_used / (target_percent / 100));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; int new_vol_size = (int)(new_avail_size / (1 - (snap_percent / 100)));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; int new_snap_size = new_vol_size - new_avail_size;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; if (snap_used &amp;gt; new_snap_size) {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; new_vol_size = new_avail_size + snap_used;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; if (new_vol_size &amp;lt; 20 ) {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; new_vol_size = 20;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; // throwException("new size: " + new_vol_size);&lt;/P&gt;&lt;P&gt; return new_vol_size;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am leveraging this function in a workflow that uses the Resize volume command. The function is in the TargetSize value. It returns the following error:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Function: 'calculateTargetVolumeSize'&lt;/P&gt;&lt;P&gt;With parameters: v1.used_size_mb, v1.available_size_mb, v1.snapshot_reserved_percent, v1.snapshot_used_mb, 70&lt;/P&gt;&lt;P&gt;Threw an Exception with a message: Percent used 9.99997731789257E-4% is already below designated percentage of 70%.&lt;/P&gt;&lt;P&gt;The following values were passed: 237883, 53957, 5, 50035&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I cannot for the life of me figure out how ( 237883 / (237883 + 53957)) * 100 = 9.999977331789257E-4&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When I run the function as a test using this syntax: calculateTargetVolumeSize(237883,53957,5,50035,70)&lt;/P&gt;&lt;P&gt;It returns the following value correctly: 389867&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any ideas?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Will&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Jun 2025 05:51:34 GMT</pubDate>
      <guid>https://community.netapp.com/t5/Active-IQ-Unified-Manager-Discussions/Function-to-calculate-new-volume-size-problem/m-p/28757#M5971</guid>
      <dc:creator>willwalsh4</dc:creator>
      <dc:date>2025-06-05T05:51:34Z</dc:date>
    </item>
    <item>
      <title>Re: Function to calculate new volume size - problem</title>
      <link>https://community.netapp.com/t5/Active-IQ-Unified-Manager-Discussions/Function-to-calculate-new-volume-size-problem/m-p/28761#M5974</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Will,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; Looking at the function, I can't make out anything wrong, it seems fine. Can you post the workflow where you are calling the function, it probably is where the problem might be.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 21 Oct 2013 11:31:07 GMT</pubDate>
      <guid>https://community.netapp.com/t5/Active-IQ-Unified-Manager-Discussions/Function-to-calculate-new-volume-size-problem/m-p/28761#M5974</guid>
      <dc:creator>sinhaa</dc:creator>
      <dc:date>2013-10-21T11:31:07Z</dc:date>
    </item>
    <item>
      <title>Re: Function to calculate new volume size - problem</title>
      <link>https://community.netapp.com/t5/Active-IQ-Unified-Manager-Discussions/Function-to-calculate-new-volume-size-problem/m-p/28765#M5977</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for looking into this. Attached is the full workflow.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 21 Oct 2013 11:36:43 GMT</pubDate>
      <guid>https://community.netapp.com/t5/Active-IQ-Unified-Manager-Discussions/Function-to-calculate-new-volume-size-problem/m-p/28765#M5977</guid>
      <dc:creator>willwalsh4</dc:creator>
      <dc:date>2013-10-21T11:36:43Z</dc:date>
    </item>
    <item>
      <title>Re: Function to calculate new volume size - problem</title>
      <link>https://community.netapp.com/t5/Active-IQ-Unified-Manager-Discussions/Function-to-calculate-new-volume-size-problem/m-p/28770#M5980</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Will,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is V1 volume variable defined by you or found using a finder?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Just asking to confirm that those attributes of V1 have values. I suspect one of them is not getting the right value.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Can you add all those parameters that you pass to the functions to be return parameters so you can see them in the planning?&lt;BR /&gt;You might need to add them and disable the function briefly (Just exchange it with some fixed size) to get through planning and see those values.&lt;/P&gt;&lt;P&gt;Very useful for debugging...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best,&lt;/P&gt;&lt;P&gt;Yaron&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 21 Oct 2013 13:13:03 GMT</pubDate>
      <guid>https://community.netapp.com/t5/Active-IQ-Unified-Manager-Discussions/Function-to-calculate-new-volume-size-problem/m-p/28770#M5980</guid>
      <dc:creator>yaronh</dc:creator>
      <dc:date>2013-10-21T13:13:03Z</dc:date>
    </item>
    <item>
      <title>Re: Function to calculate new volume size - problem</title>
      <link>https://community.netapp.com/t5/Active-IQ-Unified-Manager-Discussions/Function-to-calculate-new-volume-size-problem/m-p/28775#M5983</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Yaron,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I did as you recommended and the values returned are in the attached screenshot.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Will&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 21 Oct 2013 13:19:23 GMT</pubDate>
      <guid>https://community.netapp.com/t5/Active-IQ-Unified-Manager-Discussions/Function-to-calculate-new-volume-size-problem/m-p/28775#M5983</guid>
      <dc:creator>willwalsh4</dc:creator>
      <dc:date>2013-10-21T13:19:23Z</dc:date>
    </item>
    <item>
      <title>Re: Function to calculate new volume size - problem</title>
      <link>https://community.netapp.com/t5/Active-IQ-Unified-Manager-Discussions/Function-to-calculate-new-volume-size-problem/m-p/28780#M5986</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hey willwalsh,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I would like to know which version of WFA you have installed. is it 1.0 ?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Sinhaa,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I know this is completely off track from what we are looking at here but, I get an error while importing this workflow given by willwalsh in my setup. I have attached the snapshot of the error. &lt;/P&gt;&lt;P&gt;&lt;IMG src="http://community.netapp.com/legacyfs/online/23711_wfa.PNG" width="450" /&gt;&lt;/P&gt;&lt;P&gt;I have WFA 2.0.1.23.8 installed. I saw another thread (&lt;A _jive_internal="true" href="https://community.netapp.com/thread/25651" target="_blank"&gt;https://communities.netapp.com/thread/25651&lt;/A&gt;) on importing workflows from 1.0 to 2.0 and the outcome of the thread says that we need an intermediary installation of 1.1.1 to get it done. Is there no other way of doing it ?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 22 Oct 2013 10:56:53 GMT</pubDate>
      <guid>https://community.netapp.com/t5/Active-IQ-Unified-Manager-Discussions/Function-to-calculate-new-volume-size-problem/m-p/28780#M5986</guid>
      <dc:creator>ag</dc:creator>
      <dc:date>2013-10-22T10:56:53Z</dc:date>
    </item>
    <item>
      <title>Re: Function to calculate new volume size - problem</title>
      <link>https://community.netapp.com/t5/Active-IQ-Unified-Manager-Discussions/Function-to-calculate-new-volume-size-problem/m-p/28785#M5989</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am running version 2.1.0.70.32&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 22 Oct 2013 12:52:15 GMT</pubDate>
      <guid>https://community.netapp.com/t5/Active-IQ-Unified-Manager-Discussions/Function-to-calculate-new-volume-size-problem/m-p/28785#M5989</guid>
      <dc:creator>willwalsh4</dc:creator>
      <dc:date>2013-10-22T12:52:15Z</dc:date>
    </item>
    <item>
      <title>Re: Function to calculate new volume size - problem</title>
      <link>https://community.netapp.com/t5/Active-IQ-Unified-Manager-Discussions/Function-to-calculate-new-volume-size-problem/m-p/28790#M5991</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I realize that I did not answer part of your question. v1 is found using a finder. I ask the user to input the volume in the format &amp;lt;filer&amp;gt;:/vol/&amp;lt;volume&amp;gt;. I then parse that into the variables filer and volume and pass that to the finder. The values appear to be correct, both as returned values, and when the function throws an exception.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 22 Oct 2013 12:55:43 GMT</pubDate>
      <guid>https://community.netapp.com/t5/Active-IQ-Unified-Manager-Discussions/Function-to-calculate-new-volume-size-problem/m-p/28790#M5991</guid>
      <dc:creator>willwalsh4</dc:creator>
      <dc:date>2013-10-22T12:55:43Z</dc:date>
    </item>
    <item>
      <title>Re: Function to calculate new volume size - problem</title>
      <link>https://community.netapp.com/t5/Active-IQ-Unified-Manager-Discussions/Function-to-calculate-new-volume-size-problem/m-p/28795#M5993</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hey,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;You are running into precision issues with the math. As the input is integer, it is being converted along the way and integers cannot hold decimal places. Hence you get enormous rounding errors. ie. 1/3 = 0.333 as a double, or 0 as an integer.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;Try something like this instead, force type-cast as double the variables for the calculations:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;&amp;nbsp; int percent_used = (((double)vol_used) / (((double)vol_used) + ((double)vol_avail))) * 100;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;This will result in the correct response as the 'double' type can store many decimal places during the calculation. Keep in mind casting is a low precedence operator on MVEL unlike some other languages and needs the brackets. Without them, the first divide would be interpreted with vol_used as an integer instead then converted to double after the divide, but it's already lost the decimal places at this point. It's safest to always use brackets in MVEL when type-converting, and remember that MVEL will automatically type-convert for you which may have unexpected side effects like precision loss.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Michael.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 25 Oct 2013 01:35:20 GMT</pubDate>
      <guid>https://community.netapp.com/t5/Active-IQ-Unified-Manager-Discussions/Function-to-calculate-new-volume-size-problem/m-p/28795#M5993</guid>
      <dc:creator>mgoddard</dc:creator>
      <dc:date>2013-10-25T01:35:20Z</dc:date>
    </item>
    <item>
      <title>Re: Function to calculate new volume size - problem</title>
      <link>https://community.netapp.com/t5/Active-IQ-Unified-Manager-Discussions/Function-to-calculate-new-volume-size-problem/m-p/28803#M5996</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Michael! That fixed it. Here is the completed workflow. For those interested in using it. It was created in WFA 2.1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;BR /&gt;Will&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 28 Oct 2013 15:17:59 GMT</pubDate>
      <guid>https://community.netapp.com/t5/Active-IQ-Unified-Manager-Discussions/Function-to-calculate-new-volume-size-problem/m-p/28803#M5996</guid>
      <dc:creator>willwalsh4</dc:creator>
      <dc:date>2013-10-28T15:17:59Z</dc:date>
    </item>
  </channel>
</rss>

