Search in sources :

Example 11 with ReportingTaskNode

use of org.apache.nifi.controller.ReportingTaskNode in project nifi by apache.

the class ReportingTaskAuditor method createReportingTaskAdvice.

/**
 * Audits the creation of reporting task via createReportingTask().
 *
 * This method only needs to be run 'after returning'. However, in Java 7 the order in which these methods are returned from Class.getDeclaredMethods (even though there is no order guaranteed)
 * seems to differ from Java 6. SpringAOP depends on this ordering to determine advice precedence. By normalizing all advice into Around advice we can alleviate this issue.
 *
 * @param proceedingJoinPoint joinpoint
 * @return node
 * @throws java.lang.Throwable ex
 */
@Around("within(org.apache.nifi.web.dao.ReportingTaskDAO+) && " + "execution(org.apache.nifi.controller.ReportingTaskNode createReportingTask(org.apache.nifi.web.api.dto.ReportingTaskDTO))")
public ReportingTaskNode createReportingTaskAdvice(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
    // update the reporting task state
    ReportingTaskNode reportingTask = (ReportingTaskNode) proceedingJoinPoint.proceed();
    // if no exceptions were thrown, add the reporting task action...
    final Action action = generateAuditRecord(reportingTask, Operation.Add);
    // save the actions
    if (action != null) {
        saveAction(action, logger);
    }
    return reportingTask;
}
Also used : FlowChangeAction(org.apache.nifi.action.FlowChangeAction) Action(org.apache.nifi.action.Action) ReportingTaskNode(org.apache.nifi.controller.ReportingTaskNode) Around(org.aspectj.lang.annotation.Around)

Example 12 with ReportingTaskNode

use of org.apache.nifi.controller.ReportingTaskNode in project nifi by apache.

the class ReportingTaskAuditor method removeReportingTaskAdvice.

/**
 * Audits the removal of a reporting task via deleteReportingTask().
 *
 * @param proceedingJoinPoint join point
 * @param reportingTaskId task id
 * @param reportingTaskDAO task dao
 * @throws Throwable ex
 */
@Around("within(org.apache.nifi.web.dao.ReportingTaskDAO+) && " + "execution(void deleteReportingTask(java.lang.String)) && " + "args(reportingTaskId) && " + "target(reportingTaskDAO)")
public void removeReportingTaskAdvice(ProceedingJoinPoint proceedingJoinPoint, String reportingTaskId, ReportingTaskDAO reportingTaskDAO) throws Throwable {
    // get the reporting task before removing it
    ReportingTaskNode reportingTask = reportingTaskDAO.getReportingTask(reportingTaskId);
    // remove the reporting task
    proceedingJoinPoint.proceed();
    // if no exceptions were thrown, add removal actions...
    // audit the reporting task removal
    final Action action = generateAuditRecord(reportingTask, Operation.Remove);
    // save the actions
    if (action != null) {
        saveAction(action, logger);
    }
}
Also used : FlowChangeAction(org.apache.nifi.action.FlowChangeAction) Action(org.apache.nifi.action.Action) ReportingTaskNode(org.apache.nifi.controller.ReportingTaskNode) Around(org.aspectj.lang.annotation.Around)

Example 13 with ReportingTaskNode

use of org.apache.nifi.controller.ReportingTaskNode in project nifi by apache.

the class StandardFlowSerializer method serialize.

@Override
public void serialize(final FlowController controller, final OutputStream os, final ScheduledStateLookup scheduledStateLookup) throws FlowSerializationException {
    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");
        rootNode.setAttribute("encoding-version", MAX_ENCODING_VERSION);
        doc.appendChild(rootNode);
        addTextElement(rootNode, "maxTimerDrivenThreadCount", controller.getMaxTimerDrivenThreadCount());
        addTextElement(rootNode, "maxEventDrivenThreadCount", controller.getMaxEventDrivenThreadCount());
        final Element registriesElement = doc.createElement("registries");
        rootNode.appendChild(registriesElement);
        addFlowRegistries(registriesElement, controller.getFlowRegistryClient());
        addProcessGroup(rootNode, controller.getGroup(controller.getRootGroupId()), "rootGroup", scheduledStateLookup);
        // Add root-level controller services
        final Element controllerServicesNode = doc.createElement("controllerServices");
        rootNode.appendChild(controllerServicesNode);
        for (final ControllerServiceNode serviceNode : controller.getRootControllerServices()) {
            addControllerService(controllerServicesNode, serviceNode);
        }
        final Element reportingTasksNode = doc.createElement("reportingTasks");
        rootNode.appendChild(reportingTasksNode);
        for (final ReportingTaskNode taskNode : controller.getAllReportingTasks()) {
            addReportingTask(reportingTasksNode, taskNode, encryptor);
        }
        final DOMSource domSource = new DOMSource(doc);
        final StreamResult streamResult = new StreamResult(new BufferedOutputStream(os));
        // configure the transformer and convert the DOM
        final TransformerFactory transformFactory = TransformerFactory.newInstance();
        final Transformer transformer = transformFactory.newTransformer();
        transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
        // transform the document to byte stream
        transformer.transform(domSource, streamResult);
    } catch (final ParserConfigurationException | DOMException | TransformerFactoryConfigurationError | IllegalArgumentException | TransformerException e) {
        throw new FlowSerializationException(e);
    }
}
Also used : TransformerFactoryConfigurationError(javax.xml.transform.TransformerFactoryConfigurationError) DOMSource(javax.xml.transform.dom.DOMSource) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) TransformerFactory(javax.xml.transform.TransformerFactory) Transformer(javax.xml.transform.Transformer) StreamResult(javax.xml.transform.stream.StreamResult) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) DOMException(org.w3c.dom.DOMException) DocumentBuilder(javax.xml.parsers.DocumentBuilder) ControllerServiceNode(org.apache.nifi.controller.service.ControllerServiceNode) ReportingTaskNode(org.apache.nifi.controller.ReportingTaskNode) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) BufferedOutputStream(java.io.BufferedOutputStream) TransformerException(javax.xml.transform.TransformerException)

Example 14 with ReportingTaskNode

use of org.apache.nifi.controller.ReportingTaskNode in project nifi by apache.

the class StandardControllerServiceProvider method verifyCanScheduleReferencingComponents.

@Override
public void verifyCanScheduleReferencingComponents(final ControllerServiceNode serviceNode) {
    final List<ControllerServiceNode> referencingServices = serviceNode.getReferences().findRecursiveReferences(ControllerServiceNode.class);
    final List<ReportingTaskNode> referencingReportingTasks = serviceNode.getReferences().findRecursiveReferences(ReportingTaskNode.class);
    final List<ProcessorNode> referencingProcessors = serviceNode.getReferences().findRecursiveReferences(ProcessorNode.class);
    final Set<ControllerServiceNode> referencingServiceSet = new HashSet<>(referencingServices);
    for (final ReportingTaskNode taskNode : referencingReportingTasks) {
        if (taskNode.getScheduledState() != ScheduledState.DISABLED) {
            taskNode.verifyCanStart(referencingServiceSet);
        }
    }
    for (final ProcessorNode procNode : referencingProcessors) {
        if (procNode.getScheduledState() != ScheduledState.DISABLED) {
            procNode.verifyCanStart(referencingServiceSet);
        }
    }
}
Also used : ProcessorNode(org.apache.nifi.controller.ProcessorNode) ReportingTaskNode(org.apache.nifi.controller.ReportingTaskNode) HashSet(java.util.HashSet)

Example 15 with ReportingTaskNode

use of org.apache.nifi.controller.ReportingTaskNode in project nifi by apache.

the class StandardControllerServiceProvider method scheduleReferencingComponents.

@Override
public Set<ConfiguredComponent> scheduleReferencingComponents(final ControllerServiceNode serviceNode) {
    // find all of the schedulable components (processors, reporting tasks) that refer to this Controller Service,
    // or a service that references this controller service, etc.
    final List<ProcessorNode> processors = serviceNode.getReferences().findRecursiveReferences(ProcessorNode.class);
    final List<ReportingTaskNode> reportingTasks = serviceNode.getReferences().findRecursiveReferences(ReportingTaskNode.class);
    final Set<ConfiguredComponent> updated = new HashSet<>();
    // verify that  we can start all components (that are not disabled) before doing anything
    for (final ProcessorNode node : processors) {
        if (node.getScheduledState() != ScheduledState.DISABLED) {
            node.verifyCanStart();
            updated.add(node);
        }
    }
    for (final ReportingTaskNode node : reportingTasks) {
        if (node.getScheduledState() != ScheduledState.DISABLED) {
            node.verifyCanStart();
            updated.add(node);
        }
    }
    // start all of the components that are not disabled
    for (final ProcessorNode node : processors) {
        if (node.getScheduledState() != ScheduledState.DISABLED) {
            node.getProcessGroup().startProcessor(node, true);
            updated.add(node);
        }
    }
    for (final ReportingTaskNode node : reportingTasks) {
        if (node.getScheduledState() != ScheduledState.DISABLED) {
            processScheduler.schedule(node);
            updated.add(node);
        }
    }
    return updated;
}
Also used : ProcessorNode(org.apache.nifi.controller.ProcessorNode) ReportingTaskNode(org.apache.nifi.controller.ReportingTaskNode) ConfiguredComponent(org.apache.nifi.controller.ConfiguredComponent) HashSet(java.util.HashSet)

Aggregations

ReportingTaskNode (org.apache.nifi.controller.ReportingTaskNode)27 ProcessorNode (org.apache.nifi.controller.ProcessorNode)11 HashSet (java.util.HashSet)9 ArrayList (java.util.ArrayList)8 PropertyDescriptor (org.apache.nifi.components.PropertyDescriptor)8 ControllerServiceNode (org.apache.nifi.controller.service.ControllerServiceNode)8 Date (java.util.Date)7 Action (org.apache.nifi.action.Action)7 FlowChangeAction (org.apache.nifi.action.FlowChangeAction)7 ConfiguredComponent (org.apache.nifi.controller.ConfiguredComponent)7 HashMap (java.util.HashMap)6 Map (java.util.Map)6 StateMap (org.apache.nifi.components.state.StateMap)6 Arrays (java.util.Arrays)5 Collection (java.util.Collection)5 Collections (java.util.Collections)5 Comparator (java.util.Comparator)5 LinkedHashMap (java.util.LinkedHashMap)5 List (java.util.List)5 Set (java.util.Set)5