Java Code Examples for org.apache.nifi.controller.service.ControllerServiceState#ENABLED

The following examples show how to use org.apache.nifi.controller.service.ControllerServiceState#ENABLED . 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: StandardProcessGroupDAO.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Override
public void verifyActivateControllerServices(final ControllerServiceState state, final Collection<String> serviceIds) {
    final FlowManager flowManager = flowController.getFlowManager();

    final Set<ControllerServiceNode> serviceNodes = serviceIds.stream()
        .map(flowManager::getControllerServiceNode)
        .collect(Collectors.toSet());

    for (final ControllerServiceNode serviceNode : serviceNodes) {
        if (state == ControllerServiceState.ENABLED) {
            serviceNode.verifyCanEnable(serviceNodes);
        } else {
            serviceNode.verifyCanDisable(serviceNodes);
        }
    }
}
 
Example 3
Source File: LocalComponentLifecycle.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Override
public Set<AffectedComponentEntity> activateControllerServices(final URI exampleUri, final String groupId, final Set<AffectedComponentEntity> services,
    final ControllerServiceState desiredState, final Pause pause, final InvalidComponentAction invalidComponentAction) throws LifecycleManagementException {

    final Map<String, Revision> serviceRevisions = services.stream()
        .collect(Collectors.toMap(AffectedComponentEntity::getId, entity -> revisionManager.getRevision(entity.getId())));

    final Map<String, AffectedComponentEntity> affectedServiceMap = services.stream()
        .collect(Collectors.toMap(AffectedComponentEntity::getId, Function.identity()));

    if (desiredState == ControllerServiceState.ENABLED) {
        enableControllerServices(groupId, serviceRevisions, affectedServiceMap, pause, invalidComponentAction);
    } else {
        disableControllerServices(groupId, serviceRevisions, affectedServiceMap, pause, invalidComponentAction);
    }

    return services.stream()
        .map(componentEntity -> serviceFacade.getControllerService(componentEntity.getId()))
        .map(dtoFactory::createAffectedComponentEntity)
        .collect(Collectors.toSet());
}
 
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: 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);
}
 
Example 6
Source File: StandardProcessGroupDAO.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
public Future<Void> activateControllerServices(final String groupId, final ControllerServiceState state, final Collection<String> serviceIds) {
    final FlowManager flowManager = flowController.getFlowManager();
    final List<ControllerServiceNode> serviceNodes = serviceIds.stream()
        .map(flowManager::getControllerServiceNode)
        .collect(Collectors.toList());

    if (state == ControllerServiceState.ENABLED) {
        return flowController.getControllerServiceProvider().enableControllerServicesAsync(serviceNodes);
    } else {
        return flowController.getControllerServiceProvider().disableControllerServicesAsync(serviceNodes);
    }
}
 
Example 7
Source File: StandardFlowSynchronizer.java    From nifi with Apache License 2.0 5 votes vote down vote up
private ControllerServiceState getFinalTransitionState(final ControllerServiceState state) {
    switch (state) {
        case DISABLED:
        case DISABLING:
            return ControllerServiceState.DISABLED;
        case ENABLED:
        case ENABLING:
            return ControllerServiceState.ENABLED;
        default:
            throw new AssertionError();
    }
}
 
Example 8
Source File: StandardValidationContext.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isValidationRequired(final ControllerService service) {
    // No need to validate services that are already enabled.
    final ControllerServiceState serviceState = controllerServiceProvider.getControllerServiceNode(service.getIdentifier()).getState();
    if (serviceState == ControllerServiceState.ENABLED || serviceState == ControllerServiceState.ENABLING) {
        return false;
    }

    return true;
}
 
Example 9
Source File: LocalComponentLifecycle.java    From nifi with Apache License 2.0 4 votes vote down vote up
/**
 * Periodically polls the process group with the given ID, waiting for all controller services whose ID's are given to have the given Controller Service State.
 *
 * @param groupId the ID of the Process Group to poll
 * @param affectedServices all Controller Services whose state should be equal to the given desired state
 * @param desiredState the desired state for all services with the ID's given
 * @param pause the Pause that can be used to wait between polling
 * @return <code>true</code> if successful, <code>false</code> if unable to wait for services to reach the desired state
 */
private boolean waitForControllerServiceState(final String groupId, final Map<String, AffectedComponentEntity> affectedServices, final ControllerServiceState desiredState, final Pause pause,
                                              final InvalidComponentAction invalidComponentAction) throws LifecycleManagementException {

    logger.debug("Waiting for {} Controller Services to transition their states to {}", affectedServices.size(), desiredState);

    boolean continuePolling = true;
    while (continuePolling) {
        final Set<ControllerServiceEntity> serviceEntities = serviceFacade.getControllerServices(groupId, false, true);

        // update the affected controller services
        updateAffectedControllerServices(serviceEntities, affectedServices);

        final String desiredStateName = desiredState.name();

        boolean allReachedDesiredState = true;
        for (final ControllerServiceEntity serviceEntity : serviceEntities) {
            final ControllerServiceDTO serviceDto = serviceEntity.getComponent();
            if (!affectedServices.containsKey(serviceDto.getId())) {
                continue;
            }

            final String validationStatus = serviceDto.getValidationStatus();
            if (ControllerServiceDTO.INVALID.equals(validationStatus)) {
                switch (invalidComponentAction) {
                    case WAIT:
                        allReachedDesiredState = false;
                        break;
                    case SKIP:
                        continue;
                    case FAIL:
                        final String action = desiredState == ControllerServiceState.ENABLED ? "enable" : "disable";
                        throw new LifecycleManagementException("Could not " + action + " " + serviceEntity.getComponent().getName() + " because it is invalid");
                }
            }

            if (!desiredStateName.equals(serviceDto.getState())) {
                allReachedDesiredState = false;
                break;
            }
        }

        if (allReachedDesiredState) {
            logger.debug("All {} controller services of interest now have the desired state of {}", affectedServices.size(), desiredState);
            return true;
        }

        // Not all of the controller services are in the desired state. Pause for a bit and poll again.
        continuePolling = pause.pause();
    }

    return false;
}