Search in sources :

Example 11 with ConfigurationChangeException

use of org.apache.nifi.minifi.bootstrap.configuration.ConfigurationChangeException 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

ConfigurationChangeException (org.apache.nifi.minifi.bootstrap.configuration.ConfigurationChangeException)11 IOException (java.io.IOException)10 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)9 TransformerException (javax.xml.transform.TransformerException)9 InvalidConfigurationException (org.apache.nifi.minifi.bootstrap.exception.InvalidConfigurationException)9 DOMException (org.w3c.dom.DOMException)9 Element (org.w3c.dom.Element)9 Document (org.w3c.dom.Document)5 HashMap (java.util.HashMap)3 SecurityPropertiesSchema (org.apache.nifi.minifi.commons.schema.SecurityPropertiesSchema)3 CorePropertiesSchema (org.apache.nifi.minifi.commons.schema.CorePropertiesSchema)2 ProcessGroupSchema (org.apache.nifi.minifi.commons.schema.ProcessGroupSchema)2 ProvenanceReportingSchema (org.apache.nifi.minifi.commons.schema.ProvenanceReportingSchema)2 RemotePortSchema (org.apache.nifi.minifi.commons.schema.RemotePortSchema)2 RemoteProcessGroupSchema (org.apache.nifi.minifi.commons.schema.RemoteProcessGroupSchema)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 EOFException (java.io.EOFException)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1