Skip to content

Commit

Permalink
Add endpoints v2 endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
emerkle826 committed Jul 26, 2023
1 parent e8a223a commit 17e1eca
Show file tree
Hide file tree
Showing 23 changed files with 632 additions and 318 deletions.
2 changes: 1 addition & 1 deletion cassandra-trunk/Dockerfile.ubi8
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ COPY management-api-common /tmp/management-api-common
COPY management-api-server /tmp/management-api-server
RUN mkdir -m 775 ${MAAC_PATH} \
&& cd /tmp \
&& mvn -q -ff package -DskipTests -P trunk \
&& mvn -q -ff package -DskipTests -DskipOpenApi -P trunk \
&& find /tmp -type f -name "datastax-*.jar" -exec mv -t ${MAAC_PATH} -i '{}' + \
&& rm ${MAAC_PATH}/datastax-mgmtapi-agent-3* \
&& rm ${MAAC_PATH}/datastax-mgmtapi-agent-4.x* \
Expand Down
2 changes: 1 addition & 1 deletion dse-68/Dockerfile.jdk11
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ COPY management-api-common /tmp/management-api-common
COPY management-api-server /tmp/management-api-server
RUN mkdir -m 775 $MAAC_PATH \
&& cd /tmp \
&& mvn -q -ff package -DskipTests -P dse \
&& mvn -q -ff package -DskipTests -DskipOpenApi -P dse \
&& find /tmp -type f -name "datastax-*.jar" -exec mv -t $MAAC_PATH -i '{}' + \
&& rm $MAAC_PATH/datastax-mgmtapi-agent-3* \
&& rm $MAAC_PATH/datastax-mgmtapi-agent-4* \
Expand Down
2 changes: 1 addition & 1 deletion dse-68/Dockerfile.jdk8
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ COPY management-api-common /tmp/management-api-common
COPY management-api-server /tmp/management-api-server
RUN mkdir -m 775 $MAAC_PATH \
&& cd /tmp \
&& mvn -q -ff package -DskipTests -P dse \
&& mvn -q -ff package -DskipTests -DskipOpenApi -P dse \
&& find /tmp -type f -name "datastax-*.jar" -exec mv -t $MAAC_PATH -i '{}' + \
&& rm $MAAC_PATH/datastax-mgmtapi-agent-3* \
&& rm $MAAC_PATH/datastax-mgmtapi-agent-4* \
Expand Down
99 changes: 92 additions & 7 deletions management-api-server/doc/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@
"url" : "http://www.apache.org/licenses/LICENSE-2.0.html"
},
"title" : "Management API for Apache Cassandra™",
"version" : "0.1"
"version" : "0.1.66"
},
"servers" : [ {
"description" : "This Server URL will likely only work in a development environment.",
"url" : "http://localhost:8080"
} ],
"paths" : {
"/api/v0/lifecycle/configure" : {
"post" : {
"description" : "Configure Cassandra/DSE. Will fail if Cassandra/DSE is already started",
"description" : "Configure Cassandra. Will fail if Cassandra is already started",
"operationId" : "configureNode",
"parameters" : [ {
"in" : "query",
Expand All @@ -38,7 +42,9 @@
"type" : "string"
}
}
}
},
"description" : "JSON or YAML configuration overrides",
"required" : true
},
"responses" : {
"200" : {
Expand Down Expand Up @@ -75,6 +81,14 @@
"description" : "Cassandra can't be configured while running"
},
"500" : {
"content" : {
"text/plain" : {
"example" : "error message",
"schema" : {
"type" : "string"
}
}
},
"description" : "Error configuring Cassandra"
}
}
Expand Down Expand Up @@ -422,7 +436,13 @@
"200" : {
"content" : {
"application/json" : {
"example" : [ "system_schema", "system", "system_auth", "system_distributed", "system_traces" ]
"example" : [ "system_schema", "system", "system_auth", "system_distributed", "system_traces" ],
"schema" : {
"type" : "array",
"items" : {
"type" : "string"
}
}
}
},
"description" : "List of Keyspaces"
Expand Down Expand Up @@ -1177,7 +1197,13 @@
"200" : {
"content" : {
"application/json" : {
"example" : [ "table_1", "table_2" ]
"example" : [ "table_1", "table_2" ],
"schema" : {
"type" : "array",
"items" : {
"type" : "string"
}
}
}
},
"description" : "Table list"
Expand Down Expand Up @@ -1428,7 +1454,10 @@
"200" : {
"content" : {
"text/plain" : {
"example" : "OK"
"example" : "OK",
"schema" : {
"type" : "string"
}
}
},
"description" : "Service is running"
Expand All @@ -1444,7 +1473,10 @@
"200" : {
"content" : {
"text/plain" : {
"example" : "OK"
"example" : "OK",
"schema" : {
"type" : "string"
}
}
},
"description" : "Service is ready to handle requests"
Expand Down Expand Up @@ -1661,6 +1693,35 @@
},
"summary" : "Rewrite sstables (for the requested tables) that are not on the current version (thus upgrading them to said current version). This operation is asynchronous and returns immediately."
}
},
"/api/v2/metadata/endpoints" : {
"get" : {
"operationId" : "getEndpointStates_1",
"responses" : {
"200" : {
"content" : {
"application/json" : {
"schema" : {
"$ref" : "#/components/schemas/EndpointStatesResponse"
}
}
},
"description" : "Endpoint states"
},
"500" : {
"content" : {
"text/plain" : {
"example" : "error message",
"schema" : {
"type" : "string"
}
}
},
"description" : "Error reading endpoint states"
}
},
"summary" : "Returns this nodes view of the endpoint states of nodes"
}
}
},
"components" : {
Expand Down Expand Up @@ -1761,6 +1822,30 @@
},
"required" : [ "columns", "keyspace_name", "table_name" ]
},
"EndpointStates" : {
"type" : "object",
"properties" : {
"states" : {
"type" : "object",
"additionalProperties" : {
"type" : "string"
}
}
},
"required" : [ "states" ]
},
"EndpointStatesResponse" : {
"type" : "object",
"properties" : {
"endpoints" : {
"type" : "array",
"items" : {
"$ref" : "#/components/schemas/EndpointStates"
}
}
},
"required" : [ "endpoints" ]
},
"FeatureSet" : {
"type" : "object",
"properties" : {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.datastax.mgmtapi.resources.MetadataResources;
import com.datastax.mgmtapi.resources.NodeOpsResources;
import com.datastax.mgmtapi.resources.TableOpsResources;
import com.datastax.mgmtapi.resources.v2.MetadataResourcesV2;
import com.google.common.collect.ImmutableSet;
import io.swagger.v3.jaxrs2.SwaggerSerializers;
import io.swagger.v3.jaxrs2.integration.resources.OpenApiResource;
Expand Down Expand Up @@ -65,6 +66,8 @@ public ManagementApplication(
new TableOpsResources(this),
new com.datastax.mgmtapi.resources.v1.TableOpsResources(this),
new AuthResources(this),
// v2 resources
new MetadataResourcesV2(this),
new OpenApiResource(),
new SwaggerSerializers());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
*/
package com.datastax.mgmtapi.resources;

import static com.datastax.mgmtapi.resources.NodeOpsResources.handle;

import com.datastax.mgmtapi.CqlService;
import com.datastax.mgmtapi.ManagementApplication;
import com.datastax.mgmtapi.resources.common.BaseResource;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.ExampleObject;
Expand All @@ -22,13 +20,10 @@
import org.apache.commons.lang3.StringUtils;

@Path("/api/v0/ops/auth")
public class AuthResources {
private final ManagementApplication app;
private final CqlService cqlService;
public class AuthResources extends BaseResource {

public AuthResources(ManagementApplication application) {
this.app = application;
this.cqlService = application.cqlService;
super(application);
}

@POST
Expand Down Expand Up @@ -61,7 +56,7 @@ public Response createRole(
return Response.status(Response.Status.BAD_REQUEST.getStatusCode(), "Password is empty")
.build();

cqlService.executePreparedStatement(
app.cqlService.executePreparedStatement(
app.dbUnixSocketFile,
"CALL NodeOps.createRole(?,?,?,?)",
name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
*/
package com.datastax.mgmtapi.resources;

import static com.datastax.mgmtapi.resources.NodeOpsResources.handle;

import com.datastax.mgmtapi.CqlService;
import com.datastax.mgmtapi.ManagementApplication;
import com.datastax.mgmtapi.resources.common.BaseResource;
import com.datastax.mgmtapi.resources.helpers.ResponseTools;
import com.datastax.mgmtapi.resources.models.Job;
import com.datastax.oss.driver.api.core.cql.ResultSet;
Expand All @@ -29,20 +27,13 @@
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Path("/api/v0")
public class K8OperatorResources {
private static final Logger logger = LoggerFactory.getLogger(K8OperatorResources.class);
public class K8OperatorResources extends BaseResource {
private static final ObjectMapper jsonMapper = new ObjectMapper();

private final ManagementApplication app;
private final CqlService cqlService;

public K8OperatorResources(ManagementApplication application) {
this.app = application;
this.cqlService = application.cqlService;
super(application);
}

@GET
Expand All @@ -52,7 +43,11 @@ public K8OperatorResources(ManagementApplication application) {
@ApiResponse(
responseCode = "200",
description = "Service is running",
content = @Content(mediaType = MediaType.TEXT_PLAIN, examples = @ExampleObject(value = "OK")))
content =
@Content(
mediaType = MediaType.TEXT_PLAIN,
schema = @Schema(implementation = String.class),
examples = @ExampleObject(value = "OK")))
public Response checkLiveness() {
return Response.ok("OK").build();
}
Expand All @@ -66,13 +61,17 @@ public Response checkLiveness() {
@ApiResponse(
responseCode = "200",
description = "Service is ready to handle requests",
content = @Content(mediaType = MediaType.TEXT_PLAIN, examples = @ExampleObject(value = "OK")))
content =
@Content(
mediaType = MediaType.TEXT_PLAIN,
schema = @Schema(implementation = String.class),
examples = @ExampleObject(value = "OK")))
@ApiResponse(responseCode = "500", description = "Service is not ready to handle requests")
public Response checkReadiness() {
return handle(
() -> {
ResultSet resultSet =
cqlService.executeCql(app.dbUnixSocketFile, "SELECT * from system.local");
app.cqlService.executeCql(app.dbUnixSocketFile, "SELECT * from system.local");
Row result = resultSet.one();

if (result != null) {
Expand Down Expand Up @@ -123,7 +122,7 @@ public Response checkClusterConsistency(
if (rfPerDc == null) rfPerDc = 3;

ResultSet result =
cqlService.executePreparedStatement(
app.cqlService.executePreparedStatement(
app.dbUnixSocketFile,
"CALL NodeOps.checkConsistencyLevel(?, ?)",
consistencyLevel,
Expand Down Expand Up @@ -158,7 +157,7 @@ public Response seedReload() {
return handle(
() -> {
ResultSet result =
cqlService.executeCql(app.dbUnixSocketFile, "CALL NodeOps.reloadSeeds()");
app.cqlService.executeCql(app.dbUnixSocketFile, "CALL NodeOps.reloadSeeds()");

List<String> response = result.one().getList("result", String.class);

Expand Down Expand Up @@ -192,7 +191,7 @@ public Response getJobStatus(
Map<String, String> jobResponse =
(Map<String, String>)
ResponseTools.getSingleRowResponse(
app.dbUnixSocketFile, cqlService, "CALL NodeOps.jobStatus(?)", jobId);
app.dbUnixSocketFile, app.cqlService, "CALL NodeOps.jobStatus(?)", jobId);
if (jobResponse.isEmpty()) {
return Response.status(Response.Status.NOT_FOUND).entity(jobResponse).build();
}
Expand Down
Loading

0 comments on commit 17e1eca

Please sign in to comment.