use of org.apache.nifi.web.api.dto.PositionDTO in project nifi by apache.
the class TestFlowController method testInstantiateSnippetWhenProcessorMissingBundle.
@Test(expected = IllegalArgumentException.class)
public void testInstantiateSnippetWhenProcessorMissingBundle() throws Exception {
final String id = UUID.randomUUID().toString();
final BundleCoordinate coordinate = systemBundle.getBundleDetails().getCoordinate();
final ProcessorNode processorNode = controller.createProcessor(DummyProcessor.class.getName(), id, coordinate);
// create a processor dto
final ProcessorDTO processorDTO = new ProcessorDTO();
// use a different id here
processorDTO.setId(UUID.randomUUID().toString());
processorDTO.setPosition(new PositionDTO(new Double(0), new Double(0)));
processorDTO.setStyle(processorNode.getStyle());
processorDTO.setParentGroupId("1234");
processorDTO.setInputRequirement(processorNode.getInputRequirement().name());
processorDTO.setPersistsState(processorNode.getProcessor().getClass().isAnnotationPresent(Stateful.class));
processorDTO.setRestricted(processorNode.isRestricted());
processorDTO.setExtensionMissing(processorNode.isExtensionMissing());
processorDTO.setType(processorNode.getCanonicalClassName());
// missing bundle
processorDTO.setBundle(null);
processorDTO.setName(processorNode.getName());
processorDTO.setState(processorNode.getScheduledState().toString());
processorDTO.setRelationships(new ArrayList<>());
processorDTO.setDescription("description");
processorDTO.setSupportsParallelProcessing(!processorNode.isTriggeredSerially());
processorDTO.setSupportsEventDriven(processorNode.isEventDrivenSupported());
processorDTO.setSupportsBatching(processorNode.isSessionBatchingSupported());
ProcessorConfigDTO configDTO = new ProcessorConfigDTO();
configDTO.setSchedulingPeriod(processorNode.getSchedulingPeriod());
configDTO.setPenaltyDuration(processorNode.getPenalizationPeriod());
configDTO.setYieldDuration(processorNode.getYieldPeriod());
configDTO.setRunDurationMillis(processorNode.getRunDuration(TimeUnit.MILLISECONDS));
configDTO.setConcurrentlySchedulableTaskCount(processorNode.getMaxConcurrentTasks());
configDTO.setLossTolerant(processorNode.isLossTolerant());
configDTO.setComments(processorNode.getComments());
configDTO.setBulletinLevel(processorNode.getBulletinLevel().name());
configDTO.setSchedulingStrategy(processorNode.getSchedulingStrategy().name());
configDTO.setExecutionNode(processorNode.getExecutionNode().name());
configDTO.setAnnotationData(processorNode.getAnnotationData());
processorDTO.setConfig(configDTO);
// create the snippet with the processor
final FlowSnippetDTO flowSnippetDTO = new FlowSnippetDTO();
flowSnippetDTO.setProcessors(Collections.singleton(processorDTO));
// instantiate the snippet
assertEquals(0, controller.getRootGroup().getProcessors().size());
controller.instantiateSnippet(controller.getRootGroup(), flowSnippetDTO);
}
use of org.apache.nifi.web.api.dto.PositionDTO in project nifi by apache.
the class SnippetUtils method moveAndScaleSnippet.
/**
* 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);
}
}
use of org.apache.nifi.web.api.dto.PositionDTO in project nifi by apache.
the class JerseyFlowClient method getSuggestedProcessGroupCoordinates.
@Override
public ProcessGroupBox getSuggestedProcessGroupCoordinates(final String parentId) throws NiFiClientException, IOException {
if (StringUtils.isBlank(parentId)) {
throw new IllegalArgumentException("Process group id cannot be null");
}
final ProcessGroupFlowEntity processGroup = getProcessGroup(parentId);
final ProcessGroupFlowDTO processGroupFlowDTO = processGroup.getProcessGroupFlow();
final FlowDTO flowDTO = processGroupFlowDTO.getFlow();
final List<ComponentEntity> pgComponents = new ArrayList<>();
pgComponents.addAll(flowDTO.getProcessGroups());
pgComponents.addAll(flowDTO.getProcessors());
pgComponents.addAll(flowDTO.getRemoteProcessGroups());
pgComponents.addAll(flowDTO.getConnections());
pgComponents.addAll(flowDTO.getFunnels());
pgComponents.addAll(flowDTO.getInputPorts());
pgComponents.addAll(flowDTO.getOutputPorts());
pgComponents.addAll(flowDTO.getLabels());
final Set<PositionDTO> positions = pgComponents.stream().map(ComponentEntity::getPosition).collect(Collectors.toSet());
if (positions.isEmpty()) {
return ProcessGroupBox.CANVAS_CENTER;
}
final List<ProcessGroupBox> coords = positions.stream().filter(Objects::nonNull).map(p -> new ProcessGroupBox(p.getX().intValue(), p.getY().intValue())).collect(Collectors.toList());
final ProcessGroupBox freeSpot = coords.get(0).findFreeSpace(coords);
return freeSpot;
}
use of org.apache.nifi.web.api.dto.PositionDTO in project nifi by apache.
the class FunnelResource method updateFunnel.
/**
* Creates a new Funnel.
*
* @param httpServletRequest request
* @param id The id of the funnel to update.
* @param requestFunnelEntity A funnelEntity.
* @return A funnelEntity.
*/
@PUT
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("{id}")
@ApiOperation(value = "Updates a funnel", response = FunnelEntity.class, authorizations = { @Authorization(value = "Write - /funnels/{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 updateFunnel(@Context final HttpServletRequest httpServletRequest, @ApiParam(value = "The funnel id.", required = true) @PathParam("id") final String id, @ApiParam(value = "The funnel configuration details.", required = true) final FunnelEntity requestFunnelEntity) {
if (requestFunnelEntity == null || requestFunnelEntity.getComponent() == null) {
throw new IllegalArgumentException("Funnel details must be specified.");
}
if (requestFunnelEntity.getRevision() == null) {
throw new IllegalArgumentException("Revision must be specified.");
}
// ensure the ids are the same
final FunnelDTO requestFunnelDTO = requestFunnelEntity.getComponent();
if (!id.equals(requestFunnelDTO.getId())) {
throw new IllegalArgumentException(String.format("The funnel id (%s) in the request body does not equal the " + "funnel id of the requested resource (%s).", requestFunnelDTO.getId(), id));
}
final PositionDTO proposedPosition = requestFunnelDTO.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, requestFunnelEntity);
}
// Extract the revision
final Revision requestRevision = getRevision(requestFunnelEntity, id);
return withWriteLock(serviceFacade, requestFunnelEntity, requestRevision, lookup -> {
Authorizable authorizable = lookup.getFunnel(id);
authorizable.authorize(authorizer, RequestAction.WRITE, NiFiUserUtils.getNiFiUser());
}, null, (revision, funnelEntity) -> {
// update the funnel
final FunnelEntity entity = serviceFacade.updateFunnel(revision, funnelEntity.getComponent());
populateRemainingFunnelEntityContent(entity);
return generateOkResponse(entity).build();
});
}
use of org.apache.nifi.web.api.dto.PositionDTO 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