Skip to content

Commit

Permalink
Add all tag event
Browse files Browse the repository at this point in the history
  • Loading branch information
TungYuChiang committed Jan 9, 2025
1 parent eaa17eb commit ca71a04
Show file tree
Hide file tree
Showing 12 changed files with 668 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
package org.apache.gravitino.listener;

import java.util.Map;

import org.apache.gravitino.MetadataObject;
import org.apache.gravitino.exceptions.NoSuchTagException;
import org.apache.gravitino.listener.api.event.AssociateTagsForMetadataObjectEvent;
import org.apache.gravitino.listener.api.event.AlterTagFailureEvent;
import org.apache.gravitino.listener.api.event.AssociateTagsForMetadataObjectFailureEvent;
import org.apache.gravitino.listener.api.event.CreateTagFailureEvent;
Expand All @@ -34,7 +36,15 @@
import org.apache.gravitino.listener.api.event.ListTagsInfoForMetadataObjectFailureEvent;
import org.apache.gravitino.listener.api.info.TagInfo;
import org.apache.gravitino.listener.api.event.CreateTagEvent;
import org.apache.gravitino.listener.api.event.DeleteTagEvent;
import org.apache.gravitino.listener.api.event.GetTagEvent;
import org.apache.gravitino.listener.api.event.GetTagForMetadataObjectEvent;
import org.apache.gravitino.listener.api.event.ListMetadataObjectsForTagEvent;
import org.apache.gravitino.listener.api.event.ListTagEvent;
import org.apache.gravitino.listener.api.event.ListTagInfoEvent;
import org.apache.gravitino.listener.api.event.AlterTagEvent;
import org.apache.gravitino.listener.api.event.ListTagsForMetadataObjectEvent;
import org.apache.gravitino.listener.api.event.ListTagsInfoForMetadataObjectEvent;
import org.apache.gravitino.listener.api.info.TagInfo;
import org.apache.gravitino.tag.Tag;
import org.apache.gravitino.tag.TagChange;
Expand All @@ -48,53 +58,55 @@
* of tag operations.
*/
public class TagEventDispatcher implements TagDispatcher {
private final EventBus eventBus;
private final TagDispatcher dispatcher;
private final EventBus eventBus;
private final TagDispatcher dispatcher;

public TagEventDispatcher(EventBus eventBus, TagDispatcher dispatcher) {
this.eventBus = eventBus;
this.dispatcher = dispatcher;
}
public TagEventDispatcher(EventBus eventBus, TagDispatcher dispatcher) {
this.eventBus = eventBus;
this.dispatcher = dispatcher;
}

@Override
public String[] listTags(String metalake) {
// TODO: listTagsPreEvent
try {
String[] tags = dispatcher.listTags(metalake);
eventBus.dispatchEvent(new ListTagEvent(PrincipalUtils.getCurrentUserName(), metalake));
return tags;
} catch (Exception e) {
eventBus.dispatchEvent(
new ListTagsFailureEvent(PrincipalUtils.getCurrentUserName(), metalake, e));
throw e;
@Override
public String[] listTags(String metalake) {
// TODO: listTagsPreEvent
try {
String[] tagNames = dispatcher.listTags(metalake);
eventBus.dispatchEvent(new ListTagEvent(PrincipalUtils.getCurrentUserName(), metalake));
return tagNames;
} catch (Exception e) {
eventBus.dispatchEvent(
new ListTagsFailureEvent(PrincipalUtils.getCurrentUserName(), metalake, e));
throw e;
}
}
}

@Override
public Tag[] listTagsInfo(String metalake) {
// TODO: listTagsInfoPreEvent
try {
// TODO: listTagsInfoEvent
return dispatcher.listTagsInfo(metalake);
} catch (Exception e) {
eventBus.dispatchEvent(
new ListTagsInfoFailureEvent(PrincipalUtils.getCurrentUserName(), metalake, e));
throw e;
@Override
public Tag[] listTagsInfo(String metalake) {
// TODO: listTagsInfoPreEvent
try {
Tag[] tags = dispatcher.listTagsInfo(metalake);
eventBus.dispatchEvent(new ListTagInfoEvent(PrincipalUtils.getCurrentUserName(), metalake, tags));
return tags;
} catch (Exception e) {
eventBus.dispatchEvent(
new ListTagsInfoFailureEvent(PrincipalUtils.getCurrentUserName(), metalake, e));
throw e;
}
}
}

@Override
public Tag getTag(String metalake, String name) throws NoSuchTagException {
// TODO: getTagPreEvent
try {
// TODO: getTagEvent
return dispatcher.getTag(metalake, name);
} catch (Exception e) {
eventBus.dispatchEvent(
new GetTagFailureEvent(PrincipalUtils.getCurrentUserName(), metalake, name, e));
throw e;
@Override
public Tag getTag(String metalake, String name) throws NoSuchTagException {
// TODO: getTagPreEvent
try {
// TODO: getTagEvent
Tag tag = dispatcher.getTag(metalake, name);
eventBus.dispatchEvent(new GetTagEvent(PrincipalUtils.getCurrentUserName(), metalake, name, tag));
return tag;
} catch (NoSuchTagException e) {
new GetTagFailureEvent(PrincipalUtils.getCurrentUserName(), metalake, name, e));
throw e;
}
}
}

@Override
public Tag createTag(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,17 @@ public final class AlterTagEvent extends TagEvent {
* successful alteration of a tag.
*
* @param user The username of the individual responsible for initiating the tag alteration.
* @param identifier The unique identifier of the altered tag, serving as a clear reference
* point for the tag in question.
* @param metalake The metalake from which the tag is being altered.
* @param tagChanges An array of {@link TagChange} objects representing the specific
* changes applied to the tag during the alteration process.
* @param updatedTagInfo The post-alteration state of the tag.
*/
public AlterTagEvent(
String user,
NameIdentifier identifier,
String metalake,
TagChange[] tagChanges,
TagInfo updatedTagInfo) {
super(user, identifier);
super(user, NameIdentifier.of(metalake));
this.tagChanges = tagChanges.clone();
this.updatedTagInfo = updatedTagInfo;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/*
* 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.NameIdentifier;
import org.apache.gravitino.annotation.DeveloperApi;
import org.apache.gravitino.MetadataObject;

/** Represents an event that is triggered upon successfully associating tags with a metadata object. */
@DeveloperApi
public final class AssociateTagsForMetadataObjectEvent extends TagEvent {
private final String metalake;
private final MetadataObject metadataObject;
private final String[] tagsToAdd;
private final String[] tagsToRemove;
private final String[] associatedTags;

/**
* Constructs an instance of {@code AssociateTagsForMetadataObjectEvent}.
*
* @param user The username of the individual who initiated the tag association.
* @param metalake The metalake from which the tags were associated.
* @param metadataObject The metadata object with which the tags were associated.
* @param tagsToAdd The tags that were added.
* @param tagsToRemove The tags that were removed.
* @param associatedTags The resulting list of associated tags after the operation.
*/
public AssociateTagsForMetadataObjectEvent(String user, String metalake, MetadataObject metadataObject, String[] tagsToAdd, String[] tagsToRemove, String[] associatedTags) {
super(user, NameIdentifier.of(metalake));
this.metalake = metalake;
this.metadataObject = metadataObject;
this.tagsToAdd = tagsToAdd;
this.tagsToRemove = tagsToRemove;
this.associatedTags = associatedTags;
}

/**
* Provides the metalake associated with this event.
*
* @return The metalake from which the tags were associated.
*/
public String metalake() {
return metalake;
}

/**
* Provides the metadata object associated with this event.
*
* @return The {@link MetadataObject} with which the tags were associated.
*/
public MetadataObject metadataObject() {
return metadataObject;
}

/**
* Provides the tags that were added in this operation.
*
* @return An array of tag names that were added.
*/
public String[] tagsToAdd() {
return tagsToAdd;
}

/**
* Provides the tags that were removed in this operation.
*
* @return An array of tag names that were removed.
*/
public String[] tagsToRemove() {
return tagsToRemove;
}

/**
* Provides the resulting list of associated tags after the operation.
*
* @return An array of tag names representing the associated tags.
*/
public String[] associatedTags() {
return associatedTags;
}

/**
* Returns the type of operation.
*
* @return The operation type.
*/
@Override
public OperationType operationType() {
return OperationType.ASSOCIATE_TAGS_FOR_METADATA_OBJECT;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
@DeveloperApi
public final class CreateTagEvent extends TagEvent {
private final TagInfo createdTagInfo;
private final String metalake;

/**
* Constructs an instance of {@code CreateTagEvent}, capturing essential details about the
Expand All @@ -41,7 +40,6 @@ public final class CreateTagEvent extends TagEvent {
*/
public CreateTagEvent(String user, String metalake, TagInfo createdTagInfo) {
super(user, NameIdentifier.of(metalake));
this.metalake = metalake;
this.createdTagInfo = createdTagInfo;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ public final class DeleteTagEvent extends TagEvent {
* of a tag delete operation.
*
* @param user The user who initiated the delete tag operation.
* @param identifier The identifier of the tag that was attempted to be deleted.
* @param metalake The metalake from which the tag was deleted.
* @param isExists A boolean flag indicating whether the tag existed at the time of the delete
* operation.
*/
public DeleteTagEvent(String user, NameIdentifier identifier, boolean isExists) {
super(user, identifier);
public DeleteTagEvent(String user, String metalake, boolean isExists) {
super(user, NameIdentifier.of(metalake));
this.isExists = isExists;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* 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.NameIdentifier;
import org.apache.gravitino.annotation.DeveloperApi;
import org.apache.gravitino.tag.Tag;

/** Represents an event that is triggered upon successfully retrieving a tag. */
@DeveloperApi
public final class GetTagEvent extends TagEvent {
private final String metalake;
private final String tagName;
private final Tag tag;

/**
* Constructs an instance of {@code GetTagEvent}.
*
* @param user The username of the individual who initiated the tag retrieval.
* @param metalake The metalake from which the tag was retrieved.
* @param tagName The name of the tag being retrieved.
* @param tag The {@link Tag} object representing the retrieved tag.
*/
public GetTagEvent(String user, String metalake, String tagName, Tag tag) {
super(user, NameIdentifier.of(metalake));
this.metalake = metalake;
this.tagName = tagName;
this.tag = tag;
}

/**
* Provides the metalake associated with this event.
*
* @return The metalake from which the tag was retrieved.
*/
public String metalake() {
return metalake;
}

/**
* Provides the name of the retrieved tag.
*
* @return The name of the tag.
*/
public String tagName() {
return tagName;
}

/**
* Provides the retrieved tag object.
*
* @return The {@link Tag} object.
*/
public Tag tag() {
return tag;
}

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

0 comments on commit ca71a04

Please sign in to comment.