Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#5900] feat(tag): support tag pre-event to Gravitino server #5980

Merged
merged 23 commits into from
Feb 9, 2025
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
555756e
add TagPreEvent
amazingLychee Dec 24, 2024
90300bb
feat: Add pre-event logic for listTags method
amazingLychee Dec 24, 2024
36da9d7
feat: Add pre-event logic for listTagsInfo method
amazingLychee Dec 24, 2024
8cf9289
feat: Add pre-event logic for getTag method
amazingLychee Dec 25, 2024
f5e310e
feat: Add pre-event logic for createTag method
amazingLychee Dec 25, 2024
b7f5894
feat: Add pre-event logic for alterTag method
amazingLychee Dec 25, 2024
8557203
feat: Add pre-event logic for deleteTag method
amazingLychee Dec 25, 2024
bf2d861
feat: Add pre-event logic for listMetadataObjectsForTag method
amazingLychee Dec 25, 2024
050c17b
feat: Add pre-event logic for listTagsForMetadataObject method
amazingLychee Dec 25, 2024
816fdcb
feat: Add pre-event logic for listTagsInfoForMetadataObject method
amazingLychee Dec 25, 2024
f0a0bc9
feat: Add pre-event logic for associateTagsForMetadataObject method
amazingLychee Dec 25, 2024
867b2c3
feat: Add pre-event logic for getTagForMetadataObject method
amazingLychee Dec 25, 2024
08ffb23
feat: Add tag event in OperationType
amazingLychee Dec 25, 2024
f944fec
feat: Modify Tag PreEvent
amazingLychee Jan 16, 2025
cbc6a05
Merge branch 'main' into issue-5900
amazingLychee Jan 16, 2025
90ac14a
feat: Modify Tag PreEvent
amazingLychee Jan 25, 2025
1b49075
feat: add Tag PreEvent unit test
amazingLychee Jan 25, 2025
8aaa45e
Merge branch 'main' into issue-5900
amazingLychee Jan 25, 2025
49e1b78
Merge branch 'main' into issue-5900
amazingLychee Feb 6, 2025
4b78e91
feat: add javadoc and rename for tag pre event
amazingLychee Feb 6, 2025
05e6909
feat: add javadoc for tag pre event
amazingLychee Feb 6, 2025
893bc95
Merge branch 'main' into issue-5900
amazingLychee Feb 8, 2025
457207f
feat: rename
amazingLychee Feb 8, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,27 @@
import org.apache.gravitino.MetadataObject;
import org.apache.gravitino.exceptions.NoSuchTagException;
import org.apache.gravitino.listener.api.event.AlterTagFailureEvent;
import org.apache.gravitino.listener.api.event.AlterTagPreEvent;
import org.apache.gravitino.listener.api.event.AssociateTagsForMetadataObjectFailureEvent;
import org.apache.gravitino.listener.api.event.AssociateTagsForMetadataObjectPreEvent;
import org.apache.gravitino.listener.api.event.CreateTagFailureEvent;
import org.apache.gravitino.listener.api.event.CreateTagPreEvent;
import org.apache.gravitino.listener.api.event.DeleteTagFailureEvent;
import org.apache.gravitino.listener.api.event.DeleteTagPreEvent;
import org.apache.gravitino.listener.api.event.GetTagFailureEvent;
import org.apache.gravitino.listener.api.event.GetTagForMetadataObjectFailureEvent;
import org.apache.gravitino.listener.api.event.GetTagForMetadataObjectPreEvent;
import org.apache.gravitino.listener.api.event.GetTagPreEvent;
import org.apache.gravitino.listener.api.event.ListMetadataObjectsForTagFailureEvent;
import org.apache.gravitino.listener.api.event.ListMetadataObjectsForTagPreEvent;
import org.apache.gravitino.listener.api.event.ListTagsFailureEvent;
import org.apache.gravitino.listener.api.event.ListTagsForMetadataObjectFailureEvent;
import org.apache.gravitino.listener.api.event.ListTagsForMetadataObjectPreEvent;
import org.apache.gravitino.listener.api.event.ListTagsInfoFailureEvent;
import org.apache.gravitino.listener.api.event.ListTagsInfoForMetadataObjectFailureEvent;
import org.apache.gravitino.listener.api.event.ListTagsInfoForMetadataObjectPreEvent;
import org.apache.gravitino.listener.api.event.ListTagsInfoPreEvent;
import org.apache.gravitino.listener.api.event.ListTagsPreEvent;
import org.apache.gravitino.listener.api.info.TagInfo;
import org.apache.gravitino.tag.Tag;
import org.apache.gravitino.tag.TagChange;
Expand All @@ -55,7 +66,7 @@ public TagEventDispatcher(EventBus eventBus, TagDispatcher dispatcher) {

@Override
public String[] listTags(String metalake) {
// TODO: listTagsPreEvent
eventBus.dispatchEvent(new ListTagsPreEvent(PrincipalUtils.getCurrentUserName(), metalake));
try {
// TODO: listTagsEvent
return dispatcher.listTags(metalake);
Expand All @@ -68,7 +79,7 @@ public String[] listTags(String metalake) {

@Override
public Tag[] listTagsInfo(String metalake) {
// TODO: listTagsInfoPreEvent
eventBus.dispatchEvent(new ListTagsInfoPreEvent(PrincipalUtils.getCurrentUserName(), metalake));
try {
// TODO: listTagsInfoEvent
return dispatcher.listTagsInfo(metalake);
Expand All @@ -81,7 +92,7 @@ public Tag[] listTagsInfo(String metalake) {

@Override
public Tag getTag(String metalake, String name) throws NoSuchTagException {
// TODO: getTagPreEvent
eventBus.dispatchEvent(new GetTagPreEvent(PrincipalUtils.getCurrentUserName(), metalake, name));
try {
// TODO: getTagEvent
return dispatcher.getTag(metalake, name);
Expand All @@ -97,6 +108,9 @@ public Tag createTag(
String metalake, String name, String comment, Map<String, String> properties) {
TagInfo tagInfo = new TagInfo(name, comment, properties);
// TODO: createTagPreEvent

eventBus.dispatchEvent(
new CreateTagPreEvent(PrincipalUtils.getCurrentUserName(), metalake, tagInfo));
try {
// TODO: createTagEvent
return dispatcher.createTag(metalake, name, comment, properties);
Expand All @@ -109,7 +123,10 @@ public Tag createTag(

@Override
public Tag alterTag(String metalake, String name, TagChange... changes) {
// TODO: alterTagPreEvent
AlterTagPreEvent preEvent =
new AlterTagPreEvent(PrincipalUtils.getCurrentUserName(), metalake, name, changes);

eventBus.dispatchEvent(preEvent);
try {
// TODO: alterTagEvent
return dispatcher.alterTag(metalake, name, changes);
Expand All @@ -123,7 +140,10 @@ public Tag alterTag(String metalake, String name, TagChange... changes) {

@Override
public boolean deleteTag(String metalake, String name) {
// TODO: deleteTagPreEvent
DeleteTagPreEvent preEvent =
new DeleteTagPreEvent(PrincipalUtils.getCurrentUserName(), metalake, name);

eventBus.dispatchEvent(preEvent);
try {
// TODO: deleteTagEvent
return dispatcher.deleteTag(metalake, name);
Expand All @@ -136,7 +156,8 @@ public boolean deleteTag(String metalake, String name) {

@Override
public MetadataObject[] listMetadataObjectsForTag(String metalake, String name) {
// TODO: listMetadataObjectsForTagPreEvent
eventBus.dispatchEvent(
new ListMetadataObjectsForTagPreEvent(PrincipalUtils.getCurrentUserName(), metalake, name));
try {
// TODO: listMetadataObjectsForTagEvent
return dispatcher.listMetadataObjectsForTag(metalake, name);
Expand All @@ -150,7 +171,10 @@ public MetadataObject[] listMetadataObjectsForTag(String metalake, String name)

@Override
public String[] listTagsForMetadataObject(String metalake, MetadataObject metadataObject) {
// TODO: listTagsForMetadataObjectPreEvent
eventBus.dispatchEvent(
new ListTagsForMetadataObjectPreEvent(
PrincipalUtils.getCurrentUserName(), metalake, metadataObject));

try {
// TODO: listTagsForMetadataObjectEvent
return dispatcher.listTagsForMetadataObject(metalake, metadataObject);
Expand All @@ -164,7 +188,9 @@ public String[] listTagsForMetadataObject(String metalake, MetadataObject metada

@Override
public Tag[] listTagsInfoForMetadataObject(String metalake, MetadataObject metadataObject) {
// TODO: listTagsInfoForMetadataObjectPreEvent
eventBus.dispatchEvent(
new ListTagsInfoForMetadataObjectPreEvent(
PrincipalUtils.getCurrentUserName(), metalake, metadataObject));
try {
// TODO: listTagsInfoForMetadataObjectEvent
return dispatcher.listTagsInfoForMetadataObject(metalake, metadataObject);
Expand All @@ -179,7 +205,14 @@ public Tag[] listTagsInfoForMetadataObject(String metalake, MetadataObject metad
@Override
public String[] associateTagsForMetadataObject(
String metalake, MetadataObject metadataObject, String[] tagsToAdd, String[] tagsToRemove) {
// TODO: associateTagsForMetadataObjectPreEvent
eventBus.dispatchEvent(
new AssociateTagsForMetadataObjectPreEvent(
PrincipalUtils.getCurrentUserName(),
metalake,
metadataObject,
tagsToAdd,
tagsToRemove));

try {
// TODO: associateTagsForMetadataObjectEvent
return dispatcher.associateTagsForMetadataObject(
Expand All @@ -199,7 +232,9 @@ public String[] associateTagsForMetadataObject(

@Override
public Tag getTagForMetadataObject(String metalake, MetadataObject metadataObject, String name) {
// TODO: getTagForMetadataObjectPreEvent
eventBus.dispatchEvent(
new GetTagForMetadataObjectPreEvent(
PrincipalUtils.getCurrentUserName(), metalake, metadataObject, name));
try {
// TODO: getTagForMetadataObjectEvent
return dispatcher.getTagForMetadataObject(metalake, metadataObject, name);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* 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.api.event;

import org.apache.gravitino.annotation.DeveloperApi;
import org.apache.gravitino.tag.TagChange;
import org.apache.gravitino.utils.NameIdentifierUtil;

/** Represents an event triggered before altering a tag. */
@DeveloperApi
public class AlterTagPreEvent extends TagPreEvent {

private final TagChange[] changes;

/**
* Constructs a new AlterTagPreEvent instance.
*
* @param user The user responsible for the operation.
* @param metalake The namespace of the tag.
* @param name The name of the tag being altered.
* @param changes The changes being applied to the tag.
*/
public AlterTagPreEvent(String user, String metalake, String name, TagChange[] changes) {
super(user, NameIdentifierUtil.ofTag(metalake, name));
this.changes = changes;
}

/**
* Returns the changes being applied to the tag.
*
* @return An array of {@link TagChange}.
*/
public TagChange[] getChanges() {
return changes;
}

/**
* Returns the operation type for this event.
*
* @return The operation type {@link OperationType#ALTER_TAG}.
*/
@Override
public OperationType operationType() {
return OperationType.ALTER_TAG;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* 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.api.event;

import org.apache.gravitino.MetadataObject;
import org.apache.gravitino.annotation.DeveloperApi;
import org.apache.gravitino.utils.MetadataObjectUtil;

/** Represents an event triggered before associating tags with a specific metadata object. */
@DeveloperApi
public class AssociateTagsForMetadataObjectPreEvent extends TagPreEvent {
private final String[] tagsToAdd;
private final String[] tagsToRemove;

/**
* Constructs the pre-event with user, metalake, metadata object, tags to add, and tags to remove.
*
* @param user The user initiating the operation.
* @param metalake The metalake environment name.
* @param metadataObject The metadata object for which tags will be associated.
* @param tagsToAdd Tags to be added to the metadata object.
* @param tagsToRemove Tags to be removed from the metadata object.
*/
public AssociateTagsForMetadataObjectPreEvent(
String user,
String metalake,
MetadataObject metadataObject,
String[] tagsToAdd,
String[] tagsToRemove) {
super(user, MetadataObjectUtil.toEntityIdent(metalake, metadataObject));
this.tagsToAdd = tagsToAdd;
this.tagsToRemove = tagsToRemove;
}

/**
* Returns the tags to be added.
*
* @return Array of tag names to be added.
*/
public String[] getTagsToAdd() {
return tagsToAdd;
}

/**
* Returns the tags to be removed.
*
* @return Array of tag names to be removed.
*/
public String[] getTagsToRemove() {
return tagsToRemove;
}

/**
* Returns the operation type for this event.
*
* @return The operation type, which is ASSOCIATE_TAGS_FOR_METADATA_OBJECT.
*/
@Override
public OperationType operationType() {
return OperationType.ASSOCIATE_TAGS_FOR_METADATA_OBJECT;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* 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.api.event;

import org.apache.gravitino.annotation.DeveloperApi;
import org.apache.gravitino.listener.api.info.TagInfo;
import org.apache.gravitino.utils.NameIdentifierUtil;

/** Represents an event triggered before the creation of a tag. */
@DeveloperApi
public class CreateTagPreEvent extends TagPreEvent {
private final TagInfo tagInfo;

/**
* Constructs a new {@code CreateTagPreEvent} instance.
*
* @param user
* @param metalake
* @param tagInfo
*/
public CreateTagPreEvent(String user, String metalake, TagInfo tagInfo) {
super(user, NameIdentifierUtil.ofTag(metalake, tagInfo.name()));
this.tagInfo = tagInfo;
}

/**
* Returns the information about the tag.
*
* @return the tag information
*/
public TagInfo tagInfo() {
return tagInfo;
}

/**
* Returns the type of operation.
*
* @return the operation type.
*/
@Override
public OperationType operationType() {
return OperationType.CREATE_TAG;
}
}
Loading
Loading