Search in sources :

Example 1 with ProcessGroupSchema

use of org.apache.nifi.minifi.commons.schema.ProcessGroupSchema 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 2 with ProcessGroupSchema

use of org.apache.nifi.minifi.commons.schema.ProcessGroupSchema 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 3 with ProcessGroupSchema

use of org.apache.nifi.minifi.commons.schema.ProcessGroupSchema 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 4 with ProcessGroupSchema

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

the class ConfigTransformerTest method testEmptyQueuePrioritizerNotWritten.

@Test
public void testEmptyQueuePrioritizerNotWritten() throws ConfigurationChangeException, XPathExpressionException {
    Map<String, Object> map = new HashMap<>();
    map.put(ConnectionSchema.QUEUE_PRIORITIZER_CLASS_KEY, "");
    ConfigTransformer.addConnection(config, new ConnectionSchema(map), 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) 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 5 with ProcessGroupSchema

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

the class ConfigTransformer method createFlowXml.

protected static DOMSource createFlowXml(ConfigSchema configSchema) throws IOException, ConfigurationChangeException, ConfigTransformerException {
    try {
        // create a new, empty document
        final DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
        docFactory.setNamespaceAware(true);
        final DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
        final Document doc = docBuilder.newDocument();
        // populate document with controller state
        final Element rootNode = doc.createElement("flowController");
        doc.appendChild(rootNode);
        CorePropertiesSchema coreProperties = configSchema.getCoreProperties();
        addTextElement(rootNode, "maxTimerDrivenThreadCount", String.valueOf(coreProperties.getMaxConcurrentThreads()));
        addTextElement(rootNode, "maxEventDrivenThreadCount", String.valueOf(coreProperties.getMaxConcurrentThreads()));
        FlowControllerSchema flowControllerProperties = configSchema.getFlowControllerProperties();
        final Element element = doc.createElement("rootGroup");
        rootNode.appendChild(element);
        ProcessGroupSchema processGroupSchema = configSchema.getProcessGroupSchema();
        processGroupSchema.setId(ROOT_GROUP);
        processGroupSchema.setName(flowControllerProperties.getName());
        processGroupSchema.setComment(flowControllerProperties.getComment());
        addProcessGroup(doc, element, processGroupSchema, new ParentGroupIdResolver(processGroupSchema));
        SecurityPropertiesSchema securityProperties = configSchema.getSecurityProperties();
        if (securityProperties.useSSL()) {
            Element controllerServicesNode = doc.getElementById("controllerServices");
            if (controllerServicesNode == null) {
                controllerServicesNode = doc.createElement("controllerServices");
            }
            rootNode.appendChild(controllerServicesNode);
            addSSLControllerService(controllerServicesNode, securityProperties);
        }
        ProvenanceReportingSchema provenanceProperties = configSchema.getProvenanceReportingProperties();
        if (provenanceProperties != null) {
            final Element reportingTasksNode = doc.createElement("reportingTasks");
            rootNode.appendChild(reportingTasksNode);
            addProvenanceReportingTask(reportingTasksNode, configSchema);
        }
        return new DOMSource(doc);
    } catch (final ParserConfigurationException | DOMException | TransformerFactoryConfigurationError | IllegalArgumentException e) {
        throw new ConfigTransformerException(e);
    } catch (Exception e) {
        throw new ConfigTransformerException("Failed to parse the config YAML while writing the top level of the flow xml", e);
    }
}
Also used : TransformerFactoryConfigurationError(javax.xml.transform.TransformerFactoryConfigurationError) DOMSource(javax.xml.transform.dom.DOMSource) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) Element(org.w3c.dom.Element) RemoteProcessGroupSchema(org.apache.nifi.minifi.commons.schema.RemoteProcessGroupSchema) ProcessGroupSchema(org.apache.nifi.minifi.commons.schema.ProcessGroupSchema) ProvenanceReportingSchema(org.apache.nifi.minifi.commons.schema.ProvenanceReportingSchema) Document(org.w3c.dom.Document) 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) DOMException(org.w3c.dom.DOMException) DocumentBuilder(javax.xml.parsers.DocumentBuilder) SecurityPropertiesSchema(org.apache.nifi.minifi.commons.schema.SecurityPropertiesSchema) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) FlowControllerSchema(org.apache.nifi.minifi.commons.schema.FlowControllerSchema) CorePropertiesSchema(org.apache.nifi.minifi.commons.schema.CorePropertiesSchema)

Aggregations

ProcessGroupSchema (org.apache.nifi.minifi.commons.schema.ProcessGroupSchema)5 RemoteProcessGroupSchema (org.apache.nifi.minifi.commons.schema.RemoteProcessGroupSchema)5 ConnectionSchema (org.apache.nifi.minifi.commons.schema.ConnectionSchema)4 XPath (javax.xml.xpath.XPath)3 Test (org.junit.Test)3 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 TransformerException (javax.xml.transform.TransformerException)2 ConfigurationChangeException (org.apache.nifi.minifi.bootstrap.configuration.ConfigurationChangeException)2 InvalidConfigurationException (org.apache.nifi.minifi.bootstrap.exception.InvalidConfigurationException)2 DOMException (org.w3c.dom.DOMException)2 Element (org.w3c.dom.Element)2 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1 TransformerFactoryConfigurationError (javax.xml.transform.TransformerFactoryConfigurationError)1 DOMSource (javax.xml.transform.dom.DOMSource)1 ControllerServiceSchema (org.apache.nifi.minifi.commons.schema.ControllerServiceSchema)1 CorePropertiesSchema (org.apache.nifi.minifi.commons.schema.CorePropertiesSchema)1 FlowControllerSchema (org.apache.nifi.minifi.commons.schema.FlowControllerSchema)1