Search in sources :

Example 6 with TableChange

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

the class ChangeSetMapper method mapChangeSet.

public ChangeSet mapChangeSet(com.navercorp.pinpoint.hbase.schema.definition.xml.ChangeSet changeSet) {
    try {
        // no need to close StringWriter
        StringWriter stringWriter = new StringWriter();
        createMarshaller().marshal(changeSet, stringWriter);
        String value = stringWriter.toString();
        List<TableChange> tableChangeList = mapTableChanges(changeSet.getModifyTable(), changeSet.getCreateTable());
        return new ChangeSet(changeSet.getId(), value, tableChangeList);
    } catch (JAXBException e) {
        Throwable linkedException = e.getLinkedException();
        if (linkedException == null) {
            throw new IllegalStateException("JAXB error", e);
        }
        throw new HbaseSchemaParseException("Error computing md5 for change set id : " + changeSet.getId(), linkedException);
    }
}
Also used : StringWriter(java.io.StringWriter) HbaseSchemaParseException(com.navercorp.pinpoint.hbase.schema.reader.HbaseSchemaParseException) JAXBException(javax.xml.bind.JAXBException) ChangeSet(com.navercorp.pinpoint.hbase.schema.reader.core.ChangeSet) TableChange(com.navercorp.pinpoint.hbase.schema.reader.core.TableChange)

Example 7 with TableChange

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

the class HbaseSchemaCommandManagerTest method modifyingNonExistingTableShouldFail.

@Test(expected = InvalidHbaseSchemaException.class)
public void modifyingNonExistingTableShouldFail() {
    String namespace = "namespace";
    String tableName = "table";
    String nonExistingTableName = "anotherTable";
    HTableDescriptor existingTable = createHtd(namespace, tableName, "CF");
    HbaseSchemaCommandManager manager = new HbaseSchemaCommandManager(namespace, null, Arrays.asList(existingTable));
    TableChange modifyTableChange = newTableChange(ChangeType.MODIFY, nonExistingTableName);
    ChangeSet modifyTableChangeSet = newChangeSet(modifyTableChange);
    manager.applyChangeSet(modifyTableChangeSet);
}
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 8 with TableChange

use of com.navercorp.pinpoint.hbase.schema.reader.core.TableChange 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

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