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

The following examples show how to use org.apache.nifi.controller.service.ControllerServiceNode#verifyCanUpdate() . 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 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 2
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();
    }
}