You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by ma...@apache.org on 2016/04/15 22:04:03 UTC
[11/22] nifi git commit: NIFI-1551: - Removing the AuthorityProvider.
- Refactoring REST API in preparation for introduction of the Authorizer. -
Updating UI accordingly. - Removing unneeded properties from nifi.properties.
- Addressing comments from PR.
http://git-wip-us.apache.org/repos/asf/nifi/blob/153f63ef/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 400c92a..4cd60f7 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,59 +16,48 @@
*/
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 java.net.URI;
-import java.net.URISyntaxException;
-import java.util.HashMap;
-import java.util.LinkedHashMap;
-import java.util.Map;
-import java.util.Set;
-import java.util.UUID;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.nifi.cluster.manager.impl.WebClusterManager;
+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.LabelDTO;
+import org.apache.nifi.web.api.dto.RevisionDTO;
+import org.apache.nifi.web.api.entity.LabelEntity;
+import org.apache.nifi.web.api.request.ClientIdParameter;
+import org.apache.nifi.web.api.request.LongParameter;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.DefaultValue;
-import javax.ws.rs.FormParam;
import javax.ws.rs.GET;
import javax.ws.rs.HttpMethod;
-import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
-import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Response;
-import org.apache.nifi.cluster.manager.impl.WebClusterManager;
-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.LabelDTO;
-import org.apache.nifi.web.api.dto.PositionDTO;
-import org.apache.nifi.web.api.dto.RevisionDTO;
-import org.apache.nifi.web.api.entity.LabelEntity;
-import org.apache.nifi.web.api.entity.LabelsEntity;
-import org.apache.nifi.web.api.request.ClientIdParameter;
-import org.apache.nifi.web.api.request.DoubleParameter;
-import org.apache.nifi.web.api.request.LongParameter;
-import org.apache.commons.lang3.StringUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.security.access.prepost.PreAuthorize;
+import java.net.URI;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
/**
* RESTful endpoint for managing a Label.
*/
-@Api(hidden = true)
+@Path("labels")
public class LabelResource extends ApplicationResource {
private static final Logger logger = LoggerFactory.getLogger(LabelResource.class);
@@ -76,7 +65,6 @@ public class LabelResource extends ApplicationResource {
private NiFiServiceFacade serviceFacade;
private WebClusterManager clusterManager;
private NiFiProperties properties;
- private String groupId;
/**
* Populates the uri for the specified labels.
@@ -94,229 +82,13 @@ public class LabelResource extends ApplicationResource {
/**
* Populates the uri for the specified label.
*/
- private LabelDTO populateRemainingLabelContent(LabelDTO label) {
+ public LabelDTO populateRemainingLabelContent(LabelDTO label) {
// populate the label href
- label.setUri(generateResourceUri("controller", "process-groups", groupId, "labels", label.getId()));
+ label.setUri(generateResourceUri("labels", label.getId()));
return label;
}
/**
- * Retrieves all the of labels in this NiFi.
- *
- * @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.
- * @return A labelsEntity.
- */
- @GET
- @Consumes(MediaType.WILDCARD)
- @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
- @Path("") // necessary due to bug in swagger
- @PreAuthorize("hasAnyRole('ROLE_MONITOR', 'ROLE_DFM', 'ROLE_ADMIN')")
- @ApiOperation(
- value = "Gets all labels",
- response = LabelsEntity.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 getLabels(
- @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) {
-
- // replicate if cluster manager
- if (properties.isClusterManager()) {
- return clusterManager.applyRequest(HttpMethod.GET, getAbsolutePath(), getRequestParameters(true), getHeaders()).getResponse();
- }
-
- // get all the labels
- final Set<LabelDTO> labels = populateRemainingLabelsContent(serviceFacade.getLabels(groupId));
-
- // create the revision
- final RevisionDTO revision = new RevisionDTO();
- revision.setClientId(clientId.getClientId());
-
- // create the response entity
- final LabelsEntity entity = new LabelsEntity();
- entity.setRevision(revision);
- entity.setLabels(labels);
-
- // generate the response
- return clusterContext(generateOkResponse(entity)).build();
- }
-
- /**
- * Creates a new label.
- *
- * @param httpServletRequest request
- * @param version The revision is used to verify the client is working with the latest version of the flow.
- * @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 x The x coordinate for this funnels position.
- * @param y The y coordinate for this funnels position.
- * @param width The width of the label.
- * @param height The height of the label.
- * @param label The label's value.
- * @return A labelEntity.
- */
- @POST
- @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
- @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
- @Path("") // necessary due to bug in swagger
- @PreAuthorize("hasRole('ROLE_DFM')")
- public Response createLabel(
- @Context HttpServletRequest httpServletRequest,
- @FormParam(VERSION) LongParameter version,
- @FormParam(CLIENT_ID) @DefaultValue(StringUtils.EMPTY) ClientIdParameter clientId,
- @FormParam("x") DoubleParameter x, @FormParam("y") DoubleParameter y,
- @FormParam("width") DoubleParameter width, @FormParam("height") DoubleParameter height,
- @FormParam("label") String label) {
-
- // ensure the position has been specified
- if (x == null || y == null) {
- throw new IllegalArgumentException("The position (x, y) must be specified");
- }
-
- // ensure the size has been specified
- if (width == null || height == null) {
- throw new IllegalArgumentException("The size (width, height) must be specified.");
- }
-
- // create the label DTO
- final LabelDTO labelDTO = new LabelDTO();
- labelDTO.setPosition(new PositionDTO(x.getDouble(), y.getDouble()));
- labelDTO.setWidth(width.getDouble());
- labelDTO.setHeight(height.getDouble());
- labelDTO.setLabel(label);
-
- // create the revision
- final RevisionDTO revision = new RevisionDTO();
- revision.setClientId(clientId.getClientId());
-
- if (version != null) {
- revision.setVersion(version.getLong());
- }
-
- // create the label entity
- final LabelEntity labelEntity = new LabelEntity();
- labelEntity.setRevision(revision);
- labelEntity.setLabel(labelDTO);
-
- // create the label
- return createLabel(httpServletRequest, labelEntity);
- }
-
- /**
- * Creates a new Label.
- *
- * @param httpServletRequest request
- * @param labelEntity A labelEntity.
- * @return A labelEntity.
- */
- @POST
- @Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
- @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
- @Path("") // necessary due to bug in swagger
- @PreAuthorize("hasRole('ROLE_DFM')")
- @ApiOperation(
- value = "Creates a label",
- response = LabelEntity.class,
- authorizations = {
- @Authorization(value = "Data Flow Manager", type = "ROLE_DFM")
- }
- )
- @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 createLabel(
- @Context HttpServletRequest httpServletRequest,
- @ApiParam(
- value = "The label configuration details.",
- required = true
- ) LabelEntity labelEntity) {
-
- if (labelEntity == null || labelEntity.getLabel() == null) {
- throw new IllegalArgumentException("Label details must be specified.");
- }
-
- if (labelEntity.getRevision() == null) {
- throw new IllegalArgumentException("Revision must be specified.");
- }
-
- if (labelEntity.getLabel().getId() != null) {
- throw new IllegalArgumentException("Label ID cannot be specified.");
- }
-
- // if cluster manager, convert POST to PUT (to maintain same ID across nodes) and replicate
- if (properties.isClusterManager()) {
-
- // create ID for resource
- final String id = UUID.randomUUID().toString();
-
- // set ID for resource
- labelEntity.getLabel().setId(id);
-
- // convert POST request to PUT request to force entity ID to be the same across nodes
- URI putUri = null;
- try {
- putUri = new URI(getAbsolutePath().toString() + "/" + id);
- } catch (final URISyntaxException e) {
- throw new WebApplicationException(e);
- }
-
- // change content type to JSON for serializing entity
- final Map<String, String> headersToOverride = new HashMap<>();
- headersToOverride.put("content-type", MediaType.APPLICATION_JSON);
-
- // replicate put request
- return (Response) clusterManager.applyRequest(HttpMethod.PUT, putUri, updateClientId(labelEntity), getHeaders(headersToOverride)).getResponse();
- }
-
- // handle expects request (usually from the cluster manager)
- final String expects = httpServletRequest.getHeader(WebClusterManager.NCM_EXPECTS_HTTP_HEADER);
- if (expects != null) {
- return generateContinueResponse().build();
- }
-
- // create the label and generate the json
- final RevisionDTO revision = labelEntity.getRevision();
- final ConfigurationSnapshot<LabelDTO> controllerResponse = serviceFacade.createLabel(
- new Revision(revision.getVersion(), revision.getClientId()), groupId, labelEntity.getLabel());
- final LabelDTO label = controllerResponse.getConfiguration();
- populateRemainingLabelContent(label);
-
- // get the updated revision
- final RevisionDTO updatedRevision = new RevisionDTO();
- updatedRevision.setClientId(revision.getClientId());
- updatedRevision.setVersion(controllerResponse.getVersion());
-
- // build the response entity
- final LabelEntity entity = new LabelEntity();
- entity.setRevision(updatedRevision);
- entity.setLabel(label);
-
- // build the response
- return clusterContext(generateCreatedResponse(URI.create(label.getUri()), entity)).build();
- }
-
- /**
* Retrieves the specified label.
*
* @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.
@@ -325,9 +97,9 @@ public class LabelResource extends ApplicationResource {
*/
@GET
@Consumes(MediaType.WILDCARD)
- @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
+ @Produces(MediaType.APPLICATION_JSON)
@Path("{id}")
- @PreAuthorize("hasAnyRole('ROLE_MONITOR', 'ROLE_DFM', 'ROLE_ADMIN')")
+ // TODO - @PreAuthorize("hasAnyRole('ROLE_MONITOR', 'ROLE_DFM', 'ROLE_ADMIN')")
@ApiOperation(
value = "Gets a label",
response = LabelEntity.class,
@@ -364,7 +136,7 @@ public class LabelResource extends ApplicationResource {
}
// get the label
- final LabelDTO label = serviceFacade.getLabel(groupId, id);
+ final LabelDTO label = serviceFacade.getLabel(id);
// create the revision
final RevisionDTO revision = new RevisionDTO();
@@ -382,104 +154,15 @@ public class LabelResource extends ApplicationResource {
* Updates the specified label.
*
* @param httpServletRequest request
- * @param version The revision is used to verify the client is working with the latest version of the flow.
- * @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 label to update.
- * @param x The x coordinate for this funnels position.
- * @param y The y coordinate for this funnels position.
- * @param width The width of the label.
- * @param height The height of the label.
- * @param label The label's value.
- * @param formParams Additionally, the label styles are specified in the form parameters. They are specified in a map-like fashion:
- * <br>
- * <ul>
- * <li>style[background-color]=#aaaaaa</li>
- * </ul>
- *
- * @return A labelEntity.
- */
- @PUT
- @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
- @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
- @Path("{id}")
- @PreAuthorize("hasRole('ROLE_DFM')")
- public Response updateLabel(
- @Context HttpServletRequest httpServletRequest,
- @FormParam(VERSION) LongParameter version,
- @FormParam(CLIENT_ID) @DefaultValue(StringUtils.EMPTY) ClientIdParameter clientId,
- @PathParam("id") String id, @FormParam("label") String label,
- @FormParam("x") DoubleParameter x, @FormParam("y") DoubleParameter y,
- @FormParam("width") DoubleParameter width, @FormParam("height") DoubleParameter height,
- MultivaluedMap<String, String> formParams) {
-
- final Map<String, String> labelStyle = new LinkedHashMap<>();
-
- // go through each parameter and look for processor properties
- for (String parameterName : formParams.keySet()) {
- if (StringUtils.isNotBlank(parameterName)) {
- // see if the parameter name starts with an expected parameter type...
- if (parameterName.startsWith("style")) {
- final int startIndex = StringUtils.indexOf(parameterName, "[");
- final int endIndex = StringUtils.lastIndexOf(parameterName, "]");
- if (startIndex != -1 && endIndex != -1) {
- final String styleName = StringUtils.substring(parameterName, startIndex + 1, endIndex);
- labelStyle.put(styleName, formParams.getFirst(parameterName));
- }
- }
- }
- }
-
- // create the label DTO
- final LabelDTO labelDTO = new LabelDTO();
- labelDTO.setId(id);
- labelDTO.setLabel(label);
-
- // only set the styles when appropriate
- if (!labelStyle.isEmpty()) {
- labelDTO.setStyle(labelStyle);
- }
-
- // require both coordinates to be specified
- if (x != null && y != null) {
- labelDTO.setPosition(new PositionDTO(x.getDouble(), y.getDouble()));
- }
-
- // require both width and height to be specified
- if (width != null && height != null) {
- labelDTO.setWidth(width.getDouble());
- labelDTO.setHeight(height.getDouble());
- }
-
- // create the revision
- final RevisionDTO revision = new RevisionDTO();
- revision.setClientId(clientId.getClientId());
-
- if (version != null) {
- revision.setVersion(version.getLong());
- }
-
- // create the label entity
- final LabelEntity labelEntity = new LabelEntity();
- labelEntity.setRevision(revision);
- labelEntity.setLabel(labelDTO);
-
- // update the label
- return updateLabel(httpServletRequest, id, labelEntity);
- }
-
- /**
- * Updates the specified label.
- *
- * @param httpServletRequest request
* @param id The id of the label to update.
* @param labelEntity A labelEntity.
* @return A labelEntity.
*/
@PUT
- @Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
- @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
@Path("{id}")
- @PreAuthorize("hasRole('ROLE_DFM')")
+ // TODO - @PreAuthorize("hasRole('ROLE_DFM')")
@ApiOperation(
value = "Updates a label",
response = LabelEntity.class,
@@ -542,7 +225,7 @@ public class LabelResource extends ApplicationResource {
// update the label
final RevisionDTO revision = labelEntity.getRevision();
final ConfigurationSnapshot<LabelDTO> controllerResponse = serviceFacade.updateLabel(
- new Revision(revision.getVersion(), revision.getClientId()), groupId, requestLabelDTO);
+ new Revision(revision.getVersion(), revision.getClientId()), requestLabelDTO);
// get the results
final LabelDTO responseLabelDTO = controllerResponse.getConfiguration();
@@ -576,9 +259,9 @@ public class LabelResource extends ApplicationResource {
*/
@DELETE
@Consumes(MediaType.WILDCARD)
- @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
+ @Produces(MediaType.APPLICATION_JSON)
@Path("{id}")
- @PreAuthorize("hasRole('ROLE_DFM')")
+ // TODO - @PreAuthorize("hasRole('ROLE_DFM')")
@ApiOperation(
value = "Deletes a label",
response = LabelEntity.class,
@@ -631,7 +314,7 @@ public class LabelResource extends ApplicationResource {
}
// delete the specified label
- final ConfigurationSnapshot<Void> controllerResponse = serviceFacade.deleteLabel(new Revision(clientVersion, clientId.getClientId()), groupId, id);
+ final ConfigurationSnapshot<Void> controllerResponse = serviceFacade.deleteLabel(new Revision(clientVersion, clientId.getClientId()), id);
// get the updated revision
final RevisionDTO revision = new RevisionDTO();
@@ -650,10 +333,6 @@ public class LabelResource extends ApplicationResource {
this.serviceFacade = serviceFacade;
}
- public void setGroupId(String groupId) {
- this.groupId = groupId;
- }
-
public void setClusterManager(WebClusterManager clusterManager) {
this.clusterManager = clusterManager;
}
http://git-wip-us.apache.org/repos/asf/nifi/blob/153f63ef/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/NodeResource.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/NodeResource.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/NodeResource.java
index d3eb77a..6d19462 100644
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/NodeResource.java
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/NodeResource.java
@@ -30,7 +30,6 @@ import org.apache.nifi.web.api.dto.NodeDTO;
import org.apache.nifi.web.api.dto.RevisionDTO;
import org.apache.nifi.web.api.entity.NodeEntity;
import org.apache.nifi.web.api.request.ClientIdParameter;
-import org.springframework.security.access.prepost.PreAuthorize;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
@@ -65,7 +64,7 @@ public class NodeResource extends ApplicationResource {
@Consumes(MediaType.WILDCARD)
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
@Path("/{id}")
- @PreAuthorize("hasAnyRole('ROLE_MONITOR', 'ROLE_DFM', 'ROLE_ADMIN')")
+ // TODO - @PreAuthorize("hasAnyRole('ROLE_MONITOR', 'ROLE_DFM', 'ROLE_ADMIN')")
@ApiOperation(
value = "Gets a node in the cluster",
response = NodeEntity.class,
@@ -132,7 +131,7 @@ public class NodeResource extends ApplicationResource {
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
@Path("/{id}")
- @PreAuthorize("hasAnyRole('ROLE_ADMIN')")
+ // TODO - @PreAuthorize("hasAnyRole('ROLE_ADMIN')")
public Response updateNode(@QueryParam(CLIENT_ID) @DefaultValue(StringUtils.EMPTY) ClientIdParameter clientId,
@PathParam("id") String id,
@FormParam("status") String status,
@@ -168,7 +167,7 @@ public class NodeResource extends ApplicationResource {
@Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
@Path("/{id}")
- @PreAuthorize("hasAnyRole('ROLE_ADMIN')")
+ // TODO - @PreAuthorize("hasAnyRole('ROLE_ADMIN')")
@ApiOperation(
value = "Updates a node in the cluster",
response = NodeEntity.class,
@@ -244,7 +243,7 @@ public class NodeResource extends ApplicationResource {
@Consumes(MediaType.WILDCARD)
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
@Path("/{id}")
- @PreAuthorize("hasAnyRole('ROLE_ADMIN')")
+ // TODO - @PreAuthorize("hasAnyRole('ROLE_ADMIN')")
@ApiOperation(
value = "Removes a node from the cluster",
response = NodeEntity.class,
http://git-wip-us.apache.org/repos/asf/nifi/blob/153f63ef/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 e76fcf0..0d55525 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,38 +16,12 @@
*/
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 java.net.URI;
-import java.net.URISyntaxException;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-import java.util.UUID;
-import javax.servlet.http.HttpServletRequest;
-import javax.ws.rs.Consumes;
-import javax.ws.rs.DELETE;
-import javax.ws.rs.DefaultValue;
-import javax.ws.rs.FormParam;
-import javax.ws.rs.GET;
-import javax.ws.rs.HttpMethod;
-import javax.ws.rs.POST;
-import javax.ws.rs.PUT;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.Produces;
-import javax.ws.rs.QueryParam;
-import javax.ws.rs.WebApplicationException;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.MultivaluedMap;
-import javax.ws.rs.core.Response;
-
+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;
@@ -58,25 +32,39 @@ 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.PositionDTO;
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.OutputPortsEntity;
import org.apache.nifi.web.api.entity.PortStatusEntity;
import org.apache.nifi.web.api.request.ClientIdParameter;
-import org.apache.nifi.web.api.request.DoubleParameter;
-import org.apache.nifi.web.api.request.IntegerParameter;
import org.apache.nifi.web.api.request.LongParameter;
-import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.security.access.prepost.PreAuthorize;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.DefaultValue;
+import javax.ws.rs.GET;
+import javax.ws.rs.HttpMethod;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.Context;
+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.
*/
-@Api(hidden = true)
+@Path("output-ports")
public class OutputPortResource extends ApplicationResource {
private static final Logger logger = LoggerFactory.getLogger(OutputPortResource.class);
@@ -84,7 +72,6 @@ public class OutputPortResource extends ApplicationResource {
private NiFiServiceFacade serviceFacade;
private WebClusterManager clusterManager;
private NiFiProperties properties;
- private String groupId;
/**
* Populates the uri for the specified output ports.
@@ -102,220 +89,13 @@ public class OutputPortResource extends ApplicationResource {
/**
* Populates the uri for the specified output ports.
*/
- private PortDTO populateRemainingOutputPortContent(PortDTO outputPort) {
+ public PortDTO populateRemainingOutputPortContent(PortDTO outputPort) {
// populate the output port uri
- outputPort.setUri(generateResourceUri("controller", "process-groups", outputPort.getParentGroupId(), "output-ports", outputPort.getId()));
+ outputPort.setUri(generateResourceUri("output-ports", outputPort.getId()));
return outputPort;
}
/**
- * Retrieves all the of output ports in this NiFi.
- *
- * @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.
- * @return A outputPortsEntity.
- */
- @GET
- @Consumes(MediaType.WILDCARD)
- @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
- @Path("") // necessary due to bug in swagger
- @PreAuthorize("hasAnyRole('ROLE_MONITOR', 'ROLE_DFM', 'ROLE_ADMIN')")
- @ApiOperation(
- value = "Gets all output ports",
- response = OutputPortsEntity.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 getOutputPorts(
- @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) {
-
- // replicate if cluster manager
- if (properties.isClusterManager()) {
- return clusterManager.applyRequest(HttpMethod.GET, getAbsolutePath(), getRequestParameters(true), getHeaders()).getResponse();
- }
-
- // get all the output ports
- final Set<PortDTO> outputPorts = populateRemainingOutputPortsContent(serviceFacade.getOutputPorts(groupId));
-
- // create the revision
- final RevisionDTO revision = new RevisionDTO();
- revision.setClientId(clientId.getClientId());
-
- // create the response entity
- final OutputPortsEntity entity = new OutputPortsEntity();
- entity.setRevision(revision);
- entity.setOutputPorts(outputPorts);
-
- // generate the response
- return clusterContext(generateOkResponse(entity)).build();
- }
-
- /**
- * Creates a new output port.
- *
- * @param httpServletRequest request
- * @param version The revision is used to verify the client is working with the latest version of the flow.
- * @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 x The x coordinate for this funnels position.
- * @param y The y coordinate for this funnels position.
- * @param name The output ports name.
- * @return An outputPortEntity.
- */
- @POST
- @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
- @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
- @Path("") // necessary due to bug in swagger
- @PreAuthorize("hasRole('ROLE_DFM')")
- public Response createOutputPort(
- @Context HttpServletRequest httpServletRequest,
- @FormParam(VERSION) LongParameter version,
- @FormParam(CLIENT_ID) @DefaultValue(StringUtils.EMPTY) ClientIdParameter clientId,
- @FormParam("x") DoubleParameter x, @FormParam("y") DoubleParameter y,
- @FormParam("name") String name) {
-
- // ensure the position has been specified
- if (x == null || y == null) {
- throw new IllegalArgumentException("The position (x, y) must be specified");
- }
-
- // create the output port DTO
- final PortDTO outputPortDTO = new PortDTO();
- outputPortDTO.setPosition(new PositionDTO(x.getDouble(), y.getDouble()));
- outputPortDTO.setName(name);
-
- // create the revision
- final RevisionDTO revision = new RevisionDTO();
- revision.setClientId(clientId.getClientId());
-
- if (version != null) {
- revision.setVersion(version.getLong());
- }
-
- // create the output port entity entity
- final OutputPortEntity portEntity = new OutputPortEntity();
- portEntity.setRevision(revision);
- portEntity.setOutputPort(outputPortDTO);
-
- // create the output port
- return createOutputPort(httpServletRequest, portEntity);
- }
-
- /**
- * Creates a new output port.
- *
- * @param httpServletRequest request
- * @param portEntity A outputPortEntity.
- * @return A outputPortEntity.
- */
- @POST
- @Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
- @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
- @Path("") // necessary due to bug in swagger
- @PreAuthorize("hasRole('ROLE_DFM')")
- @ApiOperation(
- value = "Creates an output port",
- response = OutputPortEntity.class,
- authorizations = {
- @Authorization(value = "Data Flow Manager", type = "ROLE_DFM")
- }
- )
- @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 createOutputPort(
- @Context HttpServletRequest httpServletRequest,
- @ApiParam(
- value = "The output port configuration.",
- required = true
- ) OutputPortEntity portEntity) {
-
- if (portEntity == null || portEntity.getOutputPort() == null) {
- throw new IllegalArgumentException("Port details must be specified.");
- }
-
- if (portEntity.getRevision() == null) {
- throw new IllegalArgumentException("Revision must be specified.");
- }
-
- if (portEntity.getOutputPort().getId() != null) {
- throw new IllegalArgumentException("Output port ID cannot be specified.");
- }
-
- // if cluster manager, convert POST to PUT (to maintain same ID across nodes) and replicate
- if (properties.isClusterManager()) {
-
- // create ID for resource
- final String id = UUID.randomUUID().toString();
-
- // set ID for resource
- portEntity.getOutputPort().setId(id);
-
- // convert POST request to PUT request to force entity ID to be the same across nodes
- URI putUri = null;
- try {
- putUri = new URI(getAbsolutePath().toString() + "/" + id);
- } catch (final URISyntaxException e) {
- throw new WebApplicationException(e);
- }
-
- // change content type to JSON for serializing entity
- final Map<String, String> headersToOverride = new HashMap<>();
- headersToOverride.put("content-type", MediaType.APPLICATION_JSON);
-
- // replicate put request
- return (Response) clusterManager.applyRequest(HttpMethod.PUT, putUri, updateClientId(portEntity), getHeaders(headersToOverride)).getResponse();
-
- }
-
- // handle expects request (usually from the cluster manager)
- final String expects = httpServletRequest.getHeader(WebClusterManager.NCM_EXPECTS_HTTP_HEADER);
- if (expects != null) {
- return generateContinueResponse().build();
- }
-
- // create the output port and generate the json
- final RevisionDTO revision = portEntity.getRevision();
- final ConfigurationSnapshot<PortDTO> controllerResponse = serviceFacade.createOutputPort(
- new Revision(revision.getVersion(), revision.getClientId()), groupId, portEntity.getOutputPort());
- final PortDTO port = controllerResponse.getConfiguration();
- populateRemainingOutputPortContent(port);
-
- // get the updated revision
- final RevisionDTO updatedRevision = new RevisionDTO();
- updatedRevision.setClientId(revision.getClientId());
- updatedRevision.setVersion(controllerResponse.getVersion());
-
- // build the response entity
- final OutputPortEntity entity = new OutputPortEntity();
- entity.setRevision(updatedRevision);
- entity.setOutputPort(port);
-
- // build the response
- return clusterContext(generateCreatedResponse(URI.create(port.getUri()), entity)).build();
- }
-
- /**
* Retrieves the specified output port.
*
* @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.
@@ -324,9 +104,9 @@ public class OutputPortResource extends ApplicationResource {
*/
@GET
@Consumes(MediaType.WILDCARD)
- @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
+ @Produces(MediaType.APPLICATION_JSON)
@Path("{id}")
- @PreAuthorize("hasAnyRole('ROLE_MONITOR', 'ROLE_DFM', 'ROLE_ADMIN')")
+ // TODO - @PreAuthorize("hasAnyRole('ROLE_MONITOR', 'ROLE_DFM', 'ROLE_ADMIN')")
@ApiOperation(
value = "Gets an output port",
response = OutputPortEntity.class,
@@ -363,7 +143,7 @@ public class OutputPortResource extends ApplicationResource {
}
// get the port
- final PortDTO port = serviceFacade.getOutputPort(groupId, id);
+ final PortDTO port = serviceFacade.getOutputPort(id);
// create the revision
final RevisionDTO revision = new RevisionDTO();
@@ -386,9 +166,9 @@ public class OutputPortResource extends ApplicationResource {
*/
@GET
@Consumes(MediaType.WILDCARD)
- @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
+ @Produces(MediaType.APPLICATION_JSON)
@Path("/{id}/status")
- @PreAuthorize("hasAnyRole('ROLE_MONITOR', 'ROLE_DFM', 'ROLE_ADMIN')")
+ // TODO - @PreAuthorize("hasAnyRole('ROLE_MONITOR', 'ROLE_DFM', 'ROLE_ADMIN')")
@ApiOperation(
value = "Gets status for an output port",
response = PortStatusEntity.class,
@@ -462,7 +242,7 @@ public class OutputPortResource extends ApplicationResource {
}
// get the specified output port status
- final PortStatusDTO portStatus = serviceFacade.getOutputPortStatus(groupId, id);
+ final PortStatusDTO portStatus = serviceFacade.getOutputPortStatus(id);
// create the revision
final RevisionDTO revision = new RevisionDTO();
@@ -481,96 +261,15 @@ public class OutputPortResource extends ApplicationResource {
* Updates the specified output port.
*
* @param httpServletRequest request
- * @param version The revision is used to verify the client is working with the latest version of the flow.
- * @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 output port to update.
- * @param x The x coordinate for this output ports position.
- * @param y The y coordinate for this output ports position.
- * @param comments Any comments about this output port.
- * @param name The output ports name.
- * @param groupAccessControl The allowed groups for this output port.
- * @param userAccessControl The allowed users for this output port.
- * @param state The state of this port.
- * @param concurrentlySchedulableTaskCount The number of concurrently schedulable tasks.
- * @param formParams params
- * @return A outputPortEntity.
- */
- @PUT
- @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
- @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
- @Path("{id}")
- @PreAuthorize("hasRole('ROLE_DFM')")
- public Response updateOutputPort(
- @Context HttpServletRequest httpServletRequest,
- @FormParam(VERSION) LongParameter version,
- @FormParam(CLIENT_ID) @DefaultValue(StringUtils.EMPTY) ClientIdParameter clientId,
- @PathParam("id") String id,
- @FormParam("x") DoubleParameter x,
- @FormParam("y") DoubleParameter y,
- @FormParam("comments") String comments,
- @FormParam("groupAccessControl[]") Set<String> groupAccessControl,
- @FormParam("userAccessControl[]") Set<String> userAccessControl,
- @FormParam("name") String name,
- @FormParam("state") String state,
- @FormParam("concurrentlySchedulableTaskCount") IntegerParameter concurrentlySchedulableTaskCount,
- MultivaluedMap<String, String> formParams) {
-
- // create the output port DTO
- final PortDTO portDTO = new PortDTO();
- portDTO.setId(id);
- portDTO.setComments(comments);
- portDTO.setName(name);
- portDTO.setState(state);
-
- if (concurrentlySchedulableTaskCount != null) {
- portDTO.setConcurrentlySchedulableTaskCount(concurrentlySchedulableTaskCount.getInteger());
- }
-
- // require both coordinates to be specified
- if (x != null && y != null) {
- portDTO.setPosition(new PositionDTO(x.getDouble(), y.getDouble()));
- }
-
- // only set the group access control when applicable
- if (!groupAccessControl.isEmpty() || formParams.containsKey("groupAccessControl[]")) {
- portDTO.setGroupAccessControl(groupAccessControl);
- }
-
- // only set the user access control when applicable
- if (!userAccessControl.isEmpty() || formParams.containsKey("userAccessControl[]")) {
- portDTO.setUserAccessControl(userAccessControl);
- }
-
- // create the revision
- final RevisionDTO revision = new RevisionDTO();
- revision.setClientId(clientId.getClientId());
-
- if (version != null) {
- revision.setVersion(version.getLong());
- }
-
- // create the output port entity
- final OutputPortEntity portEntity = new OutputPortEntity();
- portEntity.setRevision(revision);
- portEntity.setOutputPort(portDTO);
-
- // update the port
- return updateOutputPort(httpServletRequest, id, portEntity);
- }
-
- /**
- * Updates the specified output port.
- *
- * @param httpServletRequest request
* @param id The id of the output port to update.
* @param portEntity A outputPortEntity.
* @return A outputPortEntity.
*/
@PUT
- @Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
- @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
@Path("{id}")
- @PreAuthorize("hasRole('ROLE_DFM')")
+ // TODO - @PreAuthorize("hasRole('ROLE_DFM')")
@ApiOperation(
value = "Updates an output port",
response = OutputPortEntity.class,
@@ -627,14 +326,14 @@ public class OutputPortResource extends ApplicationResource {
// handle expects request (usually from the cluster manager)
final String expects = httpServletRequest.getHeader(WebClusterManager.NCM_EXPECTS_HTTP_HEADER);
if (expects != null) {
- serviceFacade.verifyUpdateOutputPort(groupId, requestPortDTO);
+ serviceFacade.verifyUpdateOutputPort(requestPortDTO);
return generateContinueResponse().build();
}
// update the output port
final RevisionDTO revision = portEntity.getRevision();
final ConfigurationSnapshot<PortDTO> controllerResponse = serviceFacade.updateOutputPort(
- new Revision(revision.getVersion(), revision.getClientId()), groupId, requestPortDTO);
+ new Revision(revision.getVersion(), revision.getClientId()), requestPortDTO);
// get the results
final PortDTO responsePortDTO = controllerResponse.getConfiguration();
@@ -668,9 +367,9 @@ public class OutputPortResource extends ApplicationResource {
*/
@DELETE
@Consumes(MediaType.WILDCARD)
- @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
+ @Produces(MediaType.APPLICATION_JSON)
@Path("{id}")
- @PreAuthorize("hasRole('ROLE_DFM')")
+ // TODO - @PreAuthorize("hasRole('ROLE_DFM')")
@ApiOperation(
value = "Deletes an output port",
response = OutputPortEntity.class,
@@ -713,7 +412,7 @@ public class OutputPortResource extends ApplicationResource {
// handle expects request (usually from the cluster manager)
final String expects = httpServletRequest.getHeader(WebClusterManager.NCM_EXPECTS_HTTP_HEADER);
if (expects != null) {
- serviceFacade.verifyDeleteOutputPort(groupId, id);
+ serviceFacade.verifyDeleteOutputPort(id);
return generateContinueResponse().build();
}
@@ -724,7 +423,7 @@ public class OutputPortResource extends ApplicationResource {
}
// delete the specified output port
- final ConfigurationSnapshot<Void> controllerResponse = serviceFacade.deleteOutputPort(new Revision(clientVersion, clientId.getClientId()), groupId, id);
+ final ConfigurationSnapshot<Void> controllerResponse = serviceFacade.deleteOutputPort(new Revision(clientVersion, clientId.getClientId()), id);
// get the updated revision
final RevisionDTO revision = new RevisionDTO();
@@ -743,10 +442,6 @@ public class OutputPortResource extends ApplicationResource {
this.serviceFacade = serviceFacade;
}
- public void setGroupId(String groupId) {
- this.groupId = groupId;
- }
-
public void setClusterManager(WebClusterManager clusterManager) {
this.clusterManager = clusterManager;
}