How to use the nipyapi.nifi.ProcessGroupsApi 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 _running_schedule_process_group(pg_id_):
        test_obj = nipyapi.nifi.ProcessGroupsApi().get_process_group(pg_id_)
        if test_obj.status.aggregate_snapshot.active_thread_count == 0:
            return True
        return False
github Chaffelson / nipyapi / nipyapi / canvas.py View on Github external
Args:
        identifier (str): the string to filter the list for
        identifier_type (str): the field to filter on, 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':
            # assuming unique fetch of pg id
            # implementing separately to avoid recursing entire canvas
            out = nipyapi.nifi.ProcessGroupsApi().get_process_group(identifier)
        else:
            obj = list_all_process_groups()
            out = nipyapi.utils.filter_obj(obj, identifier, identifier_type)
    return out
github Chaffelson / nipyapi / nipyapi / canvas.py View on Github external
pg_id (str): ID of the parent Process Group
        port_type (str): Either of INPUT_PORT or OUTPUT_PORT
        name (str): optional, Name to assign to the port
        state (str): One of RUNNING, STOPPED, DISABLED
        position (tuple): optional, tuple of ints like (400, 400)

    Returns:
        (PortEntity) of the created port

    """
    assert state in ["RUNNING", "STOPPED", "DISABLED"]
    assert port_type in ["INPUT_PORT", "OUTPUT_PORT"]
    assert isinstance(pg_id, six.string_types)
    position = position if position else (400, 400)
    assert isinstance(position, tuple)
    handle = nipyapi.nifi.ProcessGroupsApi()
    port_generator = getattr(handle, 'create_' + port_type.lower())
    with nipyapi.utils.rest_exceptions():
        return port_generator(
            id=pg_id,
            body=nipyapi.nifi.PortEntity(
                revision=nipyapi.nifi.RevisionDTO(version=0),
                component=nipyapi.nifi.PortDTO(
                    parent_group_id=pg_id,
                    position=nipyapi.nifi.PositionDTO(
                        x=float(position[0]),
                        y=float(position[1])
                    ),
                    name=name
                )
github Chaffelson / nipyapi / nipyapi / versioning.py View on Github external
target_flow = flow_versions.versioned_flow_snapshot_metadata_set
    else:
        target_flow = [x for x
                       in flow_versions.versioned_flow_snapshot_metadata_set
                       if x.versioned_flow_snapshot_metadata.version == version
                       ]
    if not target_flow:
        raise ValueError(
            "Could not find Version [{0}] for Flow [{1}] in Bucket [{2}] on "
            "Registry Client [{3}]"
            .format(str(version), flow_id, bucket_id, reg_client_id)
        )
    target_flow = target_flow[0].versioned_flow_snapshot_metadata
    # Issue deploy statement
    with nipyapi.utils.rest_exceptions():
        return nipyapi.nifi.ProcessGroupsApi().create_process_group(
            id=parent_id,
            body=nipyapi.nifi.ProcessGroupEntity(
                revision=nipyapi.nifi.RevisionDTO(
                    version=0
                ),
                component=nipyapi.nifi.ProcessGroupDTO(
                    position=nipyapi.nifi.PositionDTO(
                        x=float(location[0]),
                        y=float(location[1])
                    ),
                    version_control_information=VciDTO(
                        bucket_id=target_flow.bucket_identifier,
                        flow_id=target_flow.flow_identifier,
                        registry_id=target_reg_client.id,
                        version=target_flow.version
                    )
github Chaffelson / nipyapi / nipyapi / canvas.py View on Github external
parent_pg (ProcessGroupEntity): The parent Process Group to create the
            new process group in
        new_pg_name (str): The name of the new Process Group
        location (tuple[x, y]): the x,y coordinates to place the new Process
            Group under the parent
        comment (str): Entry for the Comments field

    Returns:
         (ProcessGroupEntity): The new Process Group

    """
    assert isinstance(parent_pg, nipyapi.nifi.ProcessGroupEntity)
    assert isinstance(new_pg_name, six.string_types)
    assert isinstance(location, tuple)
    with nipyapi.utils.rest_exceptions():
        return nipyapi.nifi.ProcessGroupsApi().create_process_group(
            id=parent_pg.id,
            body=nipyapi.nifi.ProcessGroupEntity(
                revision={'version': 0},
                component=nipyapi.nifi.ProcessGroupDTO(
                    name=new_pg_name,
                    position=nipyapi.nifi.PositionDTO(
                        x=float(location[0]),
                        y=float(location[1])
                    ),
                    comments=comment
                )
github Chaffelson / nipyapi / nipyapi / canvas.py View on Github external
if force:
            # Stop, drop, and roll.
            purge_process_group(target, stop=True)
            # Remove inbound connections
            for con in list_all_connections():
                if pg_id in [con.destination_group_id, con.source_group_id]:
                    delete_connection(con)
            # Stop all Controller Services
            for x in list_all_controllers(process_group.id):
                delete_controller(x, True)
            # Remove templates
            for template in nipyapi.templates.list_all_templates(native=False):
                if target.id == template.template.group_id:
                    nipyapi.templates.delete_template(template.id)
            # have to refresh revision after changes
            target = nipyapi.nifi.ProcessGroupsApi().get_process_group(pg_id)
            return nipyapi.nifi.ProcessGroupsApi().remove_process_group(
                id=target.id,
                version=target.revision.version,
                client_id=target.revision.client_id
            )
        raise ValueError(e.body)
github Chaffelson / nipyapi / nipyapi / canvas.py View on Github external
def list_all_processors(pg_id='root'):
    """
    Returns a flat list of all Processors under the provided Process Group

    Args:
        pg_id (str): The UUID of the Process Group to start from, defaults to
            the Canvas root

    Returns:
         list[ProcessorEntity]
    """
    assert isinstance(pg_id, six.string_types), "pg_id should be a string"

    if nipyapi.utils.check_version('1.7.0') <= 0:
        targets = nipyapi.nifi.ProcessGroupsApi().get_processors(
            id=pg_id,
            include_descendant_groups=True
        )
        return targets.processors
    # Handle older NiFi instances
    out = []
    # list of child process groups
    pg_ids = [x.id for x in list_all_process_groups(pg_id)]
    # process target list
    for this_pg_id in pg_ids:
        procs = nipyapi.nifi.ProcessGroupsApi().get_processors(this_pg_id)
        if procs.processors:
            out += procs.processors
    return out
github Chaffelson / nipyapi / nipyapi / templates.py View on Github external
Args:
        pg_id (str): The UUID of the Process Group to deploy into
        template_id (str): The UUID of the Template to deploy. Note that the
            Template must already be uploaded and available to the target
            Process Group
        loc_x (int): The X coordinate to deploy the Template at. Default(0)
        loc_y (int): The X coordinate to deploy the Template at. Default(0)

    Returns:
        (FlowEntity): The FlowEntity of the Process Group with the deployed
            template

    """
    with nipyapi.utils.rest_exceptions():
        return nipyapi.nifi.ProcessGroupsApi().instantiate_template(
            id=pg_id,
            body=nipyapi.nifi.InstantiateTemplateRequestEntity(
                origin_x=loc_x,
                origin_y=loc_y,
                template_id=template_id
            )