Skip to content

World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.

[#15114] feat(core): Only allow deleting draft domains (#15115)

Jerry Shaodfd2231984a6
diff --git a/api/src/main/java/org/apache/gravitino/domain/DomainOperations.java b/api/src/main/java/org/apache/gravitino/domain/DomainOperations.java
index 7baee51f6d..d925a299d9 100644
--- a/api/src/main/java/org/apache/gravitino/domain/DomainOperations.java
+++ b/api/src/main/java/org/apache/gravitino/domain/DomainOperations.java
@@ -117,11 +117,15 @@ public interface DomainOperations {
throws NoSuchDomainException, DomainAlreadyExistsException, IllegalArgumentException;
/**
- * Deletes a domain. The backing tag and the tags on the member objects are kept.
+ * Deletes a draft domain. The backing tag and the tags on the member objects are kept. A
+ * published domain must be unpublished first. The status is checked before the sub-domains, so
+ * deleting a published domain with sub-domains throws {@link IllegalArgumentException}.
*
* @param name The name of the domain.
- * @return True if the domain is deleted, false if it does not exist.
- * @throws NonEmptyDomainException If the domain has sub-domains.
+ * @return True if the domain is deleted, false if it does not exist or is a draft hidden from the
+ * caller. A hidden draft is not deleted, so false does not mean the domain is absent.
+ * @throws IllegalArgumentException If the domain is published.
+ * @throws NonEmptyDomainException If the domain is a draft with sub-domains.
*/
- boolean deleteDomain(String name) throws NonEmptyDomainException;
+ boolean deleteDomain(String name) throws IllegalArgumentException, NonEmptyDomainException;
}
diff --git a/clients/client-java/src/test/java/org/apache/gravitino/client/integration/test/DomainAuthorizationIT.java b/clients/client-java/src/test/java/org/apache/gravitino/client/integration/test/DomainAuthorizationIT.java
index af74144234..5962f4bc51 100644
--- a/clients/client-java/src/test/java/org/apache/gravitino/client/integration/test/DomainAuthorizationIT.java
+++ b/clients/client-java/src/test/java/org/apache/gravitino/client/integration/test/DomainAuthorizationIT.java
@@ -447,6 +447,7 @@ public class DomainAuthorizationIT extends DomainIT {
.createSubdomain("denied-subdomain", null, null, "denied-tag", true);
assertEquals(creationParent.name(), subdomain.parent().orElseThrow());
assertEquals(created.name(), manager.getDomain(created.name()).name());
+ assertEquals(Domain.Status.DRAFT, managed.unpublish().status());
assertTrue(manager.deleteDomain(child.name()));
assertThrows(NoSuchDomainException.class, () -> metalake.getDomain(child.name()));
}
diff --git a/clients/client-java/src/test/java/org/apache/gravitino/client/integration/test/DomainIT.java b/clients/client-java/src/test/java/org/apache/gravitino/client/integration/test/DomainIT.java
index 78c4344959..6bb7f41270 100644
--- a/clients/client-java/src/test/java/org/apache/gravitino/client/integration/test/DomainIT.java
+++ b/clients/client-java/src/test/java/org/apache/gravitino/client/integration/test/DomainIT.java
@@ -209,6 +209,10 @@ public class DomainIT extends BaseIT {
assertEquals(Domain.Status.PUBLISHED, draft.publish().status());
assertEquals(Domain.Status.DRAFT, replacement.status());
+ // Only a draft domain can be deleted.
+ assertThrows(IllegalArgumentException.class, () -> metalake.deleteDomain(name));
+ assertEquals(Domain.Status.PUBLISHED, metalake.getDomain(name).status());
+ assertEquals(Domain.Status.DRAFT, draft.unpublish().status());
assertTrue(metalake.deleteDomain(name));
assertFalse(metalake.deleteDomain(name));
assertTrue(metalake.deleteDomain(changed.name()));
@@ -248,6 +252,8 @@ public class DomainIT extends BaseIT {
assertTrue(child.updateBackingTag(null).backingTag().isEmpty());
assertEquals("child tag", child.backingTag().orElseThrow());
assertNotNull(metalake.getTag("child tag"));
+ assertThrows(IllegalArgumentException.class, () -> metalake.deleteDomain(parent.name()));
+ parent.unpublish();
assertTrue(metalake.deleteDomain(parent.name()));
}
diff --git a/clients/client-python/gravitino/api/domain/domain_operations.py b/clients/client-python/gravitino/api/domain/domain_operations.py
index fae8894d59..08e7524e0a 100644
--- a/clients/client-python/gravitino/api/domain/domain_operations.py
+++ b/clients/client-python/gravitino/api/domain/domain_operations.py
@@ -71,5 +71,10 @@ class DomainOperations(ABC):
@abstractmethod
def delete_domain(self, name: str) -> bool:
- """Delete, keeping tags; return False if absent, reject nonempty parents."""
+ """Delete a draft domain, keeping tags.
+
+ Return False if the domain is absent or is a draft hidden from the
+ caller; a hidden draft is not deleted, so False does not mean absent.
+ Reject published domains (unpublish first) and nonempty parents.
+ """
raise NotImplementedError
diff --git a/clients/client-python/gravitino/client/gravitino_client.py b/clients/client-python/gravitino/client/gravitino_client.py
index dad141dc9f..14dccfa0ce 100644
--- a/clients/client-python/gravitino/client/gravitino_client.py
+++ b/clients/client-python/gravitino/client/gravitino_client.py
@@ -951,5 +951,9 @@ class GravitinoClient(
return self.get_metalake().alter_domain(name, *changes)
def delete_domain(self, name: str) -> bool:
- """Delete the named domain while preserving tags."""
+ """Delete the named draft domain while preserving tags.
+
+ Returns False if the domain is absent or is a draft hidden from the
+ caller; a hidden draft is not deleted.
+ """
return self.get_metalake().delete_domain(name)
diff --git a/clients/client-python/gravitino/client/gravitino_metalake.py b/clients/client-python/gravitino/client/gravitino_metalake.py
index 2b8492915b..d081f52154 100644
--- a/clients/client-python/gravitino/client/gravitino_metalake.py
+++ b/clients/client-python/gravitino/client/gravitino_metalake.py
@@ -798,7 +798,12 @@ class GravitinoMetalake(
return GenericDomain(self.name(), result.domain(), self.rest_client)
def delete_domain(self, name: str) -> bool:
- """Delete a domain, preserving tags; parents with children are rejected."""
+ """Delete a draft domain, preserving tags.
+
+ Published domains (unpublish first) and parents with children are rejected.
+ Returns False if the domain is absent or is a draft hidden from the caller;
+ a hidden draft is not deleted, so False does not mean absent.
+ """
response = self.rest_client.delete(
domain_path(self.name(), name),
error_handler=DOMAIN_ERROR_HANDLER,
diff --git a/clients/client-python/tests/integration/domain_api_edges_mixin.py b/clients/client-python/tests/integration/domain_api_edges_mixin.py
index 51d1404874..c84dd53fb0 100644
--- a/clients/client-python/tests/integration/domain_api_edges_mixin.py
+++ b/clients/client-python/tests/integration/domain_api_edges_mixin.py
@@ -177,6 +177,7 @@ class DomainApiEdgesMixin:
)
self.assertEqual(creation_parent.name(), subdomain.parent())
self.assertEqual(created.name(), manager.get_domain(created.name()).name())
+ self.assertEqual(Domain.Status.DRAFT, managed.unpublish().status())
self.assertTrue(manager.delete_domain(child.name()))
with self.assertRaises(NoSuchDomainException):
self.lake.get_domain(child.name())
diff --git a/clients/client-python/tests/integration/test_domain.py b/clients/client-python/tests/integration/test_domain.py
index 0e79b97705..b126422966 100644
--- a/clients/client-python/tests/integration/test_domain.py
+++ b/clients/client-python/tests/integration/test_domain.py
@@ -218,6 +218,10 @@ class TestDomain(DomainApiEdgesMixin, IntegrationTestEnv):
replacement = self.lake.create_domain(name, None, None, "replacement", True)
self.assertEqual(Domain.Status.PUBLISHED, draft.publish().status())
self.assertEqual(Domain.Status.DRAFT, replacement.status())
+ # Only a draft domain can be deleted.
+ with self.assertRaises(IllegalArgumentException):
+ self.lake.delete_domain(name)
+ self.assertEqual(Domain.Status.DRAFT, draft.unpublish().status())
self.assertTrue(self.lake.delete_domain(name))
self.assertFalse(self.lake.delete_domain(name))
diff --git a/core/src/main/java/org/apache/gravitino/domain/DomainDispatcher.java b/core/src/main/java/org/apache/gravitino/domain/DomainDispatcher.java
index 243c2b7998..c865aecfb0 100644
--- a/core/src/main/java/org/apache/gravitino/domain/DomainDispatcher.java
+++ b/core/src/main/java/org/apache/gravitino/domain/DomainDispatcher.java
@@ -191,15 +191,19 @@ public interface DomainDispatcher {
throws NoSuchDomainException, DomainAlreadyExistsException, IllegalArgumentException;
/**
- * Deletes a domain, with its parent edge.
+ * Deletes a draft domain, with its parent edge. A published domain must be unpublished first. The
+ * status is checked before the sub-domains, so deleting a published domain with sub-domains
+ * throws {@link IllegalArgumentException}.
*
* @param metalake The name of the metalake.
* @param name The name of the domain.
* @return True if the domain is deleted, false if it does not exist.
* @throws NoSuchMetalakeException If the metalake does not exist.
- * @throws NonEmptyDomainException If the domain has sub-domains.
+ * @throws IllegalArgumentException If the domain is published.
+ * @throws NonEmptyDomainException If the domain is a draft with sub-domains.
*/
- boolean deleteDomain(String metalake, String name) throws NonEmptyDomainException;
+ boolean deleteDomain(String metalake, String name)
+ throws IllegalArgumentException, NonEmptyDomainException;
/**
* Publishes a domain. Publishing a published domain changes nothing.
diff --git a/core/src/main/java/org/apache/gravitino/domain/DomainManager.java b/core/src/main/java/org/apache/gravitino/domain/DomainManager.java
index b279ef1e0a..283518d8f4 100644
--- a/core/src/main/java/org/apache/gravitino/domain/DomainManager.java
+++ b/core/src/main/java/org/apache/gravitino/domain/DomainManager.java
@@ -198,7 +198,8 @@ public class DomainManager implements DomainDispatcher {
}
@Override
- public boolean deleteDomain(String metalake, String name) throws NonEmptyDomainException {
+ public boolean deleteDomain(String metalake, String name)
+ throws IllegalArgumentException, NonEmptyDomainException {
checkMetalake(NameIdentifierUtil.ofMetalake(metalake), entityStore);
try {
// The row lock fences parent changes until the caller check and deletion complete.
@@ -206,9 +207,12 @@ public class DomainManager implements DomainDispatcher {
domainOperations()
.deleteDomain(
NameIdentifierUtil.ofDomain(metalake, name),
- domain ->
- mutationCheck.accept(
- new LockedDomainState(domain, null, Collections.emptyList())));
+ domain -> {
+ LockedDomainState state =
+ new LockedDomainState(domain, null, Collections.emptyList());
+ mutationCheck.accept(state);
+ checkDelete(state);
+ });
return deleted;
} catch (NonEmptyEntityException e) {
throw new NonEmptyDomainException(
@@ -421,6 +425,20 @@ public class DomainManager implements DomainDispatcher {
parent.name());
}
+ /**
+ * Checks a delete against the locked domain: only a draft domain can be deleted. The check runs
+ * before the sub-domain check, so a published domain with sub-domains fails here.
+ *
+ * @param state The locked state of the delete.
+ */
+ @VisibleForTesting
+ static void checkDelete(LockedDomainState state) {
+ Preconditions.checkArgument(
+ state.domain().status() == Domain.Status.DRAFT,
+ "Domain %s cannot be deleted while it is published, unpublish it first",
+ state.domain().name());
+ }
+
/**
* Checks a publish against the locked domains: a sub-domain needs a published parent.
*
diff --git a/core/src/test/java/org/apache/gravitino/domain/TestDomainManager.java b/core/src/test/java/org/apache/gravitino/domain/TestDomainManager.java
index 890ee25a1b..5f87311c3c 100644
--- a/core/src/test/java/org/apache/gravitino/domain/TestDomainManager.java
+++ b/core/src/test/java/org/apache/gravitino/domain/TestDomainManager.java
@@ -164,7 +164,14 @@ public class TestDomainManager {
@AfterEach
public void cleanUp() throws IOException {
DomainEntity[] domains = domainManager.listDomainInfos(METALAKE);
- // Sub-domains first, since a domain with sub-domains cannot be deleted.
+ // Only drafts can be deleted. Sub-domains first, since a domain with published sub-domains
+ // cannot be unpublished and a domain with sub-domains cannot be deleted.
+ Arrays.stream(domains)
+ .filter(domain -> domain.parent().isPresent())
+ .forEach(domain -> domainManager.unpublishDomain(METALAKE, domain.name()));
+ Arrays.stream(domains)
+ .filter(domain -> !domain.parent().isPresent())
+ .forEach(domain -> domainManager.unpublishDomain(METALAKE, domain.name()));
Arrays.stream(domains)
.filter(domain -> domain.parent().isPresent())
.forEach(domain -> domainManager.deleteDomain(METALAKE, domain.name()));
@@ -662,6 +669,31 @@ public class TestDomainManager {
Assertions.assertEquals(0, domainManager.listDomains(METALAKE).length);
}
+ @Test
+ public void testDeleteChecksStatus() {
+ domainManager.createDomain(METALAKE, "Finance", null, null, TagValue.noValue("Finance"), true);
+ domainManager.publishDomain(METALAKE, "Finance");
+
+ // A published domain must be unpublished before it is deleted.
+ IllegalArgumentException e =
+ Assertions.assertThrows(
+ IllegalArgumentException.class, () -> domainManager.deleteDomain(METALAKE, "Finance"));
+ Assertions.assertTrue(e.getMessage().contains("unpublish it first"), e.getMessage());
+ Assertions.assertEquals(
+ Domain.Status.PUBLISHED, domainManager.getDomain(METALAKE, "Finance").status());
+
+ // The status is checked before the sub-domains.
+ domainManager.createSubdomain(
+ METALAKE, "Finance", "Trading", null, null, TagValue.noValue("Trading"), true);
+ Assertions.assertThrows(
+ IllegalArgumentException.class, () -> domainManager.deleteDomain(METALAKE, "Finance"));
+ Assertions.assertTrue(domainManager.deleteDomain(METALAKE, "Trading"));
+
+ domainManager.unpublishDomain(METALAKE, "Finance");
+ Assertions.assertTrue(domainManager.deleteDomain(METALAKE, "Finance"));
+ Assertions.assertFalse(domainManager.deleteDomain(METALAKE, "Finance"));
+ }
+
@Test
public void testPublishAndUnpublish() {
domainManager.createDomain(METALAKE, "Finance", null, null, TagValue.noValue("Finance"), true);
diff --git a/core/src/test/java/org/apache/gravitino/storage/relational/service/TestDomainMetaService.java b/core/src/test/java/org/apache/gravitino/storage/relational/service/TestDomainMetaService.java
index 4d32a5956c..d6012aca7b 100644
--- a/core/src/test/java/org/apache/gravitino/storage/relational/service/TestDomainMetaService.java
+++ b/core/src/test/java/org/apache/gravitino/storage/relational/service/TestDomainMetaService.java
@@ -32,11 +32,13 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
+import java.util.function.UnaryOperator;
import java.util.stream.Collectors;
import org.apache.gravitino.Entity;
import org.apache.gravitino.EntityAlreadyExistsException;
@@ -549,6 +551,54 @@ public class TestDomainMetaService extends TestJDBCBackend {
}
}
+ @TestTemplate
+ public void testDeleteChecksStatusOfLockedRow() throws Exception {
+ createAndInsertMakeLake(METALAKE_NAME);
+ DomainMetaService domainMetaService = DomainMetaService.getInstance();
+ DomainEntity finance = newDomain(METALAKE_NAME, "Finance", null);
+ domainMetaService.insertDomain(finance, false);
+
+ CountDownLatch publishWritten = new CountDownLatch(1);
+ CountDownLatch allowPublishCommit = new CountDownLatch(1);
+ ExecutorService executor = Executors.newFixedThreadPool(2);
+ try {
+ Future<Throwable> publish =
+ alterInOpenTransaction(
+ executor,
+ finance.id(),
+ domain -> domain.toBuilder().withStatus(Domain.Status.PUBLISHED).build(),
+ publishWritten,
+ allowPublishCommit);
+ Assertions.assertTrue(publishWritten.await(30, TimeUnit.SECONDS));
+
+ // This delete reads the domain as a draft before the publish commits, then waits for its
+ // lock. The check, the same as DomainManager.checkDelete, must see the locked, published row.
+ Future<Boolean> delete =
+ executor.submit(
+ () ->
+ domainMetaService.deleteDomain(
+ finance.nameIdentifier(),
+ domain ->
+ Preconditions.checkArgument(
+ domain.status() == Domain.Status.DRAFT,
+ "Domain %s is published",
+ domain.name())));
+ Assertions.assertThrows(TimeoutException.class, () -> delete.get(500, TimeUnit.MILLISECONDS));
+
+ allowPublishCommit.countDown();
+ Assertions.assertNull(publish.get(30, TimeUnit.SECONDS));
+ ExecutionException e =
+ Assertions.assertThrows(ExecutionException.class, () -> delete.get(30, TimeUnit.SECONDS));
+ Assertions.assertInstanceOf(IllegalArgumentException.class, e.getCause());
+ Assertions.assertEquals(
+ Domain.Status.PUBLISHED,
+ domainMetaService.getDomainByIdentifier(finance.nameIdentifier()).status());
+ } finally {
+ allowPublishCommit.countDown();
+ executor.shutdownNow();
+ }
+ }
+
@TestTemplate
public void testDeleteDomainCleansDependentRelations() throws IOException {
createAndInsertMakeLake(METALAKE_NAME);
@@ -1060,11 +1110,24 @@ public class TestDomainMetaService extends TestJDBCBackend {
String comment,
CountDownLatch written,
CountDownLatch allowCommit) {
+ return alterInOpenTransaction(
+ executor,
+ domainId,
+ domain -> domain.toBuilder().withComment(comment).build(),
+ written,
+ allowCommit);
+ }
+
+ private Future<Throwable> alterInOpenTransaction(
+ ExecutorService executor,
+ long domainId,
+ UnaryOperator<DomainEntity> change,
+ CountDownLatch written,
+ CountDownLatch allowCommit) {
DomainPO observedPO = selectDomainPO(domainId);
DomainEntity observed =
DomainPO.fromDomainPO(observedPO, NamespaceUtil.ofDomain(METALAKE_NAME));
- DomainPO alteredPO =
- DomainPO.updateDomainPO(observedPO, observed.toBuilder().withComment(comment).build());
+ DomainPO alteredPO = DomainPO.updateDomainPO(observedPO, change.apply(observed));
return executor.submit(
() -> {
try {
diff --git a/design-docs/domain-design.md b/design-docs/domain-design.md
index dc3ade7c96..34c3f7236d 100644
--- a/design-docs/domain-design.md
+++ b/design-docs/domain-design.md
@@ -96,7 +96,7 @@ C1–C3 keep the hierarchy one level deep and acyclic, so no cycle detection is
- **Attach / move** re-points the child's single edge in one transaction. Attaching to the current parent is a no-op.
- **Detach** removes the current edge; the child becomes top-level.
-- **Delete** is refused while the domain has subdomains. Deleting removes the domain row and its own parent edge. The tag and the tags on assets stay.
+- **Delete** requires the domain to be DRAFT: a published domain must be unpublished first. The status is checked before the children, so a published domain with subdomains fails on its status. A draft domain is refused while it has subdomains. Deleting removes the domain row and its own parent edge. The tag and the tags on assets stay.
- **Membership and scope**: membership comes from backing tags only (see Membership and inheritance), so an asset tagged only `trading` is a member of Trading, not of Finance. A top-level domain's *scope* is its own members plus the members of the subdomains the caller can see; a subdomain's scope is its own members. Member listing and domains of an object report scope, with the relation of each entry; policies follow tags only (see Grants and policies).
### Locking
diff --git a/docs/manage-domains-in-gravitino.md b/docs/manage-domains-in-gravitino.md
index 04a4d51c40..c9af3482e4 100644
--- a/docs/manage-domains-in-gravitino.md
+++ b/docs/manage-domains-in-gravitino.md
@@ -283,8 +283,12 @@ draft = domain.unpublish()
### Delete a Domain
-Delete or detach children before deleting their parent. Members alone do not prevent deletion.
-The operation keeps backing tags and object assignments and returns false if the domain is absent.
+Only a draft domain can be deleted. Unpublish a published domain first; deleting it fails with
+HTTP 400 and `IllegalArgumentException`. Delete or detach children before deleting their parent;
+deleting a draft parent with children fails with HTTP 409 and `NonEmptyDomainException`. The status
+is checked first, so a published parent with children fails with HTTP 400. Members alone do not
+prevent deletion. The operation keeps backing tags and object assignments and returns false if
+the domain is absent.
<Tabs groupId='language' queryString>
<TabItem value="shell" label="REST">
@@ -915,8 +919,9 @@ public class DomainExample {
if (Arrays.asList(model.supportsDomains().listDomains()).contains("Finance")) {
throw new IllegalStateException("Detached membership must stop rolling up");
}
- lake.deleteDomain(child.name());
- lake.deleteDomain(published.name());
+ // Only draft domains can be deleted.
+ lake.deleteDomain(child.unpublish().name());
+ lake.deleteDomain(published.unpublish().name());
// Domain deletion keeps tags and assignments. Remove the assignment explicitly.
model.supportsTags().associateTags(new String[0], new String[] {"planning"});
lake.deleteTag("planning");
@@ -975,8 +980,9 @@ try:
assert len(model.supports_domains().list_domains_info()) == 2
child = child.detach_from_parent()
assert "Finance" not in model.supports_domains().list_domains()
- lake.delete_domain(child.name())
- lake.delete_domain(published.name())
+ # Only draft domains can be deleted.
+ lake.delete_domain(child.unpublish().name())
+ lake.delete_domain(published.unpublish().name())
model.supports_tags().associate_tags([], ["planning"])
lake.delete_tag("planning")
lake.delete_tag("finance")
@@ -1000,15 +1006,15 @@ unsafe segments before sending a request; the server enforces the full naming ru
Backing tags, metadata object names and `nameContains` search text have separate rules.
Encode metadata path parameters individually and supply query values with `--data-urlencode`.
-| HTTP status | Typical Domain behavior |
-| --- | --- |
-| 200 | Success with `code: 0`; empty queries return empty arrays; deleting an absent domain returns `dropped: false`. |
-| 400 | Invalid request: invalid domain names or filters, unsupported member types, or illegal hierarchy/status transition. |
-| 403 | Insufficient permission on a published domain, a required backing tag, or a reverse-lookup object. |
-| 404 | Missing metalake/domain/parent/tag/object, or a draft hidden from the caller. |
-| 409 | Duplicate domain/tag name, a tag that already backs another domain, deleting a parent with children, disabled metalake, or an optimistic lock conflict during domain alteration or deletion. |
-| 415 | Unsupported request Content-Type; the error response uses `application/json`. |
-| 5xx | Server failure; inspect the error response and server log. |
+| HTTP status | Typical Domain behavior |
+| ----------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
+| 200 | Success with `code: 0`; empty queries return empty arrays; deleting an absent domain, or a draft hidden from the caller, returns `dropped: false` and deletes nothing. |
+| 400 | Invalid request: invalid domain names or filters, unsupported member types, illegal hierarchy/status transition, or deleting a published domain. |
+| 403 | Insufficient permission on a published domain, a required backing tag, or a reverse-lookup object. |
+| 404 | Missing metalake/domain/parent/tag/object, or a draft hidden from the caller. `DELETE` on a domain returns 404 only for a missing metalake. |
+| 409 | Duplicate domain/tag name, a tag that already backs another domain, deleting a draft parent with children, disabled metalake, or an optimistic lock conflict during domain alteration or deletion. |
+| 415 | Unsupported request Content-Type; the error response uses `application/json`. |
+| 5xx | Server failure; inspect the error response and server log. |
Authentication failures follow the configured authenticator. The JSON error response contains the
exception type and message; do not infer authorization from empty lists alone. Validation and
diff --git a/docs/open-api/domains.yaml b/docs/open-api/domains.yaml
index 90dd2c9ad7..9f1c2e0a00 100644
--- a/docs/open-api/domains.yaml
+++ b/docs/open-api/domains.yaml
@@ -238,10 +238,12 @@ paths:
summary: Delete a domain
operationId: deleteDomain
description: >-
- Deletes only the domain and its parent edge. The backing tag, its assignments and member
- metadata objects remain unchanged; member objects do not prevent deletion. Deletion does
- not cascade to subdomains: a domain with subdomains fails with HTTP 409,
- NonEmptyDomainException and error code 1005. Returns dropped=false if the domain is absent
+ Deletes only the domain and its parent edge. Only a draft domain can be deleted: deleting a
+ published domain fails with HTTP 400 and IllegalArgumentException; unpublish it first. The
+ backing tag, its assignments and member metadata objects remain unchanged; member objects
+ do not prevent deletion. Deletion does not cascade to subdomains: a draft domain with
+ subdomains fails with HTTP 409, NonEmptyDomainException and error code 1005. The status is checked
+ before the subdomains, so a published domain with subdomains fails with HTTP 400. Returns dropped=false if the domain is absent
or is a draft hidden from the caller; a hidden draft is not deleted.
Requires MANAGE_DOMAIN on the domain, inherited from its current parent or the metalake.
Other permission failures return 403.
@@ -267,7 +269,7 @@ paths:
schema:
$ref: "./openapi.yaml#/components/schemas/ErrorModel"
"409":
- description: The metalake is disabled, the domain has subdomains, or the deletion conflicts with a concurrent update.
+ description: The metalake is disabled, the domain is a draft with subdomains, or the deletion conflicts with a concurrent update.
content:
application/json:
schema:
diff --git a/server/src/test/java/org/apache/gravitino/server/web/rest/TestDomainAuthorizationOperations.java b/server/src/test/java/org/apache/gravitino/server/web/rest/TestDomainAuthorizationOperations.java
index 2f4647fd61..ee4b48f13d 100644
--- a/server/src/test/java/org/apache/gravitino/server/web/rest/TestDomainAuthorizationOperations.java
+++ b/server/src/test/java/org/apache/gravitino/server/web/rest/TestDomainAuthorizationOperations.java
@@ -422,11 +422,13 @@ public class TestDomainAuthorizationOperations extends BaseOperationsTest {
void parentOnlyManagerAndOwnerCanDeleteChildBeforeDetach() {
for (Domain.Status status : Domain.Status.values()) {
current.set(domain("Trading", "Finance", status));
+ // Authorization passes for both statuses; only a draft domain can then be deleted.
+ int expected = status == Domain.Status.DRAFT ? 200 : 400;
allows.add("Finance:MANAGE_DOMAIN");
- expect("DELETE", BASE + "/Trading", null, 200);
+ expect("DELETE", BASE + "/Trading", null, expected);
allows.clear();
owners.add("Finance");
- expect("DELETE", BASE + "/Trading", null, 200);
+ expect("DELETE", BASE + "/Trading", null, expected);
owners.clear();
}
}
diff --git a/server/src/test/java/org/apache/gravitino/server/web/rest/TestDomainOperations.java b/server/src/test/java/org/apache/gravitino/server/web/rest/TestDomainOperations.java
index 294460dfee..5692f1b4a2 100644
--- a/server/src/test/java/org/apache/gravitino/server/web/rest/TestDomainOperations.java
+++ b/server/src/test/java/org/apache/gravitino/server/web/rest/TestDomainOperations.java
@@ -279,6 +279,19 @@ public class TestDomainOperations extends BaseOperationsTest {
}
}
+ @Test
+ public void testDeletePublishedDomain() {
+ when(dispatcher.deleteDomain("test", "Finance"))
+ .thenThrow(
+ new IllegalArgumentException("Domain Finance cannot be deleted while published"));
+ try (Response response = target(ITEM).request().delete()) {
+ assertEquals(400, response.getStatus());
+ ErrorResponse error = response.readEntity(ErrorResponse.class);
+ assertEquals(ErrorConstants.ILLEGAL_ARGUMENTS_CODE, error.getCode());
+ assertEquals(IllegalArgumentException.class.getSimpleName(), error.getType());
+ }
+ }
+
@Test
public void testNullBodies() {
for (String[] route :