Skip to content

Commit

Permalink
More problems due to rebase...
Browse files Browse the repository at this point in the history
  • Loading branch information
Miles-Garnsey committed Aug 24, 2023
1 parent fa342ab commit a59b202
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,8 @@ public Response repair(RepairRequest repairRequest) {
repairRequest.keyspaceName,
repairRequest.tables,
repairRequest.full,
// The default repair does not allow for specifying things like parallelism, threadCounts, source DCs or ranges etc.
// The default repair does not allow for specifying things like parallelism,
// threadCounts, source DCs or ranges etc.
Optional.empty(),
Optional.empty(),
Optional.empty(),
Expand Down Expand Up @@ -642,4 +643,4 @@ public Response move(@QueryParam(value = "newToken") String newToken) {
+ " \"language\": null,\n"
+ " \"encoding\": null\n"
+ "}";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
Expand Down Expand Up @@ -154,11 +155,15 @@ public Response repair(RepairRequest repairRequest) {
ResponseTools.getSingleRowStringResponse(
app.dbUnixSocketFile,
app.cqlService,
"CALL NodeOps.repair(?, ?, ?, ?)",
"CALL NodeOps.repair(?, ?, ?, ?, ?, ?, ?, ?)",
repairRequest.keyspaceName,
repairRequest.tables,
repairRequest.full,
true))
true,
Optional.empty(),
Optional.empty(),
Optional.empty(),
Optional.empty()))
.build();
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,25 @@
package com.datastax.mgmtapi.resources.v2;

import javax.ws.rs.Consumes;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import com.datastax.mgmtapi.ManagementApplication;
import com.datastax.mgmtapi.resources.common.BaseResources;
import com.datastax.mgmtapi.resources.v2.models.RepairRequest;
import com.datastax.mgmtapi.resources.v2.models.RepairRequestResponse;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.datastax.oss.driver.api.core.cql.ResultSet;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.ExampleObject;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import javax.ws.rs.Consumes;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

@Path("/api/v2/repairs")
public class RepairResources extends BaseResources {

private static final ObjectMapper jsonMapper = new ObjectMapper();

public RepairResources(ManagementApplication application) {
super(application);
}
Expand All @@ -47,6 +44,17 @@ public RepairResources(ManagementApplication application) {
mediaType = MediaType.TEXT_PLAIN,
schema = @Schema(implementation = Response.Status.class),
examples = @ExampleObject(value = "keyspace must be specified")))
@ApiResponse(
responseCode = "500",
description = "internal error, we did not receive the expected repair ID from Cassandra.",
content =
@Content(
mediaType = MediaType.TEXT_PLAIN,
schema = @Schema(implementation = Response.Status.class),
examples =
@ExampleObject(
value =
"internal error, we did not receive the expected repair ID from Cassandra.")))
public final Response repair(RepairRequest request) {
return handle(
() -> {
Expand All @@ -55,19 +63,27 @@ public final Response repair(RepairRequest request) {
.entity("keyspaceName must be specified")
.build();
}
app.cqlService.executePreparedStatement(
app.dbUnixSocketFile,
"CALL NodeOps.repair(?, ?, ?)",
repairRequest.keyspaceName,
repairRequest.tables,
repairRequest.full);
ResultSet res =
app.cqlService.executePreparedStatement(
app.dbUnixSocketFile,
"CALL NodeOps.repair(?, ?, ?, ?, ?, ?, ?, ?)",
request.keyspace,
request.tables,
request.fullRepair,
request.notifications,
request.repairParallelism,
request.datacenters,
request.associatedTokens,
request.repairThreadCount);

return Response.ok("OK").build();
try {
String repairID = res.one().getString(0);
return Response.accepted(new RepairRequestResponse(repairID)).build();
} catch (Exception e) {
return Response.status(Response.Status.INTERNAL_SERVER_ERROR)
.entity("Repair request failed: " + e.getMessage())
.build();
}
});

String repairID = ""; // TODO: implement me
return Response.ok(new RepairRequestResponse(repairID)).build();
}


}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.datastax.mgmtapi.resources.v2.models;


import com.fasterxml.jackson.annotation.JsonValue;

public enum RepairParallelism {
Expand Down Expand Up @@ -30,4 +29,4 @@ public String getName() {
public String toString() {
return this.getName();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,40 +1,51 @@
package com.datastax.mgmtapi.resources.v2.models;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.Collection;
import java.util.List;
import java.util.Objects;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;

public class RepairRequest {

@JsonProperty(value = "keyspace", required = true)
public final String keyspace;

@JsonProperty(value = "tables", required = true)
public final List<String> tables;

@JsonProperty(value = "full_repair", defaultValue = "true")
public final Boolean fullRepair;

@JsonProperty(value = "notifications", defaultValue = "true")
public final Boolean notifications;

@JsonProperty(value = "associated_tokens")
public final List<RingRange> associatedTokens;

@JsonProperty(value = "repair_parallelism")
public final RepairParallelism repairParallelism;

@JsonProperty(value = "datacenters")
public final Collection<String> datacenters;

@JsonProperty(value = "repair_thread_count")
public final int repairThreadCount;

@JsonCreator
public RepairRequest(
@JsonProperty(value = "keyspace", required = true) String keyspace,
@JsonProperty(value = "tables", required = true) List<String> tables,
@JsonProperty(value = "full_repair", defaultValue = "true") Boolean fullRepair,
@JsonProperty(value = "notifications", defaultValue = "true") boolean notifications,
@JsonProperty(value = "associated_tokens") List<RingRange> associatedTokens,
@JsonProperty(value = "repair_parallelism") RepairParallelism repairParallelism,
@JsonProperty(value = "datacenters") Collection<String> datacenters,
@JsonProperty(value = "repair_thread_count") int repairThreadCount){
@JsonProperty(value = "repair_thread_count") int repairThreadCount) {
this.keyspace = keyspace;
this.tables = tables;
this.fullRepair = fullRepair;
this.notifications = notifications;
this.associatedTokens = associatedTokens;
this.datacenters = datacenters;
this.repairParallelism = repairParallelism;
Expand All @@ -48,22 +59,22 @@ public boolean equals(Object o) {
if (o == null || getClass() != o.getClass()) {
return false;
}
return Objects.equals(keyspace, ((RepairRequest) o).keyspace) &&
Objects.equals(tables, ((RepairRequest) o).tables) &&
Objects.equals(fullRepair, ((RepairRequest) o).fullRepair) &&
Objects.equals(associatedTokens, ((RepairRequest) o).associatedTokens) &&
Objects.equals(datacenters, ((RepairRequest) o).datacenters) &&
Objects.equals(repairParallelism, ((RepairRequest) o).repairParallelism) &&
Objects.equals(repairThreadCount, ((RepairRequest) o).repairThreadCount);
return Objects.equals(keyspace, ((RepairRequest) o).keyspace)
&& Objects.equals(tables, ((RepairRequest) o).tables)
&& Objects.equals(fullRepair, ((RepairRequest) o).fullRepair)
&& Objects.equals(associatedTokens, ((RepairRequest) o).associatedTokens)
&& Objects.equals(datacenters, ((RepairRequest) o).datacenters)
&& Objects.equals(repairParallelism, ((RepairRequest) o).repairParallelism)
&& Objects.equals(repairThreadCount, ((RepairRequest) o).repairThreadCount);
}

public int hashCode() {
return Objects.hashCode(keyspace) +
Objects.hashCode(tables) +
Objects.hashCode(fullRepair) +
Objects.hashCode(associatedTokens) +
Objects.hashCode(datacenters) +
Objects.hashCode(repairParallelism) +
Objects.hashCode(repairThreadCount);
return Objects.hashCode(keyspace)
+ Objects.hashCode(tables)
+ Objects.hashCode(fullRepair)
+ Objects.hashCode(associatedTokens)
+ Objects.hashCode(datacenters)
+ Objects.hashCode(repairParallelism)
+ Objects.hashCode(repairThreadCount);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package com.datastax.mgmtapi.resources.v2.models;

import java.util.Objects;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.Objects;

public class RepairRequestResponse {
@JsonProperty(value = "repair_id", required = true)
public final String repairID;

@JsonCreator
public RepairRequestResponse(@JsonProperty(value = "repair_id", required = true) String repairID) {
public RepairRequestResponse(
@JsonProperty(value = "repair_id", required = true) String repairID) {
this.repairID = repairID;
}

Expand All @@ -26,4 +27,4 @@ public boolean equals(Object o) {
public int hashCode() {
return Objects.hashCode(repairID);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package com.datastax.mgmtapi.resources.v2.models;

import com.fasterxml.jackson.annotation.JsonProperty;
import java.math.BigInteger;
import java.util.Comparator;

import com.fasterxml.jackson.annotation.JsonProperty;

public final class RingRange {
public static final Comparator<RingRange> START_COMPARATOR
= (RingRange o1, RingRange o2) -> o1.start.compareTo(o2.start);
public static final Comparator<RingRange> START_COMPARATOR =
(RingRange o1, RingRange o2) -> o1.start.compareTo(o2.start);

@JsonProperty(value = "start", required = true)
public final BigInteger start;

@JsonProperty(value = "end", required = true)
public final BigInteger end;

Expand All @@ -33,4 +33,4 @@ public BigInteger getStart() {
public BigInteger getEnd() {
return end;
}
}
}

0 comments on commit a59b202

Please sign in to comment.