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
6 changes: 6 additions & 0 deletions core/src/main/java/org/apache/iceberg/rest/ResourcePaths.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ public static String tokens() {
return "v1/oauth/tokens";
}

public static final String V1_EVENTS = "/v1/{prefix}/events";

private final String prefix;
private final String namespaceSeparator;

Expand Down Expand Up @@ -151,6 +153,10 @@ public String renameView() {
return SLASH.join("v1", prefix, "views", "rename");
}

public String events() {
return SLASH.join("v1", prefix, "events");
}

public String planTableScan(TableIdentifier ident) {
return SLASH.join(
"v1",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* 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.iceberg.rest.requests;

import java.util.List;
import java.util.Map;
import org.apache.iceberg.rest.RESTRequest;
import org.immutables.value.Value;

@Value.Immutable
public interface PostEventsRequest extends RESTRequest {

List<Map<String, Object>> events();

@Override
default void validate() {
// nothing to validate for test harness
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* 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.iceberg.rest.responses;

import java.util.List;
import java.util.Map;
import org.apache.iceberg.rest.RESTResponse;
import org.immutables.value.Value;

@Value.Immutable
public interface EventsResponse extends RESTResponse {

List<Map<String, Object>> events();

static EventsResponse of(List<Map<String, Object>> events) {
return ImmutableEventsResponse.builder().addAllEvents(events).build();
}
}
16 changes: 16 additions & 0 deletions core/src/test/java/org/apache/iceberg/rest/RESTCatalogAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,15 @@
import org.apache.iceberg.rest.requests.RegisterTableRequest;
import org.apache.iceberg.rest.requests.RenameTableRequest;
import org.apache.iceberg.rest.requests.ReportMetricsRequest;
import org.apache.iceberg.rest.requests.PostEventsRequest;
import org.apache.iceberg.rest.requests.UpdateNamespacePropertiesRequest;
import org.apache.iceberg.rest.requests.UpdateTableRequest;
import org.apache.iceberg.rest.responses.ConfigResponse;
import org.apache.iceberg.rest.responses.ErrorResponse;
import org.apache.iceberg.rest.responses.LoadTableResponse;
import org.apache.iceberg.rest.responses.OAuthTokenResponse;
import org.apache.iceberg.util.Pair;
import org.apache.iceberg.rest.events.InMemoryEventsStore;
import org.apache.iceberg.util.PropertyUtil;

/** Adaptor class to translate REST requests into {@link Catalog} API calls. */
Expand Down Expand Up @@ -114,6 +116,8 @@ public class RESTCatalogAdapter extends BaseHTTPClient {

private AuthSession authSession = AuthSession.EMPTY;
private PlanningBehavior planningBehavior;
// single in-memory store used by test REST server
private static final InMemoryEventsStore EVENTS_STORE = new InMemoryEventsStore();

public RESTCatalogAdapter(Catalog catalog) {
this.catalog = catalog;
Expand Down Expand Up @@ -388,6 +392,18 @@ public <T extends RESTResponse> T handleRequest(
// nothing to do here other than checking that we're getting the correct request
castRequest(ReportMetricsRequest.class, body);
return null;

case EVENTS_POST:
{
PostEventsRequest request = castRequest(PostEventsRequest.class, body);
EVENTS_STORE.postEvents(request.events());
return castResponse(responseType, EventsResponse.of(EVENTS_STORE.getEvents()));
}

case EVENTS_GET:
{
return castResponse(responseType, EventsResponse.of(EVENTS_STORE.getEvents()));
}
}

case COMMIT_TRANSACTION:
Expand Down
11 changes: 9 additions & 2 deletions core/src/test/java/org/apache/iceberg/rest/Route.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.apache.iceberg.rest.requests.PlanTableScanRequest;
import org.apache.iceberg.rest.requests.RegisterTableRequest;
import org.apache.iceberg.rest.requests.RenameTableRequest;
import org.apache.iceberg.rest.requests.PostEventsRequest;
import org.apache.iceberg.rest.requests.ReportMetricsRequest;
import org.apache.iceberg.rest.requests.UpdateNamespacePropertiesRequest;
import org.apache.iceberg.rest.requests.UpdateTableRequest;
Expand All @@ -44,6 +45,7 @@
import org.apache.iceberg.rest.responses.LoadViewResponse;
import org.apache.iceberg.rest.responses.OAuthTokenResponse;
import org.apache.iceberg.rest.responses.PlanTableScanResponse;
import org.apache.iceberg.rest.responses.EventsResponse;
import org.apache.iceberg.rest.responses.UpdateNamespacePropertiesResponse;
import org.apache.iceberg.util.Pair;

Expand Down Expand Up @@ -130,8 +132,13 @@ enum Route {
ResourcePaths.V1_TABLE_SCAN_PLAN_TASKS,
FetchScanTasksRequest.class,
FetchScanTasksResponse.class),
CANCEL_PLAN_TABLE_SCAN(
HTTPRequest.HTTPMethod.DELETE, ResourcePaths.V1_TABLE_SCAN_PLAN, null, null);
CANCEL_PLAN_TABLE_SCAN(
HTTPRequest.HTTPMethod.DELETE, ResourcePaths.V1_TABLE_SCAN_PLAN, null, null),

EVENTS_POST(
HTTPRequest.HTTPMethod.POST, ResourcePaths.V1_EVENTS, PostEventsRequest.class, EventsResponse.class),

EVENTS_GET(HTTPRequest.HTTPMethod.GET, ResourcePaths.V1_EVENTS, null, EventsResponse.class);

private final HTTPRequest.HTTPMethod method;
private final int requiredLength;
Expand Down
49 changes: 49 additions & 0 deletions core/src/test/java/org/apache/iceberg/rest/TestEventsEndpoint.java
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.iceberg.rest;

import static org.assertj.core.api.Assertions.assertThat;

import java.util.Collections;
import java.util.List;
import java.util.Map;
import org.apache.iceberg.rest.requests.PostEventsRequest;
import org.apache.iceberg.rest.responses.EventsResponse;
import org.junit.Test;

public class TestEventsEndpoint {

@Test
public void testPostAndGetEvents() {
RESTCatalogAdapter adapter = new RESTCatalogAdapter(null) {};

PostEventsRequest req = ImmutablePostEventsRequest.builder().addAllEvents(Collections.emptyList()).build();

EventsResponse postResp = adapter.handleRequest(Route.EVENTS_POST, Collections.emptyMap(),
ImmutableHTTPRequest.builder().method(HTTPRequest.HTTPMethod.POST).path("v1/test/events").build(), EventsResponse.class, headers -> {});

assertThat(postResp).isNotNull();

EventsResponse getResp = adapter.handleRequest(Route.EVENTS_GET, Collections.emptyMap(),
ImmutableHTTPRequest.builder().method(HTTPRequest.HTTPMethod.GET).path("v1/test/events").build(), EventsResponse.class, headers -> {});

assertThat(getResp).isNotNull();
assertThat(getResp.events()).isNotNull();
}
}
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.iceberg.rest.events;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CopyOnWriteArrayList;

/** Simple in-memory events store for test harness use. */
public class InMemoryEventsStore {
private final List<Map<String, Object>> events = new CopyOnWriteArrayList<>();

public void postEvents(List<Map<String, Object>> evts) {
if (evts != null && !evts.isEmpty()) {
events.addAll(evts);
}
}

public List<Map<String, Object>> getEvents() {
return Collections.unmodifiableList(new ArrayList<>(events));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* 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.iceberg.rest.requests;

import java.util.List;
import java.util.Map;
import org.apache.iceberg.rest.RESTRequest;
import org.immutables.value.Value;

@Value.Immutable
public interface PostEventsRequest extends RESTRequest {

List<Map<String, Object>> events();

@Override
default void validate() {
// nothing to validate for test harness
}
}
Loading