Search in sources :

Example 1 with ProvenanceReportingSchema

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

the class ConfigTransformer method addProvenanceReportingTask.

protected static void addProvenanceReportingTask(final Element element, ConfigSchema configSchema) throws ConfigurationChangeException {
    try {
        ProvenanceReportingSchema provenanceProperties = configSchema.getProvenanceReportingProperties();
        final Element taskElement = element.getOwnerDocument().createElement("reportingTask");
        addTextElement(taskElement, "id", "Provenance-Reporting");
        addTextElement(taskElement, "name", "Site-To-Site-Provenance-Reporting");
        addTextElement(taskElement, "comment", provenanceProperties.getComment());
        addTextElement(taskElement, "class", DEFAULT_PROV_REPORTING_TASK_CLASS);
        addTextElement(taskElement, "schedulingPeriod", provenanceProperties.getSchedulingPeriod());
        addTextElement(taskElement, "scheduledState", "RUNNING");
        addTextElement(taskElement, "schedulingStrategy", provenanceProperties.getSchedulingStrategy());
        Map<String, Object> attributes = new HashMap<>();
        attributes.put("Destination URL", provenanceProperties.getDestinationUrl());
        attributes.put("Input Port Name", provenanceProperties.getPortName());
        attributes.put("Instance URL", provenanceProperties.getOriginatingUrl());
        attributes.put("Compress Events", provenanceProperties.getUseCompression());
        attributes.put("Batch Size", provenanceProperties.getBatchSize());
        attributes.put("Communications Timeout", provenanceProperties.getTimeout());
        SecurityPropertiesSchema securityProps = configSchema.getSecurityProperties();
        if (securityProps.useSSL()) {
            attributes.put("SSL Context Service", "SSL-Context-Service");
        }
        addConfiguration(taskElement, attributes);
        element.appendChild(taskElement);
    } catch (Exception e) {
        throw new ConfigurationChangeException("Failed to parse the config YAML while trying to add the Provenance Reporting Task", e);
    }
}
Also used : HashMap(java.util.HashMap) SecurityPropertiesSchema(org.apache.nifi.minifi.commons.schema.SecurityPropertiesSchema) ProvenanceReportingSchema(org.apache.nifi.minifi.commons.schema.ProvenanceReportingSchema) Element(org.w3c.dom.Element) ConfigurationChangeException(org.apache.nifi.minifi.bootstrap.configuration.ConfigurationChangeException) 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)

Example 2 with ProvenanceReportingSchema

use of org.apache.nifi.minifi.commons.schema.ProvenanceReportingSchema 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)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 ProvenanceReportingSchema (org.apache.nifi.minifi.commons.schema.ProvenanceReportingSchema)2 SecurityPropertiesSchema (org.apache.nifi.minifi.commons.schema.SecurityPropertiesSchema)2 DOMException (org.w3c.dom.DOMException)2 Element (org.w3c.dom.Element)2 HashMap (java.util.HashMap)1 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 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 RemoteProcessGroupSchema (org.apache.nifi.minifi.commons.schema.RemoteProcessGroupSchema)1 Document (org.w3c.dom.Document)1