Search in sources :

Example 1 with FlowControllerSchema

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

IOException (java.io.IOException)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 TransformerException (javax.xml.transform.TransformerException)1 TransformerFactoryConfigurationError (javax.xml.transform.TransformerFactoryConfigurationError)1 DOMSource (javax.xml.transform.dom.DOMSource)1 ConfigurationChangeException (org.apache.nifi.minifi.bootstrap.configuration.ConfigurationChangeException)1 InvalidConfigurationException (org.apache.nifi.minifi.bootstrap.exception.InvalidConfigurationException)1 CorePropertiesSchema (org.apache.nifi.minifi.commons.schema.CorePropertiesSchema)1 FlowControllerSchema (org.apache.nifi.minifi.commons.schema.FlowControllerSchema)1 ProcessGroupSchema (org.apache.nifi.minifi.commons.schema.ProcessGroupSchema)1 ProvenanceReportingSchema (org.apache.nifi.minifi.commons.schema.ProvenanceReportingSchema)1 RemoteProcessGroupSchema (org.apache.nifi.minifi.commons.schema.RemoteProcessGroupSchema)1 SecurityPropertiesSchema (org.apache.nifi.minifi.commons.schema.SecurityPropertiesSchema)1 DOMException (org.w3c.dom.DOMException)1 Document (org.w3c.dom.Document)1 Element (org.w3c.dom.Element)1