From 62bc636a92a991524fcdeca257f839ea52bdf62d Mon Sep 17 00:00:00 2001 From: fanng Date: Tue, 24 Sep 2024 15:36:16 +0800 Subject: [PATCH] iceberg event listener --- .../iceberg/extension/IcebergEventLogger.java | 62 +++++++++++++++++++ .../api/event/IcebergCreateTableEvent.java | 48 ++++++++++++++ .../listener/api/event/IcebergEvent.java | 28 +++++++++ .../api/event/IcebergUpdateTableEvent.java | 49 +++++++++++++++ 4 files changed, 187 insertions(+) create mode 100644 iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/iceberg/extension/IcebergEventLogger.java create mode 100644 iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/listener/api/event/IcebergCreateTableEvent.java create mode 100644 iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/listener/api/event/IcebergEvent.java create mode 100644 iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/listener/api/event/IcebergUpdateTableEvent.java diff --git a/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/iceberg/extension/IcebergEventLogger.java b/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/iceberg/extension/IcebergEventLogger.java new file mode 100644 index 00000000000..6a84dd4853e --- /dev/null +++ b/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/iceberg/extension/IcebergEventLogger.java @@ -0,0 +1,62 @@ +/* + * 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.iceberg.extension; + +import java.util.Map; +import org.apache.gravitino.listener.api.EventListenerPlugin; +import org.apache.gravitino.listener.api.event.Event; +import org.apache.gravitino.listener.api.event.IcebergCreateTableEvent; +import org.apache.gravitino.listener.api.event.IcebergUpdateTableEvent; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class IcebergEventLogger implements EventListenerPlugin { + + private static final Logger LOG = LoggerFactory.getLogger(IcebergEventLogger.class); + + @Override + public void init(Map properties) throws RuntimeException {} + + @Override + public void start() throws RuntimeException {} + + @Override + public void stop() throws RuntimeException {} + + @Override + public void onPostEvent(Event event) throws RuntimeException { + if (event instanceof IcebergCreateTableEvent) { + LOG.info( + "Create table event, request: {}", + ((IcebergCreateTableEvent) event).createTableRequest()); + } else if (event instanceof IcebergUpdateTableEvent) { + LOG.info( + "Update table event, request: {}", + ((IcebergUpdateTableEvent) event).updateTableRequest()); + } else { + LOG.info("Unknown event: {}", event.getClass().getSimpleName()); + } + } + + @Override + public Mode mode() { + return Mode.ASYNC_ISOLATED; + } +} diff --git a/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/listener/api/event/IcebergCreateTableEvent.java b/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/listener/api/event/IcebergCreateTableEvent.java new file mode 100644 index 00000000000..57980d58b44 --- /dev/null +++ b/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/listener/api/event/IcebergCreateTableEvent.java @@ -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.iceberg.rest.requests.CreateTableRequest; +import org.apache.iceberg.rest.responses.LoadTableResponse; + +public class IcebergCreateTableEvent extends IcebergEvent { + + private CreateTableRequest createTableRequest; + private LoadTableResponse loadTableResponse; + + public IcebergCreateTableEvent( + String user, + NameIdentifier resourceIdentifier, + CreateTableRequest createTableRequest, + LoadTableResponse loadTableResponse) { + super(user, resourceIdentifier); + this.createTableRequest = createTableRequest; + this.loadTableResponse = loadTableResponse; + } + + public CreateTableRequest createTableRequest() { + return createTableRequest; + } + + public LoadTableResponse loadTableResponse() { + return loadTableResponse; + } +} diff --git a/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/listener/api/event/IcebergEvent.java b/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/listener/api/event/IcebergEvent.java new file mode 100644 index 00000000000..3dda9ea111e --- /dev/null +++ b/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/listener/api/event/IcebergEvent.java @@ -0,0 +1,28 @@ +/* + * 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; + +public abstract class IcebergEvent extends Event { + public IcebergEvent(String user, NameIdentifier resourceIdentifier) { + super(user, resourceIdentifier); + } +} diff --git a/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/listener/api/event/IcebergUpdateTableEvent.java b/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/listener/api/event/IcebergUpdateTableEvent.java new file mode 100644 index 00000000000..2cd83662b28 --- /dev/null +++ b/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/listener/api/event/IcebergUpdateTableEvent.java @@ -0,0 +1,49 @@ +/* + * 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.iceberg.rest.requests.UpdateTableRequest; +import org.apache.iceberg.rest.responses.LoadTableResponse; + +public class IcebergUpdateTableEvent extends IcebergEvent { + + private UpdateTableRequest updateTableRequest; + // Iceberg table information after the table is updated. + private LoadTableResponse loadTableResponse; + + public IcebergUpdateTableEvent( + String user, + NameIdentifier resourceIdentifier, + UpdateTableRequest updateTableRequest, + LoadTableResponse loadTableResponse) { + super(user, resourceIdentifier); + this.updateTableRequest = updateTableRequest; + this.loadTableResponse = loadTableResponse; + } + + public UpdateTableRequest updateTableRequest() { + return updateTableRequest; + } + + public LoadTableResponse loadTableResponse() { + return loadTableResponse; + } +}