use of org.apache.nifi.web.api.entity.ProcessGroupEntity 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.entity.ProcessGroupEntity in project nifi by apache.
the class ProcessGroupsEndpointMerger method merge.
@Override
public final NodeResponse merge(final URI uri, final String method, final Set<NodeResponse> successfulResponses, final Set<NodeResponse> problematicResponses, final NodeResponse clientResponse) {
if (!canHandle(uri, method)) {
throw new IllegalArgumentException("Cannot use Endpoint Mapper of type " + getClass().getSimpleName() + " to map responses for URI " + uri + ", HTTP Method " + method);
}
final ProcessGroupsEntity responseEntity = clientResponse.getClientResponse().readEntity(ProcessGroupsEntity.class);
final Set<ProcessGroupEntity> processGroupEntities = responseEntity.getProcessGroups();
final Map<String, Map<NodeIdentifier, ProcessGroupEntity>> entityMap = new HashMap<>();
for (final NodeResponse nodeResponse : successfulResponses) {
final ProcessGroupsEntity nodeResponseEntity = nodeResponse == clientResponse ? responseEntity : nodeResponse.getClientResponse().readEntity(ProcessGroupsEntity.class);
final Set<ProcessGroupEntity> nodeProcessGroupEntities = nodeResponseEntity.getProcessGroups();
for (final ProcessGroupEntity nodeProcessGroupEntity : nodeProcessGroupEntities) {
final NodeIdentifier nodeId = nodeResponse.getNodeId();
Map<NodeIdentifier, ProcessGroupEntity> innerMap = entityMap.get(nodeId);
if (innerMap == null) {
innerMap = new HashMap<>();
entityMap.put(nodeProcessGroupEntity.getId(), innerMap);
}
innerMap.put(nodeResponse.getNodeId(), nodeProcessGroupEntity);
}
}
ProcessGroupsEntityMerger.mergeProcessGroups(processGroupEntities, entityMap);
// create a new client response
return new NodeResponse(clientResponse, responseEntity);
}
use of org.apache.nifi.web.api.entity.ProcessGroupEntity in project kylo by Teradata.
the class NiFiProcessGroupsRestClientV1 method create.
public ProcessGroupDTO create(@Nonnull String parentProcessGroupId, @Nonnull String name, @Nullable Double x, @Nullable Double y) {
final ProcessGroupEntity entity = new ProcessGroupEntity();
final ProcessGroupDTO processGroup = new ProcessGroupDTO();
processGroup.setName(name);
if (x != null && y != null) {
processGroup.setPosition(new PositionDTO(x, y));
}
entity.setComponent(processGroup);
final RevisionDTO revision = new RevisionDTO();
revision.setVersion(0L);
entity.setRevision(revision);
try {
return getClient().post(BASE_PATH + parentProcessGroupId + "/process-groups", entity, ProcessGroupEntity.class).getComponent();
} catch (final NotFoundException e) {
throw new NifiComponentNotFoundException(parentProcessGroupId, NifiConstants.NIFI_COMPONENT_TYPE.PROCESS_GROUP, e);
}
}
use of org.apache.nifi.web.api.entity.ProcessGroupEntity in project kylo by Teradata.
the class NiFiProcessGroupsRestClientV1 method toFlowSnippet.
/**
* Converts the specified flow to a flow snippet.
*
* @param flow the flow
* @return the flow snippet
*/
@Nonnull
private FlowSnippetDTO toFlowSnippet(@Nonnull final FlowDTO flow, boolean recursive) {
final FlowSnippetDTO snippet = new FlowSnippetDTO();
snippet.setConnections(flow.getConnections().stream().map(ConnectionEntity::getComponent).collect(Collectors.toSet()));
snippet.setControllerServices(Collections.emptySet());
snippet.setFunnels(flow.getFunnels().stream().map(FunnelEntity::getComponent).collect(Collectors.toSet()));
snippet.setInputPorts(flow.getInputPorts().stream().map(PortEntity::getComponent).collect(Collectors.toSet()));
snippet.setLabels(flow.getLabels().stream().map(LabelEntity::getComponent).collect(Collectors.toSet()));
snippet.setOutputPorts(flow.getOutputPorts().stream().map(PortEntity::getComponent).collect(Collectors.toSet()));
snippet.setProcessGroups(flow.getProcessGroups().stream().map(ProcessGroupEntity::getComponent).collect(Collectors.toSet()));
snippet.setProcessors(flow.getProcessors().stream().map(ProcessorEntity::getComponent).collect(Collectors.toSet()));
snippet.setRemoteProcessGroups(flow.getRemoteProcessGroups().stream().map(RemoteProcessGroupEntity::getComponent).collect(Collectors.toSet()));
// Add flow for child process groups
if (recursive) {
for (final ProcessGroupDTO processGroup : snippet.getProcessGroups()) {
processGroup.setContents(getFlowSnippet(processGroup.getId(), true));
}
}
return snippet;
}
use of org.apache.nifi.web.api.entity.ProcessGroupEntity in project nifi by apache.
the class StandardNiFiServiceFacade method updateProcessGroup.
@Override
public ProcessGroupEntity updateProcessGroup(final Revision revision, final ProcessGroupDTO processGroupDTO) {
final ProcessGroup processGroupNode = processGroupDAO.getProcessGroup(processGroupDTO.getId());
final RevisionUpdate<ProcessGroupDTO> snapshot = updateComponent(revision, processGroupNode, () -> processGroupDAO.updateProcessGroup(processGroupDTO), processGroup -> dtoFactory.createProcessGroupDto(processGroup));
final PermissionsDTO permissions = dtoFactory.createPermissionsDto(processGroupNode);
final RevisionDTO updatedRevision = dtoFactory.createRevisionDTO(snapshot.getLastModification());
final ProcessGroupStatusDTO status = dtoFactory.createConciseProcessGroupStatusDto(controllerFacade.getProcessGroupStatus(processGroupNode.getIdentifier()));
final List<BulletinDTO> bulletins = dtoFactory.createBulletinDtos(bulletinRepository.findBulletinsForSource(processGroupNode.getIdentifier()));
final List<BulletinEntity> bulletinEntities = bulletins.stream().map(bulletin -> entityFactory.createBulletinEntity(bulletin, permissions.getCanRead())).collect(Collectors.toList());
return entityFactory.createProcessGroupEntity(snapshot.getComponent(), updatedRevision, permissions, status, bulletinEntities);
}
Aggregations