From ef42f5297318ee27ce5952b5b37620b64a9c67df Mon Sep 17 00:00:00 2001 From: Erik Merkle Date: Fri, 13 Oct 2023 15:20:16 -0500 Subject: [PATCH] Fix test, add missing OpenAPI doc generation --- management-api-server/doc/openapi.json | 87 ++++++++++++++++++- .../mgmtapi/K8OperatorResourcesTest.java | 15 ++++ 2 files changed, 101 insertions(+), 1 deletion(-) diff --git a/management-api-server/doc/openapi.json b/management-api-server/doc/openapi.json index ee4feccc..c0aaf0ef 100644 --- a/management-api-server/doc/openapi.json +++ b/management-api-server/doc/openapi.json @@ -1678,6 +1678,91 @@ "summary" : "Returns active compactions" } }, + "/api/v1/ops/tables/flush" : { + "post" : { + "operationId" : "flush_1", + "requestBody" : { + "content" : { + "application/json" : { + "schema" : { + "$ref" : "#/components/schemas/KeyspaceRequest" + } + } + } + }, + "responses" : { + "202" : { + "content" : { + "text/plain" : { + "example" : "d69d1d95-9348-4460-95d2-ae342870fade", + "schema" : { + "type" : "string" + } + } + }, + "description" : "Job ID for table flush process" + }, + "400" : { + "content" : { + "text/plain" : { + "example" : "keyspace sys-tem does not exists", + "schema" : { + "type" : "string" + } + } + }, + "description" : "Invalid flush request" + } + }, + "summary" : "Flush one or more tables" + } + }, + "/api/v1/ops/tables/garbagecollect" : { + "post" : { + "operationId" : "garbageCollect_1", + "parameters" : [ { + "in" : "query", + "name" : "tombstoneOption", + "schema" : { + "type" : "string" + } + } ], + "requestBody" : { + "content" : { + "application/json" : { + "schema" : { + "$ref" : "#/components/schemas/KeyspaceRequest" + } + } + } + }, + "responses" : { + "202" : { + "content" : { + "text/plain" : { + "example" : "d69d1d95-9348-4460-95d2-ae342870fade", + "schema" : { + "type" : "string" + } + } + }, + "description" : "Job ID for table garbage collection process" + }, + "400" : { + "content" : { + "text/plain" : { + "example" : "tombstoneOption must be either ROW or CELL", + "schema" : { + "type" : "string" + } + } + }, + "description" : "Invalid table garbage collection request" + } + }, + "summary" : "Remove deleted data from one or more tables" + } + }, "/api/v1/ops/tables/scrub" : { "post" : { "operationId" : "scrub_1", @@ -2034,7 +2119,7 @@ "type" : "array", "items" : { "type" : "string", - "enum" : [ "ASYNC_SSTABLE_TASKS", "FULL_QUERY_LOGGING", "REBUILD", "ASYNC_UPGRADE_SSTABLE_TASK", "ASYNC_COMPACTION_TASKS", "ASYNC_SCRUB_TASK", "ASYNC_MOVE_TASK" ] + "enum" : [ "ASYNC_SSTABLE_TASKS", "FULL_QUERY_LOGGING", "REBUILD", "ASYNC_UPGRADE_SSTABLE_TASK", "ASYNC_COMPACTION_TASKS", "ASYNC_SCRUB_TASK", "ASYNC_MOVE_TASK", "ASYNC_GC_TASK", "ASYNC_FLUSH_TASK" ] } }, "mgmt_version" : { diff --git a/management-api-server/src/test/java/com/datastax/mgmtapi/K8OperatorResourcesTest.java b/management-api-server/src/test/java/com/datastax/mgmtapi/K8OperatorResourcesTest.java index d5ca7d06..897e6fd6 100644 --- a/management-api-server/src/test/java/com/datastax/mgmtapi/K8OperatorResourcesTest.java +++ b/management-api-server/src/test/java/com/datastax/mgmtapi/K8OperatorResourcesTest.java @@ -1067,6 +1067,8 @@ public void testGarbageCollectAsync() throws Exception { when(mockResultSet.one()).thenReturn(mockRow); when(mockRow.getString(0)).thenReturn("0fe65b47-98c2-47d8-9c3c-5810c9988e10"); + setpMockGetKeyspaces(context, "keyspace"); + String requestAsJSON = WriterUtility.asString(keyspaceRequest, MediaType.APPLICATION_JSON); MockHttpResponse response = postWithBodyFullPath( @@ -1199,6 +1201,8 @@ public void testFlushAsync() throws Exception { when(mockResultSet.one()).thenReturn(mockRow); when(mockRow.getString(0)).thenReturn("0fe65b47-98c2-47d8-9c3c-5810c9988e10"); + setpMockGetKeyspaces(context, "keyspace"); + String requestAsJSON = WriterUtility.asString(keyspaceRequest, MediaType.APPLICATION_JSON); MockHttpResponse response = postWithBodyFullPath("/api/v1/ops/tables/flush", requestAsJSON, context); @@ -2222,4 +2226,15 @@ public void testMoveAsync_MissingNewToken() throws Exception { verify(context.cqlService, never()) .executePreparedStatement(any(), eq("CALL NodeOps.move(?, ?)"), eq("1234"), eq(true)); } + + private void setpMockGetKeyspaces(Context context, String keyspaceName) throws Exception { + ResultSet mockKeyspacesResultSet = mock(ResultSet.class); + Row mockKeyspacesRow = mock(Row.class); + + when(context.cqlService.executePreparedStatement(any(), eq("CALL NodeOps.getKeyspaces()"))) + .thenReturn(mockKeyspacesResultSet); + + when(mockKeyspacesResultSet.one()).thenReturn(mockKeyspacesRow); + when(mockKeyspacesRow.getList(0, String.class)).thenReturn(Arrays.asList(keyspaceName)); + } }