sleeveforarm
Version:
Making Azure Easy
107 lines • 4.54 kB
JavaScript
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const CommonUtilities = require("./common-utilities");
const data = require("./data");
const promiseGate_1 = require("./promiseGate");
const resourcegroup_1 = require("./resourcegroup");
class BaseDeployResourceGroupInfrastructure {
constructor(baseGroup) {
this.baseGroup = baseGroup;
}
get deployedResourceGroupName() {
return this.baseGroup.resourceGroupName;
}
}
exports.BaseDeployResourceGroupInfrastructure = BaseDeployResourceGroupInfrastructure;
class ResourceGroupInfrastructure extends resourcegroup_1.default {
constructor() {
super(...arguments);
this.promiseGate = new promiseGate_1.default();
}
get resourceGroupName() {
return this.resourceGroupNameProperty;
}
setResourceGroupName(name) {
this.resourceGroupNameProperty = name;
return this;
}
initialize(resource, targetDirectoryPath) {
super.initialize(resource, targetDirectoryPath);
if (resource !== null) {
Object.assign(this, resource);
}
return this;
}
setup() {
return __awaiter(this, void 0, void 0, function* () {
return yield resourcegroup_1.default.internalSetup(__filename, this.targetDirectoryPath, data.data.ResourceGroupLength, true);
});
}
hydrate(resourcesInEnvironment, deploymentType) {
const _super = name => super[name];
return __awaiter(this, void 0, void 0, function* () {
yield _super("hydrate").call(this, resourcesInEnvironment, deploymentType);
if (this.dataCenter === undefined) {
throw new Error("setDataCenter in root sleeve.js file MUST be set to a DC name");
}
const locationAcronym = this.dataCenter.split(" ")
.reduce((output, word) => {
return output + word[0];
}, "");
if (this.resourceGroupName === undefined) {
this.setResourceGroupName(this.baseName + locationAcronym + deploymentType[0]);
}
return this;
});
}
deployResource() {
return __awaiter(this, void 0, void 0, function* () {
if (this.promiseGate.isGateOpen) {
throw new Error("Deploy was already called");
}
try {
yield CommonUtilities.runAzCommand(`az group create --name ${this.resourceGroupName} \
--location "${this.dataCenter}"`);
this.promiseGate.openGateSuccess(new BaseDeployResourceGroupInfrastructure(this));
return this;
}
catch (err) {
this.promiseGate.openGateError(err);
throw err;
}
});
}
deleteResource() {
return __awaiter(this, void 0, void 0, function* () {
if (!this.promiseGate.isGateOpen) {
throw new Error("Delete is intended to clean up after we deploy.");
}
try {
yield CommonUtilities.runAzCommand(`az group delete --name ${this.resourceGroupName} --yes`, CommonUtilities.azCommandOutputs.string);
return this;
}
catch (err) {
if (err.toString().includes("stderr ERROR: Resource group 'mySQLSCUp' could not be found.")) {
// Group doesn't exist, which is fine
return this;
}
throw err;
}
});
}
getBaseDeployClassInstance() {
return this.promiseGate.promise.then(function (baseClass) {
return baseClass;
});
}
}
exports.ResourceGroupInfrastructure = ResourceGroupInfrastructure;
//# sourceMappingURL=resourcegroupInfrastructure.js.map