Skip to content
Open
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
11 changes: 8 additions & 3 deletions core/src/main/java/org/apache/gravitino/GravitinoEnv.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
import org.apache.gravitino.listener.TableEventDispatcher;
import org.apache.gravitino.listener.TagEventDispatcher;
import org.apache.gravitino.listener.TopicEventDispatcher;
import org.apache.gravitino.listener.ViewEventDispatcher;
import org.apache.gravitino.lock.LockManager;
import org.apache.gravitino.metalake.MetalakeDispatcher;
import org.apache.gravitino.metalake.MetalakeManager;
Expand Down Expand Up @@ -633,13 +634,17 @@ private void initGravitinoServerComponents() {
new FunctionEventDispatcher(eventBus, functionNormalizeDispatcher);
this.functionDispatcher = new FunctionHookDispatcher(functionEventDispatcher);

// TODO: Add ViewHookDispatcher and ViewEventDispatcher when needed for view-specific hooks
// and event handling.
// View operation chain: ViewEventDispatcher -> ViewNormalizeDispatcher ->
// ViewOperationDispatcher.
// TODO(#11007): Add ViewHookDispatcher for view ownership and privilege hooks when view
// privilege support is finalized.
ViewOperationDispatcher viewOperationDispatcher =
new ViewOperationDispatcher(catalogManager, entityStore, idGenerator);
ViewNormalizeDispatcher viewNormalizeDispatcher =
new ViewNormalizeDispatcher(viewOperationDispatcher, catalogManager);
this.viewDispatcher = viewNormalizeDispatcher;
ViewEventDispatcher viewEventDispatcher =
new ViewEventDispatcher(eventBus, viewNormalizeDispatcher);
this.viewDispatcher = viewEventDispatcher;

this.statisticDispatcher =
new StatisticEventDispatcher(
Expand Down
20 changes: 20 additions & 0 deletions core/src/main/java/org/apache/gravitino/audit/AuditLog.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,16 @@
import org.apache.gravitino.listener.api.event.PurgePartitionFailureEvent;
import org.apache.gravitino.listener.api.event.PurgeTableEvent;
import org.apache.gravitino.listener.api.event.PurgeTableFailureEvent;
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.CreateViewEvent;
import org.apache.gravitino.listener.api.event.view.CreateViewFailureEvent;
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.ListViewEvent;
import org.apache.gravitino.listener.api.event.view.ListViewFailureEvent;
import org.apache.gravitino.listener.api.event.view.LoadViewEvent;
import org.apache.gravitino.listener.api.event.view.LoadViewFailureEvent;

/** The interface define unified audit log schema. */
public interface AuditLog {
Expand Down Expand Up @@ -551,6 +561,16 @@ public static Operation fromEvent(Event event) {
return LOAD_TOPIC;
} else if (event instanceof ListTopicEvent || event instanceof ListTopicFailureEvent) {
return LIST_TOPIC;
} else if (event instanceof CreateViewEvent || event instanceof CreateViewFailureEvent) {
return CREATE_VIEW;
} else if (event instanceof AlterViewEvent || event instanceof AlterViewFailureEvent) {
return ALTER_VIEW;
} else if (event instanceof DropViewEvent || event instanceof DropViewFailureEvent) {
return DROP_VIEW;
} else if (event instanceof LoadViewEvent || event instanceof LoadViewFailureEvent) {
return LOAD_VIEW;
} else if (event instanceof ListViewEvent || event instanceof ListViewFailureEvent) {
return LIST_VIEW;
} else if (event instanceof CreateFilesetEvent
|| event instanceof CreateFilesetFailureEvent) {
return CREATE_FILESET;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,10 @@ public static List<String> getMetadataObjectLocation(
case TOPIC:
// Topic doesn't have locations now.
break;
case VIEW:
// Views are logical metadata objects without a single storage location; privilege plugins
// operate on metadata only (same idea as TOPIC).
break;
default:
throw new AuthorizationPluginException(
"Failed to get location paths for metadata object %s type %s", ident, type);
Expand Down
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;
}
}
}
Comment thread
raushanprabhakar1 marked this conversation as resolved.
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;
}
}
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;
}
}
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;
}
}
Loading