-
Notifications
You must be signed in to change notification settings - Fork 14
/
plugin.ts
98 lines (74 loc) · 3.71 KB
/
plugin.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import { BaseIngredient, IngredientManager } from "@azbake/core";
import { IIngredient, DeploymentContext } from "@azbake/core";
import { ARMHelper } from "@azbake/arm-helper";
import profile from './trf-mgr.json';
import endpoint from './endpoint.json';
import { TrafficUtils } from './functions';
import stockAlerts from "./stockAlerts.json"
export class TrafficManager extends BaseIngredient {
constructor(name: string, ingredient: IIngredient, ctx: DeploymentContext) {
super(name, ingredient, ctx);
this._helper = new ARMHelper(this._ctx);
}
_helper: ARMHelper;
public async Execute(): Promise<void> {
let util = IngredientManager.getIngredientFunction("coreutils", this._ctx);
try {
// deploy the traffic manager profile to the primary region only
if (util.current_region_primary()) {
await this.DeployProfile();
}
await this.DeployEndpoint();
} catch(error){
this._logger.error(`deployment failed: ${error}`);
throw error;
}
}
public async DeployProfile(): Promise<void> {
try {
let util = IngredientManager.getIngredientFunction("coreutils", this._ctx);
const region = this._ctx.Region.code;
let trfutil = new TrafficUtils(this._ctx);
let props = await this._helper.BakeParamsToARMParamsAsync(this._name, this._ctx.Ingredient.properties.parameters);
props["name"] = {"value": trfutil.get_profile() };
props = await this._helper.ConfigureDiagnostics(props);
await this._helper.DeployTemplate(`${this._name}-profile`, profile, props, await util.resource_group());
} catch(error){
this._logger.error(`deployment failed: ${error}`);
throw error;
}
}
public async DeployEndpoint(): Promise<void> {
try {
let util = IngredientManager.getIngredientFunction("coreutils", this._ctx);
const region = this._ctx.Region.code;
let trfutil = new TrafficUtils(this._ctx);
// read parameters to get the source-type.
let temp: any = {};
for ( const[n,v] of this._ingredient.properties.parameters){
temp[n] = {
"value": await v.valueAsync(this._ctx)
};
}
let props: any = {};
const profileName = trfutil.get_profile();
const epName = util.create_resource_name("ep", null, true);
this._logger.log(`profile name: ${profileName}, endpoint name: ${epName}`);
props["profile-name"] = { "value": profileName };
props["ep-name"] = { "value": epName };
const resource = util.parseResource(await this._ctx.Ingredient.properties.source.valueAsync(this._ctx));
const sourceType = temp["source-type"].value;
this._logger.log(`resource type: ${sourceType}, resource rg: ${resource.resourceGroup}, resource name: ${resource.resource}`);
props["source-rg"] = { "value": resource.resourceGroup };
props["source-name"] = { "value": resource.resource };
props["source-type"] = temp["source-type"];
await this._helper.DeployTemplate(`${this._name}-endpoint`, endpoint, props, await util.resource_group());
let alertTarget = profileName
let alertOverrides = this._ingredient.properties.alerts
await this._helper.DeployAlerts(this._name, await util.resource_group(), alertTarget, stockAlerts, alertOverrides)
} catch(error){
this._logger.error(`deployment failed: ${error}`);
throw error;
}
}
}