Java Code Examples for org.apache.nifi.web.api.dto.ControllerServiceDTO#getBundle()

The following examples show how to use org.apache.nifi.web.api.dto.ControllerServiceDTO#getBundle() . 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: ControllerServiceResource.java    From nifi with Apache License 2.0 6 votes vote down vote up
/**
 * Populates the uri for the specified controller service.
 */
public ControllerServiceDTO populateRemainingControllerServiceContent(final ControllerServiceDTO controllerService) {
    final BundleDTO bundle = controllerService.getBundle();

    // see if this processor has any ui extensions
    final UiExtensionMapping uiExtensionMapping = (UiExtensionMapping) servletContext.getAttribute("nifi-ui-extensions");
    if (uiExtensionMapping.hasUiExtension(controllerService.getType(), bundle.getGroup(), bundle.getArtifact(), bundle.getVersion())) {
        final List<UiExtension> uiExtensions = uiExtensionMapping.getUiExtension(controllerService.getType(), bundle.getGroup(), bundle.getArtifact(), bundle.getVersion());
        for (final UiExtension uiExtension : uiExtensions) {
            if (UiExtensionType.ControllerServiceConfiguration.equals(uiExtension.getExtensionType())) {
                controllerService.setCustomUiUrl(uiExtension.getContextPath() + "/configure");
            }
        }
    }

    return controllerService;
}
 
Example 2
Source File: StandardControllerServiceDAO.java    From nifi with Apache License 2.0 6 votes vote down vote up
private void updateBundle(final ControllerServiceNode controllerService, final ControllerServiceDTO controllerServiceDTO) {
    final BundleDTO bundleDTO = controllerServiceDTO.getBundle();
    if (bundleDTO != null) {
        final ExtensionManager extensionManager = serviceProvider.getExtensionManager();
        final BundleCoordinate incomingCoordinate = BundleUtils.getBundle(extensionManager, controllerService.getCanonicalClassName(), bundleDTO);
        final BundleCoordinate existingCoordinate = controllerService.getBundleCoordinate();
        if (!existingCoordinate.getCoordinate().equals(incomingCoordinate.getCoordinate())) {
            try {
                // we need to use the property descriptors from the temp component here in case we are changing from a ghost component to a real component
                final ConfigurableComponent tempComponent = extensionManager.getTempComponent(controllerService.getCanonicalClassName(), incomingCoordinate);
                final Set<URL> additionalUrls = controllerService.getAdditionalClasspathResources(tempComponent.getPropertyDescriptors());
                flowController.getReloadComponent().reload(controllerService, controllerService.getCanonicalClassName(), incomingCoordinate, additionalUrls);
            } catch (ControllerServiceInstantiationException e) {
                throw new NiFiCoreException(String.format("Unable to update controller service %s from %s to %s due to: %s",
                        controllerServiceDTO.getId(), controllerService.getBundleCoordinate().getCoordinate(), incomingCoordinate.getCoordinate(), e.getMessage()), e);
            }
        }
    }
}
 
Example 3
Source File: ControllerServiceLoader.java    From nifi with Apache License 2.0 6 votes vote down vote up
private static ControllerServiceNode createControllerService(final FlowController flowController, final Element controllerServiceElement, final StringEncryptor encryptor,
                                                             final FlowEncodingVersion encodingVersion) {
    final ControllerServiceDTO dto = FlowFromDOMFactory.getControllerService(controllerServiceElement, encryptor, encodingVersion);

    BundleCoordinate coordinate;
    try {
        coordinate = BundleUtils.getCompatibleBundle(flowController.getExtensionManager(), dto.getType(), dto.getBundle());
    } catch (final IllegalStateException e) {
        final BundleDTO bundleDTO = dto.getBundle();
        if (bundleDTO == null) {
            coordinate = BundleCoordinate.UNKNOWN_COORDINATE;
        } else {
            coordinate = new BundleCoordinate(bundleDTO.getGroup(), bundleDTO.getArtifact(), bundleDTO.getVersion());
        }
    }

    final ControllerServiceNode node = flowController.getFlowManager().createControllerService(dto.getType(), dto.getId(), coordinate, Collections.emptySet(), false, true);
    node.setName(dto.getName());
    node.setComments(dto.getComments());
    node.setVersionedComponentId(dto.getVersionedComponentId());
    return node;
}
 
Example 4
Source File: ControllerServiceResult.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
protected void writeSimpleResult(PrintStream output) throws IOException {
    final ControllerServiceDTO controllerServiceDTO = controllerServiceEntity.getComponent();

    final BundleDTO bundle = controllerServiceDTO.getBundle();
    output.printf("Name  : %s\nID    : %s\nType  : %s\nBundle: %s - %s %s\nState : %s\n",
            controllerServiceDTO.getName(), controllerServiceDTO.getId(), controllerServiceDTO.getType(),
            bundle.getGroup(), bundle.getArtifact(), bundle.getVersion(), controllerServiceDTO.getState());
}
 
Example 5
Source File: ControllerServiceAuditor.java    From nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Extracts the values for the configured properties from the specified ControllerService.
 *
 * @param controllerService service
 * @param controllerServiceDTO dto
 * @return properties
 */
private Map<String, String> extractConfiguredPropertyValues(ControllerServiceNode controllerService, ControllerServiceDTO controllerServiceDTO) {
    Map<String, String> values = new HashMap<>();

    if (controllerServiceDTO.getName() != null) {
        values.put(NAME, controllerService.getName());
    }
    if (controllerServiceDTO.getAnnotationData() != null) {
        values.put(ANNOTATION_DATA, controllerService.getAnnotationData());
    }
    if (controllerServiceDTO.getBundle() != null) {
        final BundleCoordinate bundle = controllerService.getBundleCoordinate();
        values.put(EXTENSION_VERSION, formatExtensionVersion(controllerService.getComponentType(), bundle));
    }
    if (controllerServiceDTO.getProperties() != null) {
        // for each property specified, extract its configured value
        final Map<String, String> properties = controllerServiceDTO.getProperties();
        final Map<PropertyDescriptor, String> configuredProperties = controllerService.getRawPropertyValues();

        for (String propertyName : properties.keySet()) {
            // build a descriptor for getting the configured value
            PropertyDescriptor propertyDescriptor = new PropertyDescriptor.Builder().name(propertyName).build();
            String configuredPropertyValue = configuredProperties.get(propertyDescriptor);

            // if the configured value couldn't be found, use the default value from the actual descriptor
            if (configuredPropertyValue == null) {
                propertyDescriptor = locatePropertyDescriptor(configuredProperties.keySet(), propertyDescriptor);
                configuredPropertyValue = propertyDescriptor.getDefaultValue();
            }
            values.put(propertyName, configuredPropertyValue);
        }
    }
    if (controllerServiceDTO.getComments() != null) {
        values.put(COMMENTS, controllerService.getComments());
    }

    return values;
}
 
Example 6
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();
    }
}