use of com.linkedin.databus2.core.container.request.DatabusRequest in project databus by linkedin.
the class ClientStateRequestProcessor method processPartition.
/**
* Provide a partition information belonging to a V2/V3 client cluster and hosted in
* this client instance
*
* @param request
* DatabusRequest corresponding to the REST call.
* @throws IOException
* when unable to write to output channel.
* @throws RequestProcessingException
* when cluster not found or when partition is not hosted in this instance
*/
private void processPartition(DatabusRequest request) throws IOException, RequestProcessingException {
String category = request.getParams().getProperty(DatabusRequest.PATH_PARAM_NAME);
String clusterPartitionName = category.substring(CLIENT_CLUSTER_PARTITION_REG_KEY.length());
/**
* API: curl
* http://<HOST>:<PORT>/clientState/clientPartition/<CLUSTER_NAME>/<PARTITION> curl
* http://<HOST>:<PORT>/clientState/clientPartition/<CLUSTER_NAME>:<PARTITION>
*/
String[] toks = clusterPartitionName.split("[:/]");
if (toks.length != 2)
throw new RequestProcessingException("Cluster and partition info are expected to be in pattern = <cluster>[/:]<partition> but was " + clusterPartitionName);
RegInfo reg = null;
boolean found = true;
// Try as a V2 Partition
try {
reg = getV2PartitionRegistration(toks[0], new Long(toks[1]));
} catch (RequestProcessingException ex) {
found = false;
}
// If not found, try as V3
if (!found) {
reg = getV3PartitionRegistration(toks[0], new Long(toks[1]));
}
writeJsonObjectToResponse(reg, request);
}
use of com.linkedin.databus2.core.container.request.DatabusRequest in project databus by linkedin.
the class ClientStatsRequestProcessor method processEventsPeerStats.
private void processEventsPeerStats(DbusEventsStatisticsCollector statsCollector, String prefix, DatabusRequest request) throws IOException, RequestProcessingException {
if (null == statsCollector)
return;
String category = request.getParams().getProperty(DatabusRequest.PATH_PARAM_NAME);
String client = category.substring(prefix.length());
DbusEventsTotalStats clientStats = statsCollector.getPeerStats(client);
if (null == clientStats) {
throw new InvalidRequestParamValueException(request.getName(), 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.DatabusRequest 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;
}
use of com.linkedin.databus2.core.container.request.DatabusRequest 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.databus2.core.container.request.DatabusRequest in project databus by linkedin.
the class GenerateDataEventsRequestProcessor method process.
@Override
public DatabusRequest process(DatabusRequest request) throws IOException, RequestProcessingException {
String action = request.getParams().getProperty(DatabusRequest.PATH_PARAM_NAME, "");
if (action.equals("check")) {
boolean genRunning = _producer.checkRunning();
StringBuilder resBuilder = new StringBuilder(1024);
Formatter fmt = new Formatter(resBuilder);
fmt.format("{\"genDataEventsRunning\":\"%b\"}", genRunning);
request.getResponseContent().write(ByteBuffer.wrap(resBuilder.toString().getBytes(Charset.defaultCharset())));
} else if (action.equals("stop")) {
_producer.stopGeneration();
request.getResponseContent().write(ByteBuffer.wrap("{\"genDataEventsRunning\":\"send-stop\"}".getBytes(Charset.defaultCharset())));
} else if (action.equals("suspend")) {
_producer.suspendGeneration();
request.getResponseContent().write(ByteBuffer.wrap("{\"genDataEventsRunning\":\"send-suspend\"}".getBytes(Charset.defaultCharset())));
} else if (action.equals("resume")) {
long numEventToGenerate = request.getOptionalLongParam(NUM_EVENTS_TO_GENERATE, Long.MAX_VALUE);
long keyMin = request.getOptionalLongParam(KEY_MIN_PARAM, 0L);
long keyMax = request.getOptionalLongParam(KEY_MAX_PARAM, Long.MAX_VALUE);
int percentOfBufferToGenerate = request.getOptionalIntParam(PERCENT_BUFFER_TO_GENERATE, Integer.MAX_VALUE);
_producer.resumeGeneration(numEventToGenerate, percentOfBufferToGenerate, keyMin, keyMax);
request.getResponseContent().write(ByteBuffer.wrap("{\"genDataEventsRunning\":\"send-resume\"}".getBytes(Charset.defaultCharset())));
} else if (action.equals("start")) {
long fromScn = request.getRequiredLongParam(SCN_PARAM);
long durationMs = request.getRequiredLongParam(DURATION_MS);
int eventsPerSec = request.getRequiredIntParam(EVENTS_PER_SEC_PARAM);
long numEventToGenerate = request.getOptionalLongParam(NUM_EVENTS_TO_GENERATE, Long.MAX_VALUE);
int percentOfBufferToGenerate = request.getOptionalIntParam(PERCENT_BUFFER_TO_GENERATE, Integer.MAX_VALUE);
long keyMin = request.getOptionalLongParam(KEY_MIN_PARAM, 0L);
long keyMax = request.getOptionalLongParam(KEY_MAX_PARAM, Long.MAX_VALUE);
String sourcesListStr = request.getRequiredStringParam(SOURCES_NAME_PARAM);
String[] sourcesStrArray = sourcesListStr.split(",");
List<IdNamePair> sourcesIdList = new ArrayList<IdNamePair>(sourcesStrArray.length);
for (String sourceIdStr : sourcesStrArray) {
try {
Integer id = Integer.valueOf(sourceIdStr);
LogicalSource source = _relay.getSourcesIdNameRegistry().getSource(id);
if (null != source)
sourcesIdList.add(source.asIdNamePair());
else
LOG.error("unable to find source id: " + id);
} catch (NumberFormatException nfe) {
throw new InvalidRequestParamValueException(COMMAND_NAME, SOURCES_NAME_PARAM, sourceIdStr);
}
}
//We have to use the global stats collector because the generation can go beyond the lifespan
//of the connection
boolean tryStart = _producer.startGeneration(fromScn, eventsPerSec, durationMs, numEventToGenerate, percentOfBufferToGenerate, keyMin, keyMax, sourcesIdList, _relayStatsCollector);
StringBuilder resBuilder = new StringBuilder(1024);
Formatter fmt = new Formatter(resBuilder);
fmt.format("{\"genDataEventsStarted\":\"%b\"}", tryStart);
request.getResponseContent().write(ByteBuffer.wrap(resBuilder.toString().getBytes(Charset.defaultCharset())));
} else {
throw new InvalidRequestParamValueException(COMMAND_NAME, "request path", action);
}
return request;
}
Aggregations