use of org.apache.nifi.groups.RemoteProcessGroupCounts in project nifi by apache.
the class DtoFactory method createRemoteProcessGroupDto.
/**
* Creates a RemoteProcessGroupDTO from the specified RemoteProcessGroup.
*
* @param group group
* @return dto
*/
public RemoteProcessGroupDTO createRemoteProcessGroupDto(final RemoteProcessGroup group) {
if (group == null) {
return null;
}
final Set<RemoteProcessGroupPortDTO> inputPorts = new HashSet<>();
final Set<RemoteProcessGroupPortDTO> outputPorts = new HashSet<>();
int activeRemoteInputPortCount = 0;
int inactiveRemoteInputPortCount = 0;
for (final Port port : group.getInputPorts()) {
inputPorts.add(createRemoteProcessGroupPortDto((RemoteGroupPort) port));
if (port.hasIncomingConnection()) {
if (port.isRunning()) {
activeRemoteInputPortCount++;
} else {
inactiveRemoteInputPortCount++;
}
}
}
int activeRemoteOutputPortCount = 0;
int inactiveRemoteOutputPortCount = 0;
for (final Port port : group.getOutputPorts()) {
outputPorts.add(createRemoteProcessGroupPortDto((RemoteGroupPort) port));
if (!port.getConnections().isEmpty()) {
if (port.isRunning()) {
activeRemoteOutputPortCount++;
} else {
inactiveRemoteOutputPortCount++;
}
}
}
final RemoteProcessGroupContentsDTO contents = new RemoteProcessGroupContentsDTO();
contents.setInputPorts(inputPorts);
contents.setOutputPorts(outputPorts);
final RemoteProcessGroupDTO dto = new RemoteProcessGroupDTO();
dto.setId(group.getIdentifier());
dto.setName(group.getName());
dto.setPosition(createPositionDto(group.getPosition()));
dto.setComments(group.getComments());
dto.setTransmitting(group.isTransmitting());
dto.setCommunicationsTimeout(group.getCommunicationsTimeout());
dto.setYieldDuration(group.getYieldDuration());
dto.setParentGroupId(group.getProcessGroup().getIdentifier());
dto.setTargetUris(group.getTargetUris());
dto.setFlowRefreshed(group.getLastRefreshTime());
dto.setContents(contents);
dto.setTransportProtocol(group.getTransportProtocol().name());
dto.setProxyHost(group.getProxyHost());
dto.setProxyPort(group.getProxyPort());
dto.setProxyUser(group.getProxyUser());
if (!StringUtils.isEmpty(group.getProxyPassword())) {
dto.setProxyPassword(SENSITIVE_VALUE_MASK);
}
// only specify the secure flag if we know the target system has site to site enabled
if (group.isSiteToSiteEnabled()) {
dto.setTargetSecure(group.getSecureFlag());
}
if (group.getAuthorizationIssue() != null) {
dto.setAuthorizationIssues(Arrays.asList(group.getAuthorizationIssue()));
}
final Collection<ValidationResult> validationErrors = group.validate();
if (validationErrors != null && !validationErrors.isEmpty()) {
final List<String> errors = new ArrayList<>();
for (final ValidationResult validationResult : validationErrors) {
errors.add(validationResult.toString());
}
dto.setValidationErrors(errors);
}
dto.setLocalNetworkInterface(group.getNetworkInterface());
dto.setActiveRemoteInputPortCount(activeRemoteInputPortCount);
dto.setInactiveRemoteInputPortCount(inactiveRemoteInputPortCount);
dto.setActiveRemoteOutputPortCount(activeRemoteOutputPortCount);
dto.setInactiveRemoteOutputPortCount(inactiveRemoteOutputPortCount);
dto.setVersionedComponentId(group.getVersionedComponentId().orElse(null));
final RemoteProcessGroupCounts counts = group.getCounts();
if (counts != null) {
dto.setInputPortCount(counts.getInputPortCount());
dto.setOutputPortCount(counts.getOutputPortCount());
}
return dto;
}
use of org.apache.nifi.groups.RemoteProcessGroupCounts in project nifi by apache.
the class StandardRemoteProcessGroup method refreshFlowContents.
@Override
public void refreshFlowContents() throws CommunicationsException {
if (!initialized) {
return;
}
try {
// perform the request
final ControllerDTO dto;
try (final SiteToSiteRestApiClient apiClient = getSiteToSiteRestApiClient()) {
dto = apiClient.getController(targetUris);
} catch (IOException e) {
throw new CommunicationsException("Unable to communicate with Remote NiFi at URI " + targetUris + " due to: " + e.getMessage());
}
writeLock.lock();
try {
if (dto.getInputPorts() != null) {
setInputPorts(convertRemotePort(dto.getInputPorts()), true);
}
if (dto.getOutputPorts() != null) {
setOutputPorts(convertRemotePort(dto.getOutputPorts()), true);
}
// set the controller details
setTargetId(dto.getId());
setName(dto.getName());
setComments(dto.getComments());
// get the component counts
int inputPortCount = 0;
if (dto.getInputPortCount() != null) {
inputPortCount = dto.getInputPortCount();
}
int outputPortCount = 0;
if (dto.getOutputPortCount() != null) {
outputPortCount = dto.getOutputPortCount();
}
this.listeningPort = dto.getRemoteSiteListeningPort();
this.listeningHttpPort = dto.getRemoteSiteHttpListeningPort();
this.destinationSecure = dto.isSiteToSiteSecure();
final RemoteProcessGroupCounts newCounts = new RemoteProcessGroupCounts(inputPortCount, outputPortCount);
setCounts(newCounts);
this.refreshContentsTimestamp = System.currentTimeMillis();
} finally {
writeLock.unlock();
}
} catch (final IOException e) {
throw new CommunicationsException(e);
}
}
Aggregations