Skip to content
This repository has been archived by the owner on Nov 14, 2024. It is now read-only.

[PDS-350703 and Others | i like trains] Part 1: Conjure Undertow, and Flattening Subresource Locators #6518

Merged
merged 15 commits into from
Apr 17, 2023
7 changes: 7 additions & 0 deletions changelog/@unreleased/pr-6518.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
type: improvement
improvement:
description: We no longer use Jersey sub-resource locators for user-facing timestamp,
timestamp management and lock v1 endpoints (except for the asynchronous TimeLock
service).
links:
- https://github.com/palantir/atlasdb/pull/6518
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* (c) Copyright 2023 Palantir Technologies Inc. All rights reserved.
*
* Licensed 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 com.palantir.timelock.paxos;

import com.google.common.collect.ImmutableSet;
import com.palantir.atlasdb.http.RedirectRetryTargeter;
import com.palantir.atlasdb.timelock.LockV1Resource;
import com.palantir.atlasdb.timelock.LockV1ResourceEndpoints;
import com.palantir.atlasdb.timelock.TimelockNamespaces;
import com.palantir.atlasdb.timelock.TimestampManagementResource;
import com.palantir.atlasdb.timelock.TimestampManagementResourceEndpoints;
import com.palantir.atlasdb.timelock.TimestampResource;
import com.palantir.atlasdb.timelock.TimestampResourceEndpoints;
import com.palantir.conjure.java.undertow.lib.UndertowService;
import java.util.Set;
import java.util.stream.Collectors;

public final class NonConjureTimelockResources {
private NonConjureTimelockResources() {
// utility
}

public static Set<UndertowService> createUndertowServices(
TimelockNamespaces namespaces, RedirectRetryTargeter redirectRetryTargeter) {
Set<UndertowService> rawServices = ImmutableSet.of(
LockV1ResourceEndpoints.of(new LockV1Resource(namespaces)),
TimestampResourceEndpoints.of(new TimestampResource(namespaces)),
TimestampManagementResourceEndpoints.of(new TimestampManagementResource(namespaces)));

return rawServices.stream()
.map(service -> new TimelockUndertowExceptionWrapper(service, redirectRetryTargeter))
.collect(Collectors.toSet());
}

public static Set<Object> createJerseyResources(TimelockNamespaces namespaces) {
return ImmutableSet.of(
new LockV1Resource(namespaces),
new TimestampResource(namespaces),
new TimestampManagementResource(namespaces));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -325,10 +325,9 @@ private void createAndRegisterResources() {
Suppliers.compose(TimeLockRuntimeConfiguration::maxNumberOfClients, runtime::get));

registerManagementResource();
// Finally, register the health check, and endpoints associated with the clients.
TimeLockResource resource = TimeLockResource.create(namespaces);
healthCheck = paxosResources.leadershipComponents().healthCheck(namespaces::getActiveClients);

TimeLockResource resource = TimeLockResource.create(namespaces);
registrar.accept(resource);

Function<String, LockService> lockServiceGetter =
Expand All @@ -352,13 +351,16 @@ private void createAndRegisterResources() {
registerCorruptionHandlerWrappedService(
presentUndertowRegistrar,
MultiClientConjureTimelockResource.undertow(redirectRetryTargeter, asyncTimelockServiceGetter));
NonConjureTimelockResources.createUndertowServices(namespaces, redirectRetryTargeter)
.forEach(service -> registerCorruptionHandlerWrappedService(presentUndertowRegistrar, service));
} else {
registrar.accept(ConjureTimelockResource.jersey(redirectRetryTargeter, asyncTimelockServiceGetter));
registrar.accept(ConjureLockWatchingResource.jersey(redirectRetryTargeter, asyncTimelockServiceGetter));
registrar.accept(ConjureLockV1Resource.jersey(redirectRetryTargeter, lockServiceGetter));
registrar.accept(TimeLockPaxosHistoryProviderResource.jersey(corruptionComponents.localHistoryLoader()));
registrar.accept(
MultiClientConjureTimelockResource.jersey(redirectRetryTargeter, asyncTimelockServiceGetter));
NonConjureTimelockResources.createJerseyResources(namespaces).forEach(registrar);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@
import java.util.List;
import java.util.function.Function;

/**
* For endpoints that pre-date the introduction of conjure, we need to be able to handle legacy requests in a
* consistent way without breaking API, hence the existence of this class. Resources and services with endpoints
* predating the introduction of conjure should be wrapped in this wrapper.
*/
final class TimelockUndertowExceptionWrapper implements UndertowService {

private final UndertowService delegate;
Expand Down
Loading