Skip to content

Commit

Permalink
iceberg event listener
Browse files Browse the repository at this point in the history
  • Loading branch information
FANNG1 committed Sep 24, 2024
1 parent 9587258 commit 62bc636
Show file tree
Hide file tree
Showing 4 changed files with 187 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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<String, String> 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;
}
}
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.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;
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}

0 comments on commit 62bc636

Please sign in to comment.