org.apache.nifi.web.api.dto.ConnectionDTO Java Examples
The following examples show how to use
org.apache.nifi.web.api.dto.ConnectionDTO.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RelationshipAuditor.java From localization_nifi with Apache License 2.0 | 6 votes |
/** * Extracts configured settings from the specified connection only if they have also been specified in the connectionDTO. * * @param connection connection * @param connectionDTO dto * @return properties */ private Map<String, String> extractConfiguredPropertyValues(Connection connection, ConnectionDTO connectionDTO) { Map<String, String> values = new HashMap<>(); if (connectionDTO.getName() != null) { values.put(NAME, connection.getName()); } if (connectionDTO.getFlowFileExpiration() != null) { values.put(FLOW_FILE_EXPIRATION, String.valueOf(connection.getFlowFileQueue().getFlowFileExpiration())); } if (connectionDTO.getBackPressureObjectThreshold() != null) { values.put(BACK_PRESSURE_OBJECT_THRESHOLD, String.valueOf(connection.getFlowFileQueue().getBackPressureObjectThreshold())); } if (connectionDTO.getBackPressureDataSizeThreshold() != null) { values.put(BACK_PRESSURE_DATA_SIZE_THRESHOLD, String.valueOf(connection.getFlowFileQueue().getBackPressureDataSizeThreshold())); } if (connectionDTO.getPrioritizers() != null) { List<String> prioritizers = new ArrayList<>(); for (FlowFilePrioritizer prioritizer : connection.getFlowFileQueue().getPriorities()) { prioritizers.add(prioritizer.getClass().getCanonicalName()); } values.put(PRIORITIZERS, StringUtils.join(prioritizers, ", ")); } return values; }
Example #2
Source File: NiFiClientUtil.java From nifi with Apache License 2.0 | 6 votes |
public ConnectionEntity createConnection(final ConnectableDTO source, final ConnectableDTO destination, final Set<String> relationships) throws NiFiClientException, IOException { final String groupId = "OUTPUT_PORT".equals(source.getType()) ? destination.getGroupId() : source.getGroupId(); final ConnectionDTO connectionDto = new ConnectionDTO(); connectionDto.setSelectedRelationships(relationships); connectionDto.setDestination(destination); connectionDto.setSource(source); connectionDto.setParentGroupId(groupId); final ConnectionEntity connectionEntity = new ConnectionEntity(); connectionEntity.setComponent(connectionDto); connectionEntity.setDestinationGroupId(destination.getGroupId()); connectionEntity.setDestinationId(destination.getId()); connectionEntity.setDestinationType(destination.getType()); connectionEntity.setSourceGroupId(source.getGroupId()); connectionEntity.setSourceId(source.getId()); connectionEntity.setSourceType(source.getType()); connectionEntity.setRevision(createNewRevision()); return nifiClient.getConnectionClient().createConnection(groupId, connectionEntity); }
Example #3
Source File: ConnectionSchemaFunction.java From nifi-minifi with Apache License 2.0 | 6 votes |
@Override public ConnectionSchema apply(ConnectionDTO connectionDTO) { Map<String, Object> map = new HashMap<>(); map.put(ID_KEY, connectionDTO.getId()); map.put(NAME_KEY, connectionDTO.getName()); map.put(ConnectionSchema.SOURCE_ID_KEY, connectionDTO.getSource().getId()); Set<String> selectedRelationships = nullToEmpty(connectionDTO.getSelectedRelationships()); map.put(ConnectionSchema.SOURCE_RELATIONSHIP_NAMES_KEY, selectedRelationships.stream().sorted().collect(Collectors.toList())); map.put(ConnectionSchema.DESTINATION_ID_KEY, connectionDTO.getDestination().getId()); map.put(ConnectionSchema.MAX_WORK_QUEUE_SIZE_KEY, connectionDTO.getBackPressureObjectThreshold()); map.put(ConnectionSchema.MAX_WORK_QUEUE_DATA_SIZE_KEY, connectionDTO.getBackPressureDataSizeThreshold()); map.put(ConnectionSchema.FLOWFILE_EXPIRATION__KEY, connectionDTO.getFlowFileExpiration()); List<String> queuePrioritizers = nullToEmpty(connectionDTO.getPrioritizers()); if (queuePrioritizers.size() > 0) { map.put(ConnectionSchema.QUEUE_PRIORITIZER_CLASS_KEY, queuePrioritizers.get(0)); } ConnectionSchema connectionSchema = new ConnectionSchema(map); if (ConnectableType.FUNNEL.name().equals(connectionDTO.getSource().getType())) { connectionSchema.addValidationIssue("Connection " + connectionDTO.getName() + " has type " + ConnectableType.FUNNEL.name() + " which is not supported by MiNiFi"); } if (queuePrioritizers.size() > 1) { connectionSchema.addValidationIssue(ConnectionSchema.QUEUE_PRIORITIZER_CLASS_KEY, CONNECTIONS_KEY, " has more than one queue prioritizer"); } return connectionSchema; }
Example #4
Source File: RelationshipAuditor.java From nifi with Apache License 2.0 | 6 votes |
/** * Extracts configured settings from the specified connection only if they have also been specified in the connectionDTO. * * @param connection connection * @param connectionDTO dto * @return properties */ private Map<String, String> extractConfiguredPropertyValues(Connection connection, ConnectionDTO connectionDTO) { Map<String, String> values = new HashMap<>(); if (connectionDTO.getName() != null) { values.put(NAME, connection.getName()); } if (connectionDTO.getFlowFileExpiration() != null) { values.put(FLOW_FILE_EXPIRATION, String.valueOf(connection.getFlowFileQueue().getFlowFileExpiration())); } if (connectionDTO.getBackPressureObjectThreshold() != null) { values.put(BACK_PRESSURE_OBJECT_THRESHOLD, String.valueOf(connection.getFlowFileQueue().getBackPressureObjectThreshold())); } if (connectionDTO.getBackPressureDataSizeThreshold() != null) { values.put(BACK_PRESSURE_DATA_SIZE_THRESHOLD, String.valueOf(connection.getFlowFileQueue().getBackPressureDataSizeThreshold())); } if (connectionDTO.getPrioritizers() != null) { List<String> prioritizers = new ArrayList<>(); for (FlowFilePrioritizer prioritizer : connection.getFlowFileQueue().getPriorities()) { prioritizers.add(prioritizer.getClass().getCanonicalName()); } values.put(PRIORITIZERS, StringUtils.join(prioritizers, ", ")); } return values; }
Example #5
Source File: SnippetUtils.java From nifi with Apache License 2.0 | 6 votes |
/** * Builds a mapping of components to PositionDTO's. * * @param connections connections * @return position of connections map */ private static Map<ConnectionDTO, List<PositionDTO>> getConnectionPositionLookup(final Collection<ConnectionDTO> connections) { final Map<ConnectionDTO, List<PositionDTO>> positionLookup = new HashMap<>(); for (final ConnectionDTO connection : connections) { final List<PositionDTO> bendsCopy; if (connection.getBends() == null) { bendsCopy = Collections.emptyList(); } else { bendsCopy = new ArrayList<>(connection.getBends().size()); for (final PositionDTO bend : connection.getBends()) { bendsCopy.add(new PositionDTO(bend.getX(), bend.getY())); } } positionLookup.put(connection, bendsCopy); } return positionLookup; }
Example #6
Source File: SnippetUtils.java From localization_nifi with Apache License 2.0 | 6 votes |
/** * Builds a mapping of components to PositionDTO's. * * @param connections connections * @return position of connections map */ private static Map<ConnectionDTO, List<PositionDTO>> getConnectionPositionLookup(final Collection<ConnectionDTO> connections) { final Map<ConnectionDTO, List<PositionDTO>> positionLookup = new HashMap<>(); for (final ConnectionDTO connection : connections) { final List<PositionDTO> bendsCopy; if (connection.getBends() == null) { bendsCopy = Collections.emptyList(); } else { bendsCopy = new ArrayList<>(connection.getBends().size()); for (final PositionDTO bend : connection.getBends()) { bendsCopy.add(new PositionDTO(bend.getX(), bend.getY())); } } positionLookup.put(connection, bendsCopy); } return positionLookup; }
Example #7
Source File: StandardNiFiServiceFacade.java From localization_nifi with Apache License 2.0 | 5 votes |
@Override public ConnectionEntity deleteConnection(final Revision revision, final String connectionId) { final Connection connection = connectionDAO.getConnection(connectionId); final PermissionsDTO permissions = dtoFactory.createPermissionsDto(connection); final ConnectionDTO snapshot = deleteComponent( revision, connection.getResource(), () -> connectionDAO.deleteConnection(connectionId), false, // no policies to remove dtoFactory.createConnectionDto(connection)); return entityFactory.createConnectionEntity(snapshot, null, permissions, null); }
Example #8
Source File: StandardFlowServiceTest.java From localization_nifi with Apache License 2.0 | 5 votes |
private void assertEquals(ConnectionDTO expected, ConnectionDTO actual) { if (expected == null && actual == null) { return; } Assert.assertEquals(expected.getAvailableRelationships(), actual.getAvailableRelationships()); assertEquals(expected.getDestination(), actual.getDestination()); Assert.assertEquals(expected.getId(), actual.getId()); Assert.assertEquals(expected.getName(), actual.getName()); Assert.assertEquals(expected.getParentGroupId(), actual.getParentGroupId()); Assert.assertEquals(expected.getSelectedRelationships(), actual.getSelectedRelationships()); assertEquals(expected.getSource(), actual.getSource()); }
Example #9
Source File: SnippetUtils.java From localization_nifi with Apache License 2.0 | 5 votes |
/** * Gets all connections that are part of the specified template. * * @param contents snippet content * @return connection dtos */ private static Collection<ConnectionDTO> getConnections(FlowSnippetDTO contents) { final Collection<ConnectionDTO> connections = new HashSet<>(); if (contents.getConnections() != null) { connections.addAll(contents.getConnections()); } return connections; }
Example #10
Source File: SnippetUtils.java From localization_nifi with Apache License 2.0 | 5 votes |
/** * Scales the placement of individual components of the snippet by the * given factorX and factorY. Does not scale components in child process groups. * * @param snippet snippet * @param factorX x location scaling factor * @param factorY y location scaling factor */ public static void scaleSnippet(FlowSnippetDTO snippet, double factorX, double factorY) { // get the connections final Collection<ConnectionDTO> connections = getConnections(snippet); // get the components and their positions from the template contents final Collection<ComponentDTO> components = getComponents(snippet); // only perform the operation if there are components in this snippet if (connections.isEmpty() && components.isEmpty()) { return; } // get the component positions from the snippet contents final Map<ComponentDTO, PositionDTO> componentPositionLookup = getPositionLookup(components); final Map<ConnectionDTO, List<PositionDTO>> connectionPositionLookup = getConnectionPositionLookup(connections); // adjust all component positions for (final PositionDTO position : componentPositionLookup.values()) { position.setX(position.getX() * factorX); position.setY(position.getY() * factorY); } // adjust all connection positions for (final List<PositionDTO> bends : connectionPositionLookup.values()) { for (final PositionDTO bend : bends) { bend.setX(bend.getX() * factorX); bend.setY(bend.getY() * factorY); } } // apply the updated positions applyUpdatedPositions(componentPositionLookup, connectionPositionLookup); }
Example #11
Source File: SnippetUtils.java From localization_nifi with Apache License 2.0 | 5 votes |
/** * Moves the content of the specified snippet around the specified location * and scales the placement of individual components of the template by the * given factorX and factorY. Does not scale components in child process groups. * * @param snippet snippet * @param x x location * @param y y location * @param factorX x location scaling factor * @param factorY y location scaling factor */ public static void moveAndScaleSnippet(FlowSnippetDTO snippet, Double x, Double y, double factorX, double factorY) { // ensure the point is specified if (x != null && y != null) { final PositionDTO origin = new PositionDTO(x, y); // get the connections final Collection<ConnectionDTO> connections = getConnections(snippet); // get the components and their positions from the template contents final Collection<ComponentDTO> components = getComponents(snippet); // only perform the operation if there are components in this snippet if (connections.isEmpty() && components.isEmpty()) { return; } // get the component positions from the snippet contents final Map<ComponentDTO, PositionDTO> componentPositionLookup = getPositionLookup(components); final Map<ConnectionDTO, List<PositionDTO>> connectionPositionLookup = getConnectionPositionLookup(connections); final PositionDTO currentOrigin = getOrigin(componentPositionLookup.values(), connectionPositionLookup.values()); // adjust all component positions for (final PositionDTO position : componentPositionLookup.values()) { position.setX(origin.getX() + ((position.getX() - currentOrigin.getX()) * factorX)); position.setY(origin.getY() + ((position.getY() - currentOrigin.getY()) * factorY)); } // adjust all connection positions for (final List<PositionDTO> bends : connectionPositionLookup.values()) { for (final PositionDTO bend : bends) { bend.setX(origin.getX() + ((bend.getX() - currentOrigin.getX()) * factorX)); bend.setY(origin.getY() + ((bend.getY() - currentOrigin.getY()) * factorY)); } } // apply the updated positions applyUpdatedPositions(componentPositionLookup, connectionPositionLookup); } }
Example #12
Source File: StandardConnectionDAO.java From nifi with Apache License 2.0 | 5 votes |
private void verifyUpdate(final Connection connection, final ConnectionDTO connectionDTO) { // determine what the request is attempting if (isAnyNotNull(connectionDTO.getBackPressureDataSizeThreshold(), connectionDTO.getBackPressureObjectThreshold(), connectionDTO.getDestination(), connectionDTO.getFlowFileExpiration(), connectionDTO.getName(), connectionDTO.getPosition(), connectionDTO.getPrioritizers(), connectionDTO.getSelectedRelationships())) { // validate the incoming request final List<String> validationErrors = validateProposedConfiguration(connection.getProcessGroup().getIdentifier(), connectionDTO); // ensure there was no validation errors if (!validationErrors.isEmpty()) { throw new ValidationException(validationErrors); } // If destination is changing, ensure that current destination is not running. This check is done here, rather than // in the Connection object itself because the Connection object itself does not know which updates are to occur and // we don't want to prevent updating things like the connection name or backpressure just because the destination is running final Connectable destination = connection.getDestination(); if (destination != null && destination.isRunning() && destination.getConnectableType() != ConnectableType.FUNNEL && destination.getConnectableType() != ConnectableType.INPUT_PORT) { throw new ValidationException(Collections.singletonList("Cannot change the destination of connection because the current destination is running")); } // verify that this connection supports modification connection.verifyCanUpdate(); } }
Example #13
Source File: ITConnectionAccessControl.java From localization_nifi with Apache License 2.0 | 5 votes |
/** * Ensures the NONE user cannot put a connection. * * @throws Exception ex */ @Test public void testNoneUserPutConnection() throws Exception { final ConnectionEntity entity = getRandomConnection(helper.getNoneUser()); assertFalse(entity.getPermissions().getCanRead()); assertFalse(entity.getPermissions().getCanWrite()); assertNull(entity.getComponent()); final String updatedName = "Updated Name"; // attempt to update the name final ConnectionDTO requestDto = new ConnectionDTO(); requestDto.setId(entity.getId()); requestDto.setName(updatedName); final long version = entity.getRevision().getVersion(); final RevisionDTO requestRevision = new RevisionDTO(); requestRevision.setVersion(version); requestRevision.setClientId(AccessControlHelper.NONE_CLIENT_ID); final ConnectionEntity requestEntity = new ConnectionEntity(); requestEntity.setId(entity.getId()); requestEntity.setRevision(requestRevision); requestEntity.setComponent(requestDto); // perform the request final ClientResponse response = updateConnection(helper.getNoneUser(), requestEntity); // ensure forbidden response assertEquals(403, response.getStatus()); }
Example #14
Source File: ITConnectionAccessControl.java From localization_nifi with Apache License 2.0 | 5 votes |
/** * Ensures the WRITE user can put a connection. * * @throws Exception ex */ @Test public void testWriteUserPutConnection() throws Exception { final ConnectionEntity entity = getRandomConnection(helper.getWriteUser()); assertFalse(entity.getPermissions().getCanRead()); assertTrue(entity.getPermissions().getCanWrite()); assertNull(entity.getComponent()); final String updatedName = "Updated Name"; // attempt to update the name final ConnectionDTO requestDto = new ConnectionDTO(); requestDto.setId(entity.getId()); requestDto.setName(updatedName); final long version = entity.getRevision().getVersion(); final RevisionDTO requestRevision = new RevisionDTO(); requestRevision.setVersion(version); requestRevision.setClientId(AccessControlHelper.WRITE_CLIENT_ID); final ConnectionEntity requestEntity = new ConnectionEntity(); requestEntity.setId(entity.getId()); requestEntity.setRevision(requestRevision); requestEntity.setComponent(requestDto); // perform the request final ClientResponse response = updateConnection(helper.getWriteUser(), requestEntity); // ensure successful response assertEquals(200, response.getStatus()); // get the response final ConnectionEntity responseEntity = response.getEntity(ConnectionEntity.class); // verify assertEquals(WRITE_CLIENT_ID, responseEntity.getRevision().getClientId()); assertEquals(version + 1, responseEntity.getRevision().getVersion().longValue()); }
Example #15
Source File: StandardConnectionDAO.java From localization_nifi with Apache License 2.0 | 5 votes |
private void verifyUpdate(final Connection connection, final ConnectionDTO connectionDTO) { // determine what the request is attempting if (isAnyNotNull(connectionDTO.getBackPressureDataSizeThreshold(), connectionDTO.getBackPressureObjectThreshold(), connectionDTO.getDestination(), connectionDTO.getFlowFileExpiration(), connectionDTO.getName(), connectionDTO.getPosition(), connectionDTO.getPrioritizers(), connectionDTO.getSelectedRelationships())) { // validate the incoming request final List<String> validationErrors = validateProposedConfiguration(connection.getProcessGroup().getIdentifier(), connectionDTO); // ensure there was no validation errors if (!validationErrors.isEmpty()) { throw new ValidationException(validationErrors); } // If destination is changing, ensure that current destination is not running. This check is done here, rather than // in the Connection object itself because the Connection object itself does not know which updates are to occur and // we don't want to prevent updating things like the connection name or backpressure just because the destination is running final Connectable destination = connection.getDestination(); if (destination != null && destination.isRunning() && destination.getConnectableType() != ConnectableType.FUNNEL && destination.getConnectableType() != ConnectableType.INPUT_PORT) { throw new ValidationException(Collections.singletonList("Cannot change the destination of connection because the current destination is running")); } // verify that this connection supports modification connection.verifyCanUpdate(); } }
Example #16
Source File: FlowController.java From localization_nifi with Apache License 2.0 | 5 votes |
/** * Recursively finds all ConnectionDTO's * * @param group group * @return connection dtos */ private Set<ConnectionDTO> findAllConnections(final ProcessGroupDTO group) { final Set<ConnectionDTO> conns = new HashSet<>(); for (final ConnectionDTO dto : group.getContents().getConnections()) { conns.add(dto); } for (final ProcessGroupDTO childGroup : group.getContents().getProcessGroups()) { conns.addAll(findAllConnections(childGroup)); } return conns; }
Example #17
Source File: StandardNiFiServiceFacade.java From localization_nifi with Apache License 2.0 | 5 votes |
@Override public ConnectionEntity updateConnection(final Revision revision, final ConnectionDTO connectionDTO) { final Connection connectionNode = connectionDAO.getConnection(connectionDTO.getId()); final RevisionUpdate<ConnectionDTO> snapshot = updateComponent( revision, connectionNode, () -> connectionDAO.updateConnection(connectionDTO), connection -> dtoFactory.createConnectionDto(connection)); final PermissionsDTO permissions = dtoFactory.createPermissionsDto(connectionNode); final ConnectionStatusDTO status = dtoFactory.createConnectionStatusDto(controllerFacade.getConnectionStatus(connectionNode.getIdentifier())); return entityFactory.createConnectionEntity(snapshot.getComponent(), dtoFactory.createRevisionDTO(snapshot.getLastModification()), permissions, status); }
Example #18
Source File: ConnectionSchemaTest.java From nifi-minifi with Apache License 2.0 | 5 votes |
@Before public void setup() { ConnectableDTO source = new ConnectableDTO(); source.setId(testSourceId); ConnectableDTO destination = new ConnectableDTO(); destination.setId(testDestinationId); dto = new ConnectionDTO(); dto.setId(testId); dto.setName(testName); dto.setSource(source); dto.setSelectedRelationships(Arrays.asList(testSelectedRelationship).stream().collect(Collectors.toSet())); dto.setDestination(destination); dto.setBackPressureObjectThreshold(testMaxWorkQueueSize); dto.setBackPressureDataSizeThreshold(testMaxWorkQueueDataSize); dto.setFlowFileExpiration(testFlowfileExpiration); dto.setPrioritizers(Arrays.asList(testQueuePrioritizerClass)); map = new HashMap<>(); map.put(CommonPropertyKeys.ID_KEY, testId); map.put(CommonPropertyKeys.NAME_KEY, testName); map.put(ConnectionSchema.SOURCE_ID_KEY, testSourceId); map.put(ConnectionSchema.SOURCE_RELATIONSHIP_NAMES_KEY, new ArrayList<>(Arrays.asList(testSelectedRelationship))); map.put(ConnectionSchema.DESTINATION_ID_KEY, testDestinationId); map.put(ConnectionSchema.MAX_WORK_QUEUE_SIZE_KEY, testMaxWorkQueueSize); map.put(ConnectionSchema.MAX_WORK_QUEUE_DATA_SIZE_KEY, testMaxWorkQueueDataSize); map.put(ConnectionSchema.FLOWFILE_EXPIRATION__KEY, testFlowfileExpiration); map.put(ConnectionSchema.QUEUE_PRIORITIZER_CLASS_KEY, testQueuePrioritizerClass); }
Example #19
Source File: ConnectionEntityMerger.java From nifi with Apache License 2.0 | 5 votes |
@Override public void merge(ConnectionEntity clientEntity, Map<NodeIdentifier, ConnectionEntity> entityMap) { ComponentEntityMerger.super.merge(clientEntity, entityMap); for (Map.Entry<NodeIdentifier, ConnectionEntity> entry : entityMap.entrySet()) { final ConnectionEntity entityStatus = entry.getValue(); if (entityStatus != clientEntity) { mergeStatus(clientEntity.getStatus(), clientEntity.getPermissions().getCanRead(), entry.getValue().getStatus(), entry.getValue().getPermissions().getCanRead(), entry.getKey()); } } // If Load Balancing is configured but client entity indicates that data is not being transferred, we need to check if any other // node is actively transferring data. If Client Entity is transferring data, we already know the correct value for the Status, // and if the Connection is not configured for Load Balancing, then we also know the correct value, so no need to look at all of // the values of the other nodes. if (clientEntity.getComponent() != null && ConnectionDTO.LOAD_BALANCE_INACTIVE.equals(clientEntity.getComponent().getLoadBalanceStatus())) { final boolean anyActive = entityMap.values().stream() .map(ConnectionEntity::getComponent) .filter(Objects::nonNull) .map(ConnectionDTO::getLoadBalanceStatus) .anyMatch(status -> status.equals(ConnectionDTO.LOAD_BALANCE_ACTIVE)); if (anyActive) { clientEntity.getComponent().setLoadBalanceStatus(ConnectionDTO.LOAD_BALANCE_ACTIVE); } } final Set<String> availableRelationships = clientEntity.getComponent() == null ? null : clientEntity.getComponent().getAvailableRelationships(); if (availableRelationships != null) { clientEntity.getComponent().setAvailableRelationships(new TreeSet<>(availableRelationships)); } final Set<String> selectedRelationships = clientEntity.getComponent() == null ? null : clientEntity.getComponent().getSelectedRelationships(); if (selectedRelationships != null) { clientEntity.getComponent().setSelectedRelationships(new TreeSet<>(selectedRelationships)); } }
Example #20
Source File: ITConnectionAccessControl.java From nifi with Apache License 2.0 | 5 votes |
/** * Ensures the WRITE user can put a connection. * * @throws Exception ex */ @Test public void testWriteUserPutConnection() throws Exception { final ConnectionEntity entity = getRandomConnection(helper.getWriteUser()); assertFalse(entity.getPermissions().getCanRead()); assertTrue(entity.getPermissions().getCanWrite()); assertNull(entity.getComponent()); final String updatedName = "Updated Name"; // attempt to update the name final ConnectionDTO requestDto = new ConnectionDTO(); requestDto.setId(entity.getId()); requestDto.setName(updatedName); final long version = entity.getRevision().getVersion(); final RevisionDTO requestRevision = new RevisionDTO(); requestRevision.setVersion(version); requestRevision.setClientId(AccessControlHelper.WRITE_CLIENT_ID); final ConnectionEntity requestEntity = new ConnectionEntity(); requestEntity.setId(entity.getId()); requestEntity.setRevision(requestRevision); requestEntity.setComponent(requestDto); // perform the request final Response response = updateConnection(helper.getWriteUser(), requestEntity); // ensure successful response assertEquals(200, response.getStatus()); // get the response final ConnectionEntity responseEntity = response.readEntity(ConnectionEntity.class); // verify assertEquals(WRITE_CLIENT_ID, responseEntity.getRevision().getClientId()); assertEquals(version + 1, responseEntity.getRevision().getVersion().longValue()); }
Example #21
Source File: ITConnectionAccessControl.java From nifi with Apache License 2.0 | 5 votes |
/** * Ensures the NONE user cannot put a connection. * * @throws Exception ex */ @Test public void testNoneUserPutConnection() throws Exception { final ConnectionEntity entity = getRandomConnection(helper.getNoneUser()); assertFalse(entity.getPermissions().getCanRead()); assertFalse(entity.getPermissions().getCanWrite()); assertNull(entity.getComponent()); final String updatedName = "Updated Name"; // attempt to update the name final ConnectionDTO requestDto = new ConnectionDTO(); requestDto.setId(entity.getId()); requestDto.setName(updatedName); final long version = entity.getRevision().getVersion(); final RevisionDTO requestRevision = new RevisionDTO(); requestRevision.setVersion(version); requestRevision.setClientId(AccessControlHelper.NONE_CLIENT_ID); final ConnectionEntity requestEntity = new ConnectionEntity(); requestEntity.setId(entity.getId()); requestEntity.setRevision(requestRevision); requestEntity.setComponent(requestDto); // perform the request final Response response = updateConnection(helper.getNoneUser(), requestEntity); // ensure forbidden response assertEquals(403, response.getStatus()); }
Example #22
Source File: ConnectionMissingCheck.java From nifi with Apache License 2.0 | 5 votes |
private void findAllConnectionIds(final ProcessGroupDTO group, final Set<String> ids) { for (final ConnectionDTO connectionDTO : group.getContents().getConnections()) { ids.add(connectionDTO.getId()); } for (final ProcessGroupDTO childGroup : group.getContents().getProcessGroups()) { findAllConnectionIds(childGroup, ids); } }
Example #23
Source File: StandardFlowSnippet.java From nifi with Apache License 2.0 | 5 votes |
/** * Recursively finds all ConnectionDTO's * * @param group group * @return connection dtos */ private Set<ConnectionDTO> findAllConnections(final ProcessGroupDTO group) { final Set<ConnectionDTO> conns = new HashSet<>(); conns.addAll(group.getContents().getConnections()); for (final ProcessGroupDTO childGroup : group.getContents().getProcessGroups()) { conns.addAll(findAllConnections(childGroup)); } return conns; }
Example #24
Source File: TemplateUtils.java From nifi with Apache License 2.0 | 5 votes |
/** * Scrubs connections prior to saving. This includes removing available relationships. * * @param connections conns */ private static void scrubConnections(final Set<ConnectionDTO> connections) { // go through each connection for (final ConnectionDTO connectionDTO : connections) { connectionDTO.setAvailableRelationships(null); scrubConnectable(connectionDTO.getSource()); scrubConnectable(connectionDTO.getDestination()); } }
Example #25
Source File: SnippetUtils.java From nifi with Apache License 2.0 | 5 votes |
/** * Moves the content of the specified snippet around the specified location * and scales the placement of individual components of the template by the * given factorX and factorY. Does not scale components in child process groups. * * @param snippet snippet * @param x x location * @param y y location * @param factorX x location scaling factor * @param factorY y location scaling factor */ public static void moveAndScaleSnippet(FlowSnippetDTO snippet, Double x, Double y, double factorX, double factorY) { // ensure the point is specified if (x != null && y != null) { final PositionDTO origin = new PositionDTO(x, y); // get the connections final Collection<ConnectionDTO> connections = getConnections(snippet); // get the components and their positions from the template contents final Collection<ComponentDTO> components = getComponents(snippet); // only perform the operation if there are components in this snippet if (connections.isEmpty() && components.isEmpty()) { return; } // get the component positions from the snippet contents final Map<ComponentDTO, PositionDTO> componentPositionLookup = getPositionLookup(components); final Map<ConnectionDTO, List<PositionDTO>> connectionPositionLookup = getConnectionPositionLookup(connections); final PositionDTO currentOrigin = getOrigin(componentPositionLookup.values(), connectionPositionLookup.values()); // adjust all component positions for (final PositionDTO position : componentPositionLookup.values()) { position.setX(origin.getX() + ((position.getX() - currentOrigin.getX()) * factorX)); position.setY(origin.getY() + ((position.getY() - currentOrigin.getY()) * factorY)); } // adjust all connection positions for (final List<PositionDTO> bends : connectionPositionLookup.values()) { for (final PositionDTO bend : bends) { bend.setX(origin.getX() + ((bend.getX() - currentOrigin.getX()) * factorX)); bend.setY(origin.getY() + ((bend.getY() - currentOrigin.getY()) * factorY)); } } // apply the updated positions applyUpdatedPositions(componentPositionLookup, connectionPositionLookup); } }
Example #26
Source File: SnippetUtils.java From nifi with Apache License 2.0 | 5 votes |
/** * Scales the placement of individual components of the snippet by the * given factorX and factorY. Does not scale components in child process groups. * * @param snippet snippet * @param factorX x location scaling factor * @param factorY y location scaling factor */ public static void scaleSnippet(FlowSnippetDTO snippet, double factorX, double factorY) { // get the connections final Collection<ConnectionDTO> connections = getConnections(snippet); // get the components and their positions from the template contents final Collection<ComponentDTO> components = getComponents(snippet); // only perform the operation if there are components in this snippet if (connections.isEmpty() && components.isEmpty()) { return; } // get the component positions from the snippet contents final Map<ComponentDTO, PositionDTO> componentPositionLookup = getPositionLookup(components); final Map<ConnectionDTO, List<PositionDTO>> connectionPositionLookup = getConnectionPositionLookup(connections); // adjust all component positions for (final PositionDTO position : componentPositionLookup.values()) { position.setX(position.getX() * factorX); position.setY(position.getY() * factorY); } // adjust all connection positions for (final List<PositionDTO> bends : connectionPositionLookup.values()) { for (final PositionDTO bend : bends) { bend.setX(bend.getX() * factorX); bend.setY(bend.getY() * factorY); } } // apply the updated positions applyUpdatedPositions(componentPositionLookup, connectionPositionLookup); }
Example #27
Source File: SnippetUtils.java From nifi with Apache License 2.0 | 5 votes |
/** * Gets all connections that are part of the specified template. * * @param contents snippet content * @return connection dtos */ private static Collection<ConnectionDTO> getConnections(FlowSnippetDTO contents) { final Collection<ConnectionDTO> connections = new HashSet<>(); if (contents.getConnections() != null) { connections.addAll(contents.getConnections()); } return connections; }
Example #28
Source File: StandardFlowServiceTest.java From nifi with Apache License 2.0 | 5 votes |
private void assertEquals(ConnectionDTO expected, ConnectionDTO actual) { if (expected == null && actual == null) { return; } Assert.assertEquals(expected.getAvailableRelationships(), actual.getAvailableRelationships()); assertEquals(expected.getDestination(), actual.getDestination()); Assert.assertEquals(expected.getId(), actual.getId()); Assert.assertEquals(expected.getName(), actual.getName()); Assert.assertEquals(expected.getParentGroupId(), actual.getParentGroupId()); Assert.assertEquals(expected.getSelectedRelationships(), actual.getSelectedRelationships()); assertEquals(expected.getSource(), actual.getSource()); }
Example #29
Source File: LoadBalanceIT.java From nifi with Apache License 2.0 | 5 votes |
private boolean isConnectionDoneLoadBalancing(final String connectionId) { try { final ConnectionEntity connectionEntity = getNifiClient().getConnectionClient().getConnection(connectionId); final String loadBalanceStatus = connectionEntity.getComponent().getLoadBalanceStatus(); return ConnectionDTO.LOAD_BALANCE_INACTIVE.equals(loadBalanceStatus); } catch (Exception e) { e.printStackTrace(); return false; } }
Example #30
Source File: NiFiClientUtil.java From nifi with Apache License 2.0 | 5 votes |
public ConnectionEntity updateConnectionLoadBalancing(final ConnectionEntity connectionEntity, final LoadBalanceStrategy strategy, final LoadBalanceCompression compression, final String loadBalanceAttribute) throws NiFiClientException, IOException { final ConnectionDTO connectionDto = new ConnectionDTO(); connectionDto.setLoadBalancePartitionAttribute(loadBalanceAttribute); connectionDto.setLoadBalanceStrategy(strategy.name()); connectionDto.setLoadBalanceCompression(compression.name()); connectionDto.setId(connectionEntity.getId()); final ConnectionEntity updatedEntity = new ConnectionEntity(); updatedEntity.setComponent(connectionDto); updatedEntity.setId(connectionEntity.getId()); updatedEntity.setRevision(connectionEntity.getRevision()); return nifiClient.getConnectionClient().updateConnection(updatedEntity); }