Beispiel #1
0
def get_postprocessing_stack(username, stack_id):
    """
    Fetches the Postprocessing Stack with the given ID and username from the postprocessing server

    :param stack_id: The ID of the stack to fetch

    :param username: The username of the user who owns this stack

    :raises NotFoundError: if the requested postprocessing stack is not found

    :raises UnavailableError: if the Postprocessing service is not reachable

    :return: Instance of :class:`server.gen.phenopipe_r_pb2.PostprocessingStack`
    """
    r_stub = phenopipe_r_pb2_grpc.PhenopipeRStub(get_r_channel())
    try:
        response = r_stub.GetPostprocessingStack(
            phenopipe_r_pb2.GetPostprocessingStackRequest(stack_id=stack_id,
                                                          author=username))

        return response.stack
    except grpc.RpcError as e:
        if e.code() == grpc.StatusCode.NOT_FOUND:
            raise NotFoundError(e.details(), "PostprocessingStack")
        elif e.code() == grpc.StatusCode.UNAVAILABLE:
            raise UnavailableError("Postprocessing Service")
        raise  # TODO other error options?
def upload_stack(stack):
    """
    Uploads the given Postprocessing Stack to the Postprocessing server via GRPC

    :param stack: Instance of :class:`server.gen.phenopipe_r_pb2.PostprocessingStack`

    :return: The ID of the uploaded stack
    """
    r_stub = phenopipe_r_pb2_grpc.PhenopipeRStub(get_r_channel())
    try:
        scripts = []
        for index, script in enumerate(stack.scripts):
            scripts.append(phenopipe_r_pb2.PostprocessingScript(name=script.name, description=script.description,
                                                                index=index, file=script.file))
        stack = phenopipe_r_pb2.PostprocessingStack(name=stack.name, description=stack.description,
                                                    author=stack.author, scripts=scripts)
        response = r_stub.UploadPostprocessingStack(
            phenopipe_r_pb2.UploadPostprocessingStackRequest(stack=stack)
        )
        stack_id = response.stack_id
        print(stack_id)

        return stack_id
    except grpc.RpcError as e:
        if e.code() == grpc.StatusCode.UNAVAILABLE:
            raise UnavailableError("Postprocessing Service")
        elif e.code() == grpc.StatusCode.ALREADY_EXISTS:
            raise PostprocessingStackAlreadyExistsError(e.details(), e.initial_metadata()[0][1],
                                                        e.initial_metadata()[1][1])
Beispiel #3
0
def get_postprocessing_stacks(username):
    """
    Fetches all available Postprocessing Stacks from the postprocessing server

    :raises UnavailableError: if the Postprocessing service is not reachable

    :return: List of instances of :class:`server.gen.phenopipe_r_pb2.PostprocessingStack`
    """
    r_stub = phenopipe_r_pb2_grpc.PhenopipeRStub(get_r_channel())
    try:
        response = r_stub.GetPostprocessingStacks(
            phenopipe_r_pb2.GetPostprocessingStacksRequest(author=username))
        stacks = response.stacks
        return stacks
    except grpc.RpcError as e:
        if e.code() == grpc.StatusCode.UNAVAILABLE:
            raise UnavailableError("Postprocessing Service")
        raise  # TODO other error options?