Skip to content

Commit

Permalink
Add initial implementation for integration
Browse files Browse the repository at this point in the history
  • Loading branch information
Yingjian Wu committed Jun 2, 2024
1 parent eee6b21 commit 515ea7e
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public TableDto create(final QualifiedName name, final TableDto tableDto) {
}

private ObjectNode createParentChildObjectNode(@Nullable final ParentInfo parentInfo,
final Set<ChildInfo> childInfos) {
@Nullable final Set<ChildInfo> childInfos) {
final ObjectMapper objectMapper = new ObjectMapper();
// Create the root ObjectNode
final ObjectNode rootNode = objectMapper.createObjectNode();
Expand All @@ -162,7 +162,7 @@ private ObjectNode createParentChildObjectNode(@Nullable final ParentInfo parent
rootNode.set("parentInfo", parentNode);
}

if (!childInfos.isEmpty()) {
if (childInfos != null && !childInfos.isEmpty()) {
// Convert Set<ChildInfo> to an ArrayNode
final ArrayNode childrenArrayNode = objectMapper.createArrayNode();
for (ChildInfo childInfo : childInfos) {
Expand Down Expand Up @@ -209,13 +209,14 @@ private void saveParentChildRelationship(final QualifiedName child, final TableD
log.info("Attempting to delete child={}, after fail to store parent child relation ship for "
+ "parent={}, relationType={}",
child, child, parent);
delete(child);
this.connectorTableServiceProxy.delete(child);
} catch (Exception deleteException) {
log.error("Fail to deleteTable = {} after failing to update it's parent child relation "
+ "for child={}, parent={}",
child, child, parent, deleteException);
} finally {
throw e;
}
throw e;
}
}
}
Expand Down Expand Up @@ -361,8 +362,9 @@ public TableDto deleteAndReturn(final QualifiedName name, final boolean isMView)
log.error("Fail to recreate table={} with tableDto={} "
+ "after failing to update it's parent child relation",
name, metacatJson.toJsonString(tableDto), tableCreationException);
} finally {
throw e;
}
throw e;
}
// If this is a common view, the storage_table if present
// should also be deleted.
Expand Down Expand Up @@ -476,9 +478,13 @@ public Optional<TableDto> get(final QualifiedName name, final GetTableServicePar
final Set<ChildInfo> childInfos = parentChildRelMetadataService.getChildren(name);
final ObjectNode parentChildRelObjectNode = createParentChildObjectNode(parentInfo, childInfos);
if (definitionMetadata.isPresent()) {
definitionMetadata.get().set("parentChildRelationInfo", parentChildRelObjectNode);
if (!parentChildRelObjectNode.isEmpty()) {
definitionMetadata.get().set("parentChildRelationInfo", parentChildRelObjectNode);
}
} else {
definitionMetadata = Optional.of(parentChildRelObjectNode);
if (!parentChildRelObjectNode.isEmpty()) {
definitionMetadata = Optional.of(parentChildRelObjectNode);
}
}
definitionMetadata.ifPresent(table::setDefinitionMetadata);
}
Expand Down Expand Up @@ -549,8 +555,9 @@ public void rename(
} catch (Exception renameException) {
log.error("Fail to rename from {} to {} after failing to update it's parent child relation",
oldName, newName, renameException);
} finally {
throw e;
}
throw e;
}
userMetadataService.renameDefinitionMetadataKey(oldName, newName);
tagService.renameTableTags(oldName, newName.getTableName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class TableServiceImplSpec extends Specification {
usermetadataService.getDefinitionMetadata(_) >> Optional.empty()
usermetadataService.getDataMetadata(_) >> Optional.empty()
usermetadataService.getDefinitionMetadataWithInterceptor(_,_) >> Optional.empty()
connectorTableServiceProxy = new ConnectorTableServiceProxy(connectorManager, converterUtil)
connectorTableServiceProxy = Spy(new ConnectorTableServiceProxy(connectorManager, converterUtil))
authorizationService = new DefaultAuthorizationService(config)
ownerValidationService = Mock(OwnerValidationService)
parentChildRelSvc = Mock(ParentChildRelMetadataService)
Expand Down Expand Up @@ -273,6 +273,64 @@ class TableServiceImplSpec extends Specification {
0 * ownerValidationService.enforceOwnerValidation(_, _, _)
}

def "Test Create - Clone Table Fail to create parent child relation"() {
given:
def childTableName = QualifiedName.ofTable("clone", "clone", "c")
def createTableDto = new TableDto(
name: childTableName,
definitionMetadata: toObjectNode("{\"parent\":\"clone.clone.p\"}"),
serde: new StorageDto(uri: 's3:/clone/clone/c')
)
when:
service.create(childTableName, createTableDto)
then:
1 * ownerValidationService.extractPotentialOwners(_) >> ["cloneClient"]
1 * ownerValidationService.isUserValid(_) >> true
1 * ownerValidationService.extractPotentialOwnerGroups(_) >> ["cloneClientGroup"]
1 * ownerValidationService.isGroupValid(_) >> true

// When failing to create the parent child relationship:
// we need to try delete the childTable and always throw an exception to the client that
// table is failed to be created
1 * parentChildRelSvc.createParentChildRelation(_, _, _) >> {throw new RuntimeException("Fail to create")}
1 * connectorTableServiceProxy.delete(_)
thrown(RuntimeException)
}

def "Test Rename - Clone Table Fail to update parent child relation"() {
given:
def oldName = QualifiedName.ofTable("clone", "clone", "oldChild")
def newName = QualifiedName.ofTable("clone", "clone", "newChild")
when:
service.rename(oldName, newName, false)

then:
// When failing to update the parent child relationship:
// we need to try rename back the table and
// always throw an exception to the client indicating failure
1 * config.getNoTableRenameOnTags() >> []
1 * parentChildRelSvc.rename(oldName, newName) >> {throw new RuntimeException("Fail to create")}
1 * connectorTableServiceProxy.rename(newName, oldName, _)
thrown(RuntimeException)
}

def "Test Drop - Clone Table Fail to drop parent child relation"() {
given:
def name = QualifiedName.ofTable("clone", "clone", "child")

when:
service.delete(name)

then:
// When failing to delete the parent child relationship:
// we need to try recreate the dropped table and
// always throw an exception to the client indicating failure
1 * config.getNoTableDeleteOnTags() >> []
parentChildRelSvc.drop(name) >> {throw new RuntimeException("Fail to create")}
1 * connectorTableServiceProxy.create(name, _)
thrown(RuntimeException)
}

def "Will not throw on Successful Table Update with Failed Get"() {
given:
def updatedTableDto = new TableDto(name: name, serde: new StorageDto(uri: 's3:/a/b/c'))
Expand Down

0 comments on commit 515ea7e

Please sign in to comment.