You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by mc...@apache.org on 2016/04/21 23:30:31 UTC
[05/10] nifi git commit: NIFI-1554: - Introducing new REST endpoints
to align with the authorizable resources. - Additionally changes to support
the new endpoints. - Addressing comments in PR. - This closes #374.
http://git-wip-us.apache.org/repos/asf/nifi/blob/add29816/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/InputPortResource.java
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/InputPortResource.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/InputPortResource.java
index 568628e..1d0629f 100644
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/InputPortResource.java
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/InputPortResource.java
@@ -16,26 +16,21 @@
*/
package org.apache.nifi.web.api;
+import com.wordnik.swagger.annotations.Api;
import com.wordnik.swagger.annotations.ApiOperation;
import com.wordnik.swagger.annotations.ApiParam;
import com.wordnik.swagger.annotations.ApiResponse;
import com.wordnik.swagger.annotations.ApiResponses;
import com.wordnik.swagger.annotations.Authorization;
import org.apache.commons.lang3.StringUtils;
-import org.apache.nifi.cluster.manager.NodeResponse;
-import org.apache.nifi.cluster.manager.exception.UnknownNodeException;
import org.apache.nifi.cluster.manager.impl.WebClusterManager;
-import org.apache.nifi.cluster.node.Node;
-import org.apache.nifi.cluster.protocol.NodeIdentifier;
import org.apache.nifi.util.NiFiProperties;
import org.apache.nifi.web.ConfigurationSnapshot;
import org.apache.nifi.web.NiFiServiceFacade;
import org.apache.nifi.web.Revision;
import org.apache.nifi.web.api.dto.PortDTO;
import org.apache.nifi.web.api.dto.RevisionDTO;
-import org.apache.nifi.web.api.dto.status.PortStatusDTO;
import org.apache.nifi.web.api.entity.InputPortEntity;
-import org.apache.nifi.web.api.entity.PortStatusEntity;
import org.apache.nifi.web.api.request.ClientIdParameter;
import org.apache.nifi.web.api.request.LongParameter;
@@ -55,14 +50,17 @@ import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.net.URI;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.Map;
import java.util.Set;
/**
* RESTful endpoint for managing an Input Port.
*/
-@Path("input-ports")
+@Path("/input-ports")
+@Api(
+ value = "/input-ports",
+ description = "Endpoint for managing an Input Port."
+)
public class InputPortResource extends ApplicationResource {
private NiFiServiceFacade serviceFacade;
@@ -154,106 +152,6 @@ public class InputPortResource extends ApplicationResource {
}
/**
- * Retrieves the specified input port status.
- *
- * @param clientId Optional client id. If the client id is not specified, a new one will be generated. This value (whether specified or generated) is included in the response.
- * @param id The id of the processor history to retrieve.
- * @return A portStatusEntity.
- */
- @GET
- @Consumes(MediaType.WILDCARD)
- @Produces(MediaType.APPLICATION_JSON)
- @Path("/{id}/status")
- // TODO - @PreAuthorize("hasAnyRole('ROLE_MONITOR', 'ROLE_DFM', 'ROLE_ADMIN')")
- @ApiOperation(
- value = "Gets status for an input port",
- response = PortStatusEntity.class,
- authorizations = {
- @Authorization(value = "Read Only", type = "ROLE_MONITOR"),
- @Authorization(value = "Data Flow Manager", type = "ROLE_DFM"),
- @Authorization(value = "Administrator", type = "ROLE_ADMIN")
- }
- )
- @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 getInputPortStatus(
- @ApiParam(
- value = "If the client id is not specified, new one will be generated. This value (whether specified or generated) is included in the response.",
- required = false
- )
- @QueryParam(CLIENT_ID) @DefaultValue(StringUtils.EMPTY) ClientIdParameter clientId,
- @ApiParam(
- value = "Whether or not to include the breakdown per node. Optional, defaults to false",
- required = false
- )
- @QueryParam("nodewise") @DefaultValue(NODEWISE) Boolean nodewise,
- @ApiParam(
- value = "The id of the node where to get the status.",
- required = false
- )
- @QueryParam("clusterNodeId") String clusterNodeId,
- @ApiParam(
- value = "The input port id.",
- required = true
- )
- @PathParam("id") String id) {
-
- // ensure a valid request
- if (Boolean.TRUE.equals(nodewise) && clusterNodeId != null) {
- throw new IllegalArgumentException("Nodewise requests cannot be directed at a specific node.");
- }
-
- if (properties.isClusterManager()) {
- // determine where this request should be sent
- if (clusterNodeId == null) {
- final NodeResponse nodeResponse = clusterManager.applyRequest(HttpMethod.GET, getAbsolutePath(), getRequestParameters(true), getHeaders());
- final PortStatusEntity entity = (PortStatusEntity) nodeResponse.getUpdatedEntity();
-
- // ensure there is an updated entity (result of merging) and prune the response as necessary
- if (entity != null && !nodewise) {
- entity.getPortStatus().setNodeSnapshots(null);
- }
-
- return nodeResponse.getResponse();
- } else {
- // get the target node and ensure it exists
- final Node targetNode = clusterManager.getNode(clusterNodeId);
- if (targetNode == null) {
- throw new UnknownNodeException("The specified cluster node does not exist.");
- }
-
- final Set<NodeIdentifier> targetNodes = new HashSet<>();
- targetNodes.add(targetNode.getNodeId());
-
- // replicate the request to the specific node
- return clusterManager.applyRequest(HttpMethod.GET, getAbsolutePath(), getRequestParameters(true), getHeaders(), targetNodes).getResponse();
- }
- }
-
- // get the specified input port status
- final PortStatusDTO portStatus = serviceFacade.getInputPortStatus(id);
-
- // create the revision
- final RevisionDTO revision = new RevisionDTO();
- revision.setClientId(clientId.getClientId());
-
- // generate the response entity
- final PortStatusEntity entity = new PortStatusEntity();
- entity.setRevision(revision);
- entity.setPortStatus(portStatus);
-
- // generate the response
- return clusterContext(generateOkResponse(entity)).build();
- }
-
- /**
* Updates the specified input port.
*
* @param httpServletRequest request
http://git-wip-us.apache.org/repos/asf/nifi/blob/add29816/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/LabelResource.java
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/LabelResource.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/LabelResource.java
index 4cd60f7..411bad2 100644
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/LabelResource.java
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/LabelResource.java
@@ -16,6 +16,7 @@
*/
package org.apache.nifi.web.api;
+import com.wordnik.swagger.annotations.Api;
import com.wordnik.swagger.annotations.ApiOperation;
import com.wordnik.swagger.annotations.ApiParam;
import com.wordnik.swagger.annotations.ApiResponse;
@@ -57,7 +58,11 @@ import java.util.Set;
/**
* RESTful endpoint for managing a Label.
*/
-@Path("labels")
+@Path("/labels")
+@Api(
+ value = "/labels",
+ description = "Endpoint for managing a Label."
+)
public class LabelResource extends ApplicationResource {
private static final Logger logger = LoggerFactory.getLogger(LabelResource.class);
http://git-wip-us.apache.org/repos/asf/nifi/blob/add29816/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/OutputPortResource.java
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/OutputPortResource.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/OutputPortResource.java
index 0d55525..1335390 100644
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/OutputPortResource.java
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/OutputPortResource.java
@@ -16,26 +16,21 @@
*/
package org.apache.nifi.web.api;
+import com.wordnik.swagger.annotations.Api;
import com.wordnik.swagger.annotations.ApiOperation;
import com.wordnik.swagger.annotations.ApiParam;
import com.wordnik.swagger.annotations.ApiResponse;
import com.wordnik.swagger.annotations.ApiResponses;
import com.wordnik.swagger.annotations.Authorization;
import org.apache.commons.lang3.StringUtils;
-import org.apache.nifi.cluster.manager.NodeResponse;
-import org.apache.nifi.cluster.manager.exception.UnknownNodeException;
import org.apache.nifi.cluster.manager.impl.WebClusterManager;
-import org.apache.nifi.cluster.node.Node;
-import org.apache.nifi.cluster.protocol.NodeIdentifier;
import org.apache.nifi.util.NiFiProperties;
import org.apache.nifi.web.ConfigurationSnapshot;
import org.apache.nifi.web.NiFiServiceFacade;
import org.apache.nifi.web.Revision;
import org.apache.nifi.web.api.dto.PortDTO;
import org.apache.nifi.web.api.dto.RevisionDTO;
-import org.apache.nifi.web.api.dto.status.PortStatusDTO;
import org.apache.nifi.web.api.entity.OutputPortEntity;
-import org.apache.nifi.web.api.entity.PortStatusEntity;
import org.apache.nifi.web.api.request.ClientIdParameter;
import org.apache.nifi.web.api.request.LongParameter;
import org.slf4j.Logger;
@@ -57,14 +52,17 @@ import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.net.URI;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.Map;
import java.util.Set;
/**
* RESTful endpoint for managing an Output Port.
*/
-@Path("output-ports")
+@Path("/output-ports")
+@Api(
+ value = "/output-ports",
+ description = "Endpoint for managing an Output Port."
+)
public class OutputPortResource extends ApplicationResource {
private static final Logger logger = LoggerFactory.getLogger(OutputPortResource.class);
@@ -158,106 +156,6 @@ public class OutputPortResource extends ApplicationResource {
}
/**
- * Retrieves the specified output port status.
- *
- * @param clientId Optional client id. If the client id is not specified, a new one will be generated. This value (whether specified or generated) is included in the response.
- * @param id The id of the processor history to retrieve.
- * @return A portStatusEntity.
- */
- @GET
- @Consumes(MediaType.WILDCARD)
- @Produces(MediaType.APPLICATION_JSON)
- @Path("/{id}/status")
- // TODO - @PreAuthorize("hasAnyRole('ROLE_MONITOR', 'ROLE_DFM', 'ROLE_ADMIN')")
- @ApiOperation(
- value = "Gets status for an output port",
- response = PortStatusEntity.class,
- authorizations = {
- @Authorization(value = "Read Only", type = "ROLE_MONITOR"),
- @Authorization(value = "Data Flow Manager", type = "ROLE_DFM"),
- @Authorization(value = "Administrator", type = "ROLE_ADMIN")
- }
- )
- @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 getOutputPortStatus(
- @ApiParam(
- value = "If the client id is not specified, new one will be generated. This value (whether specified or generated) is included in the response.",
- required = false
- )
- @QueryParam(CLIENT_ID) @DefaultValue(StringUtils.EMPTY) ClientIdParameter clientId,
- @ApiParam(
- value = "Whether or not to include the breakdown per node. Optional, defaults to false",
- required = false
- )
- @QueryParam("nodewise") @DefaultValue(NODEWISE) Boolean nodewise,
- @ApiParam(
- value = "The id of the node where to get the status.",
- required = false
- )
- @QueryParam("clusterNodeId") String clusterNodeId,
- @ApiParam(
- value = "The output port id.",
- required = true
- )
- @PathParam("id") String id) {
-
- // ensure a valid request
- if (Boolean.TRUE.equals(nodewise) && clusterNodeId != null) {
- throw new IllegalArgumentException("Nodewise requests cannot be directed at a specific node.");
- }
-
- if (properties.isClusterManager()) {
- // determine where this request should be sent
- if (clusterNodeId == null) {
- final NodeResponse nodeResponse = clusterManager.applyRequest(HttpMethod.GET, getAbsolutePath(), getRequestParameters(true), getHeaders());
- final PortStatusEntity entity = (PortStatusEntity) nodeResponse.getUpdatedEntity();
-
- // ensure there is an updated entity (result of merging) and prune the response as necessary
- if (entity != null && !nodewise) {
- entity.getPortStatus().setNodeSnapshots(null);
- }
-
- return nodeResponse.getResponse();
- } else {
- // get the target node and ensure it exists
- final Node targetNode = clusterManager.getNode(clusterNodeId);
- if (targetNode == null) {
- throw new UnknownNodeException("The specified cluster node does not exist.");
- }
-
- final Set<NodeIdentifier> targetNodes = new HashSet<>();
- targetNodes.add(targetNode.getNodeId());
-
- // replicate the request to the specific node
- return clusterManager.applyRequest(HttpMethod.GET, getAbsolutePath(), getRequestParameters(true), getHeaders(), targetNodes).getResponse();
- }
- }
-
- // get the specified output port status
- final PortStatusDTO portStatus = serviceFacade.getOutputPortStatus(id);
-
- // create the revision
- final RevisionDTO revision = new RevisionDTO();
- revision.setClientId(clientId.getClientId());
-
- // generate the response entity
- final PortStatusEntity entity = new PortStatusEntity();
- entity.setRevision(revision);
- entity.setPortStatus(portStatus);
-
- // generate the response
- return clusterContext(generateOkResponse(entity)).build();
- }
-
- /**
* Updates the specified output port.
*
* @param httpServletRequest request