Search in sources :

Example 21 with ReportingTaskNode

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

the class ControllerServiceAuditor method getUpdateActionsForReferencingComponents.

/**
 * Gets the update actions for all specified referencing components.
 *
 * @param user user
 * @param actions actions
 * @param visitedServices services
 * @param referencingComponents components
 */
private void getUpdateActionsForReferencingComponents(final NiFiUser user, final Collection<Action> actions, final Collection<String> visitedServices, final Set<ConfiguredComponent> referencingComponents) {
    // consider each component updates
    for (final ConfiguredComponent component : referencingComponents) {
        if (component instanceof ProcessorNode) {
            final ProcessorNode processor = ((ProcessorNode) component);
            // create the processor details
            FlowChangeExtensionDetails processorDetails = new FlowChangeExtensionDetails();
            processorDetails.setType(processor.getComponentType());
            // create a processor action
            FlowChangeAction processorAction = new FlowChangeAction();
            processorAction.setUserIdentity(user.getIdentity());
            processorAction.setTimestamp(new Date());
            processorAction.setSourceId(processor.getIdentifier());
            processorAction.setSourceName(processor.getName());
            processorAction.setSourceType(Component.Processor);
            processorAction.setComponentDetails(processorDetails);
            processorAction.setOperation(ScheduledState.RUNNING.equals(processor.getScheduledState()) ? Operation.Start : Operation.Stop);
            actions.add(processorAction);
        } else if (component instanceof ReportingTask) {
            final ReportingTaskNode reportingTask = ((ReportingTaskNode) component);
            // create the reporting task details
            FlowChangeExtensionDetails taskDetails = new FlowChangeExtensionDetails();
            taskDetails.setType(reportingTask.getComponentType());
            // create a reporting task action
            FlowChangeAction reportingTaskAction = new FlowChangeAction();
            reportingTaskAction.setUserIdentity(user.getIdentity());
            reportingTaskAction.setTimestamp(new Date());
            reportingTaskAction.setSourceId(reportingTask.getIdentifier());
            reportingTaskAction.setSourceName(reportingTask.getName());
            reportingTaskAction.setSourceType(Component.ReportingTask);
            reportingTaskAction.setComponentDetails(taskDetails);
            reportingTaskAction.setOperation(ScheduledState.RUNNING.equals(reportingTask.getScheduledState()) ? Operation.Start : Operation.Stop);
            actions.add(reportingTaskAction);
        } else if (component instanceof ControllerServiceNode) {
            final ControllerServiceNode controllerService = ((ControllerServiceNode) component);
            // create the controller service details
            FlowChangeExtensionDetails serviceDetails = new FlowChangeExtensionDetails();
            serviceDetails.setType(controllerService.getComponentType());
            // create a controller service action
            FlowChangeAction serviceAction = new FlowChangeAction();
            serviceAction.setUserIdentity(user.getIdentity());
            serviceAction.setTimestamp(new Date());
            serviceAction.setSourceId(controllerService.getIdentifier());
            serviceAction.setSourceName(controllerService.getName());
            serviceAction.setSourceType(Component.ControllerService);
            serviceAction.setComponentDetails(serviceDetails);
            serviceAction.setOperation(isDisabled(controllerService) ? Operation.Disable : Operation.Enable);
            actions.add(serviceAction);
            // need to consider components referencing this controller service (transitive)
            if (!visitedServices.contains(controllerService.getIdentifier())) {
                getUpdateActionsForReferencingComponents(user, actions, visitedServices, controllerService.getReferences().getReferencingComponents());
            }
        }
    }
}
Also used : ProcessorNode(org.apache.nifi.controller.ProcessorNode) ReportingTaskNode(org.apache.nifi.controller.ReportingTaskNode) ControllerServiceNode(org.apache.nifi.controller.service.ControllerServiceNode) ConfiguredComponent(org.apache.nifi.controller.ConfiguredComponent) FlowChangeExtensionDetails(org.apache.nifi.action.component.details.FlowChangeExtensionDetails) Date(java.util.Date) FlowChangeAction(org.apache.nifi.action.FlowChangeAction) ReportingTask(org.apache.nifi.reporting.ReportingTask)

Example 22 with ReportingTaskNode

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

the class StandardControllerServiceProvider method unscheduleReferencingComponents.

@Override
public Set<ConfiguredComponent> unscheduleReferencingComponents(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 stop all components (that are running) before doing anything
    for (final ProcessorNode node : processors) {
        if (node.getScheduledState() == ScheduledState.RUNNING) {
            node.verifyCanStop();
        }
    }
    for (final ReportingTaskNode node : reportingTasks) {
        if (node.getScheduledState() == ScheduledState.RUNNING) {
            node.verifyCanStop();
        }
    }
    // stop all of the components that are running
    for (final ProcessorNode node : processors) {
        if (node.getScheduledState() == ScheduledState.RUNNING) {
            node.getProcessGroup().stopProcessor(node);
            updated.add(node);
        }
    }
    for (final ReportingTaskNode node : reportingTasks) {
        if (node.getScheduledState() == ScheduledState.RUNNING) {
            processScheduler.unschedule(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)

Example 23 with ReportingTaskNode

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

the class StandardNiFiServiceFacade method getReportingTaskState.

@Override
public ComponentStateDTO getReportingTaskState(final String reportingTaskId) {
    final StateMap clusterState = isClustered() ? reportingTaskDAO.getState(reportingTaskId, Scope.CLUSTER) : null;
    final StateMap localState = reportingTaskDAO.getState(reportingTaskId, Scope.LOCAL);
    // reporting task will be non null as it was already found when getting the state
    final ReportingTaskNode reportingTask = reportingTaskDAO.getReportingTask(reportingTaskId);
    return dtoFactory.createComponentStateDTO(reportingTaskId, reportingTask.getReportingTask().getClass(), localState, clusterState);
}
Also used : ReportingTaskNode(org.apache.nifi.controller.ReportingTaskNode) StateMap(org.apache.nifi.components.state.StateMap)

Example 24 with ReportingTaskNode

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

the class StandardReportingTaskDAO method deleteReportingTask.

@Override
public void deleteReportingTask(String reportingTaskId) {
    final ReportingTaskNode reportingTask = locateReportingTask(reportingTaskId);
    reportingTaskProvider.removeReportingTask(reportingTask);
}
Also used : ReportingTaskNode(org.apache.nifi.controller.ReportingTaskNode)

Example 25 with ReportingTaskNode

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

the class StandardReportingTaskDAO method verifyClearState.

@Override
public void verifyClearState(String reportingTaskId) {
    final ReportingTaskNode reportingTask = locateReportingTask(reportingTaskId);
    reportingTask.verifyCanClearState();
}
Also used : ReportingTaskNode(org.apache.nifi.controller.ReportingTaskNode)

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