forked from apache/gravitino
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[apache#1724] feat(server):Add server-side REST API support for fileset
- Loading branch information
1 parent
26a4b3d
commit 85216f2
Showing
8 changed files
with
557 additions
and
0 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
89 changes: 89 additions & 0 deletions
89
common/src/main/java/com/datastrato/gravitino/dto/file/FilesetDTO.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,89 @@ | ||
/* | ||
* Copyright 2023 Datastrato Pvt Ltd. | ||
* This software is licensed under the Apache License version 2. | ||
*/ | ||
package com.datastrato.gravitino.dto.file; | ||
|
||
import com.datastrato.gravitino.Audit; | ||
import com.datastrato.gravitino.file.Fileset; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import java.util.Map; | ||
import javax.annotation.Nullable; | ||
import lombok.Builder; | ||
|
||
/** Represents a Fileset DTO (Data Transfer Object). */ | ||
@Builder | ||
public class FilesetDTO implements Fileset { | ||
|
||
@JsonProperty("name") | ||
private String name; | ||
|
||
@JsonProperty("comment") | ||
private String comment; | ||
|
||
@JsonProperty("type") | ||
private Type type; | ||
|
||
@JsonProperty("storageLocation") | ||
private String storageLocation; | ||
|
||
@JsonProperty("properties") | ||
private Map<String, String> properties; | ||
|
||
@JsonProperty("audit") | ||
private Audit audit; | ||
|
||
private FilesetDTO() { | ||
} | ||
|
||
/** | ||
* Construct a fileset DTO. | ||
* @param name The name of the fileset. | ||
* @param comment The comment of the fileset. | ||
* @param type The type of the fileset. | ||
* @param storageLocation The storageLocation of the fileset. | ||
* @param properties The properties associated with fileset. | ||
* @param audit The audit information of fileset. | ||
*/ | ||
private FilesetDTO( | ||
String name, String comment, Type type, String storageLocation, Map<String, String> properties, | ||
Audit audit) { | ||
this.name = name; | ||
this.comment = comment; | ||
this.type = type; | ||
this.storageLocation = storageLocation; | ||
this.properties = properties; | ||
this.audit = audit; | ||
} | ||
|
||
@Override | ||
public String name() { | ||
return name; | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public String comment() { | ||
return comment; | ||
} | ||
|
||
@Override | ||
public Type type() { | ||
return type; | ||
} | ||
|
||
@Override | ||
public String storageLocation() { | ||
return storageLocation; | ||
} | ||
|
||
@Override | ||
public Map<String, String> properties() { | ||
return properties; | ||
} | ||
|
||
@Override | ||
public Audit auditInfo() { | ||
return audit; | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
common/src/main/java/com/datastrato/gravitino/dto/requests/FilesetCreateRequest.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,55 @@ | ||
/* | ||
* Copyright 2023 Datastrato Pvt Ltd. | ||
* This software is licensed under the Apache License version 2. | ||
*/ | ||
package com.datastrato.gravitino.dto.requests; | ||
|
||
import com.datastrato.gravitino.file.Fileset; | ||
import com.datastrato.gravitino.rest.RESTRequest; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.google.common.base.Preconditions; | ||
import java.util.Map; | ||
import javax.annotation.Nullable; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.ToString; | ||
import lombok.extern.jackson.Jacksonized; | ||
import org.apache.commons.lang3.StringUtils; | ||
|
||
@Getter | ||
@EqualsAndHashCode | ||
@ToString | ||
@Builder | ||
@Jacksonized | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class FilesetCreateRequest implements RESTRequest { | ||
|
||
@JsonProperty("name") | ||
private String name; | ||
|
||
@Nullable | ||
@JsonProperty("comment") | ||
private String comment; | ||
|
||
@Nullable | ||
@JsonProperty("type") | ||
private Fileset.Type type; | ||
|
||
@Nullable | ||
@JsonProperty("storageLocation") | ||
private String storageLocation; | ||
|
||
@Nullable | ||
@JsonProperty("properties") | ||
private Map<String, String> properties; | ||
|
||
@Override | ||
public void validate() throws IllegalArgumentException { | ||
Preconditions.checkArgument( | ||
StringUtils.isNotBlank(name), "\"name\" field is required and cannot be empty"); | ||
} | ||
} |
126 changes: 126 additions & 0 deletions
126
common/src/main/java/com/datastrato/gravitino/dto/requests/FilesetUpdateRequest.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,126 @@ | ||
/* | ||
* Copyright 2023 Datastrato Pvt Ltd. | ||
* This software is licensed under the Apache License version 2. | ||
*/ | ||
package com.datastrato.gravitino.dto.requests; | ||
|
||
import com.datastrato.gravitino.file.FilesetChange; | ||
import com.datastrato.gravitino.rest.RESTRequest; | ||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.annotation.JsonSubTypes; | ||
import com.fasterxml.jackson.annotation.JsonTypeInfo; | ||
import com.google.common.base.Preconditions; | ||
import lombok.AllArgsConstructor; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.Getter; | ||
import lombok.ToString; | ||
import org.apache.commons.lang3.StringUtils; | ||
|
||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY) | ||
@JsonSubTypes({ | ||
@JsonSubTypes.Type(value = TableUpdateRequest.RenameTableRequest.class, name = "rename"), | ||
@JsonSubTypes.Type( | ||
value = TableUpdateRequest.UpdateTableCommentRequest.class, | ||
name = "updateComment"), | ||
@JsonSubTypes.Type( | ||
value = TableUpdateRequest.SetTablePropertyRequest.class, | ||
name = "setProperty"), | ||
@JsonSubTypes.Type( | ||
value = TableUpdateRequest.RemoveTablePropertyRequest.class, | ||
name = "removeProperty") | ||
}) | ||
public interface FilesetUpdateRequest extends RESTRequest { | ||
FilesetChange filesetChange(); | ||
|
||
@EqualsAndHashCode | ||
@AllArgsConstructor | ||
@ToString | ||
class RenameFilesetRequest implements FilesetUpdateRequest { | ||
|
||
@Getter | ||
@JsonProperty("newName") | ||
private final String newName; | ||
|
||
@Override | ||
public FilesetChange filesetChange() { | ||
return FilesetChange.rename(newName); | ||
} | ||
|
||
@Override | ||
public void validate() throws IllegalArgumentException { | ||
Preconditions.checkArgument( | ||
StringUtils.isNotBlank(newName), "\"newName\" field is required and cannot be empty"); | ||
} | ||
} | ||
|
||
@EqualsAndHashCode | ||
@AllArgsConstructor | ||
@ToString | ||
class UpdateFilesetCommentRequest implements FilesetUpdateRequest { | ||
|
||
@Getter | ||
@JsonProperty("newComment") | ||
private final String newComment; | ||
|
||
@Override | ||
public FilesetChange filesetChange() { | ||
return FilesetChange.updateComment(newComment); | ||
} | ||
|
||
@Override | ||
public void validate() throws IllegalArgumentException { | ||
Preconditions.checkArgument( | ||
StringUtils.isNotBlank(newComment), | ||
"\"newComment\" field is required and cannot be empty"); | ||
} | ||
} | ||
|
||
@EqualsAndHashCode | ||
@AllArgsConstructor | ||
@ToString | ||
class SetFilesetPropertiesRequest implements FilesetUpdateRequest { | ||
|
||
@Getter | ||
@JsonProperty("property") | ||
private final String property; | ||
|
||
@Getter | ||
@JsonProperty("value") | ||
private final String value; | ||
|
||
@Override | ||
public FilesetChange filesetChange() { | ||
return FilesetChange.setProperty(property, value); | ||
} | ||
|
||
@Override | ||
public void validate() throws IllegalArgumentException { | ||
Preconditions.checkArgument( | ||
StringUtils.isNotBlank(property), "\"property\" field is required and cannot be empty"); | ||
Preconditions.checkArgument(value != null, "\"value\" field is required and cannot be null"); | ||
} | ||
} | ||
|
||
@EqualsAndHashCode | ||
@AllArgsConstructor | ||
@ToString | ||
class RemoveFilesetPropertiesRequest implements FilesetUpdateRequest { | ||
|
||
@Getter | ||
@JsonProperty("property") | ||
private final String property; | ||
|
||
@Override | ||
public FilesetChange filesetChange() { | ||
return FilesetChange.removeProperty(property); | ||
} | ||
|
||
@Override | ||
public void validate() throws IllegalArgumentException { | ||
Preconditions.checkArgument( | ||
StringUtils.isNotBlank(property), "\"property\" field is required and cannot be empty"); | ||
} | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
common/src/main/java/com/datastrato/gravitino/dto/requests/FilesetUpdatesRequest.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,28 @@ | ||
/* | ||
* Copyright 2023 Datastrato Pvt Ltd. | ||
* This software is licensed under the Apache License version 2. | ||
*/ | ||
package com.datastrato.gravitino.dto.requests; | ||
|
||
import com.datastrato.gravitino.rest.RESTMessage; | ||
import com.datastrato.gravitino.rest.RESTRequest; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import java.util.List; | ||
import lombok.AllArgsConstructor; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.Getter; | ||
import lombok.ToString; | ||
|
||
@Getter | ||
@EqualsAndHashCode | ||
@AllArgsConstructor | ||
@ToString | ||
public class FilesetUpdatesRequest implements RESTRequest { | ||
|
||
@JsonProperty("updates") | ||
private final List<FilesetUpdateRequest> updates; | ||
@Override | ||
public void validate() throws IllegalArgumentException { | ||
updates.forEach(RESTMessage::validate); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
common/src/main/java/com/datastrato/gravitino/dto/responses/FilesetResponse.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,40 @@ | ||
/* | ||
* Copyright 2023 Datastrato Pvt Ltd. | ||
* This software is licensed under the Apache License version 2. | ||
*/ | ||
package com.datastrato.gravitino.dto.responses; | ||
|
||
import com.datastrato.gravitino.dto.file.FilesetDTO; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.google.common.base.Preconditions; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.Getter; | ||
import lombok.ToString; | ||
import org.apache.commons.lang3.StringUtils; | ||
|
||
@Getter | ||
@ToString | ||
@EqualsAndHashCode(callSuper = true) | ||
public class FilesetResponse extends BaseResponse { | ||
|
||
@JsonProperty("fileset") | ||
private final FilesetDTO fileset; | ||
|
||
public FilesetResponse() { | ||
super(0); | ||
this.fileset = null; | ||
} | ||
|
||
public FilesetResponse(FilesetDTO fileset) { | ||
super(0); | ||
this.fileset = fileset; | ||
} | ||
|
||
@Override | ||
public void validate() throws IllegalArgumentException { | ||
super.validate(); | ||
Preconditions.checkArgument(fileset != null, "fileset must not be null"); | ||
Preconditions.checkArgument( | ||
StringUtils.isNotBlank(fileset.name()), "fileset 'name' must not be null and empty"); | ||
} | ||
} |
Oops, something went wrong.