use of org.apache.nifi.web.api.dto.flow.ProcessGroupFlowDTO in project kylo by Teradata.
the class LegacyNifiRestClient method startProcessGroupAndParentInputPorts.
public void startProcessGroupAndParentInputPorts(ProcessGroupDTO entity) {
// 1 startAll
try {
startAll(entity.getId(), entity.getParentGroupId());
} catch (NifiClientRuntimeException e) {
log.error("Error trying to mark connection ports Running for {}", entity.getName());
}
Set<PortDTO> ports = null;
try {
ports = getPortsForProcessGroup(entity.getParentGroupId());
} catch (NifiClientRuntimeException e) {
log.error("Error getPortsForProcessGroup {}", entity.getName());
}
if (ports != null && !ports.isEmpty()) {
Map<String, PortDTO> portsById = ports.stream().collect(Collectors.toMap(port -> port.getId(), port -> port));
ProcessGroupFlowDTO flow = getNiFiRestClient().processGroups().flow(entity.getParentGroupId());
if (flow != null) {
List<PortDTO> matchingParentGroupPorts = flow.getFlow().getConnections().stream().map(connectionEntity -> connectionEntity.getComponent()).filter(connectionDTO -> connectionDTO.getDestination().getGroupId().equalsIgnoreCase(entity.getId())).filter(connectionDTO -> portsById.containsKey(connectionDTO.getSource().getId())).map(connectionDTO -> portsById.get(connectionDTO.getSource().getId())).collect(Collectors.toList());
for (PortDTO port : matchingParentGroupPorts) {
port.setState(NifiProcessUtil.PROCESS_STATE.RUNNING.name());
if (port.getType().equalsIgnoreCase(NifiConstants.NIFI_PORT_TYPE.INPUT_PORT.name())) {
try {
startInputPort(entity.getParentGroupId(), port.getId());
} catch (NifiClientRuntimeException e) {
log.error("Error starting Input Port {} for process group {}", port.getName(), entity.getName());
}
} else if (port.getType().equalsIgnoreCase(NifiConstants.NIFI_PORT_TYPE.OUTPUT_PORT.name())) {
try {
startOutputPort(entity.getParentGroupId(), port.getId());
} catch (NifiClientRuntimeException e) {
log.error("Error starting Output Port {} for process group {}", port.getName(), entity.getName());
}
}
}
}
}
}
use of org.apache.nifi.web.api.dto.flow.ProcessGroupFlowDTO in project nifi by apache.
the class DtoFactory method createProcessGroupFlowDto.
public ProcessGroupFlowDTO createProcessGroupFlowDto(final ProcessGroup group, final ProcessGroupStatus groupStatus, final RevisionManager revisionManager, final Function<ProcessGroup, List<BulletinEntity>> getProcessGroupBulletins) {
final ProcessGroupFlowDTO dto = new ProcessGroupFlowDTO();
dto.setId(group.getIdentifier());
dto.setLastRefreshed(new Date());
dto.setBreadcrumb(createBreadcrumbEntity(group));
dto.setFlow(createFlowDto(group, groupStatus, revisionManager, getProcessGroupBulletins));
final ProcessGroup parent = group.getParent();
if (parent != null) {
dto.setParentGroupId(parent.getIdentifier());
}
return dto;
}
use of org.apache.nifi.web.api.dto.flow.ProcessGroupFlowDTO in project nifi by apache.
the class PGList method doExecute.
@Override
public ProcessGroupsResult doExecute(final NiFiClient client, final Properties properties) throws NiFiClientException, IOException {
final FlowClient flowClient = client.getFlowClient();
// get the optional id of the parent PG, otherwise fallback to the root group
String parentPgId = getArg(properties, CommandOption.PG_ID);
if (StringUtils.isBlank(parentPgId)) {
parentPgId = flowClient.getRootGroupId();
}
final ProcessGroupFlowEntity processGroupFlowEntity = flowClient.getProcessGroup(parentPgId);
final ProcessGroupFlowDTO processGroupFlowDTO = processGroupFlowEntity.getProcessGroupFlow();
final FlowDTO flowDTO = processGroupFlowDTO.getFlow();
final List<ProcessGroupDTO> processGroups = new ArrayList<>();
if (flowDTO.getProcessGroups() != null) {
flowDTO.getProcessGroups().stream().map(pge -> pge.getComponent()).forEach(dto -> processGroups.add(dto));
}
return new ProcessGroupsResult(getResultType(properties), processGroups);
}
use of org.apache.nifi.web.api.dto.flow.ProcessGroupFlowDTO in project nifi by apache.
the class FlowMerger method mergeResponses.
@Override
protected void mergeResponses(final ProcessGroupFlowDTO clientDto, final Map<NodeIdentifier, ProcessGroupFlowDTO> dtoMap, final Set<NodeResponse> successfulResponses, final Set<NodeResponse> problematicResponses) {
final FlowDTO flowDto = clientDto.getFlow();
final Set<ConnectionEntity> clientConnections = flowDto.getConnections();
final Set<ProcessorEntity> clientProcessors = flowDto.getProcessors();
final Set<PortEntity> clientInputPorts = flowDto.getInputPorts();
final Set<PortEntity> clientOutputPorts = flowDto.getOutputPorts();
final Set<RemoteProcessGroupEntity> clientRemoteProcessGroups = flowDto.getRemoteProcessGroups();
final Set<ProcessGroupEntity> clientProcessGroups = flowDto.getProcessGroups();
final Set<LabelEntity> clientLabels = flowDto.getLabels();
final Set<FunnelEntity> clientFunnels = flowDto.getFunnels();
final Map<String, Map<NodeIdentifier, ConnectionEntity>> connections = new HashMap<>();
final Map<String, Map<NodeIdentifier, FunnelEntity>> funnels = new HashMap<>();
final Map<String, Map<NodeIdentifier, PortEntity>> inputPorts = new HashMap<>();
final Map<String, Map<NodeIdentifier, LabelEntity>> labels = new HashMap<>();
final Map<String, Map<NodeIdentifier, PortEntity>> outputPorts = new HashMap<>();
final Map<String, Map<NodeIdentifier, ProcessorEntity>> processors = new HashMap<>();
final Map<String, Map<NodeIdentifier, RemoteProcessGroupEntity>> rpgs = new HashMap<>();
final Map<String, Map<NodeIdentifier, ProcessGroupEntity>> processGroups = new HashMap<>();
// Create mapping of ComponentID -> [nodeId, entity on that node]
for (final Map.Entry<NodeIdentifier, ProcessGroupFlowDTO> nodeGroupFlowEntry : dtoMap.entrySet()) {
final NodeIdentifier nodeIdentifier = nodeGroupFlowEntry.getKey();
final ProcessGroupFlowDTO nodeGroupFlowDto = nodeGroupFlowEntry.getValue();
final FlowDTO nodeFlowDto = nodeGroupFlowDto.getFlow();
// Merge connection statuses
for (final ConnectionEntity entity : nodeFlowDto.getConnections()) {
connections.computeIfAbsent(entity.getId(), id -> new HashMap<>()).computeIfAbsent(nodeIdentifier, nodeId -> entity);
}
for (final FunnelEntity entity : nodeFlowDto.getFunnels()) {
funnels.computeIfAbsent(entity.getId(), id -> new HashMap<>()).computeIfAbsent(nodeIdentifier, nodeId -> entity);
}
for (final PortEntity entity : nodeFlowDto.getInputPorts()) {
inputPorts.computeIfAbsent(entity.getId(), id -> new HashMap<>()).computeIfAbsent(nodeIdentifier, nodeId -> entity);
}
for (final PortEntity entity : nodeFlowDto.getOutputPorts()) {
outputPorts.computeIfAbsent(entity.getId(), id -> new HashMap<>()).computeIfAbsent(nodeIdentifier, nodeId -> entity);
}
for (final LabelEntity entity : nodeFlowDto.getLabels()) {
labels.computeIfAbsent(entity.getId(), id -> new HashMap<>()).computeIfAbsent(nodeIdentifier, nodeId -> entity);
}
for (final ProcessorEntity entity : nodeFlowDto.getProcessors()) {
processors.computeIfAbsent(entity.getId(), id -> new HashMap<>()).computeIfAbsent(nodeIdentifier, nodeId -> entity);
}
for (final RemoteProcessGroupEntity entity : nodeFlowDto.getRemoteProcessGroups()) {
rpgs.computeIfAbsent(entity.getId(), id -> new HashMap<>()).computeIfAbsent(nodeIdentifier, nodeId -> entity);
}
for (final ProcessGroupEntity entity : nodeFlowDto.getProcessGroups()) {
processGroups.computeIfAbsent(entity.getId(), id -> new HashMap<>()).computeIfAbsent(nodeIdentifier, nodeId -> entity);
}
}
//
// Merge the components that are grouped together by ID
//
// Merge connections
ConnectionsEntityMerger.mergeConnections(clientConnections, connections);
// Merge funnel statuses
FunnelsEntityMerger.mergeFunnels(clientFunnels, funnels);
// Merge input ports
PortsEntityMerger.mergePorts(clientInputPorts, inputPorts);
// Merge output ports
PortsEntityMerger.mergePorts(clientOutputPorts, outputPorts);
// Merge labels
LabelsEntityMerger.mergeLabels(clientLabels, labels);
// Merge processors
ProcessorsEntityMerger.mergeProcessors(clientProcessors, processors);
// Merge Remote Process Groups
RemoteProcessGroupsEntityMerger.mergeRemoteProcessGroups(clientRemoteProcessGroups, rpgs);
// Merge Process Groups
ProcessGroupsEntityMerger.mergeProcessGroups(clientProcessGroups, processGroups);
}
use of org.apache.nifi.web.api.dto.flow.ProcessGroupFlowDTO in project kylo by Teradata.
the class TemplateConnectionUtil method getRemoteInputPortsForReusableTemplate.
public Optional<TemplateRemoteInputPortConnections> getRemoteInputPortsForReusableTemplate(ProcessGroupFlowDTO reusableTemplateProcessGroup, String templateName) {
String templateGroupId = reusableTemplateProcessGroup.getFlow().getProcessGroups().stream().filter(g -> g.getComponent().getName().equalsIgnoreCase(templateName)).map(g -> g.getId()).findFirst().orElse(null);
if (templateGroupId != null) {
String reusableTemplateProcessGroupId = reusableTemplateProcessGroup.getId();
String rootProcessGroupId = this.getRootProcessGroup().getId();
List<String> reusableTemplateInputPortIds = reusableTemplateProcessGroup.getFlow().getConnections().stream().filter(conn -> conn.getComponent().getDestination().getGroupId().equalsIgnoreCase(templateGroupId)).map(conn -> conn.getComponent().getSource().getId()).collect(Collectors.toList());
List<ConnectionDTO> remoteConnectionsToTemplate = getRootProcessGroupConnections().stream().filter(conn -> conn.getDestination().getType().equalsIgnoreCase(NifiConstants.INPUT_PORT) && conn.getDestination().getGroupId().equalsIgnoreCase(reusableTemplateProcessGroupId) && conn.getSource().getGroupId().equalsIgnoreCase(rootProcessGroupId) && conn.getSource().getType().equalsIgnoreCase(NifiConstants.INPUT_PORT) && reusableTemplateInputPortIds.contains(conn.getDestination().getId())).collect(Collectors.toList());
Set<String> remoteInputPorts = remoteConnectionsToTemplate.stream().map(conn -> conn.getSource().getName()).collect(Collectors.toSet());
return Optional.of(new TemplateRemoteInputPortConnections(remoteConnectionsToTemplate, remoteInputPorts));
}
return Optional.empty();
}
Aggregations