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);
}
}
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;
}
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();
}
}
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();
}
}
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();
}
}
Aggregations