use of org.apache.ratis.examples.filestore.FileStoreClient in project incubator-ratis by apache.
the class Client method getClients.
public List<FileStoreClient> getClients(RaftProperties raftProperties) {
List<FileStoreClient> fileStoreClients = new ArrayList<>();
for (int i = 0; i < numClients; i++) {
final RaftGroup raftGroup = RaftGroup.valueOf(RaftGroupId.valueOf(ByteString.copyFromUtf8(getRaftGroupId())), getPeers());
RaftClient.Builder builder = RaftClient.newBuilder().setProperties(raftProperties);
builder.setRaftGroup(raftGroup);
builder.setClientRpc(new GrpcFactory(new org.apache.ratis.conf.Parameters()).newRaftClientRpc(ClientId.randomId(), raftProperties));
RaftPeer[] peers = getPeers();
builder.setPrimaryDataStreamServer(peers[0]);
RaftClient client = builder.build();
fileStoreClients.add(new FileStoreClient(client));
}
return fileStoreClients;
}
use of org.apache.ratis.examples.filestore.FileStoreClient in project incubator-ratis by apache.
the class LoadGen method writeByHeapByteBuffer.
private Map<String, CompletableFuture<List<CompletableFuture<Long>>>> writeByHeapByteBuffer(List<String> paths, List<FileStoreClient> clients, ExecutorService executor) {
Map<String, CompletableFuture<List<CompletableFuture<Long>>>> fileMap = new HashMap<>();
int clientIndex = 0;
for (String path : paths) {
final CompletableFuture<List<CompletableFuture<Long>>> future = new CompletableFuture<>();
final FileStoreClient client = clients.get(clientIndex % clients.size());
clientIndex++;
CompletableFuture.supplyAsync(() -> {
List<CompletableFuture<Long>> futures = new ArrayList<>();
File file = new File(path);
try (FileInputStream fis = new FileInputStream(file)) {
final FileChannel in = fis.getChannel();
for (long offset = 0L; offset < getFileSizeInBytes(); ) {
offset += write(in, offset, client, file.getName(), futures);
}
} catch (Throwable e) {
future.completeExceptionally(e);
}
future.complete(futures);
return future;
}, executor);
fileMap.put(path, future);
}
return fileMap;
}
use of org.apache.ratis.examples.filestore.FileStoreClient in project incubator-ratis by apache.
the class DataStream method streamWrite.
private Map<String, CompletableFuture<List<CompletableFuture<DataStreamReply>>>> streamWrite(List<String> paths, List<FileStoreClient> clients, RoutingTable routingTable, ExecutorService executor) {
Map<String, CompletableFuture<List<CompletableFuture<DataStreamReply>>>> fileMap = new HashMap<>();
int clientIndex = 0;
for (String path : paths) {
final CompletableFuture<List<CompletableFuture<DataStreamReply>>> future = new CompletableFuture<>();
final FileStoreClient client = clients.get(clientIndex % clients.size());
clientIndex++;
CompletableFuture.supplyAsync(() -> {
File file = new File(path);
final long fileLength = file.length();
Preconditions.assertTrue(fileLength == getFileSizeInBytes(), "Unexpected file size: expected size is " + getFileSizeInBytes() + " but actual size is " + fileLength);
final Type type = Optional.ofNullable(Type.valueOfIgnoreCase(dataStreamType)).orElseThrow(IllegalStateException::new);
final TransferType writer = type.getConstructor().apply(path, this);
try {
future.complete(writer.transfer(client, routingTable));
} catch (IOException e) {
future.completeExceptionally(e);
}
return future;
}, executor);
fileMap.put(path, future);
}
return fileMap;
}
Aggregations