Search in sources :

Example 1 with SchedulingStrategy

use of org.apache.nifi.scheduling.SchedulingStrategy in project nifi by apache.

the class StandardProcessorDAO method validateProposedConfiguration.

private List<String> validateProposedConfiguration(final ProcessorNode processorNode, final ProcessorConfigDTO config) {
    List<String> validationErrors = new ArrayList<>();
    // validate settings
    if (isNotNull(config.getPenaltyDuration())) {
        Matcher penaltyMatcher = FormatUtils.TIME_DURATION_PATTERN.matcher(config.getPenaltyDuration());
        if (!penaltyMatcher.matches()) {
            validationErrors.add("Penalty duration is not a valid time duration (ie 30 sec, 5 min)");
        }
    }
    if (isNotNull(config.getYieldDuration())) {
        Matcher yieldMatcher = FormatUtils.TIME_DURATION_PATTERN.matcher(config.getYieldDuration());
        if (!yieldMatcher.matches()) {
            validationErrors.add("Yield duration is not a valid time duration (ie 30 sec, 5 min)");
        }
    }
    if (isNotNull(config.getBulletinLevel())) {
        try {
            LogLevel.valueOf(config.getBulletinLevel());
        } catch (IllegalArgumentException iae) {
            validationErrors.add(String.format("Bulletin level: Value must be one of [%s]", StringUtils.join(LogLevel.values(), ", ")));
        }
    }
    if (isNotNull(config.getExecutionNode())) {
        try {
            ExecutionNode.valueOf(config.getExecutionNode());
        } catch (IllegalArgumentException iae) {
            validationErrors.add(String.format("Execution node: Value must be one of [%s]", StringUtils.join(ExecutionNode.values(), ", ")));
        }
    }
    // get the current scheduling strategy
    SchedulingStrategy schedulingStrategy = processorNode.getSchedulingStrategy();
    // validate the new scheduling strategy if appropriate
    if (isNotNull(config.getSchedulingStrategy())) {
        try {
            // this will be the new scheduling strategy so use it
            schedulingStrategy = SchedulingStrategy.valueOf(config.getSchedulingStrategy());
        } catch (IllegalArgumentException iae) {
            validationErrors.add(String.format("Scheduling strategy: Value must be one of [%s]", StringUtils.join(SchedulingStrategy.values(), ", ")));
        }
    }
    // validate the concurrent tasks based on the scheduling strategy
    if (isNotNull(config.getConcurrentlySchedulableTaskCount())) {
        switch(schedulingStrategy) {
            case TIMER_DRIVEN:
            case PRIMARY_NODE_ONLY:
                if (config.getConcurrentlySchedulableTaskCount() <= 0) {
                    validationErrors.add("Concurrent tasks must be greater than 0.");
                }
                break;
            case EVENT_DRIVEN:
                if (config.getConcurrentlySchedulableTaskCount() < 0) {
                    validationErrors.add("Concurrent tasks must be greater or equal to 0.");
                }
                break;
        }
    }
    // validate the scheduling period based on the scheduling strategy
    if (isNotNull(config.getSchedulingPeriod())) {
        switch(schedulingStrategy) {
            case TIMER_DRIVEN:
            case PRIMARY_NODE_ONLY:
                final Matcher schedulingMatcher = FormatUtils.TIME_DURATION_PATTERN.matcher(config.getSchedulingPeriod());
                if (!schedulingMatcher.matches()) {
                    validationErrors.add("Scheduling period is not a valid time duration (ie 30 sec, 5 min)");
                }
                break;
            case CRON_DRIVEN:
                try {
                    new CronExpression(config.getSchedulingPeriod());
                } catch (final ParseException pe) {
                    throw new IllegalArgumentException(String.format("Scheduling Period '%s' is not a valid cron expression: %s", config.getSchedulingPeriod(), pe.getMessage()));
                } catch (final Exception e) {
                    throw new IllegalArgumentException("Scheduling Period is not a valid cron expression: " + config.getSchedulingPeriod());
                }
                break;
        }
    }
    final Set<String> autoTerminatedRelationships = config.getAutoTerminatedRelationships();
    if (isNotNull(autoTerminatedRelationships)) {
        for (final String relationshipName : autoTerminatedRelationships) {
            final Relationship relationship = new Relationship.Builder().name(relationshipName).build();
            final Set<Connection> connections = processorNode.getConnections(relationship);
            if (isNotNull(connections) && !connections.isEmpty()) {
                validationErrors.add("Cannot automatically terminate '" + relationshipName + "' relationship because a Connection already exists with this relationship");
            }
        }
    }
    return validationErrors;
}
Also used : Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) Connection(org.apache.nifi.connectable.Connection) ProcessorInstantiationException(org.apache.nifi.controller.exception.ProcessorInstantiationException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) ResourceNotFoundException(org.apache.nifi.web.ResourceNotFoundException) ParseException(java.text.ParseException) ComponentLifeCycleException(org.apache.nifi.controller.exception.ComponentLifeCycleException) NiFiCoreException(org.apache.nifi.web.NiFiCoreException) ValidationException(org.apache.nifi.controller.exception.ValidationException) SchedulingStrategy(org.apache.nifi.scheduling.SchedulingStrategy) Relationship(org.apache.nifi.processor.Relationship) CronExpression(org.quartz.CronExpression) ParseException(java.text.ParseException)

Example 2 with SchedulingStrategy

use of org.apache.nifi.scheduling.SchedulingStrategy in project nifi by apache.

the class StandardReportingTaskDAO method validateProposedConfiguration.

private List<String> validateProposedConfiguration(final ReportingTaskNode reportingTask, final ReportingTaskDTO reportingTaskDTO) {
    final List<String> validationErrors = new ArrayList<>();
    // get the current scheduling strategy
    SchedulingStrategy schedulingStrategy = reportingTask.getSchedulingStrategy();
    // validate the new scheduling strategy if appropriate
    if (isNotNull(reportingTaskDTO.getSchedulingStrategy())) {
        try {
            // this will be the new scheduling strategy so use it
            schedulingStrategy = SchedulingStrategy.valueOf(reportingTaskDTO.getSchedulingStrategy());
        } catch (IllegalArgumentException iae) {
            validationErrors.add(String.format("Scheduling strategy: Value must be one of [%s]", StringUtils.join(SchedulingStrategy.values(), ", ")));
        }
    }
    // validate the scheduling period based on the scheduling strategy
    if (isNotNull(reportingTaskDTO.getSchedulingPeriod())) {
        switch(schedulingStrategy) {
            case TIMER_DRIVEN:
                final Matcher schedulingMatcher = FormatUtils.TIME_DURATION_PATTERN.matcher(reportingTaskDTO.getSchedulingPeriod());
                if (!schedulingMatcher.matches()) {
                    validationErrors.add("Scheduling period is not a valid time duration (ie 30 sec, 5 min)");
                }
                break;
            case CRON_DRIVEN:
                try {
                    new CronExpression(reportingTaskDTO.getSchedulingPeriod());
                } catch (final ParseException pe) {
                    throw new IllegalArgumentException(String.format("Scheduling Period '%s' is not a valid cron expression: %s", reportingTaskDTO.getSchedulingPeriod(), pe.getMessage()));
                } catch (final Exception e) {
                    throw new IllegalArgumentException("Scheduling Period is not a valid cron expression: " + reportingTaskDTO.getSchedulingPeriod());
                }
                break;
        }
    }
    return validationErrors;
}
Also used : SchedulingStrategy(org.apache.nifi.scheduling.SchedulingStrategy) Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) CronExpression(org.quartz.CronExpression) ParseException(java.text.ParseException) ReportingTaskInstantiationException(org.apache.nifi.controller.reporting.ReportingTaskInstantiationException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) ResourceNotFoundException(org.apache.nifi.web.ResourceNotFoundException) ParseException(java.text.ParseException) ComponentLifeCycleException(org.apache.nifi.controller.exception.ComponentLifeCycleException) NiFiCoreException(org.apache.nifi.web.NiFiCoreException) ValidationException(org.apache.nifi.controller.exception.ValidationException)

Aggregations

ParseException (java.text.ParseException)2 ArrayList (java.util.ArrayList)2 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)2 Matcher (java.util.regex.Matcher)2 ComponentLifeCycleException (org.apache.nifi.controller.exception.ComponentLifeCycleException)2 ValidationException (org.apache.nifi.controller.exception.ValidationException)2 SchedulingStrategy (org.apache.nifi.scheduling.SchedulingStrategy)2 NiFiCoreException (org.apache.nifi.web.NiFiCoreException)2 ResourceNotFoundException (org.apache.nifi.web.ResourceNotFoundException)2 CronExpression (org.quartz.CronExpression)2 Connection (org.apache.nifi.connectable.Connection)1 ProcessorInstantiationException (org.apache.nifi.controller.exception.ProcessorInstantiationException)1 ReportingTaskInstantiationException (org.apache.nifi.controller.reporting.ReportingTaskInstantiationException)1 Relationship (org.apache.nifi.processor.Relationship)1