Search in sources :

Example 1 with IndexFilter

use of com.torodb.packaging.config.model.protocol.mongo.FilterList.IndexFilter in project torodb by torodb.

the class ConfigTest method testReplicationFilteringWithIndexes.

@Test
public void testReplicationFilteringWithIndexes() throws Exception {
    CliConfig cliConfig = new CliConfig() {

        @Override
        public boolean hasConfFile() {
            return true;
        }

        @Override
        public InputStream getConfInputStream() {
            return ConfigTest.class.getResourceAsStream("/test-parse-with-yaml.yml");
        }

        @Override
        public List<String> getParams() {
            String[] params = new String[] { "/protocol/mongo/replication/0/include={torodb: [{postgres: {name: awesome, unique: true}}, derby]}", "/protocol/mongo/replication/0/exclude={mongodb: [{mmapv1: {keys: {\"the.old.mmapv1\": 1}}}, wiredtiger]}" };
            return Arrays.asList(params);
        }
    };
    Config config = CliConfigUtils.readConfig(cliConfig);
    Assert.assertTrue("/generic not defined", config.getGeneric() != null);
    Assert.assertTrue("/generic/logPackages not defined", config.getGeneric().getLogPackages() != null);
    Assert.assertTrue("/generic/logPackages/com.torodb not defined", config.getGeneric().getLogPackages().get("com.torodb") != null);
    Assert.assertEquals("/generic/logLevel has different value than that specified", LogLevel.NONE, config.getGeneric().getLogLevel());
    Assert.assertEquals("/generic/logPackages has not 1 entry", 1, config.getGeneric().getLogPackages().size());
    Assert.assertEquals("/generic/logPackages/com.torodb has different value than that specified", LogLevel.DEBUG, config.getGeneric().getLogPackages().get("com.torodb"));
    Assert.assertTrue("/protocol not defined", config.getProtocol() != null);
    Assert.assertTrue("/protocol/mongo not defined", config.getProtocol().getMongo() != null);
    Assert.assertTrue("/protocol/mongo/net not defined", config.getProtocol().getMongo().getNet() != null);
    Assert.assertTrue("/protocol/mongo/replication not defined", config.getProtocol().getMongo().getReplication() != null);
    Assert.assertEquals("/protocol/mongo/net/port has different value than that specified", Integer.valueOf(27019), config.getProtocol().getMongo().getNet().getPort());
    Assert.assertEquals("/protocol/mongo/replication has not 1 element", 1, config.getProtocol().getMongo().getReplication().size());
    Assert.assertEquals("/protocol/mongo/replication/0/replSetName has different value than that specified", "rs1", config.getProtocol().getMongo().getReplication().get(0).getReplSetName());
    Assert.assertEquals("/protocol/mongo/replication/0/role has different value than that specified", Role.HIDDEN_SLAVE, config.getProtocol().getMongo().getReplication().get(0).getRole());
    Assert.assertEquals("/protocol/mongo/replication/0/syncSource has different value than that specified", "localhost:27017", config.getProtocol().getMongo().getReplication().get(0).getSyncSource());
    Assert.assertTrue("/protocol/mongo/replication/0/include not defined", config.getProtocol().getMongo().getReplication().get(0).getInclude() != null);
    Assert.assertTrue("/protocol/mongo/replication/0/include/torodb not defined", config.getProtocol().getMongo().getReplication().get(0).getInclude().get("torodb") != null);
    Assert.assertEquals("/protocol/mongo/replication/0/include/torodb has different value than that specified", ImmutableMap.of("postgres", ImmutableList.of(new IndexFilter("awesome", true, null)), "derby", ImmutableList.of()), config.getProtocol().getMongo().getReplication().get(0).getInclude().get("torodb"));
    Assert.assertTrue("/protocol/mongo/replication/0/exclude not defined", config.getProtocol().getMongo().getReplication().get(0).getExclude() != null);
    Assert.assertTrue("/protocol/mongo/replication/0/exclude/mongodb not defined", config.getProtocol().getMongo().getReplication().get(0).getExclude().get("mongodb") != null);
    Assert.assertEquals("/protocol/mongo/replication/0/exclude/mongodb has different value than that specified", ImmutableMap.of("mmapv1", ImmutableList.of(new IndexFilter(null, null, ImmutableMap.<String, String>builder().put("the.old.mmapv1", "1").build())), "wiredtiger", ImmutableList.of()), config.getProtocol().getMongo().getReplication().get(0).getExclude().get("mongodb"));
    Assert.assertTrue("/backend not defined", config.getBackend() != null);
    Assert.assertEquals("/backend/postgres not defined", Postgres.class, config.getBackend().getBackendImplementation().getClass());
    Assert.assertTrue("/backend/postgres not identified as AbstractPostgres", config.getBackend().is(Postgres.class));
    Assert.assertTrue("/backend/postgres not identified as AbstractPostgres Like", config.getBackend().isLike(Postgres.class));
    Assert.assertEquals("/backend/postgres/host has different value than that specified", "localhost", config.getBackend().as(Postgres.class).getHost());
    Assert.assertEquals("/backend/postgres/port has different value than that specified", Integer.valueOf(5432), config.getBackend().as(Postgres.class).getPort());
    Assert.assertEquals("/backend/postgres/user has different value than that specified", "root", config.getBackend().as(Postgres.class).getUser());
    Assert.assertEquals("/backend/postgres/password specified but should have not been read from parameters", null, config.getBackend().as(Postgres.class).getPassword());
}
Also used : Config(com.torodb.standalone.config.model.Config) CliConfig(com.torodb.standalone.CliConfig) CliConfig(com.torodb.standalone.CliConfig) IndexFilter(com.torodb.packaging.config.model.protocol.mongo.FilterList.IndexFilter) Postgres(com.torodb.standalone.config.model.backend.postgres.Postgres) Test(org.junit.Test)

Example 2 with IndexFilter

use of com.torodb.packaging.config.model.protocol.mongo.FilterList.IndexFilter in project torodb by torodb.

the class ConfigTest method testReplicationFilteringWithIndexes.

@Test
public void testReplicationFilteringWithIndexes() throws Exception {
    CliConfig cliConfig = new CliConfig() {

        @Override
        public boolean hasConfFile() {
            return true;
        }

        @Override
        public InputStream getConfInputStream() {
            return ConfigTest.class.getResourceAsStream("/test-parse-with-yaml.yml");
        }

        @Override
        public List<String> getParams() {
            String[] params = new String[] { "/replication/include={torodb: [{postgres: {name: awesome, unique: true}}, derby]}", "/replication/exclude={mongodb: [{mmapv1: {keys: {\"the.old.mmapv1\": 1}}}, wiredtiger]}" };
            return Arrays.asList(params);
        }
    };
    Config config = CliConfigUtils.readConfig(cliConfig);
    Assert.assertTrue("/logging not defined", config.getLogging() != null);
    Assert.assertTrue("/logging/packages not defined", config.getLogging().getPackages() != null);
    Assert.assertTrue("/logging/packages/com.torodb not defined", config.getLogging().getPackages().get("com.torodb") != null);
    Assert.assertEquals("/logging/level has different value than that specified", LogLevel.NONE, config.getLogging().getLevel());
    Assert.assertEquals("/logging/packages has not 1 entry", 1, config.getLogging().getPackages().size());
    Assert.assertEquals("/logging/packages/com.torodb has different value than that specified", LogLevel.DEBUG, config.getLogging().getPackages().get("com.torodb"));
    Assert.assertTrue("/replication not defined", config.getReplication() != null);
    Assert.assertEquals("/replication/replSetName has different value than that specified", "rs1", config.getReplication().getReplSetName());
    Assert.assertEquals("/replication/role has different value than that specified", Role.HIDDEN_SLAVE, config.getReplication().getRole());
    Assert.assertEquals("/replication/syncSource has different value than that specified", "localhost:27017", config.getReplication().getSyncSource());
    Assert.assertTrue("/replication/include not defined", config.getReplication().getInclude() != null);
    Assert.assertTrue("/replication/include/torodb not defined", config.getReplication().getInclude().get("torodb") != null);
    Assert.assertEquals("/replication/include/torodb has different value than that specified", ImmutableMap.of("postgres", ImmutableList.of(new IndexFilter("awesome", true, null)), "derby", ImmutableList.of()), config.getReplication().getInclude().get("torodb"));
    Assert.assertTrue("/replication/exclude not defined", config.getReplication().getExclude() != null);
    Assert.assertTrue("/replication/exclude/mongodb not defined", config.getReplication().getExclude().get("mongodb") != null);
    Assert.assertEquals("/replication/exclude/mongodb has different value than that specified", ImmutableMap.of("mmapv1", ImmutableList.of(new IndexFilter(null, null, ImmutableMap.<String, String>builder().put("the.old.mmapv1", "1").build())), "wiredtiger", ImmutableList.of()), config.getReplication().getExclude().get("mongodb"));
    Assert.assertTrue("/backend not defined", config.getBackend() != null);
    Assert.assertEquals("/backend/postgres not defined", Postgres.class, config.getBackend().getBackendImplementation().getClass());
    Assert.assertTrue("/backend/postgres not identified as AbstractPostgres", config.getBackend().is(Postgres.class));
    Assert.assertTrue("/backend/postgres not identified as AbstractPostgres Like", config.getBackend().isLike(Postgres.class));
    Assert.assertEquals("/backend/postgres/host has different value than that specified", "localhost", config.getBackend().as(Postgres.class).getHost());
    Assert.assertEquals("/backend/postgres/port has different value than that specified", Integer.valueOf(5432), config.getBackend().as(Postgres.class).getPort());
    Assert.assertEquals("/backend/postgres/user has different value than that specified", "root", config.getBackend().as(Postgres.class).getUser());
    Assert.assertEquals("/backend/postgres/password specified but should have not been read from parameters", null, config.getBackend().as(Postgres.class).getPassword());
}
Also used : CliConfig(com.torodb.stampede.CliConfig) Config(com.torodb.stampede.config.model.Config) CliConfig(com.torodb.stampede.CliConfig) IndexFilter(com.torodb.packaging.config.model.protocol.mongo.FilterList.IndexFilter) Postgres(com.torodb.stampede.config.model.backend.postgres.Postgres) Test(org.junit.Test)

Example 3 with IndexFilter

use of com.torodb.packaging.config.model.protocol.mongo.FilterList.IndexFilter in project torodb by torodb.

the class FilterListSerializer method serializeFields.

private void serializeFields(FilterList value, JsonGenerator jgen) throws IOException {
    for (Map.Entry<String, Map<String, List<IndexFilter>>> databaseEntry : value.entrySet()) {
        jgen.writeArrayFieldStart(databaseEntry.getKey());
        for (Map.Entry<String, List<IndexFilter>> collection : databaseEntry.getValue().entrySet()) {
            if (collection.getValue().isEmpty()) {
                jgen.writeString(collection.getKey());
            } else {
                jgen.writeStartObject();
                jgen.writeArrayFieldStart(collection.getKey());
                for (IndexFilter indexFilter : collection.getValue()) {
                    jgen.writeObject(indexFilter);
                }
                jgen.writeEndArray();
                jgen.writeEndObject();
            }
        }
        jgen.writeEndArray();
    }
}
Also used : List(java.util.List) FilterList(com.torodb.packaging.config.model.protocol.mongo.FilterList) IndexFilter(com.torodb.packaging.config.model.protocol.mongo.FilterList.IndexFilter) Map(java.util.Map)

Example 4 with IndexFilter

use of com.torodb.packaging.config.model.protocol.mongo.FilterList.IndexFilter in project torodb by torodb.

the class FilterListDeserializer method readIndexFilter.

private void readIndexFilter(JsonParser jp, JsonNode indexFilter, List<IndexFilter> indexFilters) throws JsonProcessingException {
    ObjectMapper mapper = (ObjectMapper) jp.getCodec();
    indexFilters.add(mapper.treeToValue(indexFilter, IndexFilter.class));
}
Also used : IndexFilter(com.torodb.packaging.config.model.protocol.mongo.FilterList.IndexFilter) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 5 with IndexFilter

use of com.torodb.packaging.config.model.protocol.mongo.FilterList.IndexFilter in project torodb by torodb.

the class FilterListDeserializer method readCollectionObject.

@SuppressFBWarnings("REC_CATCH_EXCEPTION")
private void readCollectionObject(JsonParser jp, ObjectNode collection, Map<String, List<IndexFilter>> collections) throws JsonProcessingException, JsonMappingException {
    Iterator<Entry<String, JsonNode>> collectionEntriesIterator = collection.fields();
    while (collectionEntriesIterator.hasNext()) {
        List<IndexFilter> indexFilters = new ArrayList<>();
        Map.Entry<String, JsonNode> collectionEntry = collectionEntriesIterator.next();
        try {
            if (collectionEntry.getValue() instanceof ObjectNode) {
                readIndexFilter(jp, collectionEntry.getValue(), indexFilters);
            } else if (collectionEntry.getValue() instanceof ArrayNode) {
                Iterator<JsonNode> indexFiltersIterator = collectionEntry.getValue().elements();
                int position = 0;
                while (indexFiltersIterator.hasNext()) {
                    try {
                        JsonNode indexFilter = indexFiltersIterator.next();
                        if (indexFilter instanceof ObjectNode) {
                            readIndexFilter(jp, indexFilter, indexFilters);
                        } else {
                            throw new JsonMappingException("wrong filter format: index filter should be an " + "object", jp.getCurrentLocation());
                        }
                        position++;
                    } catch (Exception e) {
                        throw JsonMappingException.wrapWithPath(e, indexFilters, position);
                    }
                }
            }
            collections.put(collectionEntry.getKey(), indexFilters);
        } catch (Exception e) {
            throw JsonMappingException.wrapWithPath(e, collections, collectionEntry.getKey());
        }
    }
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayList(java.util.ArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) Entry(java.util.Map.Entry) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) Iterator(java.util.Iterator) IndexFilter(com.torodb.packaging.config.model.protocol.mongo.FilterList.IndexFilter) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) HashMap(java.util.HashMap) Map(java.util.Map) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Aggregations

IndexFilter (com.torodb.packaging.config.model.protocol.mongo.FilterList.IndexFilter)6 Map (java.util.Map)3 FilterList (com.torodb.packaging.config.model.protocol.mongo.FilterList)2 List (java.util.List)2 Test (org.junit.Test)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 IndexPattern (com.torodb.mongodb.repl.ReplicationFilters.IndexPattern)1 CliConfig (com.torodb.stampede.CliConfig)1 Config (com.torodb.stampede.config.model.Config)1 Postgres (com.torodb.stampede.config.model.backend.postgres.Postgres)1 CliConfig (com.torodb.standalone.CliConfig)1 Config (com.torodb.standalone.config.model.Config)1 Postgres (com.torodb.standalone.config.model.backend.postgres.Postgres)1