-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create new repair endpoint that has access to new parameters for repa…
…irs.
- Loading branch information
1 parent
d82219b
commit fa342ab
Showing
5 changed files
with
240 additions
and
0 deletions.
There are no files selected for viewing
73 changes: 73 additions & 0 deletions
73
management-api-server/src/main/java/com/datastax/mgmtapi/resources/v2/RepairResources.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
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 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; | ||
|
||
@Path("/api/v2/repairs") | ||
public class RepairResources extends BaseResources { | ||
|
||
private static final ObjectMapper jsonMapper = new ObjectMapper(); | ||
|
||
public RepairResources(ManagementApplication application) { | ||
super(application); | ||
} | ||
|
||
@PUT | ||
@Operation(summary = "Initiate a new repair", operationId = "v2PutRepair") | ||
@Produces(MediaType.APPLICATION_JSON) | ||
@Consumes("application/json") | ||
@ApiResponse( | ||
responseCode = "200", | ||
description = "Repair Successfully requested", | ||
content = | ||
@Content( | ||
mediaType = MediaType.APPLICATION_JSON, | ||
schema = @Schema(implementation = RepairRequestResponse.class), | ||
examples = @ExampleObject(value = "OK"))) | ||
@ApiResponse( | ||
responseCode = "400", | ||
description = "Repair request missing Keyspace name", | ||
content = | ||
@Content( | ||
mediaType = MediaType.TEXT_PLAIN, | ||
schema = @Schema(implementation = Response.Status.class), | ||
examples = @ExampleObject(value = "keyspace must be specified"))) | ||
public final Response repair(RepairRequest request) { | ||
return handle( | ||
() -> { | ||
if (request.keyspace == null) { | ||
return Response.status(Response.Status.BAD_REQUEST) | ||
.entity("keyspaceName must be specified") | ||
.build(); | ||
} | ||
app.cqlService.executePreparedStatement( | ||
app.dbUnixSocketFile, | ||
"CALL NodeOps.repair(?, ?, ?)", | ||
repairRequest.keyspaceName, | ||
repairRequest.tables, | ||
repairRequest.full); | ||
|
||
return Response.ok("OK").build(); | ||
}); | ||
|
||
String repairID = ""; // TODO: implement me | ||
return Response.ok(new RepairRequestResponse(repairID)).build(); | ||
} | ||
|
||
|
||
} |
33 changes: 33 additions & 0 deletions
33
...-api-server/src/main/java/com/datastax/mgmtapi/resources/v2/models/RepairParallelism.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.datastax.mgmtapi.resources.v2.models; | ||
|
||
|
||
import com.fasterxml.jackson.annotation.JsonValue; | ||
|
||
public enum RepairParallelism { | ||
SEQUENTIAL("sequential"), | ||
PARALLEL("parallel"), | ||
DATACENTER_AWARE("dc_parallel"); | ||
|
||
private final String name; | ||
|
||
public static RepairParallelism fromName(String name) { | ||
if (PARALLEL.getName().equals(name)) { | ||
return PARALLEL; | ||
} else { | ||
return DATACENTER_AWARE.getName().equals(name) ? DATACENTER_AWARE : SEQUENTIAL; | ||
} | ||
} | ||
|
||
private RepairParallelism(String name) { | ||
this.name = name; | ||
} | ||
|
||
@JsonValue | ||
public String getName() { | ||
return this.name; | ||
} | ||
|
||
public String toString() { | ||
return this.getName(); | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
...ment-api-server/src/main/java/com/datastax/mgmtapi/resources/v2/models/RepairRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package com.datastax.mgmtapi.resources.v2.models; | ||
|
||
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 = "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 = "associated_tokens") List<RingRange> associatedTokens, | ||
@JsonProperty(value = "repair_parallelism") RepairParallelism repairParallelism, | ||
@JsonProperty(value = "datacenters") Collection<String> datacenters, | ||
@JsonProperty(value = "repair_thread_count") int repairThreadCount){ | ||
this.keyspace = keyspace; | ||
this.tables = tables; | ||
this.fullRepair = fullRepair; | ||
this.associatedTokens = associatedTokens; | ||
this.datacenters = datacenters; | ||
this.repairParallelism = repairParallelism; | ||
this.repairThreadCount = repairThreadCount; | ||
} | ||
|
||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
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); | ||
} | ||
|
||
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); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...-server/src/main/java/com/datastax/mgmtapi/resources/v2/models/RepairRequestResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.datastax.mgmtapi.resources.v2.models; | ||
|
||
import java.util.Objects; | ||
|
||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
public class RepairRequestResponse { | ||
@JsonProperty(value = "repair_id", required = true) | ||
public final String repairID; | ||
@JsonCreator | ||
public RepairRequestResponse(@JsonProperty(value = "repair_id", required = true) String repairID) { | ||
this.repairID = repairID; | ||
} | ||
|
||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
return Objects.equals(repairID, ((RepairRequestResponse) o).repairID); | ||
} | ||
|
||
public int hashCode() { | ||
return Objects.hashCode(repairID); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
management-api-server/src/main/java/com/datastax/mgmtapi/resources/v2/models/RingRange.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.datastax.mgmtapi.resources.v2.models; | ||
|
||
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); | ||
|
||
@JsonProperty(value = "start", required = true) | ||
public final BigInteger start; | ||
@JsonProperty(value = "end", required = true) | ||
public final BigInteger end; | ||
|
||
public RingRange( | ||
@JsonProperty(value = "start", required = true) BigInteger start, | ||
@JsonProperty(value = "end", required = true) BigInteger end) { | ||
this.start = start; | ||
this.end = end; | ||
} | ||
|
||
public RingRange(String... range) { | ||
start = new BigInteger(range[0]); | ||
end = new BigInteger(range[1]); | ||
} | ||
|
||
public BigInteger getStart() { | ||
return start; | ||
} | ||
|
||
public BigInteger getEnd() { | ||
return end; | ||
} | ||
} |