Search in sources :

Example 6 with DatabusHttpClientImpl

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

the class TestDatabusV2RegistrationImpl method testErrorRegistration.

@Test
public void testErrorRegistration() throws Exception {
    DatabusHttpClientImpl client = null;
    try {
        DatabusHttpClientImpl.Config clientConfig = new DatabusHttpClientImpl.Config();
        clientConfig.getContainer().getJmx().setRmiEnabled(false);
        clientConfig.getContainer().setHttpPort(12003);
        client = new DatabusHttpClientImpl(clientConfig);
        registerRelay(1, "relay1", new InetSocketAddress("localhost", 8888), "S1,S2", client);
        registerRelay(2, "relay2", new InetSocketAddress("localhost", 7777), "S1,S3", client);
        registerRelay(3, "relay1.1", new InetSocketAddress("localhost", 8887), "S1,S2", client);
        registerRelay(4, "relay3", new InetSocketAddress("localhost", 6666), "S3,S4,S5", client);
        TestConsumer listener1 = new TestConsumer();
        DatabusRegistration reg = client.register(listener1, "S6", "S2");
        assertEquals("Registered State", RegistrationState.REGISTERED, reg.getState());
        assertEquals("Component Name", "Status_TestConsumer_6fdc9d8d", reg.getStatus().getComponentName());
        assertEquals("Component Status", Status.INITIALIZING, reg.getStatus().getStatus());
        // Start
        boolean started = false;
        boolean gotException = false;
        try {
            started = reg.start();
        } catch (DatabusClientException ex) {
            gotException = true;
        }
        assertEquals("gotException", true, gotException);
        assertEquals("Registered State", RegistrationState.REGISTERED, reg.getState());
        assertEquals("Component Status", Status.INITIALIZING, reg.getStatus().getStatus());
        gotException = false;
        try {
            reg = client.register((AbstractDatabusCombinedConsumer) null, "S6", "S2");
        } catch (DatabusClientException ex) {
            gotException = true;
        }
        assertEquals("gotException", true, gotException);
        gotException = false;
        try {
            reg = client.register(listener1, null);
        } catch (DatabusClientException ex) {
            gotException = true;
        }
        assertEquals("gotException", true, gotException);
        if (reg != null)
            reg.deregister();
    } finally {
        if (null != client)
            client.shutdown();
    }
}
Also used : DatabusRegistration(com.linkedin.databus.client.pub.DatabusRegistration) InetSocketAddress(java.net.InetSocketAddress) DatabusHttpClientImpl(com.linkedin.databus.client.DatabusHttpClientImpl) AbstractDatabusCombinedConsumer(com.linkedin.databus.client.consumer.AbstractDatabusCombinedConsumer) DatabusClientException(com.linkedin.databus.client.pub.DatabusClientException) Test(org.testng.annotations.Test)

Example 7 with DatabusHttpClientImpl

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

the class ClusterFileLoggingClient method mainFunction.

public void mainFunction(String[] args) throws Exception {
    String[] leftOverArgs = processLocalArgs(args);
    Properties startupProps = DatabusHttpClientImpl.processCommandLineArgs(leftOverArgs);
    DatabusHttpClientImpl.Config clientConfigBuilder = new DatabusHttpClientImpl.Config();
    clientConfigBuilder.getContainer().setIdFromName(MODULE + ".localhost");
    if (_enableBootStrap) {
        clientConfigBuilder.getRuntime().getBootstrap().setEnabled(true);
    }
    ConfigLoader<DatabusHttpClientImpl.StaticConfig> configLoader = new ConfigLoader<DatabusHttpClientImpl.StaticConfig>("databus.client.", clientConfigBuilder);
    String[] sources = getSources();
    StringBuilder sourcesString = new StringBuilder();
    boolean firstSrc = true;
    for (String source : sources) {
        if (!firstSrc)
            sourcesString.append(",");
        firstSrc = false;
        sourcesString.append(source);
    }
    if (_httpPort != null) {
        startupProps.put("databus.client.container.httpPort", _httpPort);
    }
    if (_jmxServicePort != null) {
        startupProps.put("databus.client.container.jmx.jmxServicePort", _jmxServicePort);
    }
    if (_checkpointFileRootDir != null) {
        startupProps.put("databus.client.checkpointPersistence.fileSystem.rootDirectory", _checkpointFileRootDir);
    }
    DatabusHttpClientImpl.StaticConfig clientConfig = configLoader.loadConfig(startupProps);
    // set up relay
    ServerInfoBuilder relayBuilder = clientConfig.getRuntime().getRelay("1");
    relayBuilder.setName("DefaultRelay");
    if (_relayHost != null) {
        relayBuilder.setHost(_relayHost);
    }
    if (_relayPort != null) {
        relayBuilder.setPort(Integer.parseInt(_relayPort));
    }
    relayBuilder.setSources(sourcesString.toString());
    // set up bootstrap
    if (_enableBootStrap) {
        ServerInfoBuilder bootstrapBuilder = clientConfig.getRuntime().getBootstrap().getService("2");
        bootstrapBuilder.setName("DefaultBootstrapServices");
        if (_bootstrapHost != null) {
            bootstrapBuilder.setHost(_bootstrapHost);
        }
        if (_bootstrapPort != null) {
            bootstrapBuilder.setPort(Integer.parseInt(_bootstrapPort));
        }
        bootstrapBuilder.setSources(sourcesString.toString());
    }
    // set up listeners
    DatabusHttpClientImpl client = new DatabusHttpClientImpl(clientConfig);
    List<DatabusRegistration> regs = new ArrayList<DatabusRegistration>();
    for (String cluster : _clusters) {
        DatabusRegistration reg = client.registerCluster(cluster, createConsumerFactory(cluster, _valueDumpFile, _eventDumpFile), createServerSideFactory(cluster), createPartitionListener(cluster), sources);
        regs.add(reg);
    }
    // add pause processor
    try {
        client.getProcessorRegistry().register(ContainerOperationProcessor.COMMAND_NAME, new ContainerOperationProcessor(null, client));
    } catch (ProcessorRegistrationConflictException e) {
        LOG.error("Failed to register " + ConsumerPauseRequestProcessor.COMMAND_NAME);
    }
    DatabusClientShutdownThread shutdownThread = new DatabusClientShutdownThread(client);
    Runtime.getRuntime().addShutdownHook(shutdownThread);
    client.startAndBlock();
}
Also used : DatabusRegistration(com.linkedin.databus.client.pub.DatabusRegistration) ConfigLoader(com.linkedin.databus.core.util.ConfigLoader) ArrayList(java.util.ArrayList) DatabusHttpClientImpl(com.linkedin.databus.client.DatabusHttpClientImpl) ContainerOperationProcessor(com.linkedin.databus2.core.container.request.ContainerOperationProcessor) Properties(java.util.Properties) ServerInfoBuilder(com.linkedin.databus.client.pub.ServerInfo.ServerInfoBuilder) ProcessorRegistrationConflictException(com.linkedin.databus2.core.container.request.ProcessorRegistrationConflictException)

Example 8 with DatabusHttpClientImpl

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

the class SimpleFileLoggingConsumer method mainFunction.

public void mainFunction(String[] args) throws Exception {
    String[] leftOverArgs = processLocalArgs(args);
    Properties startupProps = DatabusHttpClientImpl.processCommandLineArgs(leftOverArgs);
    DatabusHttpClientImpl.Config clientConfigBuilder = new DatabusHttpClientImpl.Config();
    clientConfigBuilder.getContainer().setIdFromName(MODULE + ".localhost");
    if (_enableBootStrap) {
        clientConfigBuilder.getRuntime().getBootstrap().setEnabled(true);
    }
    ConfigLoader<DatabusHttpClientImpl.StaticConfig> configLoader = new ConfigLoader<DatabusHttpClientImpl.StaticConfig>("databus.client.", clientConfigBuilder);
    String[] sources = addSources();
    StringBuilder sourcesString = new StringBuilder();
    boolean firstSrc = true;
    for (String source : sources) {
        if (!firstSrc)
            sourcesString.append(",");
        firstSrc = false;
        sourcesString.append(source);
    }
    if (_httpPort != null) {
        startupProps.put("databus.client.container.httpPort", _httpPort);
    }
    if (_jmxServicePort != null) {
        startupProps.put("databus.client.container.jmx.jmxServicePort", _jmxServicePort);
    }
    if (_checkpointFileRootDir != null) {
        startupProps.put("databus.client.checkpointPersistence.fileSystem.rootDirectory", _checkpointFileRootDir);
    }
    DatabusHttpClientImpl.StaticConfig clientConfig = configLoader.loadConfig(startupProps);
    // set up relay
    ServerInfoBuilder relayBuilder = clientConfig.getRuntime().getRelay("1");
    relayBuilder.setName("DefaultRelay");
    if (_relayHost != null) {
        relayBuilder.setHost(_relayHost);
    }
    if (_relayPort != null) {
        relayBuilder.setPort(Integer.parseInt(_relayPort));
    }
    relayBuilder.setSources(sourcesString.toString());
    // set up bootstrap
    if (_enableBootStrap) {
        ServerInfoBuilder bootstrapBuilder = clientConfig.getRuntime().getBootstrap().getService("2");
        bootstrapBuilder.setName("DefaultBootstrapServices");
        if (_bootstrapHost != null) {
            bootstrapBuilder.setHost(_bootstrapHost);
        }
        if (_bootstrapPort != null) {
            bootstrapBuilder.setPort(Integer.parseInt(_bootstrapPort));
        }
        bootstrapBuilder.setSources(sourcesString.toString());
    }
    // handler server side filtering, can either pass a config file or set from command line
    DbusKeyCompositeFilterConfig filterConfig = createServerSideFilterConfig(_filterConfFile, startupProps);
    // set up listeners
    DatabusHttpClientImpl client = new DatabusHttpClientImpl(clientConfig);
    // dump decoded payload values and raw (undecoded) events
    DatabusFileLoggingConsumer consumer = createTypedConsumer(_valueDumpFile, _eventDumpFile);
    if (_eventPattern != null) {
        consumer.setEventPattern(_eventPattern);
    }
    DatabusRegistration reg = client.register(consumer, sources);
    if (!(reg instanceof DatabusV2RegistrationImpl)) {
        throw new RuntimeException("Unexpected type for registration Object !!");
    }
    if (null != filterConfig)
        reg.withServerSideFilter(filterConfig);
    // add pause processor
    try {
        client.getProcessorRegistry().register(ConsumerPauseRequestProcessor.COMMAND_NAME, new ConsumerPauseRequestProcessor(null, consumer));
        client.getProcessorRegistry().register(ContainerOperationProcessor.COMMAND_NAME, new ContainerOperationProcessor(null, client));
    } catch (ProcessorRegistrationConflictException e) {
        LOG.error("Failed to register " + ConsumerPauseRequestProcessor.COMMAND_NAME);
    }
    DatabusClientShutdownThread shutdownThread = new DatabusClientShutdownThread(client);
    Runtime.getRuntime().addShutdownHook(shutdownThread);
    //this should automatically start the registration
    client.startAndBlock();
}
Also used : DbusKeyCompositeFilterConfig(com.linkedin.databus2.core.filter.DbusKeyCompositeFilterConfig) DatabusRegistration(com.linkedin.databus.client.pub.DatabusRegistration) ConfigLoader(com.linkedin.databus.core.util.ConfigLoader) DbusKeyCompositeFilterConfig(com.linkedin.databus2.core.filter.DbusKeyCompositeFilterConfig) DatabusHttpClientImpl(com.linkedin.databus.client.DatabusHttpClientImpl) ContainerOperationProcessor(com.linkedin.databus2.core.container.request.ContainerOperationProcessor) Properties(java.util.Properties) ServerInfoBuilder(com.linkedin.databus.client.pub.ServerInfo.ServerInfoBuilder) ProcessorRegistrationConflictException(com.linkedin.databus2.core.container.request.ProcessorRegistrationConflictException) DatabusV2RegistrationImpl(com.linkedin.databus.client.registration.DatabusV2RegistrationImpl)

Example 9 with DatabusHttpClientImpl

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

the class PersonClientMain method main.

public static void main(String[] args) throws Exception {
    DatabusHttpClientImpl.Config configBuilder = new DatabusHttpClientImpl.Config();
    //Try to connect to a relay on localhost
    configBuilder.getRuntime().getRelay("1").setHost("localhost");
    configBuilder.getRuntime().getRelay("1").setPort(11115);
    configBuilder.getRuntime().getRelay("1").setSources(PERSON_SOURCE);
    //Instantiate a client using command-line parameters if any
    DatabusHttpClientImpl client = DatabusHttpClientImpl.createFromCli(args, configBuilder);
    //register callbacks
    PersonConsumer personConsumer = new PersonConsumer();
    client.registerDatabusStreamListener(personConsumer, null, PERSON_SOURCE);
    client.registerDatabusBootstrapListener(personConsumer, null, PERSON_SOURCE);
    //fire off the Databus client
    client.startAndBlock();
}
Also used : DatabusHttpClientImpl(com.linkedin.databus.client.DatabusHttpClientImpl)

Aggregations

DatabusHttpClientImpl (com.linkedin.databus.client.DatabusHttpClientImpl)9 DatabusRegistration (com.linkedin.databus.client.pub.DatabusRegistration)5 InetSocketAddress (java.net.InetSocketAddress)5 Test (org.testng.annotations.Test)5 ArrayList (java.util.ArrayList)4 DatabusClientException (com.linkedin.databus.client.pub.DatabusClientException)3 ServerInfoBuilder (com.linkedin.databus.client.pub.ServerInfo.ServerInfoBuilder)3 ProcessorRegistrationConflictException (com.linkedin.databus2.core.container.request.ProcessorRegistrationConflictException)3 DbusKeyCompositeFilterConfig (com.linkedin.databus2.core.filter.DbusKeyCompositeFilterConfig)3 AbstractDatabusCombinedConsumer (com.linkedin.databus.client.consumer.AbstractDatabusCombinedConsumer)2 StaticConfig (com.linkedin.databus.client.pub.ClusterCheckpointPersistenceProvider.StaticConfig)2 DbusClusterInfo (com.linkedin.databus.client.pub.DbusClusterInfo)2 ConfigLoader (com.linkedin.databus.core.util.ConfigLoader)2 InvalidConfigException (com.linkedin.databus.core.util.InvalidConfigException)2 ContainerOperationProcessor (com.linkedin.databus2.core.container.request.ContainerOperationProcessor)2 Properties (java.util.Properties)2 DatabusSourcesConnection (com.linkedin.databus.client.DatabusSourcesConnection)1 ConsumerPauseRequestProcessor (com.linkedin.databus.client.generic.ConsumerPauseRequestProcessor)1 DatabusBootstrapConsumer (com.linkedin.databus.client.pub.DatabusBootstrapConsumer)1 DatabusCombinedConsumer (com.linkedin.databus.client.pub.DatabusCombinedConsumer)1