Search in sources :

Example 1 with InvalidResourceNameException

use of build.buildfarm.common.UrlPath.InvalidResourceNameException in project bazel-buildfarm by bazelbuild.

the class ByteStreamService method read.

@Override
public void read(ReadRequest request, StreamObserver<ReadResponse> responseObserver) {
    String resourceName = request.getResourceName();
    long offset = request.getReadOffset();
    long limit = request.getReadLimit();
    logger.log(Level.FINER, format("read resource_name=%s offset=%d limit=%d", resourceName, offset, limit));
    try {
        maybeInstanceRead(resourceName, offset, limit, responseObserver);
    } catch (InvalidResourceNameException e) {
        responseObserver.onError(INVALID_ARGUMENT.withDescription(e.getMessage()).asException());
    }
}
Also used : ByteString(com.google.protobuf.ByteString) InvalidResourceNameException(build.buildfarm.common.UrlPath.InvalidResourceNameException)

Example 2 with InvalidResourceNameException

use of build.buildfarm.common.UrlPath.InvalidResourceNameException in project bazel-buildfarm by bazelbuild.

the class ByteStreamService method read.

@Override
public void read(ReadRequest request, StreamObserver<ReadResponse> responseObserver) {
    String resourceName = request.getResourceName();
    long readLimit = request.getReadLimit();
    long readOffset = request.getReadOffset();
    if (readLimit < 0 || readOffset < 0) {
        responseObserver.onError(Status.OUT_OF_RANGE.asException());
        return;
    }
    try {
        ResourceOperation resourceOperation = detectResourceOperation(resourceName);
        if (resourceOperation == ResourceOperation.Blob) {
            readBlob(request, responseObserver);
        } else {
            throw new InvalidResourceNameException(resourceName, "Unsupported service");
        }
    } catch (IllegalArgumentException | InvalidResourceNameException e) {
        String description = e.getLocalizedMessage();
        responseObserver.onError(Status.INVALID_ARGUMENT.withDescription(description).asException());
    }
}
Also used : ByteString(com.google.protobuf.ByteString) InvalidResourceNameException(build.buildfarm.common.UrlPath.InvalidResourceNameException) ResourceOperation(build.buildfarm.common.UrlPath.ResourceOperation) UrlPath.detectResourceOperation(build.buildfarm.common.UrlPath.detectResourceOperation)

Example 3 with InvalidResourceNameException

use of build.buildfarm.common.UrlPath.InvalidResourceNameException in project bazel-buildfarm by bazelbuild.

the class ByteStreamService method queryWriteStatus.

@Override
public void queryWriteStatus(QueryWriteStatusRequest request, StreamObserver<QueryWriteStatusResponse> responseObserver) {
    String resourceName = request.getResourceName();
    Write write;
    try {
        write = findWrite(resourceName);
    } catch (InvalidResourceNameException e) {
        String description = e.getLocalizedMessage();
        responseObserver.onError(Status.INVALID_ARGUMENT.withDescription(description).asException());
        return;
    } catch (IOException e) {
        responseObserver.onError(Status.fromThrowable(e).asException());
        return;
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        return;
    }
    if (write != null) {
        responseObserver.onNext(QueryWriteStatusResponse.newBuilder().setCommittedSize(write.getCommittedSize()).setComplete(write.getComplete()).build());
        responseObserver.onCompleted();
    } else {
        responseObserver.onError(Status.NOT_FOUND.asException());
    }
}
Also used : ByteString(com.google.protobuf.ByteString) IOException(java.io.IOException) InvalidResourceNameException(build.buildfarm.common.UrlPath.InvalidResourceNameException)

Example 4 with InvalidResourceNameException

use of build.buildfarm.common.UrlPath.InvalidResourceNameException in project bazel-buildfarm by bazelbuild.

the class ByteStreamService method queryWriteStatus.

@Override
public void queryWriteStatus(QueryWriteStatusRequest request, StreamObserver<QueryWriteStatusResponse> responseObserver) {
    String resourceName = request.getResourceName();
    try {
        logger.log(Level.FINE, format("queryWriteStatus(%s)", resourceName));
        Write write = getWrite(resourceName);
        responseObserver.onNext(QueryWriteStatusResponse.newBuilder().setCommittedSize(write.getCommittedSize()).setComplete(write.isComplete()).build());
        responseObserver.onCompleted();
        logger.log(Level.FINE, format("queryWriteStatus(%s) => committed_size = %d, complete = %s", resourceName, write.getCommittedSize(), write.isComplete()));
    } catch (IllegalArgumentException | InvalidResourceNameException e) {
        logger.log(Level.SEVERE, format("queryWriteStatus(%s)", resourceName), e);
        responseObserver.onError(INVALID_ARGUMENT.withDescription(e.getMessage()).asException());
    } catch (EntryLimitException e) {
        logger.log(Level.WARNING, format("queryWriteStatus(%s): %s", resourceName, e.getMessage()));
        responseObserver.onNext(QueryWriteStatusResponse.getDefaultInstance());
        responseObserver.onCompleted();
    } catch (RuntimeException e) {
        logger.log(Level.SEVERE, format("queryWriteStatus(%s)", resourceName), e);
        responseObserver.onError(Status.fromThrowable(e).asException());
    }
}
Also used : CompleteWrite(build.buildfarm.common.Write.CompleteWrite) Write(build.buildfarm.common.Write) ByteString(com.google.protobuf.ByteString) EntryLimitException(build.buildfarm.common.EntryLimitException) InvalidResourceNameException(build.buildfarm.common.UrlPath.InvalidResourceNameException)

Aggregations

InvalidResourceNameException (build.buildfarm.common.UrlPath.InvalidResourceNameException)4 ByteString (com.google.protobuf.ByteString)4 EntryLimitException (build.buildfarm.common.EntryLimitException)1 ResourceOperation (build.buildfarm.common.UrlPath.ResourceOperation)1 UrlPath.detectResourceOperation (build.buildfarm.common.UrlPath.detectResourceOperation)1 Write (build.buildfarm.common.Write)1 CompleteWrite (build.buildfarm.common.Write.CompleteWrite)1 IOException (java.io.IOException)1