Search in sources :

Example 6 with ServerInfoBuilder

use of com.linkedin.databus.client.pub.ServerInfo.ServerInfoBuilder 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 7 with ServerInfoBuilder

use of com.linkedin.databus.client.pub.ServerInfo.ServerInfoBuilder in project databus by linkedin.

the class RelayEventProducer method createServerInfo.

static Set<ServerInfo> createServerInfo(String serverName, String subscriptions) throws InvalidConfigException {
    Set<ServerInfo> serverInfo = new HashSet<ServerInfo>();
    ServerInfoBuilder sBuilder = new ServerInfoBuilder();
    sBuilder.setAddress(serverName + ":" + subscriptions);
    // sBuilder.setSources(subscriptions);
    serverInfo.add(sBuilder.build());
    return serverInfo;
}
Also used : ServerInfo(com.linkedin.databus.client.pub.ServerInfo) HashSet(java.util.HashSet) ServerInfoBuilder(com.linkedin.databus.client.pub.ServerInfo.ServerInfoBuilder)

Example 8 with ServerInfoBuilder

use of com.linkedin.databus.client.pub.ServerInfo.ServerInfoBuilder in project databus by linkedin.

the class DatabusHttpClientImpl method parseServerInfosMap.

private static List<ServerInfo> parseServerInfosMap(Map<String, ServerInfoBuilder> map) throws InvalidConfigException {
    ArrayList<ServerInfo> infos = new ArrayList<ServerInfo>((int) (map.size() * 1.3));
    for (Map.Entry<String, ServerInfoBuilder> entry : map.entrySet()) {
        LOG.info("parseServerInfo: " + entry.toString());
        ServerInfoBuilder builder = entry.getValue();
        boolean added = infos.add(builder.build());
        LOG.info("added=" + added);
    }
    LOG.info("info size=" + infos.size());
    return infos;
}
Also used : ServerInfo(com.linkedin.databus.client.pub.ServerInfo) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) ServerInfoBuilder(com.linkedin.databus.client.pub.ServerInfo.ServerInfoBuilder)

Example 9 with ServerInfoBuilder

use of com.linkedin.databus.client.pub.ServerInfo.ServerInfoBuilder in project databus by linkedin.

the class TestServerInfo method testBuilderSetAddressWithName.

@Test
public void testBuilderSetAddressWithName() throws Exception {
    ServerInfoBuilder builder = new ServerInfoBuilder();
    String address = ServerInfoBuilder.generateAddress("SeRvEr", "localhost", 99, "com.linkedin.events.source1", "com.linkedin.events.source3");
    builder.setAddress(address);
    ServerInfo si = builder.build();
    assertEquals("SeRvEr", si.getName());
    assertEquals(99, si.getAddress().getPort());
    assertEquals(2, si.getSources().size());
    assertEquals("com.linkedin.events.source1", si.getSources().get(0));
    assertEquals("com.linkedin.events.source3", si.getSources().get(1));
}
Also used : ServerInfoBuilder(com.linkedin.databus.client.pub.ServerInfo.ServerInfoBuilder) Test(org.testng.annotations.Test)

Example 10 with ServerInfoBuilder

use of com.linkedin.databus.client.pub.ServerInfo.ServerInfoBuilder in project databus by linkedin.

the class TestServerInfo method testServerInfoSetBuilder.

@Test
public void testServerInfoSetBuilder() throws Exception {
    ServerInfoBuilder sib = new ServerInfoBuilder();
    String address1 = ServerInfoBuilder.generateAddress("SeRvEr1", "localhost", 98, "com.linkedin.events.source1", "com.linkedin.events.source3");
    sib.setAddress(address1);
    ServerInfo si1 = sib.build();
    String address2 = ServerInfoBuilder.generateAddress("SeRvEr2", "localhost", 99, "com.linkedin.events.source1", "com.linkedin.events.source3");
    sib.setAddress(address2);
    ServerInfo si2 = sib.build();
    String address3 = ServerInfoBuilder.generateAddress(null, "localhost", 100, "com.linkedin.events.source1", "com.linkedin.events.source2", "com.linkedin.events.source3");
    sib.setAddress(address3);
    ServerInfo si3 = sib.build();
    ServerInfoSetBuilder builder = new ServerInfoSetBuilder();
    builder.setServers(address1 + ServerInfoSetBuilder.SERVER_INFO_SEPARATOR + address2 + ServerInfoSetBuilder.SERVER_INFO_SEPARATOR + address3);
    List<ServerInfo> res = builder.build();
    assertEquals(3, res.size());
    assertEquals(true, res.contains(si1));
    assertEquals(true, res.contains(si2));
    assertEquals(true, res.contains(si3));
}
Also used : ServerInfoSetBuilder(com.linkedin.databus.client.pub.ServerInfo.ServerInfoSetBuilder) ServerInfoBuilder(com.linkedin.databus.client.pub.ServerInfo.ServerInfoBuilder) Test(org.testng.annotations.Test)

Aggregations

ServerInfoBuilder (com.linkedin.databus.client.pub.ServerInfo.ServerInfoBuilder)11 ServerInfo (com.linkedin.databus.client.pub.ServerInfo)5 DatabusHttpClientImpl (com.linkedin.databus.client.DatabusHttpClientImpl)3 RuntimeConfigBuilder (com.linkedin.databus.client.DatabusHttpClientImpl.RuntimeConfigBuilder)3 ProcessorRegistrationConflictException (com.linkedin.databus2.core.container.request.ProcessorRegistrationConflictException)3 ArrayList (java.util.ArrayList)3 Test (org.testng.annotations.Test)3 DatabusRegistration (com.linkedin.databus.client.pub.DatabusRegistration)2 ConfigLoader (com.linkedin.databus.core.util.ConfigLoader)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 DatabusStreamConsumer (com.linkedin.databus.client.pub.DatabusStreamConsumer)1 ServerInfoSetBuilder (com.linkedin.databus.client.pub.ServerInfo.ServerInfoSetBuilder)1 DatabusV2RegistrationImpl (com.linkedin.databus.client.registration.DatabusV2RegistrationImpl)1 DbusEventBuffer (com.linkedin.databus.core.DbusEventBuffer)1 DbusKeyCompositeFilterConfig (com.linkedin.databus2.core.filter.DbusKeyCompositeFilterConfig)1 HashMap (java.util.HashMap)1