public final RecordSchema getSchema(final Map<String, String> variables, final InputStream contentStream, final RecordSchema readSchema) throws SchemaNotFoundException, IOException { final SchemaAccessStrategy accessStrategy = getSchemaAccessStrategy(); if (accessStrategy == null) { throw new SchemaNotFoundException("Could not determine the Schema Access Strategy for this service"); } return getSchemaAccessStrategy().getSchema(variables, contentStream, readSchema); }
@Override protected Collection<ValidationResult> customValidate(final ValidationContext validationContext) { final String schemaAccessStrategy = validationContext.getProperty(getSchemaAcessStrategyDescriptor()).getValue(); return SchemaAccessUtils.validateSchemaAccessStrategy(validationContext, schemaAccessStrategy, getSchemaAccessStrategyValues()); }
@Override protected List<PropertyDescriptor> getSupportedPropertyDescriptors() { final List<PropertyDescriptor> properties = new ArrayList<>(2); final AllowableValue[] strategies = getSchemaAccessStrategyValues().toArray(new AllowableValue[0]); properties.add(buildStrategyProperty(strategies)); properties.add(SCHEMA_REGISTRY); properties.add(SCHEMA_NAME); properties.add(SCHEMA_VERSION); properties.add(SCHEMA_BRANCH_NAME); properties.add(SCHEMA_TEXT); return properties; }
protected Set<SchemaField> getSuppliedSchemaFields(final ValidationContext validationContext) { final String accessStrategyValue = validationContext.getProperty(getSchemaAcessStrategyDescriptor()).getValue(); final SchemaRegistry schemaRegistry = validationContext.getProperty(SCHEMA_REGISTRY).asControllerService(SchemaRegistry.class); final SchemaAccessStrategy accessStrategy = getSchemaAccessStrategy(accessStrategyValue, schemaRegistry, validationContext); if (accessStrategy == null) { return EnumSet.noneOf(SchemaField.class); } final Set<SchemaField> suppliedFields = accessStrategy.getSuppliedSchemaFields(); return suppliedFields; }
@Override protected List<AllowableValue> getSchemaAccessStrategyValues() { final List<AllowableValue> allowableValues = new ArrayList<>(super.getSchemaAccessStrategyValues()); allowableValues.add(headerDerivedAllowableValue); return allowableValues; }
@Override protected List<PropertyDescriptor> getSupportedPropertyDescriptors() { final List<PropertyDescriptor> properties = new ArrayList<>(super.getSupportedPropertyDescriptors()); properties.add(CACHE_SIZE); return properties; }
protected PropertyDescriptor buildStrategyProperty(AllowableValue[] values) { return new PropertyDescriptor.Builder() .fromPropertyDescriptor(SCHEMA_ACCESS_STRATEGY) .allowableValues(values) .defaultValue(getDefaultSchemaAccessStrategy().getValue()) .build(); }
protected PropertyDescriptor getSchemaAcessStrategyDescriptor() { return getPropertyDescriptor(SCHEMA_ACCESS_STRATEGY.getName()); }
public RecordSchema getSchema(final Map<String, String> variables, final RecordSchema readSchema) throws SchemaNotFoundException, IOException { return getSchema(variables, EMPTY_INPUT_STREAM, readSchema); }
@Override protected Collection<ValidationResult> customValidate(final ValidationContext validationContext) { final List<ValidationResult> results = new ArrayList<>(super.customValidate(validationContext)); final Set<SchemaField> suppliedFields = getSuppliedSchemaFields(validationContext); final Set<SchemaField> requiredFields = getRequiredSchemaFields(validationContext); final Set<SchemaField> missingFields = new HashSet<>(requiredFields); missingFields.removeAll(suppliedFields); if (!missingFields.isEmpty()) { results.add(new ValidationResult.Builder() .subject("Schema Access Strategy") .valid(false) .explanation("The configured Schema Write Strategy requires the " + missingFields.iterator().next() + " but the configured Schema Access Strategy does not provide this information in conjunction with the selected Schema Registry. " + "This Schema Access Strategy, as configured, cannot be used in conjunction with this Schema Write Strategy.") .build()); } return results; } }
@OnEnabled public void storeSchemaAccessStrategy(final ConfigurationContext context) { this.configurationContext = context; final SchemaRegistry schemaRegistry = context.getProperty(SCHEMA_REGISTRY).asControllerService(SchemaRegistry.class); final PropertyDescriptor descriptor = getSchemaAcessStrategyDescriptor(); final String schemaAccess = context.getProperty(descriptor).getValue(); this.schemaAccessStrategy = getSchemaAccessStrategy(schemaAccess, schemaRegistry, context); }
@Override protected List<AllowableValue> getSchemaAccessStrategyValues() { final List<AllowableValue> allowableValues = new ArrayList<>(super.getSchemaAccessStrategyValues()); allowableValues.add(EMBEDDED_AVRO_SCHEMA); return allowableValues; }
@Override protected List<PropertyDescriptor> getSupportedPropertyDescriptors() { final List<PropertyDescriptor> properties = new ArrayList<>(super.getSupportedPropertyDescriptors()); properties.add(DateTimeUtils.DATE_FORMAT); properties.add(DateTimeUtils.TIME_FORMAT); properties.add(DateTimeUtils.TIMESTAMP_FORMAT); return properties; }
protected PropertyDescriptor buildStrategyProperty(AllowableValue[] values) { return new PropertyDescriptor.Builder() .fromPropertyDescriptor(SCHEMA_ACCESS_STRATEGY) .allowableValues(values) .defaultValue(getDefaultSchemaAccessStrategy().getValue()) .build(); }
protected PropertyDescriptor getSchemaAcessStrategyDescriptor() { return getPropertyDescriptor(SCHEMA_ACCESS_STRATEGY.getName()); }
public RecordSchema getSchema(final Map<String, String> variables, final RecordSchema readSchema) throws SchemaNotFoundException, IOException { return getSchema(variables, EMPTY_INPUT_STREAM, readSchema); }
@Override protected Collection<ValidationResult> customValidate(final ValidationContext validationContext) { ArrayList<ValidationResult> results = new ArrayList<>(super.customValidate(validationContext)); // validate the grok expression against configuration GrokCompiler grokCompiler = GrokCompiler.newInstance(); String subject = GROK_EXPRESSION.getName(); String input = validationContext.getProperty(GROK_EXPRESSION).getValue(); GrokExpressionValidator validator; try (final InputStream in = getClass().getResourceAsStream(DEFAULT_PATTERN_NAME); final Reader reader = new InputStreamReader(in)) { grokCompiler.register(reader); } catch (IOException e) { results.add(new ValidationResult.Builder() .input(input) .subject(subject) .valid(false) .explanation("Unable to load default patterns: " + e.getMessage()) .build()); } validator = new GrokExpressionValidator(validationContext.getProperty(PATTERN_FILE).getValue(),grokCompiler); results.add(validator.validate(subject,input,validationContext)); return results; }
protected Set<SchemaField> getSuppliedSchemaFields(final ValidationContext validationContext) { final String accessStrategyValue = validationContext.getProperty(getSchemaAcessStrategyDescriptor()).getValue(); final SchemaRegistry schemaRegistry = validationContext.getProperty(SCHEMA_REGISTRY).asControllerService(SchemaRegistry.class); final SchemaAccessStrategy accessStrategy = getSchemaAccessStrategy(accessStrategyValue, schemaRegistry, validationContext); if (accessStrategy == null) { return EnumSet.noneOf(SchemaField.class); } final Set<SchemaField> suppliedFields = accessStrategy.getSuppliedSchemaFields(); return suppliedFields; }
@Override protected SchemaAccessStrategy getSchemaAccessStrategy(final String strategy, final SchemaRegistry schemaRegistry, final ValidationContext context) { if (strategy.equalsIgnoreCase(STRING_FIELDS_FROM_GROK_EXPRESSION.getValue())) { return createAccessStrategy(); } else { return super.getSchemaAccessStrategy(strategy, schemaRegistry, context); } }
@Override protected Collection<ValidationResult> customValidate(final ValidationContext validationContext) { final String schemaAccessStrategy = validationContext.getProperty(getSchemaAcessStrategyDescriptor()).getValue(); return SchemaAccessUtils.validateSchemaAccessStrategy(validationContext, schemaAccessStrategy, getSchemaAccessStrategyValues()); }