From 1d494f62234774100493b67ae87e8ed4d578cff4 Mon Sep 17 00:00:00 2001 From: Thomas Mauran Date: Wed, 5 Feb 2025 09:23:43 +0100 Subject: [PATCH 1/5] feat: collection getSettings --- .../collection/get-settings/index.md | 80 +++++++++++++++++++ lib/api/controllers/collectionController.js | 20 +++++ lib/api/httpRoutes.js | 6 ++ .../controllers/collectionController.test.js | 36 +++++++++ 4 files changed, 142 insertions(+) create mode 100644 doc/2/api/controllers/collection/get-settings/index.md diff --git a/doc/2/api/controllers/collection/get-settings/index.md b/doc/2/api/controllers/collection/get-settings/index.md new file mode 100644 index 0000000000..46e4497db2 --- /dev/null +++ b/doc/2/api/controllers/collection/get-settings/index.md @@ -0,0 +1,80 @@ +--- +code: true +type: page +title: getSettings | API | Core +--- + +# getSettings + +Returns a collection settings. + +--- + +## Query Syntax + +### HTTP + +```http +URL: http://kuzzle:7512///_settings +Method: GET +``` + +### Other protocols + +```js +{ + "index": "", + "collection": "", + "controller": "collection", + "action": "getSettings", +} +``` + +--- + +## Arguments + +- `collection`: collection name +- `index`: index name + +--- + +## Response + +Returns a setting object with the following structure: + +```js +{ + "status": 200, + "error": null, + "action": "getSettings", + "controller": "collection", + "collection": "", + "index": "", + "headers": {}, + "result": { + "routing": { + "allocation": { + "include": { + "_tier_preference": "data_content" + } + } + }, + "number_of_shards": "1", + "provided_name": "&platform.config", + "creation_date": "1738682329397", + "number_of_replicas": "1", + "uuid": "aY0IBbKJSvuIrwqqYyKkUw", + "version": { + "created": "7160299" + } + }, +} +``` + +--- + +## Possible errors + +- [Common errors](/core/2/api/errors/types#common-errors) +- [NotFoundError](/core/2/api/errors/types#notfounderror) diff --git a/lib/api/controllers/collectionController.js b/lib/api/controllers/collectionController.js index 9b432f931e..206088c340 100644 --- a/lib/api/controllers/collectionController.js +++ b/lib/api/controllers/collectionController.js @@ -36,6 +36,7 @@ class CollectionController extends NativeController { "deleteSpecifications", "exists", "getMapping", + "getSettings", "getSpecifications", "list", "refresh", @@ -97,6 +98,25 @@ class CollectionController extends NativeController { return this._filterMappingResponse(mapping); } + /** + * Get the collection settings + * + * @param {Request} request + * @returns {Promise.} + */ + async getSettings(request) { + const { index, collection } = request.getIndexAndCollection(); + + const settings = await this.ask( + "core:storage:public:collection:settings:get", + index, + collection, + {} + ); + + return settings; + } + /** * Get the collection validation specifications * diff --git a/lib/api/httpRoutes.js b/lib/api/httpRoutes.js index 420b29c4dd..43a6a10aae 100644 --- a/lib/api/httpRoutes.js +++ b/lib/api/httpRoutes.js @@ -140,6 +140,12 @@ const routes = [ controller: "collection", action: "getMapping", }, + { + verb: "get", + path: "/:index/:collection/_settings", + controller: "collection", + action: "getSettings", + }, { verb: "get", path: "/:index/:collection/_search", diff --git a/test/api/controllers/collectionController.test.js b/test/api/controllers/collectionController.test.js index 31fdb912d5..083168386d 100644 --- a/test/api/controllers/collectionController.test.js +++ b/test/api/controllers/collectionController.test.js @@ -125,6 +125,42 @@ describe("Test: collection controller", () => { }); }); + describe("#getSettings", () => { + it("should trigger the proper methods and return a valid response", async () => { + kuzzle.ask + .withArgs("core:storage:public:collection:settings:get") + .resolves({ + _source: { + some: "settings", + }, + }); + + const response = await collectionController.getSettings(request); + + should(kuzzle.ask).be.calledWithMatch( + "core:storage:public:collection:settings:get", + kuzzle.internalIndex.index, + "settings", + `${index}#${collection}`, + ); + + should(response).match({ + some: "settings", + }); + }); + + it("should give a meaningful message if there is no specifications", () => { + kuzzle.ask + .withArgs("core:storage:public:collection:settings:get") + .rejects(new NotFoundError("not found")); + + return should(collectionController.getSettings(request)).be.rejectedWith( + NotFoundError, + { id: "settings.not_found" } + ); + }); + }); + describe("#truncate", () => { it("should trigger the proper methods and return a valid response", async () => { const response = await collectionController.truncate(request); From 4be9136ad0b6ab469364d24d9ea660d31a790d09 Mon Sep 17 00:00:00 2001 From: Thomas Mauran Date: Wed, 5 Feb 2025 10:01:29 +0100 Subject: [PATCH 2/5] chore: lint --- lib/api/controllers/collectionController.js | 2 +- test/api/controllers/collectionController.test.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/api/controllers/collectionController.js b/lib/api/controllers/collectionController.js index 206088c340..15f87ae762 100644 --- a/lib/api/controllers/collectionController.js +++ b/lib/api/controllers/collectionController.js @@ -111,7 +111,7 @@ class CollectionController extends NativeController { "core:storage:public:collection:settings:get", index, collection, - {} + {}, ); return settings; diff --git a/test/api/controllers/collectionController.test.js b/test/api/controllers/collectionController.test.js index 083168386d..07e307cad5 100644 --- a/test/api/controllers/collectionController.test.js +++ b/test/api/controllers/collectionController.test.js @@ -156,7 +156,7 @@ describe("Test: collection controller", () => { return should(collectionController.getSettings(request)).be.rejectedWith( NotFoundError, - { id: "settings.not_found" } + { id: "settings.not_found" }, ); }); }); From 2a9bbbe2d2d2493d7b1d847cbfd0a27d962430a0 Mon Sep 17 00:00:00 2001 From: Thomas Mauran Date: Wed, 5 Feb 2025 14:50:40 +0100 Subject: [PATCH 3/5] test: fix the test --- features/CollectionController.feature | 13 +++++++ .../controllers/collectionController.test.js | 37 ------------------- 2 files changed, 13 insertions(+), 37 deletions(-) diff --git a/features/CollectionController.feature b/features/CollectionController.feature index 92cc8e1aa1..0982e4c621 100644 --- a/features/CollectionController.feature +++ b/features/CollectionController.feature @@ -69,6 +69,19 @@ Feature: Collection Controller | createdAt | { "type": "date" } | | updatedAt | { "type": "date" } | + + # collection:getSettings ===================================================== + + Scenario: Get collection settings + Given an index "nyc-open-data" + And I "create" the collection "nyc-open-data":"green-taxi" with: + | mappings | { "dynamic": "strict", "properties": { "name": { "type": "keyword" } } } | + When I successfully execute the action "collection":"getSettings" with args: + | index | "nyc-open-data" | + | collection | "green-taxi" | + Then I should receive a result matching: + | number_of_shards | "1" | + # collection:delete ========================================================== Scenario: Delete a collection diff --git a/test/api/controllers/collectionController.test.js b/test/api/controllers/collectionController.test.js index 07e307cad5..a15bb6dbf7 100644 --- a/test/api/controllers/collectionController.test.js +++ b/test/api/controllers/collectionController.test.js @@ -125,42 +125,6 @@ describe("Test: collection controller", () => { }); }); - describe("#getSettings", () => { - it("should trigger the proper methods and return a valid response", async () => { - kuzzle.ask - .withArgs("core:storage:public:collection:settings:get") - .resolves({ - _source: { - some: "settings", - }, - }); - - const response = await collectionController.getSettings(request); - - should(kuzzle.ask).be.calledWithMatch( - "core:storage:public:collection:settings:get", - kuzzle.internalIndex.index, - "settings", - `${index}#${collection}`, - ); - - should(response).match({ - some: "settings", - }); - }); - - it("should give a meaningful message if there is no specifications", () => { - kuzzle.ask - .withArgs("core:storage:public:collection:settings:get") - .rejects(new NotFoundError("not found")); - - return should(collectionController.getSettings(request)).be.rejectedWith( - NotFoundError, - { id: "settings.not_found" }, - ); - }); - }); - describe("#truncate", () => { it("should trigger the proper methods and return a valid response", async () => { const response = await collectionController.truncate(request); @@ -687,7 +651,6 @@ describe("Test: collection controller", () => { index, collection, ); - should(response).be.instanceof(Object); should(response).match({ acknowledged: true, From 61c72d4ad81856401adbe4611ede636d95389c13 Mon Sep 17 00:00:00 2001 From: Eric <31733541+etrousset@users.noreply.github.com> Date: Thu, 13 Feb 2025 09:21:53 +0100 Subject: [PATCH 4/5] Update doc/2/api/controllers/collection/get-settings/index.md --- doc/2/api/controllers/collection/get-settings/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/2/api/controllers/collection/get-settings/index.md b/doc/2/api/controllers/collection/get-settings/index.md index 46e4497db2..7ff515f6f1 100644 --- a/doc/2/api/controllers/collection/get-settings/index.md +++ b/doc/2/api/controllers/collection/get-settings/index.md @@ -6,7 +6,7 @@ title: getSettings | API | Core # getSettings -Returns a collection settings. +Retrieves the Elasticsearch index settings for the specified Kuzzle collection. --- From efa64f813bf967d686ba1dc8794f94f08da74d5f Mon Sep 17 00:00:00 2001 From: Thomas Mauran Date: Thu, 13 Feb 2025 09:39:12 +0100 Subject: [PATCH 5/5] fix: getSettings redundant code --- lib/api/controllers/collectionController.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/api/controllers/collectionController.js b/lib/api/controllers/collectionController.js index 15f87ae762..b8c7335af7 100644 --- a/lib/api/controllers/collectionController.js +++ b/lib/api/controllers/collectionController.js @@ -107,14 +107,12 @@ class CollectionController extends NativeController { async getSettings(request) { const { index, collection } = request.getIndexAndCollection(); - const settings = await this.ask( + return this.ask( "core:storage:public:collection:settings:get", index, collection, {}, ); - - return settings; } /**