use of io.pravega.client.connection.impl.RawClient in project pravega by pravega.
the class SegmentHelper method readTableEntries.
public CompletableFuture<HashTableIteratorItem<TableSegmentEntry>> readTableEntries(final String tableName, final PravegaNodeUri uri, final int suggestedEntryCount, final HashTableIteratorItem.State state, final String delegationToken, final long clientRequestId) {
final WireCommandType type = WireCommandType.READ_TABLE_ENTRIES;
RawClient connection = new RawClient(uri, connectionPool);
final long requestId = connection.getFlow().asLong();
final HashTableIteratorItem.State token = (state == null) ? HashTableIteratorItem.State.EMPTY : state;
WireCommands.TableIteratorArgs args = new WireCommands.TableIteratorArgs(token.getToken(), Unpooled.EMPTY_BUFFER, Unpooled.EMPTY_BUFFER, Unpooled.EMPTY_BUFFER);
WireCommands.ReadTableEntries request = new WireCommands.ReadTableEntries(requestId, tableName, delegationToken, suggestedEntryCount, args);
return sendRequest(connection, clientRequestId, request).thenApply(rpl -> {
handleReply(clientRequestId, rpl, connection, tableName, WireCommands.ReadTableEntries.class, type);
WireCommands.TableEntriesRead tableEntriesRead = (WireCommands.TableEntriesRead) rpl;
final HashTableIteratorItem.State newState = HashTableIteratorItem.State.fromBytes(tableEntriesRead.getContinuationToken());
final List<TableSegmentEntry> entries = tableEntriesRead.getEntries().getEntries().stream().map(e -> {
WireCommands.TableKey k = e.getKey();
return TableSegmentEntry.versioned(k.getData(), e.getValue().getData(), k.getKeyVersion());
}).collect(Collectors.toList());
return new HashTableIteratorItem<>(newState, entries);
});
}
use of io.pravega.client.connection.impl.RawClient in project pravega by pravega.
the class SegmentHelper method readTableKeys.
public CompletableFuture<HashTableIteratorItem<TableSegmentKey>> readTableKeys(final String tableName, final PravegaNodeUri uri, final int suggestedKeyCount, final HashTableIteratorItem.State state, final String delegationToken, final long clientRequestId) {
final WireCommandType type = WireCommandType.READ_TABLE_KEYS;
RawClient connection = new RawClient(uri, connectionPool);
final long requestId = connection.getFlow().asLong();
final HashTableIteratorItem.State token = (state == null) ? HashTableIteratorItem.State.EMPTY : state;
WireCommands.TableIteratorArgs args = new WireCommands.TableIteratorArgs(token.getToken(), Unpooled.EMPTY_BUFFER, Unpooled.EMPTY_BUFFER, Unpooled.EMPTY_BUFFER);
WireCommands.ReadTableKeys request = new WireCommands.ReadTableKeys(requestId, tableName, delegationToken, suggestedKeyCount, args);
return sendRequest(connection, clientRequestId, request).thenApply(rpl -> {
handleReply(clientRequestId, rpl, connection, tableName, WireCommands.ReadTableKeys.class, type);
WireCommands.TableKeysRead tableKeysRead = (WireCommands.TableKeysRead) rpl;
final HashTableIteratorItem.State newState = HashTableIteratorItem.State.fromBytes(tableKeysRead.getContinuationToken());
final List<TableSegmentKey> keys = tableKeysRead.getKeys().stream().map(k -> TableSegmentKey.versioned(k.getData(), k.getKeyVersion())).collect(Collectors.toList());
return new HashTableIteratorItem<>(newState, keys);
});
}
use of io.pravega.client.connection.impl.RawClient in project pravega by pravega.
the class SegmentHelper method readTable.
public CompletableFuture<List<TableSegmentEntry>> readTable(final String tableName, final PravegaNodeUri uri, final List<TableSegmentKey> keys, String delegationToken, final long clientRequestId) {
final WireCommandType type = WireCommandType.READ_TABLE;
// the version is always NO_VERSION as read returns the latest version of value.
List<WireCommands.TableKey> keyList = keys.stream().map(k -> new WireCommands.TableKey(k.getKey(), k.getVersion().getSegmentVersion())).collect(Collectors.toList());
RawClient connection = new RawClient(uri, connectionPool);
final long requestId = connection.getFlow().asLong();
WireCommands.ReadTable request = new WireCommands.ReadTable(requestId, tableName, delegationToken, keyList);
return sendRequest(connection, clientRequestId, request).thenApply(rpl -> {
handleReply(clientRequestId, rpl, connection, tableName, WireCommands.ReadTable.class, type);
return ((WireCommands.TableRead) rpl).getEntries().getEntries().stream().map(this::convertFromWireCommand).collect(Collectors.toList());
});
}
use of io.pravega.client.connection.impl.RawClient in project pravega by pravega.
the class SegmentHelper method updatePolicy.
public CompletableFuture<Void> updatePolicy(String scope, String stream, ScalingPolicy policy, long segmentId, String delegationToken, long clientRequestId) {
final String qualifiedName = getQualifiedStreamSegmentName(scope, stream, segmentId);
final Controller.NodeUri uri = getSegmentUri(scope, stream, segmentId);
final WireCommandType type = WireCommandType.UPDATE_SEGMENT_POLICY;
Pair<Byte, Integer> extracted = extractFromPolicy(policy);
RawClient connection = new RawClient(ModelHelper.encode(uri), connectionPool);
final long requestId = connection.getFlow().asLong();
WireCommands.UpdateSegmentPolicy request = new WireCommands.UpdateSegmentPolicy(requestId, qualifiedName, extracted.getLeft(), extracted.getRight(), delegationToken);
return sendRequest(connection, clientRequestId, request).thenAccept(r -> handleReply(clientRequestId, r, connection, qualifiedName, WireCommands.UpdateSegmentPolicy.class, type));
}
use of io.pravega.client.connection.impl.RawClient in project pravega by pravega.
the class SegmentHelper method readSegment.
public CompletableFuture<WireCommands.SegmentRead> readSegment(String qualifiedName, long offset, int length, PravegaNodeUri uri, String delegationToken) {
final WireCommandType type = WireCommandType.READ_SEGMENT;
RawClient connection = new RawClient(uri, connectionPool);
final long requestId = connection.getFlow().asLong();
WireCommands.ReadSegment request = new WireCommands.ReadSegment(qualifiedName, offset, length, delegationToken, requestId);
return sendRequest(connection, requestId, request).thenApply(r -> {
handleReply(requestId, r, connection, qualifiedName, WireCommands.ReadSegment.class, type);
assert r instanceof WireCommands.SegmentRead;
return (WireCommands.SegmentRead) r;
});
}
Aggregations