Search in sources :

Example 1 with CheckpointPersistenceStaticConfigBuilder

use of com.linkedin.databus.client.DatabusHttpClientImpl.CheckpointPersistenceStaticConfigBuilder in project databus by linkedin.

the class CheckpointSerializerMain method main.

public static void main(String[] args) throws Exception {
    parseArgs(args);
    PatternLayout defaultLayout = new PatternLayout("%d{ISO8601} +%r [%t] (%p) {%c{1}} %m%n");
    ConsoleAppender defaultAppender = new ConsoleAppender(defaultLayout);
    Logger.getRootLogger().removeAllAppenders();
    Logger.getRootLogger().addAppender(defaultAppender);
    Logger.getRootLogger().setLevel(Level.INFO);
    Logger.getRootLogger().info("NOTE. This tool works only with V2/V1 checkpoints");
    CheckpointPersistenceProvider cp3 = null;
    if (null != _cp3Props) {
        CheckpointPersistenceStaticConfigBuilder cp3ConfBuilder = new CheckpointPersistenceStaticConfigBuilder();
        ConfigLoader<CheckpointPersistenceStaticConfig> configLoader = new ConfigLoader<DatabusHttpClientImpl.CheckpointPersistenceStaticConfig>(_propPrefix, cp3ConfBuilder);
        configLoader.loadConfig(_cp3Props);
        CheckpointPersistenceStaticConfig cp3Conf = cp3ConfBuilder.build();
        if (cp3Conf.getType() != CheckpointPersistenceStaticConfig.ProviderType.FILE_SYSTEM) {
            throw new RuntimeException("don't know what to do with cp3 type:" + cp3Conf.getType());
        }
        cp3 = new FileSystemCheckpointPersistenceProvider(cp3Conf.getFileSystem(), 2);
    } else if (null != _clientProps) {
        DatabusHttpClientImpl.Config clientConfBuilder = new DatabusHttpClientImpl.Config();
        ConfigLoader<DatabusHttpClientImpl.StaticConfig> configLoader = new ConfigLoader<DatabusHttpClientImpl.StaticConfig>(_propPrefix, clientConfBuilder);
        configLoader.loadConfig(_clientProps);
        DatabusHttpClientImpl.StaticConfig clientConf = clientConfBuilder.build();
        if (clientConf.getCheckpointPersistence().getType() != CheckpointPersistenceStaticConfig.ProviderType.FILE_SYSTEM) {
            throw new RuntimeException("don't know what to do with cp3 type:" + clientConf.getCheckpointPersistence().getType());
        }
        cp3 = new FileSystemCheckpointPersistenceProvider(clientConf.getCheckpointPersistence().getFileSystem(), 2);
    }
    List<String> sourceList = Arrays.asList(_sources);
    Checkpoint cpOld = null != cp3 ? cp3.loadCheckpoint(sourceList) : new Checkpoint();
    Checkpoint cpNew;
    if (Action.PRINT == _action) {
        cpNew = updateCheckpoint(cpOld);
    } else if (Action.CHANGE == _action) {
        cpNew = updateCheckpoint(cpOld);
        cp3.storeCheckpoint(sourceList, cpNew);
        // reread as a sanity check
        cpNew = cp3.loadCheckpoint(sourceList);
    } else if (Action.DELETE == _action) {
        cp3.removeCheckpoint(sourceList);
        cpNew = cp3.loadCheckpoint(sourceList);
    } else {
        throw new RuntimeException("don't know what to do with action: " + _action);
    }
    if (null != cpOld)
        System.out.println("old: " + cpOld.toString());
    else
        System.out.println("old: null");
    if (null != cpNew)
        System.out.println("new: " + cpNew.toString());
    else
        System.out.println("new: null");
}
Also used : ConsoleAppender(org.apache.log4j.ConsoleAppender) CheckpointPersistenceStaticConfigBuilder(com.linkedin.databus.client.DatabusHttpClientImpl.CheckpointPersistenceStaticConfigBuilder) ConfigLoader(com.linkedin.databus.core.util.ConfigLoader) CheckpointPersistenceStaticConfig(com.linkedin.databus.client.DatabusHttpClientImpl.CheckpointPersistenceStaticConfig) PatternLayout(org.apache.log4j.PatternLayout) CheckpointPersistenceStaticConfig(com.linkedin.databus.client.DatabusHttpClientImpl.CheckpointPersistenceStaticConfig) DatabusHttpClientImpl(com.linkedin.databus.client.DatabusHttpClientImpl) FileSystemCheckpointPersistenceProvider(com.linkedin.databus.client.pub.FileSystemCheckpointPersistenceProvider) CheckpointPersistenceProvider(com.linkedin.databus.client.pub.CheckpointPersistenceProvider) Checkpoint(com.linkedin.databus.core.Checkpoint) DatabusRuntimeException(com.linkedin.databus.core.DatabusRuntimeException) FileSystemCheckpointPersistenceProvider(com.linkedin.databus.client.pub.FileSystemCheckpointPersistenceProvider) CheckpointPersistenceStaticConfig(com.linkedin.databus.client.DatabusHttpClientImpl.CheckpointPersistenceStaticConfig)

Aggregations

DatabusHttpClientImpl (com.linkedin.databus.client.DatabusHttpClientImpl)1 CheckpointPersistenceStaticConfig (com.linkedin.databus.client.DatabusHttpClientImpl.CheckpointPersistenceStaticConfig)1 CheckpointPersistenceStaticConfigBuilder (com.linkedin.databus.client.DatabusHttpClientImpl.CheckpointPersistenceStaticConfigBuilder)1 CheckpointPersistenceProvider (com.linkedin.databus.client.pub.CheckpointPersistenceProvider)1 FileSystemCheckpointPersistenceProvider (com.linkedin.databus.client.pub.FileSystemCheckpointPersistenceProvider)1 Checkpoint (com.linkedin.databus.core.Checkpoint)1 DatabusRuntimeException (com.linkedin.databus.core.DatabusRuntimeException)1 ConfigLoader (com.linkedin.databus.core.util.ConfigLoader)1 ConsoleAppender (org.apache.log4j.ConsoleAppender)1 PatternLayout (org.apache.log4j.PatternLayout)1