NIFI-2000: Ensure that if we override setters in ApplicationResource that we call the super class's setter as well

NIFI-2000: Updated to avoid multiple instance variables and instead just provide a getter in ApplicationResource

This closes #522
This commit is contained in:
Mark Payne 2016-06-10 17:08:30 -04:00 committed by Oleg Zhurakousky
parent 849c43b162
commit b753a82d7e
4 changed files with 46 additions and 57 deletions

View File

@ -16,11 +16,21 @@
*/ */
package org.apache.nifi.web.api; package org.apache.nifi.web.api;
import com.wordnik.swagger.annotations.Api; import java.net.URI;
import com.wordnik.swagger.annotations.ApiOperation; import java.security.cert.X509Certificate;
import com.wordnik.swagger.annotations.ApiResponse; import java.util.concurrent.TimeUnit;
import com.wordnik.swagger.annotations.ApiResponses;
import io.jsonwebtoken.JwtException; import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.Consumes;
import javax.ws.rs.FormParam;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.nifi.admin.service.AdministrationException; import org.apache.nifi.admin.service.AdministrationException;
import org.apache.nifi.authentication.AuthenticationResponse; import org.apache.nifi.authentication.AuthenticationResponse;
@ -39,7 +49,6 @@ import org.apache.nifi.authorization.user.NiFiUser;
import org.apache.nifi.authorization.user.NiFiUserDetails; import org.apache.nifi.authorization.user.NiFiUserDetails;
import org.apache.nifi.authorization.user.NiFiUserUtils; import org.apache.nifi.authorization.user.NiFiUserUtils;
import org.apache.nifi.util.FormatUtils; import org.apache.nifi.util.FormatUtils;
import org.apache.nifi.util.NiFiProperties;
import org.apache.nifi.web.api.dto.AccessConfigurationDTO; import org.apache.nifi.web.api.dto.AccessConfigurationDTO;
import org.apache.nifi.web.api.dto.AccessStatusDTO; import org.apache.nifi.web.api.dto.AccessStatusDTO;
import org.apache.nifi.web.api.entity.AccessConfigurationEntity; import org.apache.nifi.web.api.entity.AccessConfigurationEntity;
@ -66,19 +75,12 @@ import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException; import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.authentication.preauth.x509.X509PrincipalExtractor; import org.springframework.security.web.authentication.preauth.x509.X509PrincipalExtractor;
import javax.servlet.http.HttpServletRequest; import com.wordnik.swagger.annotations.Api;
import javax.ws.rs.Consumes; import com.wordnik.swagger.annotations.ApiOperation;
import javax.ws.rs.FormParam; import com.wordnik.swagger.annotations.ApiResponse;
import javax.ws.rs.GET; import com.wordnik.swagger.annotations.ApiResponses;
import javax.ws.rs.POST;
import javax.ws.rs.Path; import io.jsonwebtoken.JwtException;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.net.URI;
import java.security.cert.X509Certificate;
import java.util.concurrent.TimeUnit;
/** /**
* RESTful endpoint for managing access. * RESTful endpoint for managing access.
@ -92,8 +94,6 @@ public class AccessResource extends ApplicationResource {
private static final Logger logger = LoggerFactory.getLogger(AccessResource.class); private static final Logger logger = LoggerFactory.getLogger(AccessResource.class);
private NiFiProperties properties;
private X509CertificateExtractor certificateExtractor; private X509CertificateExtractor certificateExtractor;
private X509AuthenticationProvider x509AuthenticationProvider; private X509AuthenticationProvider x509AuthenticationProvider;
private X509PrincipalExtractor principalExtractor; private X509PrincipalExtractor principalExtractor;
@ -500,10 +500,6 @@ public class AccessResource extends ApplicationResource {
} }
// setters // setters
public void setProperties(NiFiProperties properties) {
this.properties = properties;
}
public void setAuthorizer(Authorizer authorizer) { public void setAuthorizer(Authorizer authorizer) {
this.authorizer = authorizer; this.authorizer = authorizer;
} }

View File

@ -671,6 +671,10 @@ public abstract class ApplicationResource {
this.clusterCoordinator = clusterCoordinator; this.clusterCoordinator = clusterCoordinator;
} }
protected ClusterCoordinator getClusterCoordinator() {
return clusterCoordinator;
}
protected NiFiProperties getProperties() { protected NiFiProperties getProperties() {
return properties; return properties;
} }

View File

@ -84,7 +84,6 @@ public class ControllerResource extends ApplicationResource {
private ReportingTaskResource reportingTaskResource; private ReportingTaskResource reportingTaskResource;
private ControllerServiceResource controllerServiceResource; private ControllerServiceResource controllerServiceResource;
private ClusterCoordinator clusterCoordinator;
@Context @Context
private ResourceContext resourceContext; private ResourceContext resourceContext;
@ -143,7 +142,7 @@ public class ControllerResource extends ApplicationResource {
@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.") @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 createArchive(@Context HttpServletRequest httpServletRequest) { public Response createArchive(@Context final HttpServletRequest httpServletRequest) {
if (isReplicateRequest()) { if (isReplicateRequest()) {
return replicate(HttpMethod.POST); return replicate(HttpMethod.POST);
@ -159,7 +158,7 @@ public class ControllerResource extends ApplicationResource {
final ProcessGroupEntity entity = serviceFacade.createArchive(); final ProcessGroupEntity entity = serviceFacade.createArchive();
// generate the response // generate the response
URI uri = URI.create(generateResourceUri("controller", "archive")); final URI uri = URI.create(generateResourceUri("controller", "archive"));
return clusterContext(generateCreatedResponse(uri, entity)).build(); return clusterContext(generateCreatedResponse(uri, entity)).build();
} }
@ -196,12 +195,12 @@ public class ControllerResource extends ApplicationResource {
value = "Whether or not to include the breakdown per node. Optional, defaults to false", value = "Whether or not to include the breakdown per node. Optional, defaults to false",
required = false required = false
) )
@QueryParam("nodewise") @DefaultValue(NODEWISE) Boolean nodewise, @QueryParam("nodewise") @DefaultValue(NODEWISE) final Boolean nodewise,
@ApiParam( @ApiParam(
value = "The id of the node where to get the status.", value = "The id of the node where to get the status.",
required = false required = false
) )
@QueryParam("clusterNodeId") String clusterNodeId) throws InterruptedException { @QueryParam("clusterNodeId") final String clusterNodeId) throws InterruptedException {
// ensure a valid request // ensure a valid request
if (Boolean.TRUE.equals(nodewise) && clusterNodeId != null) { if (Boolean.TRUE.equals(nodewise) && clusterNodeId != null) {
@ -223,7 +222,7 @@ public class ControllerResource extends ApplicationResource {
return nodeResponse.getResponse(); return nodeResponse.getResponse();
} else { } else {
// get the target node and ensure it exists // get the target node and ensure it exists
final NodeIdentifier targetNode = clusterCoordinator.getNodeIdentifier(clusterNodeId); final NodeIdentifier targetNode = getClusterCoordinator().getNodeIdentifier(clusterNodeId);
if (targetNode == null) { if (targetNode == null) {
throw new UnknownNodeException("The specified cluster node does not exist."); throw new UnknownNodeException("The specified cluster node does not exist.");
} }
@ -274,8 +273,8 @@ public class ControllerResource extends ApplicationResource {
} }
) )
public Response updateCounter( public Response updateCounter(
@Context HttpServletRequest httpServletRequest, @Context final HttpServletRequest httpServletRequest,
@PathParam("id") String id) { @PathParam("id") final String id) {
if (isReplicateRequest()) { if (isReplicateRequest()) {
return replicate(HttpMethod.PUT); return replicate(HttpMethod.PUT);
@ -366,11 +365,11 @@ public class ControllerResource extends ApplicationResource {
} }
) )
public Response updateControllerConfig( public Response updateControllerConfig(
@Context HttpServletRequest httpServletRequest, @Context final HttpServletRequest httpServletRequest,
@ApiParam( @ApiParam(
value = "The controller configuration.", value = "The controller configuration.",
required = true required = true
) ControllerConfigurationEntity configEntity) { ) final ControllerConfigurationEntity configEntity) {
if (configEntity == null || configEntity.getConfig() == null) { if (configEntity == null || configEntity.getConfig() == null) {
throw new IllegalArgumentException("Controller configuration must be specified"); throw new IllegalArgumentException("Controller configuration must be specified");
@ -431,11 +430,11 @@ public class ControllerResource extends ApplicationResource {
} }
) )
public Response createReportingTask( public Response createReportingTask(
@Context HttpServletRequest httpServletRequest, @Context final HttpServletRequest httpServletRequest,
@ApiParam( @ApiParam(
value = "The reporting task configuration details.", value = "The reporting task configuration details.",
required = true required = true
) ReportingTaskEntity reportingTaskEntity) { ) final ReportingTaskEntity reportingTaskEntity) {
if (reportingTaskEntity == null || reportingTaskEntity.getComponent() == null) { if (reportingTaskEntity == null || reportingTaskEntity.getComponent() == null) {
throw new IllegalArgumentException("Reporting task details must be specified."); throw new IllegalArgumentException("Reporting task details must be specified.");
@ -548,24 +547,19 @@ public class ControllerResource extends ApplicationResource {
} }
// setters // setters
public void setServiceFacade(NiFiServiceFacade serviceFacade) { public void setServiceFacade(final NiFiServiceFacade serviceFacade) {
this.serviceFacade = serviceFacade; this.serviceFacade = serviceFacade;
} }
@Override public void setReportingTaskResource(final ReportingTaskResource reportingTaskResource) {
public void setClusterCoordinator(ClusterCoordinator clusterCoordinator) {
this.clusterCoordinator = clusterCoordinator;
}
public void setReportingTaskResource(ReportingTaskResource reportingTaskResource) {
this.reportingTaskResource = reportingTaskResource; this.reportingTaskResource = reportingTaskResource;
} }
public void setControllerServiceResource(ControllerServiceResource controllerServiceResource) { public void setControllerServiceResource(final ControllerServiceResource controllerServiceResource) {
this.controllerServiceResource = controllerServiceResource; this.controllerServiceResource = controllerServiceResource;
} }
public void setAuthorizer(Authorizer authorizer) { public void setAuthorizer(final Authorizer authorizer) {
this.authorizer = authorizer; this.authorizer = authorizer;
} }
} }

View File

@ -80,7 +80,6 @@ public class FlowFileQueueResource extends ApplicationResource {
private NiFiServiceFacade serviceFacade; private NiFiServiceFacade serviceFacade;
private Authorizer authorizer; private Authorizer authorizer;
private ClusterCoordinator clusterCoordinator;
/** /**
* Populate the URIs for the specified flowfile listing. * Populate the URIs for the specified flowfile listing.
@ -95,7 +94,7 @@ public class FlowFileQueueResource extends ApplicationResource {
// uri of each flowfile // uri of each flowfile
if (flowFileListing.getFlowFileSummaries() != null) { if (flowFileListing.getFlowFileSummaries() != null) {
for (FlowFileSummaryDTO flowFile : flowFileListing.getFlowFileSummaries()) { for (final FlowFileSummaryDTO flowFile : flowFileListing.getFlowFileSummaries()) {
populateRemainingFlowFileContent(connectionId, flowFile); populateRemainingFlowFileContent(connectionId, flowFile);
} }
} }
@ -167,7 +166,7 @@ public class FlowFileQueueResource extends ApplicationResource {
throw new IllegalArgumentException("The id of the node in the cluster is required."); throw new IllegalArgumentException("The id of the node in the cluster is required.");
} else { } else {
// get the target node and ensure it exists // get the target node and ensure it exists
final NodeIdentifier targetNode = clusterCoordinator.getNodeIdentifier(clusterNodeId); final NodeIdentifier targetNode = getClusterCoordinator().getNodeIdentifier(clusterNodeId);
if (targetNode == null) { if (targetNode == null) {
throw new UnknownNodeException("The specified cluster node does not exist."); throw new UnknownNodeException("The specified cluster node does not exist.");
} }
@ -255,7 +254,7 @@ public class FlowFileQueueResource extends ApplicationResource {
throw new IllegalArgumentException("The id of the node in the cluster is required."); throw new IllegalArgumentException("The id of the node in the cluster is required.");
} else { } else {
// get the target node and ensure it exists // get the target node and ensure it exists
final NodeIdentifier targetNode = clusterCoordinator.getNodeIdentifier(clusterNodeId); final NodeIdentifier targetNode = getClusterCoordinator().getNodeIdentifier(clusterNodeId);
if (targetNode == null) { if (targetNode == null) {
throw new UnknownNodeException("The specified cluster node does not exist."); throw new UnknownNodeException("The specified cluster node does not exist.");
} }
@ -282,7 +281,7 @@ public class FlowFileQueueResource extends ApplicationResource {
// generate a streaming response // generate a streaming response
final StreamingOutput response = new StreamingOutput() { final StreamingOutput response = new StreamingOutput() {
@Override @Override
public void write(OutputStream output) throws IOException, WebApplicationException { public void write(final OutputStream output) throws IOException, WebApplicationException {
try (InputStream is = content.getContent()) { try (InputStream is = content.getContent()) {
// stream the content to the response // stream the content to the response
StreamUtils.copy(is, output); StreamUtils.copy(is, output);
@ -707,15 +706,11 @@ public class FlowFileQueueResource extends ApplicationResource {
} }
// setters // setters
public void setServiceFacade(NiFiServiceFacade serviceFacade) { public void setServiceFacade(final NiFiServiceFacade serviceFacade) {
this.serviceFacade = serviceFacade; this.serviceFacade = serviceFacade;
} }
public void setClusterCoordinator(ClusterCoordinator clusterCoordinator) { public void setAuthorizer(final Authorizer authorizer) {
this.clusterCoordinator = clusterCoordinator;
}
public void setAuthorizer(Authorizer authorizer) {
this.authorizer = authorizer; this.authorizer = authorizer;
} }
} }