Java Code Examples for org.apache.nifi.controller.ScheduledState#STOPPED

The following examples show how to use org.apache.nifi.controller.ScheduledState#STOPPED . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StandardRemoteGroupPort.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
@Override
public Collection<ValidationResult> getValidationErrors() {
    final Collection<ValidationResult> validationErrors = new ArrayList<>();
    if (getScheduledState() == ScheduledState.STOPPED) {
        ValidationResult error = null;
        if (!targetExists.get()) {
            error = new ValidationResult.Builder()
                    .explanation(String.format("Remote instance indicates that port '%s' no longer exists.", getName()))
                    .subject(String.format("Remote port '%s'", getName()))
                    .valid(false)
                    .build();
        } else if (getConnectableType() == ConnectableType.REMOTE_OUTPUT_PORT && getConnections(Relationship.ANONYMOUS).isEmpty()) {
            error = new ValidationResult.Builder()
                    .explanation(String.format("Port '%s' has no outbound connections", getName()))
                    .subject(String.format("Remote port '%s'", getName()))
                    .valid(false)
                    .build();
        }

        if (error != null) {
            validationErrors.add(error);
        }
    }
    return validationErrors;
}
 
Example 2
Source File: StandardProcessGroup.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
@Override
public void stopProcessor(final ProcessorNode processor) {
    readLock.lock();
    try {
        if (!processors.containsKey(processor.getIdentifier())) {
            throw new IllegalStateException("No processor with ID " + processor.getIdentifier() + " belongs to this Process Group");
        }

        final ScheduledState state = processor.getScheduledState();
        if (state == ScheduledState.DISABLED) {
            throw new IllegalStateException("Processor is disabled");
        } else if (state == ScheduledState.STOPPED) {
            return;
        }

        scheduler.stopProcessor(processor);
    } finally {
        readLock.unlock();
    }
}
 
Example 3
Source File: StandardProcessGroup.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
@Override
public void stopInputPort(final Port port) {
    readLock.lock();
    try {
        if (!inputPorts.containsKey(port.getIdentifier())) {
            throw new IllegalStateException("No Input Port with ID " + port.getIdentifier() + " belongs to this Process Group");
        }

        final ScheduledState state = port.getScheduledState();
        if (state == ScheduledState.DISABLED) {
            throw new IllegalStateException("InputPort is disabled");
        } else if (state == ScheduledState.STOPPED) {
            return;
        }

        scheduler.stopPort(port);
    } finally {
        readLock.unlock();
    }
}
 
Example 4
Source File: StandardProcessGroup.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
@Override
public void stopOutputPort(final Port port) {
    readLock.lock();
    try {
        if (!outputPorts.containsKey(port.getIdentifier())) {
            throw new IllegalStateException("No Output Port with ID " + port.getIdentifier() + " belongs to this Process Group");
        }

        final ScheduledState state = port.getScheduledState();
        if (state == ScheduledState.DISABLED) {
            throw new IllegalStateException("OutputPort is disabled");
        } else if (state == ScheduledState.STOPPED) {
            return;
        }

        scheduler.stopPort(port);
    } finally {
        readLock.unlock();
    }
}
 
Example 5
Source File: StandardProcessGroup.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
private void stopFunnel(final Funnel funnel) {
    readLock.lock();
    try {
        if (!funnels.containsKey(funnel.getIdentifier())) {
            throw new IllegalStateException("No Funnel with ID " + funnel.getIdentifier() + " belongs to this Process Group");
        }

        final ScheduledState state = funnel.getScheduledState();
        if (state == ScheduledState.DISABLED) {
            throw new IllegalStateException("Funnel is disabled");
        } else if (state == ScheduledState.STOPPED) {
            return;
        }

        scheduler.stopFunnel(funnel);
    } finally {
        readLock.unlock();
    }
}
 
Example 6
Source File: StandardProcessGroup.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
@Override
public void enableInputPort(final Port port) {
    readLock.lock();
    try {
        if (!inputPorts.containsKey(port.getIdentifier())) {
            throw new IllegalStateException("No Input Port with ID " + port.getIdentifier() + " belongs to this Process Group");
        }

        final ScheduledState state = port.getScheduledState();
        if (state == ScheduledState.STOPPED) {
            return;
        } else if (state == ScheduledState.RUNNING) {
            throw new IllegalStateException("InputPort is currently running");
        }

        scheduler.enablePort(port);
    } finally {
        readLock.unlock();
    }
}
 
Example 7
Source File: StandardProcessGroup.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
@Override
public void enableOutputPort(final Port port) {
    readLock.lock();
    try {
        if (!outputPorts.containsKey(port.getIdentifier())) {
            throw new IllegalStateException("No Output Port with ID " + port.getIdentifier() + " belongs to this Process Group");
        }

        final ScheduledState state = port.getScheduledState();
        if (state == ScheduledState.STOPPED) {
            return;
        } else if (state == ScheduledState.RUNNING) {
            throw new IllegalStateException("OutputPort is currently running");
        }

        scheduler.enablePort(port);
    } finally {
        readLock.unlock();
    }
}
 
Example 8
Source File: StandardProcessGroup.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
@Override
public void enableProcessor(final ProcessorNode processor) {
    readLock.lock();
    try {
        if (!processors.containsKey(processor.getIdentifier())) {
            throw new IllegalStateException("No Processor with ID " + processor.getIdentifier() + " belongs to this Process Group");
        }

        final ScheduledState state = processor.getScheduledState();
        if (state == ScheduledState.STOPPED) {
            return;
        } else if (state == ScheduledState.RUNNING) {
            throw new IllegalStateException("Processor is currently running");
        }

        scheduler.enableProcessor(processor);
    } finally {
        readLock.unlock();
    }
}
 
Example 9
Source File: StandardProcessScheduler.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
public synchronized void disableFunnel(final Funnel funnel) {
    if (funnel.getScheduledState() != ScheduledState.STOPPED) {
        throw new IllegalStateException("Funnel cannot be disabled because its state its state is set to " + funnel.getScheduledState());
    }
    funnel.setScheduledState(ScheduledState.DISABLED);
}
 
Example 10
Source File: StandardRootGroupPort.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@Override
public Collection<ValidationResult> getValidationErrors() {
    final Collection<ValidationResult> validationErrors = new ArrayList<>();
    if (getScheduledState() == ScheduledState.STOPPED) {
        if (!isValid()) {
            final ValidationResult error = new ValidationResult.Builder()
                    .explanation(String.format("Output connection for port '%s' is not defined.", getName()))
                    .subject(String.format("Port '%s'", getName()))
                    .valid(false)
                    .build();
            validationErrors.add(error);
        }
    }
    return validationErrors;
}
 
Example 11
Source File: StandardProcessScheduler.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
public synchronized void terminateProcessor(final ProcessorNode procNode) {
    if (procNode.getScheduledState() != ScheduledState.STOPPED) {
        throw new IllegalStateException("Cannot terminate " + procNode + " because it is not currently stopped");
    }

    final LifecycleState state = getLifecycleState(procNode, false);
    if (state.getActiveThreadCount() == 0) {
        LOG.debug("Will not terminate {} because it has no active threads", procNode);
        return;
    }

    LOG.debug("Terminating {}", procNode);

    final int tasksTerminated = procNode.terminate();
    state.terminate();

    getSchedulingAgent(procNode).incrementMaxThreadCount(tasksTerminated);

    try {
        flowController.getReloadComponent().reload(procNode, procNode.getProcessor().getClass().getName(), procNode.getBundleCoordinate(), Collections.emptySet());
    } catch (final ProcessorInstantiationException e) {
        // This shouldn't happen because we already have been able to instantiate the processor before
        LOG.error("Failed to replace instance of Processor for {} when terminating Processor", procNode);
    }

    LOG.info("Successfully terminated {} with {} active threads", procNode, tasksTerminated);
}
 
Example 12
Source File: ClusterReplicationComponentLifecycle.java    From nifi with Apache License 2.0 5 votes vote down vote up
private boolean isProcessorActionComplete(final ProcessorsRunStatusDetailsEntity runStatusDetailsEntity, final Map<String, AffectedComponentEntity> affectedComponents,
                                          final ScheduledState desiredState, final InvalidComponentAction invalidComponentAction) throws LifecycleManagementException {
    final String desiredStateName = desiredState.name();

    updateAffectedProcessors(runStatusDetailsEntity.getRunStatusDetails(), affectedComponents);

    for (final ProcessorRunStatusDetailsEntity entity : runStatusDetailsEntity.getRunStatusDetails()) {
        final ProcessorRunStatusDetailsDTO runStatusDetailsDto = entity.getRunStatusDetails();
        if (!affectedComponents.containsKey(runStatusDetailsDto.getId())) {
            continue;
        }

        if (ProcessorRunStatusDetailsDTO.INVALID.equals(runStatusDetailsDto.getRunStatus())) {
            switch (invalidComponentAction) {
                case WAIT:
                    return false;
                case SKIP:
                    continue;
                case FAIL:
                    final String action = desiredState == ScheduledState.RUNNING ? "start" : "stop";
                    throw new LifecycleManagementException("Could not " + action + " " + runStatusDetailsDto.getName() + " because it is invalid");
            }
        }

        final String runStatus = runStatusDetailsDto.getRunStatus();
        final boolean stateMatches = desiredStateName.equalsIgnoreCase(runStatus);
        if (!stateMatches) {
            return false;
        }

        if (desiredState == ScheduledState.STOPPED && runStatusDetailsDto.getActiveThreadCount() != 0) {
            return false;
        }
    }

    return true;
}
 
Example 13
Source File: StandardProcessScheduler.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
public synchronized void disablePort(final Port port) {
    if (port.getScheduledState() != ScheduledState.STOPPED) {
        throw new IllegalStateException("Port cannot be disabled because its state is set to " + port.getScheduledState());
    }

    if (!(port instanceof AbstractPort)) {
        throw new IllegalArgumentException();
    }

    ((AbstractPort) port).disable();
}
 
Example 14
Source File: StandardProcessScheduler.java    From nifi with Apache License 2.0 5 votes vote down vote up
public synchronized void disableReportingTask(final ReportingTaskNode taskNode) {
    if (taskNode.getScheduledState() != ScheduledState.STOPPED) {
        throw new IllegalStateException("Reporting Task cannot be disabled because its state is set to " + taskNode.getScheduledState()
                + " but transition to DISABLED state is allowed only from the STOPPED state");
    }

    taskNode.setScheduledState(ScheduledState.DISABLED);
}
 
Example 15
Source File: StandardPublicPort.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
public Collection<ValidationResult> getValidationErrors() {
    final Collection<ValidationResult> validationErrors = new ArrayList<>();
    if (getScheduledState() == ScheduledState.STOPPED) {
        if (!isValid()) {
            final ValidationResult error = new ValidationResult.Builder()
                    .explanation(String.format("Output connection for port '%s' is not defined.", getName()))
                    .subject(String.format("Port '%s'", getName()))
                    .valid(false)
                    .build();
            validationErrors.add(error);
        }
    }
    return validationErrors;
}
 
Example 16
Source File: StandardProcessScheduler.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
public synchronized void disableReportingTask(final ReportingTaskNode taskNode) {
    if (taskNode.getScheduledState() != ScheduledState.STOPPED) {
        throw new IllegalStateException("Reporting Task cannot be disabled because its state is set to " + taskNode.getScheduledState()
                + " but transition to DISABLED state is allowed only from the STOPPED state");
    }

    taskNode.setScheduledState(ScheduledState.DISABLED);
}
 
Example 17
Source File: StandardProcessScheduler.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@Override
public synchronized void disablePort(final Port port) {
    if (port.getScheduledState() != ScheduledState.STOPPED) {
        throw new IllegalStateException("Port cannot be disabled because its state is set to " + port.getScheduledState());
    }

    if (!(port instanceof AbstractPort)) {
        throw new IllegalArgumentException();
    }

    ((AbstractPort) port).disable();
}
 
Example 18
Source File: StandardProcessScheduler.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@Override
public synchronized void disableFunnel(final Funnel funnel) {
    if (funnel.getScheduledState() != ScheduledState.STOPPED) {
        throw new IllegalStateException("Funnel cannot be disabled because its state its state is set to " + funnel.getScheduledState());
    }
    funnel.setScheduledState(ScheduledState.DISABLED);
}
 
Example 19
Source File: AbstractReportingTaskNode.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@Override
public Collection<ValidationResult> getValidationErrors(Set<String> serviceIdentifiersNotToValidate) {
    Collection<ValidationResult> results = null;
    if (getScheduledState() == ScheduledState.STOPPED) {
        results = super.getValidationErrors(serviceIdentifiersNotToValidate);
    }
    return results != null ? results : Collections.emptySet();
}
 
Example 20
Source File: StandardProcessGroup.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@Override
public void verifyCanStart(Connectable connectable) {
    readLock.lock();
    try {
        if (connectable.getScheduledState() == ScheduledState.STOPPED) {
            if (scheduler.getActiveThreadCount(connectable) > 0) {
                throw new IllegalStateException("Cannot start component with id" + connectable.getIdentifier() + " because it is currently stopping");
            }

            connectable.verifyCanStart();
        }
    } finally {
        readLock.unlock();
    }
}