use of org.apache.nifi.groups.ProcessGroup in project nifi by apache.
the class StandardSnippetDAO method createSnippet.
@Override
public Snippet createSnippet(final SnippetDTO snippetDTO) {
// create the snippet request
final StandardSnippet snippet = new StandardSnippet();
snippet.setId(snippetDTO.getId());
snippet.setParentGroupId(snippetDTO.getParentGroupId());
snippet.addProcessors(mapDtoToRevision(snippetDTO.getProcessors()));
snippet.addProcessGroups(mapDtoToRevision(snippetDTO.getProcessGroups()));
snippet.addRemoteProcessGroups(mapDtoToRevision(snippetDTO.getRemoteProcessGroups()));
snippet.addInputPorts(mapDtoToRevision(snippetDTO.getInputPorts()));
snippet.addOutputPorts(mapDtoToRevision(snippetDTO.getOutputPorts()));
snippet.addConnections(mapDtoToRevision(snippetDTO.getConnections()));
snippet.addLabels(mapDtoToRevision(snippetDTO.getLabels()));
snippet.addFunnels(mapDtoToRevision(snippetDTO.getFunnels()));
// ensure this snippet isn't empty
if (snippet.isEmpty()) {
throw new IllegalArgumentException("Cannot create an empty snippet.");
}
// ensure the parent group exist
final ProcessGroup processGroup = flowController.getGroup(snippet.getParentGroupId());
if (processGroup == null) {
throw new IllegalArgumentException("The specified parent process group could not be found.");
}
// store the snippet
flowController.getSnippetManager().addSnippet(snippet);
return snippet;
}
use of org.apache.nifi.groups.ProcessGroup in project nifi by apache.
the class StandardSnippetDAO method verifyDeleteSnippetComponents.
@Override
public void verifyDeleteSnippetComponents(String snippetId) {
final Snippet snippet = locateSnippet(snippetId);
// ensure the parent group exist
final ProcessGroup processGroup = flowController.getGroup(snippet.getParentGroupId());
if (processGroup == null) {
throw new IllegalArgumentException("The specified parent process group could not be found.");
}
// verify the processGroup can remove the snippet
processGroup.verifyCanDelete(snippet);
}
use of org.apache.nifi.groups.ProcessGroup 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(), ".")));
}
}
use of org.apache.nifi.groups.ProcessGroup in project nifi by apache.
the class StandardTemplateDAO method createTemplate.
@Override
public Template createTemplate(TemplateDTO templateDTO, String groupId) {
final ProcessGroup processGroup = flowController.getGroup(groupId);
if (processGroup == null) {
throw new ResourceNotFoundException("Could not find Process Group with ID " + groupId);
}
verifyAdd(templateDTO.getName(), processGroup);
TemplateUtils.scrubTemplate(templateDTO);
final Template template = new Template(templateDTO);
processGroup.addTemplate(template);
return template;
}
use of org.apache.nifi.groups.ProcessGroup in project nifi by apache.
the class SnippetUtils method resolveNameConflicts.
private void resolveNameConflicts(final FlowSnippetDTO snippetContents, final ProcessGroup group) {
// get a list of all names of ports so that we can rename the ports as needed.
final List<String> existingPortNames = new ArrayList<>();
for (final Port inputPort : group.getInputPorts()) {
existingPortNames.add(inputPort.getName());
}
for (final Port outputPort : group.getOutputPorts()) {
existingPortNames.add(outputPort.getName());
}
// rename ports
if (snippetContents.getInputPorts() != null) {
for (final PortDTO portDTO : snippetContents.getInputPorts()) {
String portName = portDTO.getName();
while (existingPortNames.contains(portName)) {
portName = "Copy of " + portName;
}
portDTO.setName(portName);
existingPortNames.add(portDTO.getName());
}
}
if (snippetContents.getOutputPorts() != null) {
for (final PortDTO portDTO : snippetContents.getOutputPorts()) {
String portName = portDTO.getName();
while (existingPortNames.contains(portName)) {
portName = "Copy of " + portName;
}
portDTO.setName(portName);
existingPortNames.add(portDTO.getName());
}
}
// get a list of all names of process groups so that we can rename as needed.
final Set<String> groupNames = new HashSet<>();
for (final ProcessGroup childGroup : group.getProcessGroups()) {
groupNames.add(childGroup.getName());
}
if (snippetContents.getProcessGroups() != null) {
for (final ProcessGroupDTO groupDTO : snippetContents.getProcessGroups()) {
// 'Copy of...' so we do this only if there is no Version Control Information present.
if (groupDTO.getVersionControlInformation() == null) {
String groupName = groupDTO.getName();
while (groupNames.contains(groupName)) {
groupName = "Copy of " + groupName;
}
groupDTO.setName(groupName);
}
groupNames.add(groupDTO.getName());
}
}
}
Aggregations