You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by al...@apache.org on 2016/02/03 22:36:36 UTC
[03/12] nifi git commit: NIFI-259: Adjusting validation logic for
Connect String to catch errors at startup.
NIFI-259: Adjusting validation logic for Connect String to catch errors at startup.
Project: http://git-wip-us.apache.org/repos/asf/nifi/repo
Commit: http://git-wip-us.apache.org/repos/asf/nifi/commit/f4716821
Tree: http://git-wip-us.apache.org/repos/asf/nifi/tree/f4716821
Diff: http://git-wip-us.apache.org/repos/asf/nifi/diff/f4716821
Branch: refs/heads/NIFI-259
Commit: f47168213b90e378e35be807c31e068a1974b9f2
Parents: 6902812
Author: Aldrin Piri <al...@apache.org>
Authored: Fri Jan 29 08:43:32 2016 -0600
Committer: Aldrin Piri <al...@apache.org>
Committed: Mon Feb 1 14:07:38 2016 -0500
----------------------------------------------------------------------
.../zookeeper/ZooKeeperStateProvider.java | 21 +++++++++++++++-----
1 file changed, 16 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/nifi/blob/f4716821/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/state/providers/zookeeper/ZooKeeperStateProvider.java
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/state/providers/zookeeper/ZooKeeperStateProvider.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/state/providers/zookeeper/ZooKeeperStateProvider.java
index b1764eb..8ce74b4 100644
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/state/providers/zookeeper/ZooKeeperStateProvider.java
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/state/providers/zookeeper/ZooKeeperStateProvider.java
@@ -50,6 +50,7 @@ import org.apache.zookeeper.Watcher;
import org.apache.zookeeper.ZKUtil;
import org.apache.zookeeper.ZooDefs.Ids;
import org.apache.zookeeper.ZooKeeper;
+import org.apache.zookeeper.client.ConnectStringParser;
import org.apache.zookeeper.data.ACL;
import org.apache.zookeeper.data.Stat;
@@ -62,7 +63,18 @@ public class ZooKeeperStateProvider extends AbstractStateProvider {
.name("Connect String")
.description("The ZooKeeper Connect String to use. This is a comma-separated list of hostname/IP and port tuples, such as \"host1:2181,host2:2181,127.0.0.1:2181\". If a port is not " +
"specified it defaults to the ZooKeeper client port default of 2181")
- .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .addValidator(new Validator() {
+ @Override
+ public ValidationResult validate(String subject, String input, ValidationContext context) {
+ final String connectionString = context.getProperty(CONNECTION_STRING).getValue();
+ try {
+ new ConnectStringParser(connectionString);
+ } catch (Exception e) {
+ return new ValidationResult.Builder().subject(subject).input(input).explanation("Invalid Connect String: " + connectionString).valid(false).build();
+ }
+ return new ValidationResult.Builder().subject(subject).input(input).explanation("Valid Connect String").valid(true).build();
+ }
+ })
.required(false)
.build();
static final PropertyDescriptor SESSION_TIMEOUT = new PropertyDescriptor.Builder()
@@ -148,7 +160,6 @@ public class ZooKeeperStateProvider extends AbstractStateProvider {
.build());
}
}
-
return validationFailures;
}
@@ -251,7 +262,7 @@ public class ZooKeeperStateProvider extends AbstractStateProvider {
private byte[] serialize(final Map<String, String> stateValues) throws IOException {
try (final ByteArrayOutputStream baos = new ByteArrayOutputStream();
- final DataOutputStream dos = new DataOutputStream(baos)) {
+ final DataOutputStream dos = new DataOutputStream(baos)) {
dos.writeByte(ENCODING_VERSION);
dos.writeInt(stateValues.size());
for (final Map.Entry<String, String> entry : stateValues.entrySet()) {
@@ -273,7 +284,7 @@ public class ZooKeeperStateProvider extends AbstractStateProvider {
private StateMap deserialize(final byte[] data, final int recordVersion, final String componentId) throws IOException {
try (final ByteArrayInputStream bais = new ByteArrayInputStream(data);
- final DataInputStream dis = new DataInputStream(bais)) {
+ final DataInputStream dis = new DataInputStream(bais)) {
final byte encodingVersion = dis.readByte();
if (encodingVersion > ENCODING_VERSION) {
@@ -422,6 +433,6 @@ public class ZooKeeperStateProvider extends AbstractStateProvider {
@Override
public void clear(final String componentId) throws IOException {
verifyEnabled();
- setState(Collections.<String, String> emptyMap(), componentId);
+ setState(Collections.<String, String>emptyMap(), componentId);
}
}