Sfoglia il codice sorgente

HPCC-26601 Changes for front-end currency formatting

Signed-off-by: Shamser Ahmed <shamser.ahmed@lexisnexis.com>
Shamser Ahmed 3 anni fa
parent
commit
9c4d31e885

+ 0 - 1
esp/platform/espcfg.cpp

@@ -373,7 +373,6 @@ CEspConfig::CEspConfig(IProperties* inputs, IPropertyTree* envpt, IPropertyTree*
             mergeConfiguration(*cost, *espConfigCost, nullptr, false);
         }
 #endif
-
         initializeStorageGroups(daliClientActive());
 
         const unsigned dafilesrvConnectTimeout = m_cfg->getPropInt("@dafilesrvConnectTimeout", 10)*1000;

+ 3 - 3
esp/scm/ws_dfu.ecm

@@ -191,7 +191,7 @@ ESPStruct [nil_remove] DFUFileDetail
     [min_ver("1.39")] ESParray<ESPstruct DFUFileBloom> Blooms;
     [min_ver("1.40")] int ExpireDays;
     [min_ver("1.41")] string KeyType;
-    [min_ver("1.59")] string Cost;
+    [min_ver("1.60")] double Cost;
 };
 
 ESPStruct DFUSpaceItem
@@ -968,8 +968,8 @@ ESPresponse [exceptions_inline, nil_remove] DFUFilePublishResponse
 //  ===========================================================================
 ESPservice [
     auth_feature("DEFERRED"),
-    version("1.59"),
-    default_client_version("1.59"),
+    version("1.60"),
+    default_client_version("1.60"),
     noforms,
     exceptions_inline("./smc_xslt/exceptions.xslt")] WsDfu
 {

+ 2 - 7
esp/services/ws_dfu/ws_dfuService.cpp

@@ -2654,13 +2654,8 @@ void CWsDfuEx::doGetFileDetails(IEspContext &context, IUserDescriptor *udesc, co
                 FileDetails.setJsonInfo(jsonLayout);
         }
     }
-    if (version >= 1.59)
-    {
-        double totalCost = df->getCost(cluster);
-        StringBuffer s;
-        formatMoney(s, money2cost_type(totalCost));
-        FileDetails.setCost(s);
-    }
+    if (version >= 1.60)
+        FileDetails.setCost(df->getCost(cluster));
     PROGLOG("doGetFileDetails: %s done", name);
 }
 

+ 9 - 0
esp/services/ws_smc/ws_smcService.cpp

@@ -2645,6 +2645,15 @@ bool CWsSMCEx::onGetBuildInfo(IEspContext &context, IEspGetBuildInfoRequest &req
             namedValue->setValue("ON");
             buildInfo.append(*namedValue.getClear());
         }
+        Owned<IPropertyTree> costPT = getGlobalConfigSP()->queryPropTree("cost");
+        if (costPT)
+        {
+            Owned<IEspNamedValue> namedValue = createNamedValue();
+            namedValue->setName("currencyCode");
+            const char * currencyCode = costPT->queryProp("@currencyCode");
+            namedValue->setValue(isEmptyString(currencyCode)?"USD":currencyCode);
+            buildInfo.append(*namedValue.getClear());
+        }
         resp.setBuildInfo(buildInfo);
     }
     catch(IException* e)

+ 5 - 0
helm/hpcc/values.schema.json

@@ -265,6 +265,11 @@
           "description": "resource cost",
           "type": "object",
           "properties": {
+            "currencyCode": {
+                "description": "currency code (ISO 4217)",
+                "type": "string",
+                "maxLength": 3
+            },
             "perCpu": {
               "description": "cost of a single cpu",
               "type": "number"

+ 1 - 1
helm/hpcc/values.yaml

@@ -47,7 +47,7 @@ global:
     # kubeApiPort: 7443
 
   cost:
-    moneyLocale: "en_US.UTF-8"
+    currencyCode: USD
     perCpu: 0.126
     storageAtRest: 0.0135
     storageReads: 0.0485

+ 5 - 0
initfiles/etc/DIR_NAME/environment.xml.in

@@ -13,6 +13,11 @@
             name="localhost"
             netAddress="."/>
   <Switch name="Switch"/>
+  <cost currencyCode="USD"
+        perCpu="0.113"
+        storageAtRest="0.0135"
+        storageReads="0.0485"
+        storageWrites="0.0038"/>
  </Hardware>
  <Software>
   <DropZone build="_"

+ 1 - 45
system/jlib/jstats.cpp

@@ -386,53 +386,9 @@ static StringBuffer & formatIPV4(StringBuffer & out, unsigned __int64 value)
     return out.appendf("%d.%d.%d.%d", ip1, ip2, ip3, ip4);
 }
 
-class MoneyLocale
-{
-public:
-    ~MoneyLocale()
-    {
-        delete locale.load(std::memory_order_relaxed);
-    }
-    std::locale * createMoneyLocale() const
-    {
-        StringBuffer localestr;
-        getGlobalConfigSP()->getProp("cost/@moneyLocale", localestr);
-        std::locale * loc = nullptr;
-        try
-        {
-            loc = new std::locale(localestr.str());
-        }
-        catch (std::exception const& e)
-        {
-            // Use default locale if the specified moneyLocale is invalid
-            // (avoids difficult to track down crashes)
-            OERRLOG("Locale '%s' is not installed [%s]", localestr.str(), e.what());
-            loc = new std::locale("");
-        }
-        return loc;
-    }
-    std::locale & queryMoneyLocale()
-    {
-        return *querySingleton(locale, cslock, [this]{ return this->createMoneyLocale(); });
-    }
-
-private:
-    static CriticalSection cslock;
-    std::atomic<std::locale *> locale {nullptr};
-};
-
-static MoneyLocale moneyLocale;
-CriticalSection MoneyLocale::cslock;
-
 StringBuffer & formatMoney(StringBuffer &out, unsigned __int64 value)
 {
-    std::stringstream ss;
-    std::locale & loc = moneyLocale.queryMoneyLocale();
-    ss.imbue(loc);
-    unsigned decplaces = std::use_facet<std::moneypunct<char>>(loc).frac_digits();
-    long double mvalue = ((long double)cost_type2money(value))*std::pow(10, decplaces);
-    ss << std::showbase << std::put_money(mvalue);
-    return out.append(ss.str().c_str());
+    return out.appendf("%.6f", cost_type2money(value));
 }
 
 StringBuffer & formatStatistic(StringBuffer & out, unsigned __int64 value, StatisticMeasure measure)

+ 5 - 0
testing/regress/environment.xml.in

@@ -13,6 +13,11 @@
             name="localhost"
             netAddress="."/>
   <Switch name="Switch"/>
+  <cost currencyCode="USD"
+        perCpu="0.113"
+        storageAtRest="0.0135"
+        storageReads="0.0485"
+        storageWrites="0.0038"/>
  </Hardware>
  <Software>
   <DropZone build="_"