Search in sources :

Example 21 with ChangeSet

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

the class SchemaChangeLogServiceImplTest method recordChangeSets_withExecutionOrder.

@Test
public void recordChangeSets_withExecutionOrder() {
    // Given
    final int initialExecOrder = random.nextInt(10) + 1;
    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", initialExecOrder, changeSets);
    // Then
    MatcherAssert.assertThat(schemaChangeLogs.size(), equalTo(numChangeSets));
    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 22 with ChangeSet

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

the class HbaseSchemaServiceImpl method getSchemaStatus.

/**
 * This implementation uses the executed schema change logs to compare against the specified {@code changeSets} to
 * check the current schema status, regardless of how the actual schema looks like.
 */
// TODO May be a good idea to compare the actual tables against each of the change sets in the future.
@Override
public HbaseSchemaStatus getSchemaStatus(String namespace, List<ChangeSet> changeSets) {
    if (CollectionUtils.isEmpty(changeSets)) {
        throw new IllegalArgumentException("changeSets must not be empty");
    }
    if (!schemaChangeLogService.isAvailable(namespace)) {
        return HbaseSchemaStatus.NONE;
    }
    List<SchemaChangeLog> schemaChangeLogs = schemaChangeLogService.getSchemaChangeLogs(namespace);
    if (CollectionUtils.isEmpty(schemaChangeLogs)) {
        return HbaseSchemaStatus.NONE;
    }
    List<ChangeSet> unexecutedChangeSets;
    ChangeSetManager changeSetManager = new ChangeSetManager(changeSets);
    try {
        unexecutedChangeSets = changeSetManager.filterExecutedChangeSets(schemaChangeLogs);
    } catch (IllegalArgumentException e) {
        logger.error("[{}] Invalid hbase schema, cause : {}", namespace, e.getMessage());
        return HbaseSchemaStatus.INVALID;
    }
    if (CollectionUtils.isEmpty(unexecutedChangeSets)) {
        return HbaseSchemaStatus.VALID;
    }
    return HbaseSchemaStatus.VALID_OUT_OF_DATE;
}
Also used : ChangeSetManager(com.navercorp.pinpoint.hbase.schema.core.ChangeSetManager) ChangeSet(com.navercorp.pinpoint.hbase.schema.reader.core.ChangeSet) SchemaChangeLog(com.navercorp.pinpoint.hbase.schema.domain.SchemaChangeLog)

Example 23 with ChangeSet

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

the class SchemaChangeLogServiceImpl method recordChangeSets.

@Override
public List<SchemaChangeLog> recordChangeSets(String namespace, int executionOrder, List<ChangeSet> changeSets) {
    if (CollectionUtils.isEmpty(changeSets)) {
        return Collections.emptyList();
    }
    int startingOrder = executionOrder;
    long executionTimestamp = System.currentTimeMillis();
    List<SchemaChangeLog> schemaChangeLogs = new ArrayList<>();
    for (ChangeSet changeSet : changeSets) {
        SchemaChangeLog schemaChangeLog = recordChangeSet(namespace, executionTimestamp, startingOrder, changeSet);
        schemaChangeLogs.add(schemaChangeLog);
        startingOrder++;
    }
    return schemaChangeLogs;
}
Also used : ArrayList(java.util.ArrayList) ChangeSet(com.navercorp.pinpoint.hbase.schema.reader.core.ChangeSet) SchemaChangeLog(com.navercorp.pinpoint.hbase.schema.domain.SchemaChangeLog)

Example 24 with ChangeSet

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

the class HbaseSchemaServiceImplTest method getSchemaStatus_validSchemaChangeLogs.

@Test
public void getSchemaStatus_validSchemaChangeLogs() {
    final String namespace = "namespace";
    final List<ChangeSet> changeSets = Arrays.asList(newChangeSet("id1", "value1"), newChangeSet("id2", "value2"), newChangeSet("id3", "value3"));
    final List<SchemaChangeLog> schemaChangeLogs = Arrays.asList(newSchemaChangeLog("id1", "value1", 1), newSchemaChangeLog("id2", "value2", 2), newSchemaChangeLog("id3", "value3", 3));
    when(schemaChangeLogService.isAvailable(namespace)).thenReturn(true);
    when(schemaChangeLogService.getSchemaChangeLogs(namespace)).thenReturn(schemaChangeLogs);
    HbaseSchemaStatus schemaStatus = hbaseSchemaService.getSchemaStatus(namespace, changeSets);
    MatcherAssert.assertThat(schemaStatus, is(HbaseSchemaStatus.VALID));
}
Also used : ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ChangeSet(com.navercorp.pinpoint.hbase.schema.reader.core.ChangeSet) HbaseSchemaStatus(com.navercorp.pinpoint.hbase.schema.core.HbaseSchemaStatus) SchemaChangeLog(com.navercorp.pinpoint.hbase.schema.domain.SchemaChangeLog) Test(org.junit.Test)

Example 25 with ChangeSet

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

the class HbaseSchemaServiceImplTest method getSchemaStatus_invalidSchemaChangeLogs.

@Test
public void getSchemaStatus_invalidSchemaChangeLogs() {
    final String namespace = "namespace";
    final List<ChangeSet> changeSets = Arrays.asList(newChangeSet("id1", "value1"), newChangeSet("id2", "value2"), newChangeSet("id3", "value3"));
    final List<SchemaChangeLog> schemaChangeLogs = Arrays.asList(newSchemaChangeLog("id1", "value2", 2), newSchemaChangeLog("id2", "value1", 1), newSchemaChangeLog("someOtherId", "value3", 3));
    when(schemaChangeLogService.isAvailable(namespace)).thenReturn(true);
    when(schemaChangeLogService.getSchemaChangeLogs(namespace)).thenReturn(schemaChangeLogs);
    HbaseSchemaStatus schemaStatus = hbaseSchemaService.getSchemaStatus(namespace, changeSets);
    MatcherAssert.assertThat(schemaStatus, is(HbaseSchemaStatus.INVALID));
}
Also used : ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ChangeSet(com.navercorp.pinpoint.hbase.schema.reader.core.ChangeSet) HbaseSchemaStatus(com.navercorp.pinpoint.hbase.schema.core.HbaseSchemaStatus) 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