Search in sources :

Example 1 with AuthHeader

use of com.palantir.tokens.auth.AuthHeader in project conjure-java by palantir.

the class AuthTest method testParseAuthHeader.

@Test
public void testParseAuthHeader() {
    AuthHeader expected = AuthHeader.of(BearerToken.valueOf("token"));
    HttpServerExchange exchange = HttpServerExchanges.createStub();
    exchange.getRequestHeaders().add(Headers.AUTHORIZATION, expected.toString());
    assertThat(CONTEXT.auth().header(exchange)).isEqualTo(expected);
}
Also used : HttpServerExchange(io.undertow.server.HttpServerExchange) AuthHeader(com.palantir.tokens.auth.AuthHeader) Test(org.junit.jupiter.api.Test)

Example 2 with AuthHeader

use of com.palantir.tokens.auth.AuthHeader in project conjure-java by palantir.

the class EteServiceBlocking method of.

/**
 * Creates a synchronous/blocking client for a EteService service.
 */
static EteServiceBlocking of(EndpointChannelFactory _endpointChannelFactory, ConjureRuntime _runtime) {
    return new EteServiceBlocking() {

        private final PlainSerDe _plainSerDe = _runtime.plainSerDe();

        private final EndpointChannel stringChannel = _endpointChannelFactory.endpoint(DialogueEteEndpoints.string);

        private final Deserializer<String> stringDeserializer = _runtime.bodySerDe().deserializer(new TypeMarker<String>() {
        });

        private final EndpointChannel integerChannel = _endpointChannelFactory.endpoint(DialogueEteEndpoints.integer);

        private final Deserializer<Integer> integerDeserializer = _runtime.bodySerDe().deserializer(new TypeMarker<Integer>() {
        });

        private final EndpointChannel double_Channel = _endpointChannelFactory.endpoint(DialogueEteEndpoints.double_);

        private final Deserializer<Double> double_Deserializer = _runtime.bodySerDe().deserializer(new TypeMarker<Double>() {
        });

        private final EndpointChannel boolean_Channel = _endpointChannelFactory.endpoint(DialogueEteEndpoints.boolean_);

        private final Deserializer<Boolean> boolean_Deserializer = _runtime.bodySerDe().deserializer(new TypeMarker<Boolean>() {
        });

        private final EndpointChannel safelongChannel = _endpointChannelFactory.endpoint(DialogueEteEndpoints.safelong);

        private final Deserializer<SafeLong> safelongDeserializer = _runtime.bodySerDe().deserializer(new TypeMarker<SafeLong>() {
        });

        private final EndpointChannel ridChannel = _endpointChannelFactory.endpoint(DialogueEteEndpoints.rid);

        private final Deserializer<ResourceIdentifier> ridDeserializer = _runtime.bodySerDe().deserializer(new TypeMarker<ResourceIdentifier>() {
        });

        private final EndpointChannel bearertokenChannel = _endpointChannelFactory.endpoint(DialogueEteEndpoints.bearertoken);

        private final Deserializer<BearerToken> bearertokenDeserializer = _runtime.bodySerDe().deserializer(new TypeMarker<BearerToken>() {
        });

        private final EndpointChannel optionalStringChannel = _endpointChannelFactory.endpoint(DialogueEteEndpoints.optionalString);

        private final Deserializer<Optional<String>> optionalStringDeserializer = _runtime.bodySerDe().deserializer(new TypeMarker<Optional<String>>() {
        });

        private final EndpointChannel optionalEmptyChannel = _endpointChannelFactory.endpoint(DialogueEteEndpoints.optionalEmpty);

        private final Deserializer<Optional<String>> optionalEmptyDeserializer = _runtime.bodySerDe().deserializer(new TypeMarker<Optional<String>>() {
        });

        private final EndpointChannel datetimeChannel = _endpointChannelFactory.endpoint(DialogueEteEndpoints.datetime);

        private final Deserializer<OffsetDateTime> datetimeDeserializer = _runtime.bodySerDe().deserializer(new TypeMarker<OffsetDateTime>() {
        });

        private final EndpointChannel binaryChannel = _endpointChannelFactory.endpoint(DialogueEteEndpoints.binary);

        private final EndpointChannel pathChannel = _endpointChannelFactory.endpoint(DialogueEteEndpoints.path);

        private final Deserializer<String> pathDeserializer = _runtime.bodySerDe().deserializer(new TypeMarker<String>() {
        });

        private final EndpointChannel externalLongPathChannel = _endpointChannelFactory.endpoint(DialogueEteEndpoints.externalLongPath);

        private final Deserializer<Long> externalLongPathDeserializer = _runtime.bodySerDe().deserializer(new TypeMarker<Long>() {
        });

        private final EndpointChannel optionalExternalLongQueryChannel = _endpointChannelFactory.endpoint(DialogueEteEndpoints.optionalExternalLongQuery);

        private final Deserializer<Optional<Long>> optionalExternalLongQueryDeserializer = _runtime.bodySerDe().deserializer(new TypeMarker<Optional<Long>>() {
        });

        private final Serializer<StringAliasExample> notNullBodySerializer = _runtime.bodySerDe().serializer(new TypeMarker<StringAliasExample>() {
        });

        private final EndpointChannel notNullBodyChannel = _endpointChannelFactory.endpoint(DialogueEteEndpoints.notNullBody);

        private final Deserializer<StringAliasExample> notNullBodyDeserializer = _runtime.bodySerDe().deserializer(new TypeMarker<StringAliasExample>() {
        });

        private final EndpointChannel aliasOneChannel = _endpointChannelFactory.endpoint(DialogueEteEndpoints.aliasOne);

        private final Deserializer<StringAliasExample> aliasOneDeserializer = _runtime.bodySerDe().deserializer(new TypeMarker<StringAliasExample>() {
        });

        private final EndpointChannel optionalAliasOneChannel = _endpointChannelFactory.endpoint(DialogueEteEndpoints.optionalAliasOne);

        private final Deserializer<StringAliasExample> optionalAliasOneDeserializer = _runtime.bodySerDe().deserializer(new TypeMarker<StringAliasExample>() {
        });

        private final EndpointChannel aliasTwoChannel = _endpointChannelFactory.endpoint(DialogueEteEndpoints.aliasTwo);

        private final Deserializer<NestedStringAliasExample> aliasTwoDeserializer = _runtime.bodySerDe().deserializer(new TypeMarker<NestedStringAliasExample>() {
        });

        private final Serializer<StringAliasExample> notNullBodyExternalImportSerializer = _runtime.bodySerDe().serializer(new TypeMarker<StringAliasExample>() {
        });

        private final EndpointChannel notNullBodyExternalImportChannel = _endpointChannelFactory.endpoint(DialogueEteEndpoints.notNullBodyExternalImport);

        private final Deserializer<StringAliasExample> notNullBodyExternalImportDeserializer = _runtime.bodySerDe().deserializer(new TypeMarker<StringAliasExample>() {
        });

        private final Serializer<Optional<StringAliasExample>> optionalBodyExternalImportSerializer = _runtime.bodySerDe().serializer(new TypeMarker<Optional<StringAliasExample>>() {
        });

        private final EndpointChannel optionalBodyExternalImportChannel = _endpointChannelFactory.endpoint(DialogueEteEndpoints.optionalBodyExternalImport);

        private final Deserializer<Optional<StringAliasExample>> optionalBodyExternalImportDeserializer = _runtime.bodySerDe().deserializer(new TypeMarker<Optional<StringAliasExample>>() {
        });

        private final EndpointChannel optionalQueryExternalImportChannel = _endpointChannelFactory.endpoint(DialogueEteEndpoints.optionalQueryExternalImport);

        private final Deserializer<Optional<StringAliasExample>> optionalQueryExternalImportDeserializer = _runtime.bodySerDe().deserializer(new TypeMarker<Optional<StringAliasExample>>() {
        });

        private final EndpointChannel noReturnChannel = _endpointChannelFactory.endpoint(DialogueEteEndpoints.noReturn);

        private final Deserializer<Void> noReturnDeserializer = _runtime.bodySerDe().emptyBodyDeserializer();

        private final EndpointChannel enumQueryChannel = _endpointChannelFactory.endpoint(DialogueEteEndpoints.enumQuery);

        private final Deserializer<SimpleEnum> enumQueryDeserializer = _runtime.bodySerDe().deserializer(new TypeMarker<SimpleEnum>() {
        });

        private final EndpointChannel enumListQueryChannel = _endpointChannelFactory.endpoint(DialogueEteEndpoints.enumListQuery);

        private final Deserializer<List<SimpleEnum>> enumListQueryDeserializer = _runtime.bodySerDe().deserializer(new TypeMarker<List<SimpleEnum>>() {
        });

        private final EndpointChannel optionalEnumQueryChannel = _endpointChannelFactory.endpoint(DialogueEteEndpoints.optionalEnumQuery);

        private final Deserializer<Optional<SimpleEnum>> optionalEnumQueryDeserializer = _runtime.bodySerDe().deserializer(new TypeMarker<Optional<SimpleEnum>>() {
        });

        private final EndpointChannel enumHeaderChannel = _endpointChannelFactory.endpoint(DialogueEteEndpoints.enumHeader);

        private final Deserializer<SimpleEnum> enumHeaderDeserializer = _runtime.bodySerDe().deserializer(new TypeMarker<SimpleEnum>() {
        });

        private final EndpointChannel aliasLongEndpointChannel = _endpointChannelFactory.endpoint(DialogueEteEndpoints.aliasLongEndpoint);

        private final Deserializer<Optional<LongAlias>> aliasLongEndpointDeserializer = _runtime.bodySerDe().deserializer(new TypeMarker<Optional<LongAlias>>() {
        });

        private final EndpointChannel complexQueryParametersChannel = _endpointChannelFactory.endpoint(DialogueEteEndpoints.complexQueryParameters);

        private final Deserializer<Void> complexQueryParametersDeserializer = _runtime.bodySerDe().emptyBodyDeserializer();

        private final Serializer<List<Optional<String>>> receiveListOfOptionalsSerializer = _runtime.bodySerDe().serializer(new TypeMarker<List<Optional<String>>>() {
        });

        private final EndpointChannel receiveListOfOptionalsChannel = _endpointChannelFactory.endpoint(DialogueEteEndpoints.receiveListOfOptionals);

        private final Deserializer<Void> receiveListOfOptionalsDeserializer = _runtime.bodySerDe().emptyBodyDeserializer();

        private final Serializer<Set<Optional<String>>> receiveSetOfOptionalsSerializer = _runtime.bodySerDe().serializer(new TypeMarker<Set<Optional<String>>>() {
        });

        private final EndpointChannel receiveSetOfOptionalsChannel = _endpointChannelFactory.endpoint(DialogueEteEndpoints.receiveSetOfOptionals);

        private final Deserializer<Void> receiveSetOfOptionalsDeserializer = _runtime.bodySerDe().emptyBodyDeserializer();

        private final Serializer<List<String>> receiveListOfStringsSerializer = _runtime.bodySerDe().serializer(new TypeMarker<List<String>>() {
        });

        private final EndpointChannel receiveListOfStringsChannel = _endpointChannelFactory.endpoint(DialogueEteEndpoints.receiveListOfStrings);

        private final Deserializer<Void> receiveListOfStringsDeserializer = _runtime.bodySerDe().emptyBodyDeserializer();

        @Override
        public String string(AuthHeader authHeader) {
            Request.Builder _request = Request.builder();
            _request.putHeaderParams("Authorization", authHeader.toString());
            return _runtime.clients().callBlocking(stringChannel, _request.build(), stringDeserializer);
        }

        @Override
        public int integer(AuthHeader authHeader) {
            Request.Builder _request = Request.builder();
            _request.putHeaderParams("Authorization", authHeader.toString());
            return _runtime.clients().callBlocking(integerChannel, _request.build(), integerDeserializer);
        }

        @Override
        public double double_(AuthHeader authHeader) {
            Request.Builder _request = Request.builder();
            _request.putHeaderParams("Authorization", authHeader.toString());
            return _runtime.clients().callBlocking(double_Channel, _request.build(), double_Deserializer);
        }

        @Override
        public boolean boolean_(AuthHeader authHeader) {
            Request.Builder _request = Request.builder();
            _request.putHeaderParams("Authorization", authHeader.toString());
            return _runtime.clients().callBlocking(boolean_Channel, _request.build(), boolean_Deserializer);
        }

        @Override
        public SafeLong safelong(AuthHeader authHeader) {
            Request.Builder _request = Request.builder();
            _request.putHeaderParams("Authorization", authHeader.toString());
            return _runtime.clients().callBlocking(safelongChannel, _request.build(), safelongDeserializer);
        }

        @Override
        public ResourceIdentifier rid(AuthHeader authHeader) {
            Request.Builder _request = Request.builder();
            _request.putHeaderParams("Authorization", authHeader.toString());
            return _runtime.clients().callBlocking(ridChannel, _request.build(), ridDeserializer);
        }

        @Override
        public BearerToken bearertoken(AuthHeader authHeader) {
            Request.Builder _request = Request.builder();
            _request.putHeaderParams("Authorization", authHeader.toString());
            return _runtime.clients().callBlocking(bearertokenChannel, _request.build(), bearertokenDeserializer);
        }

        @Override
        public Optional<String> optionalString(AuthHeader authHeader) {
            Request.Builder _request = Request.builder();
            _request.putHeaderParams("Authorization", authHeader.toString());
            return _runtime.clients().callBlocking(optionalStringChannel, _request.build(), optionalStringDeserializer);
        }

        @Override
        public Optional<String> optionalEmpty(AuthHeader authHeader) {
            Request.Builder _request = Request.builder();
            _request.putHeaderParams("Authorization", authHeader.toString());
            return _runtime.clients().callBlocking(optionalEmptyChannel, _request.build(), optionalEmptyDeserializer);
        }

        @Override
        public OffsetDateTime datetime(AuthHeader authHeader) {
            Request.Builder _request = Request.builder();
            _request.putHeaderParams("Authorization", authHeader.toString());
            return _runtime.clients().callBlocking(datetimeChannel, _request.build(), datetimeDeserializer);
        }

        @Override
        public InputStream binary(AuthHeader authHeader) {
            Request.Builder _request = Request.builder();
            _request.putHeaderParams("Authorization", authHeader.toString());
            return _runtime.clients().callBlocking(binaryChannel, _request.build(), _runtime.bodySerDe().inputStreamDeserializer());
        }

        @Override
        public String path(AuthHeader authHeader, String param) {
            Request.Builder _request = Request.builder();
            _request.putHeaderParams("Authorization", authHeader.toString());
            _request.putPathParams("param", _plainSerDe.serializeString(param));
            return _runtime.clients().callBlocking(pathChannel, _request.build(), pathDeserializer);
        }

        @Override
        public long externalLongPath(AuthHeader authHeader, long param) {
            Request.Builder _request = Request.builder();
            _request.putHeaderParams("Authorization", authHeader.toString());
            _request.putPathParams("param", Objects.toString(param));
            return _runtime.clients().callBlocking(externalLongPathChannel, _request.build(), externalLongPathDeserializer);
        }

        @Override
        public Optional<Long> optionalExternalLongQuery(AuthHeader authHeader, Optional<Long> param) {
            Request.Builder _request = Request.builder();
            _request.putHeaderParams("Authorization", authHeader.toString());
            if (param.isPresent()) {
                _request.putQueryParams("param", Objects.toString(param.get()));
            }
            return _runtime.clients().callBlocking(optionalExternalLongQueryChannel, _request.build(), optionalExternalLongQueryDeserializer);
        }

        @Override
        public StringAliasExample notNullBody(AuthHeader authHeader, StringAliasExample notNullBody) {
            Request.Builder _request = Request.builder();
            _request.putHeaderParams("Authorization", authHeader.toString());
            _request.body(notNullBodySerializer.serialize(notNullBody));
            return _runtime.clients().callBlocking(notNullBodyChannel, _request.build(), notNullBodyDeserializer);
        }

        @Override
        public StringAliasExample aliasOne(AuthHeader authHeader, StringAliasExample queryParamName) {
            Request.Builder _request = Request.builder();
            _request.putHeaderParams("Authorization", authHeader.toString());
            _request.putQueryParams("queryParamName", _plainSerDe.serializeString(queryParamName.get()));
            return _runtime.clients().callBlocking(aliasOneChannel, _request.build(), aliasOneDeserializer);
        }

        @Override
        public StringAliasExample optionalAliasOne(AuthHeader authHeader, Optional<StringAliasExample> queryParamName) {
            Request.Builder _request = Request.builder();
            _request.putHeaderParams("Authorization", authHeader.toString());
            if (queryParamName.isPresent()) {
                _request.putQueryParams("queryParamName", _plainSerDe.serializeString(queryParamName.get().get()));
            }
            return _runtime.clients().callBlocking(optionalAliasOneChannel, _request.build(), optionalAliasOneDeserializer);
        }

        @Override
        public NestedStringAliasExample aliasTwo(AuthHeader authHeader, NestedStringAliasExample queryParamName) {
            Request.Builder _request = Request.builder();
            _request.putHeaderParams("Authorization", authHeader.toString());
            _request.putQueryParams("queryParamName", _plainSerDe.serializeString(queryParamName.get().get()));
            return _runtime.clients().callBlocking(aliasTwoChannel, _request.build(), aliasTwoDeserializer);
        }

        @Override
        public StringAliasExample notNullBodyExternalImport(AuthHeader authHeader, StringAliasExample notNullBody) {
            Request.Builder _request = Request.builder();
            _request.putHeaderParams("Authorization", authHeader.toString());
            _request.body(notNullBodyExternalImportSerializer.serialize(notNullBody));
            return _runtime.clients().callBlocking(notNullBodyExternalImportChannel, _request.build(), notNullBodyExternalImportDeserializer);
        }

        @Override
        public Optional<StringAliasExample> optionalBodyExternalImport(AuthHeader authHeader, Optional<StringAliasExample> body) {
            Request.Builder _request = Request.builder();
            _request.putHeaderParams("Authorization", authHeader.toString());
            _request.body(optionalBodyExternalImportSerializer.serialize(body));
            return _runtime.clients().callBlocking(optionalBodyExternalImportChannel, _request.build(), optionalBodyExternalImportDeserializer);
        }

        @Override
        public Optional<StringAliasExample> optionalQueryExternalImport(AuthHeader authHeader, Optional<StringAliasExample> query) {
            Request.Builder _request = Request.builder();
            _request.putHeaderParams("Authorization", authHeader.toString());
            if (query.isPresent()) {
                _request.putQueryParams("query", Objects.toString(query.get()));
            }
            return _runtime.clients().callBlocking(optionalQueryExternalImportChannel, _request.build(), optionalQueryExternalImportDeserializer);
        }

        @Override
        public void noReturn(AuthHeader authHeader) {
            Request.Builder _request = Request.builder();
            _request.putHeaderParams("Authorization", authHeader.toString());
            _runtime.clients().callBlocking(noReturnChannel, _request.build(), noReturnDeserializer);
        }

        @Override
        public SimpleEnum enumQuery(AuthHeader authHeader, SimpleEnum queryParamName) {
            Request.Builder _request = Request.builder();
            _request.putHeaderParams("Authorization", authHeader.toString());
            _request.putQueryParams("queryParamName", Objects.toString(queryParamName));
            return _runtime.clients().callBlocking(enumQueryChannel, _request.build(), enumQueryDeserializer);
        }

        @Override
        public List<SimpleEnum> enumListQuery(AuthHeader authHeader, List<SimpleEnum> queryParamName) {
            Request.Builder _request = Request.builder();
            _request.putHeaderParams("Authorization", authHeader.toString());
            for (SimpleEnum queryParamNameElement : queryParamName) {
                _request.putQueryParams("queryParamName", Objects.toString(queryParamNameElement));
            }
            return _runtime.clients().callBlocking(enumListQueryChannel, _request.build(), enumListQueryDeserializer);
        }

        @Override
        public Optional<SimpleEnum> optionalEnumQuery(AuthHeader authHeader, Optional<SimpleEnum> queryParamName) {
            Request.Builder _request = Request.builder();
            _request.putHeaderParams("Authorization", authHeader.toString());
            if (queryParamName.isPresent()) {
                _request.putQueryParams("queryParamName", Objects.toString(queryParamName.get()));
            }
            return _runtime.clients().callBlocking(optionalEnumQueryChannel, _request.build(), optionalEnumQueryDeserializer);
        }

        @Override
        public SimpleEnum enumHeader(AuthHeader authHeader, SimpleEnum headerParameter) {
            Request.Builder _request = Request.builder();
            _request.putHeaderParams("Authorization", authHeader.toString());
            _request.putHeaderParams("Custom-Header", Objects.toString(headerParameter));
            return _runtime.clients().callBlocking(enumHeaderChannel, _request.build(), enumHeaderDeserializer);
        }

        @Override
        public Optional<LongAlias> aliasLongEndpoint(AuthHeader authHeader, Optional<LongAlias> input) {
            Request.Builder _request = Request.builder();
            _request.putHeaderParams("Authorization", authHeader.toString());
            if (input.isPresent()) {
                _request.putQueryParams("input", Objects.toString(input.get().get()));
            }
            return _runtime.clients().callBlocking(aliasLongEndpointChannel, _request.build(), aliasLongEndpointDeserializer);
        }

        @Override
        public void complexQueryParameters(AuthHeader authHeader, ResourceIdentifier datasetRid, Set<StringAliasExample> strings, Set<Long> longs, Set<Integer> ints) {
            Request.Builder _request = Request.builder();
            _request.putHeaderParams("Authorization", authHeader.toString());
            _request.putPathParams("datasetRid", _plainSerDe.serializeRid(datasetRid));
            for (StringAliasExample stringsElement : strings) {
                _request.putQueryParams("strings", _plainSerDe.serializeString(stringsElement.get()));
            }
            for (long longsElement : longs) {
                _request.putQueryParams("longs", Objects.toString(longsElement));
            }
            for (int intsElement : ints) {
                _request.putQueryParams("ints", _plainSerDe.serializeInteger(intsElement));
            }
            _runtime.clients().callBlocking(complexQueryParametersChannel, _request.build(), complexQueryParametersDeserializer);
        }

        @Override
        public void receiveListOfOptionals(AuthHeader authHeader, List<Optional<String>> value) {
            Request.Builder _request = Request.builder();
            _request.putHeaderParams("Authorization", authHeader.toString());
            _request.body(receiveListOfOptionalsSerializer.serialize(value));
            _runtime.clients().callBlocking(receiveListOfOptionalsChannel, _request.build(), receiveListOfOptionalsDeserializer);
        }

        @Override
        public void receiveSetOfOptionals(AuthHeader authHeader, Set<Optional<String>> value) {
            Request.Builder _request = Request.builder();
            _request.putHeaderParams("Authorization", authHeader.toString());
            _request.body(receiveSetOfOptionalsSerializer.serialize(value));
            _runtime.clients().callBlocking(receiveSetOfOptionalsChannel, _request.build(), receiveSetOfOptionalsDeserializer);
        }

        @Override
        public void receiveListOfStrings(AuthHeader authHeader, List<String> value) {
            Request.Builder _request = Request.builder();
            _request.putHeaderParams("Authorization", authHeader.toString());
            _request.body(receiveListOfStringsSerializer.serialize(value));
            _runtime.clients().callBlocking(receiveListOfStringsChannel, _request.build(), receiveListOfStringsDeserializer);
        }

        @Override
        public String toString() {
            return "EteServiceBlocking{_endpointChannelFactory=" + _endpointChannelFactory + ", runtime=" + _runtime + '}';
        }
    };
}
Also used : AuthHeader(com.palantir.tokens.auth.AuthHeader) Set(java.util.Set) Optional(java.util.Optional) TypeMarker(com.palantir.dialogue.TypeMarker) Request(com.palantir.dialogue.Request) String(java.lang.String) ClientEndpoint(com.palantir.conjure.java.lib.internal.ClientEndpoint) Endpoint(com.palantir.dialogue.Endpoint) ResourceIdentifier(com.palantir.ri.ResourceIdentifier) Deserializer(com.palantir.dialogue.Deserializer) Long(java.lang.Long) SafeLong(com.palantir.conjure.java.lib.SafeLong) EndpointChannel(com.palantir.dialogue.EndpointChannel) List(java.util.List) PlainSerDe(com.palantir.dialogue.PlainSerDe) Serializer(com.palantir.dialogue.Serializer)

Example 3 with AuthHeader

use of com.palantir.tokens.auth.AuthHeader in project atlasdb by palantir.

the class AtlasRestoreServiceTest method restoresToNewNamespaceCorrectly.

@Test
public void restoresToNewNamespaceCorrectly() {
    RestoreRequest restoreRequest = RestoreRequest.builder().oldNamespace(WITH_BACKUP).newNamespace(NO_BACKUP).build();
    // prepare
    DisableNamespacesResponse successfulDisable = DisableNamespacesResponse.successful(SuccessfulDisableNamespacesResponse.of(BACKUP_ID));
    DisableNamespacesRequest request = DisableNamespacesRequest.of(ImmutableSet.of(NO_BACKUP), BACKUP_ID);
    when(timeLockManagementService.disableTimelock(authHeader, request)).thenReturn(successfulDisable);
    Set<Namespace> disabledNamespaces = atlasRestoreService.prepareRestore(ImmutableSet.of(restoreRequest), BACKUP_ID);
    assertThat(disabledNamespaces).containsExactly(NO_BACKUP);
    // repair
    BiConsumer<String, RangesForRepair> doNothingConsumer = (_unused1, _unused2) -> {
    };
    Set<Namespace> repairedNamespaces = atlasRestoreService.repairInternalTables(ImmutableSet.of(restoreRequest), doNothingConsumer);
    assertThat(repairedNamespaces).containsExactly(NO_BACKUP);
    verify(cassandraRepairHelper).repairInternalTables(NO_BACKUP, doNothingConsumer);
    verify(cassandraRepairHelper).repairTransactionsTables(eq(NO_BACKUP), anyList(), eq(doNothingConsumer));
    verify(cassandraRepairHelper).cleanTransactionsTables(eq(NO_BACKUP), eq(BACKUP_START_TIMESTAMP), anyList());
    verifyNoMoreInteractions(cassandraRepairHelper);
    // complete
    CompletedBackup completedBackup = backupPersister.getCompletedBackup(WITH_BACKUP).orElseThrow();
    CompleteRestoreRequest completeRestoreRequest = CompleteRestoreRequest.of(ImmutableMap.of(NO_BACKUP, completedBackup));
    when(atlasRestoreClient.completeRestore(authHeader, completeRestoreRequest)).thenReturn(CompleteRestoreResponse.of(ImmutableSet.of(NO_BACKUP)));
    ReenableNamespacesRequest reenableRequest = ReenableNamespacesRequest.of(ImmutableSet.of(NO_BACKUP), BACKUP_ID);
    Set<Namespace> completedNamespaces = atlasRestoreService.completeRestore(ImmutableSet.of(restoreRequest), BACKUP_ID);
    assertThat(completedNamespaces).containsExactly(NO_BACKUP);
    verify(atlasRestoreClient).completeRestore(authHeader, completeRestoreRequest);
    verify(timeLockManagementService).reenableTimelock(authHeader, reenableRequest);
}
Also used : RangesForRepair(com.palantir.atlasdb.cassandra.backup.RangesForRepair) CassandraRepairHelper(com.palantir.atlasdb.cassandra.backup.CassandraRepairHelper) CompleteRestoreResponse(com.palantir.atlasdb.backup.api.CompleteRestoreResponse) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Mock(org.mockito.Mock) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) AtlasRestoreClient(com.palantir.atlasdb.backup.api.AtlasRestoreClient) RunWith(org.junit.runner.RunWith) AuthHeader(com.palantir.tokens.auth.AuthHeader) CompleteRestoreRequest(com.palantir.atlasdb.backup.api.CompleteRestoreRequest) CompletedBackup(com.palantir.atlasdb.backup.api.CompletedBackup) Mockito.verifyNoInteractions(org.mockito.Mockito.verifyNoInteractions) ReenableNamespacesRequest(com.palantir.atlasdb.timelock.api.ReenableNamespacesRequest) SuccessfulDisableNamespacesResponse(com.palantir.atlasdb.timelock.api.SuccessfulDisableNamespacesResponse) TimeLockManagementService(com.palantir.atlasdb.timelock.api.management.TimeLockManagementService) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) Map(java.util.Map) BiConsumer(java.util.function.BiConsumer) Before(org.junit.Before) ImmutableSet(com.google.common.collect.ImmutableSet) InOrder(org.mockito.InOrder) ImmutableMap(com.google.common.collect.ImmutableMap) KeyedStream(com.palantir.common.streams.KeyedStream) DisableNamespacesRequest(com.palantir.atlasdb.timelock.api.DisableNamespacesRequest) UnsuccessfulDisableNamespacesResponse(com.palantir.atlasdb.timelock.api.UnsuccessfulDisableNamespacesResponse) SafeIllegalArgumentException(com.palantir.logsafe.exceptions.SafeIllegalArgumentException) Set(java.util.Set) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) ArgumentMatchers.anyList(org.mockito.ArgumentMatchers.anyList) RangesForRepair(com.palantir.atlasdb.cassandra.backup.RangesForRepair) Namespace(com.palantir.atlasdb.timelock.api.Namespace) Collectors(java.util.stream.Collectors) Mockito.verify(org.mockito.Mockito.verify) Mockito(org.mockito.Mockito) DisableNamespacesResponse(com.palantir.atlasdb.timelock.api.DisableNamespacesResponse) Optional(java.util.Optional) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) SuccessfulDisableNamespacesResponse(com.palantir.atlasdb.timelock.api.SuccessfulDisableNamespacesResponse) UnsuccessfulDisableNamespacesResponse(com.palantir.atlasdb.timelock.api.UnsuccessfulDisableNamespacesResponse) DisableNamespacesResponse(com.palantir.atlasdb.timelock.api.DisableNamespacesResponse) CompleteRestoreRequest(com.palantir.atlasdb.backup.api.CompleteRestoreRequest) CompletedBackup(com.palantir.atlasdb.backup.api.CompletedBackup) CompleteRestoreRequest(com.palantir.atlasdb.backup.api.CompleteRestoreRequest) ReenableNamespacesRequest(com.palantir.atlasdb.timelock.api.ReenableNamespacesRequest) DisableNamespacesRequest(com.palantir.atlasdb.timelock.api.DisableNamespacesRequest) Namespace(com.palantir.atlasdb.timelock.api.Namespace) Test(org.junit.Test)

Example 4 with AuthHeader

use of com.palantir.tokens.auth.AuthHeader in project atlasdb by palantir.

the class AtlasRestoreResourceTest method throwsIfWrongAuthHeaderIsProvided.

@Test
public void throwsIfWrongAuthHeaderIsProvided() {
    CompletedBackup completedBackup = completedBackup();
    AuthHeader wrongHeader = AuthHeader.of(BearerToken.valueOf("imposter"));
    CompleteRestoreRequest request = CompleteRestoreRequest.of(ImmutableMap.of(NAMESPACE, completedBackup));
    assertThatServiceExceptionThrownBy(() -> AtlasFutures.getUnchecked(atlasRestoreResource.completeRestore(wrongHeader, request))).hasType(ErrorType.PERMISSION_DENIED);
}
Also used : CompleteRestoreRequest(com.palantir.atlasdb.backup.api.CompleteRestoreRequest) AuthHeader(com.palantir.tokens.auth.AuthHeader) CompletedBackup(com.palantir.atlasdb.backup.api.CompletedBackup) Test(org.junit.Test)

Example 5 with AuthHeader

use of com.palantir.tokens.auth.AuthHeader in project atlasdb by palantir.

the class AtlasBackupService method completeBackup.

/**
 * Completes backup for the given set of atlas services.
 * This will store metadata about the completed backup via the BackupPersister.
 * <p>
 * In order to do this, we must unlock the immutable timestamp for each service. If {@link #prepareBackup(Set)}
 * was not called, we will not have a record of the in-progress backup (and will not have been refreshing
 * its lock anyway). Thus, we attempt to complete backup only for those atlas services where we have the in-progress
 * backup stored.
 *
 * @return the atlas services whose backups were successfully completed
 */
public Set<AtlasService> completeBackup(Set<AtlasService> atlasServices) {
    throwIfClosed(atlasServices);
    AtlasServices.throwIfAtlasServicesCollide(atlasServices);
    Map<AtlasService, InProgressBackupToken> knownBackups = KeyedStream.of(atlasServices).map((Function<AtlasService, InProgressBackupToken>) inProgressBackups::remove).filter(Objects::nonNull).collectToMap();
    Set<InProgressBackupToken> tokens = ImmutableSet.copyOf(knownBackups.values());
    if (tokens.isEmpty()) {
        log.error("Complete backup called, but no in progress backups were found.", SafeArg.of("atlasServices", atlasServices));
        return ImmutableSet.of();
    }
    lockRefresher.unregisterLocks(tokens);
    Set<AtlasService> atlasServicesWithInProgressBackups = knownBackups.keySet();
    if (tokens.size() < atlasServices.size()) {
        Set<AtlasService> atlasServicesWithNoInProgressBackup = Sets.difference(atlasServices, atlasServicesWithInProgressBackups);
        log.error("In progress backups were not found for some atlasServices. We will not complete backup for these.", SafeArg.of("numAtlasServicesWithBackup", tokens.size()), SafeArg.of("numAtlasServicesWithoutBackup", atlasServicesWithNoInProgressBackup.size()), SafeArg.of("atlasServicesWithoutBackup", atlasServicesWithNoInProgressBackup), SafeArg.of("allRequestedAtlasServices", atlasServices));
    }
    Map<Namespace, AtlasService> namespaceToServices = KeyedStream.of(atlasServices).mapKeys(AtlasService::getNamespace).collectToMap();
    CompleteBackupRequest request = CompleteBackupRequest.of(tokens);
    CompleteBackupResponse response = atlasBackupClient.completeBackup(authHeader, request);
    Map<AtlasService, CompletedBackup> successfulBackups = KeyedStream.of(response.getSuccessfulBackups()).mapKeys(token -> namespaceToServices.get(token.getNamespace())).collectToMap();
    Set<AtlasService> successfullyStoredBackups = storeCompletedBackups(successfulBackups);
    if (successfullyStoredBackups.size() < atlasServicesWithInProgressBackups.size()) {
        Set<AtlasService> failedAtlasServices = Sets.difference(atlasServicesWithInProgressBackups, successfullyStoredBackups);
        log.error("Backup did not complete successfully for all atlasServices. Check TimeLock logs to debug.", SafeArg.of("failedAtlasServices", failedAtlasServices), SafeArg.of("successfulAtlasServices", successfullyStoredBackups), SafeArg.of("atlasServicesWithoutBackup", atlasServicesWithInProgressBackups));
    }
    return successfulBackups.keySet();
}
Also used : PrepareBackupResponse(com.palantir.atlasdb.backup.api.PrepareBackupResponse) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) SafeLoggerFactory(com.palantir.logsafe.logger.SafeLoggerFactory) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) AtlasBackupClient(com.palantir.atlasdb.backup.api.AtlasBackupClient) SafeIllegalStateException(com.palantir.logsafe.exceptions.SafeIllegalStateException) AtlasBackupClientBlocking(com.palantir.atlasdb.backup.api.AtlasBackupClientBlocking) AuthHeader(com.palantir.tokens.auth.AuthHeader) CompletedBackup(com.palantir.atlasdb.backup.api.CompletedBackup) Function(java.util.function.Function) SafeLogger(com.palantir.logsafe.logger.SafeLogger) SafeArg(com.palantir.logsafe.SafeArg) CompleteBackupResponse(com.palantir.atlasdb.backup.api.CompleteBackupResponse) PTExecutors(com.palantir.common.concurrent.PTExecutors) UserAgent(com.palantir.conjure.java.api.config.service.UserAgent) Map(java.util.Map) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) AtlasFutures(com.palantir.atlasdb.futures.AtlasFutures) Path(java.nio.file.Path) ExecutorService(java.util.concurrent.ExecutorService) Refreshable(com.palantir.refreshable.Refreshable) ImmutableSet(com.google.common.collect.ImmutableSet) NamedThreadFactory(com.palantir.common.concurrent.NamedThreadFactory) CompleteBackupRequest(com.palantir.atlasdb.backup.api.CompleteBackupRequest) KeyedStream(com.palantir.common.streams.KeyedStream) PrepareBackupRequest(com.palantir.atlasdb.backup.api.PrepareBackupRequest) ReloadingFactory(com.palantir.dialogue.clients.DialogueClients.ReloadingFactory) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) InProgressBackupToken(com.palantir.atlasdb.backup.api.InProgressBackupToken) TransactionManager(com.palantir.atlasdb.transaction.api.TransactionManager) Namespace(com.palantir.atlasdb.timelock.api.Namespace) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) Objects(java.util.Objects) RefreshBackupRequest(com.palantir.atlasdb.backup.api.RefreshBackupRequest) ServicesConfigBlock(com.palantir.conjure.java.api.config.service.ServicesConfigBlock) Futures(com.google.common.util.concurrent.Futures) LockLeaseRefresher(com.palantir.lock.v2.LockLeaseRefresher) KeyValueService(com.palantir.atlasdb.keyvalue.api.KeyValueService) AtlasDbRemotingConstants(com.palantir.atlasdb.http.AtlasDbRemotingConstants) Closeable(java.io.Closeable) Optional(java.util.Optional) VisibleForTesting(com.google.common.annotations.VisibleForTesting) AtlasService(com.palantir.atlasdb.backup.api.AtlasService) DialogueClients(com.palantir.dialogue.clients.DialogueClients) LockRefresher(com.palantir.lock.client.LockRefresher) CompleteBackupResponse(com.palantir.atlasdb.backup.api.CompleteBackupResponse) AtlasService(com.palantir.atlasdb.backup.api.AtlasService) CompleteBackupRequest(com.palantir.atlasdb.backup.api.CompleteBackupRequest) CompletedBackup(com.palantir.atlasdb.backup.api.CompletedBackup) InProgressBackupToken(com.palantir.atlasdb.backup.api.InProgressBackupToken) Namespace(com.palantir.atlasdb.timelock.api.Namespace)

Aggregations

AuthHeader (com.palantir.tokens.auth.AuthHeader)13 Optional (java.util.Optional)7 Set (java.util.Set)6 ImmutableSet (com.google.common.collect.ImmutableSet)5 CompletedBackup (com.palantir.atlasdb.backup.api.CompletedBackup)5 AtlasService (com.palantir.atlasdb.backup.api.AtlasService)4 Namespace (com.palantir.atlasdb.timelock.api.Namespace)4 KeyedStream (com.palantir.common.streams.KeyedStream)4 Map (java.util.Map)4 Collectors (java.util.stream.Collectors)4 Test (org.junit.Test)4 AtlasBackupClient (com.palantir.atlasdb.backup.api.AtlasBackupClient)3 AtlasRestoreClient (com.palantir.atlasdb.backup.api.AtlasRestoreClient)3 AtlasDbRemotingConstants (com.palantir.atlasdb.http.AtlasDbRemotingConstants)3 KeyValueService (com.palantir.atlasdb.keyvalue.api.KeyValueService)3 TimeLockManagementService (com.palantir.atlasdb.timelock.api.management.TimeLockManagementService)3 TransactionManager (com.palantir.atlasdb.transaction.api.TransactionManager)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableMap (com.google.common.collect.ImmutableMap)2