Search in sources :

Example 1 with DbusClusterInfo

use of com.linkedin.databus.client.pub.DbusClusterInfo in project databus by linkedin.

the class DatabusHttpClientImpl method registerCluster.

@Override
public DatabusRegistration registerCluster(String cluster, DbusClusterConsumerFactory consumerFactory, DbusServerSideFilterFactory filterFactory, DbusPartitionListener partitionListener, String... sources) throws DatabusClientException {
    if ((null == sources) || (sources.length == 0))
        throw new DatabusClientException("Sources is empty !!");
    if (_activeClusters.contains(cluster))
        throw new DatabusClientException("Cluster :" + cluster + " has already been registed to this client instance." + " Only one registration per cluster is allowed for a databus client instance !!");
    ClusterRegistrationStaticConfig c = _clientStaticConfig.getClientCluster(cluster);
    if (null == c)
        throw new DatabusClientException("Cluster Configuration for cluster (" + cluster + ") not provided !!");
    if (null == consumerFactory)
        throw new DatabusClientException("Consumer Factory is null !!");
    ClusterCheckpointPersistenceProvider.StaticConfig ckptPersistenceProviderConfig = new ClusterCheckpointPersistenceProvider.StaticConfig(c.getZkAddr(), c.getClusterName(), c.getMaxCkptWritesSkipped(), c.getCheckpointIntervalMs());
    DbusClusterInfo clusterInfo = new DbusClusterInfo(c.getClusterName(), c.getNumPartitions(), c.getQuorum());
    RegistrationId regId = RegistrationIdGenerator.generateNewId(c.getClusterName());
    DatabusV2ClusterRegistrationImpl reg = new DatabusV2ClusterRegistrationImpl(regId, this, ckptPersistenceProviderConfig, clusterInfo, consumerFactory, filterFactory, partitionListener, sources);
    _regList.add(reg);
    reg.onRegister();
    _activeClusters.add(cluster);
    return reg;
}
Also used : DatabusV2ClusterRegistrationImpl(com.linkedin.databus.client.registration.DatabusV2ClusterRegistrationImpl) ClusterCheckpointPersistenceProvider(com.linkedin.databus.client.pub.ClusterCheckpointPersistenceProvider) DbusClusterInfo(com.linkedin.databus.client.pub.DbusClusterInfo) RegistrationId(com.linkedin.databus.client.pub.RegistrationId) ClusterRegistrationStaticConfig(com.linkedin.databus.client.registration.ClusterRegistrationStaticConfig) ClusterRegistrationStaticConfig(com.linkedin.databus.client.registration.ClusterRegistrationStaticConfig) DatabusClientException(com.linkedin.databus.client.pub.DatabusClientException)

Example 2 with DbusClusterInfo

use of com.linkedin.databus.client.pub.DbusClusterInfo in project databus by linkedin.

the class TestDatabusV2ClusterRegistrationImpl method testRegistration.

@Test
public void testRegistration() 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);
        TestDbusPartitionListener listener = new TestDbusPartitionListener();
        StaticConfig ckptConfig = new StaticConfig("localhost:1356", "dummy", 1, 1);
        DbusClusterInfo clusterInfo = new DbusClusterInfo("dummy", 10, 1);
        DatabusV2ClusterRegistrationImpl reg = new TestableDatabusV2ClusterRegistrationImpl(null, client, ckptConfig, clusterInfo, new TestDbusClusterConsumerFactory(), new TestDbusServerSideFilterFactory(), listener, "S1", "S3");
        reg.onRegister();
        // Start
        reg.start();
        assertEquals("State CHeck", reg.getState(), RegistrationState.STARTED);
        // Add Partition(s)
        reg.onGainedPartitionOwnership(1);
        assertEquals("Listener called ", listener.isAddPartitionCalled(1), true);
        reg.onGainedPartitionOwnership(2);
        assertEquals("Listener called ", listener.isAddPartitionCalled(2), true);
        assertEquals("Partition Regs size ", 2, reg.getPartitionRegs().size());
        reg.onGainedPartitionOwnership(3);
        assertEquals("Listener called ", listener.isAddPartitionCalled(3), true);
        assertEquals("Partition Regs size ", 3, reg.getPartitionRegs().size());
        reg.onGainedPartitionOwnership(4);
        assertEquals("Listener called ", listener.isAddPartitionCalled(4), true);
        // duplicate call
        listener.clearCallbacks();
        reg.onGainedPartitionOwnership(4);
        assertEquals("Listener called ", listener.isAddPartitionCalled(4), false);
        assertEquals("Partition Regs size ", 4, reg.getPartitionRegs().size());
        List<String> gotPartitionList = new ArrayList<String>();
        for (DbusPartitionInfo p : reg.getPartitions()) gotPartitionList.add(p.toString());
        Collections.sort(gotPartitionList);
        assertEquals("Partitions Check", gotPartitionList.toString(), "[1, 2, 3, 4]");
        // Drop Partitions
        reg.onLostPartitionOwnership(1);
        gotPartitionList.clear();
        for (DbusPartitionInfo p : reg.getPartitions()) gotPartitionList.add(p.toString());
        Collections.sort(gotPartitionList);
        assertEquals("Partitions Check", "[2, 3, 4]", gotPartitionList.toString());
        assertEquals("Listener called ", true, listener.isDropPartitionCalled(1));
        reg.onLostPartitionOwnership(2);
        assertEquals("Listener called ", true, listener.isDropPartitionCalled(2));
        // duplicate call
        listener.clearCallbacks();
        reg.onLostPartitionOwnership(2);
        assertEquals("Listener called ", false, listener.isDropPartitionCalled(2));
        assertEquals("Partitions Check", "[3, 4]", reg.getPartitions().toString());
        assertEquals("Partition Regs size ", 2, reg.getPartitionRegs().size());
        reg.onReset(3);
        assertEquals("Listener called ", true, listener.isDropPartitionCalled(3));
        // duplicate call
        listener.clearCallbacks();
        reg.onReset(3);
        assertEquals("Listener called ", false, listener.isDropPartitionCalled(3));
        assertEquals("Partitions Check", "[4]", reg.getPartitions().toString());
        assertEquals("Partition Regs size ", 1, reg.getPartitionRegs().size());
        reg.onError(4);
        assertEquals("Listener called ", true, listener.isDropPartitionCalled(4));
        // duplicate call
        listener.clearCallbacks();
        reg.onError(4);
        assertEquals("Listener called ", false, listener.isDropPartitionCalled(4));
        assertEquals("Partitions Check", "[]", reg.getPartitions().toString());
        assertEquals("Partition Regs size ", 0, reg.getPartitionRegs().size());
        // Add Partiton 1 again
        listener.clearCallbacks();
        reg.onGainedPartitionOwnership(1);
        assertEquals("Listener called ", listener.isAddPartitionCalled(1), true);
        assertEquals("Partition Regs size ", 1, reg.getPartitionRegs().size());
        assertEquals("Child State CHeck", reg.getPartitionRegs().values().iterator().next().getState(), RegistrationState.STARTED);
        // Pausing
        reg.pause();
        assertEquals("State CHeck", reg.getState(), RegistrationState.PAUSED);
        assertEquals("Child State CHeck", reg.getPartitionRegs().values().iterator().next().getState(), RegistrationState.PAUSED);
        // Resume
        reg.resume();
        assertEquals("State CHeck", reg.getState(), RegistrationState.RESUMED);
        assertEquals("Child State CHeck", reg.getPartitionRegs().values().iterator().next().getState(), RegistrationState.RESUMED);
        // Suspended
        reg.suspendOnError(null);
        assertEquals("State CHeck", reg.getState(), RegistrationState.SUSPENDED_ON_ERROR);
        assertEquals("Child State CHeck", reg.getPartitionRegs().values().iterator().next().getState(), RegistrationState.SUSPENDED_ON_ERROR);
        // resume
        reg.resume();
        assertEquals("State CHeck", reg.getState(), RegistrationState.RESUMED);
        assertEquals("Child State CHeck", reg.getPartitionRegs().values().iterator().next().getState(), RegistrationState.RESUMED);
        // Active node change notification
        List<String> newActiveNodes = new ArrayList<String>();
        newActiveNodes.add("localhost:7070");
        newActiveNodes.add("localhost:8080");
        newActiveNodes.add("localhost:9090");
        reg.onInstanceChange(newActiveNodes);
        assertEquals("Active Nodes", newActiveNodes, reg.getCurrentActiveNodes());
        newActiveNodes.remove(2);
        reg.onInstanceChange(newActiveNodes);
        assertEquals("Active Nodes", newActiveNodes, reg.getCurrentActiveNodes());
        newActiveNodes.add("localhost:1010");
        reg.onInstanceChange(newActiveNodes);
        assertEquals("Active Nodes", newActiveNodes, reg.getCurrentActiveNodes());
        // Partition Mapping change notification
        Map<Integer, String> activePartitionMap = new HashMap<Integer, String>();
        for (int i = 0; i < 10; i++) {
            String node = null;
            if (i % 2 == 0)
                node = "localhost:8080";
            else
                node = "localhost:7070";
            activePartitionMap.put(i, node);
        }
        reg.onPartitionMappingChange(activePartitionMap);
        assertEquals("Partition Mapping Check", activePartitionMap, reg.getActivePartitionMap());
        activePartitionMap.remove(9);
        reg.onPartitionMappingChange(activePartitionMap);
        assertEquals("Partition Mapping Check", activePartitionMap, reg.getActivePartitionMap());
        activePartitionMap.put(9, "localhost:8708");
        reg.onPartitionMappingChange(activePartitionMap);
        assertEquals("Partition Mapping Check", activePartitionMap, reg.getActivePartitionMap());
        // shutdown
        reg.shutdown();
        assertEquals("State Check", reg.getState(), RegistrationState.SHUTDOWN);
        assertEquals("Child State CHeck", reg.getPartitionRegs().values().iterator().next().getState(), RegistrationState.SHUTDOWN);
        // Operations during shutdown state
        boolean gotException = false;
        try {
            reg.onGainedPartitionOwnership(1);
        } catch (IllegalStateException ex) {
            gotException = true;
        }
        assertEquals("Exception", true, gotException);
        gotException = false;
        try {
            reg.onLostPartitionOwnership(1);
        } catch (IllegalStateException ex) {
            gotException = true;
        }
        assertEquals("Exception", true, gotException);
        gotException = false;
        try {
            reg.pause();
        } catch (IllegalStateException ex) {
            gotException = true;
        }
        assertEquals("Exception", true, gotException);
        gotException = false;
        try {
            reg.suspendOnError(null);
        } catch (IllegalStateException ex) {
            gotException = true;
        }
        assertEquals("Exception", true, gotException);
        gotException = false;
        try {
            reg.resume();
        } catch (IllegalStateException ex) {
            gotException = true;
        }
        assertEquals("Exception", true, gotException);
        // deregister
        reg.deregister();
        assertEquals("State Check", reg.getState(), RegistrationState.DEREGISTERED);
        assertEquals("Child State CHeck", 0, reg.getPartitionRegs().size());
    } finally {
        if (null != client)
            client.shutdown();
    }
}
Also used : HashMap(java.util.HashMap) DbusKeyCompositeFilterConfig(com.linkedin.databus2.core.filter.DbusKeyCompositeFilterConfig) StaticConfig(com.linkedin.databus.client.pub.ClusterCheckpointPersistenceProvider.StaticConfig) InetSocketAddress(java.net.InetSocketAddress) StaticConfig(com.linkedin.databus.client.pub.ClusterCheckpointPersistenceProvider.StaticConfig) ArrayList(java.util.ArrayList) DatabusHttpClientImpl(com.linkedin.databus.client.DatabusHttpClientImpl) DbusClusterInfo(com.linkedin.databus.client.pub.DbusClusterInfo) DbusPartitionInfo(com.linkedin.databus.client.pub.DbusPartitionInfo) Test(org.testng.annotations.Test)

Example 3 with DbusClusterInfo

use of com.linkedin.databus.client.pub.DbusClusterInfo in project databus by linkedin.

the class TestDatabusV2ClusterRegistrationImpl method testRegistrationStartFromInvalidState.

@Test
public void testRegistrationStartFromInvalidState() 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);
        TestDbusPartitionListener listener = new TestDbusPartitionListener();
        StaticConfig ckptConfig = new StaticConfig("localhost:1356", "dummy", 1, 1);
        DbusClusterInfo clusterInfo = new DbusClusterInfo("dummy", 10, 1);
        DatabusV2ClusterRegistrationImpl reg = new TestableDatabusV2ClusterRegistrationImpl(null, client, ckptConfig, clusterInfo, new TestDbusClusterConsumerFactory(), new TestDbusServerSideFilterFactory(), listener, "S1", "S3");
        try {
            // Invoking start from INIT state in illegal
            reg.start();
            Assert.fail();
        } catch (IllegalStateException e) {
        }
        try {
            // Invoking start from DEREGISTERED state in illegal
            reg.onRegister();
            reg.start();
            reg.shutdown();
            reg.deregister();
            reg.start();
            Assert.fail();
        } catch (IllegalStateException e) {
        }
    } finally {
        if (null != client) {
            client.shutdown();
        }
    }
}
Also used : DbusClusterInfo(com.linkedin.databus.client.pub.DbusClusterInfo) DbusKeyCompositeFilterConfig(com.linkedin.databus2.core.filter.DbusKeyCompositeFilterConfig) StaticConfig(com.linkedin.databus.client.pub.ClusterCheckpointPersistenceProvider.StaticConfig) InetSocketAddress(java.net.InetSocketAddress) StaticConfig(com.linkedin.databus.client.pub.ClusterCheckpointPersistenceProvider.StaticConfig) DatabusHttpClientImpl(com.linkedin.databus.client.DatabusHttpClientImpl) Test(org.testng.annotations.Test)

Example 4 with DbusClusterInfo

use of com.linkedin.databus.client.pub.DbusClusterInfo in project databus by linkedin.

the class DatabusHttpClientImpl method getAllClientClusters.

/**
 * Fetch all the client clusters which have been registered in this client instance keyed by their
 * registrationIds. This has been overridden by V3 client to provide both V2 and V3 clusters.
 *
 * Only a copy of the registration ids are returned. Hence modifying the registration ids should not
 * affect the global Registration Id map.
 * @return Client clusters registered in this client instance keyed by their registration ids.
 */
public Map<RegistrationId, DbusClusterInfo> getAllClientClusters() {
    Map<RegistrationId, DbusClusterInfo> clusters = new HashMap<RegistrationId, DbusClusterInfo>();
    Collection<DatabusMultiPartitionRegistration> regs = getAllClientClusterRegistrations();
    for (DatabusMultiPartitionRegistration reg : regs) {
        if (reg instanceof DatabusV2ClusterRegistrationImpl) {
            DatabusV2ClusterRegistrationImpl r = (DatabusV2ClusterRegistrationImpl) reg;
            clusters.put(new RegistrationId(r.getRegistrationId().getId()), r.getClusterInfo());
        }
    }
    return clusters;
}
Also used : DatabusV2ClusterRegistrationImpl(com.linkedin.databus.client.registration.DatabusV2ClusterRegistrationImpl) DbusClusterInfo(com.linkedin.databus.client.pub.DbusClusterInfo) HashMap(java.util.HashMap) DatabusMultiPartitionRegistration(com.linkedin.databus.client.registration.DatabusMultiPartitionRegistration) RegistrationId(com.linkedin.databus.client.pub.RegistrationId)

Example 5 with DbusClusterInfo

use of com.linkedin.databus.client.pub.DbusClusterInfo in project databus by linkedin.

the class MockRemoteExceptionHandler method createFakeFilter.

private static DbusKeyCompositeFilterConfig createFakeFilter() throws DatabusException {
    DbusModPartitionedFilterFactory filterFactory = new DbusModPartitionedFilterFactory("source1");
    DbusClusterInfo cluster = new DbusClusterInfo("cluster", 2, 2);
    DbusPartitionInfo partition = new DbusPartitionInfo() {

        @Override
        public long getPartitionId() {
            return 1;
        }

        @Override
        public boolean equalsPartition(DbusPartitionInfo other) {
            return true;
        }
    };
    return filterFactory.createServerSideFilter(cluster, partition);
}
Also used : DbusClusterInfo(com.linkedin.databus.client.pub.DbusClusterInfo) DbusModPartitionedFilterFactory(com.linkedin.databus.client.pub.DbusModPartitionedFilterFactory) DbusPartitionInfo(com.linkedin.databus.client.pub.DbusPartitionInfo)

Aggregations

DbusClusterInfo (com.linkedin.databus.client.pub.DbusClusterInfo)5 DatabusHttpClientImpl (com.linkedin.databus.client.DatabusHttpClientImpl)2 StaticConfig (com.linkedin.databus.client.pub.ClusterCheckpointPersistenceProvider.StaticConfig)2 DbusPartitionInfo (com.linkedin.databus.client.pub.DbusPartitionInfo)2 RegistrationId (com.linkedin.databus.client.pub.RegistrationId)2 DatabusV2ClusterRegistrationImpl (com.linkedin.databus.client.registration.DatabusV2ClusterRegistrationImpl)2 DbusKeyCompositeFilterConfig (com.linkedin.databus2.core.filter.DbusKeyCompositeFilterConfig)2 InetSocketAddress (java.net.InetSocketAddress)2 HashMap (java.util.HashMap)2 Test (org.testng.annotations.Test)2 ClusterCheckpointPersistenceProvider (com.linkedin.databus.client.pub.ClusterCheckpointPersistenceProvider)1 DatabusClientException (com.linkedin.databus.client.pub.DatabusClientException)1 DbusModPartitionedFilterFactory (com.linkedin.databus.client.pub.DbusModPartitionedFilterFactory)1 ClusterRegistrationStaticConfig (com.linkedin.databus.client.registration.ClusterRegistrationStaticConfig)1 DatabusMultiPartitionRegistration (com.linkedin.databus.client.registration.DatabusMultiPartitionRegistration)1 ArrayList (java.util.ArrayList)1