private boolean isValueAllowed(final String value) { if (allowableValues == null || value == null) { return true; } for (final AllowableValue allowableValue : allowableValues) { if (allowableValue.getValue().equals(value)) { return true; } } return false; }
/** * @param values contrained set of getAllFields * @return the builder */ public Builder allowableValues(final Set<String> values) { if (null != values) { this.allowableValues = new ArrayList<>(); for (final String value : values) { this.allowableValues.add(new AllowableValue(value, value)); } } return this; }
/** * Interrogates a PropertyDescriptor to get a list of AllowableValues, if * there are none, nothing is written to the stream. * * @param property the property to describe * @throws XMLStreamException thrown if there was a problem writing to the * XML Stream */ protected void writeValidValues(JsonGenerator generator, PropertyDescriptor property) throws IOException { if (property.getAllowableValues() != null && property.getAllowableValues().size() > 0) { for (AllowableValue value : property.getAllowableValues()) { generator.writeStringField(value.getDisplayName(), value.getDescription()); } } }
/** * @return true if <code>this</code> is equal to <code>obj</code> of <code>obj</code> is the * same object as <code>this</code> or if <code>obj</code> is an instance of * <code>AllowableValue</code> and both have the same value, or if * <code>obj</code> is a String and is equal to * {@link #getValue() this.getRawValue()}. */ @Override public boolean equals(final Object obj) { if (obj == this) { return true; } if (obj instanceof AllowableValue) { final AllowableValue other = (AllowableValue) obj; return (this.value.equals(other.getValue())); } else if (obj instanceof String) { return this.value.equals(obj); } return false; }
/** * Interrogates a PropertyDescriptor to get a list of AllowableValues, if * there are none, nothing is written to the stream. * * @param xmlStreamWriter the stream writer to use * @param property the property to describe * @throws XMLStreamException thrown if there was a problem writing to the * XML Stream */ protected void writeValidValues(XMLStreamWriter xmlStreamWriter, PropertyDescriptor property) throws XMLStreamException { if (property.getAllowableValues() != null && property.getAllowableValues().size() > 0) { xmlStreamWriter.writeStartElement("ul"); for (AllowableValue value : property.getAllowableValues()) { xmlStreamWriter.writeStartElement("li"); xmlStreamWriter.writeCharacters(value.getDisplayName()); if (value.getDescription() != null) { writeValidValueDescription(xmlStreamWriter, value.getDescription()); } xmlStreamWriter.writeEndElement(); } xmlStreamWriter.writeEndElement(); } }
/** * @param values constrained set of getAllFields * @return the builder */ public Builder allowableValues(final String... values) { if (null != values) { this.allowableValues = new ArrayList<>(); for (final String value : values) { allowableValues.add(new AllowableValue(value, value)); } } return this; }
/** * Constructs a validator that will check if the given value is in the * given set. * * @param validValues getAllFields which are acceptible * @throws NullPointerException if the given validValues is null */ private ConstrainedSetValidator(final Collection<AllowableValue> validValues) { String validVals = ""; if (!validValues.isEmpty()) { final StringBuilder valuesBuilder = new StringBuilder(); for (final AllowableValue value : validValues) { valuesBuilder.append(value).append(VALUE_DEMARCATOR); } validVals = valuesBuilder.substring(0, valuesBuilder.length() - VALUE_DEMARCATOR.length()); } validStrings = validVals; this.validValues = new ArrayList<>(validValues.size()); for (final AllowableValue value : validValues) { this.validValues.add(value.getValue()); } }
/** * Interrogates a PropertyDescriptor to get a list of AllowableValues, if * there are none, nothing is written to the stream. * * @param rstWriter the stream writer to use * @param property the property to describe * @throws XMLStreamException thrown if there was a problem writing to the * XML Stream */ protected void writeValidValues(RstPrintWriter rstWriter, PropertyDescriptor property){ if (property.getAllowableValues() != null && property.getAllowableValues().size() > 0) { boolean first = true; for (AllowableValue value : property.getAllowableValues()) { if (!first) { rstWriter.print(", "); } else { first = false; } rstWriter.print(value.getDisplayName()); if (value.getDescription() != null) { writeValidValueDescription(rstWriter, " (" + value.getDescription() + ")"); } } } }
public <E extends Enum<E>> Builder allowableValues(final E[] values) { if (null != values) { this.allowableValues = new ArrayList<>(); for (final E value : values) { allowableValues.add(new AllowableValue(value.name(), value.name())); } } return this; }
/** * build a recordSerializer * * @param inSerializerClass the recordSerializer type * @param schemaContent an Avro schema * @return the recordSerializer */ private RecordSerializer getSerializer(String inSerializerClass, String schemaContent) { if (inSerializerClass.equals(AVRO_SERIALIZER.getValue())) { Schema.Parser parser = new Schema.Parser(); Schema inSchema = parser.parse(schemaContent); new AvroSerializer(inSchema); } else if (inSerializerClass.equals(JSON_SERIALIZER.getValue())) { return new JsonSerializer(); } else if (inSerializerClass.equals(BYTESARRAY_SERIALIZER.getValue())) { return new BytesArraySerializer(); } else if (inSerializerClass.equals(KURA_PROTOCOL_BUFFER_SERIALIZER.getValue())) { return new KuraProtobufSerializer(); } return new KryoSerializer(true); }
@Override public Collection<Record> process(final ProcessContext context, final Collection<Record> collection) { String[] recordTypesToInclude = context.getPropertyValue(RECORD_TYPES).asString().split(","); if (collection.size() != 0) { RecordSerializer serializer = null; if (context.getPropertyValue(SERIALIZER).asString().equals(JSON.getValue())) { serializer = new JsonSerializer(); } else { serializer = new StringSerializer(); } final RecordSerializer finalSerializer = serializer; collection.forEach(event -> { ByteArrayOutputStream baos = new ByteArrayOutputStream(); finalSerializer.serialize(baos, event); try { baos.close(); } catch (IOException e) { logger.debug("error {} ", e.getCause()); } logger.info(new String(baos.toByteArray())); }); } return collection; }
private void extractValueFields(String[] valueFields, Record outputRecord, Matcher valueMatcher, ProcessContext context) { String conflictPolicy = context.getPropertyValue(CONFLICT_RESOLUTION_POLICY).asString(); for (int i = 0; i < Math.min(valueMatcher.groupCount() + 1, valueFields.length); i++) { String content = valueMatcher.group(i + 1); String fieldName = valueFields[i]; if (content != null) { if (outputRecord.hasField(fieldName) && (outputRecord.getField(fieldName).asString() != null) && (! outputRecord.getField(fieldName).asString().isEmpty())) { if (conflictPolicy.equals(OVERWRITE_EXISTING.getValue())) { outputRecord.setStringField(fieldName, content.replaceAll("\"", "")); } } else { outputRecord.setStringField(fieldName, content.replaceAll("\"", "")); } } } }
private void updateRecord(ProcessContext context, Record record, Map<String, String> fieldsNameMapping) { String conflictPolicy = context.getPropertyValue(CONFLICT_RESOLUTION_POLICY).asString(); if ((fieldsNameMapping == null) || (fieldsNameMapping.keySet() == null)) { return; } fieldsNameMapping.keySet().forEach(addedFieldName -> { final String defaultValueToAdd = context.getPropertyValue(addedFieldName).evaluate(record).asString(); // field is already here if (record.hasField(addedFieldName)) { if (conflictPolicy.equals(OVERWRITE_EXISTING.getValue())) { overwriteObsoleteFieldValue(record, addedFieldName, defaultValueToAdd); } } else { record.setStringField(addedFieldName, defaultValueToAdd); } }); }
if (conflictPolicy.equals(KEEP_ONLY_OLD_FIELD.getValue())) { for (String obsoleteFieldName : obsoleteFieldNames) { if (record.hasField(obsoleteFieldName)) { } else if (conflictPolicy.equals(OVERWRITE_EXISTING.getValue())) { for (String obsoleteFieldName : obsoleteFieldNames) { overwriteObsoleteFieldName(record, normalizedFieldName, obsoleteFieldName); }else if (conflictPolicy.equals(KEEP_BOTH_FIELDS.getValue())) { for (String obsoleteFieldName : obsoleteFieldNames) { if (record.hasField(obsoleteFieldName)) {
if (context.getPropertyValue(TIMEBASED_INDEX).isSet()) { final SimpleDateFormat sdf = new SimpleDateFormat(context.getPropertyValue(DATE_FORMAT).asString()); if (context.getPropertyValue(TIMEBASED_INDEX).getRawValue().equals(TODAY_DATE_SUFFIX.getValue())) { defaultCollection += "." + sdf.format(new Date()); } else if (context.getPropertyValue(TIMEBASED_INDEX).getRawValue().equals(YESTERDAY_DATE_SUFFIX.getValue())) { DateTime dt = new DateTime(new Date()).minusDays(1); defaultCollection += "." + sdf.format(dt.toDate());
/** * set up BackoffPolicy */ private BackoffPolicy getBackOffPolicy(ControllerServiceInitializationContext context) { BackoffPolicy backoffPolicy = BackoffPolicy.exponentialBackoff(); if (context.getPropertyValue(BULK_BACK_OFF_POLICY).getRawValue().equals(DEFAULT_EXPONENTIAL_BACKOFF_POLICY.getValue())) { backoffPolicy = BackoffPolicy.exponentialBackoff(); } else if (context.getPropertyValue(BULK_BACK_OFF_POLICY).getRawValue().equals(EXPONENTIAL_BACKOFF_POLICY.getValue())) { backoffPolicy = BackoffPolicy.exponentialBackoff( TimeValue.timeValueMillis(context.getPropertyValue(BULK_THROTTLING_DELAY).asLong()), context.getPropertyValue(BULK_RETRY_NUMBER).asInteger() ); } else if (context.getPropertyValue(BULK_BACK_OFF_POLICY).getRawValue().equals(CONSTANT_BACKOFF_POLICY.getValue())) { backoffPolicy = BackoffPolicy.constantBackoff( TimeValue.timeValueMillis(context.getPropertyValue(BULK_THROTTLING_DELAY).asLong()), context.getPropertyValue(BULK_RETRY_NUMBER).asInteger() ); } else if (context.getPropertyValue(BULK_BACK_OFF_POLICY).getRawValue().equals(NO_BACKOFF_POLICY.getValue())) { backoffPolicy = BackoffPolicy.noBackoff(); } return backoffPolicy; }
@Override public void init(ProcessContext context) { if (context.getPropertyValue(STRATEGY).isSet()) { if (context.getPropertyValue(STRATEGY).getRawValue().equals(RANDOM_UUID_STRATEGY.getValue())) { idBuilder = new IdBuilder() { @Override } else if (context.getPropertyValue(STRATEGY).getRawValue().equals(HASH_FIELDS_STRATEGY.getValue())) { final List<String> fieldsForHash = Lists.newArrayList( context.getPropertyValue(FIELDS_TO_USE).asString().split(",")); throw new Error("This error should not happen because the validator should ensure the algorythme exist", e); } else if (context.getPropertyValue(STRATEGY).getRawValue().equals(JAVA_FORMAT_STRING_WITH_FIELDS_STRATEGY.getValue())) { final String[] fieldsForFormat = context.getPropertyValue(FIELDS_TO_USE).asString().split(","); final String format = context.getPropertyValue(JAVA_FORMAT_STRING).asString(); } else if (context.getPropertyValue(STRATEGY).getRawValue().equals(TYPE_TIME_HASH_STRATEGY.getValue())) { final List<String> fieldsForHash = Lists.newArrayList( context.getPropertyValue(FIELDS_TO_USE).asString().split(","));
if (context.getPropertyValue(TIMEBASED_INDEX).isSet()) { final SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd"); if (context.getPropertyValue(TIMEBASED_INDEX).getRawValue().equals(TODAY_DATE_SUFFIX.getValue())) { defaultIndex += "." + sdf.format(new Date()); } else if (context.getPropertyValue(TIMEBASED_INDEX).getRawValue().equals(YESTERDAY_DATE_SUFFIX.getValue())) { DateTime dt = new DateTime(new Date()).minusDays(1); defaultIndex += "." + sdf.format(dt.toDate());
@Override protected Collection<ValidationResult> customValidate(ValidationContext context) { final List<ValidationResult> validationResults = new ArrayList<>(super.customValidate(context)); if (context.getPropertyValue(STRATEGY).isSet()) { if (context.getPropertyValue(STRATEGY).getRawValue().equals(JAVA_FORMAT_STRING_WITH_FIELDS_STRATEGY.getValue())) { if (!context.getPropertyValue(JAVA_FORMAT_STRING).isSet()) { validationResults.add( new ValidationResult.Builder() .input(JAVA_FORMAT_STRING.getName()) .explanation(String.format("%s must be set when strategy is %s", JAVA_FORMAT_STRING.getName(), context.getPropertyValue(STRATEGY).getRawValue())) .valid(false) .build()); } } } return validationResults; }
if (RedisUtils.REDIS_MODE_STANDALONE.getValue().equals(redisMode)) { final JedisShardInfo jedisShardInfo = createJedisShardInfo(connectionString, timeout, password); connectionFactory = new JedisConnectionFactory(jedisShardInfo); } else if (RedisUtils.REDIS_MODE_SENTINEL.getValue().equals(redisMode)) { final String[] sentinels = connectionString.split("[,]"); final String sentinelMaster = context.getPropertyValue(RedisUtils.SENTINEL_MASTER).asString();