Search in sources :

Example 11 with NiFiCoreException

use of org.apache.nifi.web.NiFiCoreException in project nifi by apache.

the class StandardReportingTaskDAO method updateReportingTask.

@Override
public ReportingTaskNode updateReportingTask(final ReportingTaskDTO reportingTaskDTO) {
    // get the reporting task
    final ReportingTaskNode reportingTask = locateReportingTask(reportingTaskDTO.getId());
    // ensure we can perform the update
    verifyUpdate(reportingTask, reportingTaskDTO);
    // perform the update
    configureReportingTask(reportingTask, reportingTaskDTO);
    // attempt to change the underlying processor if an updated bundle is specified
    // updating the bundle must happen after configuring so that any additional classpath resources are set first
    updateBundle(reportingTask, reportingTaskDTO);
    // see if an update is necessary
    if (isNotNull(reportingTaskDTO.getState())) {
        final ScheduledState purposedScheduledState = ScheduledState.valueOf(reportingTaskDTO.getState());
        // only attempt an action if it is changing
        if (!purposedScheduledState.equals(reportingTask.getScheduledState())) {
            try {
                // perform the appropriate action
                switch(purposedScheduledState) {
                    case RUNNING:
                        reportingTaskProvider.startReportingTask(reportingTask);
                        break;
                    case STOPPED:
                        switch(reportingTask.getScheduledState()) {
                            case RUNNING:
                                reportingTaskProvider.stopReportingTask(reportingTask);
                                break;
                            case DISABLED:
                                reportingTaskProvider.enableReportingTask(reportingTask);
                                break;
                        }
                        break;
                    case DISABLED:
                        reportingTaskProvider.disableReportingTask(reportingTask);
                        break;
                }
            } catch (IllegalStateException | ComponentLifeCycleException ise) {
                throw new NiFiCoreException(ise.getMessage(), ise);
            } catch (RejectedExecutionException ree) {
                throw new NiFiCoreException("Unable to schedule all tasks for the specified reporting task.", ree);
            } catch (NullPointerException npe) {
                throw new NiFiCoreException("Unable to update reporting task run state.", npe);
            } catch (Exception e) {
                throw new NiFiCoreException("Unable to update reporting task run state: " + e, e);
            }
        }
    }
    return reportingTask;
}
Also used : NiFiCoreException(org.apache.nifi.web.NiFiCoreException) ReportingTaskNode(org.apache.nifi.controller.ReportingTaskNode) ScheduledState(org.apache.nifi.controller.ScheduledState) ComponentLifeCycleException(org.apache.nifi.controller.exception.ComponentLifeCycleException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) ReportingTaskInstantiationException(org.apache.nifi.controller.reporting.ReportingTaskInstantiationException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) ResourceNotFoundException(org.apache.nifi.web.ResourceNotFoundException) ParseException(java.text.ParseException) ComponentLifeCycleException(org.apache.nifi.controller.exception.ComponentLifeCycleException) NiFiCoreException(org.apache.nifi.web.NiFiCoreException) ValidationException(org.apache.nifi.controller.exception.ValidationException)

Example 12 with NiFiCoreException

use of org.apache.nifi.web.NiFiCoreException in project nifi by apache.

the class FlowRegistryUtils method getRestrictedComponents.

public static Set<ConfigurableComponent> getRestrictedComponents(final VersionedProcessGroup group) {
    final Set<ConfigurableComponent> restrictedComponents = new HashSet<>();
    final Set<Tuple<String, BundleCoordinate>> componentTypes = new HashSet<>();
    populateComponentTypes(group, componentTypes);
    for (final Tuple<String, BundleCoordinate> tuple : componentTypes) {
        final ConfigurableComponent component = ExtensionManager.getTempComponent(tuple.getKey(), tuple.getValue());
        if (component == null) {
            throw new NiFiCoreException("Could not create an instance of component " + tuple.getKey() + " using bundle coordinates " + tuple.getValue());
        }
        final boolean isRestricted = component.getClass().isAnnotationPresent(Restricted.class);
        if (isRestricted) {
            restrictedComponents.add(component);
        }
    }
    return restrictedComponents;
}
Also used : NiFiCoreException(org.apache.nifi.web.NiFiCoreException) ConfigurableComponent(org.apache.nifi.components.ConfigurableComponent) BundleCoordinate(org.apache.nifi.bundle.BundleCoordinate) Tuple(org.apache.nifi.util.Tuple) HashSet(java.util.HashSet)

Example 13 with NiFiCoreException

use of org.apache.nifi.web.NiFiCoreException in project nifi by apache.

the class StandardTemplateDAO method instantiateTemplate.

@Override
public FlowSnippetDTO instantiateTemplate(String groupId, Double originX, Double originY, String encodingVersion, FlowSnippetDTO requestSnippet, String idGenerationSeed) {
    ProcessGroup group = locateProcessGroup(flowController, groupId);
    try {
        // copy the template which pre-processes all ids
        FlowSnippetDTO snippet = snippetUtils.copy(requestSnippet, group, idGenerationSeed, false);
        // calculate scaling factors based on the template encoding version attempt to parse the encoding version.
        // get the major version, or 0 if no version could be parsed
        final FlowEncodingVersion templateEncodingVersion = FlowEncodingVersion.parse(encodingVersion);
        int templateEncodingMajorVersion = templateEncodingVersion != null ? templateEncodingVersion.getMajorVersion() : 0;
        // based on the major version < 1, use the default scaling factors.  Otherwise, don't scale (use factor of 1.0)
        double factorX = templateEncodingMajorVersion < 1 ? FlowController.DEFAULT_POSITION_SCALE_FACTOR_X : 1.0;
        double factorY = templateEncodingMajorVersion < 1 ? FlowController.DEFAULT_POSITION_SCALE_FACTOR_Y : 1.0;
        // reposition and scale the template contents
        org.apache.nifi.util.SnippetUtils.moveAndScaleSnippet(snippet, originX, originY, factorX, factorY);
        // find all the child process groups in each process group in the top level of this snippet
        final List<ProcessGroupDTO> childProcessGroups = org.apache.nifi.util.SnippetUtils.findAllProcessGroups(snippet);
        // scale (but don't reposition) child process groups
        childProcessGroups.stream().forEach(processGroup -> org.apache.nifi.util.SnippetUtils.scaleSnippet(processGroup.getContents(), factorX, factorY));
        // instantiate the template into this group
        flowController.instantiateSnippet(group, snippet);
        return snippet;
    } catch (ProcessorInstantiationException pie) {
        throw new NiFiCoreException(String.format("Unable to instantiate template because processor type '%s' is unknown to this NiFi.", StringUtils.substringAfterLast(pie.getMessage(), ".")));
    }
}
Also used : FlowSnippetDTO(org.apache.nifi.web.api.dto.FlowSnippetDTO) NiFiCoreException(org.apache.nifi.web.NiFiCoreException) ProcessGroup(org.apache.nifi.groups.ProcessGroup) ProcessorInstantiationException(org.apache.nifi.controller.exception.ProcessorInstantiationException) ProcessGroupDTO(org.apache.nifi.web.api.dto.ProcessGroupDTO) FlowEncodingVersion(org.apache.nifi.controller.serialization.FlowEncodingVersion)

Example 14 with NiFiCoreException

use of org.apache.nifi.web.NiFiCoreException in project nifi by apache.

the class ApplicationStartupContextListener method contextInitialized.

@Override
public void contextInitialized(ServletContextEvent sce) {
    final ApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(sce.getServletContext());
    final NiFiProperties properties = ctx.getBean("nifiProperties", NiFiProperties.class);
    try {
        flowService = ctx.getBean("flowService", FlowService.class);
        flowController = ctx.getBean("flowController", FlowController.class);
        requestReplicator = ctx.getBean("requestReplicator", RequestReplicator.class);
        // the flow loading here when not clustered resolves this.
        if (!properties.isNode()) {
            logger.info("Starting Flow Controller...");
            // start and load the flow
            flowService.start();
            flowService.load(null);
            /*
                 * Start up all processors if specified.
                 *
                 * When operating as the node, the cluster manager controls
                 * which processors should start. As part of the flow
                 * reloading actions, the node will start the necessary
                 * processors.
                 */
            flowController.onFlowInitialized(properties.getAutoResumeState());
            logger.info("Flow Controller started successfully.");
        }
    } catch (BeansException | RepositoryPurgeException | IOException e) {
        shutdown();
        throw new NiFiCoreException("Unable to start Flow Controller.", e);
    }
    try {
        // attempt to get a few beans that we want to to ensure properly created since they are lazily initialized
        ctx.getBean("loginIdentityProvider", LoginIdentityProvider.class);
        ctx.getBean("authorizer", Authorizer.class);
    } catch (final BeansException e) {
        shutdown();
        throw new NiFiCoreException("Unable to start Flow Controller.", e);
    }
}
Also used : NiFiProperties(org.apache.nifi.util.NiFiProperties) ApplicationContext(org.springframework.context.ApplicationContext) NiFiCoreException(org.apache.nifi.web.NiFiCoreException) RequestReplicator(org.apache.nifi.cluster.coordination.http.replication.RequestReplicator) FlowController(org.apache.nifi.controller.FlowController) IOException(java.io.IOException) RepositoryPurgeException(org.apache.nifi.controller.repository.RepositoryPurgeException) FlowService(org.apache.nifi.services.FlowService) BeansException(org.springframework.beans.BeansException)

Example 15 with NiFiCoreException

use of org.apache.nifi.web.NiFiCoreException in project nifi by apache.

the class FlowRegistryDAO method getFlowsForUser.

@Override
public Set<VersionedFlow> getFlowsForUser(String registryId, String bucketId, NiFiUser user) {
    try {
        final FlowRegistry flowRegistry = flowRegistryClient.getFlowRegistry(registryId);
        if (flowRegistry == null) {
            throw new IllegalArgumentException("The specified registry id is unknown to this NiFi.");
        }
        final Set<VersionedFlow> flows = flowRegistry.getFlows(bucketId, user);
        final Set<VersionedFlow> sortedFlows = new TreeSet<>((f1, f2) -> f1.getName().compareTo(f2.getName()));
        sortedFlows.addAll(flows);
        return sortedFlows;
    } catch (final IOException | NiFiRegistryException ioe) {
        throw new NiFiCoreException("Unable to obtain listing of flows for bucket with ID " + bucketId + ": " + ioe, ioe);
    }
}
Also used : NiFiCoreException(org.apache.nifi.web.NiFiCoreException) TreeSet(java.util.TreeSet) FlowRegistry(org.apache.nifi.registry.flow.FlowRegistry) VersionedFlow(org.apache.nifi.registry.flow.VersionedFlow) IOException(java.io.IOException) NiFiRegistryException(org.apache.nifi.registry.client.NiFiRegistryException)

Aggregations

NiFiCoreException (org.apache.nifi.web.NiFiCoreException)20 IOException (java.io.IOException)7 ResourceNotFoundException (org.apache.nifi.web.ResourceNotFoundException)6 ProcessorInstantiationException (org.apache.nifi.controller.exception.ProcessorInstantiationException)5 ProcessGroup (org.apache.nifi.groups.ProcessGroup)5 BundleCoordinate (org.apache.nifi.bundle.BundleCoordinate)4 ConfigurableComponent (org.apache.nifi.components.ConfigurableComponent)4 ScheduledState (org.apache.nifi.controller.ScheduledState)4 URL (java.net.URL)3 TreeSet (java.util.TreeSet)3 ComponentLifeCycleException (org.apache.nifi.controller.exception.ComponentLifeCycleException)3 ReportingTaskInstantiationException (org.apache.nifi.controller.reporting.ReportingTaskInstantiationException)3 ProvenanceEventRecord (org.apache.nifi.provenance.ProvenanceEventRecord)3 NiFiRegistryException (org.apache.nifi.registry.client.NiFiRegistryException)3 FlowRegistry (org.apache.nifi.registry.flow.FlowRegistry)3 BundleDTO (org.apache.nifi.web.api.dto.BundleDTO)3 ParseException (java.text.ParseException)2 HashSet (java.util.HashSet)2 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)2 Port (org.apache.nifi.connectable.Port)2