Search in sources :

Example 6 with DatabusClientException

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

the class DatabusV2ClusterRegistrationImpl method activateOnePartition.

/**
   * Callback to activate one partition that was added
   * @param partition
   * @throws DatabusException
   */
private synchronized void activateOnePartition(DbusPartitionInfo partition) throws DatabusClientException {
    _log.info("Trying to activate partition :" + partition);
    try {
        if (regMap.containsKey(partition)) {
            _log.info("Partition (" + partition + ") is already added and is currently in state : " + regMap.get(partition).getState() + " skipping !!");
            return;
        }
        // Call factories to get consumer callbacks and server-side filter config.
        Collection<DatabusCombinedConsumer> consumers = _consumerFactory.createPartitionedConsumers(_clusterInfo, partition);
        DbusKeyCompositeFilterConfig filterConfig = null;
        if (_serverSideFilterFactory != null)
            filterConfig = _serverSideFilterFactory.createServerSideFilter(_clusterInfo, partition);
        if ((null == consumers) || (consumers.isEmpty())) {
            _log.error("ConsumerFactory for cluster (" + _clusterInfo + ") returned null or empty consumers ");
            throw new DatabusClientException("ConsumerFactory for cluster (" + _clusterInfo + ") returned null or empty consumers");
        }
        // Create Registration
        RegistrationId id = new RegistrationId(_id + "-" + partition.getPartitionId());
        CheckpointPersistenceProvider ckptProvider = createCheckpointPersistenceProvider(partition);
        DatabusV2RegistrationImpl reg = createChildRegistration(id, _client, ckptProvider);
        reg.addDatabusConsumers(consumers);
        String[] srcs = new String[_sources.size()];
        srcs = _sources.toArray(srcs);
        reg.addSubscriptions(srcs);
        regMap.put(partition, reg);
        reg.onRegister();
        // Add Server-Side Filter
        if (null != filterConfig)
            reg.withServerSideFilter(filterConfig);
        // Notify Listener
        if (null != _partitionListener)
            _partitionListener.onAddPartition(partition, reg);
        // Start the registration
        try {
            reg.start();
        } catch (DatabusClientException e) {
            _log.error("Got exception while starting the registration for partition (" + partition + ")", e);
            throw e;
        }
        //Add partition Specific metrics to cluster-merge
        _relayEventStatsMerger.addStatsCollector(id.getId(), (DbusEventsStatisticsCollector) reg.getRelayEventStats());
        _bootstrapEventStatsMerger.addStatsCollector(id.getId(), (DbusEventsStatisticsCollector) reg.getBootstrapEventStats());
        _relayCallbackStatsMerger.addStatsCollector(id.getId(), (ConsumerCallbackStats) reg.getRelayCallbackStats());
        _bootstrapCallbackStatsMerger.addStatsCollector(id.getId(), (ConsumerCallbackStats) reg.getBootstrapCallbackStats());
        _log.info("Partition (" + partition + ") started !!");
    } catch (DatabusException e) {
        _log.error("Got exception while activating partition(" + partition + ")", e);
        throw new DatabusClientException(e);
    } catch (ClusterCheckpointException e) {
        _log.error("Got exception while activating partition(" + partition + ")", e);
        throw new DatabusClientException(e);
    }
}
Also used : DbusKeyCompositeFilterConfig(com.linkedin.databus2.core.filter.DbusKeyCompositeFilterConfig) CheckpointPersistenceProvider(com.linkedin.databus.client.pub.CheckpointPersistenceProvider) ClusterCheckpointPersistenceProvider(com.linkedin.databus.client.pub.ClusterCheckpointPersistenceProvider) DatabusException(com.linkedin.databus2.core.DatabusException) RegistrationId(com.linkedin.databus.client.pub.RegistrationId) DatabusCombinedConsumer(com.linkedin.databus.client.pub.DatabusCombinedConsumer) DatabusClientException(com.linkedin.databus.client.pub.DatabusClientException) ClusterCheckpointException(com.linkedin.databus.client.pub.ClusterCheckpointPersistenceProvider.ClusterCheckpointException)

Example 7 with DatabusClientException

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

the class DatabusV2ClusterRegistrationImpl method start.

@Override
public synchronized boolean start() throws IllegalStateException, DatabusClientException {
    if (_state == RegistrationState.INIT || _state == RegistrationState.DEREGISTERED) {
        String errMsg = "Registration (" + _id + ") cannot be started from its current state, which is " + _state + " .It may only be started from REGISTERED or SHUTDOWN state";
        _log.error(errMsg);
        throw new IllegalStateException(errMsg);
    }
    if (_state.isRunning()) {
        _log.info("Registration (" + _id + ") already started !!");
        return false;
    }
    String host = null;
    try {
        host = InetAddress.getLocalHost().getHostName();
    } catch (UnknownHostException e) {
        _log.error("Unable to fetch the local hostname !! Trying to fetch IP Address !!", e);
        try {
            host = InetAddress.getLocalHost().getHostAddress();
        } catch (UnknownHostException e1) {
            _log.error("Unable to fetch the local IP Address too !! Giving up", e1);
            host = "UNKNOWN_HOST";
        }
    }
    /**
     *  The id below has to be unique within a given cluster. HttpPort is used to get a unique name for service colocated in a single box.
     *  The Container id is not necessarily a sufficient differentiating factor.
     */
    String id = host + "-" + _client.getContainerStaticConfig().getHttpPort() + "-" + _client.getContainerStaticConfig().getId();
    try {
        _cluster = createCluster();
        _cluster.start();
    } catch (Exception e) {
        _log.fatal("Got exception while trying to create the cluster with id (" + id + ")", e);
        throw new DatabusClientException(e);
    }
    initializeStatsCollectors();
    _log.info("Dabatus cluster object created : " + _cluster + " with id :" + id);
    _clusterMember = _cluster.addMember(id, this);
    boolean joined = _clusterMember.join();
    if (!joined) {
        _log.fatal("Unable to join the cluster " + _clusterInfo);
        throw new DatabusClientException("Unable to join the cluster :" + _clusterInfo);
    }
    _state = RegistrationState.STARTED;
    activatePartitions();
    return true;
}
Also used : UnknownHostException(java.net.UnknownHostException) DatabusException(com.linkedin.databus2.core.DatabusException) InvalidConfigException(com.linkedin.databus.core.util.InvalidConfigException) ClusterCheckpointException(com.linkedin.databus.client.pub.ClusterCheckpointPersistenceProvider.ClusterCheckpointException) UnknownHostException(java.net.UnknownHostException) DatabusClientException(com.linkedin.databus.client.pub.DatabusClientException) DatabusClientException(com.linkedin.databus.client.pub.DatabusClientException)

Example 8 with DatabusClientException

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

the class TestDatabusV2RegistrationImpl method testOneConsumerRegistrationOps.

@Test
public void testOneConsumerRegistrationOps() 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, "S1", "S3");
        assertEquals("Registered State", RegistrationState.REGISTERED, reg.getState());
        assertEquals("Component Name", "Status_TestConsumer_a62d57a7", reg.getStatus().getComponentName());
        assertEquals("Component Status", Status.INITIALIZING, reg.getStatus().getStatus());
        // Start
        boolean started = reg.start();
        assertEquals("Started", true, started);
        assertEquals("Registered State", RegistrationState.STARTED, reg.getState());
        assertEquals("Component Status", Status.RUNNING, reg.getStatus().getStatus());
        //Start again
        started = reg.start();
        assertEquals("Started", false, started);
        assertEquals("Registered State", RegistrationState.STARTED, reg.getState());
        // Pause
        reg.pause();
        assertEquals("Registered State", RegistrationState.PAUSED, reg.getState());
        assertEquals("Component Status", Status.PAUSED, reg.getStatus().getStatus());
        // resume
        reg.resume();
        assertEquals("Registered State", RegistrationState.RESUMED, reg.getState());
        assertEquals("Component Status", Status.RUNNING, reg.getStatus().getStatus());
        // suspend due to error
        reg.suspendOnError(new Exception("dummy"));
        assertEquals("Registered State", RegistrationState.SUSPENDED_ON_ERROR, reg.getState());
        assertEquals("Component Status", Status.SUSPENDED_ON_ERROR, reg.getStatus().getStatus());
        // SHutdown
        reg.shutdown();
        assertEquals("Registered State", RegistrationState.SHUTDOWN, reg.getState());
        assertEquals("Component Status", Status.SHUTDOWN, reg.getStatus().getStatus());
        // Duplicate regId
        DatabusRegistration reg2 = client.register(listener1, "S1", "S3");
        boolean isException = false;
        try {
            reg2.withRegId(reg.getRegistrationId());
        } catch (DatabusClientException ex) {
            isException = true;
        }
        assertEquals("Exception expected", true, isException);
        reg2.deregister();
        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) InvalidConfigException(com.linkedin.databus.core.util.InvalidConfigException) DatabusClientException(com.linkedin.databus.client.pub.DatabusClientException) DatabusClientException(com.linkedin.databus.client.pub.DatabusClientException) Test(org.testng.annotations.Test)

Example 9 with DatabusClientException

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

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

the class DatabusV2ClusterRegistrationImpl method onGainedPartitionOwnership.

@Override
public synchronized void onGainedPartitionOwnership(int partition) {
    _log.info("Partition (" + partition + ") getting added !!");
    DbusPartitionInfo partitionInfo = new DbusPartitionInfoImpl(partition);
    try {
        addPartition(partitionInfo);
    } catch (DatabusClientException e) {
        _log.error("Unable to add partition. Shutting down the cluster !!", e);
        deregister();
    }
}
Also used : DbusPartitionInfoImpl(com.linkedin.databus.client.DbusPartitionInfoImpl) DbusPartitionInfo(com.linkedin.databus.client.pub.DbusPartitionInfo) DatabusClientException(com.linkedin.databus.client.pub.DatabusClientException)

Aggregations

DatabusClientException (com.linkedin.databus.client.pub.DatabusClientException)14 RegistrationId (com.linkedin.databus.client.pub.RegistrationId)4 DatabusCombinedConsumer (com.linkedin.databus.client.pub.DatabusCombinedConsumer)3 DatabusRegistration (com.linkedin.databus.client.pub.DatabusRegistration)3 ServerInfo (com.linkedin.databus.client.pub.ServerInfo)3 DatabusException (com.linkedin.databus2.core.DatabusException)3 DatabusHttpClientImpl (com.linkedin.databus.client.DatabusHttpClientImpl)2 AbstractDatabusCombinedConsumer (com.linkedin.databus.client.consumer.AbstractDatabusCombinedConsumer)2 DatabusV2ConsumerRegistration (com.linkedin.databus.client.consumer.DatabusV2ConsumerRegistration)2 ClusterCheckpointPersistenceProvider (com.linkedin.databus.client.pub.ClusterCheckpointPersistenceProvider)2 ClusterCheckpointException (com.linkedin.databus.client.pub.ClusterCheckpointPersistenceProvider.ClusterCheckpointException)2 DatabusV2RegistrationImpl (com.linkedin.databus.client.registration.DatabusV2RegistrationImpl)2 DatabusComponentStatus (com.linkedin.databus.core.DatabusComponentStatus)2 DatabusSubscription (com.linkedin.databus.core.data_model.DatabusSubscription)2 InvalidConfigException (com.linkedin.databus.core.util.InvalidConfigException)2 InetSocketAddress (java.net.InetSocketAddress)2 ArrayList (java.util.ArrayList)2 Test (org.testng.annotations.Test)2 DatabusSourcesConnection (com.linkedin.databus.client.DatabusSourcesConnection)1 StaticConfig (com.linkedin.databus.client.DatabusSourcesConnection.StaticConfig)1