use of com.linkedin.databus.client.pub.DatabusRegistration in project databus by linkedin.
the class DatabusHttpClientImpl method doStart.
@Override
protected void doStart() {
super.doStart();
LOG.info("relay consumers: " + getRelayGroupStreamConsumers().size());
LOG.info("bootstrap consumers: " + getRelayGroupBootstrapConsumers().size());
if (_clientNode != null && _clientNode.isEnabled()) {
if (!waitForLeadership()) {
LOG.error("Error acquiring leadership! Not starting client");
return;
}
}
_httpStatsCollector.registerMastershipStatus(1);
if (!getClientStaticConfig().usesDynamicRelayConfiguration()) {
initializeRelayConnections();
for (DatabusRegistration r : _regList) {
if (!r.getState().isRunning()) {
try {
LOG.info("Registration (" + r.getRegistrationId() + ") has not been started yet !! Starting !!");
r.start();
} catch (DatabusClientException e) {
LOG.error("Got exception while starting registration !!", e);
throw new RuntimeException(e);
}
}
}
} else {
// The connections are made during registerDatabusListener call and not when the client is started
LOG.info("Client with dynamically configured relays: relay connections will be initialized during register call");
}
if ((_dscUpdater != null) && _dscUpdater.isRunning()) {
_dscUpdater.stop();
}
}
use of com.linkedin.databus.client.pub.DatabusRegistration in project databus by linkedin.
the class ClientStatsRequestProcessor method findRegistration.
private DatabusRegistration findRegistration(DatabusRequest request, String prefix) throws RequestProcessingException {
String category = request.getParams().getProperty(DatabusRequest.PATH_PARAM_NAME);
String registrationIdStr = category.substring(prefix.length());
RegistrationId regId = new RegistrationId(registrationIdStr);
Collection<DatabusRegistration> regs = _client.getAllRegistrations();
for (DatabusRegistration r : regs) {
if (regId.equals(r.getRegistrationId()))
return r;
if (r instanceof DatabusMultiPartitionRegistration) {
Map<DbusPartitionInfo, DatabusRegistration> childRegs = ((DatabusMultiPartitionRegistration) r).getPartitionRegs();
for (Entry<DbusPartitionInfo, DatabusRegistration> e : childRegs.entrySet()) if (regId.equals(e.getValue().getRegistrationId()))
return e.getValue();
}
}
throw new RequestProcessingException("Unable to find registration (" + regId + ") ");
}
use of com.linkedin.databus.client.pub.DatabusRegistration in project databus by linkedin.
the class ClientStatsRequestProcessor method processInboundEventsRegistration.
private void processInboundEventsRegistration(DatabusRequest request) throws IOException, RequestProcessingException {
DatabusRegistration reg = findRegistration(request, INBOUND_EVENTS_REG_KEY_PREFIX);
writeJsonObjectToResponse(reg.getRelayEventStats().getTotalStats(), request);
}
use of com.linkedin.databus.client.pub.DatabusRegistration in project databus by linkedin.
the class ClientStatsRequestProcessor method processBootstrapEventsRegistration.
private void processBootstrapEventsRegistration(DatabusRequest request) throws IOException, RequestProcessingException {
DatabusRegistration reg = findRegistration(request, BOOTSTRAP_EVENTS_REG_KEY_PREFIX);
writeJsonObjectToResponse(reg.getBootstrapEventStats().getTotalStats(), request);
}
use of com.linkedin.databus.client.pub.DatabusRegistration 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();
}
}
Aggregations