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

Draft
wants to merge 14 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,22 @@
import java.util.Map;
import org.apache.gravitino.MetadataObject;
import org.apache.gravitino.exceptions.NoSuchTagException;
import org.apache.gravitino.listener.api.event.AlterTagPreEvent;
import org.apache.gravitino.listener.api.event.AssociateTagsForMetadataObjectPreEvent;
import org.apache.gravitino.listener.api.event.CreateTagPreEvent;
import org.apache.gravitino.listener.api.event.DeleteTagPreEvent;
import org.apache.gravitino.listener.api.event.GetTagForMetadataObjectPreEvent;
import org.apache.gravitino.listener.api.event.GetTagPreEvent;
import org.apache.gravitino.listener.api.event.ListMetadataObjectsForTagPreEvent;
import org.apache.gravitino.listener.api.event.ListTagsForMetadataObjectPreEvent;
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;
import org.apache.gravitino.tag.TagDispatcher;
import org.apache.gravitino.utils.PrincipalUtils;

/**
* {@code TagEventDispatcher} is a decorator for {@link TagDispatcher} that not only delegates tag
Expand All @@ -45,7 +58,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 @@ -57,7 +70,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 @@ -69,7 +82,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 @@ -82,7 +95,10 @@ public Tag getTag(String metalake, String name) throws NoSuchTagException {
@Override
public Tag createTag(
String metalake, String name, String comment, Map<String, String> properties) {
// TODO: createTagPreEvent
TagInfo createTagRequest = new TagInfo(name, comment, properties);

eventBus.dispatchEvent(
new CreateTagPreEvent(PrincipalUtils.getCurrentUserName(), metalake, createTagRequest));
try {
// TODO: createTagEvent
return dispatcher.createTag(metalake, name, comment, properties);
Expand All @@ -94,7 +110,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 @@ -106,7 +125,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 @@ -118,7 +140,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 @@ -130,7 +153,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 @@ -142,7 +168,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 @@ -155,7 +183,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 @@ -168,7 +203,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.NameIdentifier;
import org.apache.gravitino.annotation.DeveloperApi;
import org.apache.gravitino.tag.TagChange;

/** 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 tagName The name of the tag being altered.
* @param changes The changes being applied to the tag.
*/
public AlterTagPreEvent(String user, String metalake, String tagName, TagChange[] changes) {
super(user, NameIdentifier.of(metalake, tagName));
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,89 @@
/*
* 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.NameIdentifier;
import org.apache.gravitino.annotation.DeveloperApi;

/** Represents an event triggered before associating tags with a specific metadata object. */
@DeveloperApi
public class AssociateTagsForMetadataObjectPreEvent extends TagPreEvent {
private final MetadataObject metadataObject;
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, NameIdentifier.of(metalake));
this.metadataObject = metadataObject;
this.tagsToAdd = tagsToAdd;
this.tagsToRemove = tagsToRemove;
}

/**
* Returns the metadata object associated with this event.
*
* @return The metadata object instance.
*/
public MetadataObject getMetadataObject() {
return metadataObject;
}

/**
* 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,41 @@
/*
* 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.listener.api.info.TagInfo;

public class CreateTagPreEvent extends TagPreEvent {
private final TagInfo createTagRequest;

public CreateTagPreEvent(String user, String metalake, TagInfo createTagRequest) {
super(user, NameIdentifier.of(metalake));
this.createTagRequest = createTagRequest;
}

public TagInfo getCreateTagRequest() {
return createTagRequest;
}

@Override
public OperationType operationType() {
return OperationType.CREATE_TAG;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* 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;

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

public DeleteTagPreEvent(String user, String metalake, String tagName) {
super(user, NameIdentifier.of(metalake, tagName));
}

@Override
public OperationType operationType() {
return OperationType.DELETE_TAG;
}
}
Loading
Loading