How to use the nipyapi.nifi function in nipyapi

To help you get started, we’ve selected a few nipyapi examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Chaffelson / nipyapi / nipyapi / canvas.py View on Github external
def _autumn_leaves(con_id_, drop_request_):
        test_obj = nipyapi.nifi.FlowfileQueuesApi().get_drop_request(
            con_id_,
            drop_request_.drop_request.id
        ).drop_request
        if not test_obj.finished:
            return False
        if test_obj.failure_reason:
            raise ValueError(
                "Unable to complete drop request{0}, error was {1}"
                .format(test_obj, test_obj.drop_request.failure_reason)
            )
        return True

    with nipyapi.utils.rest_exceptions():
        drop_req = nipyapi.nifi.FlowfileQueuesApi().create_drop_request(con_id)
    assert isinstance(drop_req, nipyapi.nifi.DropRequestEntity)
    return nipyapi.utils.wait_to_complete(_autumn_leaves, con_id, drop_req)
github Chaffelson / nipyapi / nipyapi / utils.py View on Github external
def infer_object_label_from_class(obj):
    """
    Returns the expected STRING label for an object class required by certain
        functions.

    Args:
        obj: The object to infer the name of

    Returns:
        str of the relevant name, or raises an AssertionError

    """
    if isinstance(obj, nipyapi.nifi.ProcessorEntity):
        return 'PROCESSOR'
    if isinstance(obj, nipyapi.nifi.FunnelEntity):
        return 'FUNNEL'
    if isinstance(obj, nipyapi.nifi.PortEntity):
        return obj.port_type
    if isinstance(obj, nipyapi.nifi.RemoteProcessGroupPortDTO):
        # get RPG summary, find id of obj in input or output list
        parent_rpg = nipyapi.canvas.get_remote_process_group(
            obj.group_id, True)
        if obj.id in [x.id for x in parent_rpg['input_ports']]:
            return 'REMOTE_INPUT_PORT'
        if obj.id in [x.id for x in parent_rpg['output_ports']]:
            return 'REMOTE_OUTPUT_PORT'
        raise ValueError("Remote Port not present as expected in RPG")
    raise AssertionError("Object Class not recognised for this function")
github Chaffelson / nipyapi / nipyapi / canvas.py View on Github external
log.info("Processor not stopped, active thread count %s",
                 test_obj.status.aggregate_snapshot.active_thread_count)
        return False

    def _starting_schedule_processor(processor_):
        test_obj = nipyapi.canvas.get_processor(processor_.id, 'id')
        if test_obj.component.state == 'RUNNING':
            return True
        log.info("Processor not started, run_status %s",
                 test_obj.component.state)
        return False

    assert isinstance(scheduled, bool)
    if refresh:
        target = nipyapi.canvas.get_processor(processor.id, 'id')
        assert isinstance(target, nipyapi.nifi.ProcessorEntity)
    else:
        target = processor
    result = schedule_components(
        pg_id=target.status.group_id,
        scheduled=scheduled,
        components=[target]
    )
    # If target scheduled state was successfully updated
    if result:
        # If we want to stop the processor
        if not scheduled:
            # Test that the processor threads have halted
            stop_test = nipyapi.utils.wait_to_complete(
                _running_schedule_processor, target
            )
            if stop_test:
github Chaffelson / nipyapi / nipyapi / system.py View on Github external
def get_node(nid):
    """
    Returns the cluster node information

    Args:
        nid (str): The UUID of the Node to target

    Returns:

    """
    with nipyapi.utils.rest_exceptions():
        return nipyapi.nifi.ControllerApi().get_node(nid)
github Chaffelson / nipyapi / nipyapi / demo / console.py View on Github external
_pg0,
    location=(400.0, 400.0)
)

log.info("Cleaning up old NiPyApi Console Processors")
processor_0 = nipyapi.canvas.get_processor(_proc0)
if processor_0 is not None:
    nipyapi.canvas.delete_processor(process_group_0, True)
log.info("Creating processor_0 as a new GenerateFlowFile named %s in the "
         "previous ProcessGroup", _proc0)
processor_0 = nipyapi.canvas.create_processor(
    parent_pg=process_group_0,
    processor=nipyapi.canvas.get_processor_type('GenerateFlowFile'),
    location=(400.0, 400.0),
    name=_proc0,
    config=nipyapi.nifi.ProcessorConfigDTO(
        scheduling_period='5s',
        auto_terminated_relationships=['failure']
    )
)

log.info("Creating reg_client_0 as NiFi Registry Client")
# If the secured environment demo setup has already run, then we just
# want to reuse that client for NiFi <> Registry Comms
reg_client_0 = nipyapi.versioning.get_registry_client(
    'nipyapi_secure_reg_client_0',
    'name'
)
try:
    reg_client_0 = nipyapi.versioning.list_registry_clients().registries[0]
except IndexError:
    reg_client_0 = None
github Chaffelson / nipyapi / nipyapi / security.py View on Github external
"""
    assert service in _valid_services
    assert isinstance(identity, six.string_types)
    assert isinstance(strict, bool)
    if service == 'registry':
        user_obj = nipyapi.registry.User(
            identity=identity
        )
    else:
        # must be nifi
        user_obj = nipyapi.nifi.UserEntity(
            revision=nipyapi.nifi.RevisionDTO(
                version=0
            ),
            component=nipyapi.nifi.UserDTO(
                identity=identity
            )
        )
    try:
        return getattr(nipyapi, service).TenantsApi().create_user(user_obj)
    except (nipyapi.nifi.rest.ApiException,
            nipyapi.registry.rest.ApiException) as e:
        if 'already exists' in e.body and not strict:
            return get_service_user(identity, service=service)
        raise ValueError(e.body)
github Chaffelson / nipyapi / nipyapi / canvas.py View on Github external
the given identifier_type field

    Args:
        identifier (str): The String to filter against
        identifier_type (str): The field to apply the filter to. Set in
            config.py

    Returns:
        None for no matches, Single Object for unique match,
        list(Objects) for multiple matches
    """
    assert isinstance(identifier, six.string_types)
    assert identifier_type in ['name', 'id']
    with nipyapi.utils.rest_exceptions():
        if identifier_type == 'id':
            out = nipyapi.nifi.ProcessorsApi().get_processor(identifier)
        else:
            obj = list_all_processors()
            out = nipyapi.utils.filter_obj(obj, identifier, identifier_type)
    return out