|
43 | 43 | import org.apache.nifi.cluster.protocol.NodeIdentifier; |
44 | 44 | import org.apache.nifi.components.ConfigurableComponent; |
45 | 45 | import org.apache.nifi.components.RequiredPermission; |
| 46 | +import org.apache.nifi.components.listen.ListenComponent; |
46 | 47 | import org.apache.nifi.connectable.Connectable; |
47 | 48 | import org.apache.nifi.connectable.Connection; |
48 | 49 | import org.apache.nifi.connectable.Port; |
| 50 | +import org.apache.nifi.controller.ComponentNode; |
| 51 | +import org.apache.nifi.controller.ConfigurationContext; |
49 | 52 | import org.apache.nifi.controller.ContentAvailability; |
50 | 53 | import org.apache.nifi.controller.ControllerService; |
51 | 54 | import org.apache.nifi.controller.Counter; |
|
64 | 67 | import org.apache.nifi.controller.service.ControllerServiceNode; |
65 | 68 | import org.apache.nifi.controller.service.ControllerServiceProvider; |
66 | 69 | import org.apache.nifi.controller.service.ControllerServiceResolver; |
| 70 | +import org.apache.nifi.controller.service.StandardConfigurationContext; |
67 | 71 | import org.apache.nifi.controller.status.ConnectionStatus; |
68 | 72 | import org.apache.nifi.controller.status.PortStatus; |
69 | 73 | import org.apache.nifi.controller.status.ProcessGroupStatus; |
|
113 | 117 | import org.apache.nifi.web.api.dto.BundleDTO; |
114 | 118 | import org.apache.nifi.web.api.dto.DocumentedTypeDTO; |
115 | 119 | import org.apache.nifi.web.api.dto.DtoFactory; |
| 120 | +import org.apache.nifi.web.api.dto.ListenPortDTO; |
116 | 121 | import org.apache.nifi.web.api.dto.diagnostics.ProcessorDiagnosticsDTO; |
117 | 122 | import org.apache.nifi.web.api.dto.provenance.AttributeDTO; |
118 | 123 | import org.apache.nifi.web.api.dto.provenance.LatestProvenanceEventsDTO; |
|
143 | 148 | import java.util.ArrayList; |
144 | 149 | import java.util.Arrays; |
145 | 150 | import java.util.Collection; |
| 151 | +import java.util.Collections; |
146 | 152 | import java.util.Comparator; |
147 | 153 | import java.util.Date; |
148 | 154 | import java.util.HashMap; |
@@ -1853,6 +1859,60 @@ public SearchResultsDTO search(final String searchLiteral, final String activeGr |
1853 | 1859 | return results; |
1854 | 1860 | } |
1855 | 1861 |
|
| 1862 | + /** |
| 1863 | + * Get all user-defined data ingress ports provided by Listen Components (e.g., Processors and Controller Services) |
| 1864 | + * |
| 1865 | + * @param user the user performing the lookup |
| 1866 | + * @return the set of listen Ports accessible to the current user |
| 1867 | + */ |
| 1868 | + public Set<ListenPortDTO> getListenPorts(final NiFiUser user) { |
| 1869 | + |
| 1870 | + // Get all listen components for which the requesting user is authorized |
| 1871 | + final Set<ComponentNode> listenComponentNodes = flowController.getFlowManager().getAllListenComponents().stream() |
| 1872 | + .filter(componentNode -> componentNode.isAuthorized(authorizer, RequestAction.READ, user)) |
| 1873 | + .collect(Collectors.toSet()); |
| 1874 | + |
| 1875 | + // If the current user doesn't have access to any listen components, return an empty result for ports |
| 1876 | + if (listenComponentNodes.isEmpty()) { |
| 1877 | + return Collections.emptySet(); |
| 1878 | + } |
| 1879 | + |
| 1880 | + // Now find all Listen Ports provided by the Listen Components. A listen component can provide multiple Listen Ports (e.g., ListenHTTP can have a data port and a health check port). |
| 1881 | + // The current Listen Ports for a component depend on configuration (e.g., port property value), so create a configuration context to provide ListenComponent.getListenPorts(context). |
| 1882 | + final Set<ListenPortDTO> listenPorts = new HashSet<>(); |
| 1883 | + final ControllerServiceProvider controllerServiceProvider = flowController.getControllerServiceProvider(); |
| 1884 | + for (final ComponentNode componentNode : listenComponentNodes) { |
| 1885 | + final ConfigurationContext configurationContext = new StandardConfigurationContext(componentNode, controllerServiceProvider, null); |
| 1886 | + final ConfigurableComponent component = componentNode.getComponent(); |
| 1887 | + if (component instanceof ListenComponent listenComponent /* should always be true */) { |
| 1888 | + listenComponent.getListenPorts(configurationContext).forEach(listenPort -> { |
| 1889 | + final ListenPortDTO listenPortDTO = new ListenPortDTO(); |
| 1890 | + listenPortDTO.setPortNumber(listenPort.getPortNumber()); |
| 1891 | + listenPortDTO.setTransportProtocol(listenPort.getTransportProtocol().name()); |
| 1892 | + listenPortDTO.setApplicationProtocols(listenPort.getApplicationProtocols()); |
| 1893 | + listenPortDTO.setParentGroupId(componentNode.getParentProcessGroup().map(ProcessGroup::getIdentifier).orElse(null)); |
| 1894 | + listenPortDTO.setParentGroupName(componentNode.getParentProcessGroup().map(ProcessGroup::getName).orElse(null)); |
| 1895 | + listenPortDTO.setComponentId(componentNode.getIdentifier()); |
| 1896 | + listenPortDTO.setComponentName(componentNode.getName()); |
| 1897 | + listenPortDTO.setComponentClass(componentNode.getCanonicalClassName()); |
| 1898 | + // TODO this next bit could be refined |
| 1899 | + if (componentNode instanceof ProcessorNode) { |
| 1900 | + listenPortDTO.setComponentType("Processor"); |
| 1901 | + } else if (componentNode instanceof ControllerServiceNode) { |
| 1902 | + listenPortDTO.setComponentType("ControllerService"); |
| 1903 | + } else { |
| 1904 | + // Would we ever have anything other than a Processor or Controller Service providing a Listen Port? |
| 1905 | + logger.warn("Unexpected listen component type {}", componentNode.getClass().getCanonicalName()); |
| 1906 | + listenPortDTO.setComponentType(null); |
| 1907 | + } |
| 1908 | + listenPorts.add(listenPortDTO); |
| 1909 | + }); |
| 1910 | + } |
| 1911 | + } |
| 1912 | + |
| 1913 | + return listenPorts; |
| 1914 | + } |
| 1915 | + |
1856 | 1916 | public void verifyComponentTypes(VersionedProcessGroup versionedFlow) { |
1857 | 1917 | flowController.verifyComponentTypesInSnippet(versionedFlow); |
1858 | 1918 | } |
|
0 commit comments