use of org.apache.nifi.minifi.commons.schema.ConfigSchema in project nifi-minifi by apache.
the class AbstractTestSecure method testUser3.
@Test
public void testUser3() throws Exception {
SSLContext sslContext = loadSslContext("user3");
assertReturnCode("", sslContext, 400);
ConfigSchema configSchema = assertReturnCode("?class=raspi2", sslContext, 200);
assertEquals("raspi2.v1", configSchema.getFlowControllerProperties().getName());
configSchema = assertReturnCode("?class=raspi3", sslContext, 200);
assertEquals("raspi3.v2", configSchema.getFlowControllerProperties().getName());
}
use of org.apache.nifi.minifi.commons.schema.ConfigSchema in project nifi-minifi by apache.
the class AbstractTestSecure method testUser2.
@Test
public void testUser2() throws Exception {
SSLContext sslContext = loadSslContext("user2");
assertReturnCode("", sslContext, 403);
assertReturnCode("?class=raspi2", sslContext, 403);
ConfigSchema configSchema = assertReturnCode("?class=raspi3", sslContext, 200);
assertEquals("raspi3.v2", configSchema.getFlowControllerProperties().getName());
}
use of org.apache.nifi.minifi.commons.schema.ConfigSchema in project nifi-minifi by apache.
the class AbstractTestUnsecure method testVersion2.
@Test
public void testVersion2() throws IOException, SchemaLoaderException {
ConfigSchema configSchema = getConfigSchema(c2Url + "?class=raspi3&version=2");
assertEquals(3, configSchema.getVersion());
assertEquals("raspi3.v2", configSchema.getFlowControllerProperties().getName());
}
use of org.apache.nifi.minifi.commons.schema.ConfigSchema in project nifi-minifi by apache.
the class ConfigMain method loadAndPrintValidationErrors.
public <T> T loadAndPrintValidationErrors(InputStream inputStream, BiFunction<ConfigSchema, Boolean, T> resultHandler) throws IOException, SchemaLoaderException {
ConvertableSchema<ConfigSchema> configSchema = SchemaLoader.loadConvertableSchemaFromYaml(inputStream);
boolean valid = true;
if (!configSchema.isValid()) {
System.out.println("Found the following errors when parsing the configuration according to its version. (" + configSchema.getVersion() + ")");
configSchema.getValidationIssues().forEach(s -> System.out.println(s));
System.out.println();
valid = false;
configSchema.clearValidationIssues();
} else {
System.out.println("No errors found when parsing configuration according to its version. (" + configSchema.getVersion() + ")");
}
ConfigSchema currentSchema = configSchema.convert();
if (!currentSchema.isValid()) {
System.out.println("Found the following errors when converting configuration to latest version. (" + ConfigSchema.CONFIG_VERSION + ")");
currentSchema.getValidationIssues().forEach(s -> System.out.println(s));
System.out.println();
valid = false;
} else if (configSchema.getVersion() == currentSchema.getVersion()) {
System.out.println("Configuration was already latest version (" + ConfigSchema.CONFIG_VERSION + ") so no conversion was needed.");
} else {
System.out.println("No errors found when converting configuration to latest version. (" + ConfigSchema.CONFIG_VERSION + ")");
}
return resultHandler.apply(currentSchema, valid);
}
use of org.apache.nifi.minifi.commons.schema.ConfigSchema in project nifi-minifi by apache.
the class ConfigMain method transform.
public int transform(String[] args) {
if (args.length != 3) {
printTransformUsage();
return ERR_INVALID_ARGS;
}
ConfigSchema configSchema = null;
try (InputStream inputStream = pathInputStreamFactory.create(args[1])) {
try {
// both transform commands call this method, so determine which transform is being done
if (TRANSFORM_VFS.equals(args[0])) {
configSchema = transformVersionedFlowSnapshotToSchema(inputStream);
} else {
configSchema = transformTemplateToSchema(inputStream);
}
if (!configSchema.isValid()) {
System.out.println(THERE_ARE_VALIDATION_ERRORS_WITH_THE_TEMPLATE_STILL_OUTPUTTING_YAML_BUT_IT_WILL_NEED_TO_BE_EDITED);
configSchema.getValidationIssues().forEach(System.out::println);
System.out.println();
} else {
System.out.println("No validation errors found in converted configuration.");
}
} catch (JAXBException e) {
System.out.println("Error reading template. (" + e + ")");
System.out.println();
printTransformUsage();
return ERR_UNABLE_TO_READ_TEMPLATE;
}
} catch (FileNotFoundException e) {
return handleErrorOpeningInput(args[1], ConfigMain::printTransformUsage, e);
} catch (IOException e) {
handleErrorClosingInput(e);
}
try (OutputStream fileOutputStream = pathOutputStreamFactory.create(args[2])) {
try {
SchemaSaver.saveConfigSchema(configSchema, fileOutputStream);
} catch (IOException e) {
return handleErrorSavingCofiguration(e);
}
} catch (FileNotFoundException e) {
return handleErrorOpeningOutput(args[2], ConfigMain::printTransformUsage, e);
} catch (IOException e) {
handleErrorClosingOutput(e);
}
return SUCCESS;
}
Aggregations