use of com.linkedin.databus2.core.container.request.RequestProcessingException in project databus by linkedin.
the class ClientStateRequestProcessor method processCluster.
/**
* Provide the list of partitions corresponding to the V2/V3 client cluster.
*
* @param request
* DatabusRequest corresponding to the REST call.
* @throws IOException
* when unable to write to output channel.
* @throws RequestProcessingException
* when cluster not found.
*/
private void processCluster(DatabusRequest request) throws IOException, RequestProcessingException {
String category = request.getParams().getProperty(DatabusRequest.PATH_PARAM_NAME);
String clusterName = category.substring(CLIENT_CLUSTER_KEY.length());
List<PartitionInfo> clusters = new ArrayList<PartitionInfo>();
RequestProcessingException rEx = null;
Collection<PartitionInfo> v2Clusters = null;
// Check as if this is V2 Cluster first
boolean found = true;
try {
v2Clusters = getV2ClusterPartitions(clusterName);
clusters.addAll(v2Clusters);
} catch (RequestProcessingException ex) {
found = false;
rEx = ex;
}
// Try as V3 cluster if it is not V2.
if (!found) {
Collection<PartitionInfo> v3Clusters = null;
try {
v3Clusters = getV3ClusterPartitions(clusterName);
clusters.addAll(v3Clusters);
found = true;
} catch (RequestProcessingException ex) {
found = false;
rEx = ex;
}
}
if (!found)
throw rEx;
writeJsonObjectToResponse(clusters, request);
}
use of com.linkedin.databus2.core.container.request.RequestProcessingException in project databus by linkedin.
the class ClientStateRequestProcessor method findV2Registration.
/**
* Helper method to locate a databus V2 registration by its registration id. This method
* can locate both top-level (registered by one of _dbusClient.registerXXX()) and
* individual-partition (child) registration that are aggregated inside a top-level
* MultiPartition registration.
*
* Please note that this can traverse the registration tree which is 1 level deep. In
* other words, it will not work when we have MultiPartition registrations aggregated
* inside another MultiPartition registrations.
*
* @param regId
* Registration Id to be located
* @param request
* Databus Request corresponding to the REST call.
* @return
* @throws RequestProcessingException
* when the registration is not found.
*/
private DatabusRegistration findV2Registration(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();
if (null != regs) {
for (DatabusRegistration r : regs) {
if (regId.equals(r.getRegistrationId())) {
return r;
}
/**
* 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. The below code handles
* the discrepancy for V2.
*/
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.databus2.core.container.request.RequestProcessingException in project databus by linkedin.
the class ClientStatsRequestProcessor method processOutboundHttpClientStats.
private void processOutboundHttpClientStats(DatabusRequest request) throws IOException, RequestProcessingException {
String category = request.getParams().getProperty(DatabusRequest.PATH_PARAM_NAME);
String client = category.substring(INBOUND_HTTP_RELAYS_PREFIX.length());
DbusHttpTotalStats clientStats = _client.getHttpStatsCollector().getPeerStats(client);
if (null == clientStats) {
throw new InvalidRequestParamValueException(request.getName(), INBOUND_HTTP_RELAYS_PREFIX, client);
}
writeJsonObjectToResponse(clientStats, request);
if (request.getRequestType() == HttpMethod.PUT || request.getRequestType() == HttpMethod.POST) {
enableOrResetStatsMBean(clientStats, request);
}
}
use of com.linkedin.databus2.core.container.request.RequestProcessingException in project databus by linkedin.
the class ContainerOperationProcessor method process.
@Override
public DatabusRequest process(DatabusRequest request) throws IOException, RequestProcessingException {
String action = request.getParams().getProperty(DatabusRequest.PATH_PARAM_NAME, "");
if (action.equals("shutdown")) {
String pid = Utils.getPid();
String response = "{\"Container\":\"set-shutdown\",\"pid\":\"" + pid + "\"}";
request.getResponseContent().write(ByteBuffer.wrap(response.getBytes(Charset.defaultCharset())));
Thread runThread = new Thread(new Runnable() {
@Override
public void run() {
_serverContainer.shutdown();
}
});
runThread.start();
} else if (action.equals("pause")) {
_serverContainer.pause();
request.getResponseContent().write(ByteBuffer.wrap("{\"Container\":\"set-pause\"}".getBytes(Charset.defaultCharset())));
} else if (action.equals("resume")) {
_serverContainer.resume();
request.getResponseContent().write(ByteBuffer.wrap("{\"Container\":\"set-resume\"}".getBytes(Charset.defaultCharset())));
} else if (action.equals("getpid")) {
String pid = Utils.getPid();
String response = "{\"pid\":\"" + pid + "\"}";
request.getResponseContent().write(ByteBuffer.wrap(response.getBytes(Charset.defaultCharset())));
} else {
throw new InvalidRequestParamValueException(COMMAND_NAME, "request path", action);
}
return request;
}
use of com.linkedin.databus2.core.container.request.RequestProcessingException in project databus by linkedin.
the class ContainerStatsRequestProcessor method processOutboundTrafficClientStats.
private void processOutboundTrafficClientStats(DatabusRequest request) throws IOException, RequestProcessingException {
String category = request.getParams().getProperty(DatabusRequest.PATH_PARAM_NAME);
String prefix = "outbound/client/";
String client = category.substring(prefix.length());
ContainerTrafficTotalStats clientStats = _containerStatsCollector.getOutboundClientStats(client);
if (null == clientStats) {
throw new InvalidRequestParamValueException(request.getName(), prefix, client);
}
JsonEncoder jsonEncoder = clientStats.createJsonEncoder(Channels.newOutputStream(request.getResponseContent()));
clientStats.toJson(jsonEncoder, null);
if (request.getRequestType() == HttpMethod.PUT || request.getRequestType() == HttpMethod.POST) {
enableOrResetStatsMBean(clientStats, request);
}
}
Aggregations