Search in sources :

Example 11 with ProcessorInstantiationException

use of org.apache.nifi.controller.exception.ProcessorInstantiationException 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

ProcessorInstantiationException (org.apache.nifi.controller.exception.ProcessorInstantiationException)11 ProcessGroup (org.apache.nifi.groups.ProcessGroup)6 HashSet (java.util.HashSet)5 ControllerServiceNode (org.apache.nifi.controller.service.ControllerServiceNode)5 ArrayList (java.util.ArrayList)4 BundleCoordinate (org.apache.nifi.bundle.BundleCoordinate)4 Connection (org.apache.nifi.connectable.Connection)4 Port (org.apache.nifi.connectable.Port)4 Position (org.apache.nifi.connectable.Position)4 Size (org.apache.nifi.connectable.Size)4 Label (org.apache.nifi.controller.label.Label)4 ReportingTaskInstantiationException (org.apache.nifi.controller.reporting.ReportingTaskInstantiationException)4 FlowFilePrioritizer (org.apache.nifi.flowfile.FlowFilePrioritizer)4 StandardVersionControlInformation (org.apache.nifi.registry.flow.StandardVersionControlInformation)4 RemoteGroupPort (org.apache.nifi.remote.RemoteGroupPort)4 RootGroupPort (org.apache.nifi.remote.RootGroupPort)4 NiFiCoreException (org.apache.nifi.web.NiFiCoreException)4 ProcessGroupDTO (org.apache.nifi.web.api.dto.ProcessGroupDTO)4 LinkedHashSet (java.util.LinkedHashSet)3 Connectable (org.apache.nifi.connectable.Connectable)3