Search in sources :

Example 1 with SortDatanodesResponseProto

use of org.apache.hadoop.hdds.protocol.proto.ScmBlockLocationProtocolProtos.SortDatanodesResponseProto in project ozone by apache.

the class ScmBlockLocationProtocolServerSideTranslatorPB method sortDatanodes.

public SortDatanodesResponseProto sortDatanodes(SortDatanodesRequestProto request, int clientVersion) throws ServiceException {
    SortDatanodesResponseProto.Builder resp = SortDatanodesResponseProto.newBuilder();
    try {
        List<String> nodeList = request.getNodeNetworkNameList();
        final List<DatanodeDetails> results = impl.sortDatanodes(nodeList, request.getClient());
        if (results != null) {
            for (DatanodeDetails dn : results) {
                resp.addNode(dn.toProto(clientVersion));
            }
        }
        return resp.build();
    } catch (IOException ex) {
        throw new ServiceException(ex);
    }
}
Also used : ServiceException(com.google.protobuf.ServiceException) DatanodeDetails(org.apache.hadoop.hdds.protocol.DatanodeDetails) IOException(java.io.IOException) SortDatanodesResponseProto(org.apache.hadoop.hdds.protocol.proto.ScmBlockLocationProtocolProtos.SortDatanodesResponseProto)

Example 2 with SortDatanodesResponseProto

use of org.apache.hadoop.hdds.protocol.proto.ScmBlockLocationProtocolProtos.SortDatanodesResponseProto in project ozone by apache.

the class ScmBlockLocationProtocolClientSideTranslatorPB method sortDatanodes.

/**
 * Sort the datanodes based on distance from client.
 * @return List<DatanodeDetails></>
 * @throws IOException
 */
@Override
public List<DatanodeDetails> sortDatanodes(List<String> nodes, String clientMachine) throws IOException {
    SortDatanodesRequestProto request = SortDatanodesRequestProto.newBuilder().addAllNodeNetworkName(nodes).setClient(clientMachine).build();
    SCMBlockLocationRequest wrapper = createSCMBlockRequest(Type.SortDatanodes).setSortDatanodesRequest(request).build();
    final SCMBlockLocationResponse wrappedResponse = handleError(submitRequest(wrapper));
    SortDatanodesResponseProto resp = wrappedResponse.getSortDatanodesResponse();
    List<DatanodeDetails> results = new ArrayList<>(resp.getNodeCount());
    results.addAll(resp.getNodeList().stream().map(node -> DatanodeDetails.getFromProtoBuf(node)).collect(Collectors.toList()));
    return results;
}
Also used : SCMBlockLocationRequest(org.apache.hadoop.hdds.protocol.proto.ScmBlockLocationProtocolProtos.SCMBlockLocationRequest) SortDatanodesRequestProto(org.apache.hadoop.hdds.protocol.proto.ScmBlockLocationProtocolProtos.SortDatanodesRequestProto) DatanodeDetails(org.apache.hadoop.hdds.protocol.DatanodeDetails) SCMBlockLocationResponse(org.apache.hadoop.hdds.protocol.proto.ScmBlockLocationProtocolProtos.SCMBlockLocationResponse) ArrayList(java.util.ArrayList) SortDatanodesResponseProto(org.apache.hadoop.hdds.protocol.proto.ScmBlockLocationProtocolProtos.SortDatanodesResponseProto)

Aggregations

DatanodeDetails (org.apache.hadoop.hdds.protocol.DatanodeDetails)2 SortDatanodesResponseProto (org.apache.hadoop.hdds.protocol.proto.ScmBlockLocationProtocolProtos.SortDatanodesResponseProto)2 ServiceException (com.google.protobuf.ServiceException)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 SCMBlockLocationRequest (org.apache.hadoop.hdds.protocol.proto.ScmBlockLocationProtocolProtos.SCMBlockLocationRequest)1 SCMBlockLocationResponse (org.apache.hadoop.hdds.protocol.proto.ScmBlockLocationProtocolProtos.SCMBlockLocationResponse)1 SortDatanodesRequestProto (org.apache.hadoop.hdds.protocol.proto.ScmBlockLocationProtocolProtos.SortDatanodesRequestProto)1