Search in sources :

Example 26 with ConfigSchema

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());
}
Also used : SSLContext(javax.net.ssl.SSLContext) ConfigSchema(org.apache.nifi.minifi.commons.schema.ConfigSchema) Test(org.junit.Test)

Example 27 with ConfigSchema

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());
}
Also used : SSLContext(javax.net.ssl.SSLContext) ConfigSchema(org.apache.nifi.minifi.commons.schema.ConfigSchema) Test(org.junit.Test)

Example 28 with ConfigSchema

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());
}
Also used : ConfigSchema(org.apache.nifi.minifi.commons.schema.ConfigSchema) Test(org.junit.Test)

Example 29 with ConfigSchema

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);
}
Also used : ConfigSchema(org.apache.nifi.minifi.commons.schema.ConfigSchema)

Example 30 with ConfigSchema

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;
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) JAXBException(javax.xml.bind.JAXBException) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) ConfigSchema(org.apache.nifi.minifi.commons.schema.ConfigSchema)

Aggregations

ConfigSchema (org.apache.nifi.minifi.commons.schema.ConfigSchema)31 Test (org.junit.Test)20 InputStream (java.io.InputStream)7 HashMap (java.util.HashMap)6 Map (java.util.Map)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 IOException (java.io.IOException)5 FileInputStream (java.io.FileInputStream)4 List (java.util.List)4 JAXBException (javax.xml.bind.JAXBException)4 FileNotFoundException (java.io.FileNotFoundException)3 OutputStream (java.io.OutputStream)3 ArrayList (java.util.ArrayList)3 Properties (java.util.Properties)3 ConfigSchemaTest (org.apache.nifi.minifi.commons.schema.ConfigSchemaTest)3 ConnectionSchema (org.apache.nifi.minifi.commons.schema.ConnectionSchema)3 HttpURLConnection (java.net.HttpURLConnection)2 ByteBuffer (java.nio.ByteBuffer)2 HashSet (java.util.HashSet)2