Search in sources :

Example 36 with PositionDTO

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);
}
Also used : Stateful(org.apache.nifi.annotation.behavior.Stateful) ProcessorConfigDTO(org.apache.nifi.web.api.dto.ProcessorConfigDTO) FlowSnippetDTO(org.apache.nifi.web.api.dto.FlowSnippetDTO) ProcessorDTO(org.apache.nifi.web.api.dto.ProcessorDTO) DummyProcessor(org.apache.nifi.controller.service.mock.DummyProcessor) BundleCoordinate(org.apache.nifi.bundle.BundleCoordinate) PositionDTO(org.apache.nifi.web.api.dto.PositionDTO) Test(org.junit.Test)

Example 37 with PositionDTO

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);
    }
}
Also used : ConnectionDTO(org.apache.nifi.web.api.dto.ConnectionDTO) ComponentDTO(org.apache.nifi.web.api.dto.ComponentDTO) ArrayList(java.util.ArrayList) List(java.util.List) PositionDTO(org.apache.nifi.web.api.dto.PositionDTO)

Example 38 with PositionDTO

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;
}
Also used : ProcessGroupBox(org.apache.nifi.toolkit.cli.impl.client.nifi.ProcessGroupBox) NiFiClientException(org.apache.nifi.toolkit.cli.impl.client.nifi.NiFiClientException) Set(java.util.Set) IOException(java.io.IOException) StringUtils(org.apache.commons.lang3.StringUtils) Entity(javax.ws.rs.client.Entity) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) PositionDTO(org.apache.nifi.web.api.dto.PositionDTO) Objects(java.util.Objects) ComponentEntity(org.apache.nifi.web.api.entity.ComponentEntity) MediaType(javax.ws.rs.core.MediaType) List(java.util.List) VersionedFlowSnapshotMetadataSetEntity(org.apache.nifi.web.api.entity.VersionedFlowSnapshotMetadataSetEntity) Map(java.util.Map) FlowClient(org.apache.nifi.toolkit.cli.impl.client.nifi.FlowClient) CurrentUserEntity(org.apache.nifi.web.api.entity.CurrentUserEntity) ProcessGroupFlowEntity(org.apache.nifi.web.api.entity.ProcessGroupFlowEntity) ProcessGroupFlowDTO(org.apache.nifi.web.api.dto.flow.ProcessGroupFlowDTO) WebTarget(javax.ws.rs.client.WebTarget) FlowDTO(org.apache.nifi.web.api.dto.flow.FlowDTO) Collections(java.util.Collections) ScheduleComponentsEntity(org.apache.nifi.web.api.entity.ScheduleComponentsEntity) ProcessGroupFlowDTO(org.apache.nifi.web.api.dto.flow.ProcessGroupFlowDTO) FlowDTO(org.apache.nifi.web.api.dto.flow.FlowDTO) ProcessGroupFlowDTO(org.apache.nifi.web.api.dto.flow.ProcessGroupFlowDTO) ProcessGroupFlowEntity(org.apache.nifi.web.api.entity.ProcessGroupFlowEntity) ComponentEntity(org.apache.nifi.web.api.entity.ComponentEntity) ArrayList(java.util.ArrayList) ProcessGroupBox(org.apache.nifi.toolkit.cli.impl.client.nifi.ProcessGroupBox) PositionDTO(org.apache.nifi.web.api.dto.PositionDTO) Objects(java.util.Objects)

Example 39 with PositionDTO

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();
    });
}
Also used : FunnelEntity(org.apache.nifi.web.api.entity.FunnelEntity) Revision(org.apache.nifi.web.Revision) Authorizable(org.apache.nifi.authorization.resource.Authorizable) FunnelDTO(org.apache.nifi.web.api.dto.FunnelDTO) PositionDTO(org.apache.nifi.web.api.dto.PositionDTO) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) PUT(javax.ws.rs.PUT) ApiResponses(io.swagger.annotations.ApiResponses)

Example 40 with PositionDTO

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();
    });
}
Also used : Revision(org.apache.nifi.web.Revision) PortDTO(org.apache.nifi.web.api.dto.PortDTO) Authorizable(org.apache.nifi.authorization.resource.Authorizable) PositionDTO(org.apache.nifi.web.api.dto.PositionDTO) PortEntity(org.apache.nifi.web.api.entity.PortEntity) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) PUT(javax.ws.rs.PUT) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

PositionDTO (org.apache.nifi.web.api.dto.PositionDTO)48 ApiOperation (io.swagger.annotations.ApiOperation)16 ApiResponses (io.swagger.annotations.ApiResponses)16 Consumes (javax.ws.rs.Consumes)16 Path (javax.ws.rs.Path)16 Produces (javax.ws.rs.Produces)16 Revision (org.apache.nifi.web.Revision)16 Authorizable (org.apache.nifi.authorization.resource.Authorizable)15 ArrayList (java.util.ArrayList)10 ComponentAuthorizable (org.apache.nifi.authorization.ComponentAuthorizable)10 ConnectionDTO (org.apache.nifi.web.api.dto.ConnectionDTO)10 ProcessGroupAuthorizable (org.apache.nifi.authorization.ProcessGroupAuthorizable)9 SnippetAuthorizable (org.apache.nifi.authorization.SnippetAuthorizable)9 TemplateContentsAuthorizable (org.apache.nifi.authorization.TemplateContentsAuthorizable)9 POST (javax.ws.rs.POST)8 PUT (javax.ws.rs.PUT)8 PortDTO (org.apache.nifi.web.api.dto.PortDTO)8 ProcessorDTO (org.apache.nifi.web.api.dto.ProcessorDTO)8 ProcessGroupDTO (org.apache.nifi.web.api.dto.ProcessGroupDTO)7 RemoteProcessGroupDTO (org.apache.nifi.web.api.dto.RemoteProcessGroupDTO)7