Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example for ProcessGroupsApi.upload_progress_group()? #377

Open
snowch opened this issue Nov 12, 2024 · 1 comment
Open

Example for ProcessGroupsApi.upload_progress_group()? #377

snowch opened this issue Nov 12, 2024 · 1 comment

Comments

@snowch
Copy link

snowch commented Nov 12, 2024

  • Nipyapi version: 0.21.0
  • NiFi version: 2.0.0-M4
  • NiFi-Registry version: N/A
  • Python version:
  • Operating System:

Description

I'm unclear how to use ProcessGroupsApi.upload_progress_group(). I've tried a few ways but they all threw exceptions.

What I Did

def upload_top_level_flow(api_client, pg_name, file_data):
    pg_api = nipyapi.nifi.apis.process_groups_api.ProcessGroupsApi(api_client=api_client)
  
    print(f"Creating new process group: {pg_name}")
    my_pg = pg_api.upload_process_group(
        id=pg_name,
        group_name=pg_name,
        position_x=400.0,
        position_y=100.0,
        client_id='12345',
        file=file_data
    )

def main():
    # Suppress SSL warnings
    requests.packages.urllib3.disable_warnings()
    
    nifi_host = 'https://xxxxx:18443/nifi-api'
    username = 'admin'
    password = 'xxxx'

    api_client = setup_nifi_connection(nifi_host, username, password)

    print('\nattempt: 1')
    try:
        with open('/Users/chris.snow/Downloads/NiFi_Flow(3).json', 'rb') as file:
            upload_top_level_flow(api_client, 'MYPG', file)
    except Exception as e:
        print(e)

    print('\nattempt: 2')
    try:
        with open('/Users/chris.snow/Downloads/NiFi_Flow(3).json', 'rb') as file:
            upload_top_level_flow(api_client, 'MYPG', file.read())
    except Exception as e:
        print(str(e)[0:100])

    print('\nattempt: 3')
    try:
        upload_top_level_flow(api_client, 'MYPG', '/Users/chris.snow/Downloads/NiFi_Flow(3).json')
    except Exception as e:
        print(str(e)[0:100])

if __name__ == "__main__":
    main()

The response:

NiFi connection successfully set up with authentication.

attempt: 1
Creating new process group: MYPG
expected str, bytes or os.PathLike object, not BufferedReader

attempt: 2
Creating new process group: MYPG
[Errno 63] File name too long: b'{"flowContents":{"identifier":"e87ff5e2-4a7c-3725-a3ee-148beb2fbabc

attempt: 3
Creating new process group: MYPG
a bytes-like object is required, not 'float'

Urgency

Not blocking

@snowch
Copy link
Author

snowch commented Nov 12, 2024

My workaround:

import requests
requests.packages.urllib3.disable_warnings()

nifi_host = 'https://xxxx:18443/nifi-api'
username = 'admin'
password = 'xxxx'

api_client = setup_nifi_connection(nifi_host, username, password)

pg_name = "MYPG"
my_pg = create_top_level_flow(pg_name)

file_path = '/Users/chris.snow/Downloads/NiFi_Flow(3).json'

with open(file_path, 'rb') as f:
    file_data = f.read()

headers = {
    'Accept': 'application/json, text/plain, */*',
    'Authorization': api_client.default_headers['Authorization'],
}

url = f'{nifi_host}/process-groups/{my_pg.id}/process-groups/upload'

form_data = {
    'id': my_pg.id,
    'groupName': pg_name,
    'positionX': '644.5',
    'positionY': '-139.05001831054688',
    'clientId': 'xxxxx',
    'disconnectedNodeAcknowledged': 'false'
}

files = {
    'file': ('NiFi_Flow.json', file_data, 'application/json')
}

response = requests.post(url, headers=headers, files=files, data=form_data, verify=False)
print(response.status_code)
print(response.text)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant