Search in sources :

Example 1 with ConnectionSchema

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

the class ConnectionSchemaV1Test method testConnectionGeneratedIds.

@Test
public void testConnectionGeneratedIds() {
    List<Map<String, Object>> listWithKeyValues = getListWithKeyValues(CommonPropertyKeys.NAME_KEY, "test", "test", "test_2", "test", "test_2");
    ConfigSchema configSchema = new ConfigSchemaV1(Collections.singletonMap(CommonPropertyKeys.CONNECTIONS_KEY, listWithKeyValues)).convert();
    assertMessageDoesNotExist(configSchema, ConfigSchema.FOUND_THE_FOLLOWING_DUPLICATE_CONNECTION_IDS);
    List<ConnectionSchema> connections = configSchema.getProcessGroupSchema().getConnections();
    assertEquals(5, connections.size());
    // Generated unique ids
    assertEquals("098f6bcd-4621-3373-8ade-4e832627b4f6", connections.get(0).getId());
    assertEquals("098f6bcd-4621-3373-8ade-4e832627b4f7", connections.get(1).getId());
    assertEquals("b9dacbc6-7962-39a9-9e45-394e2cf0dbf6", connections.get(2).getId());
    assertEquals("098f6bcd-4621-3373-8ade-4e832627b4f8", connections.get(3).getId());
    assertEquals("b9dacbc6-7962-39a9-9e45-394e2cf0dbf7", connections.get(4).getId());
}
Also used : ConnectionSchema(org.apache.nifi.minifi.commons.schema.ConnectionSchema) HashMap(java.util.HashMap) Map(java.util.Map) ConfigSchema(org.apache.nifi.minifi.commons.schema.ConfigSchema) Test(org.junit.Test)

Example 2 with ConnectionSchema

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

the class ConfigTransformerTest method testNullQueuePrioritizerNotWritten.

@Test
public void testNullQueuePrioritizerNotWritten() throws ConfigurationChangeException, XPathExpressionException {
    ConfigTransformer.addConnection(config, new ConnectionSchema(Collections.emptyMap()), new ParentGroupIdResolver(new ProcessGroupSchema(Collections.emptyMap(), ConfigSchema.TOP_LEVEL_NAME)));
    XPath xpath = xPathFactory.newXPath();
    String expression = "connection/queuePrioritizerClass";
    assertNull(xpath.evaluate(expression, config, XPathConstants.NODE));
}
Also used : ConnectionSchema(org.apache.nifi.minifi.commons.schema.ConnectionSchema) XPath(javax.xml.xpath.XPath) RemoteProcessGroupSchema(org.apache.nifi.minifi.commons.schema.RemoteProcessGroupSchema) ProcessGroupSchema(org.apache.nifi.minifi.commons.schema.ProcessGroupSchema) Test(org.junit.Test)

Example 3 with ConnectionSchema

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

the class ConfigTransformerTest method testQueuePrioritizerWritten.

@Test
public void testQueuePrioritizerWritten() throws ConfigurationChangeException, XPathExpressionException {
    Map<String, Object> map = new HashMap<>();
    map.put(ConnectionSchema.QUEUE_PRIORITIZER_CLASS_KEY, "org.apache.nifi.prioritizer.FirstInFirstOutPrioritizer");
    ConfigTransformer.addConnection(config, new ConnectionSchema(map), new ParentGroupIdResolver(new ProcessGroupSchema(Collections.emptyMap(), ConfigSchema.TOP_LEVEL_NAME)));
    XPath xpath = xPathFactory.newXPath();
    String expression = "connection/queuePrioritizerClass/text()";
    assertEquals("org.apache.nifi.prioritizer.FirstInFirstOutPrioritizer", xpath.evaluate(expression, config, XPathConstants.STRING));
}
Also used : ConnectionSchema(org.apache.nifi.minifi.commons.schema.ConnectionSchema) XPath(javax.xml.xpath.XPath) HashMap(java.util.HashMap) RemoteProcessGroupSchema(org.apache.nifi.minifi.commons.schema.RemoteProcessGroupSchema) ProcessGroupSchema(org.apache.nifi.minifi.commons.schema.ProcessGroupSchema) Test(org.junit.Test)

Example 4 with ConnectionSchema

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

the class ConfigTransformer method addProcessGroup.

protected static void addProcessGroup(Document doc, Element element, ProcessGroupSchema processGroupSchema, ParentGroupIdResolver parentGroupIdResolver) throws ConfigurationChangeException {
    try {
        String processGroupId = processGroupSchema.getId();
        addTextElement(element, "id", processGroupId);
        addTextElement(element, "name", processGroupSchema.getName());
        addPosition(element);
        addTextElement(element, "comment", processGroupSchema.getComment());
        for (ProcessorSchema processorConfig : processGroupSchema.getProcessors()) {
            addProcessor(element, processorConfig);
        }
        for (PortSchema portSchema : processGroupSchema.getInputPortSchemas()) {
            addPort(doc, element, portSchema, "inputPort");
        }
        for (PortSchema portSchema : processGroupSchema.getOutputPortSchemas()) {
            addPort(doc, element, portSchema, "outputPort");
        }
        for (FunnelSchema funnelSchema : processGroupSchema.getFunnels()) {
            addFunnel(element, funnelSchema);
        }
        for (ProcessGroupSchema child : processGroupSchema.getProcessGroupSchemas()) {
            Element processGroups = doc.createElement("processGroup");
            element.appendChild(processGroups);
            addProcessGroup(doc, processGroups, child, parentGroupIdResolver);
        }
        for (RemoteProcessGroupSchema remoteProcessGroupSchema : processGroupSchema.getRemoteProcessGroups()) {
            addRemoteProcessGroup(element, remoteProcessGroupSchema);
        }
        for (ConnectionSchema connectionConfig : processGroupSchema.getConnections()) {
            addConnection(element, connectionConfig, parentGroupIdResolver);
        }
        for (ControllerServiceSchema controllerServiceSchema : processGroupSchema.getControllerServices()) {
            addControllerService(element, controllerServiceSchema);
        }
    } catch (ConfigurationChangeException e) {
        throw e;
    } catch (Exception e) {
        throw new ConfigurationChangeException("Failed to parse the config YAML while trying to creating the root Process Group", e);
    }
}
Also used : ConnectionSchema(org.apache.nifi.minifi.commons.schema.ConnectionSchema) RemoteProcessGroupSchema(org.apache.nifi.minifi.commons.schema.RemoteProcessGroupSchema) ProcessGroupSchema(org.apache.nifi.minifi.commons.schema.ProcessGroupSchema) Element(org.w3c.dom.Element) ControllerServiceSchema(org.apache.nifi.minifi.commons.schema.ControllerServiceSchema) ConfigurationChangeException(org.apache.nifi.minifi.bootstrap.configuration.ConfigurationChangeException) FunnelSchema(org.apache.nifi.minifi.commons.schema.FunnelSchema) RemotePortSchema(org.apache.nifi.minifi.commons.schema.RemotePortSchema) PortSchema(org.apache.nifi.minifi.commons.schema.PortSchema) InvalidConfigurationException(org.apache.nifi.minifi.bootstrap.exception.InvalidConfigurationException) ConfigurationChangeException(org.apache.nifi.minifi.bootstrap.configuration.ConfigurationChangeException) TransformerException(javax.xml.transform.TransformerException) DOMException(org.w3c.dom.DOMException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) ProcessorSchema(org.apache.nifi.minifi.commons.schema.ProcessorSchema) RemoteProcessGroupSchema(org.apache.nifi.minifi.commons.schema.RemoteProcessGroupSchema)

Example 5 with ConnectionSchema

use of org.apache.nifi.minifi.commons.schema.ConnectionSchema 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)

Aggregations

ConnectionSchema (org.apache.nifi.minifi.commons.schema.ConnectionSchema)9 HashMap (java.util.HashMap)7 RemoteProcessGroupSchema (org.apache.nifi.minifi.commons.schema.RemoteProcessGroupSchema)6 ProcessGroupSchema (org.apache.nifi.minifi.commons.schema.ProcessGroupSchema)4 Test (org.junit.Test)4 Map (java.util.Map)3 XPath (javax.xml.xpath.XPath)3 ConfigSchema (org.apache.nifi.minifi.commons.schema.ConfigSchema)3 ProcessorSchema (org.apache.nifi.minifi.commons.schema.ProcessorSchema)3 RemotePortSchema (org.apache.nifi.minifi.commons.schema.RemotePortSchema)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Set (java.util.Set)2 ConvertableSchema (org.apache.nifi.minifi.commons.schema.common.ConvertableSchema)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 InputStream (java.io.InputStream)1