Skip to content

Commit 3010452

Browse files
authored
Update NiPyAPI to be roughly forward compatible with NiFi-2.x line. (#368)
* Instruct pyup to ignore pytest in requirements txt * instruct pytest to not report insecure http requests to localhost for docker testing * Templates are deprecated in nifi-2x, remove from tests for newer versions * add function to check registry version using newer aboutapi() call * update utils.check_version to ignore any non-semver elements of a version string and use newer registry version api call if available * Update registry client creation to handle nifi-2x structure * Update Testing to treat NiFI-2.x as regression target * Deprecate very old nifi-1x versions from regression testing * Fix get processor test to use a processor available in all nifi versions, GenerateFlowfile * Update readme about NiFi2.x support. * Switch 'latest' dockerfile to use 'latest' nifi tags.
1 parent f17ed60 commit 3010452

File tree

15 files changed

+121
-95
lines changed

15 files changed

+121
-95
lines changed

README.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,12 @@ Background and Documentation
9696
NiFi Version Support
9797
--------------------
9898

99-
| Currently we are testing against NiFi versions 1.1.2 - 1.27.0, and NiFi-Registry versions 0.1.0 - 1.27.0.
99+
| Currently we are testing against NiFi versions 1.9.2 - 1.27.0, and NiFi-Registry versions 0.3.0 - 1.27.0.
100+
101+
| We have also tested against the latest 2.0.0-M4 release candidates using the 1.x SDK and have found that basic functionality works as expected.
102+
| Apache NiFi offers no compatibility guarantees between major versions, and while many functions may work the same, you should test carefully for your specific use case.
103+
| In future we will create a specific branch of NiPyAPI for NiFi 2.x SDKs, and maintain separate NiFi 1.x and NiFi 2.x clients.
104+
100105
| If you find a version compatibility problem please raise an `issue <https://github.com/Chaffelson/nipyapi/issues>`_
101106
102107
Python Support

nipyapi/canvas.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -402,10 +402,11 @@ def delete_process_group(process_group, force=False, refresh=True):
402402
delete_controller(x, True)
403403
removed_controllers_id.append(x.component.id)
404404

405-
# Remove templates
406-
for template in nipyapi.templates.list_all_templates(native=False):
407-
if target.id == template.template.group_id:
408-
nipyapi.templates.delete_template(template.id)
405+
# Templates are not supported in NiFi 2.x
406+
if nipyapi.utils.check_version('2', service='nifi') < 0:
407+
for template in nipyapi.templates.list_all_templates(native=False):
408+
if target.id == template.template.group_id:
409+
nipyapi.templates.delete_template(template.id)
409410
# have to refresh revision after changes
410411
target = nipyapi.nifi.ProcessGroupsApi().get_process_group(pg_id)
411412
return nipyapi.nifi.ProcessGroupsApi().remove_process_group(

nipyapi/system.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,13 @@ def get_nifi_version_info():
5858
"""
5959
diags = get_system_diagnostics()
6060
return diags.system_diagnostics.aggregate_snapshot.version_info
61+
62+
63+
def get_registry_version_info():
64+
"""
65+
Returns the version information of the connected NiFi Registry instance
66+
67+
Returns (VersionInfoDTO):
68+
"""
69+
details = nipyapi.registry.AboutApi().get_version()
70+
return details.registry_about_version

nipyapi/utils.py

Lines changed: 27 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
from __future__ import absolute_import, unicode_literals
99
import logging
1010
import json
11-
import re
1211
import io
1312
import time
1413
from copy import copy
@@ -479,17 +478,6 @@ def start_docker_containers(docker_containers, network_name='demo'):
479478
))
480479

481480

482-
def strip_snapshot(java_version):
483-
"""
484-
Strips the -SNAPSHOT suffix from a version string
485-
486-
Args:
487-
java_version (str): the version string
488-
"""
489-
assert isinstance(java_version, six.string_types)
490-
return re.sub("-SNAPSHOT", "", java_version)
491-
492-
493481
def check_version(base, comparator=None, service='nifi',
494482
default_version='0.2.0'):
495483
"""
@@ -511,36 +499,43 @@ def check_version(base, comparator=None, service='nifi',
511499
Returns (int): -1/0/1 if base is lower/equal/newer than comparator
512500
513501
"""
502+
503+
def strip_version_string(version_string):
504+
# Reduces the string to only the major.minor.patch version
505+
return '.'.join(version_string.split('-')[0].split('.')[:3])
506+
514507
assert isinstance(base, six.string_types)
515508
assert comparator is None or isinstance(comparator, six.string_types)
516509
assert service in ['nifi', 'registry']
517-
ver_a = version.parse(base)
510+
ver_a = version.parse(strip_version_string(base))
518511
if comparator:
519-
# if b is set, we compare the passed versions
520-
comparator = strip_snapshot(comparator)
521-
ver_b = version.parse(comparator)
512+
ver_b = version.parse(strip_version_string(comparator))
522513
elif service == 'registry':
523514
try:
524-
config = nipyapi.config.registry_config
525-
if config.api_client is None:
526-
config.api_client = nipyapi.registry.ApiClient()
527-
reg_swagger_def = config.api_client.call_api(
528-
resource_path='/swagger/swagger.json',
529-
method='GET', _preload_content=False,
530-
auth_settings=['tokenAuth', 'Authorization']
531-
)
532-
reg_json = load(reg_swagger_def[0].data)
533-
ver_b = version.parse(reg_json['info']['version'])
515+
reg_ver = nipyapi.system.get_registry_version_info()
516+
ver_b = version.parse(strip_version_string(reg_ver))
534517
except nipyapi.registry.rest.ApiException:
535518
log.warning(
536-
"Unable to get registry swagger.json, assuming version %s",
537-
default_version)
538-
ver_b = version.parse(default_version)
519+
"Unable to get registry version, trying swagger.json")
520+
try:
521+
config = nipyapi.config.registry_config
522+
if config.api_client is None:
523+
config.api_client = nipyapi.registry.ApiClient()
524+
reg_swagger_def = config.api_client.call_api(
525+
resource_path='/swagger/swagger.json',
526+
method='GET', _preload_content=False,
527+
auth_settings=['tokenAuth', 'Authorization']
528+
)
529+
reg_json = load(reg_swagger_def[0].data)
530+
ver_b = version.parse(reg_json['info']['version'])
531+
except nipyapi.registry.rest.ApiException:
532+
log.warning(
533+
"Can't get registry swagger.json, assuming version %s",
534+
default_version)
535+
ver_b = version.parse(default_version)
539536
else:
540-
# Working with NiFi
541537
ver_b = version.parse(
542-
strip_snapshot(
543-
# This call currently only supports NiFi
538+
strip_version_string(
544539
nipyapi.system.get_nifi_version_info().ni_fi_version
545540
)
546541
)

nipyapi/versioning.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
log = logging.getLogger(__name__)
2828

2929

30-
def create_registry_client(name, uri, description):
30+
def create_registry_client(name, uri, description, reg_type=None):
3131
"""
3232
Creates a Registry Client in the NiFi Controller Services
3333
@@ -42,14 +42,28 @@ def create_registry_client(name, uri, description):
4242
assert isinstance(uri, six.string_types) and uri is not False
4343
assert isinstance(name, six.string_types) and name is not False
4444
assert isinstance(description, six.string_types)
45+
if nipyapi.utils.check_version('2', service='nifi') > 0:
46+
component = {
47+
'uri': uri,
48+
'name': name,
49+
'description': description
50+
}
51+
else:
52+
component = {
53+
'name': name,
54+
'description': description,
55+
'type': (
56+
reg_type or
57+
'org.apache.nifi.registry.flow.NifiRegistryFlowRegistryClient'),
58+
'properties': {
59+
'url': uri
60+
}
61+
}
62+
4563
with nipyapi.utils.rest_exceptions():
4664
return nipyapi.nifi.ControllerApi().create_flow_registry_client(
4765
body={
48-
'component': {
49-
'uri': uri,
50-
'name': name,
51-
'description': description
52-
},
66+
'component': component,
5367
'revision': {
5468
'version': 0
5569
}

requirements_dev.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ tox>=3.28.0
1414
flake8>=3.6.0
1515
coverage>=4.4.1
1616
coveralls>=1.2.0
17-
pytest # handled in setup.py
17+
pytest # pyup: ignore
1818
nose>=1.3.7
1919
pluggy>=0.3.1
2020
pylint>=1.7.4

resources/docker/latest/docker-compose.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
services:
22
nifi:
3-
image: apache/nifi:1.27.0
3+
image: apache/nifi:latest
44
container_name: nifi
55
hostname: nifi
66
ports:
@@ -9,7 +9,7 @@ services:
99
- SINGLE_USER_CREDENTIALS_USERNAME=nobel
1010
- SINGLE_USER_CREDENTIALS_PASSWORD=supersecret1!
1111
registry:
12-
image: apache/nifi-registry:1.27.0
12+
image: apache/nifi-registry:latest
1313
container_name: registry
1414
hostname: registry
1515
ports:

resources/docker/secure/docker-compose.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
services:
22
secure-nifi:
3-
image: apache/nifi:1.27.0
3+
image: apache/nifi:latest
44
container_name: secure-nifi
55
hostname: secure-nifi
66
ports:
@@ -25,7 +25,7 @@ services:
2525
- LDAP_URL=ldap://ldap.forumsys.com:389
2626
- NIFI_WEB_PROXY_HOST=localhost:9443,localhost:8443
2727
secure-registry:
28-
image: apache/nifi-registry:1.27.0
28+
image: apache/nifi-registry:latest
2929
container_name: secure-registry
3030
hostname: secure-registry
3131
ports:

resources/docker/tox-full/docker-compose.yml

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,29 @@
11
services:
2-
nifi-112:
3-
image: chaffelson/nifi:1.1.2
4-
container_name: nifi-112
5-
hostname: nifi-112
6-
ports:
7-
- "10112:8080"
8-
nifi-120:
9-
image: apache/nifi:1.2.0
10-
container_name: nifi-120
11-
hostname: nifi-120
12-
ports:
13-
- "10120:8080"
14-
nifi-180:
15-
image: apache/nifi:1.8.0
16-
container_name: nifi-180
17-
hostname: nifi-180
18-
ports:
19-
- "10180:8080"
202
nifi-192:
213
image: apache/nifi:1.9.2
224
container_name: nifi-192
235
hostname: nifi-192
246
ports:
257
- "10192:8080"
26-
nifi:
8+
nifi-127:
279
image: apache/nifi:1.27.0
10+
container_name: nifi-127
11+
hostname: nifi-127
12+
ports:
13+
- "10127:10127"
14+
environment:
15+
- SINGLE_USER_CREDENTIALS_USERNAME=nobel
16+
- SINGLE_USER_CREDENTIALS_PASSWORD=supersecret1!
17+
- NIFI_WEB_HTTPS_PORT=10127
18+
nifi:
19+
image: apache/nifi:2.0.0-M4
2820
container_name: nifi
2921
hostname: nifi
3022
ports:
3123
- "8443:8443"
3224
environment:
3325
- SINGLE_USER_CREDENTIALS_USERNAME=nobel
3426
- SINGLE_USER_CREDENTIALS_PASSWORD=supersecret1!
35-
registry-010:
36-
image: apache/nifi-registry:0.1.0
37-
container_name: registry-010
38-
hostname: registry-010
39-
ports:
40-
- "18010:18010"
41-
environment:
42-
- NIFI_REGISTRY_WEB_HTTP_PORT=18010
4327
registry-030:
4428
image: apache/nifi-registry:0.3.0
4529
container_name: registry-030
@@ -48,8 +32,16 @@ services:
4832
- "18030:18030"
4933
environment:
5034
- NIFI_REGISTRY_WEB_HTTP_PORT=18030
51-
registry:
35+
registry-127:
5236
image: apache/nifi-registry:1.27.0
37+
container_name: registry-127
38+
hostname: registry-127
39+
ports:
40+
- "18127:18127"
41+
environment:
42+
- NIFI_REGISTRY_WEB_HTTP_PORT=18127
43+
registry:
44+
image: apache/nifi-registry:2.0.0-M4
5345
container_name: registry
5446
hostname: registry
5547
ports:

resources/docker/tox-full/readme.md

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,6 @@ Stop a cluster:
1414

1515
- ```docker-compose stop```
1616

17-
## Environment Details
18-
19-
- Apache NiFi 1.2.0 available on port 10120
20-
- Apache NiFi 1.4.0 available on port 10140
21-
- Apache NiFi 1.5.0 available on port 8080
22-
- Apache NiFi-Registry 0.1.0 available on port 18080
2317

2418
### Notes
25-
Where possible the latest version will be available on the defaul port, with older versions on identifiable ports for back testing
19+
Where possible the latest version will be available on the default port, with older versions on identifiable ports for back testing

0 commit comments

Comments
 (0)