Search in sources :

Example 16 with SegmentMetadataClient

use of io.pravega.client.segment.impl.SegmentMetadataClient 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 17 with SegmentMetadataClient

use of io.pravega.client.segment.impl.SegmentMetadataClient in project pravega by pravega.

the class BatchClientFactoryImpl method segmentToInfo.

private CompletableFuture<SegmentInfo> segmentToInfo(Segment s, DelegationTokenProvider tokenProvider) {
    SegmentMetadataClient client = segmentMetadataClientFactory.createSegmentMetadataClient(s, tokenProvider);
    CompletableFuture<SegmentInfo> result = client.getSegmentInfo();
    result.whenComplete((r, e) -> client.close());
    return result;
}
Also used : SegmentInfo(io.pravega.client.segment.impl.SegmentInfo) SegmentMetadataClient(io.pravega.client.segment.impl.SegmentMetadataClient)

Example 18 with SegmentMetadataClient

use of io.pravega.client.segment.impl.SegmentMetadataClient in project pravega by pravega.

the class AppendReconnectTest method reconnectOnSegmentClient.

@Test(timeout = 30000)
public void reconnectOnSegmentClient() throws Exception {
    String endpoint = "localhost";
    int port = TestUtils.getAvailableListenPort();
    byte[] payload = "Hello world\n".getBytes();
    String scope = "scope";
    String stream = "stream";
    StreamSegmentStore store = this.serviceBuilder.createStreamSegmentService();
    @Cleanup PravegaConnectionListener server = new PravegaConnectionListener(false, port, store, mock(TableStore.class), serviceBuilder.getLowPriorityExecutor());
    server.startListening();
    @Cleanup SocketConnectionFactoryImpl clientCF = new SocketConnectionFactoryImpl(ClientConfig.builder().build());
    @Cleanup ConnectionPoolImpl connectionPool = new ConnectionPoolImpl(ClientConfig.builder().build(), clientCF);
    Controller controller = new MockController(endpoint, port, connectionPool, true);
    controller.createScope(scope);
    controller.createStream(scope, stream, StreamConfiguration.builder().build());
    SegmentOutputStreamFactoryImpl segmentClient = new SegmentOutputStreamFactoryImpl(controller, connectionPool);
    Segment segment = Futures.getAndHandleExceptions(controller.getCurrentSegments(scope, stream), RuntimeException::new).getSegments().iterator().next();
    @Cleanup SegmentOutputStream out = segmentClient.createOutputStreamForSegment(segment, segmentSealedCallback, EventWriterConfig.builder().build(), DelegationTokenProviderFactory.createWithEmptyToken());
    CompletableFuture<Void> ack = new CompletableFuture<>();
    out.write(PendingEvent.withoutHeader(null, ByteBuffer.wrap(payload), ack));
    for (AutoCloseable c : connectionPool.getActiveChannels()) {
        c.close();
    }
    CompletableFuture<Void> ack2 = new CompletableFuture<>();
    out.write(PendingEvent.withoutHeader(null, ByteBuffer.wrap(payload), ack2));
    ack.get(5, TimeUnit.SECONDS);
    ack2.get(5, TimeUnit.SECONDS);
    @Cleanup SegmentMetadataClient metadataClient = new SegmentMetadataClientFactoryImpl(controller, connectionPool).createSegmentMetadataClient(segment, DelegationTokenProviderFactory.createWithEmptyToken());
    assertEquals(payload.length * 2, metadataClient.fetchCurrentSegmentLength().join().longValue());
}
Also used : ConnectionPoolImpl(io.pravega.client.connection.impl.ConnectionPoolImpl) SocketConnectionFactoryImpl(io.pravega.client.connection.impl.SocketConnectionFactoryImpl) MockController(io.pravega.client.stream.mock.MockController) Controller(io.pravega.client.control.impl.Controller) Cleanup(lombok.Cleanup) PravegaConnectionListener(io.pravega.segmentstore.server.host.handler.PravegaConnectionListener) Segment(io.pravega.client.segment.impl.Segment) TableStore(io.pravega.segmentstore.contracts.tables.TableStore) SegmentMetadataClient(io.pravega.client.segment.impl.SegmentMetadataClient) StreamSegmentStore(io.pravega.segmentstore.contracts.StreamSegmentStore) CompletableFuture(java.util.concurrent.CompletableFuture) SegmentOutputStreamFactoryImpl(io.pravega.client.segment.impl.SegmentOutputStreamFactoryImpl) SegmentOutputStream(io.pravega.client.segment.impl.SegmentOutputStream) MockController(io.pravega.client.stream.mock.MockController) SegmentMetadataClientFactoryImpl(io.pravega.client.segment.impl.SegmentMetadataClientFactoryImpl) Test(org.junit.Test)

Example 19 with SegmentMetadataClient

use of io.pravega.client.segment.impl.SegmentMetadataClient in project pravega by pravega.

the class AppendReconnectTest method reconnectThroughConditionalClient.

@Test(timeout = 30000)
public void reconnectThroughConditionalClient() throws Exception {
    String endpoint = "localhost";
    int port = TestUtils.getAvailableListenPort();
    byte[] payload = "Hello world\n".getBytes();
    String scope = "scope";
    String stream = "stream";
    StreamSegmentStore store = this.serviceBuilder.createStreamSegmentService();
    @Cleanup PravegaConnectionListener server = new PravegaConnectionListener(false, port, store, mock(TableStore.class), serviceBuilder.getLowPriorityExecutor());
    server.startListening();
    @Cleanup SocketConnectionFactoryImpl clientCF = new SocketConnectionFactoryImpl(ClientConfig.builder().build());
    @Cleanup ConnectionPoolImpl connectionPool = new ConnectionPoolImpl(ClientConfig.builder().build(), clientCF);
    Controller controller = new MockController(endpoint, port, connectionPool, true);
    controller.createScope(scope);
    controller.createStream(scope, stream, StreamConfiguration.builder().build());
    ConditionalOutputStreamFactoryImpl segmentClient = new ConditionalOutputStreamFactoryImpl(controller, connectionPool);
    Segment segment = Futures.getAndHandleExceptions(controller.getCurrentSegments(scope, stream), RuntimeException::new).getSegments().iterator().next();
    @Cleanup ConditionalOutputStream out = segmentClient.createConditionalOutputStream(segment, DelegationTokenProviderFactory.createWithEmptyToken(), EventWriterConfig.builder().build());
    assertTrue(out.write(ByteBuffer.wrap(payload), 0));
    for (AutoCloseable c : connectionPool.getActiveChannels()) {
        c.close();
    }
    assertTrue(out.write(ByteBuffer.wrap(payload), payload.length + WireCommands.TYPE_PLUS_LENGTH_SIZE));
    @Cleanup SegmentMetadataClient metadataClient = new SegmentMetadataClientFactoryImpl(controller, connectionPool).createSegmentMetadataClient(segment, DelegationTokenProviderFactory.createWithEmptyToken());
    assertEquals((payload.length + WireCommands.TYPE_PLUS_LENGTH_SIZE) * 2, metadataClient.fetchCurrentSegmentLength().join().longValue());
}
Also used : ConnectionPoolImpl(io.pravega.client.connection.impl.ConnectionPoolImpl) ConditionalOutputStream(io.pravega.client.segment.impl.ConditionalOutputStream) SocketConnectionFactoryImpl(io.pravega.client.connection.impl.SocketConnectionFactoryImpl) MockController(io.pravega.client.stream.mock.MockController) Controller(io.pravega.client.control.impl.Controller) Cleanup(lombok.Cleanup) PravegaConnectionListener(io.pravega.segmentstore.server.host.handler.PravegaConnectionListener) Segment(io.pravega.client.segment.impl.Segment) TableStore(io.pravega.segmentstore.contracts.tables.TableStore) SegmentMetadataClient(io.pravega.client.segment.impl.SegmentMetadataClient) StreamSegmentStore(io.pravega.segmentstore.contracts.StreamSegmentStore) ConditionalOutputStreamFactoryImpl(io.pravega.client.segment.impl.ConditionalOutputStreamFactoryImpl) MockController(io.pravega.client.stream.mock.MockController) SegmentMetadataClientFactoryImpl(io.pravega.client.segment.impl.SegmentMetadataClientFactoryImpl) Test(org.junit.Test)

Aggregations

SegmentMetadataClient (io.pravega.client.segment.impl.SegmentMetadataClient)19 Segment (io.pravega.client.segment.impl.Segment)15 Cleanup (lombok.Cleanup)14 Test (org.junit.Test)10 SegmentOutputStream (io.pravega.client.segment.impl.SegmentOutputStream)7 MockController (io.pravega.client.stream.mock.MockController)6 SegmentMetadataClientFactory (io.pravega.client.segment.impl.SegmentMetadataClientFactory)5 MockSegmentStreamFactory (io.pravega.client.stream.mock.MockSegmentStreamFactory)5 Controller (io.pravega.client.control.impl.Controller)4 DelegationTokenProvider (io.pravega.client.security.auth.DelegationTokenProvider)4 SegmentInfo (io.pravega.client.segment.impl.SegmentInfo)4 SegmentInputStreamFactory (io.pravega.client.segment.impl.SegmentInputStreamFactory)4 SegmentMetadataClientFactoryImpl (io.pravega.client.segment.impl.SegmentMetadataClientFactoryImpl)4 EventWriterConfig (io.pravega.client.stream.EventWriterConfig)4 SocketConnectionFactoryImpl (io.pravega.client.connection.impl.SocketConnectionFactoryImpl)3 EventSegmentReader (io.pravega.client.segment.impl.EventSegmentReader)3 SegmentOutputStreamFactory (io.pravega.client.segment.impl.SegmentOutputStreamFactory)3 ClientConfig (io.pravega.client.ClientConfig)2 ConnectionPoolImpl (io.pravega.client.connection.impl.ConnectionPoolImpl)2 ConditionalOutputStream (io.pravega.client.segment.impl.ConditionalOutputStream)2