Search in sources :

Example 1 with SubstitutionConfig

use of com.nextdoor.bender.operation.substitution.SubstitutionConfig in project bender by Nextdoor.

the class GelfOperationFactoryTest method foo.

@Test
public void foo() {
    GelfOperationConfig config = new GelfOperationConfig();
    config.setSrcHostField(Arrays.asList("foo_host"));
    config.setSrcShortMessageField(Arrays.asList("foo_short_message", "bar"));
    config.setSrcFileField(Arrays.asList("filename"));
    GelfOperationFactory factory = new GelfOperationFactory();
    factory.setConf(config);
    GelfOperation op = factory.newInstance();
    List<SubstitutionConfig> actual = factory.getSubConfigs();
    ArrayList<SubstitutionConfig> expected = new ArrayList<SubstitutionConfig>();
    expected.add(new FieldSubstitutionConfig("host", Arrays.asList("foo_host"), false, true, true));
    expected.add(new FieldSubstitutionConfig("file", Arrays.asList("filename"), false, false, false));
    expected.add(new FieldSubstitutionConfig("short_message", Arrays.asList("foo_short_message", "bar"), false, true, true));
    expected.add(new StaticSubstitutionConfig("version", "1.1", true));
    Collections.sort(expected, Comparator.comparingInt(Object::hashCode));
    Collections.sort(actual, Comparator.comparingInt(Object::hashCode));
    assertEquals(expected, actual);
}
Also used : StaticSubstitutionConfig(com.nextdoor.bender.operation.substitution.ztatic.StaticSubstitutionConfig) FieldSubstitutionConfig(com.nextdoor.bender.operation.substitution.field.FieldSubstitutionConfig) GelfOperationConfig(com.nextdoor.bender.operation.gelf.GelfOperationConfig) GelfOperation(com.nextdoor.bender.operation.gelf.GelfOperation) ArrayList(java.util.ArrayList) GelfOperationFactory(com.nextdoor.bender.operation.gelf.GelfOperationFactory) SubstitutionConfig(com.nextdoor.bender.operation.substitution.SubstitutionConfig) FieldSubstitutionConfig(com.nextdoor.bender.operation.substitution.field.FieldSubstitutionConfig) StaticSubstitutionConfig(com.nextdoor.bender.operation.substitution.ztatic.StaticSubstitutionConfig) Test(org.junit.Test)

Example 2 with SubstitutionConfig

use of com.nextdoor.bender.operation.substitution.SubstitutionConfig in project bender by Nextdoor.

the class GelfOperationFactory method setConf.

@Override
public void setConf(AbstractConfig config) {
    this.config = (GelfOperationConfig) config;
    ArrayList<SubstitutionConfig> subConfigs = new ArrayList<SubstitutionConfig>();
    subConfigs.add(new StaticSubstitutionConfig("version", "1.1", true));
    if (this.config.getSrcHostField() != null) {
        subConfigs.add(new FieldSubstitutionConfig("host", this.config.getSrcHostField(), false, true, true));
    }
    if (this.config.getSrcShortMessageField() != null) {
        subConfigs.add(new FieldSubstitutionConfig("short_message", this.config.getSrcShortMessageField(), false, true, true));
    }
    if (this.config.getSrcFullMessageField() != null) {
        subConfigs.add(new FieldSubstitutionConfig("full_message", this.config.getSrcFullMessageField(), false, false, true));
    }
    if (this.config.getSrcTimestampField() != null) {
        subConfigs.add(new FieldSubstitutionConfig("timestamp", this.config.getSrcTimestampField(), false, false, true));
    }
    if (this.config.getSrcLevelField() != null) {
        subConfigs.add(new FieldSubstitutionConfig("level", this.config.getSrcLevelField(), false, false, true));
    }
    if (this.config.getSrcFacilityField() != null) {
        subConfigs.add(new FieldSubstitutionConfig("facility", this.config.getSrcFacilityField(), false, false, true));
    }
    if (this.config.getSrcLineNumberField() != null) {
        subConfigs.add(new FieldSubstitutionConfig("line", this.config.getSrcLineNumberField(), false, false, true));
    }
    if (this.config.getSrcFileField() != null) {
        subConfigs.add(new FieldSubstitutionConfig("file", this.config.getSrcFileField(), false, false, true));
    }
    List<Substitution> substitutions = new ArrayList<Substitution>(subConfigs.size());
    SubstitutionFactoryFactory sff = new SubstitutionFactoryFactory();
    for (SubstitutionConfig subConfig : subConfigs) {
        try {
            substitutions.add(sff.getFactory(subConfig).newInstance());
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }
    }
    this.substitutions = substitutions;
    this.subConfigs = subConfigs;
}
Also used : StaticSubstitutionConfig(com.nextdoor.bender.operation.substitution.ztatic.StaticSubstitutionConfig) Substitution(com.nextdoor.bender.operation.substitution.Substitution) FieldSubstitutionConfig(com.nextdoor.bender.operation.substitution.field.FieldSubstitutionConfig) ArrayList(java.util.ArrayList) SubstitutionConfig(com.nextdoor.bender.operation.substitution.SubstitutionConfig) FieldSubstitutionConfig(com.nextdoor.bender.operation.substitution.field.FieldSubstitutionConfig) StaticSubstitutionConfig(com.nextdoor.bender.operation.substitution.ztatic.StaticSubstitutionConfig) SubstitutionFactoryFactory(com.nextdoor.bender.operation.substitution.SubstitutionFactoryFactory)

Aggregations

SubstitutionConfig (com.nextdoor.bender.operation.substitution.SubstitutionConfig)2 FieldSubstitutionConfig (com.nextdoor.bender.operation.substitution.field.FieldSubstitutionConfig)2 StaticSubstitutionConfig (com.nextdoor.bender.operation.substitution.ztatic.StaticSubstitutionConfig)2 ArrayList (java.util.ArrayList)2 GelfOperation (com.nextdoor.bender.operation.gelf.GelfOperation)1 GelfOperationConfig (com.nextdoor.bender.operation.gelf.GelfOperationConfig)1 GelfOperationFactory (com.nextdoor.bender.operation.gelf.GelfOperationFactory)1 Substitution (com.nextdoor.bender.operation.substitution.Substitution)1 SubstitutionFactoryFactory (com.nextdoor.bender.operation.substitution.SubstitutionFactoryFactory)1 Test (org.junit.Test)1