Search in sources :

Example 16 with BundleDTO

use of org.apache.nifi.web.api.dto.BundleDTO in project nifi by apache.

the class ControllerServiceLoader method createControllerService.

private static ControllerServiceNode createControllerService(final ControllerServiceProvider provider, final Element controllerServiceElement, final StringEncryptor encryptor) {
    final ControllerServiceDTO dto = FlowFromDOMFactory.getControllerService(controllerServiceElement, encryptor);
    BundleCoordinate coordinate;
    try {
        coordinate = BundleUtils.getCompatibleBundle(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 = provider.createControllerService(dto.getType(), dto.getId(), coordinate, Collections.emptySet(), false);
    node.setName(dto.getName());
    node.setComments(dto.getComments());
    node.setVersionedComponentId(dto.getVersionedComponentId());
    return node;
}
Also used : ControllerServiceDTO(org.apache.nifi.web.api.dto.ControllerServiceDTO) BundleDTO(org.apache.nifi.web.api.dto.BundleDTO) BundleCoordinate(org.apache.nifi.bundle.BundleCoordinate)

Example 17 with BundleDTO

use of org.apache.nifi.web.api.dto.BundleDTO in project nifi by apache.

the class StandardFlowSynchronizer method getOrCreateReportingTask.

private ReportingTaskNode getOrCreateReportingTask(final FlowController controller, final ReportingTaskDTO dto, final boolean controllerInitialized, final boolean existingFlowEmpty) throws ReportingTaskInstantiationException {
    // create a new reporting task node when the controller is not initialized or the flow is empty
    if (!controllerInitialized || existingFlowEmpty) {
        BundleCoordinate coordinate;
        try {
            coordinate = BundleUtils.getCompatibleBundle(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 ReportingTaskNode reportingTask = controller.createReportingTask(dto.getType(), dto.getId(), coordinate, false);
        reportingTask.setName(dto.getName());
        reportingTask.setComments(dto.getComments());
        reportingTask.setSchedulingPeriod(dto.getSchedulingPeriod());
        reportingTask.setSchedulingStrategy(SchedulingStrategy.valueOf(dto.getSchedulingStrategy()));
        reportingTask.setAnnotationData(dto.getAnnotationData());
        reportingTask.setProperties(dto.getProperties());
        final ComponentLog componentLog = new SimpleProcessLogger(dto.getId(), reportingTask.getReportingTask());
        final ReportingInitializationContext config = new StandardReportingInitializationContext(dto.getId(), dto.getName(), SchedulingStrategy.valueOf(dto.getSchedulingStrategy()), dto.getSchedulingPeriod(), componentLog, controller, nifiProperties, controller);
        try {
            reportingTask.getReportingTask().initialize(config);
        } catch (final InitializationException ie) {
            throw new ReportingTaskInstantiationException("Failed to initialize reporting task of type " + dto.getType(), ie);
        }
        return reportingTask;
    } else {
        // otherwise return the existing reporting task node
        return controller.getReportingTaskNode(dto.getId());
    }
}
Also used : ReportingTaskInstantiationException(org.apache.nifi.controller.reporting.ReportingTaskInstantiationException) ReportingInitializationContext(org.apache.nifi.reporting.ReportingInitializationContext) StandardReportingInitializationContext(org.apache.nifi.controller.reporting.StandardReportingInitializationContext) SimpleProcessLogger(org.apache.nifi.processor.SimpleProcessLogger) BundleDTO(org.apache.nifi.web.api.dto.BundleDTO) StandardReportingInitializationContext(org.apache.nifi.controller.reporting.StandardReportingInitializationContext) InitializationException(org.apache.nifi.reporting.InitializationException) BundleCoordinate(org.apache.nifi.bundle.BundleCoordinate) ComponentLog(org.apache.nifi.logging.ComponentLog)

Example 18 with BundleDTO

use of org.apache.nifi.web.api.dto.BundleDTO in project nifi by apache.

the class ProcessGroupResource method discoverCompatibleBundles.

// -----------------
// template instance
// -----------------
/**
 * Discovers the compatible bundle details for the components in the specified snippet.
 *
 * @param snippet the snippet
 */
private void discoverCompatibleBundles(final FlowSnippetDTO snippet) {
    if (snippet.getProcessors() != null) {
        snippet.getProcessors().forEach(processor -> {
            final BundleCoordinate coordinate = BundleUtils.getCompatibleBundle(processor.getType(), processor.getBundle());
            processor.setBundle(new BundleDTO(coordinate.getGroup(), coordinate.getId(), coordinate.getVersion()));
        });
    }
    if (snippet.getControllerServices() != null) {
        snippet.getControllerServices().forEach(controllerService -> {
            final BundleCoordinate coordinate = BundleUtils.getCompatibleBundle(controllerService.getType(), controllerService.getBundle());
            controllerService.setBundle(new BundleDTO(coordinate.getGroup(), coordinate.getId(), coordinate.getVersion()));
        });
    }
    if (snippet.getProcessGroups() != null) {
        snippet.getProcessGroups().forEach(processGroup -> {
            discoverCompatibleBundles(processGroup.getContents());
        });
    }
}
Also used : BundleDTO(org.apache.nifi.web.api.dto.BundleDTO) BundleCoordinate(org.apache.nifi.bundle.BundleCoordinate)

Example 19 with BundleDTO

use of org.apache.nifi.web.api.dto.BundleDTO in project nifi by apache.

the class ReportingTaskResource method populateRemainingReportingTaskContent.

/**
 * Populates the uri for the specified reporting task.
 */
public ReportingTaskDTO populateRemainingReportingTaskContent(final ReportingTaskDTO reportingTask) {
    final BundleDTO bundle = reportingTask.getBundle();
    // see if this processor has any ui extensions
    final UiExtensionMapping uiExtensionMapping = (UiExtensionMapping) servletContext.getAttribute("nifi-ui-extensions");
    if (uiExtensionMapping.hasUiExtension(reportingTask.getType(), bundle.getGroup(), bundle.getArtifact(), bundle.getVersion())) {
        final List<UiExtension> uiExtensions = uiExtensionMapping.getUiExtension(reportingTask.getType(), bundle.getGroup(), bundle.getArtifact(), bundle.getVersion());
        for (final UiExtension uiExtension : uiExtensions) {
            if (UiExtensionType.ReportingTaskConfiguration.equals(uiExtension.getExtensionType())) {
                reportingTask.setCustomUiUrl(uiExtension.getContextPath() + "/configure");
            }
        }
    }
    return reportingTask;
}
Also used : UiExtension(org.apache.nifi.ui.extension.UiExtension) UiExtensionMapping(org.apache.nifi.ui.extension.UiExtensionMapping) BundleDTO(org.apache.nifi.web.api.dto.BundleDTO)

Example 20 with BundleDTO

use of org.apache.nifi.web.api.dto.BundleDTO in project nifi by apache.

the class StandardReportingTaskDAO method verifyUpdate.

private void verifyUpdate(final ReportingTaskNode reportingTask, final ReportingTaskDTO reportingTaskDTO) {
    // ensure the state, if specified, is valid
    if (isNotNull(reportingTaskDTO.getState())) {
        try {
            final ScheduledState purposedScheduledState = ScheduledState.valueOf(reportingTaskDTO.getState());
            // only attempt an action if it is changing
            if (!purposedScheduledState.equals(reportingTask.getScheduledState())) {
                // perform the appropriate action
                switch(purposedScheduledState) {
                    case RUNNING:
                        reportingTask.verifyCanStart();
                        break;
                    case STOPPED:
                        switch(reportingTask.getScheduledState()) {
                            case RUNNING:
                                reportingTask.verifyCanStop();
                                break;
                            case DISABLED:
                                reportingTask.verifyCanEnable();
                                break;
                        }
                        break;
                    case DISABLED:
                        reportingTask.verifyCanDisable();
                        break;
                }
            }
        } catch (IllegalArgumentException iae) {
            throw new IllegalArgumentException(String.format("The specified reporting task state (%s) is not valid. Valid options are 'RUNNING', 'STOPPED', and 'DISABLED'.", reportingTaskDTO.getState()));
        }
    }
    boolean modificationRequest = false;
    if (isAnyNotNull(reportingTaskDTO.getName(), reportingTaskDTO.getSchedulingStrategy(), reportingTaskDTO.getSchedulingPeriod(), reportingTaskDTO.getAnnotationData(), reportingTaskDTO.getProperties(), reportingTaskDTO.getBundle())) {
        modificationRequest = true;
        // validate the request
        final List<String> requestValidation = validateProposedConfiguration(reportingTask, reportingTaskDTO);
        // ensure there was no validation errors
        if (!requestValidation.isEmpty()) {
            throw new ValidationException(requestValidation);
        }
    }
    final BundleDTO bundleDTO = reportingTaskDTO.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(reportingTask.getCanonicalClassName(), bundleDTO);
        // ensure we are only changing to a bundle with the same group and id, but different version
        reportingTask.verifyCanUpdateBundle(bundleCoordinate);
    }
    if (modificationRequest) {
        reportingTask.verifyCanUpdate();
    }
}
Also used : ValidationException(org.apache.nifi.controller.exception.ValidationException) ScheduledState(org.apache.nifi.controller.ScheduledState) BundleDTO(org.apache.nifi.web.api.dto.BundleDTO) BundleCoordinate(org.apache.nifi.bundle.BundleCoordinate)

Aggregations

BundleDTO (org.apache.nifi.web.api.dto.BundleDTO)21 BundleCoordinate (org.apache.nifi.bundle.BundleCoordinate)16 ConfigurableComponent (org.apache.nifi.components.ConfigurableComponent)4 ProcessorConfigDTO (org.apache.nifi.web.api.dto.ProcessorConfigDTO)4 URL (java.net.URL)3 Stateful (org.apache.nifi.annotation.behavior.Stateful)3 ValidationException (org.apache.nifi.controller.exception.ValidationException)3 ReportingTaskInstantiationException (org.apache.nifi.controller.reporting.ReportingTaskInstantiationException)3 UiExtension (org.apache.nifi.ui.extension.UiExtension)3 UiExtensionMapping (org.apache.nifi.ui.extension.UiExtensionMapping)3 NiFiCoreException (org.apache.nifi.web.NiFiCoreException)3 PositionDTO (org.apache.nifi.web.api.dto.PositionDTO)3 ProcessorDTO (org.apache.nifi.web.api.dto.ProcessorDTO)3 Element (org.w3c.dom.Element)3 ScheduledState (org.apache.nifi.controller.ScheduledState)2 ProcessorInstantiationException (org.apache.nifi.controller.exception.ProcessorInstantiationException)2 ControllerServiceNode (org.apache.nifi.controller.service.ControllerServiceNode)2 DummyProcessor (org.apache.nifi.controller.service.mock.DummyProcessor)2 ControllerServiceDTO (org.apache.nifi.web.api.dto.ControllerServiceDTO)2 FlowSnippetDTO (org.apache.nifi.web.api.dto.FlowSnippetDTO)2