use of com.linkedin.databus2.core.container.request.RequestProcessingException in project databus by linkedin.
the class SourcesRequestProcessor method process.
@Override
public DatabusRequest process(DatabusRequest request) throws IOException, RequestProcessingException {
int protoVersion = request.getOptionalIntParam(VERSION_PARAM_NAME, 1);
ObjectMapper mapper = new ObjectMapper();
StringWriter out = new StringWriter(10240);
Collection<LogicalSource> sources = _relay.getSourcesIdNameRegistry().getAllSources();
if (1 == protoVersion) {
ArrayList<IdNamePair> sourcePairs = new ArrayList<IdNamePair>(sources.size());
for (LogicalSource source : sources) sourcePairs.add(new IdNamePair(source.getId().longValue(), source.getName()));
mapper.writeValue(out, sourcePairs);
} else if (2 == protoVersion)
mapper.writeValue(out, sources);
else
throw new InvalidRequestParamValueException(COMMAND_NAME, VERSION_PARAM_NAME, Integer.toString(protoVersion));
byte[] resultBytes = out.toString().getBytes(Charset.defaultCharset());
request.getResponseContent().write(ByteBuffer.wrap(resultBytes));
HttpStatisticsCollector relayStatsCollector = _relay.getHttpStatisticsCollector();
if (null != relayStatsCollector) {
HttpStatisticsCollector connStatsCollector = (HttpStatisticsCollector) request.getParams().get(relayStatsCollector.getName());
if (null != connStatsCollector) {
connStatsCollector.registerSourcesCall();
} else {
relayStatsCollector.registerSourcesCall();
}
}
return request;
}
use of com.linkedin.databus2.core.container.request.RequestProcessingException in project databus by linkedin.
the class BufferInfoRequestProcessor method process.
@Override
public DatabusRequest process(DatabusRequest request) throws IOException, RequestProcessingException, DatabusException {
String category = request.getParams().getProperty(DatabusRequest.PATH_PARAM_NAME);
if (null == category) {
throw new InvalidRequestParamValueException(COMMAND_NAME, "category", "null");
}
if (category.startsWith(INBOUND_VIEW)) {
String sourceIdStr = category.substring(INBOUND_VIEW.length());
sourceIdStr = sourceIdStr.replace('/', ':');
PhysicalPartition pPartition = PhysicalPartition.parsePhysicalPartitionString(sourceIdStr, ":");
processInboundRequest(request, pPartition);
} else {
throw new InvalidRequestParamValueException(COMMAND_NAME, "category", category);
}
return request;
}
use of com.linkedin.databus2.core.container.request.RequestProcessingException in project databus by linkedin.
the class ControlSourceEventsRequestProcessor method process.
/*
* @see com.linkedin.databus.container.request.RequestProcessor#process(com.linkedin.databus.container.request.DatabusRequest)
*/
@Override
public DatabusRequest process(DatabusRequest request) throws IOException, RequestProcessingException {
// Read the action from the request
Actions action;
try {
String strAction = request.getParams().getProperty(DatabusRequest.PATH_PARAM_NAME, "");
action = Actions.valueOf(strAction.toUpperCase());
} catch (Exception ex) {
throw new InvalidRequestParamValueException(COMMAND_NAME, "request path", request.getParams().getProperty(DatabusRequest.PATH_PARAM_NAME, ""));
}
switch(action) {
case STATUS:
doStatus(request);
break;
case PAUSE:
doPause(request);
break;
case SHUTDOWN:
doShutdown(request);
break;
case START:
doStart(request);
break;
case UNPAUSE:
doUnpause(request);
break;
}
return null;
}
use of com.linkedin.databus2.core.container.request.RequestProcessingException in project databus by linkedin.
the class ControlSourceEventsRequestProcessor method doStart.
private void doStart(DatabusRequest request) throws IOException, RequestProcessingException {
Set<String> sources = getSourcesParam(request);
if (sources == null || sources.size() != 1) {
throw new RequestProcessingException("start requires exactly one source be specified");
}
long scn = request.getOptionalLongParam(PARAM_SCN, -1L);
for (EventProducer producer : _eventProducers) {
if (sources.contains(producer.getName())) {
producer.start(scn);
write(request, String.format("{\"name\" : \"%s\", \"status\" : \"%s\", \"SCN\" : %d}", producer.getName(), "running", producer.getSCN()));
}
}
}
use of com.linkedin.databus2.core.container.request.RequestProcessingException in project databus by linkedin.
the class PhysicalSourcesRequestProcessor method process.
@Override
public DatabusRequest process(DatabusRequest request) throws IOException, RequestProcessingException {
ObjectMapper mapper = new ObjectMapper();
StringWriter out = new StringWriter(10240);
List<PhysicalSourceStaticConfig> sources = _relay.getPhysicalSources();
if (sources.isEmpty())
mapper.writeValue(out, new ArrayList<PhysicalSourceStaticConfig>());
else
mapper.writeValue(out, sources);
byte[] resultBytes = out.toString().getBytes(Charset.defaultCharset());
request.getResponseContent().write(ByteBuffer.wrap(resultBytes));
HttpStatisticsCollector relayStatsCollector = _relay.getHttpStatisticsCollector();
if (null != relayStatsCollector) {
HttpStatisticsCollector connStatsCollector = (HttpStatisticsCollector) request.getParams().get(relayStatsCollector.getName());
if (null != connStatsCollector) {
connStatsCollector.registerSourcesCall();
} else {
relayStatsCollector.registerSourcesCall();
}
}
return request;
}
Aggregations