-
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.
Self serve replication API server side implementation (#227)
## Summary <!--- HINT: Replace #nnn with corresponding Issue number, if you are fixing an existing issue --> Branched off from #220, this PR adds the server side implementation for the self serve replication API. Separate PR for SQL level changes can be found here: #226. This PR adds validations for the interval and destination cluster parameters and stores the replication config as part of table policies in table properties. Validations on parameters: - Destination cluster cannot be the same as the source cluster of the table. - For the interval parameter, if user inputted it should be in the format <X>H or <X>D where hourly inputs can be 12H and daily inputs can be 1-3D. This PR doesn't include the changes to generate the cron schedule from the interval input, those will be made in a separate PR. ## Changes - [x] Client-facing API Changes - [ ] Internal API Changes - [ ] Bug Fixes - [ ] New Features - [ ] Performance Improvements - [ ] Code Style - [ ] Refactoring - [ ] Documentation - [ ] Tests For all the boxes checked, please include additional details of the changes made in this pull request. ## Testing Done <!--- Check any relevant boxes with "x" --> - [x] Manually Tested on local docker setup. Please include commands ran, and their output. - [x] Added new tests for the changes made. - [ ] Updated existing tests to reflect the changes made. - [ ] No tests added or updated. Please explain why. If unsure, please feel free to ask for help. - [ ] Some other form of testing like staging or soak time in production. Please explain. Added unit testing. Tested with local docker server: successful POST to `http://localhost:8000/v1/databases/u_tableowner/tables` with parameters: ``` { "tableId": "test_table", "databaseId": "u_tableowner", "baseTableVersion": "INITIAL_VERSION", "clusterId": "LocalHadoopCluster", "schema": "{\"type\": \"struct\", \"fields\": [{\"id\": 1,\"required\": true,\"name\": \"id\",\"type\": \"string\"},{\"id\": 2,\"required\": true,\"name\": \"name\",\"type\": \"string\"},{\"id\": 3,\"required\": true,\"name\": \"ts\",\"type\": \"timestamp\"}]}", "tableProperties": { "key": "value" }, "policies": { "sharingEnabled": "true", "replication": { "config": [ { "destination": "LocalHadoopClusterA", "interval": "12H" } ] } } } ``` successful POST to `http://localhost:8000/v1/databases/u_tableowner/tables` with parameters: ``` { "tableId": "test_table", "databaseId": "u_tableowner", "baseTableVersion": "INITIAL_VERSION", "clusterId": "LocalHadoopCluster", "schema": "{\"type\": \"struct\", \"fields\": [{\"id\": 1,\"required\": true,\"name\": \"id\",\"type\": \"string\"},{\"id\": 2,\"required\": true,\"name\": \"name\",\"type\": \"string\"},{\"id\": 3,\"required\": true,\"name\": \"ts\",\"type\": \"timestamp\"}]}", "tableProperties": { "key": "value" }, "policies": { "sharingEnabled": "true", "replication": { "config": [ { "destination": "LocalHadoopClusterA", "interval": "1D" } ] } } } ``` Using `interval: 24H` gives the following error: ``` { "status": "BAD_REQUEST", "error": "Bad Request", "message": " : Replication interval for the table LocalHadoopCluster.u_tableowner.test_table1 can either be 12 hours or daily for up to 3 days", "stacktrace": null, "cause": "Not Available" } ``` Trying to set the destination cluster as the source cluster gives the following error: ``` { "status": "BAD_REQUEST", "error": "Bad Request", "message": " : Replication destination cluster for the table LocalHadoopCluster.u_tableowner.test_table1 must be different from the source cluster", "stacktrace": null, "cause": "Not Available" } ``` For all the boxes checked, include a detailed description of the testing done for the changes made in this pull request. # Additional Information - [ ] Breaking Changes - [ ] Deprecations - [ ] Large PR broken into smaller PRs, and PR plan linked in the description. For all the boxes checked, include additional details of the changes made in this pull request.
- Loading branch information
1 parent
2960f85
commit 74d85fc
Showing
15 changed files
with
668 additions
and
11 deletions.
There are no files selected for viewing
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
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
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
27 changes: 27 additions & 0 deletions
27
...c/main/java/com/linkedin/openhouse/tables/api/spec/v0/request/components/Replication.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,27 @@ | ||
package com.linkedin.openhouse.tables.api.spec.v0.request.components; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import java.util.List; | ||
import javax.validation.Valid; | ||
import javax.validation.constraints.NotNull; | ||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Builder(toBuilder = true) | ||
@EqualsAndHashCode | ||
@Getter | ||
@AllArgsConstructor(access = AccessLevel.PROTECTED) | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class Replication { | ||
@Schema( | ||
description = | ||
"Replication config for the destination cluster name and replication job interval", | ||
example = "[{destination: clusterA, interval: 12H}, {destination: clusterB, interval: 12H}]") | ||
@NotNull(message = "Incorrect replication policy specified. Replication config cannot be null.") | ||
@Valid | ||
List<ReplicationConfig> config; | ||
} |
32 changes: 32 additions & 0 deletions
32
.../java/com/linkedin/openhouse/tables/api/spec/v0/request/components/ReplicationConfig.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,32 @@ | ||
package com.linkedin.openhouse.tables.api.spec.v0.request.components; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import javax.validation.Valid; | ||
import javax.validation.constraints.NotNull; | ||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Builder(toBuilder = true) | ||
@EqualsAndHashCode | ||
@Getter | ||
@AllArgsConstructor(access = AccessLevel.PROTECTED) | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class ReplicationConfig { | ||
@Schema(description = "Replication destination cluster name", example = "clusterA") | ||
@NotNull( | ||
message = | ||
"Incorrect destination specified. Destination field for replication config cannot be null") | ||
@Valid | ||
String destination; | ||
|
||
@Schema( | ||
description = | ||
"Optional parameter interval at which the replication job should run. Default value is 1D", | ||
example = "1D") | ||
@Valid | ||
String interval; | ||
} |
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
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
19 changes: 19 additions & 0 deletions
19
services/tables/src/main/java/com/linkedin/openhouse/tables/common/ReplicationInterval.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,19 @@ | ||
package com.linkedin.openhouse.tables.common; | ||
|
||
import com.linkedin.openhouse.tables.api.spec.v0.request.components.ReplicationConfig; | ||
|
||
/** ENUM for default replication interval associated with Interval in {@link ReplicationConfig} */ | ||
public enum ReplicationInterval { | ||
// default interval to run replication jobs if no interval provided by user | ||
DEFAULT("1D"); | ||
|
||
private final String interval; | ||
|
||
ReplicationInterval(String interval) { | ||
this.interval = interval; | ||
} | ||
|
||
public String getInterval() { | ||
return interval; | ||
} | ||
} |
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
Oops, something went wrong.