Skip to content
This repository was archived by the owner on Jan 15, 2025. It is now read-only.

Commit 58c9630

Browse files
authored
fix for bf orchestrator:add command (#1236)
* updated help text for routingName param * orchestrator:add fixes * Update datasourcehelper.ts don't override routingname from user * updated tests * added add source test
1 parent 07bbd05 commit 58c9630

File tree

5 files changed

+61
-12
lines changed

5 files changed

+61
-12
lines changed

packages/orchestrator/src/commands/orchestrator/add.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ export default class OrchestratorAdd extends Command {
1515
$ bf orchestrator:add --in ./path/to/file/ --snapshot ./path/to/snapshot/
1616
$ bf orchestrator:add --in ./path/to/file/ --snapshot ./path/to/snapshot/ --out ./path/to/output/
1717
$ bf orchestrator:add --in ./path/to/file/ --out ./path/to/output/ --model ./path/to/model/directory
18-
$ bf orchestrator:add -t luis --id LUIS_APP_ID --version LUIS_APP_VERSION --key LUIS_KEY --routingname l_Weather --endpoint
19-
$ bf orchestrator:add -t qna --id QNA_KB --key QNA_KB_SERVICE_KEY --routingname q_kb
18+
$ bf orchestrator:add -t luis --id LUIS_APP_ID --version LUIS_APP_VERSION --key LUIS_KEY --routingName l_Weather --endpoint
19+
$ bf orchestrator:add -t qna --id QNA_KB --key QNA_KB_SERVICE_KEY --routingName q_kb
2020
`]
2121

2222
static flags: flags.Input<any> = {
@@ -61,7 +61,7 @@ export default class OrchestratorAdd extends Command {
6161
if (type === 'luis' && Utility.isEmptyString(endpoint)) {
6262
throw new CLIError('LUIS endpoint required, ie --endpoint https://westus.api.cognitive.microsoft.com');
6363
}
64-
OrchestratorSettings.init(cwd, baseModelPath, entityBaseModelPath, output, true);
64+
OrchestratorSettings.init(cwd, baseModelPath, entityBaseModelPath, output, true, true);
6565
const dataSource: OrchestratorDataSource = new OrchestratorDataSource(id, key, version, endpoint, type, routingName, OrchestratorSettings.DataSources.path);
6666
await DataSourceHelper.ensureDataSourceAsync(dataSource, OrchestratorSettings.DataSources.path);
6767

packages/orchestratorlib/src/datasourcehelper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ export class DataSourceHelper {
128128
}
129129
input.FilePath = path.join(filePath, input.RoutingName + '.lu');
130130
} else if (input.Type === 'qna') {
131-
input.RoutingName = Utility.isEmptyString(input.RoutingName) ? `q_${input.Id}` : `q_${input.RoutingName}`;
131+
input.RoutingName = Utility.isEmptyString(input.RoutingName) ? `q_${input.Id}` : `${input.RoutingName}`;
132132
input.FilePath = path.join(filePath, input.RoutingName + '.qna');
133133
} else {
134134
throw new Error(`Invalid content for type ${input.Type}`);

packages/orchestratorlib/src/orchestratorhelper.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,24 @@ export class OrchestratorHelper {
249249
return entitiesList;
250250
}
251251

252+
public static jsonStringify(obj: any): string {
253+
return JSON.stringify(
254+
obj,
255+
(key: string, value: any) => {
256+
if (value && typeof value === 'object' && !Array.isArray(value)) {
257+
const replacement: any = {};
258+
for (const k in value) {
259+
if (Object.hasOwnProperty.call(value, k)) {
260+
replacement[k && k.charAt(0).toLowerCase() + k.substring(1)] = value[k];
261+
}
262+
}
263+
return replacement;
264+
}
265+
return value;
266+
},
267+
2);
268+
}
269+
252270
// eslint-disable-next-line max-params
253271
static async processFile(
254272
filePath: string,

packages/orchestratorlib/src/settings.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,8 @@ export class OrchestratorSettings {
157157
baseModelPath: string,
158158
entityBaseModelPath: string,
159159
snapshotPath: string,
160-
hierarchical: boolean = false) {
160+
hierarchical: boolean = false,
161+
hasDataSources: boolean = false) {
161162
settingsDir = path.resolve(settingsDir);
162163
const settingsFile: string = path.join(settingsDir, OrchestratorSettings.OrchestratorSettingsFileName);
163164
OrchestratorSettings.SettingsPath = settingsFile;
@@ -171,8 +172,13 @@ export class OrchestratorSettings {
171172
let settings: any;
172173
if (settingsFileExists) {
173174
settings = JSON.parse(OrchestratorSettings.readFile(settingsFile));
175+
if (settings.dataSources && settings.dataSources.inputs) {
176+
hasDataSources = true;
177+
}
178+
}
179+
if (hasDataSources) {
180+
OrchestratorSettings.ensureDataSources(hierarchical, settings, settingsDir);
174181
}
175-
OrchestratorSettings.ensureDataSources(hierarchical, settings, settingsDir);
176182
OrchestratorSettings.SnapshotPath = OrchestratorSettings.ensureSnapshotPath(snapshotPath, settingsDir, settings);
177183
OrchestratorSettings.ModelPath = OrchestratorSettings.ensureBaseModelPath(baseModelPath, settings);
178184
entityBaseModelPath = OrchestratorSettings.ensureEntityBaseModelPath(entityBaseModelPath, settings);
@@ -198,7 +204,7 @@ export class OrchestratorSettings {
198204
dataSources: OrchestratorSettings.DataSources,
199205
};
200206

201-
OrchestratorSettings.writeToFile(OrchestratorSettings.SettingsPath, Utility.jsonStringify(settings, null, 2));
207+
OrchestratorSettings.writeToFile(OrchestratorSettings.SettingsPath, OrchestratorHelper.jsonStringify(settings));
202208
} catch (error) {
203209
throw new Error(error);
204210
}

packages/orchestratorlib/test/settings.test.ts

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@ import assert = require('assert');
99
import * as path from 'path';
1010
import * as fs from 'fs-extra';
1111

12-
import {OrchestratorSettings} from '../src/settings';
12+
import {OrchestratorDataSource, OrchestratorSettings} from '../src/settings';
1313

1414
import {Utility} from '../src/utility';
15-
import {UnitTestHelper} from './utility.test';
1615

1716
describe('OrchestratorSettingsTests', () => {
1817
const SettingsDir: string = './test/fixtures/';
@@ -44,10 +43,15 @@ describe('OrchestratorSettingsTests', () => {
4443
assert.ok(OrchestratorSettings.SettingsPath === SettingsFile);
4544
assert.ok(OrchestratorSettings.ModelPath === BaseModelDir);
4645
assert.ok(OrchestratorSettings.EntityModelPath === '');
46+
assert.ok(!OrchestratorSettings.DataSources);
47+
});
4748

48-
Utility.resetFlagToPrintDebuggingLogToConsole(UnitTestHelper.getDefaultUnitTestDebuggingLogFlag());
49-
Utility.debuggingLog(`OrchestratorSettings.DataSources.Path=${OrchestratorSettings.DataSources.path}`);
50-
49+
it('init settings with no settings file + data source', () => {
50+
OrchestratorSettings.init(SettingsDir, BaseModelDir, '', SettingsDir, false, true);
51+
assert.ok(OrchestratorSettings.SettingsPath === SettingsFile);
52+
assert.ok(OrchestratorSettings.ModelPath === BaseModelDir);
53+
assert.ok(OrchestratorSettings.EntityModelPath === '');
54+
assert.ok(OrchestratorSettings.DataSources);
5155
assert.ok(OrchestratorSettings.DataSources.path === DataSourcesPath);
5256
assert.ok(OrchestratorSettings.DataSources.inputs.length === 0);
5357
assert.ok(OrchestratorSettings.DataSources.hierarchical === false);
@@ -114,6 +118,27 @@ describe('OrchestratorSettingsTests', () => {
114118
assert.ok(OrchestratorSettings.DataSources.inputs[0].Type === 'qna');
115119
assert.ok(OrchestratorSettings.DataSources.inputs[1].Type === 'luis');
116120
assert.ok(OrchestratorSettings.DataSources.hierarchical);
121+
122+
const dataSource: OrchestratorDataSource = new OrchestratorDataSource(
123+
'a5ee4d79-28e0-4757-a9f8-45ab64ee1f7e',
124+
'LUISKEY',
125+
'version',
126+
'https://westus.api.cognitive.microsoft.com',
127+
'luis',
128+
'l_HomeAutomation',
129+
OrchestratorSettings.DataSources.path);
130+
131+
OrchestratorSettings.addUpdateDataSource(dataSource);
132+
OrchestratorSettings.persist();
133+
OrchestratorSettings.init(SettingsDir, BaseModelDir, '', SettingsDir);
134+
assert.ok(OrchestratorSettings.DataSources.hierarchical);
135+
assert.ok(OrchestratorSettings.DataSources.inputs.length === 3);
136+
assert.ok(OrchestratorSettings.DataSources.inputs[0].Type === 'qna');
137+
assert.ok(OrchestratorSettings.DataSources.inputs[0].Id === '213a48d3-855d-4083-af6d-339c03d497dd');
138+
assert.ok(OrchestratorSettings.DataSources.inputs[1].Type === 'luis');
139+
assert.ok(OrchestratorSettings.DataSources.inputs[1].Id === 'd06d7acf-a9ec-43e0-94c6-3b37ee313a21');
140+
assert.ok(OrchestratorSettings.DataSources.inputs[2].Type === 'luis');
141+
assert.ok(OrchestratorSettings.DataSources.inputs[2].Id === 'a5ee4d79-28e0-4757-a9f8-45ab64ee1f7e');
117142
});
118143

119144
it('init settings with settings file', () => {

0 commit comments

Comments
 (0)