From 3a467475ae7e7dc9fe73951a3b99f2ed30e5e26a Mon Sep 17 00:00:00 2001 From: TungYuChiang Date: Wed, 11 Dec 2024 21:18:21 +0800 Subject: [PATCH 01/11] New SupportsTags & TagDispatcher, and TagEventDispatcher(unfinshed) --- .../listener/TagEventDispatcher.java | 37 ++++++ .../apache/gravitino/tag/SupportsTags.java | 106 ++++++++++++++++++ .../apache/gravitino/tag/TagDispatcher.java | 22 ++++ 3 files changed, 165 insertions(+) create mode 100644 core/src/main/java/org/apache/gravitino/listener/TagEventDispatcher.java create mode 100644 core/src/main/java/org/apache/gravitino/tag/SupportsTags.java create mode 100644 core/src/main/java/org/apache/gravitino/tag/TagDispatcher.java diff --git a/core/src/main/java/org/apache/gravitino/listener/TagEventDispatcher.java b/core/src/main/java/org/apache/gravitino/listener/TagEventDispatcher.java new file mode 100644 index 00000000000..3fd3ca5c5fe --- /dev/null +++ b/core/src/main/java/org/apache/gravitino/listener/TagEventDispatcher.java @@ -0,0 +1,37 @@ +package org.apache.gravitino.listener; + +import org.apache.gravitino.MetadataObject; +import org.apache.gravitino.NameIdentifier; +import org.apache.gravitino.exceptions.NoSuchTagException; +import org.apache.gravitino.tag.Tag; +import org.apache.gravitino.tag.TagDispatcher; + +import java.io.IOException; +import java.util.List; + + +public class TagEventDispatcher implements TagDispatcher { + private final EventBus eventBus; + private final TagDispatcher dispatcher; + + public TagEventDispatcher(EventBus eventBus, TagDispatcher dispatcher) { + this.eventBus = eventBus; + this.dispatcher = dispatcher; + } + + + @Override + public String[] listTags(String metalake) { + return new String[0]; + } + + @Override + public Tag[] listTagsInfo(String metalake) { + return new Tag[0]; + } + + @Override + public Tag getTag(String metalake, String name) throws NoSuchTagException { + return null; + } +} diff --git a/core/src/main/java/org/apache/gravitino/tag/SupportsTags.java b/core/src/main/java/org/apache/gravitino/tag/SupportsTags.java new file mode 100644 index 00000000000..fbdbaa4b720 --- /dev/null +++ b/core/src/main/java/org/apache/gravitino/tag/SupportsTags.java @@ -0,0 +1,106 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.gravitino.tag; + +import org.apache.gravitino.MetadataObject; +import org.apache.gravitino.annotation.Evolving; +import org.apache.gravitino.exceptions.NoSuchTagException; + +import java.util.Map; + +/** + * Interface for supporting getting or associate tags to objects. This interface will be mixed with + * metadata objects to provide tag operations. + */ +@Evolving +public interface SupportsTags { + + /** + * List all the tag names for the specific object. + * + * @return The list of tag names. + */ + String[] listTags(String metalake); + + /** + * List all the tags with details for the specific object. + * + * @return The list of tags. + */ + Tag[] listTagsInfo(String metalake); + + /** + * Get a tag by its name for the specific object. + * + * @param name The name of the tag. + * @param metalake The name of the metalake + * @return The tag. + * @throws NoSuchTagException If the tag does not associate with the object. + */ + Tag getTag(String metalake, String name) throws NoSuchTagException; + + /** + * + * @param metalake T + * @param name + * @param comment + * @param properties + * @return + */ + Tag createTag(String metalake, String name, String comment, Map properties); + + /** + * + * @param metalake + * @param name + * @param changes + * @return + */ + Tag alterTag(String metalake, String name, TagChange... changes); + + /** + * + * @param metalake + * @param name + * @return + */ + boolean deleteTag(String metalake, String name); + + /** + * + * @param metalake + * @param name + * @return + */ + MetadataObject[] listMetadataObjectsForTag(String metalake, String name); + + /** + * + * @param metalake + * @param metadataObject + * @return + */ + String[] listTagsForMetadataObject(String metalake, MetadataObject metadataObject); + + + + + +} diff --git a/core/src/main/java/org/apache/gravitino/tag/TagDispatcher.java b/core/src/main/java/org/apache/gravitino/tag/TagDispatcher.java new file mode 100644 index 00000000000..3bb3a7bdbf1 --- /dev/null +++ b/core/src/main/java/org/apache/gravitino/tag/TagDispatcher.java @@ -0,0 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.gravitino.tag; + +public interface TagDispatcher extends SupportsTags{ +} From 8b333746a788e18d62943853204d5ab4977c78f6 Mon Sep 17 00:00:00 2001 From: TungYuChiang Date: Wed, 11 Dec 2024 21:38:08 +0800 Subject: [PATCH 02/11] Add comment in SupportsTags --- .../apache/gravitino/tag/SupportsTags.java | 38 ++++++++++--------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/core/src/main/java/org/apache/gravitino/tag/SupportsTags.java b/core/src/main/java/org/apache/gravitino/tag/SupportsTags.java index fbdbaa4b720..3c36f7e1743 100644 --- a/core/src/main/java/org/apache/gravitino/tag/SupportsTags.java +++ b/core/src/main/java/org/apache/gravitino/tag/SupportsTags.java @@ -57,45 +57,47 @@ public interface SupportsTags { Tag getTag(String metalake, String name) throws NoSuchTagException; /** + * Create a new tag in the specified metalake. * - * @param metalake T - * @param name - * @param comment - * @param properties - * @return + * @param metalake The name of the metalake + * @param name The name of the tag + * @param comment A comment for the new tag. + * @param properties The properties of the tag. + * @return The created tag. */ Tag createTag(String metalake, String name, String comment, Map properties); /** + * Alter an existing tag in the specified metalake * - * @param metalake - * @param name - * @param changes - * @return + * @param metalake The name of the metalake. + * @param name The name of the tag. + * @param changes The changes to apply to the tag. + * @return The updated tag. */ Tag alterTag(String metalake, String name, TagChange... changes); /** * - * @param metalake - * @param name - * @return + * @param metalake The name of the metalake. + * @param name The name of the tag. + * @return True if the tag was successfully deleted, false otherwise */ boolean deleteTag(String metalake, String name); /** * - * @param metalake - * @param name - * @return + * @param metalake The name of the metalake. + * @param name The name of the tag. + * @return The array of metadata objects associated with the specified tag. */ MetadataObject[] listMetadataObjectsForTag(String metalake, String name); /** * - * @param metalake - * @param metadataObject - * @return + * @param metalake The name of the metalake + * @param metadataObject The metadata object for which associated tags + * @return The list of tag names associated with the given metadata object. */ String[] listTagsForMetadataObject(String metalake, MetadataObject metadataObject); From 4e9bd41571238a5f93ce7a147854c074943920bd Mon Sep 17 00:00:00 2001 From: TungYuChiang Date: Thu, 12 Dec 2024 22:23:08 +0800 Subject: [PATCH 03/11] implement event listener support framework for Tag system --- .../java/org/apache/gravitino/Catalog.java | 1 - .../java/org/apache/gravitino/Schema.java | 1 - .../gravitino/{tag => }/SupportsTags.java | 3 +- .../org/apache/gravitino/file/Fileset.java | 2 +- .../org/apache/gravitino/messaging/Topic.java | 2 +- .../org/apache/gravitino/model/Model.java | 2 +- .../java/org/apache/gravitino/rel/Column.java | 2 +- .../java/org/apache/gravitino/rel/Table.java | 2 +- .../gravitino/client/BaseSchemaCatalog.java | 2 +- .../gravitino/client/GenericColumn.java | 2 +- .../gravitino/client/GenericFileset.java | 2 +- .../gravitino/client/GenericSchema.java | 2 +- .../apache/gravitino/client/GenericTopic.java | 2 +- .../client/MetadataObjectTagOperations.java | 2 +- .../gravitino/client/RelationalTable.java | 2 +- .../gravitino/client/TestSupportTags.java | 2 +- .../org/apache/gravitino/GravitinoEnv.java | 13 +- .../listener/TagEventDispatcher.java | 172 ++++++++++++++++-- .../apache/gravitino/tag/SupportsTags.java | 166 +++++++++-------- .../apache/gravitino/tag/TagDispatcher.java | 3 +- .../org/apache/gravitino/tag/TagManager.java | 2 +- .../gravitino/server/GravitinoServer.java | 3 +- .../web/rest/MetadataObjectTagOperations.java | 16 +- .../server/web/rest/TagOperations.java | 28 +-- .../rest/TestMetadataObjectTagOperations.java | 3 +- .../server/web/rest/TestTagOperations.java | 3 +- 26 files changed, 299 insertions(+), 141 deletions(-) rename api/src/main/java/org/apache/gravitino/{tag => }/SupportsTags.java (97%) diff --git a/api/src/main/java/org/apache/gravitino/Catalog.java b/api/src/main/java/org/apache/gravitino/Catalog.java index 7035ed94803..5ec39854063 100644 --- a/api/src/main/java/org/apache/gravitino/Catalog.java +++ b/api/src/main/java/org/apache/gravitino/Catalog.java @@ -27,7 +27,6 @@ import org.apache.gravitino.messaging.TopicCatalog; import org.apache.gravitino.model.ModelCatalog; import org.apache.gravitino.rel.TableCatalog; -import org.apache.gravitino.tag.SupportsTags; /** * The interface of a catalog. The catalog is the second level entity in the Gravitino system, diff --git a/api/src/main/java/org/apache/gravitino/Schema.java b/api/src/main/java/org/apache/gravitino/Schema.java index 7cedf94f694..fca30e1e1b1 100644 --- a/api/src/main/java/org/apache/gravitino/Schema.java +++ b/api/src/main/java/org/apache/gravitino/Schema.java @@ -23,7 +23,6 @@ import javax.annotation.Nullable; import org.apache.gravitino.annotation.Evolving; import org.apache.gravitino.authorization.SupportsRoles; -import org.apache.gravitino.tag.SupportsTags; /** * An interface representing a schema in the {@link Catalog}. A Schema is a basic container of diff --git a/api/src/main/java/org/apache/gravitino/tag/SupportsTags.java b/api/src/main/java/org/apache/gravitino/SupportsTags.java similarity index 97% rename from api/src/main/java/org/apache/gravitino/tag/SupportsTags.java rename to api/src/main/java/org/apache/gravitino/SupportsTags.java index 0a909c4c8cb..503975ffa60 100644 --- a/api/src/main/java/org/apache/gravitino/tag/SupportsTags.java +++ b/api/src/main/java/org/apache/gravitino/SupportsTags.java @@ -17,11 +17,12 @@ * under the License. */ -package org.apache.gravitino.tag; +package org.apache.gravitino; import org.apache.gravitino.annotation.Evolving; import org.apache.gravitino.exceptions.NoSuchTagException; import org.apache.gravitino.exceptions.TagAlreadyAssociatedException; +import org.apache.gravitino.tag.Tag; /** * Interface for supporting getting or associate tags to objects. This interface will be mixed with diff --git a/api/src/main/java/org/apache/gravitino/file/Fileset.java b/api/src/main/java/org/apache/gravitino/file/Fileset.java index 6ada5f8c47b..2e8d1499793 100644 --- a/api/src/main/java/org/apache/gravitino/file/Fileset.java +++ b/api/src/main/java/org/apache/gravitino/file/Fileset.java @@ -23,10 +23,10 @@ import javax.annotation.Nullable; import org.apache.gravitino.Auditable; import org.apache.gravitino.Namespace; +import org.apache.gravitino.SupportsTags; import org.apache.gravitino.annotation.Evolving; import org.apache.gravitino.authorization.SupportsRoles; import org.apache.gravitino.credential.SupportsCredentials; -import org.apache.gravitino.tag.SupportsTags; /** * An interface representing a fileset under a schema {@link Namespace}. A fileset is a virtual diff --git a/api/src/main/java/org/apache/gravitino/messaging/Topic.java b/api/src/main/java/org/apache/gravitino/messaging/Topic.java index 7162c45d2b0..5f6d75673c0 100644 --- a/api/src/main/java/org/apache/gravitino/messaging/Topic.java +++ b/api/src/main/java/org/apache/gravitino/messaging/Topic.java @@ -23,9 +23,9 @@ import javax.annotation.Nullable; import org.apache.gravitino.Auditable; import org.apache.gravitino.Namespace; +import org.apache.gravitino.SupportsTags; import org.apache.gravitino.annotation.Evolving; import org.apache.gravitino.authorization.SupportsRoles; -import org.apache.gravitino.tag.SupportsTags; /** * An interface representing a topic under a schema {@link Namespace}. A topic is a message queue diff --git a/api/src/main/java/org/apache/gravitino/model/Model.java b/api/src/main/java/org/apache/gravitino/model/Model.java index fab4e0d53cc..30471e47d80 100644 --- a/api/src/main/java/org/apache/gravitino/model/Model.java +++ b/api/src/main/java/org/apache/gravitino/model/Model.java @@ -22,9 +22,9 @@ import java.util.Map; import org.apache.gravitino.Auditable; import org.apache.gravitino.Namespace; +import org.apache.gravitino.SupportsTags; import org.apache.gravitino.annotation.Evolving; import org.apache.gravitino.authorization.SupportsRoles; -import org.apache.gravitino.tag.SupportsTags; /** * An interface representing an ML model under a schema {@link Namespace}. A model is a metadata diff --git a/api/src/main/java/org/apache/gravitino/rel/Column.java b/api/src/main/java/org/apache/gravitino/rel/Column.java index e508970fa50..4e5e17e0cea 100644 --- a/api/src/main/java/org/apache/gravitino/rel/Column.java +++ b/api/src/main/java/org/apache/gravitino/rel/Column.java @@ -23,11 +23,11 @@ import java.util.Map; import java.util.Objects; import org.apache.gravitino.NameIdentifier; +import org.apache.gravitino.SupportsTags; import org.apache.gravitino.annotation.Evolving; import org.apache.gravitino.rel.expressions.Expression; import org.apache.gravitino.rel.expressions.FunctionExpression; import org.apache.gravitino.rel.types.Type; -import org.apache.gravitino.tag.SupportsTags; /** * An interface representing a column of a {@link Table}. It defines basic properties of a column, diff --git a/api/src/main/java/org/apache/gravitino/rel/Table.java b/api/src/main/java/org/apache/gravitino/rel/Table.java index 8bb9e3c1206..d37c8eea33a 100644 --- a/api/src/main/java/org/apache/gravitino/rel/Table.java +++ b/api/src/main/java/org/apache/gravitino/rel/Table.java @@ -23,6 +23,7 @@ import javax.annotation.Nullable; import org.apache.gravitino.Auditable; import org.apache.gravitino.Namespace; +import org.apache.gravitino.SupportsTags; import org.apache.gravitino.annotation.Evolving; import org.apache.gravitino.authorization.SupportsRoles; import org.apache.gravitino.rel.expressions.distributions.Distribution; @@ -32,7 +33,6 @@ import org.apache.gravitino.rel.expressions.transforms.Transforms; import org.apache.gravitino.rel.indexes.Index; import org.apache.gravitino.rel.indexes.Indexes; -import org.apache.gravitino.tag.SupportsTags; /** * An interface representing a table in a {@link Namespace}. It defines the basic properties of a diff --git a/clients/client-java/src/main/java/org/apache/gravitino/client/BaseSchemaCatalog.java b/clients/client-java/src/main/java/org/apache/gravitino/client/BaseSchemaCatalog.java index d0a4d9db121..5ff773c4f9a 100644 --- a/clients/client-java/src/main/java/org/apache/gravitino/client/BaseSchemaCatalog.java +++ b/clients/client-java/src/main/java/org/apache/gravitino/client/BaseSchemaCatalog.java @@ -31,6 +31,7 @@ import org.apache.gravitino.Schema; import org.apache.gravitino.SchemaChange; import org.apache.gravitino.SupportsSchemas; +import org.apache.gravitino.SupportsTags; import org.apache.gravitino.authorization.SupportsRoles; import org.apache.gravitino.dto.AuditDTO; import org.apache.gravitino.dto.CatalogDTO; @@ -45,7 +46,6 @@ import org.apache.gravitino.exceptions.NonEmptySchemaException; import org.apache.gravitino.exceptions.SchemaAlreadyExistsException; import org.apache.gravitino.rest.RESTUtils; -import org.apache.gravitino.tag.SupportsTags; import org.apache.gravitino.tag.Tag; /** diff --git a/clients/client-java/src/main/java/org/apache/gravitino/client/GenericColumn.java b/clients/client-java/src/main/java/org/apache/gravitino/client/GenericColumn.java index aacf022e958..2dca80288c6 100644 --- a/clients/client-java/src/main/java/org/apache/gravitino/client/GenericColumn.java +++ b/clients/client-java/src/main/java/org/apache/gravitino/client/GenericColumn.java @@ -22,12 +22,12 @@ import java.util.Objects; import org.apache.gravitino.MetadataObject; import org.apache.gravitino.MetadataObjects; +import org.apache.gravitino.SupportsTags; import org.apache.gravitino.exceptions.NoSuchTagException; import org.apache.gravitino.exceptions.TagAlreadyAssociatedException; import org.apache.gravitino.rel.Column; import org.apache.gravitino.rel.expressions.Expression; import org.apache.gravitino.rel.types.Type; -import org.apache.gravitino.tag.SupportsTags; import org.apache.gravitino.tag.Tag; /** Represents a generic column. */ diff --git a/clients/client-java/src/main/java/org/apache/gravitino/client/GenericFileset.java b/clients/client-java/src/main/java/org/apache/gravitino/client/GenericFileset.java index 6e587b11554..0134a2972ef 100644 --- a/clients/client-java/src/main/java/org/apache/gravitino/client/GenericFileset.java +++ b/clients/client-java/src/main/java/org/apache/gravitino/client/GenericFileset.java @@ -26,13 +26,13 @@ import org.apache.gravitino.MetadataObject; import org.apache.gravitino.MetadataObjects; import org.apache.gravitino.Namespace; +import org.apache.gravitino.SupportsTags; import org.apache.gravitino.authorization.SupportsRoles; import org.apache.gravitino.credential.Credential; import org.apache.gravitino.credential.SupportsCredentials; import org.apache.gravitino.dto.file.FilesetDTO; import org.apache.gravitino.exceptions.NoSuchTagException; import org.apache.gravitino.file.Fileset; -import org.apache.gravitino.tag.SupportsTags; import org.apache.gravitino.tag.Tag; /** Represents a generic fileset. */ diff --git a/clients/client-java/src/main/java/org/apache/gravitino/client/GenericSchema.java b/clients/client-java/src/main/java/org/apache/gravitino/client/GenericSchema.java index 22af2e3a271..7fdcf155b20 100644 --- a/clients/client-java/src/main/java/org/apache/gravitino/client/GenericSchema.java +++ b/clients/client-java/src/main/java/org/apache/gravitino/client/GenericSchema.java @@ -23,10 +23,10 @@ import org.apache.gravitino.MetadataObject; import org.apache.gravitino.MetadataObjects; import org.apache.gravitino.Schema; +import org.apache.gravitino.SupportsTags; import org.apache.gravitino.authorization.SupportsRoles; import org.apache.gravitino.dto.SchemaDTO; import org.apache.gravitino.exceptions.NoSuchTagException; -import org.apache.gravitino.tag.SupportsTags; import org.apache.gravitino.tag.Tag; /** Represents a generic schema. */ diff --git a/clients/client-java/src/main/java/org/apache/gravitino/client/GenericTopic.java b/clients/client-java/src/main/java/org/apache/gravitino/client/GenericTopic.java index 0048d489ce4..48993c978c3 100644 --- a/clients/client-java/src/main/java/org/apache/gravitino/client/GenericTopic.java +++ b/clients/client-java/src/main/java/org/apache/gravitino/client/GenericTopic.java @@ -25,11 +25,11 @@ import org.apache.gravitino.MetadataObject; import org.apache.gravitino.MetadataObjects; import org.apache.gravitino.Namespace; +import org.apache.gravitino.SupportsTags; import org.apache.gravitino.authorization.SupportsRoles; import org.apache.gravitino.dto.messaging.TopicDTO; import org.apache.gravitino.exceptions.NoSuchTagException; import org.apache.gravitino.messaging.Topic; -import org.apache.gravitino.tag.SupportsTags; import org.apache.gravitino.tag.Tag; /** Represents a generic topic. */ diff --git a/clients/client-java/src/main/java/org/apache/gravitino/client/MetadataObjectTagOperations.java b/clients/client-java/src/main/java/org/apache/gravitino/client/MetadataObjectTagOperations.java index 2ac84bdbf55..1fca834f7ab 100644 --- a/clients/client-java/src/main/java/org/apache/gravitino/client/MetadataObjectTagOperations.java +++ b/clients/client-java/src/main/java/org/apache/gravitino/client/MetadataObjectTagOperations.java @@ -25,13 +25,13 @@ import java.util.Locale; import org.apache.commons.lang3.StringUtils; import org.apache.gravitino.MetadataObject; +import org.apache.gravitino.SupportsTags; import org.apache.gravitino.dto.requests.TagsAssociateRequest; import org.apache.gravitino.dto.responses.NameListResponse; import org.apache.gravitino.dto.responses.TagListResponse; import org.apache.gravitino.dto.responses.TagResponse; import org.apache.gravitino.exceptions.NoSuchTagException; import org.apache.gravitino.rest.RESTUtils; -import org.apache.gravitino.tag.SupportsTags; import org.apache.gravitino.tag.Tag; /** diff --git a/clients/client-java/src/main/java/org/apache/gravitino/client/RelationalTable.java b/clients/client-java/src/main/java/org/apache/gravitino/client/RelationalTable.java index e2ace7de278..8c526fc2a5f 100644 --- a/clients/client-java/src/main/java/org/apache/gravitino/client/RelationalTable.java +++ b/clients/client-java/src/main/java/org/apache/gravitino/client/RelationalTable.java @@ -33,6 +33,7 @@ import org.apache.gravitino.MetadataObject; import org.apache.gravitino.MetadataObjects; import org.apache.gravitino.Namespace; +import org.apache.gravitino.SupportsTags; import org.apache.gravitino.authorization.SupportsRoles; import org.apache.gravitino.dto.rel.TableDTO; import org.apache.gravitino.dto.rel.partitions.PartitionDTO; @@ -53,7 +54,6 @@ import org.apache.gravitino.rel.indexes.Index; import org.apache.gravitino.rel.partitions.Partition; import org.apache.gravitino.rest.RESTUtils; -import org.apache.gravitino.tag.SupportsTags; import org.apache.gravitino.tag.Tag; /** Represents a relational table. */ diff --git a/clients/client-java/src/test/java/org/apache/gravitino/client/TestSupportTags.java b/clients/client-java/src/test/java/org/apache/gravitino/client/TestSupportTags.java index 3d903a972c7..601f02380de 100644 --- a/clients/client-java/src/test/java/org/apache/gravitino/client/TestSupportTags.java +++ b/clients/client-java/src/test/java/org/apache/gravitino/client/TestSupportTags.java @@ -30,6 +30,7 @@ import org.apache.gravitino.MetadataObjects; import org.apache.gravitino.Namespace; import org.apache.gravitino.Schema; +import org.apache.gravitino.SupportsTags; import org.apache.gravitino.dto.AuditDTO; import org.apache.gravitino.dto.SchemaDTO; import org.apache.gravitino.dto.file.FilesetDTO; @@ -49,7 +50,6 @@ import org.apache.gravitino.rel.Column; import org.apache.gravitino.rel.Table; import org.apache.gravitino.rel.types.Types; -import org.apache.gravitino.tag.SupportsTags; import org.apache.gravitino.tag.Tag; import org.apache.hc.core5.http.Method; import org.junit.jupiter.api.Assertions; diff --git a/core/src/main/java/org/apache/gravitino/GravitinoEnv.java b/core/src/main/java/org/apache/gravitino/GravitinoEnv.java index db6ddc235fd..3024d92a5ad 100644 --- a/core/src/main/java/org/apache/gravitino/GravitinoEnv.java +++ b/core/src/main/java/org/apache/gravitino/GravitinoEnv.java @@ -62,6 +62,7 @@ import org.apache.gravitino.listener.PartitionEventDispatcher; import org.apache.gravitino.listener.SchemaEventDispatcher; import org.apache.gravitino.listener.TableEventDispatcher; +import org.apache.gravitino.listener.TagEventDispatcher; import org.apache.gravitino.listener.TopicEventDispatcher; import org.apache.gravitino.lock.LockManager; import org.apache.gravitino.metalake.MetalakeDispatcher; @@ -71,6 +72,7 @@ import org.apache.gravitino.metrics.source.JVMMetricsSource; import org.apache.gravitino.storage.IdGenerator; import org.apache.gravitino.storage.RandomIdGenerator; +import org.apache.gravitino.tag.TagDispatcher; import org.apache.gravitino.tag.TagManager; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -108,6 +110,8 @@ public class GravitinoEnv { private CredentialManager credentialManager; + private TagDispatcher tagDispatcher; + private AccessControlDispatcher accessControlDispatcher; private IdGenerator idGenerator; @@ -321,12 +325,12 @@ public AccessControlDispatcher accessControlDispatcher() { } /** - * Get the TagManager associated with the Gravitino environment. + * Get the tagDispatcher associated with the Gravitino environment. * - * @return The TagManager instance. + * @return The tagDispatcher instance. */ - public TagManager tagManager() { - return tagManager; + public TagDispatcher tagDispatcher() { + return tagDispatcher; } /** @@ -499,5 +503,6 @@ private void initGravitinoServerComponents() { // Tag manager this.tagManager = new TagManager(idGenerator, entityStore); + this.tagDispatcher = new TagEventDispatcher(eventBus, tagManager); } } diff --git a/core/src/main/java/org/apache/gravitino/listener/TagEventDispatcher.java b/core/src/main/java/org/apache/gravitino/listener/TagEventDispatcher.java index 3fd3ca5c5fe..d0977b5386e 100644 --- a/core/src/main/java/org/apache/gravitino/listener/TagEventDispatcher.java +++ b/core/src/main/java/org/apache/gravitino/listener/TagEventDispatcher.java @@ -1,37 +1,173 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ package org.apache.gravitino.listener; +import java.util.Map; import org.apache.gravitino.MetadataObject; -import org.apache.gravitino.NameIdentifier; import org.apache.gravitino.exceptions.NoSuchTagException; import org.apache.gravitino.tag.Tag; +import org.apache.gravitino.tag.TagChange; import org.apache.gravitino.tag.TagDispatcher; -import java.io.IOException; -import java.util.List; +public class TagEventDispatcher implements TagDispatcher { + @SuppressWarnings("unused") + private final EventBus eventBus; + @SuppressWarnings("unused") + private final TagDispatcher dispatcher; -public class TagEventDispatcher implements TagDispatcher { - private final EventBus eventBus; - private final TagDispatcher dispatcher; + public TagEventDispatcher(EventBus eventBus, TagDispatcher dispatcher) { + this.eventBus = eventBus; + this.dispatcher = dispatcher; + } + + @Override + public String[] listTags(String metalake) { + // TODO: listTagsPreEvent + try { + // TODO: listTagsEvent + } catch (Exception e) { + // TODO: listTagFailureEvent + throw e; + } + return new String[0]; + } + + @Override + public Tag[] listTagsInfo(String metalake) { + // TODO: listTagsInfoPreEvent + try { + // TODO: listTagsInfoEvent + } catch (Exception e) { + // TODO: listTagsInfoFailureEvent + throw e; + } + return new Tag[0]; + } + + @Override + public Tag getTag(String metalake, String name) throws NoSuchTagException { + // TODO: getTagPreEvent + try { + // TODO: getTagEvent + } catch (NoSuchTagException e) { + // TODO: getTagFailureEvent + throw e; + } + return null; + } - public TagEventDispatcher(EventBus eventBus, TagDispatcher dispatcher) { - this.eventBus = eventBus; - this.dispatcher = dispatcher; + @Override + public Tag createTag( + String metalake, String name, String comment, Map properties) { + // TODO: createTagPreEvent + try { + // TODO: createTagEvent + } catch (Exception e) { + // TODO: createTagFailureEvent + throw e; } + return null; + } + @Override + public Tag alterTag(String metalake, String name, TagChange... changes) { + // TODO: alterTagPreEvent + try { + // TODO: alterTagEvent + } catch (Exception e) { + // TODO: alterTagFailureEvent + throw e; + } + return null; + } + + @Override + public boolean deleteTag(String metalake, String name) { + // TODO: deleteTagPreEvent + try { + // TODO: deleteTagEvent + } catch (Exception e) { + // TODO: deleteTagFailureEvent + throw e; + } + return false; + } + + @Override + public MetadataObject[] listMetadataObjectsForTag(String metalake, String name) { + // TODO: listMetadataObjectsForTagPreEvent + try { + // TODO: listMetadataObjectsForTagEvent + } catch (Exception e) { + // TODO: listMetadataObjectsForTagFailureEvent + throw e; + } + return new MetadataObject[0]; + } + + @Override + public String[] listTagsForMetadataObject(String metalake, MetadataObject metadataObject) { + // TODO: listTagsForMetadataObjectPreEvent + try { + // TODO: listTagsForMetadataObjectEvent + } catch (Exception e) { + // TODO: listTagsForMetadataObjectFailureEvent + throw e; + } + return new String[0]; + } - @Override - public String[] listTags(String metalake) { - return new String[0]; + @Override + public Tag[] listTagsInfoForMetadataObject(String metalake, MetadataObject metadataObject) { + // TODO: listTagsInfoForMetadataObjectPreEvent + try { + // TODO: listTagsInfoForMetadataObjectEvent + } catch (Exception e) { + // TODO: listTagsInfoForMetadataObjectFailureEvent + throw e; } + return new Tag[0]; + } - @Override - public Tag[] listTagsInfo(String metalake) { - return new Tag[0]; + @Override + public String[] associateTagsForMetadataObject( + String metalake, MetadataObject metadataObject, String[] tagsToAdd, String[] tagsToRemove) { + // TODO: associateTagsForMetadataObjectPreEvent + try { + // TODO: associateTagsForMetadataObjectEvent + } catch (Exception e) { + // TODO: associateTagsForMetadataObjectFailureEvent + throw e; } + return new String[0]; + } - @Override - public Tag getTag(String metalake, String name) throws NoSuchTagException { - return null; + @Override + public Tag getTagForMetadataObject(String metalake, MetadataObject metadataObject, String name) { + // TODO: getTagForMetadataObjectPreEvent + try { + // TODO: getTagForMetadataObjectEvent + } catch (Exception e) { + // TODO: getTagForMetadataObjectFailureEvent + throw e; } + return null; + } } diff --git a/core/src/main/java/org/apache/gravitino/tag/SupportsTags.java b/core/src/main/java/org/apache/gravitino/tag/SupportsTags.java index 3c36f7e1743..ffc111389e6 100644 --- a/core/src/main/java/org/apache/gravitino/tag/SupportsTags.java +++ b/core/src/main/java/org/apache/gravitino/tag/SupportsTags.java @@ -19,12 +19,11 @@ package org.apache.gravitino.tag; +import java.util.Map; import org.apache.gravitino.MetadataObject; import org.apache.gravitino.annotation.Evolving; import org.apache.gravitino.exceptions.NoSuchTagException; -import java.util.Map; - /** * Interface for supporting getting or associate tags to objects. This interface will be mixed with * metadata objects to provide tag operations. @@ -32,77 +31,94 @@ @Evolving public interface SupportsTags { - /** - * List all the tag names for the specific object. - * - * @return The list of tag names. - */ - String[] listTags(String metalake); - - /** - * List all the tags with details for the specific object. - * - * @return The list of tags. - */ - Tag[] listTagsInfo(String metalake); - - /** - * Get a tag by its name for the specific object. - * - * @param name The name of the tag. - * @param metalake The name of the metalake - * @return The tag. - * @throws NoSuchTagException If the tag does not associate with the object. - */ - Tag getTag(String metalake, String name) throws NoSuchTagException; - - /** - * Create a new tag in the specified metalake. - * - * @param metalake The name of the metalake - * @param name The name of the tag - * @param comment A comment for the new tag. - * @param properties The properties of the tag. - * @return The created tag. - */ - Tag createTag(String metalake, String name, String comment, Map properties); - - /** - * Alter an existing tag in the specified metalake - * - * @param metalake The name of the metalake. - * @param name The name of the tag. - * @param changes The changes to apply to the tag. - * @return The updated tag. - */ - Tag alterTag(String metalake, String name, TagChange... changes); - - /** - * - * @param metalake The name of the metalake. - * @param name The name of the tag. - * @return True if the tag was successfully deleted, false otherwise - */ - boolean deleteTag(String metalake, String name); - - /** - * - * @param metalake The name of the metalake. - * @param name The name of the tag. - * @return The array of metadata objects associated with the specified tag. - */ - MetadataObject[] listMetadataObjectsForTag(String metalake, String name); - - /** - * - * @param metalake The name of the metalake - * @param metadataObject The metadata object for which associated tags - * @return The list of tag names associated with the given metadata object. - */ - String[] listTagsForMetadataObject(String metalake, MetadataObject metadataObject); - - - - - + /** + * List all the tag names for the specific object. + * + * @return The list of tag names. + */ + String[] listTags(String metalake); + + /** + * List all the tags with details for the specific object. + * + * @return The list of tags. + */ + Tag[] listTagsInfo(String metalake); + + /** + * Get a tag by its name for the specific object. + * + * @param name The name of the tag. + * @param metalake The name of the metalake + * @return The tag. + * @throws NoSuchTagException If the tag does not associate with the object. + */ + Tag getTag(String metalake, String name) throws NoSuchTagException; + + /** + * Create a new tag in the specified metalake. + * + * @param metalake The name of the metalake + * @param name The name of the tag + * @param comment A comment for the new tag. + * @param properties The properties of the tag. + * @return The created tag. + */ + Tag createTag(String metalake, String name, String comment, Map properties); + + /** + * Alter an existing tag in the specified metalake + * + * @param metalake The name of the metalake. + * @param name The name of the tag. + * @param changes The changes to apply to the tag. + * @return The updated tag. + */ + Tag alterTag(String metalake, String name, TagChange... changes); + + /** + * @param metalake The name of the metalake. + * @param name The name of the tag. + * @return True if the tag was successfully deleted, false otherwise + */ + boolean deleteTag(String metalake, String name); + + /** + * @param metalake The name of the metalake. + * @param name The name of the tag. + * @return The array of metadata objects associated with the specified tag. + */ + MetadataObject[] listMetadataObjectsForTag(String metalake, String name); + + /** + * @param metalake The name of the metalake + * @param metadataObject The metadata object for which associated tags + * @return The list of tag names associated with the given metadata object. + */ + String[] listTagsForMetadataObject(String metalake, MetadataObject metadataObject); + + /** + * @param metalake + * @param metadataObject + * @return + */ + Tag[] listTagsInfoForMetadataObject(String metalake, MetadataObject metadataObject); + + /** + * @param metalake + * @param metadataObject + * @param tagsToAdd + * @param tagsToRemove + * @return + */ + String[] associateTagsForMetadataObject( + String metalake, MetadataObject metadataObject, String[] tagsToAdd, String[] tagsToRemove); + + /** + * @param metalake + * @param metadataObject + * @param name + * @return + */ + Tag getTagForMetadataObject(String metalake, MetadataObject metadataObject, String name); } diff --git a/core/src/main/java/org/apache/gravitino/tag/TagDispatcher.java b/core/src/main/java/org/apache/gravitino/tag/TagDispatcher.java index 3bb3a7bdbf1..57e36bcb5d9 100644 --- a/core/src/main/java/org/apache/gravitino/tag/TagDispatcher.java +++ b/core/src/main/java/org/apache/gravitino/tag/TagDispatcher.java @@ -18,5 +18,4 @@ */ package org.apache.gravitino.tag; -public interface TagDispatcher extends SupportsTags{ -} +public interface TagDispatcher extends SupportsTags {} diff --git a/core/src/main/java/org/apache/gravitino/tag/TagManager.java b/core/src/main/java/org/apache/gravitino/tag/TagManager.java index 30fa658130e..f7932fe2607 100644 --- a/core/src/main/java/org/apache/gravitino/tag/TagManager.java +++ b/core/src/main/java/org/apache/gravitino/tag/TagManager.java @@ -51,7 +51,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class TagManager { +public class TagManager implements TagDispatcher { private static final Logger LOG = LoggerFactory.getLogger(TagManager.class); diff --git a/server/src/main/java/org/apache/gravitino/server/GravitinoServer.java b/server/src/main/java/org/apache/gravitino/server/GravitinoServer.java index 554791fff3c..486b9e735a8 100644 --- a/server/src/main/java/org/apache/gravitino/server/GravitinoServer.java +++ b/server/src/main/java/org/apache/gravitino/server/GravitinoServer.java @@ -47,7 +47,7 @@ import org.apache.gravitino.server.web.mapper.JsonParseExceptionMapper; import org.apache.gravitino.server.web.mapper.JsonProcessingExceptionMapper; import org.apache.gravitino.server.web.ui.WebUIFilter; -import org.apache.gravitino.tag.TagManager; +import org.apache.gravitino.tag.TagDispatcher; import org.glassfish.hk2.utilities.binding.AbstractBinder; import org.glassfish.jersey.CommonProperties; import org.glassfish.jersey.jackson.JacksonFeature; @@ -116,6 +116,7 @@ protected void configure() { bind(gravitinoEnv.topicDispatcher()).to(TopicDispatcher.class).ranked(1); bind(gravitinoEnv.tagManager()).to(TagManager.class).ranked(1); bind(gravitinoEnv.credentialManager()).to(CredentialManager.class).ranked(1); + bind(gravitinoEnv.tagDispatcher()).to(TagDispatcher.class).ranked(1); } }); register(JsonProcessingExceptionMapper.class); diff --git a/server/src/main/java/org/apache/gravitino/server/web/rest/MetadataObjectTagOperations.java b/server/src/main/java/org/apache/gravitino/server/web/rest/MetadataObjectTagOperations.java index c8668d225f8..9c3eda52b38 100644 --- a/server/src/main/java/org/apache/gravitino/server/web/rest/MetadataObjectTagOperations.java +++ b/server/src/main/java/org/apache/gravitino/server/web/rest/MetadataObjectTagOperations.java @@ -50,7 +50,7 @@ import org.apache.gravitino.metrics.MetricNames; import org.apache.gravitino.server.web.Utils; import org.apache.gravitino.tag.Tag; -import org.apache.gravitino.tag.TagManager; +import org.apache.gravitino.tag.TagDispatcher; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -58,13 +58,13 @@ public class MetadataObjectTagOperations { private static final Logger LOG = LoggerFactory.getLogger(MetadataObjectTagOperations.class); - private final TagManager tagManager; + private final TagDispatcher tagDispatcher; @Context private HttpServletRequest httpRequest; @Inject - public MetadataObjectTagOperations(TagManager tagManager) { - this.tagManager = tagManager; + public MetadataObjectTagOperations(TagDispatcher tagDispatcher) { + this.tagDispatcher = tagDispatcher; } // TagOperations will reuse this class to be compatible with legacy interfaces. @@ -164,7 +164,7 @@ public Response listTagsForMetadataObject( fullName, MetadataObject.Type.valueOf(type.toUpperCase(Locale.ROOT))); List tags = Lists.newArrayList(); - Tag[] nonInheritedTags = tagManager.listTagsInfoForMetadataObject(metalake, object); + Tag[] nonInheritedTags = tagDispatcher.listTagsInfoForMetadataObject(metalake, object); if (ArrayUtils.isNotEmpty(nonInheritedTags)) { Collections.addAll( tags, @@ -176,7 +176,7 @@ public Response listTagsForMetadataObject( MetadataObject parentObject = MetadataObjects.parent(object); while (parentObject != null) { Tag[] inheritedTags = - tagManager.listTagsInfoForMetadataObject(metalake, parentObject); + tagDispatcher.listTagsInfoForMetadataObject(metalake, parentObject); if (ArrayUtils.isNotEmpty(inheritedTags)) { Collections.addAll( tags, @@ -240,7 +240,7 @@ public Response associateTagsForObject( MetadataObjects.parse( fullName, MetadataObject.Type.valueOf(type.toUpperCase(Locale.ROOT))); String[] tagNames = - tagManager.associateTagsForMetadataObject( + tagDispatcher.associateTagsForMetadataObject( metalake, object, request.getTagsToAdd(), request.getTagsToRemove()); tagNames = tagNames == null ? new String[0] : tagNames; @@ -260,7 +260,7 @@ public Response associateTagsForObject( private Optional getTagForObject(String metalake, MetadataObject object, String tagName) { try { - return Optional.ofNullable(tagManager.getTagForMetadataObject(metalake, object, tagName)); + return Optional.ofNullable(tagDispatcher.getTagForMetadataObject(metalake, object, tagName)); } catch (NoSuchTagException e) { LOG.info("Tag {} not found for object: {}", tagName, object); return Optional.empty(); diff --git a/server/src/main/java/org/apache/gravitino/server/web/rest/TagOperations.java b/server/src/main/java/org/apache/gravitino/server/web/rest/TagOperations.java index 7fdd2fc6965..68ed8a2c2f0 100644 --- a/server/src/main/java/org/apache/gravitino/server/web/rest/TagOperations.java +++ b/server/src/main/java/org/apache/gravitino/server/web/rest/TagOperations.java @@ -53,7 +53,7 @@ import org.apache.gravitino.server.web.Utils; import org.apache.gravitino.tag.Tag; import org.apache.gravitino.tag.TagChange; -import org.apache.gravitino.tag.TagManager; +import org.apache.gravitino.tag.TagDispatcher; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -62,13 +62,13 @@ public class TagOperations { private static final Logger LOG = LoggerFactory.getLogger(TagOperations.class); - private final TagManager tagManager; + private final TagDispatcher tagDispatcher; @Context private HttpServletRequest httpRequest; @Inject - public TagOperations(TagManager tagManager) { - this.tagManager = tagManager; + public TagOperations(TagDispatcher tagDispatcher) { + this.tagDispatcher = tagDispatcher; } @GET @@ -86,7 +86,7 @@ public Response listTags( httpRequest, () -> { if (verbose) { - Tag[] tags = tagManager.listTagsInfo(metalake); + Tag[] tags = tagDispatcher.listTagsInfo(metalake); TagDTO[] tagDTOs; if (ArrayUtils.isEmpty(tags)) { tagDTOs = new TagDTO[0]; @@ -101,7 +101,7 @@ public Response listTags( return Utils.ok(new TagListResponse(tagDTOs)); } else { - String[] tagNames = tagManager.listTags(metalake); + String[] tagNames = tagDispatcher.listTags(metalake); tagNames = tagNames == null ? new String[0] : tagNames; LOG.info("List {} tags under metalake: {}", tagNames.length, metalake); @@ -126,7 +126,7 @@ public Response createTag(@PathParam("metalake") String metalake, TagCreateReque () -> { request.validate(); Tag tag = - tagManager.createTag( + tagDispatcher.createTag( metalake, request.getName(), request.getComment(), request.getProperties()); LOG.info("Created tag: {} under metalake: {}", tag.name(), metalake); @@ -150,7 +150,7 @@ public Response getTag(@PathParam("metalake") String metalake, @PathParam("tag") return Utils.doAs( httpRequest, () -> { - Tag tag = tagManager.getTag(metalake, name); + Tag tag = tagDispatcher.getTag(metalake, name); LOG.info("Get tag: {} under metalake: {}", name, metalake); return Utils.ok(new TagResponse(DTOConverters.toDTO(tag, Optional.empty()))); }); @@ -180,7 +180,7 @@ public Response alterTag( request.getUpdates().stream() .map(TagUpdateRequest::tagChange) .toArray(TagChange[]::new); - Tag tag = tagManager.alterTag(metalake, name, changes); + Tag tag = tagDispatcher.alterTag(metalake, name, changes); LOG.info("Altered tag: {} under metalake: {}", name, metalake); return Utils.ok(new TagResponse(DTOConverters.toDTO(tag, Optional.empty()))); @@ -202,7 +202,7 @@ public Response deleteTag(@PathParam("metalake") String metalake, @PathParam("ta return Utils.doAs( httpRequest, () -> { - boolean deleted = tagManager.deleteTag(metalake, name); + boolean deleted = tagDispatcher.deleteTag(metalake, name); if (!deleted) { LOG.warn("Failed to delete tag {} under metalake {}", name, metalake); } else { @@ -229,7 +229,7 @@ public Response listMetadataObjectsForTag( return Utils.doAs( httpRequest, () -> { - MetadataObject[] objects = tagManager.listMetadataObjectsForTag(metalake, tagName); + MetadataObject[] objects = tagDispatcher.listMetadataObjectsForTag(metalake, tagName); objects = objects == null ? new MetadataObject[0] : objects; LOG.info( @@ -260,7 +260,7 @@ public Response listTagsForMetadataObject( @PathParam("fullName") String fullName, @QueryParam("details") @DefaultValue("false") boolean verbose) { MetadataObjectTagOperations metadataObjectTagOperations = - new MetadataObjectTagOperations(tagManager); + new MetadataObjectTagOperations(tagDispatcher); metadataObjectTagOperations.setHttpRequest(httpRequest); return metadataObjectTagOperations.listTagsForMetadataObject(metalake, type, fullName, verbose); } @@ -277,7 +277,7 @@ public Response getTagForObject( @PathParam("fullName") String fullName, @PathParam("tag") String tagName) { MetadataObjectTagOperations metadataObjectTagOperations = - new MetadataObjectTagOperations(tagManager); + new MetadataObjectTagOperations(tagDispatcher); metadataObjectTagOperations.setHttpRequest(httpRequest); return metadataObjectTagOperations.getTagForObject(metalake, type, fullName, tagName); } @@ -294,7 +294,7 @@ public Response associateTagsForObject( @PathParam("fullName") String fullName, TagsAssociateRequest request) { MetadataObjectTagOperations metadataObjectTagOperations = - new MetadataObjectTagOperations(tagManager); + new MetadataObjectTagOperations(tagDispatcher); metadataObjectTagOperations.setHttpRequest(httpRequest); return metadataObjectTagOperations.associateTagsForObject(metalake, type, fullName, request); } diff --git a/server/src/test/java/org/apache/gravitino/server/web/rest/TestMetadataObjectTagOperations.java b/server/src/test/java/org/apache/gravitino/server/web/rest/TestMetadataObjectTagOperations.java index 8e0324bea2b..8a1d09d21e8 100644 --- a/server/src/test/java/org/apache/gravitino/server/web/rest/TestMetadataObjectTagOperations.java +++ b/server/src/test/java/org/apache/gravitino/server/web/rest/TestMetadataObjectTagOperations.java @@ -50,6 +50,7 @@ import org.apache.gravitino.meta.TagEntity; import org.apache.gravitino.rest.RESTUtils; import org.apache.gravitino.tag.Tag; +import org.apache.gravitino.tag.TagDispatcher; import org.apache.gravitino.tag.TagManager; import org.glassfish.jersey.internal.inject.AbstractBinder; import org.glassfish.jersey.server.ResourceConfig; @@ -92,7 +93,7 @@ protected Application configure() { new AbstractBinder() { @Override protected void configure() { - bind(tagManager).to(TagManager.class).ranked(2); + bind(tagManager).to(TagDispatcher.class).ranked(2); bindFactory(MockServletRequestFactory.class).to(HttpServletRequest.class); } }); diff --git a/server/src/test/java/org/apache/gravitino/server/web/rest/TestTagOperations.java b/server/src/test/java/org/apache/gravitino/server/web/rest/TestTagOperations.java index 23b87b60d28..50258239c6e 100644 --- a/server/src/test/java/org/apache/gravitino/server/web/rest/TestTagOperations.java +++ b/server/src/test/java/org/apache/gravitino/server/web/rest/TestTagOperations.java @@ -60,6 +60,7 @@ import org.apache.gravitino.rest.RESTUtils; import org.apache.gravitino.tag.Tag; import org.apache.gravitino.tag.TagChange; +import org.apache.gravitino.tag.TagDispatcher; import org.apache.gravitino.tag.TagManager; import org.glassfish.jersey.internal.inject.AbstractBinder; import org.glassfish.jersey.server.ResourceConfig; @@ -102,7 +103,7 @@ protected Application configure() { new AbstractBinder() { @Override protected void configure() { - bind(tagManager).to(TagManager.class).ranked(2); + bind(tagManager).to(TagDispatcher.class).ranked(2); bindFactory(TestTagOperations.MockServletRequestFactory.class) .to(HttpServletRequest.class); } From bd826ce0ae4e009fa329b33b5555f87bd0bc12a7 Mon Sep 17 00:00:00 2001 From: TungYuChiang Date: Fri, 13 Dec 2024 20:37:32 +0800 Subject: [PATCH 04/11] fix bugs --- .../apache/gravitino/listener/TagEventDispatcher.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/org/apache/gravitino/listener/TagEventDispatcher.java b/core/src/main/java/org/apache/gravitino/listener/TagEventDispatcher.java index d0977b5386e..8734a9a765e 100644 --- a/core/src/main/java/org/apache/gravitino/listener/TagEventDispatcher.java +++ b/core/src/main/java/org/apache/gravitino/listener/TagEventDispatcher.java @@ -70,7 +70,7 @@ public Tag getTag(String metalake, String name) throws NoSuchTagException { // TODO: getTagFailureEvent throw e; } - return null; + return dispatcher.getTag(metalake, name); } @Override @@ -83,7 +83,7 @@ public Tag createTag( // TODO: createTagFailureEvent throw e; } - return null; + return dispatcher.createTag(metalake, name, comment, properties); } @Override @@ -95,7 +95,7 @@ public Tag alterTag(String metalake, String name, TagChange... changes) { // TODO: alterTagFailureEvent throw e; } - return null; + return dispatcher.alterTag(metalake, name, changes); } @Override @@ -107,7 +107,7 @@ public boolean deleteTag(String metalake, String name) { // TODO: deleteTagFailureEvent throw e; } - return false; + return true; } @Override @@ -168,6 +168,6 @@ public Tag getTagForMetadataObject(String metalake, MetadataObject metadataObjec // TODO: getTagForMetadataObjectFailureEvent throw e; } - return null; + return dispatcher.getTagForMetadataObject(metalake, metadataObject, name); } } From a8221d58b1c63805336667986887720cfe535174 Mon Sep 17 00:00:00 2001 From: TungYuChiang Date: Fri, 13 Dec 2024 20:46:09 +0800 Subject: [PATCH 05/11] [Bug fix] return dispatcher.envent --- .../gravitino/listener/TagEventDispatcher.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/core/src/main/java/org/apache/gravitino/listener/TagEventDispatcher.java b/core/src/main/java/org/apache/gravitino/listener/TagEventDispatcher.java index 8734a9a765e..581f9bcb4db 100644 --- a/core/src/main/java/org/apache/gravitino/listener/TagEventDispatcher.java +++ b/core/src/main/java/org/apache/gravitino/listener/TagEventDispatcher.java @@ -46,7 +46,7 @@ public String[] listTags(String metalake) { // TODO: listTagFailureEvent throw e; } - return new String[0]; + return dispatcher.listTags(metalake); } @Override @@ -58,7 +58,7 @@ public Tag[] listTagsInfo(String metalake) { // TODO: listTagsInfoFailureEvent throw e; } - return new Tag[0]; + return dispatcher.listTagsInfo(metalake); } @Override @@ -107,7 +107,7 @@ public boolean deleteTag(String metalake, String name) { // TODO: deleteTagFailureEvent throw e; } - return true; + return dispatcher.deleteTag(metalake, name); } @Override @@ -119,7 +119,7 @@ public MetadataObject[] listMetadataObjectsForTag(String metalake, String name) // TODO: listMetadataObjectsForTagFailureEvent throw e; } - return new MetadataObject[0]; + return dispatcher.listMetadataObjectsForTag(metalake, name); } @Override @@ -131,7 +131,7 @@ public String[] listTagsForMetadataObject(String metalake, MetadataObject metada // TODO: listTagsForMetadataObjectFailureEvent throw e; } - return new String[0]; + return dispatcher.listTagsForMetadataObject(metalake, metadataObject); } @Override @@ -143,7 +143,7 @@ public Tag[] listTagsInfoForMetadataObject(String metalake, MetadataObject metad // TODO: listTagsInfoForMetadataObjectFailureEvent throw e; } - return new Tag[0]; + return dispatcher.listTagsInfoForMetadataObject(metalake, metadataObject); } @Override @@ -156,7 +156,7 @@ public String[] associateTagsForMetadataObject( // TODO: associateTagsForMetadataObjectFailureEvent throw e; } - return new String[0]; + return dispatcher.associateTagsForMetadataObject(metalake, metadataObject, tagsToAdd, tagsToRemove); } @Override From 876ae9222085ccd26c32722bc924ed4a47afebdc Mon Sep 17 00:00:00 2001 From: TungYuChiang Date: Sun, 15 Dec 2024 19:40:37 +0800 Subject: [PATCH 06/11] spotlessApply --- .../java/org/apache/gravitino/listener/TagEventDispatcher.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/org/apache/gravitino/listener/TagEventDispatcher.java b/core/src/main/java/org/apache/gravitino/listener/TagEventDispatcher.java index 581f9bcb4db..52b827ff273 100644 --- a/core/src/main/java/org/apache/gravitino/listener/TagEventDispatcher.java +++ b/core/src/main/java/org/apache/gravitino/listener/TagEventDispatcher.java @@ -156,7 +156,8 @@ public String[] associateTagsForMetadataObject( // TODO: associateTagsForMetadataObjectFailureEvent throw e; } - return dispatcher.associateTagsForMetadataObject(metalake, metadataObject, tagsToAdd, tagsToRemove); + return dispatcher.associateTagsForMetadataObject( + metalake, metadataObject, tagsToAdd, tagsToRemove); } @Override From d2c3150370fe686de394f5be36c5867ef10ec8aa Mon Sep 17 00:00:00 2001 From: TungYuChiang Date: Mon, 16 Dec 2024 20:02:03 +0800 Subject: [PATCH 07/11] remove sportTags in core module --- .../java/org/apache/gravitino/Catalog.java | 1 + .../java/org/apache/gravitino/Schema.java | 1 + .../org/apache/gravitino/file/Fileset.java | 2 +- .../org/apache/gravitino/messaging/Topic.java | 2 +- .../org/apache/gravitino/model/Model.java | 2 +- .../java/org/apache/gravitino/rel/Column.java | 2 +- .../java/org/apache/gravitino/rel/Table.java | 2 +- .../gravitino/{ => tag}/SupportsTags.java | 3 +- .../gravitino/client/BaseSchemaCatalog.java | 2 +- .../gravitino/client/GenericColumn.java | 2 +- .../gravitino/client/GenericFileset.java | 2 +- .../gravitino/client/GenericSchema.java | 2 +- .../apache/gravitino/client/GenericTopic.java | 2 +- .../client/MetadataObjectTagOperations.java | 2 +- .../gravitino/client/RelationalTable.java | 2 +- .../gravitino/client/TestSupportTags.java | 2 +- .../apache/gravitino/tag/SupportsTags.java | 124 ------------------ .../apache/gravitino/tag/TagDispatcher.java | 97 +++++++++++++- 18 files changed, 112 insertions(+), 140 deletions(-) rename api/src/main/java/org/apache/gravitino/{ => tag}/SupportsTags.java (97%) delete mode 100644 core/src/main/java/org/apache/gravitino/tag/SupportsTags.java diff --git a/api/src/main/java/org/apache/gravitino/Catalog.java b/api/src/main/java/org/apache/gravitino/Catalog.java index 5ec39854063..7035ed94803 100644 --- a/api/src/main/java/org/apache/gravitino/Catalog.java +++ b/api/src/main/java/org/apache/gravitino/Catalog.java @@ -27,6 +27,7 @@ import org.apache.gravitino.messaging.TopicCatalog; import org.apache.gravitino.model.ModelCatalog; import org.apache.gravitino.rel.TableCatalog; +import org.apache.gravitino.tag.SupportsTags; /** * The interface of a catalog. The catalog is the second level entity in the Gravitino system, diff --git a/api/src/main/java/org/apache/gravitino/Schema.java b/api/src/main/java/org/apache/gravitino/Schema.java index fca30e1e1b1..7cedf94f694 100644 --- a/api/src/main/java/org/apache/gravitino/Schema.java +++ b/api/src/main/java/org/apache/gravitino/Schema.java @@ -23,6 +23,7 @@ import javax.annotation.Nullable; import org.apache.gravitino.annotation.Evolving; import org.apache.gravitino.authorization.SupportsRoles; +import org.apache.gravitino.tag.SupportsTags; /** * An interface representing a schema in the {@link Catalog}. A Schema is a basic container of diff --git a/api/src/main/java/org/apache/gravitino/file/Fileset.java b/api/src/main/java/org/apache/gravitino/file/Fileset.java index 2e8d1499793..6ada5f8c47b 100644 --- a/api/src/main/java/org/apache/gravitino/file/Fileset.java +++ b/api/src/main/java/org/apache/gravitino/file/Fileset.java @@ -23,10 +23,10 @@ import javax.annotation.Nullable; import org.apache.gravitino.Auditable; import org.apache.gravitino.Namespace; -import org.apache.gravitino.SupportsTags; import org.apache.gravitino.annotation.Evolving; import org.apache.gravitino.authorization.SupportsRoles; import org.apache.gravitino.credential.SupportsCredentials; +import org.apache.gravitino.tag.SupportsTags; /** * An interface representing a fileset under a schema {@link Namespace}. A fileset is a virtual diff --git a/api/src/main/java/org/apache/gravitino/messaging/Topic.java b/api/src/main/java/org/apache/gravitino/messaging/Topic.java index 5f6d75673c0..7162c45d2b0 100644 --- a/api/src/main/java/org/apache/gravitino/messaging/Topic.java +++ b/api/src/main/java/org/apache/gravitino/messaging/Topic.java @@ -23,9 +23,9 @@ import javax.annotation.Nullable; import org.apache.gravitino.Auditable; import org.apache.gravitino.Namespace; -import org.apache.gravitino.SupportsTags; import org.apache.gravitino.annotation.Evolving; import org.apache.gravitino.authorization.SupportsRoles; +import org.apache.gravitino.tag.SupportsTags; /** * An interface representing a topic under a schema {@link Namespace}. A topic is a message queue diff --git a/api/src/main/java/org/apache/gravitino/model/Model.java b/api/src/main/java/org/apache/gravitino/model/Model.java index 30471e47d80..fab4e0d53cc 100644 --- a/api/src/main/java/org/apache/gravitino/model/Model.java +++ b/api/src/main/java/org/apache/gravitino/model/Model.java @@ -22,9 +22,9 @@ import java.util.Map; import org.apache.gravitino.Auditable; import org.apache.gravitino.Namespace; -import org.apache.gravitino.SupportsTags; import org.apache.gravitino.annotation.Evolving; import org.apache.gravitino.authorization.SupportsRoles; +import org.apache.gravitino.tag.SupportsTags; /** * An interface representing an ML model under a schema {@link Namespace}. A model is a metadata diff --git a/api/src/main/java/org/apache/gravitino/rel/Column.java b/api/src/main/java/org/apache/gravitino/rel/Column.java index 4e5e17e0cea..e508970fa50 100644 --- a/api/src/main/java/org/apache/gravitino/rel/Column.java +++ b/api/src/main/java/org/apache/gravitino/rel/Column.java @@ -23,11 +23,11 @@ import java.util.Map; import java.util.Objects; import org.apache.gravitino.NameIdentifier; -import org.apache.gravitino.SupportsTags; import org.apache.gravitino.annotation.Evolving; import org.apache.gravitino.rel.expressions.Expression; import org.apache.gravitino.rel.expressions.FunctionExpression; import org.apache.gravitino.rel.types.Type; +import org.apache.gravitino.tag.SupportsTags; /** * An interface representing a column of a {@link Table}. It defines basic properties of a column, diff --git a/api/src/main/java/org/apache/gravitino/rel/Table.java b/api/src/main/java/org/apache/gravitino/rel/Table.java index d37c8eea33a..8bb9e3c1206 100644 --- a/api/src/main/java/org/apache/gravitino/rel/Table.java +++ b/api/src/main/java/org/apache/gravitino/rel/Table.java @@ -23,7 +23,6 @@ import javax.annotation.Nullable; import org.apache.gravitino.Auditable; import org.apache.gravitino.Namespace; -import org.apache.gravitino.SupportsTags; import org.apache.gravitino.annotation.Evolving; import org.apache.gravitino.authorization.SupportsRoles; import org.apache.gravitino.rel.expressions.distributions.Distribution; @@ -33,6 +32,7 @@ import org.apache.gravitino.rel.expressions.transforms.Transforms; import org.apache.gravitino.rel.indexes.Index; import org.apache.gravitino.rel.indexes.Indexes; +import org.apache.gravitino.tag.SupportsTags; /** * An interface representing a table in a {@link Namespace}. It defines the basic properties of a diff --git a/api/src/main/java/org/apache/gravitino/SupportsTags.java b/api/src/main/java/org/apache/gravitino/tag/SupportsTags.java similarity index 97% rename from api/src/main/java/org/apache/gravitino/SupportsTags.java rename to api/src/main/java/org/apache/gravitino/tag/SupportsTags.java index 503975ffa60..0a909c4c8cb 100644 --- a/api/src/main/java/org/apache/gravitino/SupportsTags.java +++ b/api/src/main/java/org/apache/gravitino/tag/SupportsTags.java @@ -17,12 +17,11 @@ * under the License. */ -package org.apache.gravitino; +package org.apache.gravitino.tag; import org.apache.gravitino.annotation.Evolving; import org.apache.gravitino.exceptions.NoSuchTagException; import org.apache.gravitino.exceptions.TagAlreadyAssociatedException; -import org.apache.gravitino.tag.Tag; /** * Interface for supporting getting or associate tags to objects. This interface will be mixed with diff --git a/clients/client-java/src/main/java/org/apache/gravitino/client/BaseSchemaCatalog.java b/clients/client-java/src/main/java/org/apache/gravitino/client/BaseSchemaCatalog.java index 5ff773c4f9a..d0a4d9db121 100644 --- a/clients/client-java/src/main/java/org/apache/gravitino/client/BaseSchemaCatalog.java +++ b/clients/client-java/src/main/java/org/apache/gravitino/client/BaseSchemaCatalog.java @@ -31,7 +31,6 @@ import org.apache.gravitino.Schema; import org.apache.gravitino.SchemaChange; import org.apache.gravitino.SupportsSchemas; -import org.apache.gravitino.SupportsTags; import org.apache.gravitino.authorization.SupportsRoles; import org.apache.gravitino.dto.AuditDTO; import org.apache.gravitino.dto.CatalogDTO; @@ -46,6 +45,7 @@ import org.apache.gravitino.exceptions.NonEmptySchemaException; import org.apache.gravitino.exceptions.SchemaAlreadyExistsException; import org.apache.gravitino.rest.RESTUtils; +import org.apache.gravitino.tag.SupportsTags; import org.apache.gravitino.tag.Tag; /** diff --git a/clients/client-java/src/main/java/org/apache/gravitino/client/GenericColumn.java b/clients/client-java/src/main/java/org/apache/gravitino/client/GenericColumn.java index 2dca80288c6..aacf022e958 100644 --- a/clients/client-java/src/main/java/org/apache/gravitino/client/GenericColumn.java +++ b/clients/client-java/src/main/java/org/apache/gravitino/client/GenericColumn.java @@ -22,12 +22,12 @@ import java.util.Objects; import org.apache.gravitino.MetadataObject; import org.apache.gravitino.MetadataObjects; -import org.apache.gravitino.SupportsTags; import org.apache.gravitino.exceptions.NoSuchTagException; import org.apache.gravitino.exceptions.TagAlreadyAssociatedException; import org.apache.gravitino.rel.Column; import org.apache.gravitino.rel.expressions.Expression; import org.apache.gravitino.rel.types.Type; +import org.apache.gravitino.tag.SupportsTags; import org.apache.gravitino.tag.Tag; /** Represents a generic column. */ diff --git a/clients/client-java/src/main/java/org/apache/gravitino/client/GenericFileset.java b/clients/client-java/src/main/java/org/apache/gravitino/client/GenericFileset.java index 0134a2972ef..6e587b11554 100644 --- a/clients/client-java/src/main/java/org/apache/gravitino/client/GenericFileset.java +++ b/clients/client-java/src/main/java/org/apache/gravitino/client/GenericFileset.java @@ -26,13 +26,13 @@ import org.apache.gravitino.MetadataObject; import org.apache.gravitino.MetadataObjects; import org.apache.gravitino.Namespace; -import org.apache.gravitino.SupportsTags; import org.apache.gravitino.authorization.SupportsRoles; import org.apache.gravitino.credential.Credential; import org.apache.gravitino.credential.SupportsCredentials; import org.apache.gravitino.dto.file.FilesetDTO; import org.apache.gravitino.exceptions.NoSuchTagException; import org.apache.gravitino.file.Fileset; +import org.apache.gravitino.tag.SupportsTags; import org.apache.gravitino.tag.Tag; /** Represents a generic fileset. */ diff --git a/clients/client-java/src/main/java/org/apache/gravitino/client/GenericSchema.java b/clients/client-java/src/main/java/org/apache/gravitino/client/GenericSchema.java index 7fdcf155b20..22af2e3a271 100644 --- a/clients/client-java/src/main/java/org/apache/gravitino/client/GenericSchema.java +++ b/clients/client-java/src/main/java/org/apache/gravitino/client/GenericSchema.java @@ -23,10 +23,10 @@ import org.apache.gravitino.MetadataObject; import org.apache.gravitino.MetadataObjects; import org.apache.gravitino.Schema; -import org.apache.gravitino.SupportsTags; import org.apache.gravitino.authorization.SupportsRoles; import org.apache.gravitino.dto.SchemaDTO; import org.apache.gravitino.exceptions.NoSuchTagException; +import org.apache.gravitino.tag.SupportsTags; import org.apache.gravitino.tag.Tag; /** Represents a generic schema. */ diff --git a/clients/client-java/src/main/java/org/apache/gravitino/client/GenericTopic.java b/clients/client-java/src/main/java/org/apache/gravitino/client/GenericTopic.java index 48993c978c3..0048d489ce4 100644 --- a/clients/client-java/src/main/java/org/apache/gravitino/client/GenericTopic.java +++ b/clients/client-java/src/main/java/org/apache/gravitino/client/GenericTopic.java @@ -25,11 +25,11 @@ import org.apache.gravitino.MetadataObject; import org.apache.gravitino.MetadataObjects; import org.apache.gravitino.Namespace; -import org.apache.gravitino.SupportsTags; import org.apache.gravitino.authorization.SupportsRoles; import org.apache.gravitino.dto.messaging.TopicDTO; import org.apache.gravitino.exceptions.NoSuchTagException; import org.apache.gravitino.messaging.Topic; +import org.apache.gravitino.tag.SupportsTags; import org.apache.gravitino.tag.Tag; /** Represents a generic topic. */ diff --git a/clients/client-java/src/main/java/org/apache/gravitino/client/MetadataObjectTagOperations.java b/clients/client-java/src/main/java/org/apache/gravitino/client/MetadataObjectTagOperations.java index 1fca834f7ab..2ac84bdbf55 100644 --- a/clients/client-java/src/main/java/org/apache/gravitino/client/MetadataObjectTagOperations.java +++ b/clients/client-java/src/main/java/org/apache/gravitino/client/MetadataObjectTagOperations.java @@ -25,13 +25,13 @@ import java.util.Locale; import org.apache.commons.lang3.StringUtils; import org.apache.gravitino.MetadataObject; -import org.apache.gravitino.SupportsTags; import org.apache.gravitino.dto.requests.TagsAssociateRequest; import org.apache.gravitino.dto.responses.NameListResponse; import org.apache.gravitino.dto.responses.TagListResponse; import org.apache.gravitino.dto.responses.TagResponse; import org.apache.gravitino.exceptions.NoSuchTagException; import org.apache.gravitino.rest.RESTUtils; +import org.apache.gravitino.tag.SupportsTags; import org.apache.gravitino.tag.Tag; /** diff --git a/clients/client-java/src/main/java/org/apache/gravitino/client/RelationalTable.java b/clients/client-java/src/main/java/org/apache/gravitino/client/RelationalTable.java index 8c526fc2a5f..e2ace7de278 100644 --- a/clients/client-java/src/main/java/org/apache/gravitino/client/RelationalTable.java +++ b/clients/client-java/src/main/java/org/apache/gravitino/client/RelationalTable.java @@ -33,7 +33,6 @@ import org.apache.gravitino.MetadataObject; import org.apache.gravitino.MetadataObjects; import org.apache.gravitino.Namespace; -import org.apache.gravitino.SupportsTags; import org.apache.gravitino.authorization.SupportsRoles; import org.apache.gravitino.dto.rel.TableDTO; import org.apache.gravitino.dto.rel.partitions.PartitionDTO; @@ -54,6 +53,7 @@ import org.apache.gravitino.rel.indexes.Index; import org.apache.gravitino.rel.partitions.Partition; import org.apache.gravitino.rest.RESTUtils; +import org.apache.gravitino.tag.SupportsTags; import org.apache.gravitino.tag.Tag; /** Represents a relational table. */ diff --git a/clients/client-java/src/test/java/org/apache/gravitino/client/TestSupportTags.java b/clients/client-java/src/test/java/org/apache/gravitino/client/TestSupportTags.java index 601f02380de..3d903a972c7 100644 --- a/clients/client-java/src/test/java/org/apache/gravitino/client/TestSupportTags.java +++ b/clients/client-java/src/test/java/org/apache/gravitino/client/TestSupportTags.java @@ -30,7 +30,6 @@ import org.apache.gravitino.MetadataObjects; import org.apache.gravitino.Namespace; import org.apache.gravitino.Schema; -import org.apache.gravitino.SupportsTags; import org.apache.gravitino.dto.AuditDTO; import org.apache.gravitino.dto.SchemaDTO; import org.apache.gravitino.dto.file.FilesetDTO; @@ -50,6 +49,7 @@ import org.apache.gravitino.rel.Column; import org.apache.gravitino.rel.Table; import org.apache.gravitino.rel.types.Types; +import org.apache.gravitino.tag.SupportsTags; import org.apache.gravitino.tag.Tag; import org.apache.hc.core5.http.Method; import org.junit.jupiter.api.Assertions; diff --git a/core/src/main/java/org/apache/gravitino/tag/SupportsTags.java b/core/src/main/java/org/apache/gravitino/tag/SupportsTags.java deleted file mode 100644 index ffc111389e6..00000000000 --- a/core/src/main/java/org/apache/gravitino/tag/SupportsTags.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.gravitino.tag; - -import java.util.Map; -import org.apache.gravitino.MetadataObject; -import org.apache.gravitino.annotation.Evolving; -import org.apache.gravitino.exceptions.NoSuchTagException; - -/** - * Interface for supporting getting or associate tags to objects. This interface will be mixed with - * metadata objects to provide tag operations. - */ -@Evolving -public interface SupportsTags { - - /** - * List all the tag names for the specific object. - * - * @return The list of tag names. - */ - String[] listTags(String metalake); - - /** - * List all the tags with details for the specific object. - * - * @return The list of tags. - */ - Tag[] listTagsInfo(String metalake); - - /** - * Get a tag by its name for the specific object. - * - * @param name The name of the tag. - * @param metalake The name of the metalake - * @return The tag. - * @throws NoSuchTagException If the tag does not associate with the object. - */ - Tag getTag(String metalake, String name) throws NoSuchTagException; - - /** - * Create a new tag in the specified metalake. - * - * @param metalake The name of the metalake - * @param name The name of the tag - * @param comment A comment for the new tag. - * @param properties The properties of the tag. - * @return The created tag. - */ - Tag createTag(String metalake, String name, String comment, Map properties); - - /** - * Alter an existing tag in the specified metalake - * - * @param metalake The name of the metalake. - * @param name The name of the tag. - * @param changes The changes to apply to the tag. - * @return The updated tag. - */ - Tag alterTag(String metalake, String name, TagChange... changes); - - /** - * @param metalake The name of the metalake. - * @param name The name of the tag. - * @return True if the tag was successfully deleted, false otherwise - */ - boolean deleteTag(String metalake, String name); - - /** - * @param metalake The name of the metalake. - * @param name The name of the tag. - * @return The array of metadata objects associated with the specified tag. - */ - MetadataObject[] listMetadataObjectsForTag(String metalake, String name); - - /** - * @param metalake The name of the metalake - * @param metadataObject The metadata object for which associated tags - * @return The list of tag names associated with the given metadata object. - */ - String[] listTagsForMetadataObject(String metalake, MetadataObject metadataObject); - - /** - * @param metalake - * @param metadataObject - * @return - */ - Tag[] listTagsInfoForMetadataObject(String metalake, MetadataObject metadataObject); - - /** - * @param metalake - * @param metadataObject - * @param tagsToAdd - * @param tagsToRemove - * @return - */ - String[] associateTagsForMetadataObject( - String metalake, MetadataObject metadataObject, String[] tagsToAdd, String[] tagsToRemove); - - /** - * @param metalake - * @param metadataObject - * @param name - * @return - */ - Tag getTagForMetadataObject(String metalake, MetadataObject metadataObject, String name); -} diff --git a/core/src/main/java/org/apache/gravitino/tag/TagDispatcher.java b/core/src/main/java/org/apache/gravitino/tag/TagDispatcher.java index 57e36bcb5d9..bbceb7fd202 100644 --- a/core/src/main/java/org/apache/gravitino/tag/TagDispatcher.java +++ b/core/src/main/java/org/apache/gravitino/tag/TagDispatcher.java @@ -18,4 +18,99 @@ */ package org.apache.gravitino.tag; -public interface TagDispatcher extends SupportsTags {} +import java.util.Map; +import org.apache.gravitino.MetadataObject; +import org.apache.gravitino.exceptions.NoSuchTagException; + +public interface TagDispatcher { + /** + * List all the tag names for the specific object. + * + * @return The list of tag names. + */ + String[] listTags(String metalake); + + /** + * List all the tags with details for the specific object. + * + * @return The list of tags. + */ + Tag[] listTagsInfo(String metalake); + + /** + * Get a tag by its name for the specific object. + * + * @param name The name of the tag. + * @param metalake The name of the metalake + * @return The tag. + * @throws NoSuchTagException If the tag does not associate with the object. + */ + Tag getTag(String metalake, String name) throws NoSuchTagException; + + /** + * Create a new tag in the specified metalake. + * + * @param metalake The name of the metalake + * @param name The name of the tag + * @param comment A comment for the new tag. + * @param properties The properties of the tag. + * @return The created tag. + */ + Tag createTag(String metalake, String name, String comment, Map properties); + + /** + * Alter an existing tag in the specified metalake + * + * @param metalake The name of the metalake. + * @param name The name of the tag. + * @param changes The changes to apply to the tag. + * @return The updated tag. + */ + Tag alterTag(String metalake, String name, TagChange... changes); + + /** + * @param metalake The name of the metalake. + * @param name The name of the tag. + * @return True if the tag was successfully deleted, false otherwise + */ + boolean deleteTag(String metalake, String name); + + /** + * @param metalake The name of the metalake. + * @param name The name of the tag. + * @return The array of metadata objects associated with the specified tag. + */ + MetadataObject[] listMetadataObjectsForTag(String metalake, String name); + + /** + * @param metalake The name of the metalake + * @param metadataObject The metadata object for which associated tags + * @return The list of tag names associated with the given metadata object. + */ + String[] listTagsForMetadataObject(String metalake, MetadataObject metadataObject); + + /** + * @param metalake + * @param metadataObject + * @return + */ + Tag[] listTagsInfoForMetadataObject(String metalake, MetadataObject metadataObject); + + /** + * @param metalake + * @param metadataObject + * @param tagsToAdd + * @param tagsToRemove + * @return + */ + String[] associateTagsForMetadataObject( + String metalake, MetadataObject metadataObject, String[] tagsToAdd, String[] tagsToRemove); + + /** + * @param metalake + * @param metadataObject + * @param name + * @return + */ + Tag getTagForMetadataObject(String metalake, MetadataObject metadataObject, String name); +} From 6a33ebb0ceca2d0e168247c7464fe4303a72ec68 Mon Sep 17 00:00:00 2001 From: TungYuChiang Date: Tue, 17 Dec 2024 19:38:01 +0800 Subject: [PATCH 08/11] Add java doc --- .../org/apache/gravitino/GravitinoEnv.java | 7 +--- .../listener/TagEventDispatcher.java | 6 +++ .../apache/gravitino/tag/TagDispatcher.java | 41 +++++++++++++------ 3 files changed, 37 insertions(+), 17 deletions(-) diff --git a/core/src/main/java/org/apache/gravitino/GravitinoEnv.java b/core/src/main/java/org/apache/gravitino/GravitinoEnv.java index 3024d92a5ad..fc21d2fb01a 100644 --- a/core/src/main/java/org/apache/gravitino/GravitinoEnv.java +++ b/core/src/main/java/org/apache/gravitino/GravitinoEnv.java @@ -73,7 +73,6 @@ import org.apache.gravitino.storage.IdGenerator; import org.apache.gravitino.storage.RandomIdGenerator; import org.apache.gravitino.tag.TagDispatcher; -import org.apache.gravitino.tag.TagManager; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -126,7 +125,6 @@ public class GravitinoEnv { private AuditLogManager auditLogManager; - private TagManager tagManager; private EventBus eventBus; private OwnerManager ownerManager; private FutureGrantManager futureGrantManager; @@ -501,8 +499,7 @@ private void initGravitinoServerComponents() { // Tree lock this.lockManager = new LockManager(config); - // Tag manager - this.tagManager = new TagManager(idGenerator, entityStore); - this.tagDispatcher = new TagEventDispatcher(eventBus, tagManager); + // TagDispatcher + this.tagDispatcher = new TagEventDispatcher(eventBus, tagDispatcher); } } diff --git a/core/src/main/java/org/apache/gravitino/listener/TagEventDispatcher.java b/core/src/main/java/org/apache/gravitino/listener/TagEventDispatcher.java index 52b827ff273..6fbd8b7c74e 100644 --- a/core/src/main/java/org/apache/gravitino/listener/TagEventDispatcher.java +++ b/core/src/main/java/org/apache/gravitino/listener/TagEventDispatcher.java @@ -25,6 +25,12 @@ import org.apache.gravitino.tag.TagChange; import org.apache.gravitino.tag.TagDispatcher; +/** + * {@code TagEventDispatcher} is a decorator for {@link TagDispatcher} that not only delegates tag + * operations to the underlying tag dispatcher but also dispatches corresponding events to an {@link + * EventBus} after each operation is completed. This allows for event-driven workflows or monitoring + * of tag operations. + */ public class TagEventDispatcher implements TagDispatcher { @SuppressWarnings("unused") private final EventBus eventBus; diff --git a/core/src/main/java/org/apache/gravitino/tag/TagDispatcher.java b/core/src/main/java/org/apache/gravitino/tag/TagDispatcher.java index bbceb7fd202..0070e27179c 100644 --- a/core/src/main/java/org/apache/gravitino/tag/TagDispatcher.java +++ b/core/src/main/java/org/apache/gravitino/tag/TagDispatcher.java @@ -22,6 +22,11 @@ import org.apache.gravitino.MetadataObject; import org.apache.gravitino.exceptions.NoSuchTagException; +/** + * {@code TagDispatcher} interface provides functionalities for managing tags within a metalake. It + * includes a comprehensive set of operations such as listing, creating, retrieving, updating, and + * deleting tags, as well as associating tags with other objects. + */ public interface TagDispatcher { /** * List all the tag names for the specific object. @@ -69,6 +74,8 @@ public interface TagDispatcher { Tag alterTag(String metalake, String name, TagChange... changes); /** + * delete an existing tag in the specified metalake + * * @param metalake The name of the metalake. * @param name The name of the tag. * @return True if the tag was successfully deleted, false otherwise @@ -76,6 +83,8 @@ public interface TagDispatcher { boolean deleteTag(String metalake, String name); /** + * List all metadata objects associated with the specified tag. + * * @param metalake The name of the metalake. * @param name The name of the tag. * @return The array of metadata objects associated with the specified tag. @@ -83,6 +92,8 @@ public interface TagDispatcher { MetadataObject[] listMetadataObjectsForTag(String metalake, String name); /** + * List all tag names associated with the specified metadata object. + * * @param metalake The name of the metalake * @param metadataObject The metadata object for which associated tags * @return The list of tag names associated with the given metadata object. @@ -90,27 +101,33 @@ public interface TagDispatcher { String[] listTagsForMetadataObject(String metalake, MetadataObject metadataObject); /** - * @param metalake - * @param metadataObject - * @return + * List detailed information for all tags associated with the specified metadata object. + * + * @param metalake The name of the metalake + * @param metadataObject The metadata object to query tag details for. + * @return An array of tags with detailed information. */ Tag[] listTagsInfoForMetadataObject(String metalake, MetadataObject metadataObject); /** - * @param metalake - * @param metadataObject - * @param tagsToAdd - * @param tagsToRemove - * @return + * Associate or disassociate tags with the specified metadata object. + * + * @param metalake The name of the metalake. + * @param metadataObject The metadata object to update tags for. + * @param tagsToAdd Tags to associate with the object. + * @param tagsToRemove Tags to disassociate from the object. + * @return An array of updated tag names. */ String[] associateTagsForMetadataObject( String metalake, MetadataObject metadataObject, String[] tagsToAdd, String[] tagsToRemove); /** - * @param metalake - * @param metadataObject - * @param name - * @return + * Retrieve a specific tag associated with the specified metadata object. + * + * @param metalake The name of the metalake. + * @param metadataObject The metadata object to query the tag for. + * @param name The name of the tag to retrieve. + * @return The tag associated with the metadata object. */ Tag getTagForMetadataObject(String metalake, MetadataObject metadataObject, String name); } From adb7c9789a984e41e024524d587336821d9a55a2 Mon Sep 17 00:00:00 2001 From: TungYuChiang Date: Tue, 17 Dec 2024 20:16:34 +0800 Subject: [PATCH 09/11] fix bugs --- .../main/java/org/apache/gravitino/server/GravitinoServer.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/server/src/main/java/org/apache/gravitino/server/GravitinoServer.java b/server/src/main/java/org/apache/gravitino/server/GravitinoServer.java index 486b9e735a8..16a2096f328 100644 --- a/server/src/main/java/org/apache/gravitino/server/GravitinoServer.java +++ b/server/src/main/java/org/apache/gravitino/server/GravitinoServer.java @@ -114,9 +114,8 @@ protected void configure() { bind(gravitinoEnv.partitionDispatcher()).to(PartitionDispatcher.class).ranked(1); bind(gravitinoEnv.filesetDispatcher()).to(FilesetDispatcher.class).ranked(1); bind(gravitinoEnv.topicDispatcher()).to(TopicDispatcher.class).ranked(1); - bind(gravitinoEnv.tagManager()).to(TagManager.class).ranked(1); - bind(gravitinoEnv.credentialManager()).to(CredentialManager.class).ranked(1); bind(gravitinoEnv.tagDispatcher()).to(TagDispatcher.class).ranked(1); + bind(gravitinoEnv.credentialManager()).to(CredentialManager.class).ranked(1); } }); register(JsonProcessingExceptionMapper.class); From 061cd9c4ae13c4cd0a4bd5cbfe9b96648acebc66 Mon Sep 17 00:00:00 2001 From: TungYuChiang Date: Tue, 17 Dec 2024 22:10:36 +0800 Subject: [PATCH 10/11] move function to catch block & fix bugs --- .../org/apache/gravitino/GravitinoEnv.java | 6 ++++- .../listener/TagEventDispatcher.java | 24 +++++++++---------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/core/src/main/java/org/apache/gravitino/GravitinoEnv.java b/core/src/main/java/org/apache/gravitino/GravitinoEnv.java index fc21d2fb01a..22338fd0b65 100644 --- a/core/src/main/java/org/apache/gravitino/GravitinoEnv.java +++ b/core/src/main/java/org/apache/gravitino/GravitinoEnv.java @@ -73,6 +73,7 @@ import org.apache.gravitino.storage.IdGenerator; import org.apache.gravitino.storage.RandomIdGenerator; import org.apache.gravitino.tag.TagDispatcher; +import org.apache.gravitino.tag.TagManager; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -125,6 +126,7 @@ public class GravitinoEnv { private AuditLogManager auditLogManager; + private TagManager tagManager; private EventBus eventBus; private OwnerManager ownerManager; private FutureGrantManager futureGrantManager; @@ -499,7 +501,9 @@ private void initGravitinoServerComponents() { // Tree lock this.lockManager = new LockManager(config); + // Tag manager + this.tagManager = new TagManager(idGenerator, entityStore); // TagDispatcher - this.tagDispatcher = new TagEventDispatcher(eventBus, tagDispatcher); + this.tagDispatcher = new TagEventDispatcher(eventBus, tagManager); } } diff --git a/core/src/main/java/org/apache/gravitino/listener/TagEventDispatcher.java b/core/src/main/java/org/apache/gravitino/listener/TagEventDispatcher.java index 6fbd8b7c74e..53a568db26a 100644 --- a/core/src/main/java/org/apache/gravitino/listener/TagEventDispatcher.java +++ b/core/src/main/java/org/apache/gravitino/listener/TagEventDispatcher.java @@ -48,11 +48,11 @@ public String[] listTags(String metalake) { // TODO: listTagsPreEvent try { // TODO: listTagsEvent + return dispatcher.listTags(metalake); } catch (Exception e) { // TODO: listTagFailureEvent throw e; } - return dispatcher.listTags(metalake); } @Override @@ -60,11 +60,11 @@ public Tag[] listTagsInfo(String metalake) { // TODO: listTagsInfoPreEvent try { // TODO: listTagsInfoEvent + return dispatcher.listTagsInfo(metalake); } catch (Exception e) { // TODO: listTagsInfoFailureEvent throw e; } - return dispatcher.listTagsInfo(metalake); } @Override @@ -72,11 +72,11 @@ public Tag getTag(String metalake, String name) throws NoSuchTagException { // TODO: getTagPreEvent try { // TODO: getTagEvent + return dispatcher.getTag(metalake, name); } catch (NoSuchTagException e) { // TODO: getTagFailureEvent throw e; } - return dispatcher.getTag(metalake, name); } @Override @@ -85,11 +85,11 @@ public Tag createTag( // TODO: createTagPreEvent try { // TODO: createTagEvent + return dispatcher.createTag(metalake, name, comment, properties); } catch (Exception e) { // TODO: createTagFailureEvent throw e; } - return dispatcher.createTag(metalake, name, comment, properties); } @Override @@ -97,11 +97,11 @@ public Tag alterTag(String metalake, String name, TagChange... changes) { // TODO: alterTagPreEvent try { // TODO: alterTagEvent + return dispatcher.alterTag(metalake, name, changes); } catch (Exception e) { // TODO: alterTagFailureEvent throw e; } - return dispatcher.alterTag(metalake, name, changes); } @Override @@ -109,11 +109,11 @@ public boolean deleteTag(String metalake, String name) { // TODO: deleteTagPreEvent try { // TODO: deleteTagEvent + return dispatcher.deleteTag(metalake, name); } catch (Exception e) { // TODO: deleteTagFailureEvent throw e; } - return dispatcher.deleteTag(metalake, name); } @Override @@ -121,11 +121,11 @@ public MetadataObject[] listMetadataObjectsForTag(String metalake, String name) // TODO: listMetadataObjectsForTagPreEvent try { // TODO: listMetadataObjectsForTagEvent + return dispatcher.listMetadataObjectsForTag(metalake, name); } catch (Exception e) { // TODO: listMetadataObjectsForTagFailureEvent throw e; } - return dispatcher.listMetadataObjectsForTag(metalake, name); } @Override @@ -133,11 +133,11 @@ public String[] listTagsForMetadataObject(String metalake, MetadataObject metada // TODO: listTagsForMetadataObjectPreEvent try { // TODO: listTagsForMetadataObjectEvent + return dispatcher.listTagsForMetadataObject(metalake, metadataObject); } catch (Exception e) { // TODO: listTagsForMetadataObjectFailureEvent throw e; } - return dispatcher.listTagsForMetadataObject(metalake, metadataObject); } @Override @@ -145,11 +145,11 @@ public Tag[] listTagsInfoForMetadataObject(String metalake, MetadataObject metad // TODO: listTagsInfoForMetadataObjectPreEvent try { // TODO: listTagsInfoForMetadataObjectEvent + return dispatcher.listTagsInfoForMetadataObject(metalake, metadataObject); } catch (Exception e) { // TODO: listTagsInfoForMetadataObjectFailureEvent throw e; } - return dispatcher.listTagsInfoForMetadataObject(metalake, metadataObject); } @Override @@ -158,12 +158,12 @@ public String[] associateTagsForMetadataObject( // TODO: associateTagsForMetadataObjectPreEvent try { // TODO: associateTagsForMetadataObjectEvent + return dispatcher.associateTagsForMetadataObject( + metalake, metadataObject, tagsToAdd, tagsToRemove); } catch (Exception e) { // TODO: associateTagsForMetadataObjectFailureEvent throw e; } - return dispatcher.associateTagsForMetadataObject( - metalake, metadataObject, tagsToAdd, tagsToRemove); } @Override @@ -171,10 +171,10 @@ public Tag getTagForMetadataObject(String metalake, MetadataObject metadataObjec // TODO: getTagForMetadataObjectPreEvent try { // TODO: getTagForMetadataObjectEvent + return dispatcher.getTagForMetadataObject(metalake, metadataObject, name); } catch (Exception e) { // TODO: getTagForMetadataObjectFailureEvent throw e; } - return dispatcher.getTagForMetadataObject(metalake, metadataObject, name); } } From 198dcbf0eb354264be07a25afe7b6126ca2d0139 Mon Sep 17 00:00:00 2001 From: TungYuChiang Date: Tue, 17 Dec 2024 22:35:24 +0800 Subject: [PATCH 11/11] remove tagManager in GravitinoEnv --- core/src/main/java/org/apache/gravitino/GravitinoEnv.java | 7 ++----- .../org/apache/gravitino/listener/TagEventDispatcher.java | 2 +- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/core/src/main/java/org/apache/gravitino/GravitinoEnv.java b/core/src/main/java/org/apache/gravitino/GravitinoEnv.java index 22338fd0b65..96c60b834fc 100644 --- a/core/src/main/java/org/apache/gravitino/GravitinoEnv.java +++ b/core/src/main/java/org/apache/gravitino/GravitinoEnv.java @@ -126,7 +126,6 @@ public class GravitinoEnv { private AuditLogManager auditLogManager; - private TagManager tagManager; private EventBus eventBus; private OwnerManager ownerManager; private FutureGrantManager futureGrantManager; @@ -501,9 +500,7 @@ private void initGravitinoServerComponents() { // Tree lock this.lockManager = new LockManager(config); - // Tag manager - this.tagManager = new TagManager(idGenerator, entityStore); - // TagDispatcher - this.tagDispatcher = new TagEventDispatcher(eventBus, tagManager); + // Create and initialize Tag related modules + this.tagDispatcher = new TagEventDispatcher(eventBus, new TagManager(idGenerator, entityStore)); } } diff --git a/core/src/main/java/org/apache/gravitino/listener/TagEventDispatcher.java b/core/src/main/java/org/apache/gravitino/listener/TagEventDispatcher.java index 53a568db26a..90ca0fda23d 100644 --- a/core/src/main/java/org/apache/gravitino/listener/TagEventDispatcher.java +++ b/core/src/main/java/org/apache/gravitino/listener/TagEventDispatcher.java @@ -159,7 +159,7 @@ public String[] associateTagsForMetadataObject( try { // TODO: associateTagsForMetadataObjectEvent return dispatcher.associateTagsForMetadataObject( - metalake, metadataObject, tagsToAdd, tagsToRemove); + metalake, metadataObject, tagsToAdd, tagsToRemove); } catch (Exception e) { // TODO: associateTagsForMetadataObjectFailureEvent throw e;