private void checkWritingMultipleRecords() throws IOException { if (!allowWritingMultipleRecords && hasWrittenRecord) { StringBuilder message = new StringBuilder(); message.append("The writer attempts to write multiple record although property \'") .append(ROOT_TAG_NAME.getDisplayName()) .append("\' has not been set. If the XMLRecordSetWriter is supposed to write multiple records into one ") .append("FlowFile, this property is required to be configured."); throw new IOException(message.toString() ); } }
private void validateRequiredProperty(PropertyDescriptor property, String value) { if (isEmpty(value)) { throw new IllegalArgumentException(String.format("'%s' is required, but not specified.", property.getDisplayName())); } }
default Optional<ValidationResult> validateRequiredField(ValidationContext context, PropertyDescriptor prop) { if (!context.getProperty(prop).isSet()) { return Optional.of(new ValidationResult.Builder() .subject(prop.getDisplayName()) .valid(false) .explanation(String.format("required by '%s' auth.", this.getClass().getSimpleName())) .build()); } return Optional.empty(); } }
private void buildHeaders(ConfigurationContext context) { headers = new HashMap<>(); for (PropertyDescriptor descriptor : context.getProperties().keySet()) { if (descriptor.isDynamic()) { headers.put( descriptor.getDisplayName(), context.getProperty(descriptor).evaluateAttributeExpressions().getValue() ); } } }
/** * In order to avoid authentication expiration issues (i.e. Kerberos ticket and DelegationToken expiration), * create Atlas client instance at every onTrigger execution. */ private NiFiAtlasClient createNiFiAtlasClient(ReportingContext context) { List<String> urls = new ArrayList<>(); parseAtlasUrls(context.getProperty(ATLAS_URLS), urls::add); try { return new NiFiAtlasClient(atlasAuthN.createClient(urls.toArray(new String[]{}))); } catch (final NullPointerException e) { throw new ProcessException(String.format("Failed to initialize Atlas client due to %s." + " Make sure 'atlas-application.properties' is in the directory specified with %s" + " or under root classpath if not specified.", e, ATLAS_CONF_DIR.getDisplayName()), e); } }
@Override public Collection<ValidationResult> customValidate(final ValidationContext validationContext) { final List<ValidationResult> problems = new ArrayList<>(super.customValidate(validationContext)); final int visibilityTimeout = validationContext.getProperty(VISIBILITY_TIMEOUT).asTimePeriod(TimeUnit.SECONDS).intValue(); if (visibilityTimeout <= 0) { problems.add(new ValidationResult.Builder() .valid(false) .subject(VISIBILITY_TIMEOUT.getDisplayName()) .explanation(VISIBILITY_TIMEOUT.getDisplayName() + " should be greater than 0 secs") .build()); } AzureStorageUtils.validateProxySpec(validationContext, problems); return problems; }
@Override public Collection<ValidationResult> validate(final ValidationContext validationContext, final CredentialsStrategy primaryStrategy) { boolean thisIsSelectedStrategy = this == primaryStrategy; Boolean useStrategy = validationContext.getProperty(strategyProperty).asBoolean(); if (!thisIsSelectedStrategy && useStrategy) { String failureFormat = "property %1$s cannot be used with %2$s"; Collection<ValidationResult> validationFailureResults = new ArrayList<ValidationResult>(); String message = String.format(failureFormat, strategyProperty.getDisplayName(), primaryStrategy.getName()); validationFailureResults.add(new ValidationResult.Builder() .subject(strategyProperty.getDisplayName()) .valid(false) .explanation(message).build()); return validationFailureResults; } return null; }
@Override protected Collection<ValidationResult> customValidate(ValidationContext validationContext) { final List<ValidationResult> results = new ArrayList<>(); final ControllerService recordReader = validationContext.getProperty(RECORD_READER).asControllerService(); final ControllerService recordWriter = validationContext.getProperty(RECORD_WRITER).asControllerService(); if ((recordReader != null && recordWriter == null) || (recordReader == null && recordWriter != null)) { results.add(new ValidationResult.Builder() .subject("Record Reader and Writer") .explanation(String.format("Both %s and %s should be set in order to write FlowFiles as Records.", RECORD_READER.getDisplayName(), RECORD_WRITER.getDisplayName())) .valid(false) .build()); } return results; }
@Override public Collection<ValidationResult> validate(final ValidationContext validationContext, final CredentialsStrategy primaryStrategy) { boolean thisIsSelectedStrategy = this == primaryStrategy; Boolean useStrategy = validationContext.getProperty(strategyProperty).asBoolean(); if (!thisIsSelectedStrategy && (useStrategy == null ? false : useStrategy)) { String failureFormat = "property %1$s cannot be used with %2$s"; Collection<ValidationResult> validationFailureResults = new ArrayList<ValidationResult>(); String message = String.format(failureFormat, strategyProperty.getDisplayName(), primaryStrategy.getName()); validationFailureResults.add(new ValidationResult.Builder() .subject(strategyProperty.getDisplayName()) .valid(false) .explanation(message).build()); return validationFailureResults; } return null; }
@Override protected Collection<ValidationResult> customValidate(ValidationContext validationContext) { final List<ValidationResult> results = new ArrayList<>(super.customValidate(validationContext)); final Long waitTimeoutMillis = validationContext.getProperty(WAIT_TIMEOUT).asTimePeriod(TimeUnit.MICROSECONDS); final Long inactiveTimeoutMillis = validationContext.getProperty(INACTIVE_TIMEOUT).asTimePeriod(TimeUnit.MICROSECONDS); if (waitTimeoutMillis >= inactiveTimeoutMillis) { results.add(new ValidationResult.Builder().input(validationContext.getProperty(INACTIVE_TIMEOUT).getValue()) .subject(INACTIVE_TIMEOUT.getDisplayName()) .explanation(String.format("%s should be longer than %s", INACTIVE_TIMEOUT.getDisplayName(), WAIT_TIMEOUT.getDisplayName())) .valid(false) .build()); } return results; }
@Override protected Collection<ValidationResult> customValidate(ValidationContext validationContext) { final List<ValidationResult> results = new ArrayList<>(RedisUtils.validate(validationContext)); final RedisType redisType = RedisType.fromDisplayName(validationContext.getProperty(RedisUtils.REDIS_MODE).getValue()); if (redisType != null && redisType == RedisType.CLUSTER) { results.add(new ValidationResult.Builder() .subject(RedisUtils.REDIS_MODE.getDisplayName()) .valid(false) .explanation(RedisUtils.REDIS_MODE.getDisplayName() + " is configured in clustered mode, and this service requires a non-clustered Redis") .build()); } return results; }
private Map<String, VersionedPropertyDescriptor> mapPropertyDescriptors(final ComponentNode component) { final Map<String, VersionedPropertyDescriptor> descriptors = new HashMap<>(); for (final PropertyDescriptor descriptor : component.getProperties().keySet()) { final VersionedPropertyDescriptor versionedDescriptor = new VersionedPropertyDescriptor(); versionedDescriptor.setName(descriptor.getName()); versionedDescriptor.setDisplayName(descriptor.getDisplayName()); versionedDescriptor.setIdentifiesControllerService(descriptor.getControllerServiceDefinition() != null); descriptors.put(descriptor.getName(), versionedDescriptor); } return descriptors; }
@Override protected Collection<ValidationResult> customValidate(ValidationContext validationContext) { List<ValidationResult> results = new ArrayList<>(super.customValidate(validationContext)); final PropertyValue columnForPartitioning = validationContext.getProperty(COLUMN_FOR_VALUE_PARTITIONING); // If no EL is present, ensure it's a single column (i.e. no commas in the property value) if (columnForPartitioning.isSet() && !columnForPartitioning.isExpressionLanguagePresent() && columnForPartitioning.getValue().contains(",")) { results.add(new ValidationResult.Builder().valid(false).explanation( COLUMN_FOR_VALUE_PARTITIONING.getDisplayName() + " requires a single column name, but a comma was detected").build()); } return results; }
@Override protected Collection<ValidationResult> customValidate(ValidationContext validationContext) { final String columns = validationContext.getProperty(COLUMNS).getValue(); final String filter = validationContext.getProperty(FILTER_EXPRESSION).getValue(); final List<ValidationResult> problems = new ArrayList<>(); if (!StringUtils.isBlank(columns) && !StringUtils.isBlank(filter)) { problems.add(new ValidationResult.Builder() .subject(FILTER_EXPRESSION.getDisplayName()) .input(filter).valid(false) .explanation("a filter expression can not be used in conjunction with the Columns property") .build()); } return problems; }
static void validateProperties(ValidationContext context, Collection<ValidationResult> results, Scope scope) { validateRequiredProperty(context, results, ListedEntityTracker.TRACKING_STATE_CACHE); validateRequiredProperty(context, results, ListedEntityTracker.TRACKING_TIME_WINDOW); if (Scope.LOCAL.equals(scope) && StringUtils.isEmpty(context.getProperty(NODE_IDENTIFIER).evaluateAttributeExpressions().getValue())) { results.add(new ValidationResult.Builder() .subject(NODE_IDENTIFIER.getDisplayName()) .explanation(format("'%s' is required to use local scope with '%s' listing strategy", NODE_IDENTIFIER.getDisplayName(), AbstractListProcessor.BY_ENTITIES.getDisplayName())) .build()); } }
@Override protected Collection<ValidationResult> customValidate(ValidationContext validationContext) { final List<ValidationResult> results = new ArrayList<>(super.customValidate(validationContext)); Validator validator = new RecordPathValidator(); Map<PropertyDescriptor, String> processorProperties = validationContext.getProperties(); for (final Map.Entry<PropertyDescriptor, String> entry : processorProperties.entrySet()) { PropertyDescriptor property = entry.getKey(); if (property.isDynamic() && property.isExpressionLanguageSupported()) { String dynamicValue = validationContext.getProperty(property).getValue(); if(!validationContext.isExpressionLanguagePresent(dynamicValue)) { results.add(validator.validate(property.getDisplayName(), dynamicValue, validationContext)); } } } return results; }
private static void validateRequiredProperty(ValidationContext context, Collection<ValidationResult> results, PropertyDescriptor property) { if (!context.getProperty(property).isSet()) { final String displayName = property.getDisplayName(); results.add(new ValidationResult.Builder() .subject(displayName) .explanation(format("'%s' is required to use '%s' listing strategy", displayName, AbstractListProcessor.BY_ENTITIES.getDisplayName())) .valid(false) .build()); } }
@Override public void onPropertyModified(PropertyDescriptor descriptor, String oldValue, String newValue) { if ( ((oldValue != null && !oldValue.equals(newValue))) && (descriptor.equals(QUERY) || descriptor.equals(TIME_FIELD_STRATEGY) || descriptor.equals(TIME_RANGE_STRATEGY) || descriptor.equals(EARLIEST_TIME) || descriptor.equals(LATEST_TIME) || descriptor.equals(HOSTNAME)) ) { getLogger().debug("A property that require resetting state was modified - {} oldValue {} newValue {}", new Object[] {descriptor.getDisplayName(), oldValue, newValue}); resetState = true; } }
@Override protected Collection<ValidationResult> customValidate(ValidationContext validationContext) { final List<ValidationResult> results = new ArrayList<>(); if (validationContext.getProperty(BASIC_AUTH).asBoolean()) { final String loginServiceValue = validationContext.getProperty(LOGIN_SERVICE).getValue(); if (LOGIN_SERVICE_HASH.equals(loginServiceValue)) { if (!validationContext.getProperty(USERS_PROPERTIES_FILE).isSet()) { results.add(new ValidationResult.Builder().subject(USERS_PROPERTIES_FILE.getDisplayName()) .explanation("it is required by HashLoginService").valid(false).build()); } } } return results; }
private void writeProperty(final PropertyDescriptor property) throws IOException { writeStartElement("property"); writeTextElement("name", property.getName()); writeTextElement("displayName", property.getDisplayName()); writeTextElement("description", property.getDescription()); writeTextElement("defaultValue", property.getDefaultValue()); writeTextElement("controllerServiceDefinition", property.getControllerServiceDefinition() == null ? null : property.getControllerServiceDefinition().getName()); writeTextArray("allowableValues", "allowableValue", property.getAllowableValues(), AllowableValue::getDisplayName); writeBooleanElement("required", property.isRequired()); writeBooleanElement("sensitive", property.isSensitive()); writeBooleanElement("expressionLanguageSupported", property.isExpressionLanguageSupported()); writeTextElement("expressionLanguageScope", property.getExpressionLanguageScope() == null ? null : property.getExpressionLanguageScope().name()); writeBooleanElement("dynamicallyModifiesClasspath", property.isDynamicClasspathModifier()); writeBooleanElement("dynamic", property.isDynamic()); writeEndElement(); }