Search in sources :

Example 6 with ProcessorConfigDTO

use of org.apache.nifi.web.api.dto.ProcessorConfigDTO in project nifi by apache.

the class ProcessorResource method updateProcessor.

/**
 * Updates the specified processor with the specified values.
 *
 * @param httpServletRequest request
 * @param id                 The id of the processor to update.
 * @param requestProcessorEntity    A processorEntity.
 * @return A processorEntity.
 * @throws InterruptedException if interrupted
 */
@PUT
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("/{id}")
@ApiOperation(value = "Updates a processor", response = ProcessorEntity.class, authorizations = { @Authorization(value = "Write - /processors/{uuid}"), @Authorization(value = "Read - any referenced Controller Services if this request changes the reference - /controller-services/{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 updateProcessor(@Context final HttpServletRequest httpServletRequest, @ApiParam(value = "The processor id.", required = true) @PathParam("id") final String id, @ApiParam(value = "The processor configuration details.", required = true) final ProcessorEntity requestProcessorEntity) throws InterruptedException {
    if (requestProcessorEntity == null || requestProcessorEntity.getComponent() == null) {
        throw new IllegalArgumentException("Processor details must be specified.");
    }
    if (requestProcessorEntity.getRevision() == null) {
        throw new IllegalArgumentException("Revision must be specified.");
    }
    // ensure the same id is being used
    final ProcessorDTO requestProcessorDTO = requestProcessorEntity.getComponent();
    if (!id.equals(requestProcessorDTO.getId())) {
        throw new IllegalArgumentException(String.format("The processor id (%s) in the request body does " + "not equal the processor id of the requested resource (%s).", requestProcessorDTO.getId(), id));
    }
    final PositionDTO proposedPosition = requestProcessorDTO.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, requestProcessorEntity);
    }
    // handle expects request (usually from the cluster manager)
    final Revision requestRevision = getRevision(requestProcessorEntity, id);
    return withWriteLock(serviceFacade, requestProcessorEntity, requestRevision, lookup -> {
        final NiFiUser user = NiFiUserUtils.getNiFiUser();
        final ComponentAuthorizable authorizable = lookup.getProcessor(id);
        authorizable.getAuthorizable().authorize(authorizer, RequestAction.WRITE, user);
        final ProcessorConfigDTO config = requestProcessorDTO.getConfig();
        if (config != null) {
            AuthorizeControllerServiceReference.authorizeControllerServiceReferences(config.getProperties(), authorizable, authorizer, lookup);
        }
    }, () -> serviceFacade.verifyUpdateProcessor(requestProcessorDTO), (revision, processorEntity) -> {
        final ProcessorDTO processorDTO = processorEntity.getComponent();
        // update the processor
        final ProcessorEntity entity = serviceFacade.updateProcessor(revision, processorDTO);
        populateRemainingProcessorEntityContent(entity);
        return generateOkResponse(entity).build();
    });
}
Also used : ComponentAuthorizable(org.apache.nifi.authorization.ComponentAuthorizable) ProcessorConfigDTO(org.apache.nifi.web.api.dto.ProcessorConfigDTO) Revision(org.apache.nifi.web.Revision) NiFiUser(org.apache.nifi.authorization.user.NiFiUser) ProcessorDTO(org.apache.nifi.web.api.dto.ProcessorDTO) ProcessorEntity(org.apache.nifi.web.api.entity.ProcessorEntity) 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 7 with ProcessorConfigDTO

use of org.apache.nifi.web.api.dto.ProcessorConfigDTO in project nifi by apache.

the class StandardProcessorDAO method configureProcessor.

private void configureProcessor(final ProcessorNode processor, final ProcessorDTO processorDTO) {
    final ProcessorConfigDTO config = processorDTO.getConfig();
    // ensure some configuration was specified
    if (isNotNull(config)) {
        // perform the configuration
        final String schedulingStrategy = config.getSchedulingStrategy();
        final String executionNode = config.getExecutionNode();
        final String comments = config.getComments();
        final String annotationData = config.getAnnotationData();
        final Integer maxTasks = config.getConcurrentlySchedulableTaskCount();
        final Map<String, String> configProperties = config.getProperties();
        final String schedulingPeriod = config.getSchedulingPeriod();
        final String penaltyDuration = config.getPenaltyDuration();
        final String yieldDuration = config.getYieldDuration();
        final Long runDurationMillis = config.getRunDurationMillis();
        final String bulletinLevel = config.getBulletinLevel();
        final Set<String> undefinedRelationshipsToTerminate = config.getAutoTerminatedRelationships();
        // ensure scheduling strategy is set first
        if (isNotNull(schedulingStrategy)) {
            processor.setSchedulingStrategy(SchedulingStrategy.valueOf(schedulingStrategy));
        }
        if (isNotNull(executionNode)) {
            processor.setExecutionNode(ExecutionNode.valueOf(executionNode));
        }
        if (isNotNull(comments)) {
            processor.setComments(comments);
        }
        if (isNotNull(annotationData)) {
            processor.setAnnotationData(annotationData);
        }
        if (isNotNull(maxTasks)) {
            processor.setMaxConcurrentTasks(maxTasks);
        }
        if (isNotNull(schedulingPeriod)) {
            processor.setScheduldingPeriod(schedulingPeriod);
        }
        if (isNotNull(penaltyDuration)) {
            processor.setPenalizationPeriod(penaltyDuration);
        }
        if (isNotNull(yieldDuration)) {
            processor.setYieldPeriod(yieldDuration);
        }
        if (isNotNull(runDurationMillis)) {
            processor.setRunDuration(runDurationMillis, TimeUnit.MILLISECONDS);
        }
        if (isNotNull(bulletinLevel)) {
            processor.setBulletinLevel(LogLevel.valueOf(bulletinLevel));
        }
        if (isNotNull(config.isLossTolerant())) {
            processor.setLossTolerant(config.isLossTolerant());
        }
        if (isNotNull(configProperties)) {
            processor.setProperties(configProperties);
        }
        if (isNotNull(undefinedRelationshipsToTerminate)) {
            final Set<Relationship> relationships = new HashSet<>();
            for (final String relName : undefinedRelationshipsToTerminate) {
                relationships.add(new Relationship.Builder().name(relName).build());
            }
            processor.setAutoTerminatedRelationships(relationships);
        }
    }
    // update processor settings
    if (isNotNull(processorDTO.getPosition())) {
        processor.setPosition(new Position(processorDTO.getPosition().getX(), processorDTO.getPosition().getY()));
    }
    if (isNotNull(processorDTO.getStyle())) {
        processor.setStyle(processorDTO.getStyle());
    }
    final String name = processorDTO.getName();
    if (isNotNull(name)) {
        processor.setName(name);
    }
}
Also used : ProcessorConfigDTO(org.apache.nifi.web.api.dto.ProcessorConfigDTO) Position(org.apache.nifi.connectable.Position) Relationship(org.apache.nifi.processor.Relationship) HashSet(java.util.HashSet)

Example 8 with ProcessorConfigDTO

use of org.apache.nifi.web.api.dto.ProcessorConfigDTO in project nifi by apache.

the class StandardProcessorDAO method verifyUpdate.

private void verifyUpdate(ProcessorNode processor, ProcessorDTO processorDTO) {
    // ensure the state, if specified, is valid
    if (isNotNull(processorDTO.getState())) {
        try {
            final ScheduledState purposedScheduledState = ScheduledState.valueOf(processorDTO.getState());
            // only attempt an action if it is changing
            if (!purposedScheduledState.equals(processor.getScheduledState())) {
                // perform the appropriate action
                switch(purposedScheduledState) {
                    case RUNNING:
                        processor.verifyCanStart();
                        break;
                    case STOPPED:
                        switch(processor.getScheduledState()) {
                            case RUNNING:
                                processor.verifyCanStop();
                                break;
                            case DISABLED:
                                processor.verifyCanEnable();
                                break;
                        }
                        break;
                    case DISABLED:
                        processor.verifyCanDisable();
                        break;
                }
            }
        } catch (IllegalArgumentException iae) {
            throw new IllegalArgumentException(String.format("The specified processor state (%s) is not valid. Valid options are 'RUNNING', 'STOPPED', and 'DISABLED'.", processorDTO.getState()));
        }
    }
    boolean modificationRequest = false;
    if (isAnyNotNull(processorDTO.getName(), processorDTO.getBundle())) {
        modificationRequest = true;
    }
    final BundleDTO bundleDTO = processorDTO.getBundle();
    if (bundleDTO != null) {
        // ensures all nodes in a cluster have the bundle, throws exception if bundle not found for the given type
        final BundleCoordinate bundleCoordinate = BundleUtils.getBundle(processor.getCanonicalClassName(), bundleDTO);
        // ensure we are only changing to a bundle with the same group and id, but different version
        processor.verifyCanUpdateBundle(bundleCoordinate);
    }
    final ProcessorConfigDTO configDTO = processorDTO.getConfig();
    if (configDTO != null) {
        if (isAnyNotNull(configDTO.getAnnotationData(), configDTO.getAutoTerminatedRelationships(), configDTO.getBulletinLevel(), configDTO.getComments(), configDTO.getConcurrentlySchedulableTaskCount(), configDTO.getPenaltyDuration(), configDTO.getProperties(), configDTO.getSchedulingPeriod(), configDTO.getSchedulingStrategy(), configDTO.getExecutionNode(), configDTO.getYieldDuration())) {
            modificationRequest = true;
        }
        // validate the request
        final List<String> requestValidation = validateProposedConfiguration(processor, configDTO);
        // ensure there was no validation errors
        if (!requestValidation.isEmpty()) {
            throw new ValidationException(requestValidation);
        }
    }
    if (modificationRequest) {
        processor.verifyCanUpdate();
    }
}
Also used : ProcessorConfigDTO(org.apache.nifi.web.api.dto.ProcessorConfigDTO) ValidationException(org.apache.nifi.controller.exception.ValidationException) ScheduledState(org.apache.nifi.controller.ScheduledState) BundleDTO(org.apache.nifi.web.api.dto.BundleDTO) BundleCoordinate(org.apache.nifi.bundle.BundleCoordinate)

Example 9 with ProcessorConfigDTO

use of org.apache.nifi.web.api.dto.ProcessorConfigDTO in project nifi by apache.

the class TestFlowController method testInstantiateSnippetWithDisabledProcessor.

@Test
public void testInstantiateSnippetWithDisabledProcessor() throws ProcessorInstantiationException {
    final String id = UUID.randomUUID().toString();
    final BundleCoordinate coordinate = systemBundle.getBundleDetails().getCoordinate();
    final ProcessorNode processorNode = controller.createProcessor(DummyProcessor.class.getName(), id, coordinate);
    processorNode.disable();
    // 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());
    processorDTO.setBundle(new BundleDTO(coordinate.getGroup(), coordinate.getId(), coordinate.getVersion()));
    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);
    assertEquals(1, controller.getRootGroup().getProcessors().size());
    assertTrue(controller.getRootGroup().getProcessors().iterator().next().getScheduledState().equals(ScheduledState.DISABLED));
}
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) BundleDTO(org.apache.nifi.web.api.dto.BundleDTO) BundleCoordinate(org.apache.nifi.bundle.BundleCoordinate) PositionDTO(org.apache.nifi.web.api.dto.PositionDTO) Test(org.junit.Test)

Example 10 with ProcessorConfigDTO

use of org.apache.nifi.web.api.dto.ProcessorConfigDTO in project nifi by apache.

the class StandardSnippetDAO method lookupSensitiveProcessorProperties.

private void lookupSensitiveProcessorProperties(final Set<ProcessorDTO> processors) {
    final ProcessGroup rootGroup = flowController.getGroup(flowController.getRootGroupId());
    // go through each processor
    for (final ProcessorDTO processorDTO : processors) {
        final ProcessorConfigDTO processorConfig = processorDTO.getConfig();
        // ensure that some property configuration have been specified
        if (processorConfig != null && processorConfig.getProperties() != null) {
            final Map<String, String> processorProperties = processorConfig.getProperties();
            // find the corresponding processor
            final ProcessorNode processorNode = rootGroup.findProcessor(processorDTO.getId());
            if (processorNode == null) {
                throw new IllegalArgumentException(String.format("Unable to create snippet because Processor '%s' could not be found", processorDTO.getId()));
            }
            // look for sensitive properties get the actual value
            for (Entry<PropertyDescriptor, String> entry : processorNode.getProperties().entrySet()) {
                final PropertyDescriptor descriptor = entry.getKey();
                if (descriptor.isSensitive()) {
                    processorProperties.put(descriptor.getName(), entry.getValue());
                }
            }
        }
    }
}
Also used : ProcessorConfigDTO(org.apache.nifi.web.api.dto.ProcessorConfigDTO) ProcessorNode(org.apache.nifi.controller.ProcessorNode) PropertyDescriptor(org.apache.nifi.components.PropertyDescriptor) ProcessorDTO(org.apache.nifi.web.api.dto.ProcessorDTO) ProcessGroup(org.apache.nifi.groups.ProcessGroup)

Aggregations

ProcessorConfigDTO (org.apache.nifi.web.api.dto.ProcessorConfigDTO)23 ProcessorDTO (org.apache.nifi.web.api.dto.ProcessorDTO)15 BundleCoordinate (org.apache.nifi.bundle.BundleCoordinate)6 PositionDTO (org.apache.nifi.web.api.dto.PositionDTO)6 HashSet (java.util.HashSet)5 FlowSnippetDTO (org.apache.nifi.web.api.dto.FlowSnippetDTO)5 Test (org.junit.Test)5 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 ControllerServiceDTO (org.apache.nifi.web.api.dto.ControllerServiceDTO)4 LegacyNifiRestClient (com.thinkbiganalytics.nifi.rest.client.LegacyNifiRestClient)3 NifiProperty (com.thinkbiganalytics.nifi.rest.model.NifiProperty)3 Stateful (org.apache.nifi.annotation.behavior.Stateful)3 Relationship (org.apache.nifi.processor.Relationship)3 BundleDTO (org.apache.nifi.web.api.dto.BundleDTO)3 RelationshipDTO (org.apache.nifi.web.api.dto.RelationshipDTO)3 NiFiRestClient (com.thinkbiganalytics.nifi.rest.client.NiFiRestClient)2 ApiOperation (io.swagger.annotations.ApiOperation)2 ApiResponses (io.swagger.annotations.ApiResponses)2 Consumes (javax.ws.rs.Consumes)2