Search in sources :

Example 16 with SchemaChangeLog

use of com.navercorp.pinpoint.hbase.schema.domain.SchemaChangeLog 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 17 with SchemaChangeLog

use of com.navercorp.pinpoint.hbase.schema.domain.SchemaChangeLog 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 18 with SchemaChangeLog

use of com.navercorp.pinpoint.hbase.schema.domain.SchemaChangeLog 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 19 with SchemaChangeLog

use of com.navercorp.pinpoint.hbase.schema.domain.SchemaChangeLog 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)

Example 20 with SchemaChangeLog

use of com.navercorp.pinpoint.hbase.schema.domain.SchemaChangeLog in project pinpoint by naver.

the class ChangeSetManagerTest method filterExecutedChangeSets_largerSchemaChangeLogs.

@Test
public void filterExecutedChangeSets_largerSchemaChangeLogs() {
    ChangeSet changeSet = newChangeSet("id1", "value1");
    ChangeSetManager changeSetManager = new ChangeSetManager(Arrays.asList(changeSet));
    List<SchemaChangeLog> schemaChangeLogs = Arrays.asList(newSchemaChangeLog("id1", "value1", 1), newSchemaChangeLog("id2", "value2", 2));
    List<ChangeSet> unexecutedChangeSets = changeSetManager.filterExecutedChangeSets(schemaChangeLogs);
    assertThat(unexecutedChangeSets, is(empty()));
}
Also used : ChangeSet(com.navercorp.pinpoint.hbase.schema.reader.core.ChangeSet) SchemaChangeLog(com.navercorp.pinpoint.hbase.schema.domain.SchemaChangeLog) Test(org.junit.Test)

Aggregations

SchemaChangeLog (com.navercorp.pinpoint.hbase.schema.domain.SchemaChangeLog)29 ChangeSet (com.navercorp.pinpoint.hbase.schema.reader.core.ChangeSet)23 Test (org.junit.Test)20 ArrayList (java.util.ArrayList)10 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)5 HbaseSchemaStatus (com.navercorp.pinpoint.hbase.schema.core.HbaseSchemaStatus)3 ChangeSetManager (com.navercorp.pinpoint.hbase.schema.core.ChangeSetManager)1 CheckSum (com.navercorp.pinpoint.hbase.schema.core.CheckSum)1 HbaseSchemaCommandManager (com.navercorp.pinpoint.hbase.schema.core.command.HbaseSchemaCommandManager)1 HashSet (java.util.HashSet)1 TreeMap (java.util.TreeMap)1