Java Code Examples for org.apache.nifi.scheduling.SchedulingStrategy#valueOf()

The following examples show how to use org.apache.nifi.scheduling.SchedulingStrategy#valueOf() . 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: ProvenanceReportingSchema.java    From nifi-minifi with Apache License 2.0 6 votes vote down vote up
public ProvenanceReportingSchema(Map map) {
    schedulingStrategy = getRequiredKeyAsType(map, SCHEDULING_STRATEGY_KEY, String.class, PROVENANCE_REPORTING_KEY);
    if (schedulingStrategy != null) {
        try {
            SchedulingStrategy.valueOf(schedulingStrategy);
        } catch (IllegalArgumentException e) {
            addValidationIssue(SCHEDULING_STRATEGY_KEY, PROVENANCE_REPORTING_KEY, "it is not a valid scheduling strategy");
        }
    }
    schedulingPeriod = getRequiredKeyAsType(map, SCHEDULING_PERIOD_KEY, String.class, PROVENANCE_REPORTING_KEY);
    comment = getOptionalKeyAsType(map, COMMENT_KEY, String.class, PROVENANCE_REPORTING_KEY, "");

    originatingUrl = getOptionalKeyAsType(map, ORIGINATING_URL_KEY, String.class, PROVENANCE_REPORTING_KEY, DEFAULT_ORGINATING_URL);
    destinationUrl = getRequiredKeyAsType(map, DESTINATION_URL_KEY, String.class, PROVENANCE_REPORTING_KEY);
    portName = getRequiredKeyAsType(map, PORT_NAME_KEY, String.class, PROVENANCE_REPORTING_KEY);
    useCompression = getOptionalKeyAsType(map, USE_COMPRESSION_KEY, Boolean.class, PROVENANCE_REPORTING_KEY, DEFAULT_USE_COMPRESSION);
    timeout = getOptionalKeyAsType(map, TIMEOUT_KEY, String.class, PROVENANCE_REPORTING_KEY, DEFAULT_TIMEOUT);
    batchSize = getOptionalKeyAsType(map, BATCH_SIZE_KEY, Number.class, PROVENANCE_REPORTING_KEY, DEFAULT_BATCH_SIZE);
}
 
Example 2
Source File: StandardReportingTaskDAO.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 3
Source File: StandardFlowSynchronizer.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
private ReportingTaskNode getOrCreateReportingTask(final FlowController controller, final ReportingTaskDTO dto, final boolean controllerInitialized, final boolean existingFlowEmpty)
        throws ReportingTaskInstantiationException {
    // create a new reporting task node when the controller is not initialized or the flow is empty
    if (!controllerInitialized || existingFlowEmpty) {
        final ReportingTaskNode reportingTask = controller.createReportingTask(dto.getType(), dto.getId(), false);
        reportingTask.setName(dto.getName());
        reportingTask.setComments(dto.getComments());
        reportingTask.setSchedulingPeriod(dto.getSchedulingPeriod());
        reportingTask.setSchedulingStrategy(SchedulingStrategy.valueOf(dto.getSchedulingStrategy()));

        reportingTask.setAnnotationData(dto.getAnnotationData());
        reportingTask.setProperties(dto.getProperties());

        final ComponentLog componentLog = new SimpleProcessLogger(dto.getId(), reportingTask.getReportingTask());
        final ReportingInitializationContext config = new StandardReportingInitializationContext(dto.getId(), dto.getName(),
                SchedulingStrategy.valueOf(dto.getSchedulingStrategy()), dto.getSchedulingPeriod(), componentLog, controller, nifiProperties);

        try {
            reportingTask.getReportingTask().initialize(config);
        } catch (final InitializationException ie) {
            throw new ReportingTaskInstantiationException("Failed to initialize reporting task of type " + dto.getType(), ie);
        }

        return reportingTask;
    } else {
        // otherwise return the existing reporting task node
        return controller.getReportingTaskNode(dto.getId());
    }
}
 
Example 4
Source File: ReportingSchema.java    From nifi-minifi with Apache License 2.0 5 votes vote down vote up
public static boolean isSchedulingStrategy(String string) {
    try {
        SchedulingStrategy.valueOf(string);
    } catch (Exception e) {
        return false;
    }
    return true;
}
 
Example 5
Source File: ProcessorSchema.java    From nifi-minifi with Apache License 2.0 5 votes vote down vote up
public static boolean isSchedulingStrategy(String string) {
    try {
        SchedulingStrategy.valueOf(string);
    } catch (Exception e) {
        return false;
    }
    return true;
}
 
Example 6
Source File: StandardReportingTaskDAO.java    From nifi with Apache License 2.0 5 votes vote down vote up
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;
}