fix(all): TRUE multicloud.

This commit is contained in:
Rodrigo Rodriguez 2024-08-28 19:42:12 -03:00
parent c2bdbbe140
commit 21ed20dcf0
3 changed files with 72 additions and 73 deletions

View file

@ -291,7 +291,6 @@ export class GBVMService extends GBService {
} }
connections.forEach(async con => { connections.forEach(async con => {
const connectionName = con['name']; const connectionName = con['name'];
const dialect = con['storageDriver']; const dialect = con['storageDriver'];
@ -1124,7 +1123,7 @@ export class GBVMService extends GBService {
let result; let result;
try { try {
if (GBConfigService.get('GBVM') === 'false') { if (!GBConfigService.get('GBVM')) {
return await (async () => { return await (async () => {
return await new Promise((resolve, reject) => { return await new Promise((resolve, reject) => {
sandbox['resolve'] = resolve; sandbox['resolve'] = resolve;
@ -1145,6 +1144,7 @@ export class GBVMService extends GBService {
}); });
const s = new VMScript(code, { filename: scriptPath }); const s = new VMScript(code, { filename: scriptPath });
result = vm1.run(s); result = vm1.run(s);
}); });
})(); })();
} else { } else {
@ -1167,7 +1167,7 @@ export class GBVMService extends GBService {
cpu: 100, cpu: 100,
memory: 50000, memory: 50000,
time: 60 * 60 * 24 * 14, time: 60 * 60 * 24 * 14,
cwd: gbdialogPath, cwd: scriptPath,
script: runnerPath script: runnerPath
}); });

View file

@ -76,7 +76,7 @@ export class GBConfigService {
} }
} }
public static get(key: string): string | undefined { public static get(key: string) {
let value = GBConfigService.tryGet(key); let value = GBConfigService.tryGet(key);
if (!value) { if (!value) {
@ -84,6 +84,9 @@ export class GBConfigService {
case 'PORT': case 'PORT':
value = this.getServerPort(); value = this.getServerPort();
break; break;
case 'GBVM':
value = false;
break;
case 'STORAGE_NAME': case 'STORAGE_NAME':
value = null; value = null;
break; break;

View file

@ -314,8 +314,7 @@ export class GBDeployer implements IGBDeployer {
instance.marketplacePassword, instance.marketplacePassword,
subscriptionId subscriptionId
); );
}
}
// Saves final instance object and returns it. // Saves final instance object and returns it.
@ -422,53 +421,53 @@ export class GBDeployer implements IGBDeployer {
/** /**
* Loads all para from tabular file Config.xlsx. * Loads all para from tabular file Config.xlsx.
*/ */
public async loadParamsFromTabular(min: GBMinInstance, filePath: string): Promise<any> { public async loadParamsFromTabular(min: GBMinInstance, filePath: string): Promise<any> {
if (!Fs.existsSync(filePath)) { const xls = Path.join(filePath, 'Config.xlsx');
return []; const csv = Path.join(filePath, 'config.csv');
let rows: any[] = [];
let obj: any = {};
const workbook = new Excel.Workbook();
if (Fs.existsSync(xls)) {
await workbook.xlsx.readFile(xls);
let worksheet: any;
for (let t = 0; t < workbook.worksheets.length; t++) {
worksheet = workbook.worksheets[t];
if (worksheet) {
break;
}
} }
rows = worksheet.getSheetValues();
const ext = Path.extname(filePath).toLowerCase();
let rows: any[] = [];
const workbook = new Excel.Workbook();
if (ext === '.xlsx') {
await workbook.xlsx.readFile(filePath);
let worksheet: any;
for (let t = 0; t < workbook.worksheets.length; t++) {
worksheet = workbook.worksheets[t];
if (worksheet) {
break;
}
}
rows = worksheet.getSheetValues();
} else if (ext === '.csv') {
await workbook.csv.readFile(filePath);
let worksheet = workbook.worksheets[0]; // Assuming the CSV file has only one sheet
rows = worksheet.getSheetValues();
} else {
return [];
}
GBLogEx.info(min, `Processing ${rows.length} rows from Config file ${filePath}...`);
// Skips the header lines. // Skips the header lines.
for (let index = 0; index < 6; index++) { for (let index = 0; index < 6; index++) {
rows.shift(); rows.shift();
} }
} else if (Fs.existsSync(csv)) {
let obj: any = {}; await workbook.csv.readFile(filePath);
await asyncPromise.eachSeries(rows, async (line: any) => { let worksheet = workbook.worksheets[0]; // Assuming the CSV file has only one sheet
if (line && line._cells[0] && line._cells[1] && line._cells[0].text) { rows = worksheet.getSheetValues();
obj[line._cells[0].text] = line._cells[1].text;
} // Skips the header lines.
});
rows.shift();
GBLogEx.info(min, GBUtil.toYAML(obj)); } else {
return obj; return [];
}
await asyncPromise.eachSeries(rows, async (line: any) => {
if (line && line.length > 0) {
obj[line[1]] = line[2];
}
});
GBLogEx.info(min, `Processing ${rows.length} rows from ${filePath}...`);
rows = null;
return obj;
} }
/** /**
*/ */
public async downloadFolder( public async downloadFolder(
@ -624,39 +623,36 @@ export class GBDeployer implements IGBDeployer {
switch (packageType) { switch (packageType) {
case '.gbot': case '.gbot':
// Extracts configuration information from .gbot files. // Extracts configuration information from .gbot files.
min.instance.params = await this.loadParamsFromTabular(min, localPath); min.instance.params = await this.loadParamsFromTabular(min, localPath);
if (min.instance.params.length){ if (min.instance.params) {
let connections = [];
let connections = []; // Find all tokens in .gbot Config.
const strFind = ' Driver';
const conns = await min.core['findParam'](min.instance, strFind);
await CollectionUtil.asyncForEach(conns, async t => {
const connectionName = t.replace(strFind, '');
let con = {};
con['name'] = connectionName;
con['storageServer'] = min.core.getParam<string>(min.instance, `${connectionName} Server`, null);
con['storageUsername'] = min.core.getParam<string>(min.instance, `${connectionName} Username`, null);
con['storageName'] = min.core.getParam<string>(min.instance, `${connectionName} Name`, null);
con['storagePort'] = min.core.getParam<string>(min.instance, `${connectionName} Port`, null);
con['storagePassword'] = min.core.getParam<string>(min.instance, `${connectionName} Password`, null);
con['storageDriver'] = min.core.getParam<string>(min.instance, `${connectionName} Driver`, null);
connections.push(con);
});
// Find all tokens in .gbot Config. const path = DialogKeywords.getGBAIPath(min.botId, null);
const strFind = ' Driver'; const localFolder = Path.join('work', path, 'connections.json');
const conns = await min.core['findParam'](min.instance, strFind); Fs.writeFileSync(localFolder, JSON.stringify(connections), { encoding: null });
await CollectionUtil.asyncForEach(conns, async t => {
const connectionName = t.replace(strFind, '');
let con = {};
con['name'] = connectionName;
(con['storageServer'] = min.core.getParam<string>(min.instance, `${connectionName} Server`, null)),
(con['storageName'] = min.core.getParam<string>(min.instance, `${connectionName} Name`, null)),
(con['storageUsername'] = min.core.getParam<string>(min.instance, `${connectionName} Username`, null)),
(con['storagePort'] = min.core.getParam<string>(min.instance, `${connectionName} Port`, null)),
(con['storagePassword'] = min.core.getParam<string>(min.instance, `${connectionName} Password`, null)),
(con['storageDriver'] = min.core.getParam<string>(min.instance, `${connectionName} Driver`, null));
connections.push(con);
});
const path = DialogKeywords.getGBAIPath(min.botId, null); // Updates instance object.
const localFolder = Path.join('work', path, 'connections.json');
Fs.writeFileSync(localFolder, JSON.stringify(connections), { encoding: null });
// Updates instance object. await this.core.saveInstance(min.instance);
}
await this.core.saveInstance(min.instance);
}
break; break;
case '.gbkb': case '.gbkb':