use of org.apache.nifi.controller.Snippet in project nifi by apache.
the class StandardAuthorizableLookup method getSnippet.
@Override
public SnippetAuthorizable getSnippet(final String id) {
final Snippet snippet = snippetDAO.getSnippet(id);
final ProcessGroup processGroup = processGroupDAO.getProcessGroup(snippet.getParentGroupId());
return new SnippetAuthorizable() {
@Override
public Authorizable getParentProcessGroup() {
return processGroup;
}
@Override
public Set<ComponentAuthorizable> getSelectedProcessors() {
return processGroup.getProcessors().stream().filter(processor -> snippet.getProcessors().containsKey(processor.getIdentifier())).map(processor -> getProcessor(processor.getIdentifier())).collect(Collectors.toSet());
}
@Override
public Set<ConnectionAuthorizable> getSelectedConnections() {
return processGroup.getConnections().stream().filter(connection -> snippet.getConnections().containsKey(connection.getIdentifier())).map(connection -> getConnection(connection.getIdentifier())).collect(Collectors.toSet());
}
@Override
public Set<Authorizable> getSelectedInputPorts() {
return processGroup.getInputPorts().stream().filter(inputPort -> snippet.getInputPorts().containsKey(inputPort.getIdentifier())).map(inputPort -> getInputPort(inputPort.getIdentifier())).collect(Collectors.toSet());
}
@Override
public Set<Authorizable> getSelectedOutputPorts() {
return processGroup.getOutputPorts().stream().filter(outputPort -> snippet.getOutputPorts().containsKey(outputPort.getIdentifier())).map(outputPort -> getOutputPort(outputPort.getIdentifier())).collect(Collectors.toSet());
}
@Override
public Set<Authorizable> getSelectedFunnels() {
return processGroup.getFunnels().stream().filter(funnel -> snippet.getFunnels().containsKey(funnel.getIdentifier())).map(funnel -> getFunnel(funnel.getIdentifier())).collect(Collectors.toSet());
}
@Override
public Set<Authorizable> getSelectedLabels() {
return processGroup.getLabels().stream().filter(label -> snippet.getLabels().containsKey(label.getIdentifier())).map(label -> getLabel(label.getIdentifier())).collect(Collectors.toSet());
}
@Override
public Set<ProcessGroupAuthorizable> getSelectedProcessGroups() {
return processGroup.getProcessGroups().stream().filter(processGroup -> snippet.getProcessGroups().containsKey(processGroup.getIdentifier())).map(processGroup -> getProcessGroup(processGroup.getIdentifier())).collect(Collectors.toSet());
}
@Override
public Set<Authorizable> getSelectedRemoteProcessGroups() {
return processGroup.getRemoteProcessGroups().stream().filter(remoteProcessGroup -> snippet.getRemoteProcessGroups().containsKey(remoteProcessGroup.getIdentifier())).map(remoteProcessGroup -> getRemoteProcessGroup(remoteProcessGroup.getIdentifier())).collect(Collectors.toSet());
}
};
}
use of org.apache.nifi.controller.Snippet in project nifi by apache.
the class StandardNiFiServiceFacade method postProcessNewFlowSnippet.
/**
* Post processes a new flow snippet including validation, removing the snippet, and DTO conversion.
*
* @param groupId group id
* @param snippet snippet
* @return flow dto
*/
private FlowDTO postProcessNewFlowSnippet(final String groupId, final FlowSnippetDTO snippet) {
// validate the new snippet
validateSnippetContents(snippet);
// identify all components added
final Set<String> identifiers = new HashSet<>();
snippet.getProcessors().stream().map(proc -> proc.getId()).forEach(id -> identifiers.add(id));
snippet.getConnections().stream().map(conn -> conn.getId()).forEach(id -> identifiers.add(id));
snippet.getInputPorts().stream().map(port -> port.getId()).forEach(id -> identifiers.add(id));
snippet.getOutputPorts().stream().map(port -> port.getId()).forEach(id -> identifiers.add(id));
snippet.getProcessGroups().stream().map(group -> group.getId()).forEach(id -> identifiers.add(id));
snippet.getRemoteProcessGroups().stream().map(remoteGroup -> remoteGroup.getId()).forEach(id -> identifiers.add(id));
snippet.getRemoteProcessGroups().stream().filter(remoteGroup -> remoteGroup.getContents() != null && remoteGroup.getContents().getInputPorts() != null).flatMap(remoteGroup -> remoteGroup.getContents().getInputPorts().stream()).map(remoteInputPort -> remoteInputPort.getId()).forEach(id -> identifiers.add(id));
snippet.getRemoteProcessGroups().stream().filter(remoteGroup -> remoteGroup.getContents() != null && remoteGroup.getContents().getOutputPorts() != null).flatMap(remoteGroup -> remoteGroup.getContents().getOutputPorts().stream()).map(remoteOutputPort -> remoteOutputPort.getId()).forEach(id -> identifiers.add(id));
snippet.getLabels().stream().map(label -> label.getId()).forEach(id -> identifiers.add(id));
final ProcessGroup group = processGroupDAO.getProcessGroup(groupId);
final ProcessGroupStatus groupStatus = controllerFacade.getProcessGroupStatus(groupId);
return dtoFactory.createFlowDto(group, groupStatus, snippet, revisionManager, this::getProcessGroupBulletins);
}
use of org.apache.nifi.controller.Snippet in project nifi by apache.
the class StandardNiFiServiceFacade method updateSnippet.
@Override
public SnippetEntity updateSnippet(final Set<Revision> revisions, final SnippetDTO snippetDto) {
final NiFiUser user = NiFiUserUtils.getNiFiUser();
final RevisionClaim revisionClaim = new StandardRevisionClaim(revisions);
final RevisionUpdate<SnippetDTO> snapshot;
try {
snapshot = revisionManager.updateRevision(revisionClaim, user, new UpdateRevisionTask<SnippetDTO>() {
@Override
public RevisionUpdate<SnippetDTO> update() {
// get the updated component
final Snippet snippet = snippetDAO.updateSnippetComponents(snippetDto);
// drop the snippet
snippetDAO.dropSnippet(snippet.getId());
// save updated controller
controllerFacade.save();
// increment the revisions
final Set<Revision> updatedRevisions = revisions.stream().map(revision -> {
final Revision currentRevision = revisionManager.getRevision(revision.getComponentId());
return currentRevision.incrementRevision(revision.getClientId());
}).collect(Collectors.toSet());
final SnippetDTO dto = dtoFactory.createSnippetDto(snippet);
return new StandardRevisionUpdate<>(dto, null, updatedRevisions);
}
});
} catch (final ExpiredRevisionClaimException e) {
throw new InvalidRevisionException("Failed to update Snippet", e);
}
return entityFactory.createSnippetEntity(snapshot.getComponent());
}
use of org.apache.nifi.controller.Snippet 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(), ".")));
}
}
use of org.apache.nifi.controller.Snippet in project nifi by apache.
the class StandardSnippetDAO method deleteSnippetComponents.
@Override
public void deleteSnippetComponents(String snippetId) {
// verify the action
verifyDeleteSnippetComponents(snippetId);
// locate the snippet in question
final Snippet snippet = locateSnippet(snippetId);
// remove the contents
final ProcessGroup processGroup = flowController.getGroup(snippet.getParentGroupId());
if (processGroup == null) {
throw new IllegalArgumentException("The specified parent process group could not be found.");
}
// remove the underlying components
processGroup.remove(snippet);
}
Aggregations