Skip to content

Commit

Permalink
Fix: rate card api braking change (#1570)
Browse files Browse the repository at this point in the history
  • Loading branch information
timotheeguerin authored Aug 29, 2018
1 parent 99d1313 commit b90310d
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 18 deletions.
7 changes: 3 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
6 changes: 5 additions & 1 deletion app/services/pricing.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"]);
}
}
}
Expand Down
27 changes: 15 additions & 12 deletions app/services/pricing/pricing.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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)) {
Expand Down Expand Up @@ -73,16 +71,18 @@ export class NodePricing {

private _map: Map<string, RegionPrices> = 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"),
windows: new OSPricing(region, "windows"),
});
}
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 {
Expand Down Expand Up @@ -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 };
}
}

Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b90310d

Please sign in to comment.