You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by mc...@apache.org on 2016/06/03 19:30:19 UTC
[18/18] nifi git commit: NIFI-1897: - Refactoring to allow requests
to be replicated from a node to other nodes - Renaming cluster node
connection/read timeout properties. - Renaming NCM DN to Cluster Coordinator
DN. - Fixing default values in properties
NIFI-1897:
- Refactoring to allow requests to be replicated from a node to other nodes
- Renaming cluster node connection/read timeout properties.
- Renaming NCM DN to Cluster Coordinator DN.
- Fixing default values in properties.
- Starting to fix Spring context to load correctly in standalone mode.
- Using the cluster protocol to handle connection failures instead of heartbeats.
- Ensured replicate call is returned from ControllerResource.
- Ensure the appropriate classloader when serializing templates.
- Handling when the flow contents are null.
- This closes #488
Project: http://git-wip-us.apache.org/repos/asf/nifi/repo
Commit: http://git-wip-us.apache.org/repos/asf/nifi/commit/df0e4e79
Tree: http://git-wip-us.apache.org/repos/asf/nifi/tree/df0e4e79
Diff: http://git-wip-us.apache.org/repos/asf/nifi/diff/df0e4e79
Branch: refs/heads/master
Commit: df0e4e7960f715a8cf7d1ae38250b7122b3a0e47
Parents: cd01173
Author: Mark Payne <ma...@hotmail.com>
Authored: Thu May 19 10:42:39 2016 -0400
Committer: Matt Gilman <ma...@gmail.com>
Committed: Fri Jun 3 15:29:16 2016 -0400
----------------------------------------------------------------------
.../main/java/org/apache/nifi/web/Revision.java | 1 +
nifi-assembly/pom.xml | 33 +-
.../org/apache/nifi/util/NiFiProperties.java | 172 +-
.../apache/nifi/io/socket/SocketListener.java | 8 +-
.../nifi/util/StandardProcessorTestRunner.java | 2 +-
.../apache/nifi/web/api/dto/ComponentDTO.java | 18 +
.../nifi/web/api/entity/ComponentEntity.java | 22 +
.../coordination/ClusterCoordinator.java | 203 ++
.../heartbeat/HeartbeatMonitor.java | 55 +
.../coordination/heartbeat/NodeHeartbeat.java | 66 +
.../cluster/coordination/node/ClusterRoles.java | 25 +
.../coordination/node/DisconnectionCode.java | 10 +
.../coordination/node/NodeConnectionState.java | 8 +-
.../coordination/node/NodeConnectionStatus.java | 105 +-
.../apache/nifi/cluster/event/NodeEvent.java | 30 +
.../protocol/AbstractNodeProtocolSender.java | 145 ++
.../ClusterCoordinationProtocolSender.java | 64 +
.../protocol/ClusterManagerProtocolSender.java | 75 -
.../nifi/cluster/protocol/ClusterNodes.java | 39 -
.../cluster/protocol/ComponentRevision.java | 104 +
.../cluster/protocol/ConnectionResponse.java | 46 +-
.../apache/nifi/cluster/protocol/Heartbeat.java | 14 +-
...usterCoordinationProtocolSenderListener.java | 111 +
.../impl/ClusterManagerProtocolSenderImpl.java | 263 ---
.../ClusterManagerProtocolSenderListener.java | 118 -
.../protocol/impl/ClusterServiceDiscovery.java | 180 --
.../protocol/impl/ClusterServiceLocator.java | 228 --
.../impl/ClusterServicesBroadcaster.java | 185 --
.../impl/MulticastProtocolListener.java | 203 --
.../protocol/impl/NodeProtocolSenderImpl.java | 159 --
.../impl/NodeProtocolSenderListener.java | 1 -
.../protocol/impl/SocketProtocolListener.java | 17 +-
...andardClusterCoordinationProtocolSender.java | 237 ++
.../jaxb/message/AdaptedConnectionResponse.java | 30 +-
.../protocol/jaxb/message/AdaptedHeartbeat.java | 12 +-
.../message/AdaptedNodeConnectionStatus.java | 30 +
.../jaxb/message/ConnectionResponseAdapter.java | 5 +-
.../protocol/jaxb/message/DataFlowAdapter.java | 8 +-
.../protocol/jaxb/message/HeartbeatAdapter.java | 4 +-
.../jaxb/message/JaxbProtocolUtils.java | 1 -
.../message/NodeConnectionStatusAdapter.java | 11 +-
.../message/ConnectionResponseMessage.java | 21 +-
.../message/NodeStatusChangeMessage.java | 32 +-
.../message/ReconnectionRequestMessage.java | 22 +
.../MulticastConfigurationFactoryBean.java | 60 -
.../ServerSocketConfigurationFactoryBean.java | 7 +-
.../spring/SocketConfigurationFactoryBean.java | 7 +-
.../resources/nifi-cluster-protocol-context.xml | 50 +-
.../ClusterManagerProtocolSenderImplTest.java | 133 --
.../impl/ClusterServiceDiscoveryTest.java | 134 --
.../impl/ClusterServiceLocatorTest.java | 121 -
.../impl/ClusterServicesBroadcasterTest.java | 131 --
.../impl/MulticastProtocolListenerTest.java | 168 --
.../impl/NodeProtocolSenderImplTest.java | 168 --
.../jaxb/message/TestJaxbProtocolUtils.java | 68 +
.../cluster/client/MulticastTestClient.java | 151 --
.../coordination/ClusterCoordinator.java | 136 --
.../heartbeat/AbstractHeartbeatMonitor.java | 86 +-
.../ClusterProtocolHeartbeatMonitor.java | 50 +-
.../heartbeat/CuratorHeartbeatMonitor.java | 376 ---
.../heartbeat/HeartbeatMonitor.java | 55 -
.../coordination/heartbeat/NodeHeartbeat.java | 64 -
.../heartbeat/StandardNodeHeartbeat.java | 16 +-
.../http/StandardHttpResponseMerger.java | 70 +-
.../endpoints/AbstractNodeStatusEndpoint.java | 9 +-
.../endpoints/AbstractSingleDTOEndpoint.java | 115 +
.../endpoints/AbstractSingleEntityEndpoint.java | 56 +-
.../endpoints/BulletinBoardEndpointMerger.java | 2 +-
.../endpoints/ComponentStateEndpointMerger.java | 2 +-
.../ControllerServiceEndpointMerger.java | 2 +-
.../ControllerStatusEndpointMerger.java | 9 +-
.../endpoints/DropRequestEndpiontMerger.java | 2 +-
.../coordination/http/endpoints/FlowMerger.java | 267 +++
.../endpoints/FlowSnippetEndpointMerger.java | 14 +-
.../endpoints/ListFlowFilesEndpointMerger.java | 2 +-
.../http/endpoints/ProcessorEndpointMerger.java | 17 +-
.../ProvenanceEventEndpointMerger.java | 2 +-
.../RemoteProcessGroupEndpointMerger.java | 2 +-
.../endpoints/ReportingTaskEndpointMerger.java | 2 +-
.../http/replication/RequestReplicator.java | 26 +-
.../ThreadPoolRequestReplicator.java | 137 +-
.../cluster/coordination/node/ClusterNode.java | 39 -
.../node/CuratorNodeProtocolSender.java | 116 +
.../node/NodeClusterCoordinator.java | 782 +++++++
.../coordination/node/NodeStateManager.java | 41 +
.../org/apache/nifi/cluster/event/Event.java | 43 +-
.../apache/nifi/cluster/event/EventManager.java | 62 -
.../cluster/event/impl/EventManagerImpl.java | 141 --
.../nifi/cluster/flow/ClusterDataFlow.java | 55 -
.../apache/nifi/cluster/flow/DaoException.java | 39 -
.../apache/nifi/cluster/flow/DataFlowDao.java | 60 -
.../cluster/flow/DataFlowManagementService.java | 124 -
.../nifi/cluster/flow/PersistedFlowState.java | 36 -
.../nifi/cluster/flow/StaleFlowException.java | 40 -
.../nifi/cluster/flow/impl/DataFlowDaoImpl.java | 595 -----
.../impl/DataFlowManagementServiceImpl.java | 403 ----
.../nifi/cluster/manager/ClusterManager.java | 142 --
.../cluster/manager/HttpClusterManager.java | 129 --
.../cluster/manager/HttpRequestReplicator.java | 84 -
.../cluster/manager/HttpResponseMapper.java | 41 -
.../nifi/cluster/manager/NodeResponse.java | 48 +-
.../exception/BlockedByFirewallException.java | 2 +-
.../IneligiblePrimaryNodeException.java | 39 -
.../PrimaryRoleAssignmentException.java | 39 -
.../SafeModeMutableRequestException.java | 39 -
.../manager/impl/ClusteredEventAccess.java | 146 --
.../manager/impl/ClusteredReportingContext.java | 217 --
.../manager/impl/HttpRequestReplicatorImpl.java | 512 -----
.../manager/impl/HttpResponseMapperImpl.java | 82 -
.../cluster/manager/impl/WebClusterManager.java | 2159 ------------------
.../impl/WebClusterManagerCoordinator.java | 264 ---
.../java/org/apache/nifi/cluster/node/Node.java | 190 --
...anagerProtocolServiceLocatorFactoryBean.java | 113 -
...FileBasedClusterNodeFirewallFactoryBean.java | 2 +-
.../spring/HeartbeatMonitorFactoryBean.java | 68 +
.../NodeClusterCoordinatorFactoryBean.java | 71 +
.../ThreadPoolRequestReplicatorFactoryBean.java | 78 +
.../spring/WebClusterManagerFactoryBean.java | 118 -
.../reporting/ClusteredReportingTaskNode.java | 75 -
.../resources/nifi-cluster-manager-context.xml | 61 +-
.../heartbeat/TestAbstractHeartbeatMonitor.java | 131 +-
.../heartbeat/TestCuratorHeartbeatMonitor.java | 355 ---
.../TestThreadPoolRequestReplicator.java | 115 +-
.../node/TestNodeClusterCoordinator.java | 497 ++++
.../event/impl/EventManagerImplTest.java | 121 -
.../impl/DataFlowManagementServiceImplTest.java | 344 ---
.../impl/HttpRequestReplicatorImplTest.java | 374 ---
.../impl/HttpResponseMapperImplTest.java | 128 --
.../org/apache/nifi/lifecycle/LifeCycle.java | 46 +
.../nifi/lifecycle/LifeCycleException.java | 46 +
.../nifi/lifecycle/LifeCycleStartException.java | 46 +
.../nifi/lifecycle/LifeCycleStopException.java | 46 +
.../org/apache/nifi/services/FlowService.java | 120 +
.../org/apache/nifi/web/FlowModification.java | 61 +
.../nifi/web/revision/DeleteRevisionTask.java | 24 +
.../revision/ExpiredRevisionClaimException.java | 28 +
.../web/revision/ReadOnlyRevisionCallback.java | 34 +
.../apache/nifi/web/revision/RevisionClaim.java | 26 +
.../nifi/web/revision/RevisionManager.java | 222 ++
.../nifi/web/revision/RevisionUpdate.java | 43 +
.../nifi/web/revision/UpdateRevisionTask.java | 64 +
.../apache/nifi/controller/FlowController.java | 295 +--
.../nifi/controller/StandardFlowService.java | 354 +--
.../cluster/ClusterProtocolHeartbeater.java | 3 +-
.../nifi/controller/cluster/Heartbeater.java | 4 +
.../election/CuratorLeaderElectionManager.java | 16 +-
.../nifi/events/StandardEventReporter.java | 38 +
.../nifi/groups/StandardProcessGroup.java | 1 +
.../org/apache/nifi/lifecycle/LifeCycle.java | 46 -
.../nifi/lifecycle/LifeCycleException.java | 46 -
.../nifi/lifecycle/LifeCycleStartException.java | 46 -
.../nifi/lifecycle/LifeCycleStopException.java | 46 -
.../StandardXMLFlowConfigurationDAO.java | 5 +
.../nifi/persistence/TemplateSerializer.java | 20 +-
.../org/apache/nifi/services/FlowService.java | 124 -
.../nifi/spring/FlowControllerFactoryBean.java | 39 +-
.../spring/StandardFlowServiceFactoryBean.java | 35 +-
.../src/main/resources/nifi-context.xml | 7 +
.../controller/StandardFlowServiceTest.java | 9 +-
.../scheduling/TestProcessorLifecycle.java | 3 +-
.../src/main/resources/conf/bootstrap.conf | 10 +-
.../src/main/resources/conf/logback.xml | 1 +
.../src/main/resources/conf/nifi.properties | 37 +-
.../org/apache/nifi/web/server/JettyServer.java | 51 +-
.../org/apache/nifi/web/NiFiServiceFacade.java | 18 +
.../nifi/web/StandardNiFiContentAccess.java | 69 +-
.../nifi/web/StandardNiFiServiceFacade.java | 157 +-
.../StandardNiFiWebConfigurationContext.java | 101 +-
.../apache/nifi/web/StandardNiFiWebContext.java | 46 +-
.../nifi/web/api/ApplicationResource.java | 292 ++-
.../apache/nifi/web/api/ClusterResource.java | 136 +-
.../apache/nifi/web/api/ConnectionResource.java | 80 +-
.../apache/nifi/web/api/ControllerResource.java | 63 +-
.../nifi/web/api/ControllerServiceResource.java | 110 +-
.../nifi/web/api/FlowFileQueueResource.java | 129 +-
.../org/apache/nifi/web/api/FlowResource.java | 260 +--
.../org/apache/nifi/web/api/FunnelResource.java | 71 +-
.../apache/nifi/web/api/InputPortResource.java | 67 +-
.../org/apache/nifi/web/api/LabelResource.java | 71 +-
.../org/apache/nifi/web/api/NodeResource.java | 219 ++
.../apache/nifi/web/api/OutputPortResource.java | 71 +-
.../nifi/web/api/ProcessGroupResource.java | 212 +-
.../apache/nifi/web/api/ProcessorResource.java | 132 +-
.../apache/nifi/web/api/ProvenanceResource.java | 238 +-
.../web/api/RemoteProcessGroupResource.java | 83 +-
.../nifi/web/api/ReportingTaskResource.java | 94 +-
.../apache/nifi/web/api/ResourceResource.java | 45 +-
.../apache/nifi/web/api/SiteToSiteResource.java | 38 +-
.../apache/nifi/web/api/SnippetResource.java | 60 +-
.../nifi/web/api/SystemDiagnosticsResource.java | 67 +-
.../apache/nifi/web/api/TemplateResource.java | 56 +-
.../IneligiblePrimaryNodeExceptionMapper.java | 47 -
.../api/config/InterruptedExceptionMapper.java | 43 +
.../PrimaryRoleAssignmentExceptionMapper.java | 47 -
.../SafeModeMutableRequestExceptionMapper.java | 48 -
.../org/apache/nifi/web/api/dto/DtoFactory.java | 79 +-
.../ApplicationStartupContextListener.java | 154 +-
.../nifi/web/controller/ControllerFacade.java | 62 +-
.../ControllerServiceProviderFactoryBean.java | 19 +-
.../OptimisticLockingManagerFactoryBean.java | 67 -
.../ReportingTaskProviderFactoryBean.java | 19 +-
.../spring/StateManagerProviderFactoryBean.java | 26 +-
.../src/main/resources/nifi-web-api-context.xml | 109 +-
.../org/apache/nifi/web/FlowModification.java | 61 -
.../web/StandardOptimisticLockingManager.java | 149 --
.../nifi/web/revision/DeleteRevisionTask.java | 24 -
.../revision/ExpiredRevisionClaimException.java | 28 -
.../nifi/web/revision/NaiveRevisionManager.java | 60 +-
.../web/revision/ReadOnlyRevisionCallback.java | 34 -
.../apache/nifi/web/revision/RevisionClaim.java | 26 -
.../nifi/web/revision/RevisionManager.java | 210 --
.../nifi/web/revision/RevisionUpdate.java | 43 -
.../nifi/web/revision/UpdateRevisionTask.java | 64 -
.../web/revision/TestNaiveRevisionManager.java | 111 +-
214 files changed, 7101 insertions(+), 14656 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/nifi/blob/df0e4e79/nifi-api/src/main/java/org/apache/nifi/web/Revision.java
----------------------------------------------------------------------
diff --git a/nifi-api/src/main/java/org/apache/nifi/web/Revision.java b/nifi-api/src/main/java/org/apache/nifi/web/Revision.java
index 4c47dde..1308e1b 100644
--- a/nifi-api/src/main/java/org/apache/nifi/web/Revision.java
+++ b/nifi-api/src/main/java/org/apache/nifi/web/Revision.java
@@ -27,6 +27,7 @@ import java.util.Objects;
* @Threadsafe
*/
public class Revision implements Serializable {
+ private static final long serialVersionUID = 988658790374170022L;
/**
* the version number
http://git-wip-us.apache.org/repos/asf/nifi/blob/df0e4e79/nifi-assembly/pom.xml
----------------------------------------------------------------------
diff --git a/nifi-assembly/pom.xml b/nifi-assembly/pom.xml
index d226726..7f097cb 100644
--- a/nifi-assembly/pom.xml
+++ b/nifi-assembly/pom.xml
@@ -447,37 +447,18 @@ language governing permissions and limitations under the License. -->
<!-- nifi.properties: cluster common properties (cluster manager and nodes must have same values) -->
<nifi.cluster.protocol.heartbeat.interval>5 sec</nifi.cluster.protocol.heartbeat.interval>
<nifi.cluster.protocol.is.secure>false</nifi.cluster.protocol.is.secure>
- <nifi.cluster.protocol.socket.timeout>30 sec</nifi.cluster.protocol.socket.timeout>
- <nifi.cluster.protocol.connection.handshake.timeout>45 sec</nifi.cluster.protocol.connection.handshake.timeout>
- <nifi.cluster.protocol.use.multicast>false</nifi.cluster.protocol.use.multicast>
- <nifi.cluster.protocol.multicast.address />
- <nifi.cluster.protocol.multicast.port />
- <nifi.cluster.protocol.multicast.service.broadcast.delay>500 ms</nifi.cluster.protocol.multicast.service.broadcast.delay>
- <nifi.cluster.protocol.multicast.service.locator.attempts>3</nifi.cluster.protocol.multicast.service.locator.attempts>
- <nifi.cluster.protocol.multicast.service.locator.attempts.delay>1 sec</nifi.cluster.protocol.multicast.service.locator.attempts.delay>
<!-- nifi.properties: cluster node properties (only configure for cluster nodes) -->
<nifi.cluster.is.node>false</nifi.cluster.is.node>
<nifi.cluster.node.address />
<nifi.cluster.node.protocol.port />
- <nifi.cluster.node.protocol.threads>2</nifi.cluster.node.protocol.threads>
- <nifi.cluster.node.unicast.manager.address />
- <nifi.cluster.node.unicast.manager.protocol.port />
-
- <!-- nifi.properties: cluster manager properties (only configure for cluster manager) -->
- <nifi.cluster.is.manager>false</nifi.cluster.is.manager>
- <nifi.cluster.manager.address />
- <nifi.cluster.manager.protocol.port />
- <nifi.cluster.manager.node.firewall.file />
- <nifi.cluster.manager.node.event.history.size>10</nifi.cluster.manager.node.event.history.size>
- <nifi.cluster.manager.node.api.connection.timeout>30 sec</nifi.cluster.manager.node.api.connection.timeout>
- <nifi.cluster.manager.node.api.read.timeout>30 sec</nifi.cluster.manager.node.api.read.timeout>
- <nifi.cluster.manager.node.api.request.threads>10</nifi.cluster.manager.node.api.request.threads>
- <nifi.cluster.manager.flow.retrieval.delay>5 sec</nifi.cluster.manager.flow.retrieval.delay>
- <nifi.cluster.manager.protocol.threads>10</nifi.cluster.manager.protocol.threads>
- <nifi.cluster.manager.safemode.duration>0 sec</nifi.cluster.manager.safemode.duration>
-
- <nifi.cluster.request.replication.claim.timeout>1 min</nifi.cluster.request.replication.claim.timeout>
+ <nifi.cluster.node.protocol.threads>10</nifi.cluster.node.protocol.threads>
+ <nifi.cluster.node.event.history.size>25</nifi.cluster.node.event.history.size>
+ <nifi.cluster.node.connection.timeout>5 sec</nifi.cluster.node.connection.timeout>
+ <nifi.cluster.node.read.timeout>5 sec</nifi.cluster.node.read.timeout>
+ <nifi.cluster.firewall.file />
+
+ <nifi.cluster.request.replication.claim.timeout>15 secs</nifi.cluster.request.replication.claim.timeout>
<!-- nifi.properties: zookeeper properties -->
<nifi.zookeeper.connect.string></nifi.zookeeper.connect.string>
http://git-wip-us.apache.org/repos/asf/nifi/blob/df0e4e79/nifi-commons/nifi-properties/src/main/java/org/apache/nifi/util/NiFiProperties.java
----------------------------------------------------------------------
diff --git a/nifi-commons/nifi-properties/src/main/java/org/apache/nifi/util/NiFiProperties.java b/nifi-commons/nifi-properties/src/main/java/org/apache/nifi/util/NiFiProperties.java
index 1b560fc..8021cca 100644
--- a/nifi-commons/nifi-properties/src/main/java/org/apache/nifi/util/NiFiProperties.java
+++ b/nifi-commons/nifi-properties/src/main/java/org/apache/nifi/util/NiFiProperties.java
@@ -150,22 +150,16 @@ public class NiFiProperties extends Properties {
// cluster common properties
public static final String CLUSTER_PROTOCOL_HEARTBEAT_INTERVAL = "nifi.cluster.protocol.heartbeat.interval";
public static final String CLUSTER_PROTOCOL_IS_SECURE = "nifi.cluster.protocol.is.secure";
- public static final String CLUSTER_PROTOCOL_SOCKET_TIMEOUT = "nifi.cluster.protocol.socket.timeout";
- public static final String CLUSTER_PROTOCOL_CONNECTION_HANDSHAKE_TIMEOUT = "nifi.cluster.protocol.connection.handshake.timeout";
- public static final String CLUSTER_PROTOCOL_USE_MULTICAST = "nifi.cluster.protocol.use.multicast";
- public static final String CLUSTER_PROTOCOL_MULTICAST_ADDRESS = "nifi.cluster.protocol.multicast.address";
- public static final String CLUSTER_PROTOCOL_MULTICAST_PORT = "nifi.cluster.protocol.multicast.port";
- public static final String CLUSTER_PROTOCOL_MULTICAST_SERVICE_BROADCAST_DELAY = "nifi.cluster.protocol.multicast.service.broadcast.delay";
- public static final String CLUSTER_PROTOCOL_MULTICAST_SERVICE_LOCATOR_ATTEMPTS = "nifi.cluster.protocol.multicast.service.locator.attempts";
- public static final String CLUSTER_PROTOCOL_MULTICAST_SERVICE_LOCATOR_ATTEMPTS_DELAY = "nifi.cluster.protocol.multicast.service.locator.attempts.delay";
// cluster node properties
public static final String CLUSTER_IS_NODE = "nifi.cluster.is.node";
public static final String CLUSTER_NODE_ADDRESS = "nifi.cluster.node.address";
public static final String CLUSTER_NODE_PROTOCOL_PORT = "nifi.cluster.node.protocol.port";
public static final String CLUSTER_NODE_PROTOCOL_THREADS = "nifi.cluster.node.protocol.threads";
- public static final String CLUSTER_NODE_UNICAST_MANAGER_ADDRESS = "nifi.cluster.node.unicast.manager.address";
- public static final String CLUSTER_NODE_UNICAST_MANAGER_PROTOCOL_PORT = "nifi.cluster.node.unicast.manager.protocol.port";
+ public static final String REQUEST_REPLICATION_CLAIM_TIMEOUT = "nifi.cluster.request.replication.claim.timeout";
+ public static final String CLUSTER_NODE_CONNECTION_TIMEOUT = "nifi.cluster.node.connection.timeout";
+ public static final String CLUSTER_NODE_READ_TIMEOUT = "nifi.cluster.node.read.timeout";
+ public static final String CLUSTER_FIREWALL_FILE = "nifi.cluster.firewall.file";
// zookeeper properties
public static final String ZOOKEEPER_CONNECT_STRING = "nifi.zookeeper.connect.string";
@@ -173,20 +167,6 @@ public class NiFiProperties extends Properties {
public static final String ZOOKEEPER_SESSION_TIMEOUT = "nifi.zookeeper.session.timeout";
public static final String ZOOKEEPER_ROOT_NODE = "nifi.zookeeper.root.node";
- // cluster manager properties
- public static final String CLUSTER_IS_MANAGER = "nifi.cluster.is.manager";
- public static final String CLUSTER_MANAGER_ADDRESS = "nifi.cluster.manager.address";
- public static final String CLUSTER_MANAGER_PROTOCOL_PORT = "nifi.cluster.manager.protocol.port";
- public static final String CLUSTER_MANAGER_NODE_FIREWALL_FILE = "nifi.cluster.manager.node.firewall.file";
- public static final String CLUSTER_MANAGER_NODE_EVENT_HISTORY_SIZE = "nifi.cluster.manager.node.event.history.size";
- public static final String CLUSTER_MANAGER_NODE_API_CONNECTION_TIMEOUT = "nifi.cluster.manager.node.api.connection.timeout";
- public static final String CLUSTER_MANAGER_NODE_API_READ_TIMEOUT = "nifi.cluster.manager.node.api.read.timeout";
- public static final String CLUSTER_MANAGER_NODE_API_REQUEST_THREADS = "nifi.cluster.manager.node.api.request.threads";
- public static final String CLUSTER_MANAGER_FLOW_RETRIEVAL_DELAY = "nifi.cluster.manager.flow.retrieval.delay";
- public static final String CLUSTER_MANAGER_PROTOCOL_THREADS = "nifi.cluster.manager.protocol.threads";
- public static final String CLUSTER_MANAGER_SAFEMODE_DURATION = "nifi.cluster.manager.safemode.duration";
-
- public static final String REQUEST_REPLICATION_CLAIM_TIMEOUT = "nifi.cluster.request.replication.claim.timeout";
// kerberos properties
public static final String KERBEROS_KRB5_FILE = "nifi.kerberos.krb5.file";
@@ -236,22 +216,12 @@ public class NiFiProperties extends Properties {
public static final String DEFAULT_CLUSTER_PROTOCOL_MULTICAST_SERVICE_BROADCAST_DELAY = "500 ms";
public static final int DEFAULT_CLUSTER_PROTOCOL_MULTICAST_SERVICE_LOCATOR_ATTEMPTS = 3;
public static final String DEFAULT_CLUSTER_PROTOCOL_MULTICAST_SERVICE_LOCATOR_ATTEMPTS_DELAY = "1 sec";
- public static final String DEFAULT_CLUSTER_PROTOCOL_SOCKET_TIMEOUT = "30 sec";
- public static final String DEFAULT_CLUSTER_PROTOCOL_CONNECTION_HANDSHAKE_TIMEOUT = "45 sec";
+ public static final String DEFAULT_CLUSTER_NODE_READ_TIMEOUT = "5 sec";
+ public static final String DEFAULT_CLUSTER_NODE_CONNECTION_TIMEOUT = "5 sec";
// cluster node defaults
public static final int DEFAULT_CLUSTER_NODE_PROTOCOL_THREADS = 2;
-
- // cluster manager defaults
- public static final int DEFAULT_CLUSTER_MANAGER_NODE_EVENT_HISTORY_SIZE = 10;
- public static final String DEFAULT_CLUSTER_MANAGER_NODE_API_CONNECTION_TIMEOUT = "30 sec";
- public static final String DEFAULT_CLUSTER_MANAGER_NODE_API_READ_TIMEOUT = "30 sec";
- public static final int DEFAULT_CLUSTER_MANAGER_NODE_API_NUM_REQUEST_THREADS = 10;
- public static final String DEFAULT_CLUSTER_MANAGER_FLOW_RETRIEVAL_DELAY = "5 sec";
- public static final int DEFAULT_CLUSTER_MANAGER_PROTOCOL_THREADS = 10;
- public static final String DEFAULT_CLUSTER_MANAGER_SAFEMODE_DURATION = "0 sec";
-
- public static final String DEFAULT_REQUEST_REPLICATION_CLAIM_TIMEOUT = "1 min";
+ public static final String DEFAULT_REQUEST_REPLICATION_CLAIM_TIMEOUT = "15 secs";
// state management defaults
public static final String DEFAULT_STATE_MANAGEMENT_CONFIG_FILE = "conf/state-management.xml";
@@ -643,31 +613,13 @@ public class NiFiProperties extends Properties {
return getClusterProtocolHeartbeatInterval();
}
- public String getClusterProtocolSocketTimeout() {
- return getProperty(CLUSTER_PROTOCOL_SOCKET_TIMEOUT, DEFAULT_CLUSTER_PROTOCOL_SOCKET_TIMEOUT);
+ public String getClusterNodeReadTimeout() {
+ return getProperty(CLUSTER_NODE_READ_TIMEOUT, DEFAULT_CLUSTER_NODE_READ_TIMEOUT);
}
- public String getClusterProtocolConnectionHandshakeTimeout() {
- return getProperty(CLUSTER_PROTOCOL_CONNECTION_HANDSHAKE_TIMEOUT,
- DEFAULT_CLUSTER_PROTOCOL_CONNECTION_HANDSHAKE_TIMEOUT);
- }
-
- public boolean getClusterProtocolUseMulticast() {
- return Boolean.parseBoolean(getProperty(CLUSTER_PROTOCOL_USE_MULTICAST));
- }
-
- public InetSocketAddress getClusterProtocolMulticastAddress() {
- try {
- String multicastAddress = getProperty(CLUSTER_PROTOCOL_MULTICAST_ADDRESS);
- int multicastPort = Integer.parseInt(getProperty(CLUSTER_PROTOCOL_MULTICAST_PORT));
- return new InetSocketAddress(multicastAddress, multicastPort);
- } catch (Exception ex) {
- throw new RuntimeException("Invalid multicast address/port due to: " + ex, ex);
- }
- }
-
- public String getClusterProtocolMulticastServiceBroadcastDelay() {
- return getProperty(CLUSTER_PROTOCOL_MULTICAST_SERVICE_BROADCAST_DELAY);
+ public String getClusterNodeConnectionTimeout() {
+ return getProperty(CLUSTER_NODE_CONNECTION_TIMEOUT,
+ DEFAULT_CLUSTER_NODE_CONNECTION_TIMEOUT);
}
public File getPersistentStateDirectory() {
@@ -680,19 +632,6 @@ public class NiFiProperties extends Properties {
return file;
}
- public int getClusterProtocolMulticastServiceLocatorAttempts() {
- try {
- return Integer
- .parseInt(getProperty(CLUSTER_PROTOCOL_MULTICAST_SERVICE_LOCATOR_ATTEMPTS));
- } catch (NumberFormatException nfe) {
- return DEFAULT_CLUSTER_PROTOCOL_MULTICAST_SERVICE_LOCATOR_ATTEMPTS;
- }
- }
-
- public String getClusterProtocolMulticastServiceLocatorAttemptsDelay() {
- return getProperty(CLUSTER_PROTOCOL_MULTICAST_SERVICE_LOCATOR_ATTEMPTS_DELAY,
- DEFAULT_CLUSTER_PROTOCOL_MULTICAST_SERVICE_LOCATOR_ATTEMPTS_DELAY);
- }
// getters for cluster node properties //
public boolean isNode() {
@@ -728,48 +667,13 @@ public class NiFiProperties extends Properties {
}
}
- public InetSocketAddress getClusterNodeUnicastManagerProtocolAddress() {
- try {
- String socketAddress = getProperty(CLUSTER_NODE_UNICAST_MANAGER_ADDRESS);
- if (StringUtils.isBlank(socketAddress)) {
- socketAddress = "localhost";
- }
- int socketPort = Integer
- .parseInt(getProperty(CLUSTER_NODE_UNICAST_MANAGER_PROTOCOL_PORT));
- return InetSocketAddress.createUnresolved(socketAddress, socketPort);
- } catch (Exception ex) {
- throw new RuntimeException("Invalid unicast manager address/port due to: " + ex, ex);
- }
- }
-
- // getters for cluster manager properties //
- public boolean isClusterManager() {
- return Boolean.parseBoolean(getProperty(CLUSTER_IS_MANAGER));
- }
- public InetSocketAddress getClusterManagerProtocolAddress() {
- try {
- String socketAddress = getProperty(CLUSTER_MANAGER_ADDRESS);
- if (StringUtils.isBlank(socketAddress)) {
- socketAddress = "localhost";
- }
- int socketPort = getClusterManagerProtocolPort();
- return InetSocketAddress.createUnresolved(socketAddress, socketPort);
- } catch (Exception ex) {
- throw new RuntimeException("Invalid manager protocol address/port due to: " + ex, ex);
- }
- }
-
- public Integer getClusterManagerProtocolPort() {
- try {
- return Integer.parseInt(getProperty(CLUSTER_MANAGER_PROTOCOL_PORT));
- } catch (NumberFormatException nfe) {
- return null;
- }
+ public boolean isClustered() {
+ return Boolean.parseBoolean(getProperty(CLUSTER_IS_NODE));
}
- public File getClusterManagerNodeFirewallFile() {
- final String firewallFile = getProperty(CLUSTER_MANAGER_NODE_FIREWALL_FILE);
+ public File getClusterNodeFirewallFile() {
+ final String firewallFile = getProperty(CLUSTER_FIREWALL_FILE);
if (StringUtils.isBlank(firewallFile)) {
return null;
} else {
@@ -777,50 +681,6 @@ public class NiFiProperties extends Properties {
}
}
- public int getClusterManagerNodeEventHistorySize() {
- try {
- return Integer.parseInt(getProperty(CLUSTER_MANAGER_NODE_EVENT_HISTORY_SIZE));
- } catch (NumberFormatException nfe) {
- return DEFAULT_CLUSTER_MANAGER_NODE_EVENT_HISTORY_SIZE;
- }
- }
-
- public String getClusterManagerNodeApiConnectionTimeout() {
- return getProperty(CLUSTER_MANAGER_NODE_API_CONNECTION_TIMEOUT,
- DEFAULT_CLUSTER_MANAGER_NODE_API_CONNECTION_TIMEOUT);
- }
-
- public String getClusterManagerNodeApiReadTimeout() {
- return getProperty(CLUSTER_MANAGER_NODE_API_READ_TIMEOUT,
- DEFAULT_CLUSTER_MANAGER_NODE_API_READ_TIMEOUT);
- }
-
- public int getClusterManagerNodeApiRequestThreads() {
- try {
- return Integer.parseInt(getProperty(CLUSTER_MANAGER_NODE_API_REQUEST_THREADS));
- } catch (NumberFormatException nfe) {
- return DEFAULT_CLUSTER_MANAGER_NODE_API_NUM_REQUEST_THREADS;
- }
- }
-
- public String getClusterManagerFlowRetrievalDelay() {
- return getProperty(CLUSTER_MANAGER_FLOW_RETRIEVAL_DELAY,
- DEFAULT_CLUSTER_MANAGER_FLOW_RETRIEVAL_DELAY);
- }
-
- public int getClusterManagerProtocolThreads() {
- try {
- return Integer.parseInt(getProperty(CLUSTER_MANAGER_PROTOCOL_THREADS));
- } catch (NumberFormatException nfe) {
- return DEFAULT_CLUSTER_MANAGER_PROTOCOL_THREADS;
- }
- }
-
- public String getClusterManagerSafeModeDuration() {
- return getProperty(CLUSTER_MANAGER_SAFEMODE_DURATION,
- DEFAULT_CLUSTER_MANAGER_SAFEMODE_DURATION);
- }
-
public String getClusterProtocolManagerToNodeApiScheme() {
final String isSecureProperty = getProperty(CLUSTER_PROTOCOL_IS_SECURE);
if (Boolean.valueOf(isSecureProperty)) {
http://git-wip-us.apache.org/repos/asf/nifi/blob/df0e4e79/nifi-commons/nifi-socket-utils/src/main/java/org/apache/nifi/io/socket/SocketListener.java
----------------------------------------------------------------------
diff --git a/nifi-commons/nifi-socket-utils/src/main/java/org/apache/nifi/io/socket/SocketListener.java b/nifi-commons/nifi-socket-utils/src/main/java/org/apache/nifi/io/socket/SocketListener.java
index b509035..718a386 100644
--- a/nifi-commons/nifi-socket-utils/src/main/java/org/apache/nifi/io/socket/SocketListener.java
+++ b/nifi-commons/nifi-socket-utils/src/main/java/org/apache/nifi/io/socket/SocketListener.java
@@ -33,8 +33,6 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
-import org.apache.nifi.logging.NiFiLog;
-
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -45,7 +43,7 @@ import org.slf4j.LoggerFactory;
public abstract class SocketListener {
private static final int DEFAULT_SHUTDOWN_LISTENER_SECONDS = 5;
- private static final Logger logger = new NiFiLog(LoggerFactory.getLogger(SocketListener.class));
+ private static final Logger logger = LoggerFactory.getLogger(SocketListener.class);
private volatile ExecutorService executorService; // volatile to guarantee most current value is visible
private volatile ServerSocket serverSocket; // volatile to guarantee most current value is visible
private final int numThreads;
@@ -96,7 +94,7 @@ public abstract class SocketListener {
@Override
public Thread newThread(final Runnable r) {
final Thread newThread = defaultThreadFactory.newThread(r);
- newThread.setName("Process NCM Request-" + threadCounter.incrementAndGet());
+ newThread.setName("Process Cluster Protocol Request-" + threadCounter.incrementAndGet());
return newThread;
}
});
@@ -152,6 +150,8 @@ public abstract class SocketListener {
});
t.setName("Cluster Socket Listener");
t.start();
+
+ logger.info("Now listening for connections from nodes on port " + port);
}
public boolean isRunning() {
http://git-wip-us.apache.org/repos/asf/nifi/blob/df0e4e79/nifi-mock/src/main/java/org/apache/nifi/util/StandardProcessorTestRunner.java
----------------------------------------------------------------------
diff --git a/nifi-mock/src/main/java/org/apache/nifi/util/StandardProcessorTestRunner.java b/nifi-mock/src/main/java/org/apache/nifi/util/StandardProcessorTestRunner.java
index 9e87d98..8979353 100644
--- a/nifi-mock/src/main/java/org/apache/nifi/util/StandardProcessorTestRunner.java
+++ b/nifi-mock/src/main/java/org/apache/nifi/util/StandardProcessorTestRunner.java
@@ -435,7 +435,7 @@ public class StandardProcessorTestRunner implements TestRunner {
@Override
public void enqueue(final String data) {
- enqueue(data.getBytes(StandardCharsets.UTF_8), Collections.emptyMap());
+ enqueue(data.getBytes(StandardCharsets.UTF_8), Collections.<String, String> emptyMap());
}
@Override
http://git-wip-us.apache.org/repos/asf/nifi/blob/df0e4e79/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/main/java/org/apache/nifi/web/api/dto/ComponentDTO.java
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/main/java/org/apache/nifi/web/api/dto/ComponentDTO.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/main/java/org/apache/nifi/web/api/dto/ComponentDTO.java
index ca5e06f..0ef7fef 100644
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/main/java/org/apache/nifi/web/api/dto/ComponentDTO.java
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/main/java/org/apache/nifi/web/api/dto/ComponentDTO.java
@@ -91,4 +91,22 @@ public class ComponentDTO {
public void setPosition(final PositionDTO position) {
this.position = position;
}
+
+ @Override
+ public int hashCode() {
+ return id == null ? 187 : 187 * id.hashCode();
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == null) {
+ return false;
+ }
+
+ if (obj.getClass() != getClass()) {
+ return false;
+ }
+
+ return id.equals(((ComponentDTO) obj).getId());
+ }
}
http://git-wip-us.apache.org/repos/asf/nifi/blob/df0e4e79/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/main/java/org/apache/nifi/web/api/entity/ComponentEntity.java
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/main/java/org/apache/nifi/web/api/entity/ComponentEntity.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/main/java/org/apache/nifi/web/api/entity/ComponentEntity.java
index ab98899..2f7798e 100644
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/main/java/org/apache/nifi/web/api/entity/ComponentEntity.java
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/main/java/org/apache/nifi/web/api/entity/ComponentEntity.java
@@ -112,4 +112,26 @@ public class ComponentEntity extends Entity {
public void setAccessPolicy(AccessPolicyDTO accessPolicy) {
this.accessPolicy = accessPolicy;
}
+
+ @Override
+ public int hashCode() {
+ return id.hashCode();
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == null) {
+ return false;
+ }
+
+ if (obj == this) {
+ return true;
+ }
+
+ if (obj.getClass() != getClass()) {
+ return false;
+ }
+
+ return id.equals(((ComponentEntity) obj).getId());
+ }
}
http://git-wip-us.apache.org/repos/asf/nifi/blob/df0e4e79/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster-protocol/src/main/java/org/apache/nifi/cluster/coordination/ClusterCoordinator.java
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster-protocol/src/main/java/org/apache/nifi/cluster/coordination/ClusterCoordinator.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster-protocol/src/main/java/org/apache/nifi/cluster/coordination/ClusterCoordinator.java
new file mode 100644
index 0000000..7cd9f80
--- /dev/null
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster-protocol/src/main/java/org/apache/nifi/cluster/coordination/ClusterCoordinator.java
@@ -0,0 +1,203 @@
+/*
+ * 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.cluster.coordination;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.nifi.cluster.coordination.node.DisconnectionCode;
+import org.apache.nifi.cluster.coordination.node.NodeConnectionState;
+import org.apache.nifi.cluster.coordination.node.NodeConnectionStatus;
+import org.apache.nifi.cluster.event.NodeEvent;
+import org.apache.nifi.cluster.protocol.NodeIdentifier;
+import org.apache.nifi.reporting.Severity;
+import org.apache.nifi.services.FlowService;
+
+/**
+ * <p>
+ * Responsible for coordinating nodes in the cluster
+ * <p>
+ */
+public interface ClusterCoordinator {
+
+ /**
+ * Sends a request to the node to connect to the cluster. This will immediately
+ * set the NodeConnectionStatus to CONNECTING.
+ *
+ * @param nodeId the identifier of the node
+ * @param userDn the DN of the user that requested that the node connect, or <code>null</code> if the action is not user-driven
+ */
+ void requestNodeConnect(NodeIdentifier nodeId, String userDn);
+
+ /**
+ * Notifies the Cluster Coordinator that the NiFi instance is being shutdown so that
+ * the coordinator is able to perform cleanup of resources
+ */
+ void shutdown();
+
+ /**
+ * Indicates that the node has sent a valid heartbeat and should now
+ * be considered part of the cluster
+ *
+ * @param nodeId the identifier of the node
+ */
+ void finishNodeConnection(NodeIdentifier nodeId);
+
+ /**
+ * Sends a request to the node to disconnect from the cluster.
+ * The node will be marked as disconnected immediately.
+ *
+ * @param nodeId the identifier of the node
+ * @param disconnectionCode the code that represents why this node is being asked to disconnect
+ * @param explanation an explanation as to why the node is being asked to disconnect
+ * from the cluster
+ */
+ void requestNodeDisconnect(NodeIdentifier nodeId, DisconnectionCode disconnectionCode, String explanation);
+
+ /**
+ * Notifies the Cluster Coordinator that the node with the given ID has requested to disconnect
+ * from the cluster. If no node exists in the cluster with the given ID, this method has no effect.
+ *
+ * @param nodeId the identifier of the node
+ * @param disconnectionCode the code that represents why this node is requesting to disconnect
+ * @param explanation an explanation as to why the node is requesting to disconnect from the cluster
+ */
+ void disconnectionRequestedByNode(NodeIdentifier nodeId, DisconnectionCode disconnectionCode, String explanation);
+
+ /**
+ * Removes the given disconnected node from the cluster
+ *
+ * @param nodeId the node to remove
+ * @param userDn the DN of the user requesting that the node be removed
+ */
+ void removeNode(NodeIdentifier nodeId, String userDn);
+
+ /**
+ * Returns the current status of the node with the given identifier
+ *
+ * @param nodeId the identifier of the node
+ *
+ * @return the current status of the node with the given identifier,
+ * or <code>null</code> if no node is known with the given identifier
+ */
+ NodeConnectionStatus getConnectionStatus(NodeIdentifier nodeId);
+
+ /**
+ * Returns the identifiers of all nodes that have the given connection state
+ *
+ * @param states the states of interest
+ * @return the identifiers of all nodes that have the given connection state
+ */
+ Set<NodeIdentifier> getNodeIdentifiers(NodeConnectionState... states);
+
+ /**
+ * Returns a Map of NodeConnectionStatus to all Node Identifiers that have that status.
+ *
+ * @return the NodeConnectionStatus for each Node in the cluster, grouped by the Connection Status
+ */
+ Map<NodeConnectionState, List<NodeIdentifier>> getConnectionStates();
+
+ /**
+ * Checks if the given hostname is blocked by the configured firewall, returning
+ * <code>true</code> if the node is blocked, <code>false</code> if the node is
+ * allowed through the firewall or if there is no firewall configured
+ *
+ * @param hostname the hostname of the node that is attempting to connect to the cluster
+ *
+ * @return <code>true</code> if the node is blocked, <code>false</code> if the node is
+ * allowed through the firewall or if there is no firewall configured
+ */
+ boolean isBlockedByFirewall(String hostname);
+
+ /**
+ * Reports that some event occurred that is relevant to the cluster
+ *
+ * @param nodeId the identifier of the node that the event pertains to, or <code>null</code> if not applicable
+ * @param severity the severity of the event
+ * @param event an explanation of the event
+ */
+ void reportEvent(NodeIdentifier nodeId, Severity severity, String event);
+
+ /**
+ * Updates the roles held by the given node
+ *
+ * @param nodeId the id of the node to update
+ * @param roles the new roles that the node possesses
+ */
+ void updateNodeRoles(NodeIdentifier nodeId, Set<String> roles);
+
+ /**
+ * Returns the NodeIdentifier that exists that has the given UUID, or <code>null</code> if no NodeIdentifier
+ * exists for the given UUID
+ *
+ * @param uuid the UUID of the NodeIdentifier to obtain
+ * @return the NodeIdentifier that exists that has the given UUID, or <code>null</code> if no NodeIdentifier
+ * exists for the given UUID
+ */
+ NodeIdentifier getNodeIdentifier(String uuid);
+
+ /**
+ * Returns all of the events that have occurred for the given node
+ *
+ * @param nodeId the identifier of the node
+ * @return all of the events that have occurred for the given node
+ */
+ List<NodeEvent> getNodeEvents(NodeIdentifier nodeId);
+
+ /**
+ * @return the identifier of the node that is elected primary, or <code>null</code> if either there is no
+ * primary or the primary is not known by this node.
+ */
+ NodeIdentifier getPrimaryNode();
+
+ /**
+ * Updates the Flow Service to use for obtaining the current flow
+ *
+ * @param flowService the flow service to use for obtaining the current flow
+ */
+ void setFlowService(FlowService flowService);
+
+ /**
+ * Clears the current state of all nodes and replaces them with the values provided in the given map
+ *
+ * @param statusMap the new states of all nodes in the cluster
+ */
+ void resetNodeStatuses(Map<NodeIdentifier, NodeConnectionStatus> statusMap);
+
+ /**
+ * Notifies the Cluster Coordinator of the Node Identifier that the coordinator is currently running on
+ *
+ * @param nodeId the ID of the current node
+ */
+ void setLocalNodeIdentifier(NodeIdentifier nodeId);
+
+ /**
+ * Notifies the Cluster Coordinator whether or not the node is connected to the cluster
+ *
+ * @param connected <code>true</code> if the node is connected to a cluster, <code>false</code> otherwise.
+ */
+ void setConnected(boolean connected);
+
+ /**
+ * Indicates whether or not the node is currently connected to the cluster
+ *
+ * @return <code>true</code> if connected, <code>false</code> otherwise
+ */
+ boolean isConnected();
+}
http://git-wip-us.apache.org/repos/asf/nifi/blob/df0e4e79/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster-protocol/src/main/java/org/apache/nifi/cluster/coordination/heartbeat/HeartbeatMonitor.java
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster-protocol/src/main/java/org/apache/nifi/cluster/coordination/heartbeat/HeartbeatMonitor.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster-protocol/src/main/java/org/apache/nifi/cluster/coordination/heartbeat/HeartbeatMonitor.java
new file mode 100644
index 0000000..c151382
--- /dev/null
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster-protocol/src/main/java/org/apache/nifi/cluster/coordination/heartbeat/HeartbeatMonitor.java
@@ -0,0 +1,55 @@
+/*
+ * 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.cluster.coordination.heartbeat;
+
+import org.apache.nifi.cluster.protocol.NodeIdentifier;
+
+/**
+ * A HeartbeatMonitor is responsible for monitoring some remote resource for heartbeats from each
+ * node in a cluster and reacting to those heartbeats (or lack thereof).
+ */
+public interface HeartbeatMonitor {
+
+ /**
+ * Begin monitoring for heartbeats
+ */
+ void start();
+
+ /**
+ * Stop monitoring heartbeats
+ */
+ void stop();
+
+ /**
+ * Returns the latest heartbeat that has been obtained for the node with
+ * the given id
+ *
+ * @param nodeId the id of the node whose heartbeat should be retrieved
+ * @return the latest heartbeat that has been obtained for the node with
+ * the given id, or <code>null</code> if no heartbeat has been obtained
+ */
+ NodeHeartbeat getLatestHeartbeat(NodeIdentifier nodeId);
+
+ /**
+ * Removes the heartbeat for the given node from the monitor and the
+ * remote location where heartbeats are sent
+ *
+ * @param nodeId the id of the node whose heartbeat should be removed
+ */
+ void removeHeartbeat(NodeIdentifier nodeId);
+}
http://git-wip-us.apache.org/repos/asf/nifi/blob/df0e4e79/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster-protocol/src/main/java/org/apache/nifi/cluster/coordination/heartbeat/NodeHeartbeat.java
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster-protocol/src/main/java/org/apache/nifi/cluster/coordination/heartbeat/NodeHeartbeat.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster-protocol/src/main/java/org/apache/nifi/cluster/coordination/heartbeat/NodeHeartbeat.java
new file mode 100644
index 0000000..2ddda79
--- /dev/null
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster-protocol/src/main/java/org/apache/nifi/cluster/coordination/heartbeat/NodeHeartbeat.java
@@ -0,0 +1,66 @@
+/*
+ * 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.cluster.coordination.heartbeat;
+
+import java.util.Set;
+
+import org.apache.nifi.cluster.coordination.node.NodeConnectionStatus;
+import org.apache.nifi.cluster.protocol.NodeIdentifier;
+
+public interface NodeHeartbeat {
+ /**
+ * @return the time at which the node reported the heartbeat, according
+ * to the system that received the heartbeat
+ */
+ long getTimestamp();
+
+ /**
+ * @return the identifier of the node that sent the heartbeat
+ */
+ NodeIdentifier getNodeIdentifier();
+
+ /**
+ * @return the Connection Status reported by the node
+ */
+ NodeConnectionStatus getConnectionStatus();
+
+ /**
+ * @return the set of Roles that the node currently possesses.
+ */
+ Set<String> getRoles();
+
+ /**
+ * @return the number of FlowFiles that are queued up on the node
+ */
+ int getFlowFileCount();
+
+ /**
+ * @return the total size of all FlowFiles that are queued up on the node
+ */
+ long getFlowFileBytes();
+
+ /**
+ * @return the number of threads that are actively running in Processors and Reporting Tasks on the node
+ */
+ int getActiveThreadCount();
+
+ /**
+ * @return the time that the node reports having started NiFi
+ */
+ long getSystemStartTime();
+}
http://git-wip-us.apache.org/repos/asf/nifi/blob/df0e4e79/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster-protocol/src/main/java/org/apache/nifi/cluster/coordination/node/ClusterRoles.java
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster-protocol/src/main/java/org/apache/nifi/cluster/coordination/node/ClusterRoles.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster-protocol/src/main/java/org/apache/nifi/cluster/coordination/node/ClusterRoles.java
new file mode 100644
index 0000000..611faa4
--- /dev/null
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster-protocol/src/main/java/org/apache/nifi/cluster/coordination/node/ClusterRoles.java
@@ -0,0 +1,25 @@
+/*
+ * 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.cluster.coordination.node;
+
+public class ClusterRoles {
+
+ public static final String PRIMARY_NODE = "Primary Node";
+
+ public static final String CLUSTER_COORDINATOR = "Cluster Coordinator";
+}
http://git-wip-us.apache.org/repos/asf/nifi/blob/df0e4e79/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster-protocol/src/main/java/org/apache/nifi/cluster/coordination/node/DisconnectionCode.java
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster-protocol/src/main/java/org/apache/nifi/cluster/coordination/node/DisconnectionCode.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster-protocol/src/main/java/org/apache/nifi/cluster/coordination/node/DisconnectionCode.java
index bd20c3f..ae18699 100644
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster-protocol/src/main/java/org/apache/nifi/cluster/coordination/node/DisconnectionCode.java
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster-protocol/src/main/java/org/apache/nifi/cluster/coordination/node/DisconnectionCode.java
@@ -58,6 +58,16 @@ public enum DisconnectionCode {
MISMATCHED_FLOWS("Node's Flow did not Match Cluster Flow"),
/**
+ * Cannot communicate with the node
+ */
+ UNABLE_TO_COMMUNICATE("Unable to Communicate with Node"),
+
+ /**
+ * Node did not service a request that was replicated to it
+ */
+ FAILED_TO_SERVICE_REQUEST("Failed to Service Request"),
+
+ /**
* Node is being shut down
*/
NODE_SHUTDOWN("Node was Shutdown");
http://git-wip-us.apache.org/repos/asf/nifi/blob/df0e4e79/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster-protocol/src/main/java/org/apache/nifi/cluster/coordination/node/NodeConnectionState.java
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster-protocol/src/main/java/org/apache/nifi/cluster/coordination/node/NodeConnectionState.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster-protocol/src/main/java/org/apache/nifi/cluster/coordination/node/NodeConnectionState.java
index 9627b2d..8d5824f 100644
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster-protocol/src/main/java/org/apache/nifi/cluster/coordination/node/NodeConnectionState.java
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster-protocol/src/main/java/org/apache/nifi/cluster/coordination/node/NodeConnectionState.java
@@ -46,5 +46,11 @@ public enum NodeConnectionState {
* A node that is not connected to the cluster.
* A DISCONNECTED node can transition to CONNECTING.
*/
- DISCONNECTED
+ DISCONNECTED,
+
+ /**
+ * A NodeConnectionState of REMOVED indicates that the node was removed from the cluster
+ * and is used in order to notify other nodes in the cluster.
+ */
+ REMOVED;
}
http://git-wip-us.apache.org/repos/asf/nifi/blob/df0e4e79/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster-protocol/src/main/java/org/apache/nifi/cluster/coordination/node/NodeConnectionStatus.java
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster-protocol/src/main/java/org/apache/nifi/cluster/coordination/node/NodeConnectionStatus.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster-protocol/src/main/java/org/apache/nifi/cluster/coordination/node/NodeConnectionStatus.java
index cd2a6a7..4570a24 100644
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster-protocol/src/main/java/org/apache/nifi/cluster/coordination/node/NodeConnectionStatus.java
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster-protocol/src/main/java/org/apache/nifi/cluster/coordination/node/NodeConnectionStatus.java
@@ -17,8 +17,15 @@
package org.apache.nifi.cluster.coordination.node;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Objects;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicLong;
+
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
+import org.apache.nifi.cluster.protocol.NodeIdentifier;
import org.apache.nifi.cluster.protocol.jaxb.message.NodeConnectionStatusAdapter;
/**
@@ -26,33 +33,55 @@ import org.apache.nifi.cluster.protocol.jaxb.message.NodeConnectionStatusAdapter
*/
@XmlJavaTypeAdapter(NodeConnectionStatusAdapter.class)
public class NodeConnectionStatus {
+ private static final AtomicLong idGenerator = new AtomicLong(0L);
+
+ private final long updateId;
+ private final NodeIdentifier nodeId;
private final NodeConnectionState state;
private final DisconnectionCode disconnectCode;
private final String disconnectReason;
private final Long connectionRequestTime;
+ private final Set<String> roles;
+
+ public NodeConnectionStatus(final NodeIdentifier nodeId, final NodeConnectionState state) {
+ this(nodeId, state, null, null, null, null);
+ }
+
+ public NodeConnectionStatus(final NodeIdentifier nodeId, final NodeConnectionState state, final Set<String> roles) {
+ this(nodeId, state, null, null, null, roles);
+ }
+
+ public NodeConnectionStatus(final NodeIdentifier nodeId, final NodeConnectionState state, final long connectionRequestTime) {
+ this(nodeId, state, null, null, connectionRequestTime, null);
+ }
- public NodeConnectionStatus(final NodeConnectionState state) {
- this(state, null, null, null);
+ public NodeConnectionStatus(final NodeIdentifier nodeId, final DisconnectionCode disconnectionCode) {
+ this(nodeId, NodeConnectionState.DISCONNECTED, disconnectionCode, disconnectionCode.name(), null, null);
}
- public NodeConnectionStatus(final NodeConnectionState state, final long connectionRequestTime) {
- this(state, null, null, connectionRequestTime);
+ public NodeConnectionStatus(final NodeIdentifier nodeId, final DisconnectionCode disconnectionCode, final String disconnectionExplanation) {
+ this(nodeId, NodeConnectionState.DISCONNECTED, disconnectionCode, disconnectionExplanation, null, null);
}
- public NodeConnectionStatus(final DisconnectionCode disconnectionCode) {
- this(NodeConnectionState.DISCONNECTED, disconnectionCode, disconnectionCode.name(), null);
+ public NodeConnectionStatus(final NodeIdentifier nodeId, final NodeConnectionState state, final DisconnectionCode disconnectionCode, final Set<String> roles) {
+ this(nodeId, state, disconnectionCode, disconnectionCode.name(), null, roles);
}
- public NodeConnectionStatus(final DisconnectionCode disconnectionCode, final String disconnectionExplanation) {
- this(NodeConnectionState.DISCONNECTED, disconnectionCode, disconnectionExplanation, null);
+ public NodeConnectionStatus(final NodeConnectionStatus status, final Set<String> roles) {
+ this(status.getNodeIdentifier(), status.getState(), status.getDisconnectCode(), status.getDisconnectReason(), status.getConnectionRequestTime(), roles);
}
- public NodeConnectionStatus(final NodeConnectionState state, final DisconnectionCode disconnectionCode) {
- this(state, disconnectionCode, disconnectionCode.name(), null);
+ public NodeConnectionStatus(final NodeIdentifier nodeId, final NodeConnectionState state, final DisconnectionCode disconnectCode,
+ final String disconnectReason, final Long connectionRequestTime, final Set<String> roles) {
+ this(idGenerator.getAndIncrement(), nodeId, state, disconnectCode, disconnectReason, connectionRequestTime, roles);
}
- public NodeConnectionStatus(final NodeConnectionState state, final DisconnectionCode disconnectCode, final String disconnectReason, final Long connectionRequestTime) {
+ public NodeConnectionStatus(final long updateId, final NodeIdentifier nodeId, final NodeConnectionState state, final DisconnectionCode disconnectCode,
+ final String disconnectReason, final Long connectionRequestTime, final Set<String> roles) {
+ this.updateId = updateId;
+ this.nodeId = nodeId;
this.state = state;
+ this.roles = roles == null ? Collections.emptySet() : Collections.unmodifiableSet(new HashSet<>(roles));
if (state == NodeConnectionState.DISCONNECTED && disconnectCode == null) {
this.disconnectCode = DisconnectionCode.UNKNOWN;
this.disconnectReason = this.disconnectCode.toString();
@@ -61,7 +90,19 @@ public class NodeConnectionStatus {
this.disconnectReason = disconnectReason;
}
- this.connectionRequestTime = connectionRequestTime;
+ this.connectionRequestTime = (connectionRequestTime == null && state == NodeConnectionState.CONNECTING) ? Long.valueOf(System.currentTimeMillis()) : connectionRequestTime;
+ }
+
+ public long getUpdateIdentifier() {
+ return updateId;
+ }
+
+ public Set<String> getRoles() {
+ return roles;
+ }
+
+ public NodeIdentifier getNodeIdentifier() {
+ return nodeId;
}
public NodeConnectionState getState() {
@@ -88,7 +129,47 @@ public class NodeConnectionStatus {
if (state == NodeConnectionState.DISCONNECTED || state == NodeConnectionState.DISCONNECTING) {
sb.append(", Disconnect Code=").append(getDisconnectCode()).append(", Disconnect Reason=").append(getDisconnectReason());
}
+ sb.append(", updateId=").append(getUpdateIdentifier());
sb.append("]");
return sb.toString();
}
+
+ /**
+ * Updates the ID Generator so that it is at least equal to the given minimum value
+ *
+ * @param minimumValue the minimum value that the ID Generator should be set to
+ */
+ static void updateIdGenerator(long minimumValue) {
+ idGenerator.updateAndGet(curValue -> Math.max(minimumValue, curValue));
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((nodeId == null) ? 0 : nodeId.hashCode());
+ result = prime * result + ((roles == null) ? 0 : roles.hashCode());
+ result = prime * result + ((state == null) ? 0 : state.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+
+ if (obj == null) {
+ return false;
+ }
+
+ if (!(obj instanceof NodeConnectionStatus)) {
+ return false;
+ }
+
+ NodeConnectionStatus other = (NodeConnectionStatus) obj;
+ return Objects.deepEquals(getNodeIdentifier(), other.getNodeIdentifier())
+ && Objects.deepEquals(getRoles(), other.getRoles())
+ && Objects.deepEquals(getState(), other.getState());
+ }
}
http://git-wip-us.apache.org/repos/asf/nifi/blob/df0e4e79/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster-protocol/src/main/java/org/apache/nifi/cluster/event/NodeEvent.java
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster-protocol/src/main/java/org/apache/nifi/cluster/event/NodeEvent.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster-protocol/src/main/java/org/apache/nifi/cluster/event/NodeEvent.java
new file mode 100644
index 0000000..15accb6
--- /dev/null
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster-protocol/src/main/java/org/apache/nifi/cluster/event/NodeEvent.java
@@ -0,0 +1,30 @@
+/*
+ * 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.cluster.event;
+
+import org.apache.nifi.reporting.Severity;
+
+public interface NodeEvent {
+ Severity getSeverity();
+
+ String getMessage();
+
+ String getSource();
+
+ long getTimestamp();
+}
http://git-wip-us.apache.org/repos/asf/nifi/blob/df0e4e79/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster-protocol/src/main/java/org/apache/nifi/cluster/protocol/AbstractNodeProtocolSender.java
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster-protocol/src/main/java/org/apache/nifi/cluster/protocol/AbstractNodeProtocolSender.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster-protocol/src/main/java/org/apache/nifi/cluster/protocol/AbstractNodeProtocolSender.java
new file mode 100644
index 0000000..7d5f442
--- /dev/null
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster-protocol/src/main/java/org/apache/nifi/cluster/protocol/AbstractNodeProtocolSender.java
@@ -0,0 +1,145 @@
+/*
+ * 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.cluster.protocol;
+
+import org.apache.nifi.cluster.protocol.message.ConnectionRequestMessage;
+import org.apache.nifi.cluster.protocol.message.ConnectionResponseMessage;
+import org.apache.nifi.cluster.protocol.message.HeartbeatMessage;
+import org.apache.nifi.cluster.protocol.message.ProtocolMessage;
+import org.apache.nifi.cluster.protocol.message.ProtocolMessage.MessageType;
+import org.apache.nifi.io.socket.SocketConfiguration;
+import org.apache.nifi.io.socket.SocketUtils;
+import org.apache.nifi.security.util.CertificateUtils;
+
+import java.io.IOException;
+import java.net.InetSocketAddress;
+import java.net.Socket;
+import java.security.cert.CertificateException;
+
+public abstract class AbstractNodeProtocolSender implements NodeProtocolSender {
+ private final SocketConfiguration socketConfiguration;
+ private final ProtocolContext<ProtocolMessage> protocolContext;
+
+ public AbstractNodeProtocolSender(final SocketConfiguration socketConfiguration, final ProtocolContext<ProtocolMessage> protocolContext) {
+ this.socketConfiguration = socketConfiguration;
+ this.protocolContext = protocolContext;
+ }
+
+ @Override
+ public ConnectionResponseMessage requestConnection(final ConnectionRequestMessage msg) throws ProtocolException, UnknownServiceAddressException {
+ Socket socket = null;
+ try {
+ socket = createSocket();
+
+ String coordinatorDN = getCoordinatorDN(socket);
+
+ try {
+ // marshal message to output stream
+ final ProtocolMessageMarshaller<ProtocolMessage> marshaller = protocolContext.createMarshaller();
+ marshaller.marshal(msg, socket.getOutputStream());
+ } catch (final IOException ioe) {
+ throw new ProtocolException("Failed marshalling '" + msg.getType() + "' protocol message due to: " + ioe, ioe);
+ }
+
+ final ProtocolMessage response;
+ try {
+ // unmarshall response and return
+ final ProtocolMessageUnmarshaller<ProtocolMessage> unmarshaller = protocolContext.createUnmarshaller();
+ response = unmarshaller.unmarshal(socket.getInputStream());
+ } catch (final IOException ioe) {
+ throw new ProtocolException("Failed unmarshalling '" + MessageType.CONNECTION_RESPONSE + "' protocol message from "
+ + socket.getRemoteSocketAddress() + " due to: " + ioe, ioe);
+ }
+
+ if (MessageType.CONNECTION_RESPONSE == response.getType()) {
+ final ConnectionResponseMessage connectionResponse = (ConnectionResponseMessage) response;
+ connectionResponse.setCoordinatorDN(coordinatorDN);
+ return connectionResponse;
+ } else {
+ throw new ProtocolException("Expected message type '" + MessageType.CONNECTION_RESPONSE + "' but found '" + response.getType() + "'");
+ }
+ } finally {
+ SocketUtils.closeQuietly(socket);
+ }
+ }
+
+ @Override
+ public void heartbeat(final HeartbeatMessage msg, final String address) throws ProtocolException {
+ final String hostname;
+ final int port;
+ try {
+ final String[] parts = address.split(":");
+ hostname = parts[0];
+ port = Integer.parseInt(parts[1]);
+ } catch (final Exception e) {
+ throw new IllegalArgumentException("Cannot send heartbeat to address [" + address + "]. Address must be in <hostname>:<port> format");
+ }
+
+ sendProtocolMessage(msg, hostname, port);
+ }
+
+ private String getCoordinatorDN(Socket socket) {
+ try {
+ return CertificateUtils.extractClientDNFromSSLSocket(socket);
+ } catch (CertificateException e) {
+ throw new ProtocolException(e);
+ }
+ }
+
+ private Socket createSocket() {
+ InetSocketAddress socketAddress = null;
+ try {
+ // create a socket
+ socketAddress = getServiceAddress();
+ return SocketUtils.createSocket(socketAddress, socketConfiguration);
+ } catch (final IOException ioe) {
+ if (socketAddress == null) {
+ throw new ProtocolException("Failed to create socket due to: " + ioe, ioe);
+ } else {
+ throw new ProtocolException("Failed to create socket to " + socketAddress + " due to: " + ioe, ioe);
+ }
+ }
+ }
+
+ public SocketConfiguration getSocketConfiguration() {
+ return socketConfiguration;
+ }
+
+ private void sendProtocolMessage(final ProtocolMessage msg, final String hostname, final int port) {
+ Socket socket = null;
+ try {
+ try {
+ socket = SocketUtils.createSocket(new InetSocketAddress(hostname, port), socketConfiguration);
+ } catch (IOException e) {
+ throw new ProtocolException("Failed to send message to Cluster Coordinator due to: " + e, e);
+ }
+
+ try {
+ // marshal message to output stream
+ final ProtocolMessageMarshaller<ProtocolMessage> marshaller = protocolContext.createMarshaller();
+ marshaller.marshal(msg, socket.getOutputStream());
+ } catch (final IOException ioe) {
+ throw new ProtocolException("Failed marshalling '" + msg.getType() + "' protocol message due to: " + ioe, ioe);
+ }
+ } finally {
+ SocketUtils.closeQuietly(socket);
+ }
+ }
+
+ protected abstract InetSocketAddress getServiceAddress() throws IOException;
+}
http://git-wip-us.apache.org/repos/asf/nifi/blob/df0e4e79/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster-protocol/src/main/java/org/apache/nifi/cluster/protocol/ClusterCoordinationProtocolSender.java
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster-protocol/src/main/java/org/apache/nifi/cluster/protocol/ClusterCoordinationProtocolSender.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster-protocol/src/main/java/org/apache/nifi/cluster/protocol/ClusterCoordinationProtocolSender.java
new file mode 100644
index 0000000..a1af0f8
--- /dev/null
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster-protocol/src/main/java/org/apache/nifi/cluster/protocol/ClusterCoordinationProtocolSender.java
@@ -0,0 +1,64 @@
+/*
+ * 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.cluster.protocol;
+
+import java.util.Set;
+
+import org.apache.nifi.cluster.protocol.message.DisconnectMessage;
+import org.apache.nifi.cluster.protocol.message.NodeStatusChangeMessage;
+import org.apache.nifi.cluster.protocol.message.ReconnectionRequestMessage;
+import org.apache.nifi.cluster.protocol.message.ReconnectionResponseMessage;
+import org.apache.nifi.reporting.BulletinRepository;
+
+/**
+ * An interface for sending protocol messages from the cluster manager to nodes.
+ *
+ */
+public interface ClusterCoordinationProtocolSender {
+
+ /**
+ * Sends a "reconnection request" message to a node.
+ *
+ * @param msg a message
+ * @return the response
+ * @throws ProtocolException if communication failed
+ */
+ ReconnectionResponseMessage requestReconnection(ReconnectionRequestMessage msg) throws ProtocolException;
+
+ /**
+ * Sends a "disconnection request" message to a node.
+ *
+ * @param msg a message
+ * @throws ProtocolException if communication failed
+ */
+ void disconnect(DisconnectMessage msg) throws ProtocolException;
+
+ /**
+ * Sets the {@link BulletinRepository} that can be used to report bulletins
+ *
+ * @param bulletinRepository repo
+ */
+ void setBulletinRepository(final BulletinRepository bulletinRepository);
+
+ /**
+ * Notifies all nodes in the given set that a node in the cluster has a new status
+ *
+ * @param nodesToNotify the nodes that should be notified of the change
+ * @param msg the message that indicates which node's status changed and what it changed to
+ */
+ void notifyNodeStatusChange(Set<NodeIdentifier> nodesToNotify, NodeStatusChangeMessage msg);
+}
http://git-wip-us.apache.org/repos/asf/nifi/blob/df0e4e79/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster-protocol/src/main/java/org/apache/nifi/cluster/protocol/ClusterManagerProtocolSender.java
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster-protocol/src/main/java/org/apache/nifi/cluster/protocol/ClusterManagerProtocolSender.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster-protocol/src/main/java/org/apache/nifi/cluster/protocol/ClusterManagerProtocolSender.java
deleted file mode 100644
index 010aed7..0000000
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster-protocol/src/main/java/org/apache/nifi/cluster/protocol/ClusterManagerProtocolSender.java
+++ /dev/null
@@ -1,75 +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.cluster.protocol;
-
-import java.util.Set;
-
-import org.apache.nifi.cluster.protocol.message.DisconnectMessage;
-import org.apache.nifi.cluster.protocol.message.FlowRequestMessage;
-import org.apache.nifi.cluster.protocol.message.FlowResponseMessage;
-import org.apache.nifi.cluster.protocol.message.NodeStatusChangeMessage;
-import org.apache.nifi.cluster.protocol.message.ReconnectionRequestMessage;
-import org.apache.nifi.cluster.protocol.message.ReconnectionResponseMessage;
-import org.apache.nifi.reporting.BulletinRepository;
-
-/**
- * An interface for sending protocol messages from the cluster manager to nodes.
- *
- */
-public interface ClusterManagerProtocolSender {
-
- /**
- * Sends a "flow request" message to a node.
- *
- * @param msg a message
- * @return the response
- * @throws ProtocolException if communication failed
- */
- FlowResponseMessage requestFlow(FlowRequestMessage msg) throws ProtocolException;
-
- /**
- * Sends a "reconnection request" message to a node.
- *
- * @param msg a message
- * @return the response
- * @throws ProtocolException if communication failed
- */
- ReconnectionResponseMessage requestReconnection(ReconnectionRequestMessage msg) throws ProtocolException;
-
- /**
- * Sends a "disconnection request" message to a node.
- *
- * @param msg a message
- * @throws ProtocolException if communication failed
- */
- void disconnect(DisconnectMessage msg) throws ProtocolException;
-
- /**
- * Sets the {@link BulletinRepository} that can be used to report bulletins
- *
- * @param bulletinRepository repo
- */
- void setBulletinRepository(final BulletinRepository bulletinRepository);
-
- /**
- * Notifies all nodes in the given set that a node in the cluster has a new status
- *
- * @param nodesToNotify the nodes that should be notified of the change
- * @param msg the message that indicates which node's status changed and what it changed to
- */
- void notifyNodeStatusChange(Set<NodeIdentifier> nodesToNotify, NodeStatusChangeMessage msg);
-}
http://git-wip-us.apache.org/repos/asf/nifi/blob/df0e4e79/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster-protocol/src/main/java/org/apache/nifi/cluster/protocol/ClusterNodes.java
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster-protocol/src/main/java/org/apache/nifi/cluster/protocol/ClusterNodes.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster-protocol/src/main/java/org/apache/nifi/cluster/protocol/ClusterNodes.java
deleted file mode 100644
index ad31e68..0000000
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster-protocol/src/main/java/org/apache/nifi/cluster/protocol/ClusterNodes.java
+++ /dev/null
@@ -1,39 +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.cluster.protocol;
-
-import java.util.Collection;
-import java.util.Collections;
-
-import javax.xml.bind.annotation.XmlRootElement;
-
-/**
- * Represents a set of Node Identifiers that identify all nodes that are in a NiFi Cluster
- */
-@XmlRootElement(name = "ClusterNodes")
-public class ClusterNodes {
- private Collection<NodeIdentifier> nodeIds;
-
- public ClusterNodes(final Collection<NodeIdentifier> nodeIds) {
- this.nodeIds = nodeIds;
- }
-
- public Collection<NodeIdentifier> getNodeIdentifiers() {
- return Collections.unmodifiableCollection(nodeIds);
- }
-}
http://git-wip-us.apache.org/repos/asf/nifi/blob/df0e4e79/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster-protocol/src/main/java/org/apache/nifi/cluster/protocol/ComponentRevision.java
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster-protocol/src/main/java/org/apache/nifi/cluster/protocol/ComponentRevision.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster-protocol/src/main/java/org/apache/nifi/cluster/protocol/ComponentRevision.java
new file mode 100644
index 0000000..5c5257a
--- /dev/null
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster-protocol/src/main/java/org/apache/nifi/cluster/protocol/ComponentRevision.java
@@ -0,0 +1,104 @@
+/*
+ * 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.cluster.protocol;
+
+import org.apache.nifi.web.Revision;
+
+public class ComponentRevision {
+ private Long version;
+ private String clientId;
+ private String componentId;
+
+ public Long getVersion() {
+ return version;
+ }
+
+ public void setVersion(Long version) {
+ this.version = version;
+ }
+
+ public String getClientId() {
+ return clientId;
+ }
+
+ public void setClientId(String clientId) {
+ this.clientId = clientId;
+ }
+
+ public String getComponentId() {
+ return componentId;
+ }
+
+ public void setComponentId(String componentId) {
+ this.componentId = componentId;
+ }
+
+ public Revision toRevision() {
+ return new Revision(getVersion(), getClientId(), getComponentId());
+ }
+
+ public static ComponentRevision fromRevision(final Revision revision) {
+ final ComponentRevision componentRevision = new ComponentRevision();
+ componentRevision.setVersion(revision.getVersion());
+ componentRevision.setClientId(revision.getClientId());
+ componentRevision.setComponentId(revision.getComponentId());
+ return componentRevision;
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ if (obj == null) {
+ return false;
+ }
+ if (obj == this) {
+ return true;
+ }
+
+ if ((obj instanceof ComponentRevision) == false) {
+ return false;
+ }
+
+ ComponentRevision thatRevision = (ComponentRevision) obj;
+ // ensure that component ID's are the same (including null)
+ if (thatRevision.getComponentId() == null && getComponentId() != null) {
+ return false;
+ }
+ if (thatRevision.getComponentId() != null && getComponentId() == null) {
+ return false;
+ }
+ if (thatRevision.getComponentId() != null && !thatRevision.getComponentId().equals(getComponentId())) {
+ return false;
+ }
+
+ if (this.version != null && this.version.equals(thatRevision.version)) {
+ return true;
+ } else {
+ return clientId != null && !clientId.trim().isEmpty() && clientId.equals(thatRevision.getClientId());
+ }
+
+ }
+
+ @Override
+ public int hashCode() {
+ int hash = 5;
+ hash = 59 * hash + (this.componentId != null ? this.componentId.hashCode() : 0);
+ hash = 59 * hash + (this.version != null ? this.version.hashCode() : 0);
+ hash = 59 * hash + (this.clientId != null ? this.clientId.hashCode() : 0);
+ return hash;
+ }
+}