本文整理汇总了Java中org.apache.nifi.components.ValidationResult类的典型用法代码示例。如果您正苦于以下问题:Java ValidationResult类的具体用法?Java ValidationResult怎么用?Java ValidationResult使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ValidationResult类属于org.apache.nifi.components包,在下文中一共展示了ValidationResult类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: validate
import org.apache.nifi.components.ValidationResult; //导入依赖的package包/类
@Override
public ValidationResult validate(String subject, String input, ValidationContext context) {
String libDirPath = context.getProperty(CLIENT_LIB_DIR_PATH).getValue();
StringBuilder invalidationMessageBuilder = new StringBuilder();
if (libDirPath != null) {
File file = new File(libDirPath);
if (!file.isDirectory()) {
invalidationMessageBuilder.append("'MQ Client Libraries path' must point to a directory. Was '"
+ file.getAbsolutePath() + "'.");
}
} else {
invalidationMessageBuilder.append("'MQ Client Libraries path' must be provided. \n");
}
String invalidationMessage = invalidationMessageBuilder.toString();
ValidationResult vResult;
if (invalidationMessage.length() == 0) {
vResult = new ValidationResult.Builder().subject(subject).input(input)
.explanation("Client lib path is valid and points to a directory").valid(true).build();
} else {
vResult = new ValidationResult.Builder().subject(subject).input(input)
.explanation("Client lib path is invalid. " + invalidationMessage)
.valid(false).build();
}
return vResult;
}
示例2: customValidate
import org.apache.nifi.components.ValidationResult; //导入依赖的package包/类
@Override
protected Collection<ValidationResult> customValidate(ValidationContext validationContext) {
final Collection<ValidationResult> results = new ArrayList<>();
parseAtlasUrls(validationContext.getProperty(ATLAS_URLS), input -> {
final ValidationResult.Builder builder = new ValidationResult.Builder().subject(ATLAS_URLS.getDisplayName()).input(input);
try {
new URL(input);
results.add(builder.explanation("Valid URI").valid(true).build());
} catch (Exception e) {
results.add(builder.explanation("Contains invalid URI: " + e).valid(false).build());
}
});
clusterResolverLoader.forEach(resolver -> results.addAll(resolver.validate(validationContext)));
return results;
}
示例3: validate
import org.apache.nifi.components.ValidationResult; //导入依赖的package包/类
@Override
public Collection<ValidationResult> validate(ValidationContext validationContext) {
final List<ValidationResult> validationResults = new ArrayList<>();
consumeConfigurations(validationContext.getAllProperties(),
(clusterNamePatterns, patterns) -> {},
(entry, e) -> {
final ValidationResult result = new ValidationResult.Builder()
.subject(entry.getKey())
.input(entry.getValue())
.explanation(e.getMessage())
.valid(false)
.build();
validationResults.add(result);
});
return validationResults;
}
示例4: testInvalidClusterName
import org.apache.nifi.components.ValidationResult; //导入依赖的package包/类
@Test
public void testInvalidClusterName() {
final Map<String, String> properties = new HashMap<>();
properties.put(RegexClusterResolver.PATTERN_PROPERTY_PREFIX, ".*\\.example.com");
setupMock(properties);
final RegexClusterResolver resolver = new RegexClusterResolver();
final Collection<ValidationResult> validationResults = resolver.validate(validationContext);
Assert.assertEquals(1, validationResults.size());
final ValidationResult validationResult = validationResults.iterator().next();
Assert.assertEquals(RegexClusterResolver.PATTERN_PROPERTY_PREFIX, validationResult.getSubject());
try {
resolver.configure(context);
Assert.fail("Configure method should fail, too");
} catch (IllegalArgumentException e) {
}
}
示例5: testEmptyPattern
import org.apache.nifi.components.ValidationResult; //导入依赖的package包/类
@Test
public void testEmptyPattern() {
final Map<String, String> properties = new HashMap<>();
final String propertyName = RegexClusterResolver.PATTERN_PROPERTY_PREFIX + "Cluster1";
properties.put(propertyName, "");
setupMock(properties);
final RegexClusterResolver resolver = new RegexClusterResolver();
final Collection<ValidationResult> validationResults = resolver.validate(validationContext);
Assert.assertEquals(1, validationResults.size());
final ValidationResult validationResult = validationResults.iterator().next();
Assert.assertEquals(propertyName, validationResult.getSubject());
try {
resolver.configure(context);
Assert.fail("Configure method should fail, too");
} catch (IllegalArgumentException e) {
}
}
示例6: testMultiplePatterns
import org.apache.nifi.components.ValidationResult; //导入依赖的package包/类
@Test
public void testMultiplePatterns() {
final Map<String, String> properties = new HashMap<>();
final String propertyName = RegexClusterResolver.PATTERN_PROPERTY_PREFIX + "Cluster1";
// Hostname or local ip address, delimited with a whitespace
properties.put(propertyName, "^.*\\.example.com$\n^192.168.1.[\\d]+$");
setupMock(properties);
final RegexClusterResolver resolver = new RegexClusterResolver();
final Collection<ValidationResult> validationResults = resolver.validate(validationContext);
Assert.assertEquals(0, validationResults.size());
resolver.configure(context);
Assert.assertEquals("Cluster1", resolver.fromHostname("host1.example.com"));
Assert.assertEquals("Cluster1", resolver.fromHostname("192.168.1.10"));
Assert.assertEquals("Cluster1", resolver.fromHostname("192.168.1.22"));
Assert.assertNull(resolver.fromHostname("192.168.2.30"));
}
示例7: testMultipleClusters
import org.apache.nifi.components.ValidationResult; //导入依赖的package包/类
@Test
public void testMultipleClusters() {
final Map<String, String> properties = new HashMap<>();
final String c1PropertyName = RegexClusterResolver.PATTERN_PROPERTY_PREFIX + "Cluster1";
final String c2PropertyName = RegexClusterResolver.PATTERN_PROPERTY_PREFIX + "Cluster2";
// Hostname or local ip address
properties.put(c1PropertyName, "^.*\\.c1\\.example.com$ ^192.168.1.[\\d]+$");
properties.put(c2PropertyName, "^.*\\.c2\\.example.com$ ^192.168.2.[\\d]+$");
setupMock(properties);
final RegexClusterResolver resolver = new RegexClusterResolver();
final Collection<ValidationResult> validationResults = resolver.validate(validationContext);
Assert.assertEquals(0, validationResults.size());
resolver.configure(context);
Assert.assertEquals("Cluster1", resolver.fromHostname("host1.c1.example.com"));
Assert.assertEquals("Cluster1", resolver.fromHostname("192.168.1.10"));
Assert.assertEquals("Cluster1", resolver.fromHostname("192.168.1.22"));
Assert.assertEquals("Cluster2", resolver.fromHostname("host2.c2.example.com"));
Assert.assertEquals("Cluster2", resolver.fromHostname("192.168.2.10"));
Assert.assertEquals("Cluster2", resolver.fromHostname("192.168.2.22"));
Assert.assertNull(resolver.fromHostname("192.168.3.30"));
}
示例8: customValidate
import org.apache.nifi.components.ValidationResult; //导入依赖的package包/类
@Override
protected Collection<ValidationResult> customValidate(final ValidationContext context) {
final Collection<ValidationResult> results = new ArrayList<>();
PropertyValue usernameProperty = context.getProperty(USERNAME);
PropertyValue passwordProperty = context.getProperty(PASSWORD);
PropertyValue authDatabaseProperty = context.getProperty(AUTH_DATABASE);
boolean valid = true;
if (usernameProperty.isSet() || passwordProperty.isSet() || authDatabaseProperty.isSet()) {
valid = usernameProperty.isSet() && passwordProperty.isSet() && authDatabaseProperty.isSet();
}
results.add(new ValidationResult.Builder()
.explanation("Using authentication requires Username, Password, and the Authentication Database")
.valid(valid)
.subject("Mongo Authentication")
.build());
return results;
}
示例9: addValidationErrors
import org.apache.nifi.components.ValidationResult; //导入依赖的package包/类
private void addValidationErrors(ConfiguredComponent connectable) {
ValidationResult validationResult = new ValidationResult.Builder()
.input("input")
.subject("subject")
.explanation("is not valid")
.build();
ValidationResult validationResult2 = new ValidationResult.Builder()
.input("input2")
.subject("subject2")
.explanation("is not valid too")
.build();
List<ValidationResult> validationResultList = new ArrayList<>();
validationResultList.add(validationResult);
validationResultList.add(validationResult2);
when(connectable.getValidationErrors()).thenReturn(validationResultList);
}
示例10: customValidate
import org.apache.nifi.components.ValidationResult; //导入依赖的package包/类
@Override
protected Collection<ValidationResult> customValidate(ValidationContext validationContext) {
boolean zkQuorumProvided = validationContext.getProperty(ZOOKEEPER_QUORUM).isSet();
boolean instanceNamerovided = validationContext.getProperty(INSTANCE_NAME).isSet();
boolean userProvided = validationContext.getProperty(USER).isSet();
boolean passwordProvided = validationContext.getProperty(PASSWORD).isSet();
final List<ValidationResult> problems = new ArrayList<>();
if (!zkQuorumProvided && (!instanceNamerovided || !userProvided || !passwordProvided)) {
problems.add(new ValidationResult.Builder()
.valid(false)
.subject(this.getClass().getSimpleName())
.explanation("ZooKeeper Quorum, Instance Name, Accumulo User, and Accumulo Password are required " +
"to connect")
.build());
}
return problems;
}
示例11: validate
import org.apache.nifi.components.ValidationResult; //导入依赖的package包/类
@Override
public ValidationResult validate(String subject, String input, ValidationContext context) {
try {
JSONUtils.INSTANCE.load(input, new TypeReference<Map<String, String>>() {
});
} catch (IOException e) {
return new ValidationResult.Builder()
.subject(subject)
.input(value)
.valid(false)
.explanation("Not a valid JSON map value: " + e.getMessage())
.build();
}
return new ValidationResult.Builder()
.valid(true)
.input(value)
.subject(subject)
.build();
}
示例12: customValidate
import org.apache.nifi.components.ValidationResult; //导入依赖的package包/类
@Override
protected Collection<ValidationResult> customValidate(
final ValidationContext validationContext) {
final List<ValidationResult> results = new ArrayList<>();
final String endpointName = validationContext.getProperty(ENDPOINT)
.getValue();
if (ENDPOINT_FILTER.getValue().equals(endpointName)) {
if (!validationContext.getProperty(TERMS).isSet()
&& !validationContext.getProperty(FOLLOWING).isSet()
&& !validationContext.getProperty(LOCATIONS).isSet()) {
results.add(new ValidationResult.Builder()
.input("")
.subject(FOLLOWING.getName())
.valid(false)
.explanation(
"When using the 'Filter Endpoint', at least one of '"
+ TERMS.getName() + "' or '"
+ FOLLOWING.getName() + "'" + "' or '"
+ LOCATIONS.getName() + " must be set")
.build());
}
}
return results;
}
示例13: testValidations
import org.apache.nifi.components.ValidationResult; //导入依赖的package包/类
@Test
public void testValidations() throws IOException {
TestRunner runner = TestRunners.newTestRunner(OpenScoringProcessor.class);
Collection<ValidationResult> results;
ProcessContext pc;
results = new HashSet<>();
runner.enqueue(new byte[0]);
runner.setProperty(OpenScoringProcessor.OPENSCORING_URL, "http://localhost:8080/openscoring");
runner.setProperty(OpenScoringProcessor.PMML, IOUtils.toString(getClass().getResourceAsStream(PMML_FILE)));
pc = runner.getProcessContext();
if (pc instanceof MockProcessContext) {
results = ((MockProcessContext) pc).validate();
}
Assert.assertEquals(0, results.size());
}
示例14: customValidate
import org.apache.nifi.components.ValidationResult; //导入依赖的package包/类
@Override
protected Collection<ValidationResult> customValidate(ValidationContext validationContext) {
final List<ValidationResult> results = new ArrayList<>(1);
ObjectMapper mapper = new ObjectMapper();
JsonNode rootNode = null;
try {
rootNode = mapper.readValue(new File(validationContext.getProperty(GENERATOR_RESOURCE).getValue()), JsonNode.class);
generator = new RecordGenerator(rootNode);
} catch (IOException ioe) {
results.add(new ValidationResult.Builder().subject("Generator Resource").valid(false).explanation("Couldn't read specified resource").build());
}
return results;
}
示例15: validate
import org.apache.nifi.components.ValidationResult; //导入依赖的package包/类
@Override
public Collection<ValidationResult> validate(ValidationContext validationContext) {
Collection<ValidationResult> results = new ArrayList<>();
for (ClusterResolver resolver : resolvers) {
results.addAll(resolver.validate(validationContext));
}
return results;
}