Search in sources :

Example 1 with TableCountKey

use of io.datarouter.nodewatch.storage.tablecount.TableCountKey in project datarouter by hotpads.

the class MigrateTableCountMetadataHandler method migrate.

private void migrate(String sourceNode, String targetNode) {
    String sourceClientName = sourceNode.split("\\.")[0];
    String sourceTableName = sourceNode.split("\\.")[1];
    String targetClientName = targetNode.split("\\.")[0];
    String targetTableName = targetNode.split("\\.")[1];
    // migrate rows in TableCount
    var tableCountKeyPrefix = new TableCountKey(sourceClientName, sourceTableName, null);
    tableCountDao.scanWithPrefix(tableCountKeyPrefix).map(tableCount -> {
        tableCount.getKey().setClientName(targetClientName);
        tableCount.getKey().setTableName(targetTableName);
        return tableCount;
    }).batch(100).forEach(tableCountDao::putMulti);
    // migrate rows in TableSample
    var tableSampleKeyPrefix = new TableSampleKey(sourceClientName, sourceTableName, null, null);
    tableSampleDao.scanWithPrefix(tableSampleKeyPrefix).map(tableSample -> {
        tableSample.getKey().setClientName(targetClientName);
        tableSample.getKey().setTableName(targetTableName);
        return tableSample;
    }).batch(100).forEach(tableSampleDao::putMulti);
}
Also used : OptionalString(io.datarouter.web.handler.types.optional.OptionalString) TableCountKey(io.datarouter.nodewatch.storage.tablecount.TableCountKey) TableSampleKey(io.datarouter.nodewatch.storage.tablesample.TableSampleKey)

Example 2 with TableCountKey

use of io.datarouter.nodewatch.storage.tablecount.TableCountKey in project datarouter by hotpads.

the class TableCountHandler method deleteAllMetadata.

@Handler
private Mav deleteAllMetadata(String clientName, String tableName) {
    // delete rows from TableCount
    var tableCountKeyPrefix = new TableCountKey(clientName, tableName, null);
    tableCountDao.deleteWithPrefix(tableCountKeyPrefix);
    // delete rows from TableSample
    var tableSampleKeyPrefix = new TableSampleKey(clientName, tableName, null, null);
    tableSampleDao.deleteWithPrefix(tableSampleKeyPrefix);
    // delete from LatestTableCount
    var latestTableCountKey = new LatestTableCountKey(clientName, tableName);
    latestTableCountDao.delete(latestTableCountKey);
    var dto = new DatarouterChangelogDtoBuilder("Nodewatch", clientName + "." + tableName, "deleted metadata", getSessionInfo().getNonEmptyUsernameOrElse("")).build();
    changelogRecorder.record(dto);
    return new InContextRedirectMav(request, paths.datarouter.nodewatch.tableCount.toSlashedString());
}
Also used : LatestTableCountKey(io.datarouter.nodewatch.storage.latesttablecount.LatestTableCountKey) InContextRedirectMav(io.datarouter.web.handler.mav.imp.InContextRedirectMav) TableCountKey(io.datarouter.nodewatch.storage.tablecount.TableCountKey) LatestTableCountKey(io.datarouter.nodewatch.storage.latesttablecount.LatestTableCountKey) TableSampleKey(io.datarouter.nodewatch.storage.tablesample.TableSampleKey) DatarouterChangelogDtoBuilder(io.datarouter.instrumentation.changelog.ChangelogRecorder.DatarouterChangelogDtoBuilder) BaseHandler(io.datarouter.web.handler.BaseHandler)

Aggregations

TableCountKey (io.datarouter.nodewatch.storage.tablecount.TableCountKey)2 TableSampleKey (io.datarouter.nodewatch.storage.tablesample.TableSampleKey)2 DatarouterChangelogDtoBuilder (io.datarouter.instrumentation.changelog.ChangelogRecorder.DatarouterChangelogDtoBuilder)1 LatestTableCountKey (io.datarouter.nodewatch.storage.latesttablecount.LatestTableCountKey)1 BaseHandler (io.datarouter.web.handler.BaseHandler)1 InContextRedirectMav (io.datarouter.web.handler.mav.imp.InContextRedirectMav)1 OptionalString (io.datarouter.web.handler.types.optional.OptionalString)1