-
Notifications
You must be signed in to change notification settings - Fork 836
Add view CRUD event dispatching, hooks, audit mapping, and tests #11028
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
Open
raushanprabhakar1
wants to merge
4
commits into
apache:main
Choose a base branch
from
raushanprabhakar1:feat-11002
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
174 changes: 174 additions & 0 deletions
174
core/src/main/java/org/apache/gravitino/listener/ViewEventDispatcher.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,174 @@ | ||
| /* | ||
| * 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 javax.annotation.Nullable; | ||
| import org.apache.gravitino.NameIdentifier; | ||
| import org.apache.gravitino.Namespace; | ||
| import org.apache.gravitino.catalog.ViewDispatcher; | ||
| import org.apache.gravitino.catalog.ViewOperationDispatcher; | ||
| import org.apache.gravitino.exceptions.NoSuchSchemaException; | ||
| import org.apache.gravitino.exceptions.NoSuchViewException; | ||
| import org.apache.gravitino.exceptions.ViewAlreadyExistsException; | ||
| import org.apache.gravitino.listener.api.event.view.AlterViewEvent; | ||
| import org.apache.gravitino.listener.api.event.view.AlterViewFailureEvent; | ||
| import org.apache.gravitino.listener.api.event.view.AlterViewPreEvent; | ||
| import org.apache.gravitino.listener.api.event.view.CreateViewEvent; | ||
| import org.apache.gravitino.listener.api.event.view.CreateViewFailureEvent; | ||
| import org.apache.gravitino.listener.api.event.view.CreateViewPreEvent; | ||
| import org.apache.gravitino.listener.api.event.view.DropViewEvent; | ||
| import org.apache.gravitino.listener.api.event.view.DropViewFailureEvent; | ||
| import org.apache.gravitino.listener.api.event.view.DropViewPreEvent; | ||
| import org.apache.gravitino.listener.api.event.view.ListViewEvent; | ||
| import org.apache.gravitino.listener.api.event.view.ListViewFailureEvent; | ||
| import org.apache.gravitino.listener.api.event.view.ListViewPreEvent; | ||
| import org.apache.gravitino.listener.api.event.view.LoadViewEvent; | ||
| import org.apache.gravitino.listener.api.event.view.LoadViewFailureEvent; | ||
| import org.apache.gravitino.listener.api.event.view.LoadViewPreEvent; | ||
| import org.apache.gravitino.listener.api.info.ViewInfo; | ||
| import org.apache.gravitino.rel.Column; | ||
| import org.apache.gravitino.rel.Representation; | ||
| import org.apache.gravitino.rel.View; | ||
| import org.apache.gravitino.rel.ViewChange; | ||
| import org.apache.gravitino.utils.PrincipalUtils; | ||
|
|
||
| /** | ||
| * Decorates a {@link ViewDispatcher} to dispatch pre/post/failure view events to an {@link | ||
| * EventBus}, mirroring {@link TableEventDispatcher}. | ||
| */ | ||
| public class ViewEventDispatcher implements ViewDispatcher { | ||
|
|
||
| private final EventBus eventBus; | ||
| private final ViewDispatcher dispatcher; | ||
|
|
||
| /** | ||
| * @param eventBus event bus for listener plugins | ||
| * @param dispatcher underlying dispatcher (for example {@link ViewOperationDispatcher} behind a | ||
| * normalize layer) | ||
| */ | ||
| public ViewEventDispatcher(EventBus eventBus, ViewDispatcher dispatcher) { | ||
| this.eventBus = eventBus; | ||
| this.dispatcher = dispatcher; | ||
| } | ||
|
|
||
| @Override | ||
| public NameIdentifier[] listViews(Namespace namespace) throws NoSuchSchemaException { | ||
| eventBus.dispatchEvent(new ListViewPreEvent(PrincipalUtils.getCurrentUserName(), namespace)); | ||
| try { | ||
| NameIdentifier[] identifiers = dispatcher.listViews(namespace); | ||
| eventBus.dispatchEvent(new ListViewEvent(PrincipalUtils.getCurrentUserName(), namespace)); | ||
| return identifiers; | ||
| } catch (Exception e) { | ||
| eventBus.dispatchEvent( | ||
| new ListViewFailureEvent(PrincipalUtils.getCurrentUserName(), namespace, e)); | ||
| throw e; | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public View loadView(NameIdentifier ident) throws NoSuchViewException { | ||
| eventBus.dispatchEvent(new LoadViewPreEvent(PrincipalUtils.getCurrentUserName(), ident)); | ||
| try { | ||
| View view = dispatcher.loadView(ident); | ||
| eventBus.dispatchEvent( | ||
| new LoadViewEvent(PrincipalUtils.getCurrentUserName(), ident, new ViewInfo(view))); | ||
| return view; | ||
| } catch (Exception e) { | ||
| eventBus.dispatchEvent( | ||
| new LoadViewFailureEvent(PrincipalUtils.getCurrentUserName(), ident, e)); | ||
| throw e; | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public boolean viewExists(NameIdentifier ident) { | ||
| return dispatcher.viewExists(ident); | ||
| } | ||
|
|
||
| @Override | ||
| public View createView( | ||
| NameIdentifier ident, | ||
| @Nullable String comment, | ||
| Column[] columns, | ||
| Representation[] representations, | ||
| @Nullable String defaultCatalog, | ||
| @Nullable String defaultSchema, | ||
| Map<String, String> properties) | ||
| throws NoSuchSchemaException, ViewAlreadyExistsException { | ||
| ViewInfo createRequest = | ||
| new ViewInfo( | ||
| ident.name(), | ||
| columns, | ||
| comment, | ||
| representations, | ||
| defaultCatalog, | ||
| defaultSchema, | ||
| properties, | ||
| null); | ||
| eventBus.dispatchEvent( | ||
| new CreateViewPreEvent(PrincipalUtils.getCurrentUserName(), ident, createRequest)); | ||
| try { | ||
| View view = | ||
| dispatcher.createView( | ||
| ident, comment, columns, representations, defaultCatalog, defaultSchema, properties); | ||
| eventBus.dispatchEvent( | ||
| new CreateViewEvent(PrincipalUtils.getCurrentUserName(), ident, new ViewInfo(view))); | ||
| return view; | ||
| } catch (Exception e) { | ||
| eventBus.dispatchEvent( | ||
| new CreateViewFailureEvent(PrincipalUtils.getCurrentUserName(), ident, e, createRequest)); | ||
| throw e; | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public View alterView(NameIdentifier ident, ViewChange... changes) | ||
| throws NoSuchViewException, IllegalArgumentException { | ||
| eventBus.dispatchEvent( | ||
| new AlterViewPreEvent(PrincipalUtils.getCurrentUserName(), ident, changes)); | ||
| try { | ||
| View view = dispatcher.alterView(ident, changes); | ||
| eventBus.dispatchEvent( | ||
| new AlterViewEvent( | ||
| PrincipalUtils.getCurrentUserName(), ident, changes, new ViewInfo(view))); | ||
| return view; | ||
| } catch (Exception e) { | ||
| eventBus.dispatchEvent( | ||
| new AlterViewFailureEvent(PrincipalUtils.getCurrentUserName(), ident, e, changes)); | ||
| throw e; | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public boolean dropView(NameIdentifier ident) { | ||
| eventBus.dispatchEvent(new DropViewPreEvent(PrincipalUtils.getCurrentUserName(), ident)); | ||
| try { | ||
| boolean existed = dispatcher.dropView(ident); | ||
| eventBus.dispatchEvent( | ||
| new DropViewEvent(PrincipalUtils.getCurrentUserName(), ident, existed)); | ||
| return existed; | ||
| } catch (Exception e) { | ||
| eventBus.dispatchEvent( | ||
| new DropViewFailureEvent(PrincipalUtils.getCurrentUserName(), ident, e)); | ||
| throw e; | ||
| } | ||
| } | ||
| } |
53 changes: 53 additions & 0 deletions
53
core/src/main/java/org/apache/gravitino/listener/api/event/view/AlterViewEvent.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| /* | ||
| * 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.view; | ||
|
|
||
| import org.apache.gravitino.NameIdentifier; | ||
| import org.apache.gravitino.annotation.DeveloperApi; | ||
| import org.apache.gravitino.listener.api.event.OperationType; | ||
| import org.apache.gravitino.listener.api.info.ViewInfo; | ||
| import org.apache.gravitino.rel.ViewChange; | ||
|
|
||
| /** Successful alter-view event. */ | ||
| @DeveloperApi | ||
| public final class AlterViewEvent extends ViewEvent { | ||
| private final ViewInfo updatedViewInfo; | ||
| private final ViewChange[] viewChanges; | ||
|
|
||
| public AlterViewEvent( | ||
| String user, NameIdentifier identifier, ViewChange[] viewChanges, ViewInfo updatedViewInfo) { | ||
| super(user, identifier); | ||
| this.viewChanges = viewChanges.clone(); | ||
| this.updatedViewInfo = updatedViewInfo; | ||
| } | ||
|
|
||
| public ViewInfo updatedViewInfo() { | ||
| return updatedViewInfo; | ||
| } | ||
|
|
||
| public ViewChange[] viewChanges() { | ||
| return viewChanges; | ||
| } | ||
|
|
||
| @Override | ||
| public OperationType operationType() { | ||
| return OperationType.ALTER_VIEW; | ||
| } | ||
| } |
46 changes: 46 additions & 0 deletions
46
core/src/main/java/org/apache/gravitino/listener/api/event/view/AlterViewFailureEvent.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| /* | ||
| * 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.view; | ||
|
|
||
| import org.apache.gravitino.NameIdentifier; | ||
| import org.apache.gravitino.annotation.DeveloperApi; | ||
| import org.apache.gravitino.listener.api.event.OperationType; | ||
| import org.apache.gravitino.rel.ViewChange; | ||
|
|
||
| /** Failure event for altering a view. */ | ||
| @DeveloperApi | ||
| public final class AlterViewFailureEvent extends ViewFailureEvent { | ||
| private final ViewChange[] viewChanges; | ||
|
|
||
| public AlterViewFailureEvent( | ||
| String user, NameIdentifier identifier, Exception exception, ViewChange[] viewChanges) { | ||
| super(user, identifier, exception); | ||
| this.viewChanges = viewChanges.clone(); | ||
| } | ||
|
|
||
| public ViewChange[] viewChanges() { | ||
| return viewChanges; | ||
| } | ||
|
|
||
| @Override | ||
| public OperationType operationType() { | ||
| return OperationType.ALTER_VIEW; | ||
| } | ||
| } |
45 changes: 45 additions & 0 deletions
45
core/src/main/java/org/apache/gravitino/listener/api/event/view/AlterViewPreEvent.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| /* | ||
| * 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.view; | ||
|
|
||
| import org.apache.gravitino.NameIdentifier; | ||
| import org.apache.gravitino.annotation.DeveloperApi; | ||
| import org.apache.gravitino.listener.api.event.OperationType; | ||
| import org.apache.gravitino.rel.ViewChange; | ||
|
|
||
| /** Pre-event before altering a view. */ | ||
| @DeveloperApi | ||
| public class AlterViewPreEvent extends ViewPreEvent { | ||
| private final ViewChange[] viewChanges; | ||
|
|
||
| public AlterViewPreEvent(String user, NameIdentifier identifier, ViewChange[] viewChanges) { | ||
| super(user, identifier); | ||
| this.viewChanges = viewChanges; | ||
| } | ||
|
|
||
| public ViewChange[] viewChanges() { | ||
| return viewChanges; | ||
| } | ||
|
|
||
| @Override | ||
| public OperationType operationType() { | ||
| return OperationType.ALTER_VIEW; | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.