From 71b8575aac0f5d212b6538cb569872d93af14aec Mon Sep 17 00:00:00 2001 From: Bernd Hufmann Date: Thu, 2 Nov 2023 10:18:22 -0400 Subject: [PATCH] Add an endpoint for closing an experiment With this it's possible to close an experiment on the server. Upon reception of the command the server can dispose allocated resources hence the client doesn't need them anymore. This change follows the TSP update provided by: https://github.com/eclipse-cdt-cloud/trace-server-protocol/pull/95 Signed-off-by: Bernd Hufmann --- .../tsp-client/close-experiment-0.json | 19 +++++++++++++++++++ .../src/protocol/http-tsp-client.ts | 12 ++++++++++++ .../src/protocol/tsp-client.test.ts | 8 ++++++++ .../src/protocol/tsp-client.ts | 9 +++++++++ 4 files changed, 48 insertions(+) create mode 100644 tsp-typescript-client/fixtures/tsp-client/close-experiment-0.json diff --git a/tsp-typescript-client/fixtures/tsp-client/close-experiment-0.json b/tsp-typescript-client/fixtures/tsp-client/close-experiment-0.json new file mode 100644 index 0000000..087f624 --- /dev/null +++ b/tsp-typescript-client/fixtures/tsp-client/close-experiment-0.json @@ -0,0 +1,19 @@ +{ + "name": "kernel", + "UUID": "22222222-2222-2222-2222-222222222222", + "nbEvents": 0, + "start": 0, + "end": 0, + "indexingStatus": "CLOSED", + "traces": [ + { + "name": "kernel", + "path": "/path/kernel", + "UUID": "11111111-1111-1111-1111-111111111111", + "nbEvents": 0, + "start": 0, + "end": 0, + "indexingStatus": "CLOSED" + } + ] +} diff --git a/tsp-typescript-client/src/protocol/http-tsp-client.ts b/tsp-typescript-client/src/protocol/http-tsp-client.ts index 3233432..5d32760 100644 --- a/tsp-typescript-client/src/protocol/http-tsp-client.ts +++ b/tsp-typescript-client/src/protocol/http-tsp-client.ts @@ -142,6 +142,18 @@ export class HttpTspClient implements ITspClient { return RestClient.put(url, parameters, Experiment); } + /** + * Close an experiment + * @param expUUID Experiment UUID to close + * @returns The closed experiment + */ + closeExperiment( + expUUID: string + ): Promise> { + const url = this.baseUrl + "/experiments/" + expUUID + ":close"; + return RestClient.put(url, new Query({}), Experiment); + } + /** * Delete an experiment on the server * @param expUUID Experiment UUID to delete diff --git a/tsp-typescript-client/src/protocol/tsp-client.test.ts b/tsp-typescript-client/src/protocol/tsp-client.test.ts index 78dec89..5992192 100644 --- a/tsp-typescript-client/src/protocol/tsp-client.test.ts +++ b/tsp-typescript-client/src/protocol/tsp-client.test.ts @@ -108,6 +108,14 @@ describe('HttpTspClient Deserialization', () => { expect(typeof experiment.nbEvents).toEqual('number'); }); + it('deleteExperiment', async () => { + httpRequestMock.mockReturnValueOnce(fixtures.asResponse('close-experiment-0.json')); + const response = await client.closeExperiment('not-relevant'); + const experiment = response.getModel()!; + + expect(experiment.indexingStatus).toEqual('CLOSED'); + }); + it('deleteTrace', async () => { httpRequestMock.mockReturnValueOnce(fixtures.asResponse('delete-trace-0.json')); const response = await client.deleteTrace('not-relevant'); diff --git a/tsp-typescript-client/src/protocol/tsp-client.ts b/tsp-typescript-client/src/protocol/tsp-client.ts index e35900f..0e818d7 100644 --- a/tsp-typescript-client/src/protocol/tsp-client.ts +++ b/tsp-typescript-client/src/protocol/tsp-client.ts @@ -94,6 +94,15 @@ export interface ITspClient { parameters: Query ): Promise>; + /** + * Close an experiment + * @param expUUID Experiment UUID to close + * @returns The closed experiment + */ + closeExperiment( + expUUID: string + ): Promise>; + /** * Delete an experiment on the server * @param expUUID Experiment UUID to delete