Search in sources :

Example 11 with DelegationTokenProvider

use of io.pravega.client.security.auth.DelegationTokenProvider in project pravega by pravega.

the class ByteStreamClientImpl method createByteStreamReaders.

private ByteStreamReader createByteStreamReaders(Segment segment) {
    String delegationToken = Futures.getAndHandleExceptions(controller.getOrRefreshDelegationTokenFor(segment.getScope(), segment.getStream().getStreamName(), AccessOperation.READ), RuntimeException::new);
    DelegationTokenProvider tokenProvider = DelegationTokenProviderFactory.create(delegationToken, controller, segment, AccessOperation.READ);
    SegmentMetadataClient metaClient = metaStreamFactory.createSegmentMetadataClient(segment, tokenProvider);
    long startOffset = Futures.getThrowingException(metaClient.getSegmentInfo()).getStartingOffset();
    return new ByteStreamReaderImpl(inputStreamFactory.createInputStreamForSegment(segment, tokenProvider, startOffset), metaClient);
}
Also used : DelegationTokenProvider(io.pravega.client.security.auth.DelegationTokenProvider) SegmentMetadataClient(io.pravega.client.segment.impl.SegmentMetadataClient)

Example 12 with DelegationTokenProvider

use of io.pravega.client.security.auth.DelegationTokenProvider in project pravega by pravega.

the class SegmentMetadataClientImpl method truncateSegmentAsync.

private CompletableFuture<SegmentTruncated> truncateSegmentAsync(Segment segment, long offset, DelegationTokenProvider tokenProvider) {
    log.debug("Truncating segment: {} at offset {}", segment, offset);
    RawClient connection = getConnection();
    long requestId = connection.getFlow().getNextSequenceNumber();
    return tokenProvider.retrieveToken().thenCompose(token -> connection.sendRequest(requestId, new TruncateSegment(requestId, segment.getScopedName(), offset, token))).thenApply(r -> transformReply(r, SegmentTruncated.class));
}
Also used : SneakyThrows(lombok.SneakyThrows) TokenExpiredException(io.pravega.auth.TokenExpiredException) Retry(io.pravega.common.util.Retry) ConnectionFailedException(io.pravega.shared.protocol.netty.ConnectionFailedException) Reply(io.pravega.shared.protocol.netty.Reply) Exceptions(io.pravega.common.Exceptions) RequiredArgsConstructor(lombok.RequiredArgsConstructor) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CompletableFuture(java.util.concurrent.CompletableFuture) GetSegmentAttribute(io.pravega.shared.protocol.netty.WireCommands.GetSegmentAttribute) GetStreamSegmentInfo(io.pravega.shared.protocol.netty.WireCommands.GetStreamSegmentInfo) RawClient(io.pravega.client.connection.impl.RawClient) UpdateSegmentAttribute(io.pravega.shared.protocol.netty.WireCommands.UpdateSegmentAttribute) AccessOperation(io.pravega.shared.security.auth.AccessOperation) TokenException(io.pravega.auth.TokenException) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) StreamSegmentInfo(io.pravega.shared.protocol.netty.WireCommands.StreamSegmentInfo) TruncateSegment(io.pravega.shared.protocol.netty.WireCommands.TruncateSegment) RetryWithBackoff(io.pravega.common.util.Retry.RetryWithBackoff) ConnectionPool(io.pravega.client.connection.impl.ConnectionPool) lombok.val(lombok.val) CompletionException(java.util.concurrent.CompletionException) DelegationTokenProviderFactory(io.pravega.client.security.auth.DelegationTokenProviderFactory) UUID(java.util.UUID) WireCommands(io.pravega.shared.protocol.netty.WireCommands) GuardedBy(javax.annotation.concurrent.GuardedBy) WrongHost(io.pravega.shared.protocol.netty.WireCommands.WrongHost) DelegationTokenProvider(io.pravega.client.security.auth.DelegationTokenProvider) SegmentAttributeUpdated(io.pravega.shared.protocol.netty.WireCommands.SegmentAttributeUpdated) Slf4j(lombok.extern.slf4j.Slf4j) InvalidTokenException(io.pravega.auth.InvalidTokenException) SegmentTruncated(io.pravega.shared.protocol.netty.WireCommands.SegmentTruncated) SealSegment(io.pravega.shared.protocol.netty.WireCommands.SealSegment) SegmentSealed(io.pravega.shared.protocol.netty.WireCommands.SegmentSealed) VisibleForTesting(com.google.common.annotations.VisibleForTesting) ConnectionClosedException(io.pravega.client.stream.impl.ConnectionClosedException) Controller(io.pravega.client.control.impl.Controller) Futures(io.pravega.common.concurrent.Futures) SegmentTruncated(io.pravega.shared.protocol.netty.WireCommands.SegmentTruncated) RawClient(io.pravega.client.connection.impl.RawClient) TruncateSegment(io.pravega.shared.protocol.netty.WireCommands.TruncateSegment)

Aggregations

DelegationTokenProvider (io.pravega.client.security.auth.DelegationTokenProvider)12 Segment (io.pravega.client.segment.impl.Segment)6 WireCommands (io.pravega.shared.protocol.netty.WireCommands)5 ConnectionPool (io.pravega.client.connection.impl.ConnectionPool)4 Controller (io.pravega.client.control.impl.Controller)4 ConnectionFailedException (io.pravega.shared.protocol.netty.ConnectionFailedException)4 UUID (java.util.UUID)4 CompletableFuture (java.util.concurrent.CompletableFuture)4 Slf4j (lombok.extern.slf4j.Slf4j)4 lombok.val (lombok.val)4 VisibleForTesting (com.google.common.annotations.VisibleForTesting)3 TokenExpiredException (io.pravega.auth.TokenExpiredException)3 ClientConnection (io.pravega.client.connection.impl.ClientConnection)3 RawClient (io.pravega.client.connection.impl.RawClient)3 DelegationTokenProviderFactory (io.pravega.client.security.auth.DelegationTokenProviderFactory)3 SegmentMetadataClient (io.pravega.client.segment.impl.SegmentMetadataClient)3 EventWriterConfig (io.pravega.client.stream.EventWriterConfig)3 InvalidTokenException (io.pravega.auth.InvalidTokenException)2 TokenException (io.pravega.auth.TokenException)2 SegmentOutputStream (io.pravega.client.segment.impl.SegmentOutputStream)2