-
Notifications
You must be signed in to change notification settings - Fork 283
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add ParentChildRelationSqlService (#595)
* add ParentChildRelationSqlService * add search endpoint * add isParent field + address comments --------- Co-authored-by: Yingjian Wu <yingjianw@netflix.com>
- Loading branch information
1 parent
8ca992e
commit e9fce8d
Showing
20 changed files
with
1,767 additions
and
23 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
43 changes: 43 additions & 0 deletions
43
metacat-client/src/main/java/com/netflix/metacat/client/api/ParentChildRelV1.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,43 @@ | ||
package com.netflix.metacat.client.api; | ||
|
||
import javax.ws.rs.Path; | ||
import javax.ws.rs.Consumes; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.PathParam; | ||
|
||
import javax.ws.rs.core.MediaType; | ||
import com.netflix.metacat.common.dto.notifications.ChildInfoDto; | ||
|
||
import java.util.Set; | ||
|
||
/** | ||
* Metacat API for managing parent child relation. | ||
* | ||
* @author Yingjianw | ||
*/ | ||
|
||
@Path("/mds/v1/parentChildRel") | ||
@Consumes(MediaType.APPLICATION_JSON) | ||
@Produces(MediaType.APPLICATION_JSON) | ||
public interface ParentChildRelV1 { | ||
/** | ||
* Return the list of children. | ||
* @param catalogName catalogName | ||
* @param databaseName databaseName | ||
* @param tableName tableName | ||
* @return list of childInfos | ||
*/ | ||
@GET | ||
@Path("children/catalog/{catalog-name}/database/{database-name}/table/{table-name}") | ||
@Consumes(MediaType.APPLICATION_JSON) | ||
@Produces(MediaType.APPLICATION_JSON) | ||
Set<ChildInfoDto> getChildren( | ||
@PathParam("catalog-name") | ||
String catalogName, | ||
@PathParam("database-name") | ||
String databaseName, | ||
@PathParam("table-name") | ||
String tableName | ||
); | ||
} |
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
21 changes: 21 additions & 0 deletions
21
...ommon-server/src/main/java/com/netflix/metacat/common/server/model/BaseRelEntityInfo.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,21 @@ | ||
package com.netflix.metacat.common.server.model; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.io.Serializable; | ||
|
||
/** | ||
* Base class to represent relation entity. | ||
*/ | ||
@Data | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public abstract class BaseRelEntityInfo implements Serializable { | ||
private static final long serialVersionUID = 9121109874202888889L; | ||
private String name; | ||
private String relationType; | ||
private String uuid; | ||
|
||
} |
23 changes: 23 additions & 0 deletions
23
metacat-common-server/src/main/java/com/netflix/metacat/common/server/model/ChildInfo.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,23 @@ | ||
package com.netflix.metacat.common.server.model; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.EqualsAndHashCode; | ||
|
||
/** | ||
* ChildInfo. | ||
*/ | ||
@EqualsAndHashCode(callSuper = true) | ||
@AllArgsConstructor | ||
@Data | ||
public class ChildInfo extends BaseRelEntityInfo { | ||
/** | ||
Constructor with all params. | ||
@param name name of the entity | ||
@param relationType type of the relation | ||
@param uuid uuid of the entity | ||
*/ | ||
public ChildInfo(final String name, final String relationType, final String uuid) { | ||
super(name, relationType, uuid); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
metacat-common-server/src/main/java/com/netflix/metacat/common/server/model/ParentInfo.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.netflix.metacat.common.server.model; | ||
|
||
import lombok.Data; | ||
import lombok.EqualsAndHashCode; | ||
|
||
/** | ||
* ParentInfo. | ||
*/ | ||
@EqualsAndHashCode(callSuper = true) | ||
@Data | ||
public class ParentInfo extends BaseRelEntityInfo { | ||
|
||
/** | ||
Empty Constructor. | ||
*/ | ||
public ParentInfo() { | ||
|
||
} | ||
|
||
/** | ||
Constructor with all params. | ||
@param name name of the entity | ||
@param relationType type of the relation | ||
@param uuid uuid of the entity | ||
*/ | ||
public ParentInfo(final String name, final String relationType, final String uuid) { | ||
super(name, relationType, uuid); | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
.../java/com/netflix/metacat/common/server/usermetadata/ParentChildRelMetadataConstants.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 @@ | ||
package com.netflix.metacat.common.server.usermetadata; | ||
|
||
/** | ||
* ParentChildRelMetadataConstants. | ||
* | ||
* @author yingjianw | ||
*/ | ||
public final class ParentChildRelMetadataConstants { | ||
/** | ||
* During get and create, top level key specified in DefinitionMetadata that indicates the parent child infos. | ||
*/ | ||
public static final String PARENT_CHILD_RELINFO = "parentChildRelationInfo"; | ||
/** | ||
* During create, nested level key specified in DefinitionMetadata['parentChildRelationInfo'] | ||
* that indicate the parent table name. | ||
*/ | ||
public static final String PARENT_NAME = "root_table_name"; | ||
/** | ||
* During create, nested level key specified in DefinitionMetadata['parentChildRelationInfo'] | ||
* that indicates the parent table uuid. | ||
*/ | ||
public static final String PARENT_UUID = "root_table_uuid"; | ||
/** | ||
* During create, nested level key specified in DefinitionMetadata['parentChildRelationInfo'] | ||
* that indicates the child table uuid. | ||
*/ | ||
public static final String CHILD_UUID = "child_table_uuid"; | ||
|
||
/** | ||
* During create, nested level key specified in DefinitionMetadata['parentChildRelationInfo'] | ||
* that indicates relationType. | ||
*/ | ||
public static final String RELATION_TYPE = "relationType"; | ||
|
||
/** | ||
* During get, the nested key specified in DefinitionMetadata[PARENTCHILDRELINFO] that indicates parent infos. | ||
*/ | ||
public static final String PARENT_INFOS = "parentInfos"; | ||
|
||
/** | ||
* During get, the nested key specified in DefinitionMetadata[PARENTCHILDRELINFO] that indicates child infos. | ||
*/ | ||
public static final String CHILD_INFOS = "childInfos"; | ||
|
||
/** | ||
* During get, the nested key specified in DefinitionMetadata[PARENTCHILDRELINFO] | ||
* that indicates if a table is parent. | ||
*/ | ||
public static final String IS_PARENT = "isParent"; | ||
|
||
private ParentChildRelMetadataConstants() { | ||
|
||
} | ||
|
||
} |
106 changes: 106 additions & 0 deletions
106
...in/java/com/netflix/metacat/common/server/usermetadata/ParentChildRelMetadataService.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,106 @@ | ||
package com.netflix.metacat.common.server.usermetadata; | ||
import com.netflix.metacat.common.QualifiedName; | ||
import com.netflix.metacat.common.dto.notifications.ChildInfoDto; | ||
import com.netflix.metacat.common.server.model.ChildInfo; | ||
import com.netflix.metacat.common.server.model.ParentInfo; | ||
|
||
import java.util.Set; | ||
|
||
/** | ||
* Parent-Child Relationship Metadata Service API. | ||
* | ||
* @author yingjianw | ||
*/ | ||
public interface ParentChildRelMetadataService { | ||
/** | ||
* Establishes a parent-child relationship with a specified relation type. | ||
* Currently, exceptions are thrown in the following cases: | ||
* 1. Attempting to create a child table as the parent of another child table. | ||
* 2. Attempting to create a parent table on top of a parent table | ||
* 3. A child table having more than one parent. | ||
* | ||
* @param parentName the name of the parent entity | ||
* @param parentUUID the uuid of the parent | ||
* @param childName the name of the child entity | ||
* @param childUUID the uuid of the child | ||
* @param relationType the type of the relationship | ||
*/ | ||
void createParentChildRelation( | ||
QualifiedName parentName, | ||
String parentUUID, | ||
QualifiedName childName, | ||
String childUUID, | ||
String relationType | ||
); | ||
|
||
/** | ||
* Deletes a parent-child relationship with a specified relation type. | ||
* This function is only called in the recovery process when | ||
* we first create the parent-child relationship but fail to create the table. | ||
* | ||
* @param parentName the name of the parent entity | ||
* @param parentUUID the uuid of the parent | ||
* @param childName the name of the child entity | ||
* @param childUUID the uuid of the child | ||
* @param type the type of the relationship | ||
*/ | ||
void deleteParentChildRelation( | ||
QualifiedName parentName, | ||
String parentUUID, | ||
QualifiedName childName, | ||
String childUUID, | ||
String type | ||
); | ||
|
||
/** | ||
* Renames `oldName` to `newName` in the parentChildRelationship store. | ||
* This involves two steps: | ||
* 1. Rename all records where the child is `oldName` to `newName` | ||
* 2. Rename all records where the parent is `oldName` to `newName` | ||
* | ||
* @param oldName the current name to be renamed | ||
* @param newName the new name to rename to | ||
*/ | ||
void rename( | ||
QualifiedName oldName, | ||
QualifiedName newName | ||
); | ||
|
||
/** | ||
* Removes the entity from the parentChildRelationship store. | ||
* This involves two steps: | ||
* 1. drop all records where the child column = `name` | ||
* 2. drop all records where the parent column = `name` | ||
* @param name the name of the entity to drop | ||
*/ | ||
void drop( | ||
QualifiedName name | ||
); | ||
|
||
/** | ||
* get the set of parent for the input name. | ||
* @param name name | ||
* @return parentInfo | ||
*/ | ||
Set<ParentInfo> getParents( | ||
QualifiedName name | ||
); | ||
|
||
/** | ||
* get the set of children for the input name. | ||
* @param name name | ||
* @return a set of ChildInfo | ||
*/ | ||
Set<ChildInfo> getChildren( | ||
QualifiedName name | ||
); | ||
|
||
/** | ||
* get the set of children dto for the input name. | ||
* @param name name | ||
* @return a set of ChildInfo | ||
*/ | ||
Set<ChildInfoDto> getChildrenDto( | ||
QualifiedName name | ||
); | ||
} |
25 changes: 25 additions & 0 deletions
25
...n/java/com/netflix/metacat/common/server/usermetadata/ParentChildRelServiceException.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,25 @@ | ||
package com.netflix.metacat.common.server.usermetadata; | ||
|
||
/** | ||
* Parent Child Rel Service exception. | ||
*/ | ||
public class ParentChildRelServiceException extends RuntimeException { | ||
/** | ||
* Constructor. | ||
* | ||
* @param m message | ||
*/ | ||
public ParentChildRelServiceException(final String m) { | ||
super(m); | ||
} | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param m message | ||
* @param e exception | ||
*/ | ||
public ParentChildRelServiceException(final String m, final Exception e) { | ||
super(m, e); | ||
} | ||
} |
Oops, something went wrong.