Search in sources :

Example 1 with CreateTableChange

use of com.navercorp.pinpoint.hbase.schema.reader.core.CreateTableChange in project pinpoint by naver.

the class XmlHbaseSchemaParserTest method parseSchema.

@Test
public void parseSchema() {
    final String schemaFile = "hbase-schema/test-hbase-schema.xml";
    TableConfiguration expectedChangeSet1_tableConfiguration = new TableConfiguration.Builder().durability(TableConfiguration.Durability.ASYNC_WAL).build();
    List<ColumnFamilyChange> expectedChangeSet1_columnFamilies = Arrays.asList(new CreateColumnFamilyChange("CF1", new ColumnFamilyConfiguration.Builder().timeToLive(86400).dataBlockEncoding(ColumnFamilyConfiguration.DataBlockEncoding.NONE).build()), new CreateColumnFamilyChange("CF2", ColumnFamilyConfiguration.EMPTY_CONFIGURATION));
    CreateTableChange.SplitOption expectedChangeSet1_tableSplitOption = new CreateTableChange.SplitOption.Auto(16);
    TableChange expectedChangeSet1_tableChange = new CreateTableChange("Table1", expectedChangeSet1_tableConfiguration, expectedChangeSet1_columnFamilies, expectedChangeSet1_tableSplitOption);
    List<ColumnFamilyChange> expectedChangeSet2_columnFamilies = Arrays.asList(new CreateColumnFamilyChange("CF3", ColumnFamilyConfiguration.EMPTY_CONFIGURATION));
    TableChange expectedChangeSet2_tableChange = new ModifyTableChange("Table1", TableConfiguration.EMPTY_CONFIGURATION, expectedChangeSet2_columnFamilies);
    InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream(schemaFile);
    XmlHbaseSchemaParseResult parseResult = parser.parseSchema(new InputSource(inputStream));
    List<String> includeFiles = new ArrayList<>(parseResult.getIncludeFiles());
    assertThat(includeFiles.size(), is(1));
    String includeFile = includeFiles.get(0);
    assertThat(includeFile, is("test-hbase-schema-include.xml"));
    List<ChangeSet> changeSets = new ArrayList<>(parseResult.getChangeSets());
    assertThat(changeSets.size(), is(2));
    ChangeSet changeSet1 = changeSets.get(0);
    assertThat(changeSet1.getId(), is("id-1"));
    assertThat(changeSet1.getTableChanges(), is(Arrays.asList(expectedChangeSet1_tableChange)));
    ChangeSet changeSet2 = changeSets.get(1);
    assertThat(changeSet2.getId(), is("id-2"));
    assertThat(changeSet2.getTableChanges(), is(Arrays.asList(expectedChangeSet2_tableChange)));
}
Also used : CreateColumnFamilyChange(com.navercorp.pinpoint.hbase.schema.reader.core.CreateColumnFamilyChange) InputSource(org.xml.sax.InputSource) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) CreateColumnFamilyChange(com.navercorp.pinpoint.hbase.schema.reader.core.CreateColumnFamilyChange) ColumnFamilyChange(com.navercorp.pinpoint.hbase.schema.reader.core.ColumnFamilyChange) ModifyTableChange(com.navercorp.pinpoint.hbase.schema.reader.core.ModifyTableChange) CreateTableChange(com.navercorp.pinpoint.hbase.schema.reader.core.CreateTableChange) ChangeSet(com.navercorp.pinpoint.hbase.schema.reader.core.ChangeSet) TableConfiguration(com.navercorp.pinpoint.hbase.schema.reader.core.TableConfiguration) ColumnFamilyConfiguration(com.navercorp.pinpoint.hbase.schema.reader.core.ColumnFamilyConfiguration) CreateTableChange(com.navercorp.pinpoint.hbase.schema.reader.core.CreateTableChange) TableChange(com.navercorp.pinpoint.hbase.schema.reader.core.TableChange) ModifyTableChange(com.navercorp.pinpoint.hbase.schema.reader.core.ModifyTableChange) Test(org.junit.Test)

Example 2 with CreateTableChange

use of com.navercorp.pinpoint.hbase.schema.reader.core.CreateTableChange in project pinpoint by naver.

the class HbaseSchemaCommandManagerTest method creatingExistingTableShouldFail.

@Test(expected = InvalidHbaseSchemaException.class)
public void creatingExistingTableShouldFail() {
    String namespace = "namespace";
    String tableName = "table";
    HTableDescriptor existingTable = createHtd(namespace, tableName, "CF");
    HbaseSchemaCommandManager manager = new HbaseSchemaCommandManager(namespace, null, Arrays.asList(existingTable));
    TableChange createTableChange = newTableChange(ChangeType.CREATE, tableName);
    ChangeSet createTableChangeSet = newChangeSet(createTableChange);
    manager.applyChangeSet(createTableChangeSet);
}
Also used : ChangeSet(com.navercorp.pinpoint.hbase.schema.reader.core.ChangeSet) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor) CreateTableChange(com.navercorp.pinpoint.hbase.schema.reader.core.CreateTableChange) TableChange(com.navercorp.pinpoint.hbase.schema.reader.core.TableChange) ModifyTableChange(com.navercorp.pinpoint.hbase.schema.reader.core.ModifyTableChange) Test(org.junit.Test)

Example 3 with CreateTableChange

use of com.navercorp.pinpoint.hbase.schema.reader.core.CreateTableChange in project pinpoint by naver.

the class HbaseSchemaCommandManagerTest method failedChangesShouldNotAffectTheSchema.

@Test
public void failedChangesShouldNotAffectTheSchema() {
    String namespace = "namespace";
    String tableName = "table";
    String columnFamilyName = "CF";
    HbaseSchemaCommandManager manager = new HbaseSchemaCommandManager(namespace, null);
    // initial create table
    ColumnFamilyChange columnFamilyChange = newColumnFamilyChange(columnFamilyName);
    TableChange createTableChange = newTableChange(ChangeType.CREATE, tableName, columnFamilyChange);
    ChangeSet createTableChangeSet = newChangeSet(createTableChange);
    manager.applyChangeSet(createTableChangeSet);
    List<HTableDescriptor> initialSnapshot = manager.getSchemaSnapshot();
    // modify non-existing table
    TableChange modifyNonExistingTableChange = newTableChange(ChangeType.MODIFY, "nonExistingTable", newColumnFamilyChange("newCF"));
    ChangeSet modifyNonExistingTableChangeSet = newChangeSet(modifyNonExistingTableChange);
    try {
        manager.applyChangeSet(modifyNonExistingTableChangeSet);
        fail("Expected an InvalidHbaseSchemaException to be thrown");
    } catch (InvalidHbaseSchemaException expected) {
        List<HTableDescriptor> currentSnapshot = manager.getSchemaSnapshot();
        assertThat(currentSnapshot, equalTo(initialSnapshot));
    }
    // create existing table
    TableChange createExistingTableChange = newTableChange(ChangeType.CREATE, tableName);
    ChangeSet createExistingTableChangeSet = newChangeSet(createExistingTableChange);
    try {
        manager.applyChangeSet(createExistingTableChangeSet);
        fail("Expected an InvalidHbaseSchemaException to be thrown");
    } catch (InvalidHbaseSchemaException expected) {
        List<HTableDescriptor> currentSnapshot = manager.getSchemaSnapshot();
        assertThat(currentSnapshot, equalTo(initialSnapshot));
    }
    // create existing column family
    ColumnFamilyChange createExistingColumnFamilyChange = newColumnFamilyChange(columnFamilyName);
    TableChange createExistingColumnFamilyTableChange = newTableChange(ChangeType.MODIFY, tableName, createExistingColumnFamilyChange);
    ChangeSet createExistingColumnFamilyChangeSet = newChangeSet(createExistingColumnFamilyTableChange);
    try {
        manager.applyChangeSet(createExistingColumnFamilyChangeSet);
        fail("Expected an InvalidHbaseSchemaException to be thrown");
    } catch (InvalidHbaseSchemaException expected) {
        List<HTableDescriptor> currentSnapshot = manager.getSchemaSnapshot();
        assertThat(currentSnapshot, equalTo(initialSnapshot));
    }
}
Also used : InvalidHbaseSchemaException(com.navercorp.pinpoint.hbase.schema.reader.InvalidHbaseSchemaException) CreateColumnFamilyChange(com.navercorp.pinpoint.hbase.schema.reader.core.CreateColumnFamilyChange) ColumnFamilyChange(com.navercorp.pinpoint.hbase.schema.reader.core.ColumnFamilyChange) List(java.util.List) ChangeSet(com.navercorp.pinpoint.hbase.schema.reader.core.ChangeSet) CreateTableChange(com.navercorp.pinpoint.hbase.schema.reader.core.CreateTableChange) TableChange(com.navercorp.pinpoint.hbase.schema.reader.core.TableChange) ModifyTableChange(com.navercorp.pinpoint.hbase.schema.reader.core.ModifyTableChange) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor) Test(org.junit.Test)

Example 4 with CreateTableChange

use of com.navercorp.pinpoint.hbase.schema.reader.core.CreateTableChange in project pinpoint by naver.

the class TableChangeMapper method map.

public TableChange map(ChangeSet.CreateTable createTable) {
    String tableName = createTable.getName();
    if (StringUtils.isEmpty(tableName)) {
        throw new InvalidHbaseSchemaException("Table name must not be empty");
    }
    TableConfiguration tableConfiguration = tableConfigurationMapper.mapConfiguration(createTable.getConfiguration());
    List<ColumnFamilyChange> columnFamilyChanges = mapColumnFamilies(createTable.getCreateColumnFamily());
    CreateTableChange.SplitOption splitOption = splitOptionMapper.mapSplitOption(createTable.getSplit());
    return new CreateTableChange(tableName, tableConfiguration, columnFamilyChanges, splitOption);
}
Also used : InvalidHbaseSchemaException(com.navercorp.pinpoint.hbase.schema.reader.InvalidHbaseSchemaException) CreateTableChange(com.navercorp.pinpoint.hbase.schema.reader.core.CreateTableChange) ColumnFamilyChange(com.navercorp.pinpoint.hbase.schema.reader.core.ColumnFamilyChange) TableConfiguration(com.navercorp.pinpoint.hbase.schema.reader.core.TableConfiguration)

Example 5 with CreateTableChange

use of com.navercorp.pinpoint.hbase.schema.reader.core.CreateTableChange in project pinpoint by naver.

the class XmlHbaseSchemaReaderTest method loadChangeSets.

@Test
public void loadChangeSets() {
    final String schemaFilePath = "classpath:hbase-schema/test-hbase-schema.xml";
    String expectedIncludeChangeSetId = "include-1";
    List<TableChange> expectedIncludeChangeSetTableChanges = Arrays.asList(new CreateTableChange("IncludeTable1", TableConfiguration.EMPTY_CONFIGURATION, Arrays.asList(new CreateColumnFamilyChange("CF1", new ColumnFamilyConfiguration.Builder().timeToLive(5184000).build())), new CreateTableChange.SplitOption.Manual(Arrays.asList("\\x01", "\\x02", "\\x03"))));
    String expectedChangeSetId1 = "id-1";
    List<TableChange> expectedChangeSet1TableChanges = Arrays.asList(new CreateTableChange("Table1", new TableConfiguration.Builder().durability(TableConfiguration.Durability.ASYNC_WAL).build(), Arrays.asList(new CreateColumnFamilyChange("CF1", new ColumnFamilyConfiguration.Builder().timeToLive(86400).dataBlockEncoding(ColumnFamilyConfiguration.DataBlockEncoding.NONE).build()), new CreateColumnFamilyChange("CF2", ColumnFamilyConfiguration.EMPTY_CONFIGURATION)), new CreateTableChange.SplitOption.Auto(16)));
    String expectedChangeSetId2 = "id-2";
    List<TableChange> expectedChangeSet2TableChanges = Arrays.asList(new ModifyTableChange("Table1", TableConfiguration.EMPTY_CONFIGURATION, Arrays.asList(new CreateColumnFamilyChange("CF3", ColumnFamilyConfiguration.EMPTY_CONFIGURATION))));
    List<ChangeSet> changeSets = reader.loadChangeSets(schemaFilePath);
    assertThat(changeSets.size(), is(3));
    ChangeSet includeChangeSet = changeSets.get(0);
    assertThat(includeChangeSet, matches(expectedIncludeChangeSetId, expectedIncludeChangeSetTableChanges));
    ChangeSet changeSet1 = changeSets.get(1);
    assertThat(changeSet1, matches(expectedChangeSetId1, expectedChangeSet1TableChanges));
    ChangeSet changeSet2 = changeSets.get(2);
    assertThat(changeSet2, matches(expectedChangeSetId2, expectedChangeSet2TableChanges));
}
Also used : CreateColumnFamilyChange(com.navercorp.pinpoint.hbase.schema.reader.core.CreateColumnFamilyChange) ModifyTableChange(com.navercorp.pinpoint.hbase.schema.reader.core.ModifyTableChange) CreateTableChange(com.navercorp.pinpoint.hbase.schema.reader.core.CreateTableChange) ChangeSet(com.navercorp.pinpoint.hbase.schema.reader.core.ChangeSet) CreateTableChange(com.navercorp.pinpoint.hbase.schema.reader.core.CreateTableChange) TableChange(com.navercorp.pinpoint.hbase.schema.reader.core.TableChange) ModifyTableChange(com.navercorp.pinpoint.hbase.schema.reader.core.ModifyTableChange) ColumnFamilyConfiguration(com.navercorp.pinpoint.hbase.schema.reader.core.ColumnFamilyConfiguration) Test(org.junit.Test)

Aggregations

CreateTableChange (com.navercorp.pinpoint.hbase.schema.reader.core.CreateTableChange)5 ChangeSet (com.navercorp.pinpoint.hbase.schema.reader.core.ChangeSet)4 ModifyTableChange (com.navercorp.pinpoint.hbase.schema.reader.core.ModifyTableChange)4 TableChange (com.navercorp.pinpoint.hbase.schema.reader.core.TableChange)4 Test (org.junit.Test)4 ColumnFamilyChange (com.navercorp.pinpoint.hbase.schema.reader.core.ColumnFamilyChange)3 CreateColumnFamilyChange (com.navercorp.pinpoint.hbase.schema.reader.core.CreateColumnFamilyChange)3 InvalidHbaseSchemaException (com.navercorp.pinpoint.hbase.schema.reader.InvalidHbaseSchemaException)2 ColumnFamilyConfiguration (com.navercorp.pinpoint.hbase.schema.reader.core.ColumnFamilyConfiguration)2 TableConfiguration (com.navercorp.pinpoint.hbase.schema.reader.core.TableConfiguration)2 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)2 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 InputSource (org.xml.sax.InputSource)1