Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.parallel.Execution;
import org.junit.jupiter.api.parallel.ExecutionMode;
import org.junit.jupiter.api.parallel.ResourceLock;
import org.openmetadata.it.bootstrap.SharedEntities;
import org.openmetadata.it.factories.DashboardServiceTestFactory;
import org.openmetadata.it.factories.MessagingServiceTestFactory;
Expand Down Expand Up @@ -1148,6 +1149,116 @@ void test_changeDataProductDomain_noAssets(TestNamespace ns) {
assertEquals(domain2.getId(), fetched.getDomains().get(0).getId());
}

@Test
void test_changeDataProductDomain_thenDeleteOriginalDomain_preservesDataProduct(
TestNamespace ns) {
OpenMetadataClient client = SdkClients.adminClient();
Domain domain1 = createTestDomain(ns, "domain_delete_original_1");
Domain domain2 = createTestDomain(ns, "domain_delete_original_2");

DataProduct dataProduct =
createEntity(
new CreateDataProduct()
.withName(ns.prefix("dp_delete_original_domain"))
.withDescription("Data product moved before original domain deletion")
.withDomains(List.of(domain1.getFullyQualifiedName())));

dataProduct.setDomains(List.of(domain2.getEntityReference()));
DataProduct updated = patchEntity(dataProduct.getId().toString(), dataProduct);
assertEquals(1, updated.getDomains().size());
assertEquals(domain2.getId(), updated.getDomains().getFirst().getId());

client
.domains()
.delete(domain1.getId().toString(), Map.of("hardDelete", "true", "recursive", "true"));

DataProduct fetched = client.dataProducts().get(dataProduct.getId().toString(), "domains");
assertFalse(Boolean.TRUE.equals(fetched.getDeleted()));
assertEquals(1, fetched.getDomains().size());
assertEquals(domain2.getId(), fetched.getDomains().getFirst().getId());

ListResponse<DataProduct> listed =
client
.dataProducts()
.list(
new ListParams()
.setFields("domains")
.withDomain(domain2.getFullyQualifiedName())
.withLimit(100));
assertTrue(
listed.getData().stream().anyMatch(dp -> dp.getId().equals(dataProduct.getId())),
"Moved data product must remain visible under its target domain after original domain deletion");
}

@Test
@ResourceLock("MULTI_DOMAIN_RULE")
void test_deleteOneDomainForMultiDomainDataProduct_preservesDataProductUntilLastDomain(
TestNamespace ns) {
OpenMetadataClient client = SdkClients.adminClient();
Domain domain1 = createTestDomain(ns, "multi_domain_delete_1");
Domain domain2 = createTestDomain(ns, "multi_domain_delete_2");

DataProduct dataProduct =
createEntity(
new CreateDataProduct()
.withName(ns.prefix("dp_multi_domain_delete"))
.withDescription("Data product shared by multiple domains")
.withDomains(List.of(domain1.getFullyQualifiedName())));
updateDataProductDomainsWithMultiDomainRuleDisabled(client, dataProduct, domain1, domain2);

DataProduct sharedDataProduct =
client.dataProducts().get(dataProduct.getId().toString(), "domains");
assertEquals(2, sharedDataProduct.getDomains().size());
assertTrue(
sharedDataProduct.getDomains().stream()
.anyMatch(domain -> domain.getId().equals(domain1.getId())));
assertTrue(
sharedDataProduct.getDomains().stream()
.anyMatch(domain -> domain.getId().equals(domain2.getId())));

client
.domains()
.delete(domain1.getId().toString(), Map.of("hardDelete", "true", "recursive", "true"));

DataProduct fetched = client.dataProducts().get(dataProduct.getId().toString(), "domains");
assertFalse(Boolean.TRUE.equals(fetched.getDeleted()));
assertEquals(1, fetched.getDomains().size());
assertEquals(domain2.getId(), fetched.getDomains().getFirst().getId());

ListResponse<DataProduct> listed =
client
.dataProducts()
.list(
new ListParams()
.setFields("domains")
.withDomain(domain2.getFullyQualifiedName())
.withLimit(100));
assertTrue(
listed.getData().stream().anyMatch(dp -> dp.getId().equals(dataProduct.getId())),
"Data product must remain visible under the surviving domain");

client
.domains()
.delete(domain2.getId().toString(), Map.of("hardDelete", "true", "recursive", "true"));

assertThrows(
Exception.class,
() -> client.dataProducts().get(dataProduct.getId().toString(), "domains"));
}

private DataProduct updateDataProductDomainsWithMultiDomainRuleDisabled(
OpenMetadataClient client, DataProduct dataProduct, Domain... domains) {
boolean originalRuleState = EntityRulesUtil.isMultiDomainRuleEnabled(client);
EntityRulesUtil.toggleMultiDomainRule(client, false);
try {
DataProduct update = client.dataProducts().get(dataProduct.getId().toString(), "domains");
update.setDomains(List.of(domains).stream().map(Domain::getEntityReference).toList());
return client.dataProducts().update(dataProduct.getId().toString(), update);
} finally {
EntityRulesUtil.toggleMultiDomainRule(client, originalRuleState);
}
}
Comment thread
gitar-bot[bot] marked this conversation as resolved.

@Test
void test_changeDataProductDomain_withAssetMigration(TestNamespace ns) throws Exception {
// Create two domains
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -855,11 +855,8 @@ private CsvImportResult importCsvRecursive(String entityName, String csvData, bo
void test_csvImportEntityRuleValidation(TestNamespace ns)
throws IOException, InterruptedException {

final String MULTI_DOMAIN_RULE = "Multiple Domains are not allowed";

// Check if rule is currently enabled and store original state
boolean originalRuleState =
EntityRulesUtil.isRuleEnabled(SdkClients.adminClient(), MULTI_DOMAIN_RULE);
boolean originalRuleState = EntityRulesUtil.isMultiDomainRuleEnabled(SdkClients.adminClient());

try {
// Enable the multi-domain rule for testing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3918,7 +3918,9 @@ void test_multipleDomainInheritance(TestNamespace ns) throws Exception {

// Try to disable multi-domain rule for this test
boolean rulesAvailable = false;
boolean originalRuleState = false;
try {
originalRuleState = EntityRulesUtil.isMultiDomainRuleEnabled(client);
EntityRulesUtil.toggleMultiDomainRule(client, false);
rulesAvailable = true;
} catch (Exception e) {
Expand Down Expand Up @@ -4032,13 +4034,13 @@ void test_multipleDomainInheritance(TestNamespace ns) throws Exception {
return searchResponse.contains("\"id\":\"" + tableId + "\"");
});
} finally {
// Re-enable multi-domain rule after test (only if we successfully disabled it)
// Restore multi-domain rule after test (only if we successfully disabled it)
if (rulesAvailable) {
try {
EntityRulesUtil.toggleMultiDomainRule(client, true);
EntityRulesUtil.toggleMultiDomainRule(client, originalRuleState);
} catch (Exception e) {
// Ignore - test is finishing anyway
System.out.println("Could not re-enable multi-domain rule: " + e.getMessage());
System.out.println("Could not restore multi-domain rule: " + e.getMessage());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ public static Settings toggleMultiDomainRule(OpenMetadataClient client, boolean
return toggleRule(client, MULTI_DOMAIN_RULE_NAME, enableRule);
}

public static boolean isMultiDomainRuleEnabled(OpenMetadataClient client) {
return isRuleEnabled(client, MULTI_DOMAIN_RULE_NAME);
}

/**
* Toggle any entity rule by name.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,8 @@ private void updateDataProductDomains() {
origDomains.stream().map(EntityReference::getFullyQualifiedName).toList(),
updatedDomains.stream().map(EntityReference::getFullyQualifiedName).toList());

updateDataProductDomainContainment(origDomains, updatedDomains);

List<CollectionDAO.EntityRelationshipRecord> assetRecords =
daoCollection
.relationshipDAO()
Expand Down Expand Up @@ -902,6 +904,33 @@ private void updateDataProductDomains() {
}
}

private void updateDataProductDomainContainment(
List<EntityReference> oldDomains, List<EntityReference> newDomains) {
List<EntityReference> addedDomains =
diffLists(
newDomains,
oldDomains,
EntityReference::getId,
EntityReference::getId,
Function.identity());
List<EntityReference> removedDomains =
diffLists(
oldDomains,
newDomains,
EntityReference::getId,
EntityReference::getId,
Function.identity());

for (EntityReference domain : removedDomains) {
deleteRelationship(
domain.getId(), DOMAIN, updated.getId(), DATA_PRODUCT, Relationship.CONTAINS);
}
for (EntityReference domain : addedDomains) {
addRelationship(
domain.getId(), updated.getId(), DOMAIN, DATA_PRODUCT, Relationship.CONTAINS);
}
}

private void batchMigrateAssetDomains(
List<CollectionDAO.EntityRelationshipRecord> assetRecords,
List<EntityReference> oldDomains,
Expand Down
Loading
Loading