📜  Apache NiFi-API(1)

📅  最后修改于: 2023-12-03 14:39:16.667000             🧑  作者: Mango

Apache NiFi-API

Apache NiFi is an open-source dataflow automation tool that helps to automate the flow of data between systems. It provides a web-based interface for users to design and manage data flows, and the API interface enables developers to interact with NiFi programmatically.

In this article, we will explore the NiFi API, covering the following topics:

  • API basics
  • API authentication
  • Performing CRUD operations with the NiFi API
  • Listing and retrieving process group and component details
API basics

The NiFi API leverages the RESTful principles for creating, updating, and deleting resources in NiFi. The API supports JSON and XML data formats to send and receive data. Users can interact with the NiFi API using a command-line application, a web browser, or using the NiFi API client libraries available for multiple programming languages such as Java, Python, and Ruby.

The NiFi API organizes resources into resource groups and endpoints. The resource groups represent the high-level functional areas of NiFi, while the endpoints represent the specific operations that can be performed on the resources.

API authentication

Authentication is necessary to access the resources using the NiFi API. The NiFi API supports different authentication mechanisms such as client certificate authentication, username/password authentication, and anonymous access. The authentication mechanism can be set up by configuring the NiFi security settings.

Client certificate authentication

Client certificate authentication is the most secure method to access the NiFi API. In this method, the client identifies itself to the server using a certificate signed by a trusted Certificate Authority (CA). The steps for configuring client certificate authentication are:

  1. Generate a client certificate-signing request (CSR)
  2. Send the CSR to the CA
  3. Receive the signed certificate from the CA
  4. Import the signed client certificate and private key into the client's truststore
Username/password authentication

Username/password authentication is a basic method for accessing the NiFi API. In this method, the client sends the username and password as part of the authentication request. The steps for configuring username/password authentication are:

  1. Enable username/password authentication in the NiFi security settings
  2. Create a user account with a password
  3. Use the created username and password to access the NiFi API
Anonymous access

Anonymous access allows access to the NiFi API without any authentication. This method is not recommended for production environments. To enable anonymous access:

  1. Enable anonymous access in the NiFi security settings
  2. Configure the access policy for the resources to allow anonymous access
Performing CRUD operations with the NiFi API

The NiFi API supports CRUD (Create, Read, Update, Delete) operations for managing the resources. The following are the commonly used endpoints for CRUD operations:

Create a resource

To create a resource, use the HTTP POST method and specify the resource endpoint. The body of the request contains the resource information in JSON or XML format.

For example, to create a new processor in the root process group, use the following endpoint:

POST /api/process-groups/root/processors

The body of the request specifies the details of the processor to be created:

{
  "config": {
    "properties": {
      "property1": "value1",
      "property2": "value2"
    }
  },
  "type": "org.apache.nifi.processors.standard.LogAttribute"
}
Read a resource

To retrieve the details of a resource, use the HTTP GET method and specify the resource endpoint.

For example, to retrieve the details of a processor with the ID of "1234", use the following endpoint:

GET /api/processors/1234
Update a resource

To update the details of a resource, use the HTTP PUT method and specify the resource endpoint. The body of the request contains the updated resource details in JSON or XML format.

For example, to update the properties of a processor with the ID of "1234", use the following endpoint:

PUT /api/processors/1234

The body of the request specifies the updated properties of the processor:

{
  "revision": {
    "version": 2
  },
  "id": "1234",
  "config": {
    "properties": {
      "property1": "updated_value1",
      "property2": "updated_value2"
    }
  },
  "component": {
    "id": "1234",
    "name": "my_updated_processor",
    "type": "org.apache.nifi.processors.standard.LogAttribute"
  }
}
Delete a resource

To delete a resource, use the HTTP DELETE method and specify the resource endpoint.

For example, to delete a processor with the ID of "1234", use the following endpoint:

DELETE /api/processors/1234
Listing and retrieving process group and component details

The NiFi API provides endpoints to retrieve the details of process groups and components. The following are the commonly used endpoints for listing and retrieving process group and component details:

Listing process groups

To retrieve the list of root process groups, use the following endpoint:

GET /api/process-groups/root

To retrieve the list of child process groups within a process group, use the following endpoint:

GET /api/process-groups/{process-group-id}/process-groups
Retrieving process group details

To retrieve the details of a process group, use the following endpoint:

GET /api/process-groups/{process-group-id}
Listing components

To retrieve the list of components within a process group, use the following endpoint:

GET /api/process-groups/{process-group-id}/components
Retrieving component details

To retrieve the details of a component, use the following endpoint:

GET /api/{component-type}/{component-id}

For example, to retrieve the details of a processor with the ID of "1234", use the following endpoint:

GET /api/processors/1234
Conclusion

The NiFi API provides a powerful mechanism for interacting with NiFi programmatically. In this article, we covered the basics of the NiFi API, including authentication, CRUD operations, and listing and retrieving process group and component details. The NiFi API documentation provides the complete list of endpoints and detailed documentation on the usage of each endpoint.