Call orchestration.

This commit is contained in:
Rodrigo Rodriguez (pragmatismo.io) 2018-10-15 21:03:17 -03:00
parent a7142c5cfe
commit 533787372f
2 changed files with 68 additions and 51 deletions

View file

@ -33,7 +33,6 @@
"use strict"; "use strict";
import { GBService, IGBInstance } from "botlib"; import { GBService, IGBInstance } from "botlib";
const msRestAzure = require("ms-rest-azure");
import { import {
ResourceManagementClient, ResourceManagementClient,
SubscriptionClient SubscriptionClient
@ -46,8 +45,10 @@ import { SearchManagementClient } from "azure-arm-search";
import { WebResource, ServiceClient } from "ms-rest-js"; import { WebResource, ServiceClient } from "ms-rest-js";
import * as simplegit from "simple-git/promise"; import * as simplegit from "simple-git/promise";
import { AppServicePlan } from "azure-arm-website/lib/models"; import { AppServicePlan } from "azure-arm-website/lib/models";
import { GBConfigService } from "deploy/core.gbapp/services/GBConfigService"; import { GBConfigService } from "../../../deploy/core.gbapp/services/GBConfigService";
const scanf = require("scanf"); const scanf = require("scanf");
const msRestAzure = require("ms-rest-azure");
const git = simplegit(); const git = simplegit();
const logger = require("../../../src/logger"); const logger = require("../../../src/logger");
const UrlJoin = require("url-join"); const UrlJoin = require("url-join");
@ -55,6 +56,11 @@ const PasswordGenerator = require("strict-password-generator").default;
const iconUrl = const iconUrl =
"https://github.com/pragmatismo-io/BotServer/blob/master/docs/images/generalbots-logo-squared.png"; "https://github.com/pragmatismo-io/BotServer/blob/master/docs/images/generalbots-logo-squared.png";
class x implements IGBInstance {
};
export class AzureDeployerService extends GBService { export class AzureDeployerService extends GBService {
instance: IGBInstance; instance: IGBInstance;
@ -85,7 +91,7 @@ export class AzureDeployerService extends GBService {
); );
this.searchClient = new SearchManagementClient(credentials, subscriptionId); this.searchClient = new SearchManagementClient(credentials, subscriptionId);
this.accessToken = credentials.tokenCache._entries[0].accessToken; this.accessToken = credentials.tokenCache._entries[0].accessToken;
this.location= location; this.location = location;
} }
public static async getSubscriptions(credentials) { public static async getSubscriptions(credentials) {
@ -97,12 +103,19 @@ export class AzureDeployerService extends GBService {
name: string, name: string,
location: string location: string
): Promise<IGBInstance> { ): Promise<IGBInstance> {
let instance = new IGBInstance();
logger.info(`Creating Deploy...`); let instance:any = {};
await this.createDeploy(name, location);
logger.info(`Creating Server...`); logger.info(`Starting infrastructure deployment...`);
// TODO: REMOVE THIS*********
//await this.dangerouslyDeleteDeploy(name);
logger.info(`Deploying Deploy Group...`);
await this.createDeployGroup(name, location);
logger.info(`Deploying Bot Server...`);
let serverFarm = await this.createHostingPlan( let serverFarm = await this.createHostingPlan(
name, name,
`${name}-server-plan`, `${name}-server-plan`,
@ -113,11 +126,11 @@ export class AzureDeployerService extends GBService {
let administratorLogin = AzureDeployerService.getRndAdminAccount(); let administratorLogin = AzureDeployerService.getRndAdminAccount();
let administratorPassword = AzureDeployerService.getRndPassword(); let administratorPassword = AzureDeployerService.getRndPassword();
logger.info(`Creating Storage...`); logger.info(`Deploying Bot Storage ...`);
let storageServerName = `${name}-storage`; let storageServerName = `${name}-storage-server`;
await this.createStorageServer( await this.createStorageServer(
name, name,
`${storageServerName}-server`, storageServerName,
administratorLogin, administratorLogin,
administratorPassword, administratorPassword,
storageServerName, storageServerName,
@ -136,27 +149,29 @@ export class AzureDeployerService extends GBService {
instance.storageDialect = "mssql"; instance.storageDialect = "mssql";
instance.storageServerName = storageServerName; instance.storageServerName = storageServerName;
logger.info(`Creating Search...`); logger.info(`Deploying Search...`);
let search = await this.createSearch(name, `${name}-search`, location); let searchName = `${name}-search`;
instance.searchHost = "generalbots.search.windows.net"; let search = await this.createSearch(name,searchName , location);
let searchKeys = await this.searchClient.queryKeys.listBySearchService(name, searchName)
instance.searchHost = `${searchName}.search.windows.net`;
instance.searchIndex = "azuresql-index"; instance.searchIndex = "azuresql-index";
instance.searchIndexer = "azuresql-indexer"; instance.searchIndexer = "azuresql-indexer";
instance.searchKey = "0FF1CE27564C208555A22B6E278289813"; instance.searchKey = searchKeys[0];
logger.info(`Creating NLP...`); logger.info(`Deploying NLP...`);
let nlp = await this.createNLP(name, `${name}-nlp`, location); let nlp = await this.createNLP(name, `${name}-nlp`, location);
let keys = await this.cognitiveClient.accounts.listKeys(name, nlp.name); let keys = await this.cognitiveClient.accounts.listKeys(name, nlp.name);
instance.nlpEndpoint = nlp.endpoint; instance.nlpEndpoint = nlp.endpoint;
instance.nlpKey = keys.key1; instance.nlpKey = keys.key1;
instance.nlpAppId = "0ff1ceb4f-96a4-4bdb-b2d5-3ea462ddb773"; instance.nlpAppId = "0ff1ceb4f-96a4-4bdb-b2d5-3ea462ddb773";
logger.info(`Creating Speech...`); logger.info(`Deploying Speech...`);
let speech = await this.createSpeech(name, `${name}-speech`, location); let speech = await this.createSpeech(name, `${name}-speech`, location);
keys = await this.cognitiveClient.accounts.listKeys(name, speech.name); keys = await this.cognitiveClient.accounts.listKeys(name, speech.name);
instance.speechKeyEndpoint = speech.endpoint; instance.speechKeyEndpoint = speech.endpoint;
instance.speechKey = keys.key1; instance.speechKey = keys.key1;
logger.info(`Creating SpellChecker...`); logger.info(`Deploying SpellChecker...`);
let spellChecker = await this.createSpellChecker( let spellChecker = await this.createSpellChecker(
name, name,
`${name}-spellchecker`, `${name}-spellchecker`,
@ -169,7 +184,7 @@ export class AzureDeployerService extends GBService {
instance.spellCheckerKey = keys.key1; instance.spellCheckerKey = keys.key1;
instance.spellCheckerEndpoint = spellChecker.endpoint; instance.spellCheckerEndpoint = spellChecker.endpoint;
logger.info(`Creating Text Analytics...`); logger.info(`Deploying Text Analytics...`);
let textAnalytics = await this.createTextAnalytics( let textAnalytics = await this.createTextAnalytics(
name, name,
`${name}-textanalytics`, `${name}-textanalytics`,
@ -185,9 +200,15 @@ export class AzureDeployerService extends GBService {
return instance; return instance;
} }
public async deployBot(instance, name, endpoint, nlpAppId, nlpKey, subscriptionId) { public async deployBot(
instance,
logger.info(`Creating Bot...`); name,
endpoint,
nlpAppId,
nlpKey,
subscriptionId
) {
logger.info(`Deploying Bot...`);
await this.internalDeployBot( await this.internalDeployBot(
this.accessToken, this.accessToken,
name, name,
@ -402,7 +423,7 @@ export class AzureDeployerService extends GBService {
); );
} }
private async createDeploy(name, location) { private async createDeployGroup(name, location) {
var params = { location: location }; var params = { location: location };
return this.resourceClient.resourceGroups.createOrUpdate(name, params); return this.resourceClient.resourceGroups.createOrUpdate(name, params);
} }
@ -488,17 +509,16 @@ export class AzureDeployerService extends GBService {
} }
static async ensureDeployer() { static async ensureDeployer() {
// Tries do get information from .env file otherwise asks in command-line. // Tries do get information from .env file otherwise asks in command-line.
let username = GBConfigService.get("CLOUD_USERNAME"); let username = GBConfigService.get("CLOUD_USERNAME");
let password = GBConfigService.get("CLOUD_PASSWORD"); let password = GBConfigService.get("CLOUD_PASSWORD");
let subscriptionId = GBConfigService.get("CLOUD_SUBSCRIPTIONID"); let subscriptionId = GBConfigService.get("CLOUD_SUBSCRIPTIONID");
let cloudLocation = GBConfigService.get("CLOUD_LOCATION"); let location = GBConfigService.get("CLOUD_LOCATION");
// No .env so asks for cloud credentials to start a new farm. // No .env so asks for cloud credentials to start a new farm.
if (!username || !password || !subscriptionId || !cloudLocation) { if (!username || !password || !subscriptionId || !location) {
process.stdout.write( process.stdout.write(
"FIRST RUN: A empty enviroment is detected. Please, enter credentials to create a new General Bots Farm." "FIRST RUN: A empty enviroment is detected. Please, enter credentials to create a new General Bots Farm."
); );
@ -532,10 +552,11 @@ export class AzureDeployerService extends GBService {
username, username,
password password
); );
let list = await AzureDeployerService.getSubscriptions(credentials);
if (!subscriptionId) {
let map = {}; let map = {};
let index = 1; let index = 1;
let list = await AzureDeployerService.getSubscriptions(credentials);
list.forEach(element => { list.forEach(element => {
console.log( console.log(
`${index}: ${element.displayName} (${element.subscriptionId})` `${index}: ${element.displayName} (${element.subscriptionId})`
@ -550,14 +571,13 @@ export class AzureDeployerService extends GBService {
subscriptionIndex = scanf("%d"); subscriptionIndex = scanf("%d");
} }
}; };
if (!subscriptionId) {
while (!subscriptionIndex) { while (!subscriptionIndex) {
retrieveSubscription(); retrieveSubscription();
} }
subscriptionId = map[subscriptionIndex].subscriptionId; subscriptionId = map[subscriptionIndex].subscriptionId;
} }
let retriveLocation = () => { let retriveLocation = () => {
if (!location) { if (!location) {
process.stdout.write("CLOUD_LOCATION:"); process.stdout.write("CLOUD_LOCATION:");
@ -571,5 +591,4 @@ export class AzureDeployerService extends GBService {
return new AzureDeployerService(credentials, subscriptionId, location); return new AzureDeployerService(credentials, subscriptionId, location);
} }
} }

View file

@ -50,10 +50,10 @@ import { GBKBPackage } from "../deploy/kb.gbapp";
import { GBSecurityPackage } from "../deploy/security.gblib"; import { GBSecurityPackage } from "../deploy/security.gblib";
import { GBAdminPackage } from "../deploy/admin.gbapp/index"; import { GBAdminPackage } from "../deploy/admin.gbapp/index";
import { GBCustomerSatisfactionPackage } from "../deploy/customer-satisfaction.gbapp"; import { GBCustomerSatisfactionPackage } from "../deploy/customer-satisfaction.gbapp";
import { IGBPackage } from "botlib";
import { GBAdminService } from "../deploy/admin.gbapp/services/GBAdminService"; import { GBAdminService } from "../deploy/admin.gbapp/services/GBAdminService";
import { GuaribasInstance } from "../deploy/core.gbapp/models/GBModel"; import { GuaribasInstance } from "../deploy/core.gbapp/models/GBModel";
import { AzureDeployerService } from "../deploy/azuredeployer.gbapp/services/AzureDeployerService"; import { AzureDeployerService } from "../deploy/azuredeployer.gbapp/services/AzureDeployerService";
import { IGBPackage } from "botlib";
let appPackages = new Array<IGBPackage>(); let appPackages = new Array<IGBPackage>();
@ -97,11 +97,9 @@ export class GBServer {
// Ensures cloud / on-premises infrastructure is setup. // Ensures cloud / on-premises infrastructure is setup.
logger.info(`Connecting to the infrastructure...`);
let cloudDeployer = await AzureDeployerService.ensureDeployer(); let cloudDeployer = await AzureDeployerService.ensureDeployer();
let masterBotName = `${GBServer.MASTERBOT_PREFIX}-${Math.floor( let instance = await cloudDeployer.deployFarm('gbot', 'westus');
Math.random() * 1000000000
)}`;
cloudDeployer.deployFarm(masterBotName, 'westus');
// TODO: Get .gb* templates from GitHub and download do additional deploy folder. // TODO: Get .gb* templates from GitHub and download do additional deploy folder.