Search in sources :

Example 1 with PrimaryNodeState

use of org.apache.nifi.annotation.notification.PrimaryNodeState in project nifi by apache.

the class FlowController method setPrimary.

public void setPrimary(final boolean primary) {
    final PrimaryNodeState nodeState = primary ? PrimaryNodeState.ELECTED_PRIMARY_NODE : PrimaryNodeState.PRIMARY_NODE_REVOKED;
    final ProcessGroup rootGroup = getGroup(getRootGroupId());
    for (final ProcessorNode procNode : rootGroup.findAllProcessors()) {
        try (final NarCloseable narCloseable = NarCloseable.withComponentNarLoader(procNode.getProcessor().getClass(), procNode.getIdentifier())) {
            ReflectionUtils.quietlyInvokeMethodsWithAnnotation(OnPrimaryNodeStateChange.class, procNode.getProcessor(), nodeState);
        }
    }
    for (final ControllerServiceNode serviceNode : getAllControllerServices()) {
        try (final NarCloseable narCloseable = NarCloseable.withComponentNarLoader(serviceNode.getControllerServiceImplementation().getClass(), serviceNode.getIdentifier())) {
            ReflectionUtils.quietlyInvokeMethodsWithAnnotation(OnPrimaryNodeStateChange.class, serviceNode.getControllerServiceImplementation(), nodeState);
        }
    }
    for (final ReportingTaskNode reportingTaskNode : getAllReportingTasks()) {
        try (final NarCloseable narCloseable = NarCloseable.withComponentNarLoader(reportingTaskNode.getReportingTask().getClass(), reportingTaskNode.getIdentifier())) {
            ReflectionUtils.quietlyInvokeMethodsWithAnnotation(OnPrimaryNodeStateChange.class, reportingTaskNode.getReportingTask(), nodeState);
        }
    }
    // update primary
    eventDrivenWorkerQueue.setPrimary(primary);
    // update the heartbeat bean
    final HeartbeatBean oldBean = this.heartbeatBeanRef.getAndSet(new HeartbeatBean(rootGroup, primary));
    // Emit a bulletin detailing the fact that the primary node state has changed
    if (oldBean == null || oldBean.isPrimary() != primary) {
        final String message = primary ? "This node has been elected Primary Node" : "This node is no longer Primary Node";
        final Bulletin bulletin = BulletinFactory.createBulletin("Primary Node", Severity.INFO.name(), message);
        bulletinRepository.addBulletin(bulletin);
        LOG.info(message);
    }
}
Also used : NarCloseable(org.apache.nifi.nar.NarCloseable) Bulletin(org.apache.nifi.reporting.Bulletin) ControllerServiceNode(org.apache.nifi.controller.service.ControllerServiceNode) StandardReportingTaskNode(org.apache.nifi.controller.reporting.StandardReportingTaskNode) VersionedProcessGroup(org.apache.nifi.registry.flow.VersionedProcessGroup) StandardProcessGroup(org.apache.nifi.groups.StandardProcessGroup) RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup) ProcessGroup(org.apache.nifi.groups.ProcessGroup) StandardRemoteProcessGroup(org.apache.nifi.remote.StandardRemoteProcessGroup) PrimaryNodeState(org.apache.nifi.annotation.notification.PrimaryNodeState)

Aggregations

PrimaryNodeState (org.apache.nifi.annotation.notification.PrimaryNodeState)1 StandardReportingTaskNode (org.apache.nifi.controller.reporting.StandardReportingTaskNode)1 ControllerServiceNode (org.apache.nifi.controller.service.ControllerServiceNode)1 ProcessGroup (org.apache.nifi.groups.ProcessGroup)1 RemoteProcessGroup (org.apache.nifi.groups.RemoteProcessGroup)1 StandardProcessGroup (org.apache.nifi.groups.StandardProcessGroup)1 NarCloseable (org.apache.nifi.nar.NarCloseable)1 VersionedProcessGroup (org.apache.nifi.registry.flow.VersionedProcessGroup)1 StandardRemoteProcessGroup (org.apache.nifi.remote.StandardRemoteProcessGroup)1 Bulletin (org.apache.nifi.reporting.Bulletin)1