Search in sources :

Example 1 with GetBookieInfoRequest

use of org.apache.bookkeeper.proto.BookkeeperProtocol.GetBookieInfoRequest in project bookkeeper by apache.

the class GetBookieInfoProcessorV3 method getGetBookieInfoResponse.

private GetBookieInfoResponse getGetBookieInfoResponse() {
    long startTimeNanos = MathUtils.nowInNano();
    GetBookieInfoRequest getBookieInfoRequest = request.getGetBookieInfoRequest();
    long requested = getBookieInfoRequest.getRequested();
    GetBookieInfoResponse.Builder getBookieInfoResponse = GetBookieInfoResponse.newBuilder();
    if (!isVersionCompatible()) {
        getBookieInfoResponse.setStatus(StatusCode.EBADVERSION);
        requestProcessor.getBookieInfoStats.registerFailedEvent(MathUtils.elapsedNanos(startTimeNanos), TimeUnit.NANOSECONDS);
        return getBookieInfoResponse.build();
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("Received new getBookieInfo request: {}", request);
    }
    StatusCode status = StatusCode.EOK;
    long freeDiskSpace = 0L, totalDiskSpace = 0L;
    try {
        if ((requested & GetBookieInfoRequest.Flags.FREE_DISK_SPACE_VALUE) != 0) {
            freeDiskSpace = requestProcessor.bookie.getTotalFreeSpace();
            getBookieInfoResponse.setFreeDiskSpace(freeDiskSpace);
        }
        if ((requested & GetBookieInfoRequest.Flags.TOTAL_DISK_CAPACITY_VALUE) != 0) {
            totalDiskSpace = requestProcessor.bookie.getTotalDiskSpace();
            getBookieInfoResponse.setTotalDiskCapacity(totalDiskSpace);
        }
        LOG.debug("FreeDiskSpace info is " + freeDiskSpace + " totalDiskSpace is: " + totalDiskSpace);
    } catch (IOException e) {
        status = StatusCode.EIO;
        LOG.error("IOException while getting  freespace/totalspace", e);
    }
    getBookieInfoResponse.setStatus(status);
    requestProcessor.getBookieInfoStats.registerSuccessfulEvent(MathUtils.elapsedNanos(startTimeNanos), TimeUnit.NANOSECONDS);
    return getBookieInfoResponse.build();
}
Also used : GetBookieInfoResponse(org.apache.bookkeeper.proto.BookkeeperProtocol.GetBookieInfoResponse) GetBookieInfoRequest(org.apache.bookkeeper.proto.BookkeeperProtocol.GetBookieInfoRequest) IOException(java.io.IOException) StatusCode(org.apache.bookkeeper.proto.BookkeeperProtocol.StatusCode)

Example 2 with GetBookieInfoRequest

use of org.apache.bookkeeper.proto.BookkeeperProtocol.GetBookieInfoRequest in project bookkeeper by apache.

the class PerChannelBookieClient method getBookieInfo.

public void getBookieInfo(final long requested, GetBookieInfoCallback cb, Object ctx) {
    final long txnId = getTxnId();
    final CompletionKey completionKey = new V3CompletionKey(txnId, OperationType.GET_BOOKIE_INFO);
    completionObjects.put(completionKey, new GetBookieInfoCompletion(completionKey, cb, ctx));
    // Build the request and calculate the total size to be included in the packet.
    BKPacketHeader.Builder headerBuilder = BKPacketHeader.newBuilder().setVersion(ProtocolVersion.VERSION_THREE).setOperation(OperationType.GET_BOOKIE_INFO).setTxnId(txnId);
    GetBookieInfoRequest.Builder getBookieInfoBuilder = GetBookieInfoRequest.newBuilder().setRequested(requested);
    final Request getBookieInfoRequest = Request.newBuilder().setHeader(headerBuilder).setGetBookieInfoRequest(getBookieInfoBuilder).build();
    writeAndFlush(channel, completionKey, getBookieInfoRequest);
}
Also used : ReadLacRequest(org.apache.bookkeeper.proto.BookkeeperProtocol.ReadLacRequest) WriteLacRequest(org.apache.bookkeeper.proto.BookkeeperProtocol.WriteLacRequest) GetBookieInfoRequest(org.apache.bookkeeper.proto.BookkeeperProtocol.GetBookieInfoRequest) AddRequest(org.apache.bookkeeper.proto.BookkeeperProtocol.AddRequest) ReadRequest(org.apache.bookkeeper.proto.BookkeeperProtocol.ReadRequest) Request(org.apache.bookkeeper.proto.BookkeeperProtocol.Request) GetBookieInfoRequest(org.apache.bookkeeper.proto.BookkeeperProtocol.GetBookieInfoRequest) BKPacketHeader(org.apache.bookkeeper.proto.BookkeeperProtocol.BKPacketHeader)

Aggregations

GetBookieInfoRequest (org.apache.bookkeeper.proto.BookkeeperProtocol.GetBookieInfoRequest)2 IOException (java.io.IOException)1 AddRequest (org.apache.bookkeeper.proto.BookkeeperProtocol.AddRequest)1 BKPacketHeader (org.apache.bookkeeper.proto.BookkeeperProtocol.BKPacketHeader)1 GetBookieInfoResponse (org.apache.bookkeeper.proto.BookkeeperProtocol.GetBookieInfoResponse)1 ReadLacRequest (org.apache.bookkeeper.proto.BookkeeperProtocol.ReadLacRequest)1 ReadRequest (org.apache.bookkeeper.proto.BookkeeperProtocol.ReadRequest)1 Request (org.apache.bookkeeper.proto.BookkeeperProtocol.Request)1 StatusCode (org.apache.bookkeeper.proto.BookkeeperProtocol.StatusCode)1 WriteLacRequest (org.apache.bookkeeper.proto.BookkeeperProtocol.WriteLacRequest)1