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(), ".")));
}
}
Aggregations