Search in sources :

Example 16 with NiFiCoreException

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

the class StandardInputPortDAO method updatePort.

@Override
public Port updatePort(PortDTO portDTO) {
    Port inputPort = locatePort(portDTO.getId());
    // ensure we can do this update
    verifyUpdate(inputPort, portDTO);
    // handle state transition
    if (isNotNull(portDTO.getState())) {
        final ScheduledState purposedScheduledState = ScheduledState.valueOf(portDTO.getState());
        // only attempt an action if it is changing
        if (!purposedScheduledState.equals(inputPort.getScheduledState())) {
            try {
                // perform the appropriate action
                switch(purposedScheduledState) {
                    case RUNNING:
                        inputPort.getProcessGroup().startInputPort(inputPort);
                        break;
                    case STOPPED:
                        switch(inputPort.getScheduledState()) {
                            case RUNNING:
                                inputPort.getProcessGroup().stopInputPort(inputPort);
                                break;
                            case DISABLED:
                                inputPort.getProcessGroup().enableInputPort(inputPort);
                                break;
                        }
                        break;
                    case DISABLED:
                        inputPort.getProcessGroup().disableInputPort(inputPort);
                        break;
                }
            } catch (IllegalStateException ise) {
                throw new NiFiCoreException(ise.getMessage(), ise);
            }
        }
    }
    if (inputPort instanceof RootGroupPort) {
        final RootGroupPort rootPort = (RootGroupPort) inputPort;
        if (isNotNull(portDTO.getGroupAccessControl())) {
            rootPort.setGroupAccessControl(portDTO.getGroupAccessControl());
        }
        if (isNotNull(portDTO.getUserAccessControl())) {
            rootPort.setUserAccessControl(portDTO.getUserAccessControl());
        }
    }
    // update the port
    final String name = portDTO.getName();
    final String comments = portDTO.getComments();
    final Integer concurrentTasks = portDTO.getConcurrentlySchedulableTaskCount();
    if (isNotNull(portDTO.getPosition())) {
        inputPort.setPosition(new Position(portDTO.getPosition().getX(), portDTO.getPosition().getY()));
    }
    if (isNotNull(name)) {
        inputPort.setName(name);
    }
    if (isNotNull(comments)) {
        inputPort.setComments(comments);
    }
    if (isNotNull(concurrentTasks)) {
        inputPort.setMaxConcurrentTasks(concurrentTasks);
    }
    inputPort.getProcessGroup().onComponentModified();
    return inputPort;
}
Also used : NiFiCoreException(org.apache.nifi.web.NiFiCoreException) ScheduledState(org.apache.nifi.controller.ScheduledState) RootGroupPort(org.apache.nifi.remote.RootGroupPort) Position(org.apache.nifi.connectable.Position) Port(org.apache.nifi.connectable.Port) RootGroupPort(org.apache.nifi.remote.RootGroupPort)

Example 17 with NiFiCoreException

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

the class StandardOutputPortDAO method updatePort.

@Override
public Port updatePort(PortDTO portDTO) {
    Port outputPort = locatePort(portDTO.getId());
    // ensure we can do this update
    verifyUpdate(outputPort, portDTO);
    // handle state transition
    if (portDTO.getState() != null) {
        final ScheduledState purposedScheduledState = ScheduledState.valueOf(portDTO.getState());
        // only attempt an action if it is changing
        if (!purposedScheduledState.equals(outputPort.getScheduledState())) {
            try {
                // perform the appropriate action
                switch(purposedScheduledState) {
                    case RUNNING:
                        outputPort.getProcessGroup().startOutputPort(outputPort);
                        break;
                    case STOPPED:
                        switch(outputPort.getScheduledState()) {
                            case RUNNING:
                                outputPort.getProcessGroup().stopOutputPort(outputPort);
                                break;
                            case DISABLED:
                                outputPort.getProcessGroup().enableOutputPort(outputPort);
                                break;
                        }
                        break;
                    case DISABLED:
                        outputPort.getProcessGroup().disableOutputPort(outputPort);
                        break;
                }
            } catch (IllegalStateException ise) {
                throw new NiFiCoreException(ise.getMessage(), ise);
            }
        }
    }
    if (outputPort instanceof RootGroupPort) {
        final RootGroupPort rootPort = (RootGroupPort) outputPort;
        if (isNotNull(portDTO.getGroupAccessControl())) {
            rootPort.setGroupAccessControl(portDTO.getGroupAccessControl());
        }
        if (isNotNull(portDTO.getUserAccessControl())) {
            rootPort.setUserAccessControl(portDTO.getUserAccessControl());
        }
    }
    // perform the configuration
    final String name = portDTO.getName();
    final String comments = portDTO.getComments();
    final Integer concurrentTasks = portDTO.getConcurrentlySchedulableTaskCount();
    if (isNotNull(portDTO.getPosition())) {
        outputPort.setPosition(new Position(portDTO.getPosition().getX(), portDTO.getPosition().getY()));
    }
    if (isNotNull(name)) {
        outputPort.setName(name);
    }
    if (isNotNull(comments)) {
        outputPort.setComments(comments);
    }
    if (isNotNull(concurrentTasks)) {
        outputPort.setMaxConcurrentTasks(concurrentTasks);
    }
    outputPort.getProcessGroup().onComponentModified();
    return outputPort;
}
Also used : NiFiCoreException(org.apache.nifi.web.NiFiCoreException) ScheduledState(org.apache.nifi.controller.ScheduledState) RootGroupPort(org.apache.nifi.remote.RootGroupPort) Position(org.apache.nifi.connectable.Position) Port(org.apache.nifi.connectable.Port) RootGroupPort(org.apache.nifi.remote.RootGroupPort)

Example 18 with NiFiCoreException

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

the class StandardProcessorDAO method updateProcessor.

@Override
public ProcessorNode updateProcessor(ProcessorDTO processorDTO) {
    ProcessorNode processor = locateProcessor(processorDTO.getId());
    ProcessGroup parentGroup = processor.getProcessGroup();
    // ensure we can perform the update
    verifyUpdate(processor, processorDTO);
    // configure the processor
    configureProcessor(processor, processorDTO);
    parentGroup.onComponentModified();
    // 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(processor, processorDTO);
    // see if an update is necessary
    if (isNotNull(processorDTO.getState())) {
        final ScheduledState purposedScheduledState = ScheduledState.valueOf(processorDTO.getState());
        // only attempt an action if it is changing
        if (!purposedScheduledState.equals(processor.getScheduledState())) {
            try {
                // perform the appropriate action
                switch(purposedScheduledState) {
                    case RUNNING:
                        parentGroup.startProcessor(processor, true);
                        break;
                    case STOPPED:
                        switch(processor.getScheduledState()) {
                            case RUNNING:
                                parentGroup.stopProcessor(processor);
                                break;
                            case DISABLED:
                                parentGroup.enableProcessor(processor);
                                break;
                        }
                        break;
                    case DISABLED:
                        parentGroup.disableProcessor(processor);
                        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 processor.", ree);
            } catch (NullPointerException npe) {
                throw new NiFiCoreException("Unable to update processor run state.", npe);
            } catch (Exception e) {
                throw new NiFiCoreException("Unable to update processor run state: " + e, e);
            }
        }
    }
    return processor;
}
Also used : NiFiCoreException(org.apache.nifi.web.NiFiCoreException) ProcessorNode(org.apache.nifi.controller.ProcessorNode) ScheduledState(org.apache.nifi.controller.ScheduledState) ProcessGroup(org.apache.nifi.groups.ProcessGroup) ComponentLifeCycleException(org.apache.nifi.controller.exception.ComponentLifeCycleException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) ProcessorInstantiationException(org.apache.nifi.controller.exception.ProcessorInstantiationException) 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 19 with NiFiCoreException

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

the class StandardReportingTaskDAO method updateBundle.

private void updateBundle(ReportingTaskNode reportingTask, ReportingTaskDTO reportingTaskDTO) {
    final BundleDTO bundleDTO = reportingTaskDTO.getBundle();
    if (bundleDTO != null) {
        final BundleCoordinate incomingCoordinate = BundleUtils.getBundle(reportingTask.getCanonicalClassName(), bundleDTO);
        final BundleCoordinate existingCoordinate = reportingTask.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(reportingTask.getCanonicalClassName(), incomingCoordinate);
                final Set<URL> additionalUrls = reportingTask.getAdditionalClasspathResources(tempComponent.getPropertyDescriptors());
                reloadComponent.reload(reportingTask, reportingTask.getCanonicalClassName(), incomingCoordinate, additionalUrls);
            } catch (ReportingTaskInstantiationException e) {
                throw new NiFiCoreException(String.format("Unable to update reporting task %s from %s to %s due to: %s", reportingTaskDTO.getId(), reportingTask.getBundleCoordinate().getCoordinate(), incomingCoordinate.getCoordinate(), e.getMessage()), e);
            }
        }
    }
}
Also used : NiFiCoreException(org.apache.nifi.web.NiFiCoreException) ReportingTaskInstantiationException(org.apache.nifi.controller.reporting.ReportingTaskInstantiationException) ConfigurableComponent(org.apache.nifi.components.ConfigurableComponent) BundleDTO(org.apache.nifi.web.api.dto.BundleDTO) BundleCoordinate(org.apache.nifi.bundle.BundleCoordinate) URL(java.net.URL)

Example 20 with NiFiCoreException

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

the class StandardSnippetDAO method copySnippet.

@Override
public FlowSnippetDTO copySnippet(final String groupId, final String snippetId, final Double originX, final Double originY, final String idGenerationSeed) {
    try {
        // ensure the parent group exist
        final ProcessGroup processGroup = flowController.getGroup(groupId);
        if (processGroup == null) {
            throw new IllegalArgumentException("The specified parent process group could not be found");
        }
        // get the existing snippet
        Snippet existingSnippet = getSnippet(snippetId);
        // get the process group
        ProcessGroup existingSnippetProcessGroup = flowController.getGroup(existingSnippet.getParentGroupId());
        // ensure the group could be found
        if (existingSnippetProcessGroup == null) {
            throw new IllegalStateException("The parent process group for the existing snippet could not be found.");
        }
        // generate the snippet contents
        FlowSnippetDTO snippetContents = snippetUtils.populateFlowSnippet(existingSnippet, true, false, false);
        // resolve sensitive properties
        lookupSensitiveProperties(snippetContents);
        // copy snippet
        snippetContents = snippetUtils.copy(snippetContents, processGroup, idGenerationSeed, true);
        // move the snippet if necessary
        if (originX != null && originY != null) {
            org.apache.nifi.util.SnippetUtils.moveSnippet(snippetContents, originX, originY);
        }
        try {
            // instantiate the snippet and return the contents
            flowController.instantiateSnippet(processGroup, snippetContents);
            return snippetContents;
        } catch (IllegalStateException ise) {
            // illegal state will be thrown from instantiateSnippet when there is an issue with the snippet _before_ any of the
            // components are actually created. if we've received this exception we want to attempt to roll back any of the
            // policies that we've already cloned for this request
            snippetUtils.rollbackClonedPolicies(snippetContents);
            // rethrow the same exception
            throw ise;
        }
    } catch (ProcessorInstantiationException pie) {
        throw new NiFiCoreException(String.format("Unable to copy snippet 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) Snippet(org.apache.nifi.controller.Snippet) StandardSnippet(org.apache.nifi.controller.StandardSnippet)

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