Java Code Examples for org.apache.nifi.controller.service.ControllerServiceNode#getState()

The following examples show how to use org.apache.nifi.controller.service.ControllerServiceNode#getState() . 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: StandardSchedulingContext.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
@Override
public void leaseControllerService(final String identifier) {
    final ControllerServiceNode serviceNode = serviceProvider.getControllerServiceNode(identifier);
    if (serviceNode == null) {
        throw new IllegalArgumentException("Cannot lease Controller Service because no Controller Service exists with identifier " + identifier);
    }

    if (serviceNode.getState() != ControllerServiceState.ENABLED) {
        throw new IllegalStateException("Cannot lease Controller Service because Controller Service " + serviceNode.getProxiedControllerService().getIdentifier() + " is not currently enabled");
    }

    if (!serviceNode.isValid()) {
        throw new IllegalStateException("Cannot lease Controller Service because Controller Service " + serviceNode.getProxiedControllerService().getIdentifier() + " is not currently valid");
    }

    serviceNode.addReference(processorNode);
}
 
Example 2
Source File: StandardParameterContextDAO.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Override
public void verifyDelete(final String parameterContextId) {
    // Find all Process Groups that are bound to the Parameter Context
    final List<ProcessGroup> groupsReferencingParameterContext = getBoundProcessGroups(parameterContextId);

    // If any component is referencing a Parameter and is running/enabled then fail
    for (final ProcessGroup group : groupsReferencingParameterContext) {
        for (final ProcessorNode processor : group.getProcessors()) {
            if (processor.isReferencingParameter() && processor.isRunning()) {
                throw new IllegalStateException("Cannot delete Parameter Context with ID " + parameterContextId + " because it is in use by at least one Processor that is running");
            }
        }

        for (final ControllerServiceNode service : group.getControllerServices(false)) {
            if (service.isReferencingParameter() && service.getState() != ControllerServiceState.DISABLED) {
                throw new IllegalStateException("Cannot delete Parameter Context with ID " + parameterContextId + " because it is in use by at least one Controller Service that is enabled");
            }
        }
    }
}
 
Example 3
Source File: StandardParameterContext.java    From nifi with Apache License 2.0 6 votes vote down vote up
private void validateReferencingComponents(final String parameterName, final Parameter parameter, final String parameterAction) {
    for (final ProcessorNode procNode : parameterReferenceManager.getProcessorsReferencing(this, parameterName)) {
        if (procNode.isRunning()) {
            throw new IllegalStateException("Cannot " + parameterAction + " parameter '" + parameterName + "' because it is referenced by " + procNode + ", which is currently running");
        }

        if (parameter != null) {
            validateParameterSensitivity(parameter, procNode);
        }
    }

    for (final ControllerServiceNode serviceNode : parameterReferenceManager.getControllerServicesReferencing(this, parameterName)) {
        final ControllerServiceState serviceState = serviceNode.getState();
        if (serviceState != ControllerServiceState.DISABLED) {
            throw new IllegalStateException("Cannot " + parameterAction + " parameter '" + parameterName + "' because it is referenced by "
                + serviceNode + ", which currently has a state of " + serviceState);
        }

        if (parameter != null) {
            validateParameterSensitivity(parameter, serviceNode);
        }
    }
}
 
Example 4
Source File: StandardFlowSerializer.java    From nifi with Apache License 2.0 6 votes vote down vote up
public void addControllerService(final Element element, final ControllerServiceNode serviceNode) {
    final Element serviceElement = element.getOwnerDocument().createElement("controllerService");
    addTextElement(serviceElement, "id", serviceNode.getIdentifier());
    addTextElement(serviceElement, "versionedComponentId", serviceNode.getVersionedComponentId());
    addTextElement(serviceElement, "name", serviceNode.getName());
    addTextElement(serviceElement, "comment", serviceNode.getComments());
    addTextElement(serviceElement, "class", serviceNode.getCanonicalClassName());

    addBundle(serviceElement, serviceNode.getBundleCoordinate());

    final ControllerServiceState state = serviceNode.getState();
    final boolean enabled = (state == ControllerServiceState.ENABLED || state == ControllerServiceState.ENABLING);
    addTextElement(serviceElement, "enabled", String.valueOf(enabled));

    addConfiguration(serviceElement, serviceNode.getRawPropertyValues(), serviceNode.getAnnotationData(), encryptor);

    element.appendChild(serviceElement);
}
 
Example 5
Source File: ComponentCountTask.java    From nifi with Apache License 2.0 6 votes vote down vote up
private void countControllerServices(final Collection<ControllerServiceNode> services, final List<String> details) {
    final Map<String, Map<ControllerServiceState, Integer>> typeMap = new HashMap<>();

    for (final ControllerServiceNode serviceNode : services) {
        final String componentType = serviceNode.getComponentType();

        final ControllerServiceState serviceState = serviceNode.getState();
        final Map<ControllerServiceState, Integer> stateCounts = typeMap.computeIfAbsent(componentType, key -> new HashMap<>());
        final Integer count = stateCounts.computeIfAbsent(serviceState, key -> 0);
        stateCounts.put(serviceState, count + 1);
    }

    for (final Map.Entry<String, Map<ControllerServiceState, Integer>> typeEntry : typeMap.entrySet()) {
        final String type = typeEntry.getKey();
        final Map<ControllerServiceState, Integer> stateMap = typeEntry.getValue();

        final int total = stateMap.values().stream().mapToInt(Integer::intValue).sum();
        details.add(type + " : " + total + " total, " + stateMap.toString().toLowerCase());
    }

    if (typeMap.isEmpty()) {
        details.add("No Controller Services");
    }
}
 
Example 6
Source File: StandardFlowSerializer.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
public void addControllerService(final Element element, final ControllerServiceNode serviceNode) {
    final Element serviceElement = element.getOwnerDocument().createElement("controllerService");
    addTextElement(serviceElement, "id", serviceNode.getIdentifier());
    addTextElement(serviceElement, "name", serviceNode.getName());
    addTextElement(serviceElement, "comment", serviceNode.getComments());
    addTextElement(serviceElement, "class", serviceNode.getCanonicalClassName());

    final ControllerServiceState state = serviceNode.getState();
    final boolean enabled = (state == ControllerServiceState.ENABLED || state == ControllerServiceState.ENABLING);
    addTextElement(serviceElement, "enabled", String.valueOf(enabled));

    addConfiguration(serviceElement, serviceNode.getProperties(), serviceNode.getAnnotationData(), encryptor);

    element.appendChild(serviceElement);
}