NIFI-259: Adjusting validation logic for Connect String to catch errors at startup.

This commit is contained in:
Aldrin Piri 2016-01-29 08:43:32 -06:00
parent 6902812678
commit f47168213b
1 changed files with 16 additions and 5 deletions

View File

@ -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;
}
@ -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);
}
}