use of com.linkedin.databus2.core.container.request.InvalidRequestParamValueException 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);
}
}
use of com.linkedin.databus2.core.container.request.InvalidRequestParamValueException in project databus by linkedin.
the class ConsumerPauseRequestProcessor method process.
@Override
public DatabusRequest process(DatabusRequest request) throws IOException, RequestProcessingException {
String action = request.getParams().getProperty(DatabusRequest.PATH_PARAM_NAME, "");
if (action.equals("pause")) {
_pauseConsumer.pause();
request.getResponseContent().write(ByteBuffer.wrap("{\"pauseConsumer\":\"set-pause\"}".getBytes(Charset.defaultCharset())));
} else if (action.equals("resume")) {
_pauseConsumer.resume();
request.getResponseContent().write(ByteBuffer.wrap("{\"pauseConsumer\":\"set-resume\"}".getBytes(Charset.defaultCharset())));
} else {
throw new InvalidRequestParamValueException(COMMAND_NAME, "request path", action);
}
return request;
}
use of com.linkedin.databus2.core.container.request.InvalidRequestParamValueException 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.InvalidRequestParamValueException 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.InvalidRequestParamValueException 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