mtien-apache commented on a change in pull request #4846:
URL: https://github.com/apache/nifi/pull/4846#discussion_r585892971
##########
File path:
nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/ProcessGroupResource.java
##########
@@ -4173,6 +4157,163 @@ private void sanitizeRegistryInfo(final
VersionedProcessGroup versionedProcessGr
}
}
+ /**
+ * Uploads the specified versioned flow definition and adds it to a new
process group.
+ *
+ * @param httpServletRequest request
+ * @param in The flow definition stream
+ * @return A processGroupEntity
+ * @throws IOException if there is an error during deserialization of the
InputStream
+ */
+ @POST
+ @Consumes(MediaType.MULTIPART_FORM_DATA)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Path("{id}/process-groups/upload")
+ @ApiOperation(
+ value = "Uploads a versioned flow definition and creates a process
group",
+ response = ProcessGroupEntity.class,
+ authorizations = {
+ @Authorization(value = "Write - /process-groups/{uuid}")
+ }
+ )
+ @ApiResponses(
+ value = {
+ @ApiResponse(code = 400, message = "NiFi was unable to
complete the request because it was invalid. The request should not be retried
without modification."),
+ @ApiResponse(code = 401, message = "Client could not be
authenticated."),
+ @ApiResponse(code = 403, message = "Client is not
authorized to make this request."),
+ @ApiResponse(code = 404, message = "The specified resource
could not be found."),
+ @ApiResponse(code = 409, message = "The request was valid
but NiFi was not in the appropriate state to process it. Retrying the same
request later may be successful.")
+ }
+ )
+ public Response uploadProcessGroup(
+ @Context final HttpServletRequest httpServletRequest,
+ @ApiParam(
+ value = "The process group id.",
+ required = true
+ )
+ @PathParam("id") final String groupId,
+ @ApiParam(
+ value = "The process group name.",
+ required = true
+ )
+ @FormDataParam("groupName") final String groupName,
+ @ApiParam(
+ value = "The process group X position.",
+ required = true
+ )
+ @FormDataParam("position-x") final Double positionX,
+ @ApiParam(
+ value = "The process group Y position.",
+ required = true
+ )
+ @FormDataParam("position-y") final Double positionY,
+ @ApiParam(
+ value = "The client id.",
+ required = true
+ )
+ @FormDataParam("clientId") final String clientId,
+ @ApiParam(
+ value = "Acknowledges that this node is disconnected to
allow for mutable requests to proceed.",
+ required = false
+ )
+ @FormDataParam(DISCONNECTED_NODE_ACKNOWLEDGED)
@DefaultValue("false") final Boolean disconnectedNodeAcknowledged,
+ @FormDataParam("file") final InputStream in) throws IOException {
+
+ // ensure the group name is specified
+ if (StringUtils.isBlank(groupName)) {
+ throw new IllegalArgumentException("The process group name is
required.");
+ }
+
+ if (StringUtils.isBlank(groupId)) {
+ throw new IllegalArgumentException("The parent process group id is
required");
+ }
+
+ if (positionX == null) {
+ throw new IllegalArgumentException("The x coordinate of the
proposed position must be specified.");
+ }
+
+ if (positionY == null) {
+ throw new IllegalArgumentException("The y coordinate of the
proposed position must be specified.");
+ }
+
+ if (StringUtils.isBlank(clientId)) {
+ throw new IllegalArgumentException("The client id must be
specified");
+ }
+
+ // deserialize InputStream to a VersionedFlowSnapshot
+ VersionedFlowSnapshot deserializedSnapshot;
+
+ try {
+ deserializedSnapshot = MAPPER.readValue(in,
VersionedFlowSnapshot.class);
+ } catch (IOException e) {
+ logger.warn("Deserialization of uploaded JSON failed", e);
+ throw new IllegalArgumentException("Deserialization of uploaded
JSON failed", e);
+ }
+
+ // create a PositionDTO
+ final PositionDTO positionDTO = new PositionDTO();
+ positionDTO.setX(positionX);
+ positionDTO.setY(positionY);
+
+ // create a new ProcessGroupEntity
+ final ProcessGroupEntity newProcessGroupEntity =
createProcessGroupEntity(groupId, groupName, positionDTO, deserializedSnapshot);
+
+ // replicate the request or call serviceFacade.updateProcessGroup
+ if (isReplicateRequest()) {
+ return replicate(HttpMethod.POST, newProcessGroupEntity);
Review comment:
@markap14 Thanks for reviewing and catching this. I just pushed a commit
that added a second endpoint to handle a cluster replicate request. Can you
review again? Thanks!
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]