http://git-wip-us.apache.org/repos/asf/nifi/blob/4b74e4de/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/ApplicationResource.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/ApplicationResource.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/ApplicationResource.java index e946117..cee84eb 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/ApplicationResource.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/ApplicationResource.java @@ -16,22 +16,31 @@ */ package org.apache.nifi.web.api; -import com.sun.jersey.api.core.HttpContext; -import com.sun.jersey.api.representation.Form; -import com.sun.jersey.core.util.MultivaluedMapImpl; -import com.sun.jersey.server.impl.model.method.dispatch.FormDispatchProvider; +import java.io.Serializable; +import java.net.URI; +import java.net.URISyntaxException; +import java.nio.charset.StandardCharsets; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; +import java.util.TreeMap; +import java.util.UUID; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.ws.rs.core.CacheControl; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.MultivaluedMap; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.Response.ResponseBuilder; +import javax.ws.rs.core.UriBuilder; +import javax.ws.rs.core.UriBuilderException; +import javax.ws.rs.core.UriInfo; + import org.apache.commons.lang3.StringUtils; -import org.apache.commons.lang3.builder.ReflectionToStringBuilder; -import org.apache.commons.lang3.builder.ToStringStyle; -import org.apache.nifi.action.Action; -import org.apache.nifi.action.FlowChangeAction; -import org.apache.nifi.action.Operation; import org.apache.nifi.authorization.user.NiFiUserDetails; -import org.apache.nifi.cluster.context.ClusterContext; -import org.apache.nifi.cluster.context.ClusterContextThreadLocal; import org.apache.nifi.cluster.coordination.http.replication.RequestReplicator; -import org.apache.nifi.cluster.manager.impl.WebClusterManager; -import org.apache.nifi.util.NiFiProperties; import org.apache.nifi.web.Revision; import org.apache.nifi.web.api.dto.RevisionDTO; import org.apache.nifi.web.api.entity.ComponentEntity; @@ -43,24 +52,10 @@ import org.slf4j.LoggerFactory; import org.springframework.security.core.Authentication; import org.springframework.security.core.context.SecurityContextHolder; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.ws.rs.core.CacheControl; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.MultivaluedMap; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.Response.ResponseBuilder; -import javax.ws.rs.core.UriBuilder; -import javax.ws.rs.core.UriBuilderException; -import javax.ws.rs.core.UriInfo; -import java.io.Serializable; -import java.net.URI; -import java.net.URISyntaxException; -import java.util.Collection; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.Map; -import java.util.TreeMap; +import com.sun.jersey.api.core.HttpContext; +import com.sun.jersey.api.representation.Form; +import com.sun.jersey.core.util.MultivaluedMapImpl; +import com.sun.jersey.server.impl.model.method.dispatch.FormDispatchProvider; /** * Base class for controllers. @@ -77,8 +72,6 @@ public abstract class ApplicationResource { public static final String PROXIED_ENTITIES_CHAIN_HTTP_HEADER = "X-ProxiedEntitiesChain"; public static final String PROXIED_ENTITY_USER_DETAILS_HTTP_HEADER = "X-ProxiedEntityUserDetails"; - private static final int HEADER_BUFFER_SIZE = 16 * 1024; // 16kb - private static final int CLUSTER_CONTEXT_HEADER_VALUE_MAX_BYTES = (int) (0.75 * HEADER_BUFFER_SIZE); private static final Logger logger = LoggerFactory.getLogger(ApplicationResource.class); public static final String NODEWISE = "false"; @@ -173,84 +166,25 @@ public abstract class ApplicationResource { * @return builder */ protected ResponseBuilder clusterContext(ResponseBuilder response) { + // TODO: Remove this method. Since ClusterContext was removed, it is no longer needed. However, + // it is called by practically every endpoint so for now it is just being stubbed out. + return response; + } - NiFiProperties properties = NiFiProperties.getInstance(); - if (!properties.isNode()) { - return response; - } - - // get cluster context from threadlocal - ClusterContext clusterCtx = ClusterContextThreadLocal.getContext(); - if (clusterCtx != null) { - - // serialize cluster context - String serializedClusterContext = WebUtils.serializeObjectToHex(clusterCtx); - if (serializedClusterContext.length() > CLUSTER_CONTEXT_HEADER_VALUE_MAX_BYTES) { - /* - * Actions is the only field that can vary in size. If we have no - * actions and we exceeded the header size, then basic assumptions - * about the cluster context have been violated. - */ - if (clusterCtx.getActions().isEmpty()) { - throw new IllegalStateException( - String.format("Serialized Cluster context size '%d' is too big for response header", serializedClusterContext.length())); - } - - // use the first action as the prototype for creating the "batch" action - Action prototypeAction = clusterCtx.getActions().get(0); - - // log the batched actions - StringBuilder loggedActions = new StringBuilder(); - createBatchedActionLogStatement(loggedActions, clusterCtx.getActions()); - logger.info(loggedActions.toString()); - - // remove current actions and replace with batch action - clusterCtx.getActions().clear(); - - // create the batch action - FlowChangeAction batchAction = new FlowChangeAction(); - batchAction.setOperation(Operation.Batch); - - // copy values from prototype action - batchAction.setTimestamp(prototypeAction.getTimestamp()); - batchAction.setUserIdentity(prototypeAction.getUserIdentity()); - batchAction.setUserName(prototypeAction.getUserName()); - batchAction.setSourceId(prototypeAction.getSourceId()); - batchAction.setSourceName(prototypeAction.getSourceName()); - batchAction.setSourceType(prototypeAction.getSourceType()); - - // add batch action - clusterCtx.getActions().add(batchAction); - - // create the final serialized copy of the cluster context - serializedClusterContext = WebUtils.serializeObjectToHex(clusterCtx); - } + protected String generateUuid() { + final Optional<String> seed = getIdGenerationSeed(); + return seed.isPresent() ? UUID.nameUUIDFromBytes(seed.get().getBytes(StandardCharsets.UTF_8)).toString() : UUID.randomUUID().toString(); + } - // put serialized cluster context in response header - response.header(WebClusterManager.CLUSTER_CONTEXT_HTTP_HEADER, serializedClusterContext); + protected Optional<String> getIdGenerationSeed() { + final String idGenerationSeed = httpServletRequest.getHeader(RequestReplicator.CLUSTER_ID_GENERATION_SEED_HEADER); + if (StringUtils.isBlank(idGenerationSeed)) { + return Optional.empty(); } - return response; + return Optional.of(idGenerationSeed); } - /** - * @return the cluster context if found in the request header 'X-CLUSTER_CONTEXT'. - */ - protected ClusterContext getClusterContextFromRequest() { - String clusterContextHeaderValue = httpServletRequest.getHeader(WebClusterManager.CLUSTER_CONTEXT_HTTP_HEADER); - if (StringUtils.isNotBlank(clusterContextHeaderValue)) { - try { - // deserialize object - Serializable clusterContextObj = WebUtils.deserializeHexToObject(clusterContextHeaderValue); - if (clusterContextObj instanceof ClusterContext) { - return (ClusterContext) clusterContextObj; - } - } catch (ClassNotFoundException cnfe) { - logger.warn("Classpath issue detected because failed to deserialize cluster context from request due to: " + cnfe, cnfe); - } - } - return null; - } /** * Generates an Ok response with no content. @@ -300,7 +234,7 @@ public abstract class ApplicationResource { * @return a 150 Node Continue response to be used within the cluster request handshake */ protected ResponseBuilder generateContinueResponse() { - return Response.status(WebClusterManager.NODE_CONTINUE_STATUS_CODE); + return Response.status(RequestReplicator.NODE_CONTINUE_STATUS_CODE); } protected URI getAbsolutePath() { @@ -390,13 +324,6 @@ public abstract class ApplicationResource { return result; } - private void createBatchedActionLogStatement(StringBuilder strb, Collection<Action> actions) { - strb.append("Cluster context too big for response header. Replacing below actions with 'batch' action...\n"); - for (Action action : actions) { - strb.append(ReflectionToStringBuilder.toString(action, ToStringStyle.MULTI_LINE_STYLE)).append("\n"); - } - } - /** * Checks whether the request is part of a two-phase commit style request (either phase 1 or phase 2) * @@ -404,7 +331,7 @@ public abstract class ApplicationResource { * @return <code>true</code> if the request represents a two-phase commit style request */ protected boolean isTwoPhaseRequest(HttpServletRequest httpServletRequest) { - final String headerValue = httpServletRequest.getHeader(RequestReplicator.REQUEST_TRANSACTION_ID); + final String headerValue = httpServletRequest.getHeader(RequestReplicator.REQUEST_TRANSACTION_ID_HEADER); return headerValue != null; } @@ -419,7 +346,7 @@ public abstract class ApplicationResource { * first of the two phases. */ protected boolean isValidationPhase(HttpServletRequest httpServletRequest) { - return isTwoPhaseRequest(httpServletRequest) && httpServletRequest.getHeader(WebClusterManager.NCM_EXPECTS_HTTP_HEADER) != null; + return isTwoPhaseRequest(httpServletRequest) && httpServletRequest.getHeader(RequestReplicator.REQUEST_VALIDATION_HTTP_HEADER) != null; } /**
http://git-wip-us.apache.org/repos/asf/nifi/blob/4b74e4de/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/ControllerResource.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/ControllerResource.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/ControllerResource.java index d3912ed..695898e 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/ControllerResource.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/ControllerResource.java @@ -16,18 +16,31 @@ */ package org.apache.nifi.web.api; -import com.sun.jersey.api.core.ResourceContext; -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.util.Arrays; +import java.util.HashSet; +import java.util.Set; + +import javax.servlet.http.HttpServletRequest; +import javax.ws.rs.Consumes; +import javax.ws.rs.DefaultValue; +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.Response; + import org.apache.commons.lang3.StringUtils; import org.apache.nifi.authorization.user.NiFiUser; import org.apache.nifi.authorization.user.NiFiUserUtils; -import org.apache.nifi.cluster.context.ClusterContext; -import org.apache.nifi.cluster.context.ClusterContextThreadLocal; +import org.apache.nifi.cluster.coordination.http.replication.RequestReplicator; import org.apache.nifi.cluster.manager.NodeResponse; import org.apache.nifi.cluster.manager.exception.UnknownNodeException; import org.apache.nifi.cluster.manager.impl.WebClusterManager; @@ -51,27 +64,13 @@ import org.apache.nifi.web.api.entity.ReportingTaskEntity; import org.apache.nifi.web.api.entity.ReportingTasksEntity; import org.apache.nifi.web.api.request.ClientIdParameter; -import javax.servlet.http.HttpServletRequest; -import javax.ws.rs.Consumes; -import javax.ws.rs.DefaultValue; -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.Response; -import java.net.URI; -import java.nio.charset.StandardCharsets; -import java.util.Arrays; -import java.util.HashSet; -import java.util.Set; -import java.util.UUID; +import com.sun.jersey.api.core.ResourceContext; +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; /** * RESTful endpoint for managing a Flow Controller. @@ -134,7 +133,7 @@ public class ControllerResource extends ApplicationResource { } // handle expects request (usually from the cluster manager) - final String expects = httpServletRequest.getHeader(WebClusterManager.NCM_EXPECTS_HTTP_HEADER); + final String expects = httpServletRequest.getHeader(RequestReplicator.REQUEST_VALIDATION_HTTP_HEADER); if (expects != null) { return generateContinueResponse().build(); } @@ -267,7 +266,7 @@ public class ControllerResource extends ApplicationResource { } // handle expects request (usually from the cluster manager) - final String expects = httpServletRequest.getHeader(WebClusterManager.NCM_EXPECTS_HTTP_HEADER); + final String expects = httpServletRequest.getHeader(RequestReplicator.REQUEST_VALIDATION_HTTP_HEADER); if (expects != null) { return generateContinueResponse().build(); } @@ -379,7 +378,7 @@ public class ControllerResource extends ApplicationResource { final Revision revision = new Revision(revisionDto.getVersion(), revisionDto.getClientId(), "controller"); // handle expects request (usually from the cluster manager) - final String expects = httpServletRequest.getHeader(WebClusterManager.NCM_EXPECTS_HTTP_HEADER); + final String expects = httpServletRequest.getHeader(RequestReplicator.REQUEST_VALIDATION_HTTP_HEADER); if (expects != null) { return generateContinueResponse().build(); } @@ -504,18 +503,13 @@ public class ControllerResource extends ApplicationResource { } // handle expects request (usually from the cluster manager) - final String expects = httpServletRequest.getHeader(WebClusterManager.NCM_EXPECTS_HTTP_HEADER); + final String expects = httpServletRequest.getHeader(RequestReplicator.REQUEST_VALIDATION_HTTP_HEADER); if (expects != null) { return generateContinueResponse().build(); } // set the processor id as appropriate - final ClusterContext clusterContext = ClusterContextThreadLocal.getContext(); - if (clusterContext != null) { - reportingTaskEntity.getComponent().setId(UUID.nameUUIDFromBytes(clusterContext.getIdGenerationSeed().getBytes(StandardCharsets.UTF_8)).toString()); - } else { - reportingTaskEntity.getComponent().setId(UUID.randomUUID().toString()); - } + reportingTaskEntity.getComponent().setId(generateUuid()); // create the reporting task and generate the json final ReportingTaskEntity entity = serviceFacade.createReportingTask(reportingTaskEntity.getComponent()); http://git-wip-us.apache.org/repos/asf/nifi/blob/4b74e4de/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/FlowFileQueueResource.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/FlowFileQueueResource.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/FlowFileQueueResource.java index d832847..f6dd081 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/FlowFileQueueResource.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/FlowFileQueueResource.java @@ -16,31 +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 org.apache.commons.lang3.StringUtils; -import org.apache.nifi.cluster.context.ClusterContext; -import org.apache.nifi.cluster.context.ClusterContextThreadLocal; -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.stream.io.StreamUtils; -import org.apache.nifi.util.NiFiProperties; -import org.apache.nifi.web.DownloadableContent; -import org.apache.nifi.web.NiFiServiceFacade; -import org.apache.nifi.web.api.dto.DropRequestDTO; -import org.apache.nifi.web.api.dto.FlowFileDTO; -import org.apache.nifi.web.api.dto.FlowFileSummaryDTO; -import org.apache.nifi.web.api.dto.ListingRequestDTO; -import org.apache.nifi.web.api.entity.DropRequestEntity; -import org.apache.nifi.web.api.entity.FlowFileEntity; -import org.apache.nifi.web.api.entity.ListingRequestEntity; -import org.apache.nifi.web.api.request.ClientIdParameter; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.URI; +import java.util.HashSet; +import java.util.Set; import javax.servlet.http.HttpServletRequest; import javax.ws.rs.Consumes; @@ -59,14 +40,32 @@ import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import javax.ws.rs.core.Response.Status; import javax.ws.rs.core.StreamingOutput; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.net.URI; -import java.nio.charset.StandardCharsets; -import java.util.HashSet; -import java.util.Set; -import java.util.UUID; + +import org.apache.commons.lang3.StringUtils; +import org.apache.nifi.cluster.coordination.http.replication.RequestReplicator; +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.stream.io.StreamUtils; +import org.apache.nifi.util.NiFiProperties; +import org.apache.nifi.web.DownloadableContent; +import org.apache.nifi.web.NiFiServiceFacade; +import org.apache.nifi.web.api.dto.DropRequestDTO; +import org.apache.nifi.web.api.dto.FlowFileDTO; +import org.apache.nifi.web.api.dto.FlowFileSummaryDTO; +import org.apache.nifi.web.api.dto.ListingRequestDTO; +import org.apache.nifi.web.api.entity.DropRequestEntity; +import org.apache.nifi.web.api.entity.FlowFileEntity; +import org.apache.nifi.web.api.entity.ListingRequestEntity; +import org.apache.nifi.web.api.request.ClientIdParameter; + +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; /** * RESTful endpoint for managing a flowfile queue. @@ -334,20 +333,14 @@ public class FlowFileQueueResource extends ApplicationResource { } // handle expects request (usually from the cluster manager) - final String expects = httpServletRequest.getHeader(WebClusterManager.NCM_EXPECTS_HTTP_HEADER); + final String expects = httpServletRequest.getHeader(RequestReplicator.REQUEST_VALIDATION_HTTP_HEADER); if (expects != null) { serviceFacade.verifyListQueue(id); return generateContinueResponse().build(); } // ensure the id is the same across the cluster - final String listingRequestId; - final ClusterContext clusterContext = ClusterContextThreadLocal.getContext(); - if (clusterContext != null) { - listingRequestId = UUID.nameUUIDFromBytes(clusterContext.getIdGenerationSeed().getBytes(StandardCharsets.UTF_8)).toString(); - } else { - listingRequestId = UUID.randomUUID().toString(); - } + final String listingRequestId = generateUuid(); // submit the listing request final ListingRequestDTO listingRequest = serviceFacade.createFlowFileListingRequest(id, listingRequestId); @@ -466,7 +459,7 @@ public class FlowFileQueueResource extends ApplicationResource { } // handle expects request (usually from the cluster manager) - final String expects = httpServletRequest.getHeader(WebClusterManager.NCM_EXPECTS_HTTP_HEADER); + final String expects = httpServletRequest.getHeader(RequestReplicator.REQUEST_VALIDATION_HTTP_HEADER); if (expects != null) { return generateContinueResponse().build(); } @@ -530,19 +523,13 @@ public class FlowFileQueueResource extends ApplicationResource { } // handle expects request (usually from the cluster manager) - final String expects = httpServletRequest.getHeader(WebClusterManager.NCM_EXPECTS_HTTP_HEADER); + final String expects = httpServletRequest.getHeader(RequestReplicator.REQUEST_VALIDATION_HTTP_HEADER); if (expects != null) { return generateContinueResponse().build(); } // ensure the id is the same across the cluster - final String dropRequestId; - final ClusterContext clusterContext = ClusterContextThreadLocal.getContext(); - if (clusterContext != null) { - dropRequestId = UUID.nameUUIDFromBytes(clusterContext.getIdGenerationSeed().getBytes(StandardCharsets.UTF_8)).toString(); - } else { - dropRequestId = UUID.randomUUID().toString(); - } + final String dropRequestId = generateUuid(); // submit the drop request final DropRequestDTO dropRequest = serviceFacade.createFlowFileDropRequest(id, dropRequestId); @@ -661,7 +648,7 @@ public class FlowFileQueueResource extends ApplicationResource { } // handle expects request (usually from the cluster manager) - final String expects = httpServletRequest.getHeader(WebClusterManager.NCM_EXPECTS_HTTP_HEADER); + final String expects = httpServletRequest.getHeader(RequestReplicator.REQUEST_VALIDATION_HTTP_HEADER); if (expects != null) { return generateContinueResponse().build(); } http://git-wip-us.apache.org/repos/asf/nifi/blob/4b74e4de/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/FlowResource.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/FlowResource.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/FlowResource.java index 68d9d27..7e882a8 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/FlowResource.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/FlowResource.java @@ -16,13 +16,22 @@ */ package org.apache.nifi.web.api; -import com.sun.jersey.api.core.ResourceContext; -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.util.HashSet; +import java.util.Set; + +import javax.ws.rs.Consumes; +import javax.ws.rs.DefaultValue; +import javax.ws.rs.GET; +import javax.ws.rs.HttpMethod; +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.Response; + import org.apache.commons.lang3.StringUtils; import org.apache.nifi.authorization.AccessDeniedException; import org.apache.nifi.authorization.AuthorizationRequest; @@ -33,8 +42,6 @@ import org.apache.nifi.authorization.RequestAction; import org.apache.nifi.authorization.resource.ResourceFactory; import org.apache.nifi.authorization.user.NiFiUser; import org.apache.nifi.authorization.user.NiFiUserUtils; -import org.apache.nifi.cluster.context.ClusterContext; -import org.apache.nifi.cluster.context.ClusterContextThreadLocal; import org.apache.nifi.cluster.manager.NodeResponse; import org.apache.nifi.cluster.manager.exception.UnknownNodeException; import org.apache.nifi.cluster.manager.impl.WebClusterManager; @@ -88,22 +95,13 @@ import org.apache.nifi.web.api.request.ClientIdParameter; import org.apache.nifi.web.api.request.IntegerParameter; import org.apache.nifi.web.api.request.LongParameter; -import javax.ws.rs.Consumes; -import javax.ws.rs.DefaultValue; -import javax.ws.rs.GET; -import javax.ws.rs.HttpMethod; -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.Response; -import java.nio.charset.StandardCharsets; -import java.util.HashSet; -import java.util.Set; -import java.util.UUID; +import com.sun.jersey.api.core.ResourceContext; +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; /** * RESTful endpoint for managing a Flow. @@ -348,16 +346,7 @@ public class FlowResource extends ApplicationResource { ) public Response generateClientId() { authorizeFlow(); - - final String clientId; - final ClusterContext clusterContext = ClusterContextThreadLocal.getContext(); - if (clusterContext != null) { - clientId = UUID.nameUUIDFromBytes(clusterContext.getIdGenerationSeed().getBytes(StandardCharsets.UTF_8)).toString(); - } else { - clientId = UUID.randomUUID().toString(); - } - - return clusterContext(generateOkResponse(clientId)).build(); + return clusterContext(generateOkResponse(generateUuid())).build(); } // ------ http://git-wip-us.apache.org/repos/asf/nifi/blob/4b74e4de/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/ProcessGroupResource.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/ProcessGroupResource.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/ProcessGroupResource.java index 41f09d4..097f214 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/ProcessGroupResource.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/ProcessGroupResource.java @@ -16,17 +16,38 @@ */ package org.apache.nifi.web.api; -import com.sun.jersey.api.core.ResourceContext; -import com.sun.jersey.multipart.FormDataParam; -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.io.InputStream; +import java.net.URI; +import java.net.URISyntaxException; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + +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.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.Response; +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBElement; +import javax.xml.bind.JAXBException; +import javax.xml.bind.Unmarshaller; +import javax.xml.transform.stream.StreamSource; + import org.apache.commons.lang3.StringUtils; -import org.apache.nifi.cluster.context.ClusterContext; -import org.apache.nifi.cluster.context.ClusterContextThreadLocal; +import org.apache.nifi.cluster.coordination.http.replication.RequestReplicator; import org.apache.nifi.cluster.manager.impl.WebClusterManager; import org.apache.nifi.util.NiFiProperties; import org.apache.nifi.web.NiFiServiceFacade; @@ -67,36 +88,14 @@ 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.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.Response; -import javax.xml.bind.JAXBContext; -import javax.xml.bind.JAXBElement; -import javax.xml.bind.JAXBException; -import javax.xml.bind.Unmarshaller; -import javax.xml.transform.stream.StreamSource; -import java.io.InputStream; -import java.net.URI; -import java.net.URISyntaxException; -import java.nio.charset.StandardCharsets; -import java.util.Date; -import java.util.HashMap; -import java.util.Map; -import java.util.Set; -import java.util.UUID; +import com.sun.jersey.api.core.ResourceContext; +import com.sun.jersey.multipart.FormDataParam; +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; /** * RESTful endpoint for managing a Group. @@ -111,7 +110,6 @@ public class ProcessGroupResource extends ApplicationResource { private static final Logger logger = LoggerFactory.getLogger(ProcessGroupResource.class); private static final String VERBOSE = "false"; - private static final String RECURSIVE = "false"; @Context private ResourceContext resourceContext; @@ -494,18 +492,13 @@ public class ProcessGroupResource extends ApplicationResource { } // handle expects request (usually from the cluster manager) - final String expects = httpServletRequest.getHeader(WebClusterManager.NCM_EXPECTS_HTTP_HEADER); + final String expects = httpServletRequest.getHeader(RequestReplicator.REQUEST_VALIDATION_HTTP_HEADER); if (expects != null) { return generateContinueResponse().build(); } // set the processor id as appropriate - final ClusterContext clusterContext = ClusterContextThreadLocal.getContext(); - if (clusterContext != null) { - processGroupEntity.getComponent().setId(UUID.nameUUIDFromBytes(clusterContext.getIdGenerationSeed().getBytes(StandardCharsets.UTF_8)).toString()); - } else { - processGroupEntity.getComponent().setId(UUID.randomUUID().toString()); - } + processGroupEntity.getComponent().setId(generateUuid()); // create the process group contents final ProcessGroupEntity entity = serviceFacade.createProcessGroup(groupId, processGroupEntity.getComponent()); @@ -643,18 +636,13 @@ public class ProcessGroupResource extends ApplicationResource { } // handle expects request (usually from the cluster manager) - final String expects = httpServletRequest.getHeader(WebClusterManager.NCM_EXPECTS_HTTP_HEADER); + final String expects = httpServletRequest.getHeader(RequestReplicator.REQUEST_VALIDATION_HTTP_HEADER); if (expects != null) { return generateContinueResponse().build(); } // set the processor id as appropriate - final ClusterContext clusterContext = ClusterContextThreadLocal.getContext(); - if (clusterContext != null) { - processorEntity.getComponent().setId(UUID.nameUUIDFromBytes(clusterContext.getIdGenerationSeed().getBytes(StandardCharsets.UTF_8)).toString()); - } else { - processorEntity.getComponent().setId(UUID.randomUUID().toString()); - } + processorEntity.getComponent().setId(generateUuid()); // create the new processor final ProcessorEntity entity = serviceFacade.createProcessor(groupId, processorEntity.getComponent()); @@ -781,18 +769,13 @@ public class ProcessGroupResource extends ApplicationResource { } // handle expects request (usually from the cluster manager) - final String expects = httpServletRequest.getHeader(WebClusterManager.NCM_EXPECTS_HTTP_HEADER); + final String expects = httpServletRequest.getHeader(RequestReplicator.REQUEST_VALIDATION_HTTP_HEADER); if (expects != null) { return generateContinueResponse().build(); } // set the processor id as appropriate - final ClusterContext clusterContext = ClusterContextThreadLocal.getContext(); - if (clusterContext != null) { - portEntity.getComponent().setId(UUID.nameUUIDFromBytes(clusterContext.getIdGenerationSeed().getBytes(StandardCharsets.UTF_8)).toString()); - } else { - portEntity.getComponent().setId(UUID.randomUUID().toString()); - } + portEntity.getComponent().setId(generateUuid()); // create the input port and generate the json final PortEntity entity = serviceFacade.createInputPort(groupId, portEntity.getComponent()); @@ -916,18 +899,13 @@ public class ProcessGroupResource extends ApplicationResource { } // handle expects request (usually from the cluster manager) - final String expects = httpServletRequest.getHeader(WebClusterManager.NCM_EXPECTS_HTTP_HEADER); + final String expects = httpServletRequest.getHeader(RequestReplicator.REQUEST_VALIDATION_HTTP_HEADER); if (expects != null) { return generateContinueResponse().build(); } // set the processor id as appropriate - final ClusterContext clusterContext = ClusterContextThreadLocal.getContext(); - if (clusterContext != null) { - portEntity.getComponent().setId(UUID.nameUUIDFromBytes(clusterContext.getIdGenerationSeed().getBytes(StandardCharsets.UTF_8)).toString()); - } else { - portEntity.getComponent().setId(UUID.randomUUID().toString()); - } + portEntity.getComponent().setId(generateUuid()); // create the output port and generate the json final PortEntity entity = serviceFacade.createOutputPort(groupId, portEntity.getComponent()); @@ -1052,18 +1030,13 @@ public class ProcessGroupResource extends ApplicationResource { } // handle expects request (usually from the cluster manager) - final String expects = httpServletRequest.getHeader(WebClusterManager.NCM_EXPECTS_HTTP_HEADER); + final String expects = httpServletRequest.getHeader(RequestReplicator.REQUEST_VALIDATION_HTTP_HEADER); if (expects != null) { return generateContinueResponse().build(); } // set the processor id as appropriate - final ClusterContext clusterContext = ClusterContextThreadLocal.getContext(); - if (clusterContext != null) { - funnelEntity.getComponent().setId(UUID.nameUUIDFromBytes(clusterContext.getIdGenerationSeed().getBytes(StandardCharsets.UTF_8)).toString()); - } else { - funnelEntity.getComponent().setId(UUID.randomUUID().toString()); - } + funnelEntity.getComponent().setId(generateUuid()); // create the funnel and generate the json final FunnelEntity entity = serviceFacade.createFunnel(groupId, funnelEntity.getComponent()); @@ -1188,18 +1161,13 @@ public class ProcessGroupResource extends ApplicationResource { } // handle expects request (usually from the cluster manager) - final String expects = httpServletRequest.getHeader(WebClusterManager.NCM_EXPECTS_HTTP_HEADER); + final String expects = httpServletRequest.getHeader(RequestReplicator.REQUEST_VALIDATION_HTTP_HEADER); if (expects != null) { return generateContinueResponse().build(); } // set the processor id as appropriate - final ClusterContext clusterContext = ClusterContextThreadLocal.getContext(); - if (clusterContext != null) { - labelEntity.getComponent().setId(UUID.nameUUIDFromBytes(clusterContext.getIdGenerationSeed().getBytes(StandardCharsets.UTF_8)).toString()); - } else { - labelEntity.getComponent().setId(UUID.randomUUID().toString()); - } + labelEntity.getComponent().setId(generateUuid()); // create the label and generate the json final LabelEntity entity = serviceFacade.createLabel(groupId, labelEntity.getComponent()); @@ -1330,18 +1298,13 @@ public class ProcessGroupResource extends ApplicationResource { } // handle expects request (usually from the cluster manager) - final String expects = httpServletRequest.getHeader(WebClusterManager.NCM_EXPECTS_HTTP_HEADER); + final String expects = httpServletRequest.getHeader(RequestReplicator.REQUEST_VALIDATION_HTTP_HEADER); if (expects != null) { return generateContinueResponse().build(); } // set the processor id as appropriate - final ClusterContext clusterContext = ClusterContextThreadLocal.getContext(); - if (clusterContext != null) { - requestProcessGroupDTO.setId(UUID.nameUUIDFromBytes(clusterContext.getIdGenerationSeed().getBytes(StandardCharsets.UTF_8)).toString()); - } else { - requestProcessGroupDTO.setId(UUID.randomUUID().toString()); - } + requestProcessGroupDTO.setId(generateUuid()); // parse the uri final URI uri; @@ -1509,19 +1472,14 @@ public class ProcessGroupResource extends ApplicationResource { final ConnectionDTO connection = connectionEntity.getComponent(); // handle expects request (usually from the cluster manager) - final String expects = httpServletRequest.getHeader(WebClusterManager.NCM_EXPECTS_HTTP_HEADER); + final String expects = httpServletRequest.getHeader(RequestReplicator.REQUEST_VALIDATION_HTTP_HEADER); if (expects != null) { serviceFacade.verifyCreateConnection(groupId, connection); return generateContinueResponse().build(); } // set the processor id as appropriate - final ClusterContext clusterContext = ClusterContextThreadLocal.getContext(); - if (clusterContext != null) { - connection.setId(UUID.nameUUIDFromBytes(clusterContext.getIdGenerationSeed().getBytes(StandardCharsets.UTF_8)).toString()); - } else { - connection.setId(UUID.randomUUID().toString()); - } + connection.setId(generateUuid()); // create the new relationship target final ConnectionEntity entity = serviceFacade.createConnection(groupId, connection); @@ -1654,18 +1612,13 @@ public class ProcessGroupResource extends ApplicationResource { } // handle expects request (usually from the cluster manager) - final String expects = httpServletRequest.getHeader(WebClusterManager.NCM_EXPECTS_HTTP_HEADER); + final String expects = httpServletRequest.getHeader(RequestReplicator.REQUEST_VALIDATION_HTTP_HEADER); if (expects != null) { return generateContinueResponse().build(); } // set the processor id as appropriate - final ClusterContext clusterContext = ClusterContextThreadLocal.getContext(); - if (clusterContext != null) { - snippetEntity.getSnippet().setId(UUID.nameUUIDFromBytes(clusterContext.getIdGenerationSeed().getBytes(StandardCharsets.UTF_8)).toString()); - } else { - snippetEntity.getSnippet().setId(UUID.randomUUID().toString()); - } + snippetEntity.getSnippet().setId(generateUuid()); // create the snippet final SnippetEntity entity = serviceFacade.createSnippet(snippetEntity.getSnippet()); @@ -1961,14 +1914,14 @@ public class ProcessGroupResource extends ApplicationResource { } // handle expects request (usually from the cluster manager) - final String expects = httpServletRequest.getHeader(WebClusterManager.NCM_EXPECTS_HTTP_HEADER); + final String expects = httpServletRequest.getHeader(RequestReplicator.REQUEST_VALIDATION_HTTP_HEADER); if (expects != null) { return generateContinueResponse().build(); } // copy the specified snippet final FlowEntity flowEntity = serviceFacade.copySnippet( - groupId, copySnippetEntity.getSnippetId(), copySnippetEntity.getOriginX(), copySnippetEntity.getOriginY()); + groupId, copySnippetEntity.getSnippetId(), copySnippetEntity.getOriginX(), copySnippetEntity.getOriginY(), getIdGenerationSeed().orElse(null)); // get the snippet final FlowDTO flow = flowEntity.getFlow(); @@ -2044,14 +1997,14 @@ public class ProcessGroupResource extends ApplicationResource { } // handle expects request (usually from the cluster manager) - final String expects = httpServletRequest.getHeader(WebClusterManager.NCM_EXPECTS_HTTP_HEADER); + final String expects = httpServletRequest.getHeader(RequestReplicator.REQUEST_VALIDATION_HTTP_HEADER); if (expects != null) { return generateContinueResponse().build(); } // create the template and generate the json final FlowEntity entity = serviceFacade.createTemplateInstance(groupId, instantiateTemplateRequestEntity.getOriginX(), - instantiateTemplateRequestEntity.getOriginY(), instantiateTemplateRequestEntity.getTemplateId()); + instantiateTemplateRequestEntity.getOriginY(), instantiateTemplateRequestEntity.getTemplateId(), getIdGenerationSeed().orElse(null)); final FlowDTO flowSnippet = entity.getFlow(); @@ -2170,14 +2123,14 @@ public class ProcessGroupResource extends ApplicationResource { } // handle expects request (usually from the cluster manager) - final String expects = httpServletRequest.getHeader(WebClusterManager.NCM_EXPECTS_HTTP_HEADER); + final String expects = httpServletRequest.getHeader(RequestReplicator.REQUEST_VALIDATION_HTTP_HEADER); if (expects != null) { return generateContinueResponse().build(); } // create the template and generate the json final TemplateDTO template = serviceFacade.createTemplate(createTemplateRequestEntity.getName(), createTemplateRequestEntity.getDescription(), - createTemplateRequestEntity.getSnippetId(), groupId); + createTemplateRequestEntity.getSnippetId(), groupId, getIdGenerationSeed()); templateResource.populateRemainingTemplateContent(template); // build the response entity @@ -2288,7 +2241,7 @@ public class ProcessGroupResource extends ApplicationResource { } // handle expects request (usually from the cluster manager) - final String expects = httpServletRequest.getHeader(WebClusterManager.NCM_EXPECTS_HTTP_HEADER); + final String expects = httpServletRequest.getHeader(RequestReplicator.REQUEST_VALIDATION_HTTP_HEADER); if (expects != null) { return generateContinueResponse().build(); } @@ -2300,7 +2253,7 @@ public class ProcessGroupResource extends ApplicationResource { } // import the template - final TemplateDTO template = serviceFacade.importTemplate(templateEntity.getTemplate(), groupId); + final TemplateDTO template = serviceFacade.importTemplate(templateEntity.getTemplate(), groupId, getIdGenerationSeed()); templateResource.populateRemainingTemplateContent(template); // build the response entity @@ -2387,18 +2340,13 @@ public class ProcessGroupResource extends ApplicationResource { } // handle expects request (usually from the cluster manager) - final String expects = httpServletRequest.getHeader(WebClusterManager.NCM_EXPECTS_HTTP_HEADER); + final String expects = httpServletRequest.getHeader(RequestReplicator.REQUEST_VALIDATION_HTTP_HEADER); if (expects != null) { return generateContinueResponse().build(); } // set the processor id as appropriate - final ClusterContext clusterContext = ClusterContextThreadLocal.getContext(); - if (clusterContext != null) { - controllerServiceEntity.getComponent().setId(UUID.nameUUIDFromBytes(clusterContext.getIdGenerationSeed().getBytes(StandardCharsets.UTF_8)).toString()); - } else { - controllerServiceEntity.getComponent().setId(UUID.randomUUID().toString()); - } + controllerServiceEntity.getComponent().setId(generateUuid()); // create the controller service and generate the json final ControllerServiceEntity entity = serviceFacade.createControllerService(groupId, controllerServiceEntity.getComponent()); http://git-wip-us.apache.org/repos/asf/nifi/blob/4b74e4de/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/ProvenanceResource.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/ProvenanceResource.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/ProvenanceResource.java index f0e3a25..a01f6e6 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/ProvenanceResource.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/ProvenanceResource.java @@ -16,14 +16,32 @@ */ 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.nifi.cluster.context.ClusterContext; -import org.apache.nifi.cluster.context.ClusterContextThreadLocal; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.URI; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +import javax.servlet.http.HttpServletRequest; +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.HttpMethod; +import javax.ws.rs.POST; +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.Response; +import javax.ws.rs.core.StreamingOutput; + +import org.apache.nifi.cluster.coordination.http.replication.RequestReplicator; import org.apache.nifi.cluster.manager.exception.UnknownNodeException; import org.apache.nifi.cluster.manager.impl.WebClusterManager; import org.apache.nifi.cluster.node.Node; @@ -47,31 +65,13 @@ 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.GET; -import javax.ws.rs.HttpMethod; -import javax.ws.rs.POST; -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.Response; -import javax.ws.rs.core.StreamingOutput; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.net.URI; -import java.nio.charset.StandardCharsets; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; -import java.util.UUID; +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; + /** * RESTful endpoint for querying data provenance. @@ -210,7 +210,7 @@ public class ProvenanceResource extends ApplicationResource { } // handle expects request (usually from the cluster manager) - final String expects = httpServletRequest.getHeader(WebClusterManager.NCM_EXPECTS_HTTP_HEADER); + final String expects = httpServletRequest.getHeader(RequestReplicator.REQUEST_VALIDATION_HTTP_HEADER); if (expects != null) { return generateContinueResponse().build(); } @@ -489,19 +489,13 @@ public class ProvenanceResource extends ApplicationResource { } // handle expects request (usually from the cluster manager) - final String expects = httpServletRequest.getHeader(WebClusterManager.NCM_EXPECTS_HTTP_HEADER); + final String expects = httpServletRequest.getHeader(RequestReplicator.REQUEST_VALIDATION_HTTP_HEADER); if (expects != null) { return generateContinueResponse().build(); } // ensure the id is the same across the cluster - final String provenanceId; - final ClusterContext clusterContext = ClusterContextThreadLocal.getContext(); - if (clusterContext != null) { - provenanceId = UUID.nameUUIDFromBytes(clusterContext.getIdGenerationSeed().getBytes(StandardCharsets.UTF_8)).toString(); - } else { - provenanceId = UUID.randomUUID().toString(); - } + final String provenanceId = generateUuid(); // set the provenance id accordingly provenanceDto.setId(provenanceId); @@ -657,7 +651,7 @@ public class ProvenanceResource extends ApplicationResource { } // handle expects request (usually from the cluster manager) - final String expects = httpServletRequest.getHeader(WebClusterManager.NCM_EXPECTS_HTTP_HEADER); + final String expects = httpServletRequest.getHeader(RequestReplicator.REQUEST_VALIDATION_HTTP_HEADER); if (expects != null) { return generateContinueResponse().build(); } @@ -847,7 +841,7 @@ public class ProvenanceResource extends ApplicationResource { } // handle expects request (usually from the cluster manager) - final String expects = httpServletRequest.getHeader(WebClusterManager.NCM_EXPECTS_HTTP_HEADER); + final String expects = httpServletRequest.getHeader(RequestReplicator.REQUEST_VALIDATION_HTTP_HEADER); if (expects != null) { return generateContinueResponse().build(); } @@ -999,7 +993,7 @@ public class ProvenanceResource extends ApplicationResource { } // handle expects request (usually from the cluster manager) - final String expects = httpServletRequest.getHeader(WebClusterManager.NCM_EXPECTS_HTTP_HEADER); + final String expects = httpServletRequest.getHeader(RequestReplicator.REQUEST_VALIDATION_HTTP_HEADER); if (expects != null) { return generateContinueResponse().build(); } http://git-wip-us.apache.org/repos/asf/nifi/blob/4b74e4de/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/dao/SnippetDAO.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/dao/SnippetDAO.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/dao/SnippetDAO.java index a3cbed4..7e21440 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/dao/SnippetDAO.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/dao/SnippetDAO.java @@ -29,9 +29,10 @@ public interface SnippetDAO { * @param snippetId snippet id * @param originX x * @param originY y + * @param idGenerationSeed the seed to use for generating UUID's. May be null. * @return snippet */ - FlowSnippetDTO copySnippet(String groupId, String snippetId, Double originX, Double originY); + FlowSnippetDTO copySnippet(String groupId, String snippetId, Double originX, Double originY, String idGenerationSeed); /** * Creates a snippet. http://git-wip-us.apache.org/repos/asf/nifi/blob/4b74e4de/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/dao/TemplateDAO.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/dao/TemplateDAO.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/dao/TemplateDAO.java index 02e8f0a..9f44f8a 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/dao/TemplateDAO.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/dao/TemplateDAO.java @@ -49,9 +49,10 @@ public interface TemplateDAO { * @param originX x * @param originY y * @param templateId template id + * @param idGenerationSeed the seed to use for generating UUID's. May be null. * @return flow snippet */ - FlowSnippetDTO instantiateTemplate(String groupId, Double originX, Double originY, String templateId); + FlowSnippetDTO instantiateTemplate(String groupId, Double originX, Double originY, String templateId, String idGenerationSeed); /** * Gets the specified template. http://git-wip-us.apache.org/repos/asf/nifi/blob/4b74e4de/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/dao/impl/StandardSnippetDAO.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/dao/impl/StandardSnippetDAO.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/dao/impl/StandardSnippetDAO.java index f4b0582..fa3da71 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/dao/impl/StandardSnippetDAO.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/dao/impl/StandardSnippetDAO.java @@ -59,7 +59,7 @@ public class StandardSnippetDAO implements SnippetDAO { } @Override - public FlowSnippetDTO copySnippet(final String groupId, final String snippetId, final Double originX, final Double originY) { + public FlowSnippetDTO copySnippet(final String groupId, final String snippetId, final Double originX, final Double originY, final String idGenerationSeed) { try { // ensure the parent group exist final ProcessGroup processGroup = flowController.getGroup(groupId); @@ -85,7 +85,7 @@ public class StandardSnippetDAO implements SnippetDAO { lookupSensitiveProperties(snippetContents); // copy snippet - snippetContents = snippetUtils.copy(snippetContents, processGroup); + snippetContents = snippetUtils.copy(snippetContents, processGroup, idGenerationSeed); // move the snippet if necessary if (originX != null && originY != null) { http://git-wip-us.apache.org/repos/asf/nifi/blob/4b74e4de/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/dao/impl/StandardTemplateDAO.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/dao/impl/StandardTemplateDAO.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/dao/impl/StandardTemplateDAO.java index 42b5da3..b2fd681 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/dao/impl/StandardTemplateDAO.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/dao/impl/StandardTemplateDAO.java @@ -72,7 +72,7 @@ public class StandardTemplateDAO extends ComponentDAO implements TemplateDAO { } @Override - public FlowSnippetDTO instantiateTemplate(String groupId, Double originX, Double originY, String templateId) { + public FlowSnippetDTO instantiateTemplate(String groupId, Double originX, Double originY, String templateId, String idGenerationSeed) { ProcessGroup group = locateProcessGroup(flowController, groupId); // get the template id and find the template @@ -86,7 +86,7 @@ public class StandardTemplateDAO extends ComponentDAO implements TemplateDAO { try { // copy the template which pre-processes all ids TemplateDTO templateDetails = template.getDetails(); - FlowSnippetDTO snippet = snippetUtils.copy(templateDetails.getSnippet(), group); + FlowSnippetDTO snippet = snippetUtils.copy(templateDetails.getSnippet(), group, idGenerationSeed); // reposition the template contents org.apache.nifi.util.SnippetUtils.moveSnippet(snippet, originX, originY); http://git-wip-us.apache.org/repos/asf/nifi/blob/4b74e4de/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/filter/NodeRequestFilter.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/filter/NodeRequestFilter.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/filter/NodeRequestFilter.java deleted file mode 100644 index a072293..0000000 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/filter/NodeRequestFilter.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.nifi.web.filter; - -import java.io.IOException; -import java.io.Serializable; -import javax.servlet.Filter; -import javax.servlet.FilterChain; -import javax.servlet.FilterConfig; -import javax.servlet.ServletException; -import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import org.apache.nifi.cluster.context.ClusterContext; -import org.apache.nifi.cluster.context.ClusterContextThreadLocal; -import org.apache.nifi.cluster.manager.impl.WebClusterManager; -import org.apache.nifi.logging.NiFiLog; -import org.apache.nifi.util.NiFiProperties; -import org.apache.nifi.web.NiFiServiceFacade; -import org.apache.nifi.web.util.WebUtils; -import org.apache.commons.lang3.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.context.ApplicationContext; -import org.springframework.web.context.support.WebApplicationContextUtils; - -/** - * A filter that prevents direct access to nodes (i.e., flow controllers connected to a cluster). Direct access to nodes by clients external to the cluster is prevented because the dataflow must be - * identical across the cluster. - * - * Direct access to a node is determined by the presence of a custom request header. The header key is "X-CLUSTER_MANAGER" and the value can be anything/empty. The presence of this header is a simple - * way to flag that the request was issued by the cluster manager and may proceed to the next filter. - * - * Since this header may be faked, we only make decisions about the header if the application instance is a node and connected to the cluster. - * - */ -public class NodeRequestFilter implements Filter { - - private static final Logger logger = new NiFiLog(LoggerFactory.getLogger(NodeRequestFilter.class)); - - private FilterConfig config; - - @Override - public void doFilter(final ServletRequest req, final ServletResponse resp, final FilterChain filterChain) - throws IOException, ServletException { - - ApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(config.getServletContext()); - NiFiProperties properties = ctx.getBean("nifiProperties", NiFiProperties.class); - - HttpServletRequest httpReq = (HttpServletRequest) req; - HttpServletResponse httpResp = (HttpServletResponse) resp; - - if (properties.isClusterManager() || "HEAD".equalsIgnoreCase(httpReq.getMethod())) { - filterChain.doFilter(req, resp); - } else { - - NiFiServiceFacade serviceFacade = ctx.getBean("serviceFacade", NiFiServiceFacade.class); - - if (!serviceFacade.isClustered()) { - filterChain.doFilter(req, resp); - } else { - // get the cluster context from the request - ClusterContext clusterContext = null; - String clusterContextHeaderValue = httpReq.getHeader(WebClusterManager.CLUSTER_CONTEXT_HTTP_HEADER); - if (StringUtils.isNotBlank(clusterContextHeaderValue)) { - try { - // deserialize object - Serializable clusterContextObj = WebUtils.deserializeHexToObject(clusterContextHeaderValue); - if (clusterContextObj instanceof ClusterContext) { - clusterContext = (ClusterContext) clusterContextObj; - } - } catch (final ClassNotFoundException cnfe) { - logger.warn("Failed to deserialize cluster context from request due to: " + cnfe, cnfe); - } - } - - // if don't have a cluster context or the context indicates - if (clusterContext == null || !clusterContext.isRequestSentByClusterManager()) { - // node is connected and request is not from cluster manager, so respond with error - httpResp.setContentType("text/plain"); - httpResp.setStatus(HttpServletResponse.SC_FORBIDDEN); - httpResp.getWriter().print("Direct access to Flow Controller node is only permissible if node is disconnected."); - } else { - ClusterContextThreadLocal.setContext(clusterContext); - filterChain.doFilter(req, resp); - } - } - } - } - - @Override - public void init(final FilterConfig config) { - this.config = config; - } - - @Override - public void destroy() { - } -} http://git-wip-us.apache.org/repos/asf/nifi/blob/4b74e4de/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/filter/ThreadLocalFilter.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/filter/ThreadLocalFilter.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/filter/ThreadLocalFilter.java deleted file mode 100644 index 053727b..0000000 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/filter/ThreadLocalFilter.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.nifi.web.filter; - -import java.io.IOException; -import javax.servlet.Filter; -import javax.servlet.FilterChain; -import javax.servlet.FilterConfig; -import javax.servlet.ServletException; -import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; -import org.apache.nifi.cluster.context.ClusterContextThreadLocal; - -/** - * A filter to remove the threadlocal configuration. - * - */ -public class ThreadLocalFilter implements Filter { - - @Override - public void doFilter(final ServletRequest req, final ServletResponse resp, final FilterChain filterChain) - throws IOException, ServletException { - try { - filterChain.doFilter(req, resp); - } finally { - ClusterContextThreadLocal.removeContext(); - } - - } - - @Override - public void init(final FilterConfig config) { - } - - @Override - public void destroy() { - } - -} http://git-wip-us.apache.org/repos/asf/nifi/blob/4b74e4de/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/filter/TimerFilter.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/filter/TimerFilter.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/filter/TimerFilter.java index a50d1b9..a5bf7e5 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/filter/TimerFilter.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/filter/TimerFilter.java @@ -27,9 +27,8 @@ import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; import javax.servlet.http.HttpServletRequest; -import org.apache.nifi.cluster.manager.impl.WebClusterManager; +import org.apache.nifi.cluster.coordination.http.replication.RequestReplicator; import org.apache.nifi.logging.NiFiLog; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -52,9 +51,9 @@ public class TimerFilter implements Filter { filterChain.doFilter(req, resp); } finally { final long stop = System.nanoTime(); - final String requestId = ((HttpServletRequest) req).getHeader(WebClusterManager.REQUEST_ID_HEADER); - logger.debug("{} {} from {} request duration: {} millis", request.getMethod(), request.getRequestURL().toString(), - req.getRemoteHost(), TimeUnit.MILLISECONDS.convert(stop - start, TimeUnit.NANOSECONDS)); + final String requestId = ((HttpServletRequest) req).getHeader(RequestReplicator.REQUEST_TRANSACTION_ID_HEADER); + logger.debug("{} {} from {} request duration for Request ID {}: {} millis", request.getMethod(), request.getRequestURL().toString(), + req.getRemoteHost(), requestId, TimeUnit.MILLISECONDS.convert(stop - start, TimeUnit.NANOSECONDS)); } } http://git-wip-us.apache.org/repos/asf/nifi/blob/4b74e4de/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/util/SnippetUtils.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/util/SnippetUtils.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/util/SnippetUtils.java index 44cbb52..9aaf43f 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/util/SnippetUtils.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/util/SnippetUtils.java @@ -27,8 +27,6 @@ import java.util.Map; import java.util.Set; import java.util.UUID; -import org.apache.nifi.cluster.context.ClusterContext; -import org.apache.nifi.cluster.context.ClusterContextThreadLocal; import org.apache.nifi.components.PropertyDescriptor; import org.apache.nifi.connectable.ConnectableType; import org.apache.nifi.connectable.Connection; @@ -291,8 +289,8 @@ public final class SnippetUtils { return false; } - public FlowSnippetDTO copy(final FlowSnippetDTO snippetContents, final ProcessGroup group) { - final FlowSnippetDTO snippetCopy = copyContentsForGroup(snippetContents, group.getIdentifier(), null, null); + public FlowSnippetDTO copy(final FlowSnippetDTO snippetContents, final ProcessGroup group, final String idGenerationSeed) { + final FlowSnippetDTO snippetCopy = copyContentsForGroup(snippetContents, group.getIdentifier(), null, null, idGenerationSeed); resolveNameConflicts(snippetCopy, group); return snippetCopy; } @@ -347,7 +345,8 @@ public final class SnippetUtils { } } - private FlowSnippetDTO copyContentsForGroup(final FlowSnippetDTO snippetContents, final String groupId, final Map<String, ConnectableDTO> parentConnectableMap, Map<String, String> serviceIdMap) { + private FlowSnippetDTO copyContentsForGroup(final FlowSnippetDTO snippetContents, final String groupId, final Map<String, ConnectableDTO> parentConnectableMap, Map<String, String> serviceIdMap, + String idGenerationSeed) { final FlowSnippetDTO snippetContentsCopy = new FlowSnippetDTO(); // @@ -359,7 +358,7 @@ public final class SnippetUtils { if (snippetContents.getControllerServices() != null) { for (final ControllerServiceDTO serviceDTO : snippetContents.getControllerServices()) { final ControllerServiceDTO service = dtoFactory.copy(serviceDTO); - service.setId(generateId(serviceDTO.getId())); + service.setId(generateId(serviceDTO.getId(), idGenerationSeed)); service.setState(ControllerServiceState.DISABLED.name()); services.add(service); @@ -396,7 +395,7 @@ public final class SnippetUtils { if (snippetContents.getLabels() != null) { for (final LabelDTO labelDTO : snippetContents.getLabels()) { final LabelDTO label = dtoFactory.copy(labelDTO); - label.setId(generateId(labelDTO.getId())); + label.setId(generateId(labelDTO.getId(), idGenerationSeed)); label.setParentGroupId(groupId); labels.add(label); } @@ -416,7 +415,7 @@ public final class SnippetUtils { if (snippetContents.getFunnels() != null) { for (final FunnelDTO funnelDTO : snippetContents.getFunnels()) { final FunnelDTO cp = dtoFactory.copy(funnelDTO); - cp.setId(generateId(funnelDTO.getId())); + cp.setId(generateId(funnelDTO.getId(), idGenerationSeed)); cp.setParentGroupId(groupId); funnels.add(cp); @@ -429,7 +428,7 @@ public final class SnippetUtils { if (snippetContents.getInputPorts() != null) { for (final PortDTO portDTO : snippetContents.getInputPorts()) { final PortDTO cp = dtoFactory.copy(portDTO); - cp.setId(generateId(portDTO.getId())); + cp.setId(generateId(portDTO.getId(), idGenerationSeed)); cp.setParentGroupId(groupId); cp.setState(ScheduledState.STOPPED.toString()); inputPorts.add(cp); @@ -447,7 +446,7 @@ public final class SnippetUtils { if (snippetContents.getOutputPorts() != null) { for (final PortDTO portDTO : snippetContents.getOutputPorts()) { final PortDTO cp = dtoFactory.copy(portDTO); - cp.setId(generateId(portDTO.getId())); + cp.setId(generateId(portDTO.getId(), idGenerationSeed)); cp.setParentGroupId(groupId); cp.setState(ScheduledState.STOPPED.toString()); outputPorts.add(cp); @@ -468,7 +467,7 @@ public final class SnippetUtils { if (snippetContents.getProcessors() != null) { for (final ProcessorDTO processorDTO : snippetContents.getProcessors()) { final ProcessorDTO cp = dtoFactory.copy(processorDTO); - cp.setId(generateId(processorDTO.getId())); + cp.setId(generateId(processorDTO.getId(), idGenerationSeed)); cp.setParentGroupId(groupId); cp.setState(ScheduledState.STOPPED.toString()); processors.add(cp); @@ -489,11 +488,11 @@ public final class SnippetUtils { if (snippetContents.getProcessGroups() != null) { for (final ProcessGroupDTO groupDTO : snippetContents.getProcessGroups()) { final ProcessGroupDTO cp = dtoFactory.copy(groupDTO, false); - cp.setId(generateId(groupDTO.getId())); + cp.setId(generateId(groupDTO.getId(), idGenerationSeed)); cp.setParentGroupId(groupId); // copy the contents of this group - we do not copy via the dto factory since we want to specify new ids - final FlowSnippetDTO contentsCopy = copyContentsForGroup(groupDTO.getContents(), cp.getId(), connectableMap, serviceIdMap); + final FlowSnippetDTO contentsCopy = copyContentsForGroup(groupDTO.getContents(), cp.getId(), connectableMap, serviceIdMap, idGenerationSeed); cp.setContents(contentsCopy); groups.add(cp); } @@ -504,7 +503,7 @@ public final class SnippetUtils { if (snippetContents.getRemoteProcessGroups() != null) { for (final RemoteProcessGroupDTO remoteGroupDTO : snippetContents.getRemoteProcessGroups()) { final RemoteProcessGroupDTO cp = dtoFactory.copy(remoteGroupDTO); - cp.setId(generateId(remoteGroupDTO.getId())); + cp.setId(generateId(remoteGroupDTO.getId(), idGenerationSeed)); cp.setParentGroupId(groupId); final RemoteProcessGroupContentsDTO contents = cp.getContents(); @@ -539,7 +538,7 @@ public final class SnippetUtils { throw new IllegalArgumentException("The flow snippet contains a Connection that references a component that is not included."); } - cp.setId(generateId(connectionDTO.getId())); + cp.setId(generateId(connectionDTO.getId(), idGenerationSeed)); cp.setSource(source); cp.setDestination(destination); cp.setParentGroupId(groupId); @@ -593,13 +592,11 @@ public final class SnippetUtils { /** * Generates a new id for the current id that is specified. If no seed is found, a new random id will be created. */ - private String generateId(final String currentId) { - final ClusterContext clusterContext = ClusterContextThreadLocal.getContext(); - if (clusterContext != null) { - final String seed = clusterContext.getIdGenerationSeed() + "-" + currentId; - return UUID.nameUUIDFromBytes(seed.getBytes(StandardCharsets.UTF_8)).toString(); - } else { + private String generateId(final String currentId, final String seed) { + if (seed == null) { return UUID.randomUUID().toString(); + } else { + return UUID.nameUUIDFromBytes(seed.getBytes(StandardCharsets.UTF_8)).toString(); } } http://git-wip-us.apache.org/repos/asf/nifi/blob/4b74e4de/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/resources/nifi-web-api-context.xml ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/resources/nifi-web-api-context.xml b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/resources/nifi-web-api-context.xml index 7578c10..08ce354 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/resources/nifi-web-api-context.xml +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/resources/nifi-web-api-context.xml @@ -38,7 +38,9 @@ </bean> <!-- revision manager --> - <bean id="revisionManager" class="org.apache.nifi.web.revision.NaiveRevisionManager" /> + <bean id="revisionManager" class="org.apache.nifi.web.revision.NaiveRevisionManager"> + <constructor-arg ref="nifiProperties"></constructor-arg> + </bean> <!-- content access --> <bean id="contentAccess" class="org.apache.nifi.web.StandardNiFiContentAccess"> http://git-wip-us.apache.org/repos/asf/nifi/blob/4b74e4de/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/webapp/WEB-INF/web.xml ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/webapp/WEB-INF/web.xml b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/webapp/WEB-INF/web.xml index 11a80c8..2f01bd4 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/webapp/WEB-INF/web.xml +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/webapp/WEB-INF/web.xml @@ -55,14 +55,6 @@ <url-pattern>/*</url-pattern> </filter-mapping> <filter> - <filter-name>threadLocal</filter-name> - <filter-class>org.apache.nifi.web.filter.ThreadLocalFilter</filter-class> - </filter> - <filter-mapping> - <filter-name>threadLocal</filter-name> - <url-pattern>/*</url-pattern> - </filter-mapping> - <filter> <filter-name>springSecurityFilterChain</filter-name> <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class> </filter> @@ -90,12 +82,4 @@ <filter-name>gzipCompressionFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> - <filter> - <filter-name>nodeRequestFilter</filter-name> - <filter-class>org.apache.nifi.web.filter.NodeRequestFilter</filter-class> - </filter> - <filter-mapping> - <filter-name>nodeRequestFilter</filter-name> - <url-pattern>/*</url-pattern> - </filter-mapping> </web-app> http://git-wip-us.apache.org/repos/asf/nifi/blob/4b74e4de/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-optimistic-locking/pom.xml ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-optimistic-locking/pom.xml b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-optimistic-locking/pom.xml index 78ab058..f38376b 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-optimistic-locking/pom.xml +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-optimistic-locking/pom.xml @@ -35,9 +35,5 @@ <groupId>org.apache.nifi</groupId> <artifactId>nifi-web-security</artifactId> </dependency> - <dependency> - <groupId>org.apache.nifi</groupId> - <artifactId>nifi-framework-cluster-web</artifactId> - </dependency> </dependencies> </project> http://git-wip-us.apache.org/repos/asf/nifi/blob/4b74e4de/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-optimistic-locking/src/main/java/org/apache/nifi/web/StandardOptimisticLockingManager.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-optimistic-locking/src/main/java/org/apache/nifi/web/StandardOptimisticLockingManager.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-optimistic-locking/src/main/java/org/apache/nifi/web/StandardOptimisticLockingManager.java index 3cc6aca..dd79fd4 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-optimistic-locking/src/main/java/org/apache/nifi/web/StandardOptimisticLockingManager.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-optimistic-locking/src/main/java/org/apache/nifi/web/StandardOptimisticLockingManager.java @@ -20,8 +20,6 @@ import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; import org.apache.nifi.authorization.user.NiFiUserUtils; -import org.apache.nifi.cluster.context.ClusterContext; -import org.apache.nifi.cluster.context.ClusterContextThreadLocal; import org.apache.nifi.web.revision.NaiveRevisionManager; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -115,13 +113,7 @@ public class StandardOptimisticLockingManager implements OptimisticLockingManage public FlowModification getLastModification() { lock(); try { - final Revision revision; - final ClusterContext ctx = ClusterContextThreadLocal.getContext(); - if (ctx == null || ctx.getRevision() == null) { - revision = currentRevision; - } else { - revision = ctx.getRevision(); - } + final Revision revision = currentRevision; return new FlowModification(revision, lastModifier); } finally { @@ -136,12 +128,7 @@ public class StandardOptimisticLockingManager implements OptimisticLockingManage lastModifier = lastModification.getLastModifier(); // record the updated revision in the cluster context if possible - final ClusterContext ctx = ClusterContextThreadLocal.getContext(); - if (ctx != null) { - ctx.setRevision(lastModification.getRevision()); - } else { - currentRevision = lastModification.getRevision(); - } + currentRevision = lastModification.getRevision(); } finally { unlock(); }
