Exemplo n.º 1
0
def delete_object(obj):
    # type: (object) -> bool
    """ Remove object.

    Removes a used object from the internal structures and calls the
    external python library (that calls the bindings-common)
    in order to request a its corresponding file removal.

    :param obj: Object to remove.
    :return: True if success. False otherwise.
    """
    with event_master(DELETE_OBJECT_EVENT):
        app_id = 0
        obj_id = OT.is_tracked(obj)
        if obj_id is None:
            # Not being tracked
            return False
        else:
            try:
                file_name = OT.get_file_name(obj_id)
                COMPSs.delete_file(app_id, file_name, False)
                OT.stop_tracking(obj)
            except KeyError:
                pass
            return True
Exemplo n.º 2
0
def _synchronize(obj, mode):
    # type: (typing.Any, int) -> typing.Any
    """ Synchronization function.

    This method retrieves the value of a future object.
    Calls the runtime in order to wait for the value and returns it when
    received.

    :param obj: Object to synchronize.
    :param mode: Direction of the object to synchronize.
    :return: The value of the object requested.
    """
    # TODO: Add a boolean to differentiate between files and object on the
    # COMPSs.open_file call. This change pretends to obtain better traces.
    # Must be implemented first in the Runtime, then in the bindings common
    # C API and finally add the boolean here
    app_id = 0
    obj_id = ""  # noqa

    if is_psco(obj):
        obj_id = str(get_id(obj))
        if not OT.is_pending_to_synchronize(obj_id):
            return obj
        else:
            # file_path is of the form storage://pscoId or
            # file://sys_path_to_file
            file_path = COMPSs.open_file(app_id, "".join(
                ("storage://", str(obj_id))), mode)
            # TODO: Add switch on protocol (first parameter returned currently ignored)
            _, file_name = file_path.split("://")
            new_obj = get_by_id(file_name)
            OT.stop_tracking(obj)
            return new_obj

    obj_id = OT.is_tracked(obj)
    obj_name = OT.get_obj_name(obj_id)
    if obj_id is None:  # Not being tracked
        return obj
    if not OT.is_pending_to_synchronize(obj_id):
        return obj

    if __debug__:
        logger.debug("Synchronizing object %s with mode %s" % (obj_id, mode))

    file_name = OT.get_file_name(obj_id)
    compss_file = COMPSs.open_file(app_id, file_name, mode)

    # Runtime can return a path or a PSCOId
    if compss_file.startswith('/'):
        # If the real filename is null, then return None. The task that
        # produces the output file may have been ignored or cancelled, so its
        # result does not exist.
        real_file_name = compss_file.split('/')[-1]
        if real_file_name == "null":
            print(
                "WARNING: Could not retrieve the object " + str(file_name) +
                " since the task that produces it may have been IGNORED or CANCELLED. Please, check the logs. Returning None."
            )  # noqa: E501
            return None
        new_obj = deserialize_from_file(compss_file)
        COMPSs.close_file(app_id, file_name, mode)
    else:
        new_obj = get_by_id(compss_file)

    if context.is_nesting_enabled() and context.in_worker():
        # If nesting and in worker, the user wants to synchronize an object.
        # So it is necessary to update the parameter with the new object.
        update_worker_argument_parameter_content(obj_name, new_obj)

    if mode == 'r':
        OT.update_mapping(obj_id, new_obj)

    if mode != 'r':
        COMPSs.delete_file(app_id, OT.get_file_name(obj_id), False)
        OT.stop_tracking(obj)

    return new_obj