Skip to content

Commit

Permalink
NIFI-8614 Adjusted NodeClusterCoordinatorFactoryBean to handle null C…
Browse files Browse the repository at this point in the history
…lusterNodeFirewall (apache#5100)

- Changed FileBasedClusterNodeFirewallFactoryBean to return null when configuration file is not found
  • Loading branch information
exceptionfactory authored May 25, 2021
1 parent beb1d2f commit 103aae6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,18 @@ public class FileBasedClusterNodeFirewallFactoryBean implements FactoryBean<Clus

private NiFiProperties properties;

/**
* Get Cluster Node Firewall should return null when firewall file is not configured
*
* @return Cluster Node Firewall or null when file not configured
* @throws Exception Thrown on new FileBasedClusterNodeFirewall()
*/
@Override
public ClusterNodeFirewall getObject() throws Exception {
if (firewall == null) {
final File config = properties.getClusterNodeFirewallFile();
final File restoreDirectory = properties.getRestoreDirectory();
if (config == null) {
firewall = new PermitAllClusterNodeFirewall();
} else {
if (config != null) {
firewall = new FileBasedClusterNodeFirewall(config, restoreDirectory);
}
}
Expand All @@ -59,12 +63,4 @@ public boolean isSingleton() {
public void setProperties(NiFiProperties properties) {
this.properties = properties;
}

private static class PermitAllClusterNodeFirewall implements ClusterNodeFirewall {

@Override
public boolean isPermissible(final String hostOrIp) {
return true;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ public NodeClusterCoordinator getObject() throws Exception {
final ClusterCoordinationProtocolSenderListener protocolSenderListener =
applicationContext.getBean("clusterCoordinationProtocolSenderListener", ClusterCoordinationProtocolSenderListener.class);
final EventReporter eventReporter = applicationContext.getBean("eventReporter", EventReporter.class);
final ClusterNodeFirewall clusterFirewall = applicationContext.getBean("clusterFirewall", ClusterNodeFirewall.class);
final Object clusterFirewallBean = applicationContext.getBean("clusterFirewall");
final ClusterNodeFirewall clusterFirewall = clusterFirewallBean instanceof ClusterNodeFirewall ? (ClusterNodeFirewall) clusterFirewallBean : null;
final RevisionManager revisionManager = applicationContext.getBean("revisionManager", RevisionManager.class);
final LeaderElectionManager electionManager = applicationContext.getBean("leaderElectionManager", LeaderElectionManager.class);
final FlowElection flowElection = applicationContext.getBean("flowElection", FlowElection.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;

public class FileBasedClusterNodeFirewallFactoryBeanTest {
private static final String PROPERTIES_SUFFIX = ".firewall.properties";
Expand All @@ -53,7 +54,7 @@ public void testGetObjectType() {
@Test
public void testGetObjectClusterNodeFirewallFileNotConfigured() throws Exception {
final ClusterNodeFirewall clusterNodeFirewall = factoryBean.getObject();
assertNotNull(clusterNodeFirewall);
assertNull(clusterNodeFirewall);
}

@Test
Expand Down

0 comments on commit 103aae6

Please sign in to comment.