Search in sources :

Example 1 with RemoteProcessGroupCounts

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;
}
Also used : RemoteProcessGroupCounts(org.apache.nifi.groups.RemoteProcessGroupCounts) InstantiatedVersionedRemoteGroupPort(org.apache.nifi.registry.flow.mapping.InstantiatedVersionedRemoteGroupPort) RemoteGroupPort(org.apache.nifi.remote.RemoteGroupPort) InstantiatedVersionedRemoteGroupPort(org.apache.nifi.registry.flow.mapping.InstantiatedVersionedRemoteGroupPort) RemoteGroupPort(org.apache.nifi.remote.RemoteGroupPort) RootGroupPort(org.apache.nifi.remote.RootGroupPort) Port(org.apache.nifi.connectable.Port) InstantiatedVersionedPort(org.apache.nifi.registry.flow.mapping.InstantiatedVersionedPort) ArrayList(java.util.ArrayList) ValidationResult(org.apache.nifi.components.ValidationResult) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 2 with RemoteProcessGroupCounts

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);
    }
}
Also used : RemoteProcessGroupCounts(org.apache.nifi.groups.RemoteProcessGroupCounts) SiteToSiteRestApiClient(org.apache.nifi.remote.util.SiteToSiteRestApiClient) ControllerDTO(org.apache.nifi.web.api.dto.ControllerDTO) IOException(java.io.IOException) CommunicationsException(org.apache.nifi.controller.exception.CommunicationsException)

Aggregations

RemoteProcessGroupCounts (org.apache.nifi.groups.RemoteProcessGroupCounts)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 ValidationResult (org.apache.nifi.components.ValidationResult)1 Port (org.apache.nifi.connectable.Port)1 CommunicationsException (org.apache.nifi.controller.exception.CommunicationsException)1 InstantiatedVersionedPort (org.apache.nifi.registry.flow.mapping.InstantiatedVersionedPort)1 InstantiatedVersionedRemoteGroupPort (org.apache.nifi.registry.flow.mapping.InstantiatedVersionedRemoteGroupPort)1 RemoteGroupPort (org.apache.nifi.remote.RemoteGroupPort)1 RootGroupPort (org.apache.nifi.remote.RootGroupPort)1 SiteToSiteRestApiClient (org.apache.nifi.remote.util.SiteToSiteRestApiClient)1 ControllerDTO (org.apache.nifi.web.api.dto.ControllerDTO)1