Search in sources :

Example 1 with FileStoreClient

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;
}
Also used : GrpcFactory(org.apache.ratis.grpc.GrpcFactory) ArrayList(java.util.ArrayList) RaftGroup(org.apache.ratis.protocol.RaftGroup) RaftPeer(org.apache.ratis.protocol.RaftPeer) FileStoreClient(org.apache.ratis.examples.filestore.FileStoreClient) RaftClient(org.apache.ratis.client.RaftClient)

Example 2 with FileStoreClient

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;
}
Also used : HashMap(java.util.HashMap) FileChannel(java.nio.channels.FileChannel) ArrayList(java.util.ArrayList) FileInputStream(java.io.FileInputStream) FileStoreClient(org.apache.ratis.examples.filestore.FileStoreClient) CompletableFuture(java.util.concurrent.CompletableFuture) ArrayList(java.util.ArrayList) List(java.util.List) File(java.io.File)

Example 3 with FileStoreClient

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;
}
Also used : HashMap(java.util.HashMap) IOException(java.io.IOException) DataStreamReply(org.apache.ratis.protocol.DataStreamReply) FileStoreClient(org.apache.ratis.examples.filestore.FileStoreClient) CompletableFuture(java.util.concurrent.CompletableFuture) ArrayList(java.util.ArrayList) List(java.util.List) File(java.io.File)

Aggregations

ArrayList (java.util.ArrayList)3 FileStoreClient (org.apache.ratis.examples.filestore.FileStoreClient)3 File (java.io.File)2 HashMap (java.util.HashMap)2 List (java.util.List)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 FileChannel (java.nio.channels.FileChannel)1 RaftClient (org.apache.ratis.client.RaftClient)1 GrpcFactory (org.apache.ratis.grpc.GrpcFactory)1 DataStreamReply (org.apache.ratis.protocol.DataStreamReply)1 RaftGroup (org.apache.ratis.protocol.RaftGroup)1 RaftPeer (org.apache.ratis.protocol.RaftPeer)1