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;
}
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;
}
Aggregations