Skip to content

Commit

Permalink
Add support for Parameter Contexts in parameters.py with appropriate …
Browse files Browse the repository at this point in the history
…tests and fixtures

Update release process in devnotes.rst with additional checks
Rework error raising to provide raise_from support inline with newer Python best practices, added future to requirements.txt in support of this for Py2 and Py3 intercompatibility
Add greedy control support to canvas.get_processor_type
Add checks to canvas.create_processor for correct user submissions
Improve get by ID behavior to correctly return None when an invalid ID is submitted (previously raised a 404)
Add canvas.get_controller_type to fetch a single controller type, previously only a listing option was provided
Add utils.enforce_min_version to improve controls when a feature is not available in older versions of NiFi as Paramter Contexts were only introduced in 1.10.0
Minor test case and style improvements
  • Loading branch information
Chaffelson committed Nov 10, 2020
1 parent 1e54f22 commit aa5fade
Show file tree
Hide file tree
Showing 12 changed files with 488 additions and 44 deletions.
1 change: 1 addition & 0 deletions docs/devnotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ This assumes you have virtualenvwrapper, git, and appropriate python versions in
deactivate
Push changes to Github
Check build on TravisCI
Check dockerhub automated build
# You may have to reactivate your original virtualenv
twine upload dist/*
# You may get a file exists error, check you're not trying to reupload an existing version
Expand Down
2 changes: 1 addition & 1 deletion nipyapi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
__email__ = 'chaffelson@gmail.com'
__version__ = '0.15.0'
__all__ = ['canvas', 'system', 'templates', 'config', 'nifi', 'registry',
'versioning', 'demo', 'utils', 'security']
'versioning', 'demo', 'utils', 'security', 'parameters']

for sub_module in __all__:
importlib.import_module('nipyapi.' + sub_module)
57 changes: 45 additions & 12 deletions nipyapi/canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
from __future__ import absolute_import
import logging
import six
from future.utils import raise_from as _raise
import nipyapi
from nipyapi.utils import exception_handler

__all__ = [
"get_root_pg_id", "recurse_flow", "get_flow", "get_process_group_status",
Expand Down Expand Up @@ -119,6 +121,7 @@ def get_process_group_status(pg_id='root', detail='names'):
return raw


@exception_handler(404, None)
def get_process_group(identifier, identifier_type='name', greedy=True):
"""
Filters the list of all process groups against a given identifier string
Expand Down Expand Up @@ -412,7 +415,7 @@ def delete_process_group(process_group, force=False, refresh=True):
version=target.revision.version,
client_id=target.revision.client_id
)
raise ValueError(e.body)
_raise(ValueError(e.body), e)


def create_process_group(parent_pg, new_pg_name, location, comment=''):
Expand Down Expand Up @@ -465,13 +468,14 @@ def list_all_processor_types():
return nipyapi.nifi.FlowApi().get_processor_types()


def get_processor_type(identifier, identifier_type='name'):
def get_processor_type(identifier, identifier_type='name', greedy=True):
"""
Gets the abstract object describing a Processor, or list thereof
Args:
identifier (str): the string to filter the list for
identifier_type (str): the field to filter on, set in config.py
greedy (bool): False for exact match, True for greedy match
Returns:
None for no matches, Single Object for unique match,
Expand All @@ -481,7 +485,9 @@ def get_processor_type(identifier, identifier_type='name'):
with nipyapi.utils.rest_exceptions():
obj = list_all_processor_types().processor_types
if obj:
return nipyapi.utils.filter_obj(obj, identifier, identifier_type)
return nipyapi.utils.filter_obj(
obj, identifier, identifier_type, greedy=greedy
)
return obj


Expand All @@ -502,6 +508,8 @@ def create_processor(parent_pg, processor, location, name=None, config=None):
(ProcessorEntity): The new Processor
"""
assert isinstance(parent_pg, nipyapi.nifi.ProcessGroupEntity)
assert isinstance(processor, nipyapi.nifi.DocumentedTypeDTO)
if name is None:
processor_name = processor.type.split('.')[-1]
else:
Expand All @@ -528,6 +536,7 @@ def create_processor(parent_pg, processor, location, name=None, config=None):
)


@exception_handler(404, None)
def get_processor(identifier, identifier_type='name', greedy=True):
"""
Filters the list of all Processors against the given identifier string in
Expand All @@ -545,14 +554,13 @@ def get_processor(identifier, identifier_type='name', greedy=True):
"""
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, greedy=greedy
)
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, greedy=greedy
)
return out


Expand All @@ -575,6 +583,8 @@ def delete_processor(processor, refresh=True, force=False):
assert isinstance(force, bool)
if refresh or force:
target = get_processor(processor.id, 'id')
if target is None:
return None # Processor does not exist
assert isinstance(target, nipyapi.nifi.ProcessorEntity)
else:
target = processor
Expand Down Expand Up @@ -1281,7 +1291,7 @@ def get_controller(identifier, identifier_type='name', bool_response=False):
except nipyapi.nifi.rest.ApiException as e:
if bool_response:
return False
raise ValueError(e.body)
_raise(ValueError(e.body), e)
return out


Expand All @@ -1296,6 +1306,29 @@ def list_all_controller_types():
return handle.get_controller_service_types().controller_service_types


def get_controller_type(identifier, identifier_type='name', greedy=True):
"""
Gets the abstract object describing a controller, or list thereof
Args:
identifier (str): the string to filter the list for
identifier_type (str): the field to filter on, set in config.py
greedy (bool): False for exact match, True for greedy match
Returns:
None for no matches, Single Object for unique match,
list(Objects) for multiple matches
"""
with nipyapi.utils.rest_exceptions():
obj = list_all_controller_types()
if obj:
return nipyapi.utils.filter_obj(
obj, identifier, identifier_type, greedy=greedy
)
return obj


def list_all_by_kind(kind, pg_id='root', descendants=True):
"""
Retrieves a list of all instances of a supported object type
Expand Down
7 changes: 4 additions & 3 deletions nipyapi/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
# convenience function for this in nipyapi.utils.set_endpoint

# Set Default Host for NiFi
default_host = 'localhost' # Default to localhost for release
default_host = '34.244.104.232' # Default to localhost for release
#
nifi_config.host = os.getenv(
'NIFI_API_ENDPOINT',
Expand Down Expand Up @@ -92,14 +92,15 @@
'ProcessGroupEntity': {'id': ['id'], 'name': ['status', 'name']},
'DocumentedTypeDTO': {'bundle': ['bundle', 'artifact'],
'name': ['type'],
'tag': ['tags']}, # This is Processor Types
'tag': ['tags']},
'ProcessorEntity': {'id': ['id'], 'name': ['status', 'name']},
'User': {'identity': ['identity'], 'id': ['identifier']},
'UserGroupEntity': {'identity': ['component', 'identity'], 'id': ['id']},
'UserGroup': {'identity': ['identity'], 'id': ['identifier']},
'UserEntity': {'identity': ['component', 'identity'], 'id': ['id']},
'TemplateEntity': {'id': ['id'], 'name': ['template', 'name']},
'ControllerServiceEntity': {'is': ['id'], 'name': ['component', 'name']}
'ControllerServiceEntity': {'id': ['id'], 'name': ['component', 'name']},
'ParameterContextEntity': {'id': ['id'], 'name': ['component', 'name']}
}


Expand Down
Loading

0 comments on commit aa5fade

Please sign in to comment.