From b90310d36876e87eea354dfe21d60a146efaf6bd Mon Sep 17 00:00:00 2001 From: Timothee Guerin Date: Wed, 29 Aug 2018 14:32:01 -0700 Subject: [PATCH] Fix: rate card api braking change (#1570) --- CHANGELOG.md | 7 +++---- app/services/pricing.service.ts | 6 +++++- app/services/pricing/pricing.model.ts | 27 +++++++++++++++------------ package-lock.json | 2 +- 4 files changed, 24 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 84c8fcfdf6..bbe0cd99d5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,13 +1,12 @@ # 0.17.3 -### Bug fixes: +### Minor feature: * Display storage account URL in the Credentials and code samples dialog [\#1556](https://github.com/Azure/BatchExplorer/issues/1556) -* Cannot upload files to file group in govt cloud [\#1557](https://github.com/Azure/BatchExplorer/issues/1557) - -# 0.17.2 ### Bug fixes: +* Cannot upload files to file group in govt cloud [\#1557](https://github.com/Azure/BatchExplorer/issues/1557) * Cannot login to GOVT cloud [\#1548](https://github.com/Azure/BatchExplorer/issues/1548) +* Pricing broken, due to api breaking change [\#1562](https://github.com/Azure/BatchExplorer/issues/1562) # 0.17.1 [All items](https://github.com/Azure/BatchExplorer/milestone/25?closed=1) diff --git a/app/services/pricing.service.ts b/app/services/pricing.service.ts index 5ec43b23c3..8ff55e55fb 100644 --- a/app/services/pricing.service.ts +++ b/app/services/pricing.service.ts @@ -150,7 +150,11 @@ export class PricingService { && meter.MeterRegion !== "Azure Stack" && meter.MeterRegion in regionMapping && !meter.MeterSubCategory.includes("VM_Promo")) { - pricing.nodes.add(regionMapping[meter.MeterRegion], meter.MeterSubCategory, meter.MeterRates["0"]); + pricing.nodes.add( + regionMapping[meter.MeterRegion], + meter.MeterSubCategory, + meter.MeterName, + meter.MeterRates["0"]); } } } diff --git a/app/services/pricing/pricing.model.ts b/app/services/pricing/pricing.model.ts index ab5512d550..475faa70f1 100644 --- a/app/services/pricing/pricing.model.ts +++ b/app/services/pricing/pricing.model.ts @@ -10,8 +10,6 @@ export interface VMPrices { lowpri: number; } -const missingCategoryRegex = /^a[0-9]+$/; - export class OSPricing { public static fromJS(name, os, data: any[]): OSPricing { const pricing = new OSPricing(name, os); @@ -24,7 +22,7 @@ export class OSPricing { public add(vmsize: string, lowpri: boolean, price: number) { vmsize = vmsize.toLowerCase().replace(/\./g, "_"); - if (missingCategoryRegex.exec(vmsize)) { + if (!vmsize.startsWith("standard_")) { vmsize = `standard_${vmsize}`; } if (!this._map.has(vmsize)) { @@ -73,7 +71,7 @@ export class NodePricing { private _map: Map = new Map(); - public add(region: string, vmName: string, price: number) { + public add(region: string, category: string, vmName: string, price: number) { if (!this._map.has(region)) { this._map.set(region, { linux: new OSPricing(region, "linux"), @@ -81,8 +79,10 @@ export class NodePricing { }); } const regionPricing = this._map.get(region); - const { os, lowpri, vmsize } = this._parseVmName(vmName); - regionPricing[os].add(vmsize, lowpri, price); + const { os, lowpri, vmSizes } = this._parseVmName(category, vmName); + for (const vmSize of vmSizes) { + regionPricing[os].add(vmSize, lowpri, price); + } } public getPrice(region: string, os: OsType, vmsize: string, lowpri = false): number { @@ -116,12 +116,15 @@ export class NodePricing { }); } - private _parseVmName(name: string): { os: OsType, lowpri: boolean, vmsize: string } { - const segments = name.split(" ", 2); - const vmsize = segments[0]; - const os = name.includes("(Windows)") ? "windows" : "linux"; - const lowpri = name.includes("Low Priority"); - return { os, lowpri, vmsize }; + private _parseVmName(category: string, name: string): { os: OsType, lowpri: boolean, vmSizes: string[] } { + let lowpri = false; + if (name.endsWith(" Low Priority")) { + lowpri = true; + name = name.replace(" Low Priority", ""); + } + const vmSizes = name.split("/").map(x => x.replace(/ /g, "_")); + const os = category.includes("Windows") ? "windows" : "linux"; + return { os, lowpri, vmSizes }; } } diff --git a/package-lock.json b/package-lock.json index 717e2545c1..2a6aaf2416 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "batch-labs", - "version": "0.17.1", + "version": "0.17.3", "lockfileVersion": 1, "requires": true, "dependencies": {