use of org.apache.nifi.web.api.dto.PortDTO in project nifi by apache.
the class ControllerEndpointMerger method mergeResponses.
@Override
protected void mergeResponses(ControllerDTO clientDto, Map<NodeIdentifier, ControllerDTO> dtoMap, Set<NodeResponse> successfulResponses, Set<NodeResponse> problematicResponses) {
// map of port id to map of node id to port dto
final Map<String, Map<NodeIdentifier, PortDTO>> inputPortMap = new HashMap<>();
// map of port id to map of node id to port dto
final Map<String, Map<NodeIdentifier, PortDTO>> outputPortMap = new HashMap<>();
for (final Map.Entry<NodeIdentifier, ControllerDTO> entry : dtoMap.entrySet()) {
final NodeIdentifier nodeId = entry.getKey();
final ControllerDTO nodeController = entry.getValue();
// gather all input and output ports for merging, including the ports from clientDto
nodeController.getInputPorts().stream().forEach(inputPort -> inputPortMap.computeIfAbsent(inputPort.getId(), nodeIdToInputPort -> new HashMap<>()).put(nodeId, inputPort));
nodeController.getOutputPorts().stream().forEach(outputPort -> outputPortMap.computeIfAbsent(outputPort.getId(), nodeIdToOutputPort -> new HashMap<>()).put(nodeId, outputPort));
}
// merge input ports
for (Map<NodeIdentifier, PortDTO> inputPortByNodeId : inputPortMap.values()) {
final Collection<PortDTO> nodeInputPorts = inputPortByNodeId.values();
if (!nodeInputPorts.isEmpty()) {
final PortDTO inputPort = nodeInputPorts.iterator().next();
final PortDTO clientInputPort = clientDto.getInputPorts().stream().filter(p -> p.getId().equals(inputPort.getId())).findFirst().orElse(null);
if (clientInputPort != null) {
PortEntityMerger.mergeDtos(clientInputPort, inputPortByNodeId);
}
}
}
// merge output ports
for (Map<NodeIdentifier, PortDTO> outputPortByNodeId : outputPortMap.values()) {
final Collection<PortDTO> nodeOutputPorts = outputPortByNodeId.values();
if (!nodeOutputPorts.isEmpty()) {
final PortDTO outputPort = nodeOutputPorts.iterator().next();
final PortDTO clientOutputPort = clientDto.getInputPorts().stream().filter(p -> p.getId().equals(outputPort.getId())).findFirst().orElse(null);
if (clientOutputPort != null) {
PortEntityMerger.mergeDtos(clientOutputPort, outputPortByNodeId);
}
}
}
// get intersection of input and output ports
final Set<PortDTO> clientInputPorts = Sets.newHashSet(clientDto.getInputPorts());
final Set<PortDTO> clientOutputPorts = Sets.newHashSet(clientDto.getOutputPorts());
dtoMap.values().forEach(controller -> {
clientInputPorts.retainAll(controller.getInputPorts());
clientOutputPorts.retainAll(controller.getOutputPorts());
});
clientDto.setInputPorts(clientInputPorts);
clientDto.setInputPortCount(clientInputPorts.size());
clientDto.setOutputPorts(clientOutputPorts);
clientDto.setOutputPortCount(clientOutputPorts.size());
}
use of org.apache.nifi.web.api.dto.PortDTO in project nifi by apache.
the class FlowController method validateSnippetContents.
/**
* <p>
* Verifies that the given DTO is valid, according to the following:
*
* <ul>
* <li>None of the ID's in any component of the DTO can be used in this
* flow.</li>
* <li>The ProcessGroup to which the template's contents will be added must
* not contain any InputPort or OutputPort with the same name as one of the
* corresponding components in the root level of the template.</li>
* <li>All Processors' classes must exist in this instance.</li>
* <li>All Flow File Prioritizers' classes must exist in this instance.</li>
* </ul>
* </p>
*
* <p>
* If any of the above statements does not hold true, an
* {@link IllegalStateException} or a
* {@link ProcessorInstantiationException} will be thrown.
* </p>
*
* @param group group
* @param snippetContents contents
*/
private void validateSnippetContents(final ProcessGroup group, final FlowSnippetDTO snippetContents) {
// validate the names of Input Ports
for (final PortDTO port : snippetContents.getInputPorts()) {
if (group.getInputPortByName(port.getName()) != null) {
throw new IllegalStateException("One or more of the proposed Port names is not available in the process group");
}
}
// validate the names of Output Ports
for (final PortDTO port : snippetContents.getOutputPorts()) {
if (group.getOutputPortByName(port.getName()) != null) {
throw new IllegalStateException("One or more of the proposed Port names is not available in the process group");
}
}
verifyComponentTypesInSnippet(snippetContents);
SnippetUtils.verifyNoVersionControlConflicts(snippetContents, group);
}
use of org.apache.nifi.web.api.dto.PortDTO in project nifi by apache.
the class TestSiteInfoProvider method testSecure.
@Test
public void testSecure() throws Exception {
final Set<String> expectedClusterUrl = new LinkedHashSet<>(Arrays.asList(new String[] { "https://node1:8443", "https://node2:8443" }));
final String expectedActiveClusterUrl = "https://node2:8443/nifi-api";
final SSLContext expectedSslConText = mock(SSLContext.class);
final HttpProxy expectedHttpProxy = mock(HttpProxy.class);
final SiteInfoProvider siteInfoProvider = spy(new SiteInfoProvider());
siteInfoProvider.setClusterUrls(expectedClusterUrl);
siteInfoProvider.setSslContext(expectedSslConText);
siteInfoProvider.setProxy(expectedHttpProxy);
final ControllerDTO controllerDTO = new ControllerDTO();
final PortDTO inputPort1 = new PortDTO();
inputPort1.setName("input-one");
inputPort1.setId("input-0001");
final PortDTO inputPort2 = new PortDTO();
inputPort2.setName("input-two");
inputPort2.setId("input-0002");
final PortDTO outputPort1 = new PortDTO();
outputPort1.setName("output-one");
outputPort1.setId("output-0001");
final PortDTO outputPort2 = new PortDTO();
outputPort2.setName("output-two");
outputPort2.setId("output-0002");
final Set<PortDTO> inputPorts = new HashSet<>();
inputPorts.add(inputPort1);
inputPorts.add(inputPort2);
final Set<PortDTO> outputPorts = new HashSet<>();
outputPorts.add(outputPort1);
outputPorts.add(outputPort2);
controllerDTO.setInputPorts(inputPorts);
controllerDTO.setOutputPorts(outputPorts);
controllerDTO.setRemoteSiteListeningPort(8081);
controllerDTO.setRemoteSiteHttpListeningPort(8443);
controllerDTO.setSiteToSiteSecure(true);
// SiteInfoProvider uses SiteToSIteRestApiClient to get ControllerDTO.
doAnswer(invocation -> {
final SSLContext sslContext = invocation.getArgumentAt(0, SSLContext.class);
final HttpProxy httpProxy = invocation.getArgumentAt(1, HttpProxy.class);
assertEquals(expectedSslConText, sslContext);
assertEquals(expectedHttpProxy, httpProxy);
final SiteToSiteRestApiClient apiClient = mock(SiteToSiteRestApiClient.class);
when(apiClient.getController(eq(expectedClusterUrl))).thenReturn(controllerDTO);
when(apiClient.getBaseUrl()).thenReturn(expectedActiveClusterUrl);
return apiClient;
}).when(siteInfoProvider).createSiteToSiteRestApiClient(any(), any());
// siteInfoProvider should expose correct information of the remote NiFi cluster.
assertEquals(controllerDTO.getRemoteSiteListeningPort(), siteInfoProvider.getSiteToSitePort());
assertEquals(controllerDTO.getRemoteSiteHttpListeningPort(), siteInfoProvider.getSiteToSiteHttpPort());
assertEquals(controllerDTO.isSiteToSiteSecure(), siteInfoProvider.isSecure());
assertTrue(siteInfoProvider.isWebInterfaceSecure());
assertEquals(inputPort1.getId(), siteInfoProvider.getInputPortIdentifier(inputPort1.getName()));
assertEquals(inputPort2.getId(), siteInfoProvider.getInputPortIdentifier(inputPort2.getName()));
assertEquals(outputPort1.getId(), siteInfoProvider.getOutputPortIdentifier(outputPort1.getName()));
assertEquals(outputPort2.getId(), siteInfoProvider.getOutputPortIdentifier(outputPort2.getName()));
assertNull(siteInfoProvider.getInputPortIdentifier("not-exist"));
assertNull(siteInfoProvider.getOutputPortIdentifier("not-exist"));
assertEquals(inputPort1.getId(), siteInfoProvider.getPortIdentifier(inputPort1.getName(), TransferDirection.SEND));
assertEquals(outputPort1.getId(), siteInfoProvider.getPortIdentifier(outputPort1.getName(), TransferDirection.RECEIVE));
assertEquals(expectedActiveClusterUrl, siteInfoProvider.getActiveClusterUrl().toString());
}
use of org.apache.nifi.web.api.dto.PortDTO in project nifi by apache.
the class SiteInfoProvider method refreshRemoteInfo.
private ControllerDTO refreshRemoteInfo() throws IOException {
final ControllerDTO controller;
final URI connectedClusterUrl;
try (final SiteToSiteRestApiClient apiClient = createSiteToSiteRestApiClient(sslContext, proxy)) {
controller = apiClient.getController(clusterUrls);
try {
connectedClusterUrl = new URI(apiClient.getBaseUrl());
} catch (URISyntaxException e) {
// This should not happen since apiClient has successfully communicated with this URL.
throw new RuntimeException("Failed to parse connected cluster URL due to " + e);
}
}
remoteInfoWriteLock.lock();
try {
this.siteToSitePort = controller.getRemoteSiteListeningPort();
this.siteToSiteHttpPort = controller.getRemoteSiteHttpListeningPort();
this.siteToSiteSecure = controller.isSiteToSiteSecure();
this.activeClusterUrl = connectedClusterUrl;
inputPortMap.clear();
for (final PortDTO inputPort : controller.getInputPorts()) {
inputPortMap.put(inputPort.getName(), inputPort.getId());
}
outputPortMap.clear();
for (final PortDTO outputPort : controller.getOutputPorts()) {
outputPortMap.put(outputPort.getName(), outputPort.getId());
}
this.remoteRefreshTime = System.currentTimeMillis();
} finally {
remoteInfoWriteLock.unlock();
}
return controller;
}
use of org.apache.nifi.web.api.dto.PortDTO in project nifi by apache.
the class InputPortResource method updateInputPort.
/**
* Updates the specified input port.
*
* @param httpServletRequest request
* @param id The id of the input port to update.
* @param requestPortEntity A inputPortEntity.
* @return A inputPortEntity.
*/
@PUT
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("{id}")
@ApiOperation(value = "Updates an input port", response = PortEntity.class, authorizations = { @Authorization(value = "Write - /input-ports/{uuid}") })
@ApiResponses(value = { @ApiResponse(code = 400, message = "NiFi was unable to complete the request because it was invalid. The request should not be retried without modification."), @ApiResponse(code = 401, message = "Client could not be authenticated."), @ApiResponse(code = 403, message = "Client is not authorized to make this request."), @ApiResponse(code = 404, message = "The specified resource could not be found."), @ApiResponse(code = 409, message = "The request was valid but NiFi was not in the appropriate state to process it. Retrying the same request later may be successful.") })
public Response updateInputPort(@Context HttpServletRequest httpServletRequest, @ApiParam(value = "The input port id.", required = true) @PathParam("id") final String id, @ApiParam(value = "The input port configuration details.", required = true) final PortEntity requestPortEntity) {
if (requestPortEntity == null || requestPortEntity.getComponent() == null) {
throw new IllegalArgumentException("Input port details must be specified.");
}
if (requestPortEntity.getRevision() == null) {
throw new IllegalArgumentException("Revision must be specified.");
}
// ensure the ids are the same
final PortDTO requestPortDTO = requestPortEntity.getComponent();
if (!id.equals(requestPortDTO.getId())) {
throw new IllegalArgumentException(String.format("The input port id (%s) in the request body does not equal the " + "input port id of the requested resource (%s).", requestPortDTO.getId(), id));
}
final PositionDTO proposedPosition = requestPortDTO.getPosition();
if (proposedPosition != null) {
if (proposedPosition.getX() == null || proposedPosition.getY() == null) {
throw new IllegalArgumentException("The x and y coordinate of the proposed position must be specified.");
}
}
if (isReplicateRequest()) {
return replicate(HttpMethod.PUT, requestPortEntity);
}
// handle expects request (usually from the cluster manager)
final Revision requestRevision = getRevision(requestPortEntity, id);
return withWriteLock(serviceFacade, requestPortEntity, requestRevision, lookup -> {
Authorizable authorizable = lookup.getInputPort(id);
authorizable.authorize(authorizer, RequestAction.WRITE, NiFiUserUtils.getNiFiUser());
}, () -> serviceFacade.verifyUpdateInputPort(requestPortDTO), (revision, portEntity) -> {
final PortDTO portDTO = portEntity.getComponent();
// update the input port
final PortEntity entity = serviceFacade.updateInputPort(revision, portDTO);
populateRemainingInputPortEntityContent(entity);
return generateOkResponse(entity).build();
});
}
Aggregations