Skip to content

Commit a5128df

Browse files
committed
Add support for configuration service end-points
This adds APIs to the tsp-client to use the end-points newly defined in TSP: - eclipse-cdt-cloud/trace-server-protocol#93 - eclipse-cdt-cloud/trace-server-protocol#92 Signed-off-by: Bernd Hufmann <[email protected]>
1 parent 5c2d465 commit a5128df

File tree

8 files changed

+390
-15
lines changed

8 files changed

+390
-15
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"id": "my-config-1-id",
3+
"name": "My configuration 1",
4+
"description": "My configuration 1 description",
5+
"sourceTypeId": "my-source-type-1-id",
6+
"parameters": {
7+
"path": "/home/user/tmp"
8+
}
9+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[
2+
{
3+
"id": "my-source-type-1-id",
4+
"name": "My configuration source 1",
5+
"description": "My configuration source 1 description",
6+
"configParamDescriptors": [
7+
{
8+
"keyName": "path",
9+
"description": "path description",
10+
"dataType": "STRING",
11+
"isRequired": "True"
12+
},
13+
{
14+
"keyName": "test1"
15+
}
16+
]
17+
}
18+
]
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[
2+
{
3+
"id": "my-config-1-id",
4+
"name": "My configuration 1",
5+
"description": "My configuration 1 description",
6+
"sourceTypeId": "my-source-type-1-id",
7+
"parameters": {
8+
"path": "/home/user/tmp"
9+
}
10+
},
11+
{
12+
"id": "my-config-2-id",
13+
"name": "My configuration 2",
14+
"sourceTypeId": "my-source-type-1-id"
15+
}
16+
]
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
2+
/**
3+
* Model of a configuration source type
4+
*/
5+
export interface ConfigurationSourceType {
6+
/**
7+
* Unique identifier of the configuration source type
8+
*/
9+
id: string;
10+
11+
/**
12+
* The name of the configuration source type
13+
*/
14+
name: string;
15+
16+
/**
17+
* A short description of this configuration source type.
18+
*/
19+
description?: string;
20+
21+
/**
22+
* A list of query parameter keys to be passed when creating
23+
* configuration instance of this type
24+
*/
25+
configParamDescriptors: ConfigParamDescriptor[];
26+
}
27+
28+
/**
29+
* Model of a configuration parameter descriptor
30+
*/
31+
export interface ConfigParamDescriptor {
32+
/**
33+
* The unique name of the key
34+
*/
35+
keyName: string;
36+
37+
/**
38+
* A short description.
39+
*/
40+
description?: string;
41+
42+
/**
43+
* The data type string, e.g. use NUMBER for numbers, or STRING as strings
44+
*/
45+
dataType?: string;
46+
47+
/**
48+
* If parameter needs to in the query parameters or not. Default is false.
49+
*/
50+
isRequired?: boolean;
51+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
2+
/**
3+
* Model of a configuration instance
4+
*/
5+
export interface Configuration {
6+
/**
7+
* Unique identifier of the configuration
8+
*/
9+
id: string;
10+
11+
/**
12+
* The name of the configuration
13+
*/
14+
name: string;
15+
16+
/**
17+
* A short description of this configuration
18+
*/
19+
description?: string;
20+
21+
/**
22+
* the configuration source type ID
23+
*/
24+
sourceTypeId: string;
25+
26+
/**
27+
* Optional informational map of parameters to return.
28+
* Can be used to show more details to users of the configuration instance.
29+
*/
30+
parameters?: Record<string, any>;
31+
}
32+
33+
/**
34+
* Model of a configuration parameter descriptor
35+
*/
36+
export interface ConfigParamDescriptor {
37+
/**
38+
* The unique name of the key
39+
*/
40+
keyName: string;
41+
42+
/**
43+
* A short description.
44+
*/
45+
description?: string;
46+
47+
/**
48+
* The data type string, e.g. use NUMBER for numbers, or STRING as strings
49+
*/
50+
dataType?: string;
51+
52+
/**
53+
* If parameter needs to in the query parameters or not. Default is false.
54+
*/
55+
isRequired?: boolean;
56+
}

tsp-typescript-client/src/protocol/http-tsp-client.ts

Lines changed: 91 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,30 @@
1+
import {
2+
AnnotationCategoriesModel,
3+
AnnotationModel,
4+
} from "../models/annotation";
5+
import { Configuration } from "../models/configuration";
6+
import { ConfigurationSourceType } from "../models/configuration-source";
7+
import { DataTreeEntry } from "../models/data-tree";
8+
import { Entry, EntryModel } from "../models/entry";
9+
import { Experiment } from "../models/experiment";
10+
import { HealthStatus } from "../models/health";
11+
import { MarkerSet } from "../models/markerset";
12+
import { OutputDescriptor } from "../models/output-descriptor";
113
import { Query } from "../models/query/query";
214
import { GenericResponse } from "../models/response/responses";
3-
import { XyEntry, XYModel } from "../models/xy";
15+
import { OutputStyleModel } from "../models/styles";
16+
import { ColumnHeaderEntry, TableModel } from "../models/table";
417
import {
5-
TimeGraphEntry,
618
TimeGraphArrow,
19+
TimeGraphEntry,
720
TimeGraphModel,
821
} from "../models/timegraph";
9-
import {
10-
AnnotationCategoriesModel,
11-
AnnotationModel,
12-
} from "../models/annotation";
13-
import { TableModel, ColumnHeaderEntry } from "../models/table";
1422
import { Trace } from "../models/trace";
23+
import { XYModel, XyEntry } from "../models/xy";
1524
import { RestClient } from "./rest-client";
16-
import { Experiment } from "../models/experiment";
17-
import { OutputDescriptor } from "../models/output-descriptor";
18-
import { EntryModel, Entry } from "../models/entry";
19-
import { TspClientResponse } from "./tsp-client-response";
20-
import { OutputStyleModel } from "../models/styles";
21-
import { HealthStatus } from "../models/health";
22-
import { MarkerSet } from "../models/markerset";
2325
import { array } from "./serialization";
24-
import { DataTreeEntry } from "../models/data-tree";
2526
import { ITspClient } from "./tsp-client";
27+
import { TspClientResponse } from "./tsp-client-response";
2628

2729
/**
2830
* Http request implementation, using the RestClient helper, of the Trace Server Protocol client
@@ -516,4 +518,78 @@ export class HttpTspClient implements ITspClient {
516518
const url = this.baseUrl + "/health";
517519
return RestClient.get(url);
518520
}
521+
522+
/**
523+
* Fetch all configuration source types
524+
* @returns Generic response with the model
525+
*/
526+
fetchConfigurationSourceTypes(): Promise<TspClientResponse<ConfigurationSourceType[]>> {
527+
const url = this.baseUrl + "/config/types";
528+
return RestClient.get(url);
529+
}
530+
531+
/**
532+
* Fetch configuration source type for a given type ID
533+
* @param typeId the ID of the configuration source type
534+
* @returns Generic response with the model
535+
*/
536+
fetchConfigurationSourceType(typeId: string): Promise<TspClientResponse<ConfigurationSourceType>> {
537+
const url = this.baseUrl + "/config/types/" + typeId;
538+
return RestClient.get(url);
539+
}
540+
541+
/**
542+
* Fetch all configurations for a given type ID
543+
* @param typeId the ID of the configuration source type
544+
* @returns Generic response with the model
545+
*/
546+
fetchConfigurations(typeId: string): Promise<TspClientResponse<Configuration[]>> {
547+
const url = this.baseUrl + "/config/types/" + typeId + "/configs";
548+
return RestClient.get(url);
549+
}
550+
551+
/**
552+
* Fetch a configuration by ID for a given type ID
553+
* @param typeId the ID of the configuration source type
554+
* @param configId the ID of the configuration
555+
* @returns Generic response with the model
556+
*/
557+
fetchConfiguration(typeId: string, configId: string): Promise<TspClientResponse<Configuration>> {
558+
const url = this.baseUrl + "/config/types/" + typeId + "/configs/" + configId;
559+
return RestClient.get(url);
560+
}
561+
562+
/**
563+
* Create a configuration for a given type ID and parameters
564+
* @param typeId the ID of the configuration source type
565+
* @param parameters Query object
566+
* @returns Generic response with the model
567+
*/
568+
createConfiguration(typeId: string, parameters: Query): Promise<TspClientResponse<Configuration>> {
569+
const url = this.baseUrl + "/config/types/" + typeId;
570+
return RestClient.post(url, parameters);
571+
}
572+
573+
/**
574+
* Update a configuration for a given type ID, config ID and parameters
575+
* @param typeId the ID of the configuration source type
576+
* @param configId the ID of the configuration
577+
* @param parameters Query object
578+
* @returns Generic response with the model
579+
*/
580+
updateConfiguration(typeId: string, configId: string, parameters: Query): Promise<TspClientResponse<Configuration>> {
581+
const url = this.baseUrl + "/config/types/" + typeId + "/configs/" + configId;
582+
return RestClient.put(url, parameters);
583+
}
584+
585+
/**
586+
* Delete a configuration for a given type ID and config ID
587+
* @param typeId the ID of the configuration source type
588+
* @param configId the ID of the configuration
589+
* @returns Generic response with the model
590+
*/
591+
deleteConfiguration(typeId: string, configId: string): Promise<TspClientResponse<Configuration>> {
592+
const url = this.baseUrl + "/config/types/" + typeId + "/configs/" + configId;
593+
return RestClient.delete(url);
594+
}
519595
}

tsp-typescript-client/src/protocol/tsp-client.test.ts

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,4 +384,98 @@ describe('HttpTspClient Deserialization', () => {
384384
expect(typeof trace.nbEvents).toEqual('number');
385385
expect(typeof trace.start).toEqual('bigint');
386386
});
387+
388+
it('configurationSourceTypes', async () => {
389+
httpRequestMock.mockReturnValueOnce(fixtures.asResponse('fetch-configuration-sources-0.json'));
390+
const response = await client.fetchConfigurationSourceTypes();
391+
const sourceTypes = response.getModel()!;
392+
393+
expect(sourceTypes).toHaveLength(1);
394+
expect(sourceTypes[0].name).toEqual('My configuration source 1');
395+
expect(sourceTypes[0].description).toEqual('My configuration source 1 description');
396+
expect(sourceTypes[0].id).toEqual('my-source-type-1-id');
397+
expect(sourceTypes[0].configParamDescriptors).toHaveLength(2);
398+
399+
expect(sourceTypes[0].configParamDescriptors[0].keyName).toEqual('path');
400+
expect(sourceTypes[0].configParamDescriptors[0].description).toEqual('path description');
401+
expect(sourceTypes[0].configParamDescriptors[0].dataType).toEqual('STRING');
402+
expect(sourceTypes[0].configParamDescriptors[0].isRequired).toBeTruthy();
403+
404+
expect(sourceTypes[0].configParamDescriptors[1].keyName).toEqual('test1');
405+
expect(sourceTypes[0].configParamDescriptors[1].description).toBeUndefined();
406+
expect(sourceTypes[0].configParamDescriptors[1].dataType).toBeUndefined();
407+
expect(sourceTypes[0].configParamDescriptors[1].isRequired).toBeUndefined();
408+
});
409+
410+
it('configurations', async () => {
411+
httpRequestMock.mockReturnValueOnce(fixtures.asResponse('fetch-configurations-0.json'));
412+
const response = await client.fetchConfigurations("my-config-1-id");
413+
const configs = response.getModel()!;
414+
415+
expect(configs).toHaveLength(2);
416+
expect(configs[0].name).toEqual('My configuration 1');
417+
expect(configs[0].description).toEqual('My configuration 1 description');
418+
expect(configs[0].id).toEqual('my-config-1-id');
419+
expect(configs[0].parameters).toBeDefined();
420+
expect(configs[0].parameters?.path).toBeDefined();
421+
expect(configs[0].parameters?.path).toEqual('/home/user/tmp');
422+
423+
expect(configs[1].name).toEqual('My configuration 2');
424+
expect(configs[1].description).toBeUndefined()
425+
expect(configs[1].id).toEqual('my-config-2-id');
426+
expect(configs[1].parameters).toBeUndefined();
427+
});
428+
429+
it('configuration', async () => {
430+
httpRequestMock.mockReturnValueOnce(fixtures.asResponse('configuration-0.json'));
431+
const response = await client.fetchConfiguration("my-source-type-1-id", "my-config-1-id");
432+
const config = response.getModel()!;
433+
434+
expect(config.name).toEqual('My configuration 1');
435+
expect(config.description).toEqual('My configuration 1 description');
436+
expect(config.id).toEqual('my-config-1-id');
437+
expect(config.parameters).toBeDefined();
438+
expect(config.parameters?.path).toBeDefined();
439+
expect(config.parameters?.path).toEqual('/home/user/tmp');
440+
});
441+
442+
it('createConfiguration', async () => {
443+
httpRequestMock.mockReturnValueOnce(fixtures.asResponse('configuration-0.json'));
444+
const response = await client.createConfiguration("my-source-type-1-id", new Query({}));
445+
const config = response.getModel()!;
446+
447+
expect(config.name).toEqual('My configuration 1');
448+
expect(config.description).toEqual('My configuration 1 description');
449+
expect(config.id).toEqual('my-config-1-id');
450+
expect(config.parameters).toBeDefined();
451+
expect(config.parameters?.path).toBeDefined();
452+
expect(config.parameters?.path).toEqual('/home/user/tmp');
453+
});
454+
455+
it('updateConfiguration', async () => {
456+
httpRequestMock.mockReturnValueOnce(fixtures.asResponse('configuration-0.json'));
457+
const response = await client.updateConfiguration("my-source-type-1-id", "my-config-1-id", new Query({}));
458+
const config = response.getModel()!;
459+
460+
expect(config.name).toEqual('My configuration 1');
461+
expect(config.description).toEqual('My configuration 1 description');
462+
expect(config.id).toEqual('my-config-1-id');
463+
expect(config.parameters).toBeDefined();
464+
expect(config.parameters?.path).toBeDefined();
465+
expect(config.parameters?.path).toEqual('/home/user/tmp');
466+
});
467+
468+
it('deleteConfiguration', async () => {
469+
httpRequestMock.mockReturnValueOnce(fixtures.asResponse('configuration-0.json'));
470+
const response = await client.deleteConfiguration("my-source-type-1-id", "my-config-1-id");
471+
const config = response.getModel()!;
472+
473+
expect(config.name).toEqual('My configuration 1');
474+
expect(config.description).toEqual('My configuration 1 description');
475+
expect(config.id).toEqual('my-config-1-id');
476+
expect(config.parameters).toBeDefined();
477+
expect(config.parameters?.path).toBeDefined();
478+
expect(config.parameters?.path).toEqual('/home/user/tmp');
479+
});
480+
387481
});

0 commit comments

Comments
 (0)