Search in sources :

Example 16 with ChangeSet

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

the class HbaseSchemaCommandManagerTest method shouldFilterTablesFromDifferentNamespace.

@Test
public void shouldFilterTablesFromDifferentNamespace() {
    String namespace = "namespace";
    String differentNamespace = "differentNamespace";
    String tableName = "table1";
    HTableDescriptor sameNamespaceHtd = createHtd(namespace, tableName, "CF1");
    HTableDescriptor differentNamespaceHtd = createHtd(differentNamespace, tableName, "CF1");
    List<HTableDescriptor> htds = Arrays.asList(sameNamespaceHtd, differentNamespaceHtd);
    HbaseSchemaCommandManager manager = new HbaseSchemaCommandManager(namespace, null, htds);
    ColumnFamilyChange createColumnFamilyChange = newColumnFamilyChange("CF2");
    TableChange modifyTableChange = newTableChange(ChangeType.MODIFY, tableName, createColumnFamilyChange);
    ChangeSet modifyTableChangeSet = newChangeSet(modifyTableChange);
    manager.applyChangeSet(modifyTableChangeSet);
    List<HTableDescriptor> schemaSnapshot = manager.getSchemaSnapshot();
    assertThat(schemaSnapshot, contains(sameNamespaceHtd));
    assertThat(schemaSnapshot, not(contains(differentNamespaceHtd)));
}
Also used : CreateColumnFamilyChange(com.navercorp.pinpoint.hbase.schema.reader.core.CreateColumnFamilyChange) ColumnFamilyChange(com.navercorp.pinpoint.hbase.schema.reader.core.ColumnFamilyChange) 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 17 with ChangeSet

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

the class ChangeSetManager method getExecutedChangeSets.

/**
 * Returns a new list of {@link ChangeSet} that has already been executed as specified by {@code schemaChangeLogs}.
 *
 * @param schemaChangeLogs logs of change sets already executed
 * @return a list of change sets already executed
 * @throws IllegalArgumentException if the current change sets are not valid for the specified{@code schemaChangeLogs}
 */
public List<ChangeSet> getExecutedChangeSets(List<SchemaChangeLog> schemaChangeLogs) {
    if (CollectionUtils.isEmpty(schemaChangeLogs)) {
        return Collections.emptyList();
    }
    List<SchemaChangeLog> sortedSchemaChangeLogs = sortSchemaChangeLogs(schemaChangeLogs);
    List<ChangeSet> executedChangeSets = new ArrayList<>();
    for (int i = 0; i < changeSets.size() && i < sortedSchemaChangeLogs.size(); i++) {
        ChangeSet changeSet = changeSets.get(i);
        SchemaChangeLog executedSchemaChangeLog = sortedSchemaChangeLogs.get(i);
        int expectedOrder = i + 1;
        verifyChangeLog(executedSchemaChangeLog, changeSet, expectedOrder);
        executedChangeSets.add(changeSet);
    }
    return executedChangeSets;
}
Also used : ArrayList(java.util.ArrayList) ChangeSet(com.navercorp.pinpoint.hbase.schema.reader.core.ChangeSet) SchemaChangeLog(com.navercorp.pinpoint.hbase.schema.domain.SchemaChangeLog)

Example 18 with ChangeSet

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

the class ChangeSetManager method filterExecutedChangeSets.

/**
 * Returns a new list of {@link ChangeSet} that has not been executed as specified by {@code schemaChangeLogs}.
 *
 * @param schemaChangeLogs logs of change sets already executed
 * @return a list of change sets not yet executed
 * @throws IllegalArgumentException if the current change sets are not valid for the specified{@code schemaChangeLogs}
 */
public List<ChangeSet> filterExecutedChangeSets(List<SchemaChangeLog> schemaChangeLogs) {
    if (CollectionUtils.isEmpty(schemaChangeLogs)) {
        return new ArrayList<>(changeSets);
    }
    List<SchemaChangeLog> sortedSchemaChangeLogs = sortSchemaChangeLogs(schemaChangeLogs);
    int i = 0;
    while (i < changeSets.size() && i < sortedSchemaChangeLogs.size()) {
        ChangeSet changeSet = changeSets.get(i);
        SchemaChangeLog executedSchemaChangeLog = sortedSchemaChangeLogs.get(i);
        int expectedOrder = i + 1;
        verifyChangeLog(executedSchemaChangeLog, changeSet, expectedOrder);
        i++;
    }
    if (i >= changeSets.size()) {
        return Collections.emptyList();
    }
    return new ArrayList<>(changeSets.subList(i, changeSets.size()));
}
Also used : ArrayList(java.util.ArrayList) ChangeSet(com.navercorp.pinpoint.hbase.schema.reader.core.ChangeSet) SchemaChangeLog(com.navercorp.pinpoint.hbase.schema.domain.SchemaChangeLog)

Example 19 with ChangeSet

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

the class SchemaChangeLogServiceImplTest method recordChangeSets.

@Test
public void recordChangeSets() {
    // Given
    final int numChangeSets = random.nextInt(100) + 1;
    final List<ChangeSet> changeSets = new ArrayList<>(numChangeSets);
    for (int i = 0; i < numChangeSets; i++) {
        changeSets.add(newChangeSet("id" + (i + 1)));
    }
    doNothing().when(schemaChangeLogDao).insertChangeLog(anyString(), any(SchemaChangeLog.class));
    // When
    List<SchemaChangeLog> schemaChangeLogs = schemaChangeLogService.recordChangeSets("namespace", changeSets);
    // Then
    MatcherAssert.assertThat(schemaChangeLogs.size(), equalTo(numChangeSets));
    final int initialExecOrder = 1;
    for (int i = 0; i < numChangeSets; i++) {
        SchemaChangeLog schemaChangeLog = schemaChangeLogs.get(i);
        ChangeSet changeSet = changeSets.get(i);
        MatcherAssert.assertThat(schemaChangeLog.getId(), equalTo(changeSet.getId()));
        int expectedExecOrder = initialExecOrder + i;
        MatcherAssert.assertThat(schemaChangeLog.getExecOrder(), equalTo(expectedExecOrder));
    }
}
Also used : ArrayList(java.util.ArrayList) ChangeSet(com.navercorp.pinpoint.hbase.schema.reader.core.ChangeSet) SchemaChangeLog(com.navercorp.pinpoint.hbase.schema.domain.SchemaChangeLog) Test(org.junit.Test)

Example 20 with ChangeSet

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

the class SchemaChangeLogServiceImplTest method recordChangeSet.

@Test
public void recordChangeSet() {
    // Given
    final ChangeSet changeSet = newChangeSet("id1");
    doNothing().when(schemaChangeLogDao).insertChangeLog(anyString(), any(SchemaChangeLog.class));
    // When
    SchemaChangeLog schemaChangeLog = schemaChangeLogService.recordChangeSet("namespace", changeSet);
    // Then
    MatcherAssert.assertThat(schemaChangeLog.getId(), equalTo(changeSet.getId()));
    MatcherAssert.assertThat(schemaChangeLog.getExecOrder(), equalTo(1));
}
Also used : ChangeSet(com.navercorp.pinpoint.hbase.schema.reader.core.ChangeSet) SchemaChangeLog(com.navercorp.pinpoint.hbase.schema.domain.SchemaChangeLog) Test(org.junit.Test)

Aggregations

ChangeSet (com.navercorp.pinpoint.hbase.schema.reader.core.ChangeSet)39 Test (org.junit.Test)28 SchemaChangeLog (com.navercorp.pinpoint.hbase.schema.domain.SchemaChangeLog)23 ArrayList (java.util.ArrayList)8 TableChange (com.navercorp.pinpoint.hbase.schema.reader.core.TableChange)7 CreateTableChange (com.navercorp.pinpoint.hbase.schema.reader.core.CreateTableChange)6 ModifyTableChange (com.navercorp.pinpoint.hbase.schema.reader.core.ModifyTableChange)6 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)6 HbaseSchemaStatus (com.navercorp.pinpoint.hbase.schema.core.HbaseSchemaStatus)5 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)5 CreateColumnFamilyChange (com.navercorp.pinpoint.hbase.schema.reader.core.CreateColumnFamilyChange)4 ColumnFamilyChange (com.navercorp.pinpoint.hbase.schema.reader.core.ColumnFamilyChange)3 HbaseAdminOperation (com.navercorp.pinpoint.common.hbase.HbaseAdminOperation)2 ChangeSetManager (com.navercorp.pinpoint.hbase.schema.core.ChangeSetManager)2 HbaseSchemaCommandManager (com.navercorp.pinpoint.hbase.schema.core.command.HbaseSchemaCommandManager)2 InvalidHbaseSchemaException (com.navercorp.pinpoint.hbase.schema.reader.InvalidHbaseSchemaException)2 ColumnFamilyConfiguration (com.navercorp.pinpoint.hbase.schema.reader.core.ColumnFamilyConfiguration)2 TableCommand (com.navercorp.pinpoint.hbase.schema.core.command.TableCommand)1 HbaseSchemaParseException (com.navercorp.pinpoint.hbase.schema.reader.HbaseSchemaParseException)1 TableConfiguration (com.navercorp.pinpoint.hbase.schema.reader.core.TableConfiguration)1