Search in sources :

Example 1 with MetadataTable

use of io.cdap.cdap.messaging.store.MetadataTable in project cdap by caskdata.

the class CoreMessagingService method deleteTopic.

@Override
public void deleteTopic(TopicId topicId) throws TopicNotFoundException, IOException {
    try (MetadataTable metadataTable = createMetadataTable()) {
        metadataTable.deleteTopic(topicId);
        topicCache.invalidate(topicId);
        messageTableWriterCache.invalidate(topicId);
        payloadTableWriterCache.invalidate(topicId);
    }
}
Also used : MetadataTable(io.cdap.cdap.messaging.store.MetadataTable)

Example 2 with MetadataTable

use of io.cdap.cdap.messaging.store.MetadataTable in project cdap by caskdata.

the class CoreMessagingService method updateTopic.

@Override
public void updateTopic(TopicMetadata topicMetadata) throws TopicNotFoundException, IOException {
    try (MetadataTable metadataTable = createMetadataTable()) {
        Map<String, String> properties = createDefaultProperties();
        properties.putAll(topicMetadata.getProperties());
        metadataTable.updateTopic(new TopicMetadata(topicMetadata.getTopicId(), properties, true));
        topicCache.invalidate(topicMetadata.getTopicId());
    }
}
Also used : MetadataTable(io.cdap.cdap.messaging.store.MetadataTable) TopicMetadata(io.cdap.cdap.messaging.TopicMetadata)

Example 3 with MetadataTable

use of io.cdap.cdap.messaging.store.MetadataTable in project cdap by caskdata.

the class LevelDBMetadataTableTest method testScanTopics.

@Test
public void testScanTopics() throws Exception {
    try (MetadataTable metadataTable = createMetadataTable()) {
        LevelDBMetadataTable table = (LevelDBMetadataTable) metadataTable;
        TopicMetadata t1 = new TopicMetadata(NamespaceId.CDAP.topic("t1"), ImmutableMap.of(TopicMetadata.TTL_KEY, "10", TopicMetadata.GENERATION_KEY, "1"));
        TopicMetadata t2 = new TopicMetadata(NamespaceId.SYSTEM.topic("t2"), ImmutableMap.of(TopicMetadata.TTL_KEY, "20", TopicMetadata.GENERATION_KEY, "1"));
        metadataTable.createTopic(t1);
        metadataTable.createTopic(t2);
        List<TopicId> allTopics = table.listTopics();
        Assert.assertEquals(2, allTopics.size());
        List<TopicMetadata> metadatas = new ArrayList<>();
        Iterators.addAll(metadatas, table.scanTopics());
        Assert.assertEquals(2, metadatas.size());
        allTopics = table.listTopics(NamespaceId.CDAP);
        Assert.assertEquals(1, allTopics.size());
        allTopics = table.listTopics(NamespaceId.SYSTEM);
        Assert.assertEquals(1, allTopics.size());
        metadataTable.deleteTopic(t1.getTopicId());
        metadatas.clear();
        Iterators.addAll(metadatas, table.scanTopics());
        Assert.assertEquals(2, metadatas.size());
        Assert.assertEquals(1, metadataTable.listTopics().size());
        Assert.assertEquals(1, metadataTable.listTopics(NamespaceId.SYSTEM).size());
        Assert.assertTrue(metadataTable.listTopics(NamespaceId.CDAP).isEmpty());
        metadataTable.deleteTopic(t2.getTopicId());
        metadatas.clear();
        Iterators.addAll(metadatas, table.scanTopics());
        for (TopicMetadata metadata : metadatas) {
            Assert.assertEquals(-1, metadata.getGeneration());
        }
        Assert.assertTrue(metadataTable.listTopics().isEmpty());
    }
}
Also used : MetadataTable(io.cdap.cdap.messaging.store.MetadataTable) ArrayList(java.util.ArrayList) TopicId(io.cdap.cdap.proto.id.TopicId) TopicMetadata(io.cdap.cdap.messaging.TopicMetadata) Test(org.junit.Test) MetadataTableTest(io.cdap.cdap.messaging.store.MetadataTableTest)

Example 4 with MetadataTable

use of io.cdap.cdap.messaging.store.MetadataTable in project cdap by caskdata.

the class HBaseTableFactory method createMetadataTable.

@Override
public MetadataTable createMetadataTable() throws IOException {
    TableId tableId = tableUtil.createHTableId(NamespaceId.SYSTEM, metadataTableName);
    Table table = null;
    // If the table descriptor is in the cache, we assume the table exists.
    if (!tableDescriptors.containsKey(tableId)) {
        synchronized (this) {
            if (!tableDescriptors.containsKey(tableId)) {
                try (HBaseDDLExecutor ddlExecutor = ddlExecutorFactory.get()) {
                    ColumnFamilyDescriptorBuilder cfdBuilder = HBaseTableUtil.getColumnFamilyDescriptorBuilder(Bytes.toString(COLUMN_FAMILY), hConf);
                    TableDescriptorBuilder tdBuilder = HBaseTableUtil.getTableDescriptorBuilder(tableId, cConf).addColumnFamily(cfdBuilder.build());
                    ddlExecutor.createTableIfNotExists(tdBuilder.build(), null);
                    table = tableUtil.createTable(hConf, tableId);
                    tableDescriptors.put(tableId, table.getTableDescriptor());
                }
            }
        }
    }
    if (table == null) {
        table = tableUtil.createTable(hConf, tableId);
    }
    return new HBaseMetadataTable(tableUtil, table, COLUMN_FAMILY, cConf.getInt(Constants.MessagingSystem.HBASE_SCAN_CACHE_ROWS), createExceptionHandler(tableId));
}
Also used : TableId(io.cdap.cdap.data2.util.TableId) HBaseDDLExecutor(io.cdap.cdap.spi.hbase.HBaseDDLExecutor) MetadataTable(io.cdap.cdap.messaging.store.MetadataTable) MessageTable(io.cdap.cdap.messaging.store.MessageTable) PayloadTable(io.cdap.cdap.messaging.store.PayloadTable) Table(org.apache.hadoop.hbase.client.Table) ColumnFamilyDescriptorBuilder(io.cdap.cdap.data2.util.hbase.ColumnFamilyDescriptorBuilder) HTableDescriptorBuilder(io.cdap.cdap.data2.util.hbase.HTableDescriptorBuilder) TableDescriptorBuilder(io.cdap.cdap.data2.util.hbase.TableDescriptorBuilder)

Example 5 with MetadataTable

use of io.cdap.cdap.messaging.store.MetadataTable in project cdap by caskdata.

the class CoreMessagingService method createTopic.

@Override
public void createTopic(TopicMetadata topicMetadata) throws TopicAlreadyExistsException, IOException {
    try (MetadataTable metadataTable = createMetadataTable()) {
        Map<String, String> properties = createDefaultProperties();
        properties.putAll(topicMetadata.getProperties());
        metadataTable.createTopic(new TopicMetadata(topicMetadata.getTopicId(), properties, true));
    }
}
Also used : MetadataTable(io.cdap.cdap.messaging.store.MetadataTable) TopicMetadata(io.cdap.cdap.messaging.TopicMetadata)

Aggregations

MetadataTable (io.cdap.cdap.messaging.store.MetadataTable)6 TopicMetadata (io.cdap.cdap.messaging.TopicMetadata)4 MessageTable (io.cdap.cdap.messaging.store.MessageTable)2 TopicId (io.cdap.cdap.proto.id.TopicId)2 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 TableId (io.cdap.cdap.data2.util.TableId)1 ColumnFamilyDescriptorBuilder (io.cdap.cdap.data2.util.hbase.ColumnFamilyDescriptorBuilder)1 HTableDescriptorBuilder (io.cdap.cdap.data2.util.hbase.HTableDescriptorBuilder)1 TableDescriptorBuilder (io.cdap.cdap.data2.util.hbase.TableDescriptorBuilder)1 DataCleanupTest (io.cdap.cdap.messaging.store.DataCleanupTest)1 MetadataTableTest (io.cdap.cdap.messaging.store.MetadataTableTest)1 PayloadTable (io.cdap.cdap.messaging.store.PayloadTable)1 HBaseDDLExecutor (io.cdap.cdap.spi.hbase.HBaseDDLExecutor)1 Table (org.apache.hadoop.hbase.client.Table)1 Transaction (org.apache.tephra.Transaction)1