Search in sources :

Example 1 with DatabaseEntities

use of com.instaclustr.esop.impl.DatabaseEntities in project esop by instaclustr.

the class ManifestComponentsTest method testManifestFilterNoRestoreSystemKeyspaceYesNewCluster.

@Test
public void testManifestFilterNoRestoreSystemKeyspaceYesNewCluster() throws Exception {
    Manifest manifest = parseManifest();
    manifest.enrichManifestEntries();
    List<ManifestEntry> manifestFiles = manifest.getManifestFiles(new DatabaseEntities(), // restoreSystemKeyspace
    false, // restoreSystemAuth
    false, // newCluster
    true, // withSchemas
    false);
    Assert.assertTrue(manifestFiles.stream().allMatch(entry -> {
        if (entry.keyspaceTable.keyspace.equals("system")) {
            return entry.keyspaceTable.table.startsWith("schema_");
        } else if (entry.keyspaceTable.keyspace.equals("system_schema")) {
            return true;
        } else
            return !KeyspaceTable.isSystemKeyspace(entry.keyspaceTable.keyspace);
    }));
}
Also used : DatabaseEntities(com.instaclustr.esop.impl.DatabaseEntities) ManifestEntry(com.instaclustr.esop.impl.ManifestEntry) Module(com.google.inject.Module) Inject(com.google.inject.Inject) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) BeforeMethod(org.testng.annotations.BeforeMethod) Keyspace(com.instaclustr.esop.impl.Snapshots.Snapshot.Keyspace) Type(com.instaclustr.esop.impl.ManifestEntry.Type) JacksonModule(com.instaclustr.jackson.JacksonModule) Test(org.testng.annotations.Test) HashMap(java.util.HashMap) Manifest(com.instaclustr.esop.impl.Manifest) Snapshot(com.instaclustr.esop.impl.Snapshots.Snapshot) ArrayList(java.util.ArrayList) Injector(com.google.inject.Injector) DatabaseEntities(com.instaclustr.esop.impl.DatabaseEntities) List(java.util.List) Assert(org.testng.Assert) Paths(java.nio.file.Paths) Table(com.instaclustr.esop.impl.Snapshots.Snapshot.Keyspace.Table) Guice(com.google.inject.Guice) KeyspaceTable(com.instaclustr.esop.impl.KeyspaceTable) Path(java.nio.file.Path) ManifestEntry(com.instaclustr.esop.impl.ManifestEntry) Manifest(com.instaclustr.esop.impl.Manifest) Test(org.testng.annotations.Test)

Example 2 with DatabaseEntities

use of com.instaclustr.esop.impl.DatabaseEntities in project esop by instaclustr.

the class ManifestComponentsTest method testManifestFilterYesRestoreSystemKeyspaceYesNewCluster.

@Test
public void testManifestFilterYesRestoreSystemKeyspaceYesNewCluster() throws Exception {
    Manifest manifest = parseManifest();
    manifest.enrichManifestEntries();
    List<ManifestEntry> manifestFiles = manifest.getManifestFiles(new DatabaseEntities(), // restoreSystemKeyspace
    true, // restoreSystemAuth
    false, // newCluster
    true, // withSchemas
    false);
    Assert.assertEquals(manifestFiles.size(), 304);
}
Also used : DatabaseEntities(com.instaclustr.esop.impl.DatabaseEntities) ManifestEntry(com.instaclustr.esop.impl.ManifestEntry) Manifest(com.instaclustr.esop.impl.Manifest) Test(org.testng.annotations.Test)

Example 3 with DatabaseEntities

use of com.instaclustr.esop.impl.DatabaseEntities in project esop by instaclustr.

the class CassandraDataTest method testCassandraData.

@Test
public void testCassandraData() {
    CassandraData parsed = new CassandraData(tableIdsMap, paths);
    assertTrue(parsed.getTableId("system_schema", "tables").isPresent());
    assertFalse(parsed.getTableId("system_schema", "asdadsad").isPresent());
    assertFalse(parsed.getTableId("sdadasd", "types").isPresent());
    Optional<List<String>> systemSchemaTablesNames = parsed.getTablesNames("system_schema");
    assertTrue(systemSchemaTablesNames.isPresent());
    Optional<List<Path>> systemSchemaTablesPaths = parsed.getTablesPaths("system_schema");
    assertTrue(systemSchemaTablesPaths.isPresent());
    assertEquals(2, systemSchemaTablesPaths.get().size());
    assertTrue(parsed.containsKeyspace("ks1"));
    assertFalse(parsed.containsKeyspace("asdsad"));
    assertTrue(parsed.containsTable("ks1", "tb1"));
    assertTrue(parsed.containsTable("ks1", "tb2"));
    assertFalse(parsed.containsTable("ks1", "sdada"));
    assertEquals("11111111111111111111111111111111", parsed.getTableId("ks1", "tb1").get());
    assertEquals("88888888888888888888888888888888", parsed.getTableId("ks2", "tb4").get());
    assertFalse(parsed.getTableId("ks2", "sdadsad").isPresent());
    assertTrue(parsed.getTablesNames("ks1").get().containsAll(Arrays.asList("tb1", "tb2", "tb3", "tb4")));
    assertTrue(parsed.getTablesNames("ks2").get().containsAll(Arrays.asList("tb1", "tb2", "tb3", "tb4")));
    assertTrue(parsed.getTablesPaths("ks1").get().containsAll(Arrays.asList(Paths.get("/var/lib/cassandra/data/data/ks1/tb1-11111111111111111111111111111111"), Paths.get("/var/lib/cassandra/data/data/ks1/tb2-22222222222222222222222222222222"), Paths.get("/var/lib/cassandra/data/data/ks1/tb3-33333333333333333333333333333333"), Paths.get("/var/lib/cassandra/data/data/ks1/tb4-44444444444444444444444444444444"))));
    assertTrue(parsed.getTablePath("ks1", "tb3").get().equals(Paths.get("/var/lib/cassandra/data/data/ks1/tb3-33333333333333333333333333333333")));
    assertFalse(parsed.getTablePath("ks1", "sdad").isPresent());
    assertFalse(parsed.getTablePath("sdad", "sdad").isPresent());
    assertEquals(Paths.get("/var/lib/cassandra/data/data/ks1"), parsed.getKeyspacePath("ks1").get());
    assertEquals(3, parsed.getKeyspacePaths().size());
    // database entities
    DatabaseEntities databaseEntities = parsed.toDatabaseEntities(false);
    assertFalse(databaseEntities.areEmpty());
    assertTrue(databaseEntities.getKeyspaces().containsAll(Arrays.asList("ks1", "ks2")));
    databaseEntities.getKeyspacesAndTables().entries().forEach(entry -> {
        assertTrue(parsed.getTableId(entry.getKey(), entry.getValue()).isPresent());
    });
    assertFalse(databaseEntities.contains("system_schema"));
    assertFalse(databaseEntities.contains("asdasda", "asdad"));
}
Also used : CassandraData(com.instaclustr.esop.impl.CassandraData) DatabaseEntities(com.instaclustr.esop.impl.DatabaseEntities) List(java.util.List) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 4 with DatabaseEntities

use of com.instaclustr.esop.impl.DatabaseEntities in project esop by instaclustr.

the class CassandraDataTest method testDatabaseEntities.

@Test
public void testDatabaseEntities() throws Exception {
    CassandraData parsed = new CassandraData(tableIdsMap, paths);
    DatabaseEntities entities = DatabaseEntities.parse("ks1  .tb1  ,  kb3.  tb3");
    try {
        parsed.setDatabaseEntitiesFromRequest(entities);
    } catch (Exception ex) {
        assertEquals(ex.getMessage(), "Tables [kb3.tb3] to process are not present in Cassandra.");
    }
    parsed.setDatabaseEntitiesFromRequest(DatabaseEntities.parse("ks1  .tb1"));
}
Also used : CassandraData(com.instaclustr.esop.impl.CassandraData) DatabaseEntities(com.instaclustr.esop.impl.DatabaseEntities) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 5 with DatabaseEntities

use of com.instaclustr.esop.impl.DatabaseEntities in project esop by instaclustr.

the class KeyspaceTablesTest method testMissingTables.

@Test
public void testMissingTables() {
    KeyspaceTables keyspaceTables = new KeyspaceTables();
    keyspaceTables.add("ks1", "t1");
    keyspaceTables.add("ks2", "t2");
    keyspaceTables.add("ks3", "t3");
    keyspaceTables.add("ks4", "t4");
    // ks5.t5 and ks6.t6 are missing
    DatabaseEntities entities = DatabaseEntities.parse("ks1.t1,ks2.t2,ks5.t5,ks6.t6");
    Optional<Pair<List<String>, Multimap<String, String>>> result = keyspaceTables.filterNotPresent(entities);
    Assert.assertTrue(result.isPresent());
    Pair<List<String>, Multimap<String, String>> pair = result.get();
    Assert.assertEquals(2, pair.getRight().size());
    Assert.assertTrue(pair.getRight().containsEntry("ks5", "t5"));
    Assert.assertTrue(pair.getRight().containsEntry("ks6", "t6"));
}
Also used : DatabaseEntities(com.instaclustr.esop.impl.DatabaseEntities) Multimap(com.google.common.collect.Multimap) KeyspaceTables(com.instaclustr.esop.impl.KeyspaceTable.KeyspaceTables) List(java.util.List) Pair(org.apache.commons.lang3.tuple.Pair) Test(org.testng.annotations.Test)

Aggregations

DatabaseEntities (com.instaclustr.esop.impl.DatabaseEntities)13 Test (org.testng.annotations.Test)12 List (java.util.List)6 CassandraData (com.instaclustr.esop.impl.CassandraData)5 Manifest (com.instaclustr.esop.impl.Manifest)5 ManifestEntry (com.instaclustr.esop.impl.ManifestEntry)5 BeforeTest (org.testng.annotations.BeforeTest)5 Path (java.nio.file.Path)4 Pair (org.apache.commons.lang3.tuple.Pair)4 KeyspaceTables (com.instaclustr.esop.impl.KeyspaceTable.KeyspaceTables)3 Snapshot (com.instaclustr.esop.impl.Snapshots.Snapshot)3 Keyspace (com.instaclustr.esop.impl.Snapshots.Snapshot.Keyspace)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 Multimap (com.google.common.collect.Multimap)2 Guice (com.google.inject.Guice)2 Inject (com.google.inject.Inject)2 Injector (com.google.inject.Injector)2 Module (com.google.inject.Module)2