Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autodesk Arnold Meter Change #2178

Merged
merged 8 commits into from
May 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { ElectronTestingModule } from "@batch-flask/electron/testing";
import { BreadcrumbService } from "@batch-flask/ui/breadcrumbs";
import { TableTestingModule } from "@batch-flask/ui/testing";
import { AppLicensePickerComponent } from "app/components/pool/action/add";
import { SoftwareBillingUnit } from "app/models";
import { PricingService } from "app/services";
import { SoftwarePricing } from "app/services/pricing";
import { of } from "rxjs";
Expand All @@ -22,8 +23,8 @@ class TestComponent {
}

const pricing = new SoftwarePricing();
pricing.add("maya", 12, false);
pricing.add("arnold", 5, true);
pricing.add("maya", 12, SoftwareBillingUnit.node);
pricing.add("arnold", 5, SoftwareBillingUnit.node);

describe("AppLicensePickerComponent", () => {
let fixture: ComponentFixture<TestComponent>;
Expand Down Expand Up @@ -64,9 +65,9 @@ describe("AppLicensePickerComponent", () => {
fixture.detectChanges();
});

it("Should show 4 licenses", () => {
it("Should show 5 licenses", () => {
const tableRows = debugElement.queryAll(By.css("bl-row-render"));
expect(tableRows.length).toBe(4);
expect(tableRows.length).toBe(5);

const row1Columns = tableRows[0].queryAll(By.css(".bl-table-cell"));
expect(row1Columns.length).toBe(3, "Row has 3 columns");
Expand All @@ -82,12 +83,17 @@ describe("AppLicensePickerComponent", () => {
const row3Columns = tableRows[2].queryAll(By.css(".bl-table-cell"));
expect(row3Columns[0].nativeElement.textContent).toContain("Autodesk Arnold");
expect(row3Columns[1].nativeElement.textContent).toContain("EULA");
expect(row3Columns[2].nativeElement.textContent).toContain("$5/core/hour");
expect(row3Columns[2].nativeElement.textContent).toContain("$5/node/hour");

const row4Columns = tableRows[3].queryAll(By.css(".bl-table-cell"));
expect(row4Columns[0].nativeElement.textContent).toContain("Chaos Group V-Ray");
expect(row4Columns[1].nativeElement.textContent).toContain("EULA");
expect(row4Columns[2].nativeElement.textContent).toContain("-");

const row5Columns = tableRows[4].queryAll(By.css(".bl-table-cell"));
expect(row5Columns[0].nativeElement.textContent).toContain("Chaos Group V-Ray RT");
expect(row5Columns[1].nativeElement.textContent).toContain("EULA");
expect(row5Columns[2].nativeElement.textContent).toContain("-");
});

it("Should select license by checking checkbox", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ const softwares = [
id: "vray",
description: "Chaos Group V-Ray",
},
{
id: "vrayrt",
description: "Chaos Group V-Ray RT",
},
];

@Component({
Expand Down Expand Up @@ -134,8 +138,7 @@ export class AppLicensePickerComponent implements ControlValueAccessor, OnInit,
const cost = this._pricing && this._pricing.get(software.id);
let costStr = "-";
if (cost) {
const unit = cost.perCore ? "core" : "node";
costStr = `$${cost.price}/${unit}/hour`;
costStr = `$${cost.price}/${cost.billingUnit as string}/hour`;
}
return new ApplicationLicense({
...software,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ export class LicenseEulaDialogComponent {
}

public get isVray(): boolean {
return this.license && this.license.id === "vray";
return this.license && (this.license.id === "vray"
|| this.license.id === "vrayrt");
}

public openLink(link: string) {
Expand Down
1 change: 1 addition & 0 deletions src/app/models/batch-software-license.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ export enum BatchSoftwareLicense {
arnold = "arnold",
maya = "maya",
vray = "vray",
vrayrt = "vrayrt",
}
1 change: 1 addition & 0 deletions src/app/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export * from "./autoscale-formula";
export * from "./azure-batch";
export * from "./batch-account";
export * from "./batch-software-license";
export * from "./software-billing-unit";
export * from "./blob-container";
export * from "./certificate-reference";
export * from "./certificate";
Expand Down
8 changes: 8 additions & 0 deletions src/app/models/software-billing-unit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* List of pricing units for software licenses
*/
export enum SoftwareBillingUnit {
core = "core",
gpu = "gpu",
node = "node",
}
37 changes: 29 additions & 8 deletions src/app/services/pricing.service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Injectable } from "@angular/core";
import { GlobalStorage } from "@batch-flask/core";
import { log } from "@batch-flask/utils";
import { ArmBatchAccount, BatchSoftwareLicense, Pool, RateCardMeter } from "app/models";
import { ArmBatchAccount, BatchSoftwareLicense, Pool, RateCardMeter, SoftwareBillingUnit } from "app/models";
import { BatchPricing, OSPricing, OsType, SoftwarePricing, VMPrices } from "app/services/pricing";
import { PoolPrice, PoolPriceOptions, PoolUtils } from "app/utils";
import { DateTime } from "luxon";
Expand Down Expand Up @@ -55,10 +55,26 @@ const regionMapping = {
};

const softwareMeterId = {
"089f79d8-0349-432c-96a6-8add90b8a40e": BatchSoftwareLicense.arnold,
"0ec88494-2022-4939-b809-0d914d954692": BatchSoftwareLicense["3dsmax"],
"1d3bb602-0cde-4618-9fb0-f9d94805c2a6": BatchSoftwareLicense.maya,
"e2d2d63e-8741-499a-8989-f5f7ec5c3b3f": BatchSoftwareLicense.vray,
"da155550-4041-54ce-bf5c-385c0bd5eaba": {
license: BatchSoftwareLicense.arnold,
billingUnit: SoftwareBillingUnit.node,
},
"0ec88494-2022-4939-b809-0d914d954692": {
license: BatchSoftwareLicense["3dsmax"],
billingUnit: SoftwareBillingUnit.node,
},
"1d3bb602-0cde-4618-9fb0-f9d94805c2a6": {
license: BatchSoftwareLicense.maya,
billingUnit: SoftwareBillingUnit.node,
},
"e2d2d63e-8741-499a-8989-f5f7ec5c3b3f": {
license: BatchSoftwareLicense.vray,
billingUnit: SoftwareBillingUnit.core,
},
"450f680c-b109-486a-8fec-2b9e7ab0fbc9": {
license: BatchSoftwareLicense.vrayrt,
billingUnit: SoftwareBillingUnit.gpu,
},
};

@Injectable({ providedIn: "root" })
Expand Down Expand Up @@ -172,12 +188,17 @@ export class PricingService {
return pricing;
}

/**
* Sets the software prices using meter IDs
* @param meters RateCardMeter[]
* @param pricing BatchPricing
*/
private _processSoftwaresPricings(meters: RateCardMeter[], pricing: BatchPricing) {
for (const meter of meters) {
if (meter.MeterId in softwareMeterId) {
const software = softwareMeterId[meter.MeterId];
const perCore = meter.MeterName.toLowerCase().includes("1 vcpu");
pricing.softwares.add(software, meter.MeterRates["0"], perCore);
const software = softwareMeterId[meter.MeterId].license;
const unit = softwareMeterId[meter.MeterId].billingUnit;
pricing.softwares.add(software, meter.MeterRates["0"], unit);
}
}
}
Expand Down
10 changes: 6 additions & 4 deletions src/app/services/pricing/pricing.model.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { SoftwareBillingUnit } from "app/models/software-billing-unit";

export type OsType = "linux" | "windows";

export interface RegionPrices {
Expand Down Expand Up @@ -132,7 +134,7 @@ export class NodePricing {
export interface SoftwarePrice {
name: string;
price: number;
perCore: boolean;
billingUnit: SoftwareBillingUnit;
}

export class SoftwarePricing {
Expand All @@ -143,11 +145,11 @@ export class SoftwarePricing {
}
private _map: Map<string, SoftwarePrice> = new Map();

public add(software: string, price: number, perCore = false) {
public add(software: string, price: number, billingUnit: SoftwareBillingUnit) {
this._map.set(software, {
name: software,
price,
perCore,
billingUnit,
});
}

Expand All @@ -162,7 +164,7 @@ export class SoftwarePricing {
public getPrice(software: string, coreCount = 1): number {
const data = this._map.get(software);
if (!data) { return null; }
return data.perCore ? coreCount * data.price : data.price;
return data.billingUnit === "core" ? coreCount * data.price : data.price;
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/app/utils/pool-utils.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CloudServiceOsFamily, Pool, VmSize } from "app/models";
import { CloudServiceOsFamily, Pool, SoftwareBillingUnit, VmSize } from "app/models";
import { SoftwarePricing } from "app/services/pricing";
import { PoolUtils } from "app/utils";

Expand Down Expand Up @@ -183,9 +183,9 @@ describe("PoolUtils", () => {
} as any);

const softwares = new SoftwarePricing();
softwares.add("vray", 0.02, true);
softwares.add("3dsmax", 0.65, false);
softwares.add("maya", 0.75, false);
softwares.add("vray", 0.02, SoftwareBillingUnit.core);
softwares.add("3dsmax", 0.65, SoftwareBillingUnit.node);
softwares.add("maya", 0.75, SoftwareBillingUnit.node);

it("works for a basic pool", () => {
const windowsConfig = {
Expand Down