use of com.linkedin.databus.client.pub.DatabusV3Registration in project databus by linkedin.
the class ClientStateRequestProcessor method processRegistrationInfo.
/**
* Provides an individual registrations details. The individual registration can be
* either that of V2/V3 and top-level or child. Top-level registrations are those that
* were created as a result of one of "registerXXX()" calls on databus-client. In the
* case of multi-partition registrations (like MPRegistration, V2/V3 CLB), only the
* parent registration is considered the top-level registration. Per-partition (child)
* registrations which were created as part of partition migration are NOT top-level
* registrations. The output format can be different depending on whether it is a V2/V3
* as we are dumping the entire Registration in the case of V2. In the case of V3, we
* create an intermediate objects. These are legacy formats which when changed could
* cause the integ-tests to fail.
*
* @param request
* DatabusRequest corresponding to the REST call.
* @throws IOException
* if unable to write to output channel.
* @throws RequestProcessingException
* when registration could not be located.
*/
private void processRegistrationInfo(DatabusRequest request) throws IOException, RequestProcessingException {
boolean found = true;
// V2 Registration lookup first
RegistrationStatsInfo regStatsInfo = null;
try {
DatabusRegistration r = findV2Registration(request, REGISTRATION_KEY_PREFIX);
writeJsonObjectToResponse(r, request);
} catch (RequestProcessingException ex) {
found = false;
}
// V3 Registration lookup if not found
if (!found) {
// if
DatabusV3Registration reg = findV3Registration(request, REGISTRATION_KEY_PREFIX);
// reg
// is
// null,
// the
// callee
// throws
// an
// exception.
DatabusSourcesConnection sourcesConn = _client.getDatabusSourcesConnection(reg.getRegistrationId().getId());
regStatsInfo = new RegistrationStatsInfo(reg, sourcesConn);
writeJsonObjectToResponse(regStatsInfo, request);
}
}
use of com.linkedin.databus.client.pub.DatabusV3Registration in project databus by linkedin.
the class ClientStateRequestProcessor method pauseResumeRegistration.
/**
* Pause or resume a V2 or V3 registration. The registration can be a top-level or
* child-level registration Top-level registrations are those that were created as a
* result of one of "registerXXX()" calls on databus-client. In the case of
* multi-partition registrations (like MPRegistration, V2/V3 CLB), only the parent
* registration is considered the top-level registration. Per-partition (child)
* registrations which were created as part of partition migration are NOT top-level
* registrations.
*
* @param request
* Databus request corresponding to the REST call.
* @param doPause
* true if wanted to pause, false if to be resumed
* @throws IOException
* if unable to write output to channel
* @throws RequestProcessingException
* when registration could not be found.
*/
private void pauseResumeRegistration(DatabusRequest request, boolean doPause) throws IOException, RequestProcessingException {
DatabusRegistration r = null;
DatabusV3Registration r2 = null;
boolean found = true;
boolean isRunning = false;
boolean isPaused = false;
boolean isSuspended = false;
RegistrationId regId = null;
RequestProcessingException rEx = null;
RegStatePair regStatePair = null;
try {
r = findV2Registration(request, PAUSE_REGISTRATION);
isRunning = r.getState().isRunning();
isPaused = (r.getState() == DatabusRegistration.RegistrationState.PAUSED);
isSuspended = (r.getState() == DatabusRegistration.RegistrationState.SUSPENDED_ON_ERROR);
regId = r.getRegistrationId();
} catch (RequestProcessingException ex) {
found = false;
rEx = ex;
}
if (!found) {
try {
r2 = findV3Registration(request, PAUSE_REGISTRATION);
found = true;
isRunning = r2.getState().isRunning();
isPaused = (r2.getState() == RegistrationState.PAUSED);
isSuspended = (r2.getState() == RegistrationState.SUSPENDED_ON_ERROR);
regId = r.getRegistrationId();
} catch (RequestProcessingException ex) {
found = false;
rEx = ex;
}
}
if (!found)
throw rEx;
LOG.info("REST call to pause registration : " + regId);
if (isRunning) {
if (doPause) {
if (!isPaused) {
if (null != r) {
r.pause();
regStatePair = new RegStatePair(r.getState(), r.getRegistrationId());
} else {
r2.pause();
regStatePair = new RegStatePair(r2.getState().name(), r2.getRegistrationId());
}
}
} else {
if (isPaused || isSuspended) {
if (null != r) {
r.resume();
regStatePair = new RegStatePair(r.getState(), r.getRegistrationId());
} else {
r2.resume();
regStatePair = new RegStatePair(r2.getState().name(), r2.getRegistrationId());
}
}
}
}
writeJsonObjectToResponse(regStatePair, request);
}
use of com.linkedin.databus.client.pub.DatabusV3Registration in project databus by linkedin.
the class ClientStateRequestProcessor method resumeAllRegistrations.
/**
* Resume all registrations paused or suspended (both V2 and V3 in this client instance)
*
* @param request
* DatabusRequest corresponding to the REST call.
* @throws IOException
* when unable to write the output.
*/
private void resumeAllRegistrations(DatabusRequest request) throws IOException {
LOG.info("REST call to resume all registrations");
/**
* Get the top-level V2 registrations and pause them. The child-level registrations by
* the top-level registrations that aggregates them.
*/
Collection<DatabusRegistration> regs = _client.getAllRegistrations();
if (null != regs) {
for (DatabusRegistration r : regs) {
if (r.getState().isRunning()) {
if ((r.getState() == DatabusRegistration.RegistrationState.PAUSED) || (r.getState() == DatabusRegistration.RegistrationState.SUSPENDED_ON_ERROR))
r.resume();
}
}
}
/**
* Get the top-level V3 registrations and pause them. The child-level registrations by
* the top-level registrations that aggregates them.
*/
Map<RegistrationId, DatabusV3Registration> regMap = _client.getRegistrationIdMap();
Collection<RegInfo> topLevelRegs = getAllTopLevelV3Registrations();
/**
* Important Note: There is an important implementation difference on which
* registrations are stored in the global registration data-structure maintained by
* the client (DatabusHttp[V3]ClientImpls) between V2 and V3.
*
* 1. In the case of V2, only top-level registrations are stored in the global
* data-structure (DatabusHttpClientImpl.regList 2. In the case of V3, all
* registrations are stored in the global data-structure.
*
* In the case of V3, this is needed so that all registrations can act on the relay
* external view change. This can be refactored in the future by moving the
* relay-external view change to registration impl ( reduce the complexity in
* ClientImpl ). The V2 implementation did not have this logic and was following a
* more intuitive structure of preserving the hierarchy.
*/
if ((null != regMap) && (null != topLevelRegs)) {
for (RegInfo reg : topLevelRegs) {
DatabusV3Registration r = regMap.get(reg.getRegId());
if (r.getState().isRunning()) {
if ((r.getState() == RegistrationState.PAUSED) || (r.getState() == RegistrationState.SUSPENDED_ON_ERROR))
r.resume();
}
}
}
writeJsonObjectToResponse(getAllTopLevelRegStates(), request);
}
use of com.linkedin.databus.client.pub.DatabusV3Registration in project databus by linkedin.
the class ClientStateRequestProcessor method pauseAllRegistrations.
/**
* Pause all registrations (both V2 and V3 in this client instance) which are in running
* state.
*
* @param request
* DatabusRequest corresponding to the REST call.
* @throws IOException
* when unable to write the output.
*/
private void pauseAllRegistrations(DatabusRequest request) throws IOException {
LOG.info("REST call to pause all registrations");
/**
* Get the top-level V2 registrations and pause them. The child-level registrations by
* the top-level registrations that aggregates them.
*/
Collection<DatabusRegistration> regs = _client.getAllRegistrations();
if (null != regs) {
for (DatabusRegistration r : regs) {
if (r.getState().isRunning()) {
if (r.getState() != DatabusRegistration.RegistrationState.PAUSED)
r.pause();
}
}
}
/**
* Get the top-level V3 registrations and pause them. The child-level registrations by
* the top-level registrations that aggregates them.
*/
Map<RegistrationId, DatabusV3Registration> regMap = _client.getRegistrationIdMap();
Collection<RegInfo> topLevelRegs = getAllTopLevelV3Registrations();
/**
* Important Note: There is an important implementation difference on which
* registrations are stored in the global registration data-structure maintained by
* the client (DatabusHttp[V3]ClientImpls) between V2 and V3.
*
* 1. In the case of V2, only top-level registrations are stored in the global
* data-structure (DatabusHttpClientImpl.regList 2. In the case of V3, all
* registrations are stored in the global data-structure.
*
* In the case of V3, this is needed so that all registrations can act on the relay
* external view change. This can be refactored in the future by moving the
* relay-external view change to registration impl ( reduce the complexity in
* ClientImpl ). The V2 implementation did not have this logic and was following a
* more intuitive structure of preserving the hierarchy.
*/
if ((null != regMap) && (null != topLevelRegs)) {
for (RegInfo reg : topLevelRegs) {
DatabusV3Registration r = regMap.get(reg.getRegId());
if (r.getState().isRunning()) {
if (r.getState() != RegistrationState.PAUSED)
r.pause();
}
}
}
writeJsonObjectToResponse(getAllTopLevelRegStates(), request);
}
use of com.linkedin.databus.client.pub.DatabusV3Registration in project databus by linkedin.
the class ClientStatsRequestProcessor method findV3Registration.
private DatabusV3Registration findV3Registration(DatabusRequest request, String prefix) throws InvalidRequestParamValueException {
String category = request.getParams().getProperty(DatabusRequest.PATH_PARAM_NAME);
String registrationIdStr = category.substring(prefix.length());
DatabusV3Registration reg = _client.getRegistration(new RegistrationId(registrationIdStr));
if (null == reg) {
LOG.warn("Invalid registrationId: " + registrationIdStr);
throw new InvalidRequestParamValueException(request.getName(), prefix, "No data available for this RegistrationId yet");
}
return reg;
}
Aggregations