Java Code Examples for org.apache.nifi.controller.service.ControllerServiceState#equals()

The following examples show how to use org.apache.nifi.controller.service.ControllerServiceState#equals() . 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: StandardControllerServiceDAO.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@Override
public ControllerServiceNode updateControllerService(final ControllerServiceDTO controllerServiceDTO) {
    // get the controller service
    final ControllerServiceNode controllerService = locateControllerService(controllerServiceDTO.getId());

    // ensure we can perform the update
    verifyUpdate(controllerService, controllerServiceDTO);

    // perform the update
    configureControllerService(controllerService, controllerServiceDTO);

    // enable or disable as appropriate
    if (isNotNull(controllerServiceDTO.getState())) {
        final ControllerServiceState purposedControllerServiceState = ControllerServiceState.valueOf(controllerServiceDTO.getState());

        // only attempt an action if it is changing
        if (!purposedControllerServiceState.equals(controllerService.getState())) {
            if (ControllerServiceState.ENABLED.equals(purposedControllerServiceState)) {
                serviceProvider.enableControllerService(controllerService);
            } else if (ControllerServiceState.DISABLED.equals(purposedControllerServiceState)) {
                serviceProvider.disableControllerService(controllerService);
            }
        }
    }

    return controllerService;
}
 
Example 2
Source File: StandardControllerServiceDAO.java    From localization_nifi with Apache License 2.0 4 votes vote down vote up
private void verifyUpdate(final ControllerServiceNode controllerService, final ControllerServiceDTO controllerServiceDTO) {
    // validate the new controller service state if appropriate
    if (isNotNull(controllerServiceDTO.getState())) {
        try {
            // attempt to parse the service state
            final ControllerServiceState purposedControllerServiceState = ControllerServiceState.valueOf(controllerServiceDTO.getState());

            // ensure the state is valid
            if (ControllerServiceState.ENABLING.equals(purposedControllerServiceState) || ControllerServiceState.DISABLING.equals(purposedControllerServiceState)) {
                throw new IllegalArgumentException();
            }

            // only attempt an action if it is changing
            if (!purposedControllerServiceState.equals(controllerService.getState())) {
                if (ControllerServiceState.ENABLED.equals(purposedControllerServiceState)) {
                    controllerService.verifyCanEnable();
                } else if (ControllerServiceState.DISABLED.equals(purposedControllerServiceState)) {
                    controllerService.verifyCanDisable();
                }
            }
        } catch (final IllegalArgumentException iae) {
            throw new IllegalArgumentException("Controller Service state: Value must be one of [ENABLED, DISABLED]");
        }
    }

    boolean modificationRequest = false;
    if (isAnyNotNull(controllerServiceDTO.getName(),
            controllerServiceDTO.getAnnotationData(),
            controllerServiceDTO.getComments(),
            controllerServiceDTO.getProperties())) {
        modificationRequest = true;

        // validate the request
        final List<String> requestValidation = validateProposedConfiguration(controllerService, controllerServiceDTO);

        // ensure there was no validation errors
        if (!requestValidation.isEmpty()) {
            throw new ValidationException(requestValidation);
        }
    }

    if (modificationRequest) {
        controllerService.verifyCanUpdate();
    }
}
 
Example 3
Source File: StandardControllerServiceDAO.java    From nifi with Apache License 2.0 4 votes vote down vote up
@Override
public ControllerServiceNode updateControllerService(final ControllerServiceDTO controllerServiceDTO) {
    // get the controller service
    final ControllerServiceNode controllerService = locateControllerService(controllerServiceDTO.getId());

    // ensure we can perform the update
    verifyUpdate(controllerService, controllerServiceDTO);

    // perform the update
    configureControllerService(controllerService, controllerServiceDTO);

    // attempt to change the underlying controller service if an updated bundle is specified
    // updating the bundle must happen after configuring so that any additional classpath resources are set first
    updateBundle(controllerService, controllerServiceDTO);

    // enable or disable as appropriate
    if (isNotNull(controllerServiceDTO.getState())) {
        final ControllerServiceState purposedControllerServiceState = ControllerServiceState.valueOf(controllerServiceDTO.getState());

        // only attempt an action if it is changing
        if (!purposedControllerServiceState.equals(controllerService.getState())) {
            if (ControllerServiceState.ENABLED.equals(purposedControllerServiceState)) {
                serviceProvider.enableControllerService(controllerService);
            } else if (ControllerServiceState.DISABLED.equals(purposedControllerServiceState)) {
                serviceProvider.disableControllerService(controllerService);
            }
        }
    }

    final ProcessGroup group = controllerService.getProcessGroup();
    if (group != null) {
        group.onComponentModified();

        // For any component that references this Controller Service, find the component's Process Group
        // and notify the Process Group that a component has been modified. This way, we know to re-calculate
        // whether or not the Process Group has local modifications.
        controllerService.getReferences().getReferencingComponents().stream()
            .map(ComponentNode::getProcessGroupIdentifier)
            .filter(id -> !id.equals(group.getIdentifier()))
            .forEach(groupId -> {
                final ProcessGroup descendant = group.findProcessGroup(groupId);
                if (descendant != null) {
                    descendant.onComponentModified();
                }
            });
    }

    return controllerService;
}
 
Example 4
Source File: StandardControllerServiceDAO.java    From nifi with Apache License 2.0 4 votes vote down vote up
private void verifyUpdate(final ControllerServiceNode controllerService, final ControllerServiceDTO controllerServiceDTO) {
    // validate the new controller service state if appropriate
    if (isNotNull(controllerServiceDTO.getState())) {
        try {
            // attempt to parse the service state
            final ControllerServiceState purposedControllerServiceState = ControllerServiceState.valueOf(controllerServiceDTO.getState());

            // ensure the state is valid
            if (ControllerServiceState.ENABLING.equals(purposedControllerServiceState) || ControllerServiceState.DISABLING.equals(purposedControllerServiceState)) {
                throw new IllegalArgumentException();
            }

            // only attempt an action if it is changing
            if (!purposedControllerServiceState.equals(controllerService.getState())) {
                if (ControllerServiceState.ENABLED.equals(purposedControllerServiceState)) {
                    controllerService.verifyCanEnable();
                } else if (ControllerServiceState.DISABLED.equals(purposedControllerServiceState)) {
                    controllerService.verifyCanDisable();
                }
            }
        } catch (final IllegalArgumentException iae) {
            throw new IllegalArgumentException("Controller Service state: Value must be one of [ENABLED, DISABLED]");
        }
    }

    boolean modificationRequest = false;
    if (isAnyNotNull(controllerServiceDTO.getName(),
            controllerServiceDTO.getAnnotationData(),
            controllerServiceDTO.getComments(),
            controllerServiceDTO.getProperties(),
            controllerServiceDTO.getBundle())) {
        modificationRequest = true;

        // validate the request
        final List<String> requestValidation = validateProposedConfiguration(controllerService, controllerServiceDTO);

        // ensure there was no validation errors
        if (!requestValidation.isEmpty()) {
            throw new ValidationException(requestValidation);
        }
    }

    final BundleDTO bundleDTO = controllerServiceDTO.getBundle();
    if (bundleDTO != null) {
        // ensures all nodes in a cluster have the bundle, throws exception if bundle not found for the given type
        final BundleCoordinate bundleCoordinate = BundleUtils.getBundle(serviceProvider.getExtensionManager(), controllerService.getCanonicalClassName(), bundleDTO);
        // ensure we are only changing to a bundle with the same group and id, but different version
        controllerService.verifyCanUpdateBundle(bundleCoordinate);
    }

    if (modificationRequest) {
        controllerService.verifyCanUpdate();
    }
}