Search in sources :

Example 16 with ConfigSchema

use of org.apache.nifi.minifi.commons.schema.ConfigSchema in project nifi-minifi by apache.

the class AbstractTestUnsecure method testVersion1.

@Test
public void testVersion1() throws IOException, SchemaLoaderException {
    ConfigSchema configSchema = getConfigSchema(c2Url + "?class=raspi3&version=1");
    assertEquals(3, configSchema.getVersion());
    assertEquals("raspi3.v1", configSchema.getFlowControllerProperties().getName());
}
Also used : ConfigSchema(org.apache.nifi.minifi.commons.schema.ConfigSchema) Test(org.junit.Test)

Example 17 with ConfigSchema

use of org.apache.nifi.minifi.commons.schema.ConfigSchema in project nifi-minifi by apache.

the class ConfigMainTest method testV1YmlIfPresent.

private void testV1YmlIfPresent(String name, Map<String, Object> yamlMap) throws IOException, SchemaLoaderException {
    InputStream upgradedInputStream = upgradeAndReturn(name + "-v1.yml");
    if (upgradedInputStream != null) {
        ConvertableSchema<ConfigSchema> configSchemaConvertableSchema = SchemaLoader.loadConvertableSchemaFromYaml(upgradedInputStream);
        ConfigSchema configSchemaUpgradedFromV1 = configSchemaConvertableSchema.convert();
        assertTrue(configSchemaUpgradedFromV1.isValid());
        assertEquals(configSchemaConvertableSchema, configSchemaUpgradedFromV1);
        ConfigSchema configSchemaFromCurrent = new ConfigSchema(yamlMap);
        List<ProcessorSchema> currentProcessors = configSchemaFromCurrent.getProcessGroupSchema().getProcessors();
        List<ProcessorSchema> v1Processors = configSchemaUpgradedFromV1.getProcessGroupSchema().getProcessors();
        assertEquals(currentProcessors.size(), v1Processors.size());
        // V1 doesn't have ids so we need to map the autogenerated ones to the ones from the template
        Map<String, String> v1IdToCurrentIdMap = new HashMap<>();
        for (int i = 0; i < currentProcessors.size(); i++) {
            ProcessorSchema currentProcessor = currentProcessors.get(i);
            ProcessorSchema v1Processor = v1Processors.get(i);
            assertEquals(currentProcessor.getName(), v1Processor.getName());
            v1IdToCurrentIdMap.put(v1Processor.getId(), currentProcessor.getId());
            v1Processor.setId(currentProcessor.getId());
        }
        List<RemoteProcessGroupSchema> currentRPGs = configSchemaFromCurrent.getProcessGroupSchema().getRemoteProcessGroups();
        List<RemoteProcessGroupSchema> v1RPGs = configSchemaUpgradedFromV1.getProcessGroupSchema().getRemoteProcessGroups();
        // V1 doesn't have ids so we need to map the autogenerated ones to the ones from the template
        for (int i = 0; i < currentRPGs.size(); i++) {
            RemoteProcessGroupSchema currentRPG = currentRPGs.get(i);
            RemoteProcessGroupSchema v1RPG = v1RPGs.get(i);
            assertEquals(currentRPG.getName(), v1RPG.getName());
            v1IdToCurrentIdMap.put(v1RPG.getId(), currentRPG.getId());
            v1RPG.setId(currentRPG.getId());
        }
        configSchemaUpgradedFromV1.getProcessGroupSchema().getRemoteProcessGroups().stream().flatMap(g -> g.getInputPorts().stream()).map(RemotePortSchema::getId).sequential().forEach(id -> v1IdToCurrentIdMap.put(id, id));
        List<ConnectionSchema> currentConnections = configSchemaFromCurrent.getProcessGroupSchema().getConnections();
        List<ConnectionSchema> v1Connections = configSchemaUpgradedFromV1.getProcessGroupSchema().getConnections();
        // Update source and dest ids, can set connection id equal because it isn't referenced elsewhere
        assertEquals(currentConnections.size(), v1Connections.size());
        for (int i = 0; i < currentConnections.size(); i++) {
            ConnectionSchema currentConnection = currentConnections.get(i);
            ConnectionSchema v1Connection = v1Connections.get(i);
            assertEquals(currentConnection.getName(), v1Connection.getName());
            v1Connection.setId(currentConnection.getId());
            v1Connection.setSourceId(v1IdToCurrentIdMap.get(v1Connection.getSourceId()));
            v1Connection.setDestinationId(v1IdToCurrentIdMap.get(v1Connection.getDestinationId()));
        }
        ConfigSchema.getAllProcessGroups(configSchemaFromCurrent.getProcessGroupSchema()).stream().flatMap(p -> p.getRemoteProcessGroups().stream()).forEach(r -> {
            clearV3orLaterProperties(r);
            r.setTransportProtocol(RemoteProcessGroupSchema.TransportProtocolOptions.RAW.name());
        });
        Map<String, Object> v1YamlMap = configSchemaUpgradedFromV1.toMap();
        assertNoMapDifferences(v1YamlMap, configSchemaFromCurrent.toMap());
    }
}
Also used : RemotePortSchema(org.apache.nifi.minifi.commons.schema.RemotePortSchema) RemoteProcessGroupSchema(org.apache.nifi.minifi.commons.schema.RemoteProcessGroupSchema) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SchemaLoader(org.apache.nifi.minifi.commons.schema.serialization.SchemaLoader) Mock(org.mockito.Mock) ProcessorSchema(org.apache.nifi.minifi.commons.schema.ProcessorSchema) RunWith(org.junit.runner.RunWith) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ByteArrayInputStream(java.io.ByteArrayInputStream) Map(java.util.Map) Assert.fail(org.junit.Assert.fail) LimitedInputStream(org.apache.nifi.controller.repository.io.LimitedInputStream) Before(org.junit.Before) Charsets(org.apache.commons.io.Charsets) OutputStream(java.io.OutputStream) ConvertableSchema(org.apache.nifi.minifi.commons.schema.common.ConvertableSchema) Set(java.util.Set) Assert.assertTrue(org.junit.Assert.assertTrue) ConfigSchema(org.apache.nifi.minifi.commons.schema.ConfigSchema) Test(org.junit.Test) IOException(java.io.IOException) Mockito.when(org.mockito.Mockito.when) JAXBException(javax.xml.bind.JAXBException) FileNotFoundException(java.io.FileNotFoundException) List(java.util.List) MockitoJUnitRunner(org.mockito.runners.MockitoJUnitRunner) SchemaLoaderException(org.apache.nifi.minifi.commons.schema.exception.SchemaLoaderException) ConnectionSchema(org.apache.nifi.minifi.commons.schema.ConnectionSchema) SUCCESS(org.apache.nifi.minifi.toolkit.configuration.ConfigMain.SUCCESS) Assert.assertEquals(org.junit.Assert.assertEquals) InputStream(java.io.InputStream) ConnectionSchema(org.apache.nifi.minifi.commons.schema.ConnectionSchema) HashMap(java.util.HashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) LimitedInputStream(org.apache.nifi.controller.repository.io.LimitedInputStream) InputStream(java.io.InputStream) RemotePortSchema(org.apache.nifi.minifi.commons.schema.RemotePortSchema) ProcessorSchema(org.apache.nifi.minifi.commons.schema.ProcessorSchema) RemoteProcessGroupSchema(org.apache.nifi.minifi.commons.schema.RemoteProcessGroupSchema) ConfigSchema(org.apache.nifi.minifi.commons.schema.ConfigSchema)

Example 18 with ConfigSchema

use of org.apache.nifi.minifi.commons.schema.ConfigSchema in project nifi-minifi by apache.

the class ConfigMainTest method testV2YmlIfPresent.

private void testV2YmlIfPresent(String name, Map<String, Object> yamlMap) throws IOException, SchemaLoaderException {
    InputStream upgradedInputStream = upgradeAndReturn(name + "-v2.yml");
    if (upgradedInputStream != null) {
        ConvertableSchema<ConfigSchema> configSchemaConvertableSchema = SchemaLoader.loadConvertableSchemaFromYaml(upgradedInputStream);
        ConfigSchema configSchemaUpgradedFromV2 = configSchemaConvertableSchema.convert();
        ConfigSchema configSchemaFromCurrent = new ConfigSchema(yamlMap);
        ConfigSchema.getAllProcessGroups(configSchemaFromCurrent.getProcessGroupSchema()).stream().flatMap(p -> p.getRemoteProcessGroups().stream()).forEach(r -> {
            clearV3orLaterProperties(r);
        });
        assertNoMapDifferences(configSchemaUpgradedFromV2.toMap(), configSchemaFromCurrent.toMap());
    }
}
Also used : RemotePortSchema(org.apache.nifi.minifi.commons.schema.RemotePortSchema) RemoteProcessGroupSchema(org.apache.nifi.minifi.commons.schema.RemoteProcessGroupSchema) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SchemaLoader(org.apache.nifi.minifi.commons.schema.serialization.SchemaLoader) Mock(org.mockito.Mock) ProcessorSchema(org.apache.nifi.minifi.commons.schema.ProcessorSchema) RunWith(org.junit.runner.RunWith) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ByteArrayInputStream(java.io.ByteArrayInputStream) Map(java.util.Map) Assert.fail(org.junit.Assert.fail) LimitedInputStream(org.apache.nifi.controller.repository.io.LimitedInputStream) Before(org.junit.Before) Charsets(org.apache.commons.io.Charsets) OutputStream(java.io.OutputStream) ConvertableSchema(org.apache.nifi.minifi.commons.schema.common.ConvertableSchema) Set(java.util.Set) Assert.assertTrue(org.junit.Assert.assertTrue) ConfigSchema(org.apache.nifi.minifi.commons.schema.ConfigSchema) Test(org.junit.Test) IOException(java.io.IOException) Mockito.when(org.mockito.Mockito.when) JAXBException(javax.xml.bind.JAXBException) FileNotFoundException(java.io.FileNotFoundException) List(java.util.List) MockitoJUnitRunner(org.mockito.runners.MockitoJUnitRunner) SchemaLoaderException(org.apache.nifi.minifi.commons.schema.exception.SchemaLoaderException) ConnectionSchema(org.apache.nifi.minifi.commons.schema.ConnectionSchema) SUCCESS(org.apache.nifi.minifi.toolkit.configuration.ConfigMain.SUCCESS) Assert.assertEquals(org.junit.Assert.assertEquals) InputStream(java.io.InputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) LimitedInputStream(org.apache.nifi.controller.repository.io.LimitedInputStream) InputStream(java.io.InputStream) ConfigSchema(org.apache.nifi.minifi.commons.schema.ConfigSchema)

Example 19 with ConfigSchema

use of org.apache.nifi.minifi.commons.schema.ConfigSchema in project nifi-minifi by apache.

the class NiFiRegConfigSchemaFunction method apply.

@Override
public ConfigSchema apply(final VersionedFlowSnapshot versionedFlowSnapshot) {
    Map<String, Object> map = new HashMap<>();
    map.put(CommonPropertyKeys.FLOW_CONTROLLER_PROPS_KEY, flowControllerSchemaFunction.apply(versionedFlowSnapshot).toMap());
    VersionedProcessGroup versionedProcessGroup = versionedFlowSnapshot.getFlowContents();
    addVersionedProcessGroup(map, versionedProcessGroup);
    return new ConfigSchema(map);
}
Also used : HashMap(java.util.HashMap) VersionedProcessGroup(org.apache.nifi.registry.flow.VersionedProcessGroup) ConfigSchema(org.apache.nifi.minifi.commons.schema.ConfigSchema)

Example 20 with ConfigSchema

use of org.apache.nifi.minifi.commons.schema.ConfigSchema in project nifi-minifi by apache.

the class ConfigMain method transformTemplateToSchema.

public static ConfigSchema transformTemplateToSchema(InputStream source) throws JAXBException, IOException {
    try {
        TemplateDTO templateDTO = (TemplateDTO) JAXBContext.newInstance(TemplateDTO.class).createUnmarshaller().unmarshal(source);
        FlowSnippetDTOEnricher enricher = new FlowSnippetDTOEnricher();
        enricher.enrich(templateDTO.getSnippet(), templateDTO.getEncodingVersion());
        ConfigSchema configSchema = new ConfigSchemaFunction().apply(templateDTO);
        return configSchema;
    } finally {
        source.close();
    }
}
Also used : NiFiRegConfigSchemaFunction(org.apache.nifi.minifi.toolkit.configuration.registry.NiFiRegConfigSchemaFunction) ConfigSchemaFunction(org.apache.nifi.minifi.toolkit.configuration.dto.ConfigSchemaFunction) FlowSnippetDTOEnricher(org.apache.nifi.minifi.toolkit.configuration.dto.FlowSnippetDTOEnricher) TemplateDTO(org.apache.nifi.web.api.dto.TemplateDTO) 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