use of org.apache.nifi.web.api.dto.RemoteProcessGroupPortDTO in project nifi by apache.
the class FlowController method convertRemotePort.
/**
* Converts a set of ports into a set of remote process group ports.
*
* @param ports ports
* @return group descriptors
*/
private Set<RemoteProcessGroupPortDescriptor> convertRemotePort(final Set<RemoteProcessGroupPortDTO> ports) {
Set<RemoteProcessGroupPortDescriptor> remotePorts = null;
if (ports != null) {
remotePorts = new LinkedHashSet<>(ports.size());
for (final RemoteProcessGroupPortDTO port : ports) {
final StandardRemoteProcessGroupPortDescriptor descriptor = new StandardRemoteProcessGroupPortDescriptor();
descriptor.setId(port.getId());
descriptor.setVersionedComponentId(port.getVersionedComponentId());
descriptor.setTargetId(port.getTargetId());
descriptor.setName(port.getName());
descriptor.setComments(port.getComments());
descriptor.setTargetRunning(port.isTargetRunning());
descriptor.setConnected(port.isConnected());
descriptor.setConcurrentlySchedulableTaskCount(port.getConcurrentlySchedulableTaskCount());
descriptor.setTransmitting(port.isTransmitting());
descriptor.setUseCompression(port.getUseCompression());
final BatchSettingsDTO batchSettings = port.getBatchSettings();
if (batchSettings != null) {
descriptor.setBatchCount(batchSettings.getCount());
descriptor.setBatchSize(batchSettings.getSize());
descriptor.setBatchDuration(batchSettings.getDuration());
}
remotePorts.add(descriptor);
}
}
return remotePorts;
}
use of org.apache.nifi.web.api.dto.RemoteProcessGroupPortDTO in project nifi-minifi by apache.
the class RemoteInputPortSchemaTest method setup.
@Before
public void setup() {
dto = new RemoteProcessGroupPortDTO();
dto.setId(testId);
dto.setName(testName);
dto.setComments(testComment);
dto.setConcurrentlySchedulableTaskCount(testMaxConcurrentTasks);
dto.setUseCompression(testUseCompression);
map = new HashMap<>();
map.put(CommonPropertyKeys.ID_KEY, testId);
map.put(CommonPropertyKeys.NAME_KEY, testName);
map.put(CommonPropertyKeys.COMMENT_KEY, testComment);
map.put(CommonPropertyKeys.MAX_CONCURRENT_TASKS_KEY, testMaxConcurrentTasks);
map.put(CommonPropertyKeys.USE_COMPRESSION_KEY, testUseCompression);
}
use of org.apache.nifi.web.api.dto.RemoteProcessGroupPortDTO in project nifi-minifi by apache.
the class FlowSnippetDTOEnricher method enrich.
public void enrich(FlowSnippetDTO flowSnippetDTO, final String encodingVersion) {
List<FlowSnippetDTO> allFlowSnippets = getAllFlowSnippets(flowSnippetDTO);
Set<RemoteProcessGroupDTO> remoteProcessGroups = getAll(allFlowSnippets, FlowSnippetDTO::getRemoteProcessGroups).collect(Collectors.toSet());
Map<String, String> connectableNameMap = getAll(allFlowSnippets, FlowSnippetDTO::getProcessors).collect(Collectors.toMap(ComponentDTO::getId, ProcessorDTO::getName));
Map<String, String> rpgIdToTargetIdMap = new HashMap<>();
for (RemoteProcessGroupDTO remoteProcessGroupDTO : remoteProcessGroups) {
final RemoteProcessGroupContentsDTO contents = remoteProcessGroupDTO.getContents();
final Set<RemoteProcessGroupPortDTO> rpgInputPortDtos = nullToEmpty(contents.getInputPorts());
final Set<RemoteProcessGroupPortDTO> rpgOutputPortDtos = nullToEmpty(contents.getOutputPorts());
switch(encodingVersion) {
case "1.2":
// Map all port DTOs to their respective targetIds
rpgIdToTargetIdMap.putAll(Stream.concat(rpgInputPortDtos.stream(), rpgOutputPortDtos.stream()).collect(Collectors.toMap(RemoteProcessGroupPortDTO::getId, RemoteProcessGroupPortDTO::getTargetId)));
break;
default:
break;
}
addConnectables(connectableNameMap, rpgInputPortDtos, RemoteProcessGroupPortDTO::getId, RemoteProcessGroupPortDTO::getId);
addConnectables(connectableNameMap, rpgOutputPortDtos, RemoteProcessGroupPortDTO::getId, RemoteProcessGroupPortDTO::getId);
}
addConnectables(connectableNameMap, getAll(allFlowSnippets, FlowSnippetDTO::getInputPorts).collect(Collectors.toList()), PortDTO::getId, PortDTO::getName);
addConnectables(connectableNameMap, getAll(allFlowSnippets, FlowSnippetDTO::getOutputPorts).collect(Collectors.toList()), PortDTO::getId, PortDTO::getName);
final Set<ConnectionDTO> connections = getAll(allFlowSnippets, FlowSnippetDTO::getConnections).collect(Collectors.toSet());
// Enrich connection endpoints using known names and overriding with targetIds for remote ports
for (ConnectionDTO connection : connections) {
setName(connectableNameMap, connection.getSource(), rpgIdToTargetIdMap);
setName(connectableNameMap, connection.getDestination(), rpgIdToTargetIdMap);
}
// Override any ids that are for Remote Ports to use their target Ids where available
connections.stream().flatMap(connectionDTO -> Stream.of(connectionDTO.getSource(), connectionDTO.getDestination())).filter(connectable -> connectable.getType().equals(ConnectableType.REMOTE_OUTPUT_PORT.toString()) || connectable.getType().equals(ConnectableType.REMOTE_INPUT_PORT.toString())).forEach(connectable -> connectable.setId(Optional.ofNullable(rpgIdToTargetIdMap.get(connectable.getId())).orElse(connectable.getId())));
// Establish unique names for connections
for (ConnectionDTO connection : connections) {
if (StringUtil.isNullOrEmpty(connection.getName())) {
StringBuilder name = new StringBuilder();
ConnectableDTO connectionSource = connection.getSource();
name.append(determineValueForConnectable(connectionSource, rpgIdToTargetIdMap));
name.append("/");
if (connection.getSelectedRelationships() != null && connection.getSelectedRelationships().size() > 0) {
name.append(connection.getSelectedRelationships().iterator().next());
}
name.append("/");
ConnectableDTO connectionDestination = connection.getDestination();
name.append(determineValueForConnectable(connectionDestination, rpgIdToTargetIdMap));
connection.setName(name.toString());
}
}
nullToEmpty(flowSnippetDTO.getProcessGroups()).stream().map(ProcessGroupDTO::getContents).forEach(snippetDTO -> enrich(snippetDTO, encodingVersion));
}
use of org.apache.nifi.web.api.dto.RemoteProcessGroupPortDTO in project nifi-minifi by apache.
the class RemoteProcessGroupSchemaFunction method apply.
@Override
public RemoteProcessGroupSchema apply(RemoteProcessGroupDTO remoteProcessGroupDTO) {
Map<String, Object> map = new HashMap<>();
map.put(CommonPropertyKeys.ID_KEY, remoteProcessGroupDTO.getId());
map.put(CommonPropertyKeys.NAME_KEY, remoteProcessGroupDTO.getName());
map.put(RemoteProcessGroupSchema.URL_KEY, remoteProcessGroupDTO.getTargetUri());
RemoteProcessGroupContentsDTO contents = remoteProcessGroupDTO.getContents();
if (contents != null) {
Set<RemoteProcessGroupPortDTO> inputPorts = contents.getInputPorts();
if (inputPorts != null) {
map.put(CommonPropertyKeys.INPUT_PORTS_KEY, inputPorts.stream().map(remotePortSchemaFunction).map(RemotePortSchema::toMap).collect(Collectors.toList()));
}
Set<RemoteProcessGroupPortDTO> outputPorts = contents.getOutputPorts();
if (outputPorts != null) {
map.put(CommonPropertyKeys.OUTPUT_PORTS_KEY, outputPorts.stream().map(remotePortSchemaFunction).map(RemotePortSchema::toMap).collect(Collectors.toList()));
}
}
map.put(CommonPropertyKeys.COMMENT_KEY, remoteProcessGroupDTO.getComments());
map.put(RemoteProcessGroupSchema.TIMEOUT_KEY, remoteProcessGroupDTO.getCommunicationsTimeout());
map.put(CommonPropertyKeys.YIELD_PERIOD_KEY, remoteProcessGroupDTO.getYieldDuration());
map.put(RemoteProcessGroupSchema.TRANSPORT_PROTOCOL_KEY, remoteProcessGroupDTO.getTransportProtocol());
map.put(RemoteProcessGroupSchema.PROXY_HOST_KEY, remoteProcessGroupDTO.getProxyHost());
map.put(RemoteProcessGroupSchema.PROXY_PORT_KEY, remoteProcessGroupDTO.getProxyPort());
map.put(RemoteProcessGroupSchema.PROXY_USER_KEY, remoteProcessGroupDTO.getProxyUser());
map.put(RemoteProcessGroupSchema.PROXY_PASSWORD_KEY, remoteProcessGroupDTO.getProxyPassword());
map.put(RemoteProcessGroupSchema.LOCAL_NETWORK_INTERFACE_KEY, remoteProcessGroupDTO.getLocalNetworkInterface());
return new RemoteProcessGroupSchema(map);
}
use of org.apache.nifi.web.api.dto.RemoteProcessGroupPortDTO in project nifi by apache.
the class RemoteProcessGroupEntityMerger method mergeDtos.
private static void mergeDtos(final RemoteProcessGroupDTO clientDto, final Map<NodeIdentifier, RemoteProcessGroupDTO> dtoMap) {
// if unauthorized for the client dto, simple return
if (clientDto == null) {
return;
}
final RemoteProcessGroupContentsDTO remoteProcessGroupContents = clientDto.getContents();
final Map<String, Set<NodeIdentifier>> authorizationErrorMap = new HashMap<>();
final Map<String, Set<NodeIdentifier>> validationErrorMap = new HashMap<>();
Boolean mergedIsTargetSecure = null;
Set<RemoteProcessGroupPortDTO> mergedInputPorts = null;
Set<RemoteProcessGroupPortDTO> mergedOutputPorts = null;
for (final Map.Entry<NodeIdentifier, RemoteProcessGroupDTO> nodeEntry : dtoMap.entrySet()) {
final RemoteProcessGroupDTO nodeRemoteProcessGroup = nodeEntry.getValue();
// consider the node remote process group when authorized
if (nodeRemoteProcessGroup != null) {
final NodeIdentifier nodeId = nodeEntry.getKey();
// merge the authorization errors
ErrorMerger.mergeErrors(authorizationErrorMap, nodeId, nodeRemoteProcessGroup.getAuthorizationIssues());
ErrorMerger.mergeErrors(validationErrorMap, nodeId, nodeRemoteProcessGroup.getValidationErrors());
// use the first target secure flag since they will all be the same
final Boolean nodeIsTargetSecure = nodeRemoteProcessGroup.isTargetSecure();
if (mergedIsTargetSecure == null) {
mergedIsTargetSecure = nodeIsTargetSecure;
}
// merge the ports in the contents
final RemoteProcessGroupContentsDTO nodeRemoteProcessGroupContentsDto = nodeRemoteProcessGroup.getContents();
if (remoteProcessGroupContents != null && nodeRemoteProcessGroupContentsDto != null) {
final Set<RemoteProcessGroupPortDTO> nodeInputPorts = nodeRemoteProcessGroupContentsDto.getInputPorts();
if (nodeInputPorts != null) {
if (mergedInputPorts == null) {
mergedInputPorts = new HashSet<>(nodeInputPorts);
} else {
mergedInputPorts.retainAll(nodeInputPorts);
}
}
final Set<RemoteProcessGroupPortDTO> nodeOutputPorts = nodeRemoteProcessGroupContentsDto.getOutputPorts();
if (nodeOutputPorts != null) {
if (mergedOutputPorts == null) {
mergedOutputPorts = new HashSet<>(nodeOutputPorts);
} else {
mergedOutputPorts.retainAll(nodeOutputPorts);
}
}
}
}
}
if (remoteProcessGroupContents != null) {
if (mergedInputPorts != null && !mergedInputPorts.isEmpty()) {
remoteProcessGroupContents.setInputPorts(mergedInputPorts);
}
if (mergedOutputPorts != null && !mergedOutputPorts.isEmpty()) {
remoteProcessGroupContents.setOutputPorts(mergedOutputPorts);
}
}
if (mergedIsTargetSecure != null) {
clientDto.setTargetSecure(mergedIsTargetSecure);
}
// set the merged the validation errors
clientDto.setAuthorizationIssues(ErrorMerger.normalizedMergedErrors(authorizationErrorMap, dtoMap.size()));
clientDto.setValidationErrors(ErrorMerger.normalizedMergedErrors(validationErrorMap, dtoMap.size()));
}
Aggregations