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

[#5550] feat(core): add partition pre event to Gravitino event #5590

Merged
Merged
Show file tree
Hide file tree
Changes from 10 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 @@ -25,18 +25,24 @@
import org.apache.gravitino.exceptions.PartitionAlreadyExistsException;
import org.apache.gravitino.listener.api.event.AddPartitionEvent;
import org.apache.gravitino.listener.api.event.AddPartitionFailureEvent;
import org.apache.gravitino.listener.api.event.AddPartitionPreEvent;
import org.apache.gravitino.listener.api.event.DropPartitionEvent;
import org.apache.gravitino.listener.api.event.DropPartitionFailureEvent;
import org.apache.gravitino.listener.api.event.DropPartitionPreEvent;
import org.apache.gravitino.listener.api.event.GetPartitionEvent;
import org.apache.gravitino.listener.api.event.GetPartitionFailureEvent;
import org.apache.gravitino.listener.api.event.GetPartitionPreEvent;
import org.apache.gravitino.listener.api.event.ListPartitionEvent;
import org.apache.gravitino.listener.api.event.ListPartitionFailureEvent;
import org.apache.gravitino.listener.api.event.ListPartitionNamesEvent;
import org.apache.gravitino.listener.api.event.ListPartitionNamesFailureEvent;
import org.apache.gravitino.listener.api.event.ListPartitionNamesPreEvent;
import org.apache.gravitino.listener.api.event.ListPartitionPreEvent;
import org.apache.gravitino.listener.api.event.PartitionExistsEvent;
import org.apache.gravitino.listener.api.event.PartitionExistsFailureEvent;
import org.apache.gravitino.listener.api.event.PurgePartitionEvent;
import org.apache.gravitino.listener.api.event.PurgePartitionFailureEvent;
import org.apache.gravitino.listener.api.event.PurgePartitionPreEvent;
import org.apache.gravitino.listener.api.info.partitions.PartitionInfo;
import org.apache.gravitino.rel.partitions.Partition;
import org.apache.gravitino.utils.PrincipalUtils;
Expand Down Expand Up @@ -66,6 +72,9 @@ public PartitionEventDispatcher(EventBus eventBus, PartitionDispatcher dispatche
@Override
public Partition addPartition(NameIdentifier ident, Partition partition)
throws NoSuchPartitionException, PartitionAlreadyExistsException {
eventBus.dispatchEvent(
new AddPartitionPreEvent(
PrincipalUtils.getCurrentUserName(), ident, PartitionInfo.of(partition)));
try {
Partition newPartition = dispatcher.addPartition(ident, partition);
eventBus.dispatchEvent(
Expand All @@ -84,6 +93,8 @@ public Partition addPartition(NameIdentifier ident, Partition partition)
@Override
public Partition getPartition(NameIdentifier ident, String partitionName)
throws NoSuchPartitionException {
eventBus.dispatchEvent(
new GetPartitionPreEvent(PrincipalUtils.getCurrentUserName(), ident, partitionName));
try {
Partition partition = dispatcher.getPartition(ident, partitionName);
eventBus.dispatchEvent(
Expand All @@ -100,6 +111,8 @@ public Partition getPartition(NameIdentifier ident, String partitionName)

@Override
public boolean dropPartition(NameIdentifier ident, String partitionName) {
eventBus.dispatchEvent(
new DropPartitionPreEvent(PrincipalUtils.getCurrentUserName(), ident, partitionName));
try {
boolean isExists = dispatcher.dropPartition(ident, partitionName);
eventBus.dispatchEvent(
Expand All @@ -116,6 +129,7 @@ public boolean dropPartition(NameIdentifier ident, String partitionName) {

@Override
public Partition[] listPartitions(NameIdentifier ident) {
eventBus.dispatchEvent(new ListPartitionPreEvent(PrincipalUtils.getCurrentUserName(), ident));
try {
Partition[] listPartitions = dispatcher.listPartitions(ident);
eventBus.dispatchEvent(new ListPartitionEvent(PrincipalUtils.getCurrentUserName(), ident));
Expand All @@ -129,6 +143,8 @@ public Partition[] listPartitions(NameIdentifier ident) {

@Override
public String[] listPartitionNames(NameIdentifier ident) {
eventBus.dispatchEvent(
new ListPartitionNamesPreEvent(PrincipalUtils.getCurrentUserName(), ident));
try {
String[] listPartitionNames = dispatcher.listPartitionNames(ident);
eventBus.dispatchEvent(
Expand Down Expand Up @@ -159,6 +175,8 @@ public boolean partitionExists(NameIdentifier ident, String partitionName) {

@Override
public boolean purgePartition(NameIdentifier ident, String partitionName) {
eventBus.dispatchEvent(
new PurgePartitionPreEvent(PrincipalUtils.getCurrentUserName(), ident, partitionName));
try {
boolean isExists = dispatcher.purgePartition(ident, partitionName);
eventBus.dispatchEvent(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* 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.listener.api.info.TableInfo;
import org.apache.gravitino.listener.api.info.partitions.PartitionInfo;

/** Represents an event triggered before creating a partition. */
@DeveloperApi
public class AddPartitionPreEvent extends PartitionPreEvent {

private final PartitionInfo createPartitionRequest;

public AddPartitionPreEvent(
String user, NameIdentifier identifier, PartitionInfo createPartitionRequest) {
super(user, identifier);
this.createPartitionRequest = createPartitionRequest;
}

/**
* Retrieves the create partition request.
*
* @return A {@link TableInfo} instance encapsulating the comprehensive details of create
* partition request.
*/
public PartitionInfo createdPartitionRequest() {
return createPartitionRequest;
}

/**
* Returns the type of operation.
*
* @return the operation type.
*/
@Override
public OperationType operationType() {
return OperationType.ADD_PARTITION;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* 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 that is triggered before dropping a partition. */
@DeveloperApi
public class DropPartitionPreEvent extends PartitionPreEvent {
private final String partitionName;

public DropPartitionPreEvent(String user, NameIdentifier identifier, String partitionName) {
super(user, identifier);
this.partitionName = partitionName;
}

public String partitionName() {
return partitionName;
}

/**
* Returns the type of operation.
*
* @return the operation type.
*/
@Override
public OperationType operationType() {
return OperationType.DROP_PARTITION;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* 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 that is triggered before getting a partition. */
@DeveloperApi
public class GetPartitionPreEvent extends PartitionPreEvent {

private final String partitionName;

public GetPartitionPreEvent(String user, NameIdentifier identifier, String partitionName) {
super(user, identifier);
this.partitionName = partitionName;
}

public String partitionName() {
return partitionName;
}

/**
* Returns the type of operation.
*
* @return the operation type.
*/
@Override
public OperationType operationType() {
return OperationType.LOAD_PARTITION;
}
}
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.annotation.DeveloperApi;

/** Represents an event that is triggered before listing of partition name within a namespace. */
@DeveloperApi
public class ListPartitionNamesPreEvent extends PartitionPreEvent {

public ListPartitionNamesPreEvent(String user, NameIdentifier identifier) {
super(user, identifier);
}

/**
* Returns the type of operation.
*
* @return the operation type.
*/
@Override
public OperationType operationType() {
return OperationType.LIST_PARTITION_NAMES;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* 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 that is triggered before listing of partition within a namespace. */
@DeveloperApi
public class ListPartitionPreEvent extends PartitionPreEvent {

public ListPartitionPreEvent(String user, NameIdentifier identifier) {
super(user, identifier);
}
/**
* Returns the type of operation.
*
* @return the operation type.
*/
@Override
public OperationType operationType() {
return OperationType.LIST_PARTITION;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* 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 a pre-event for partition operations. */
@DeveloperApi
public abstract class PartitionPreEvent extends PreEvent {

protected PartitionPreEvent(String user, NameIdentifier identifier) {
super(user, identifier);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* 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 purging a partition. */
@DeveloperApi
public class PurgePartitionPreEvent extends PartitionPreEvent {

private final String partitionName;

public PurgePartitionPreEvent(String user, NameIdentifier identifier, String partitionName) {
super(user, identifier);
this.partitionName = partitionName;
}

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