use of com.linkedin.databus2.core.container.request.DatabusRequest in project databus by linkedin.
the class ClientStatsRequestProcessor method processEventsSourceStats.
private void processEventsSourceStats(DbusEventsStatisticsCollector statsCollector, String prefix, DatabusRequest request) throws IOException, RequestProcessingException {
if (null == statsCollector)
return;
String category = request.getParams().getProperty(DatabusRequest.PATH_PARAM_NAME);
String sourceIdStr = category.substring(prefix.length());
int sourceId = -1;
try {
sourceId = Integer.valueOf(sourceIdStr);
} catch (NumberFormatException nfe) {
throw new InvalidRequestParamValueException(request.getName(), prefix, sourceIdStr);
}
DbusEventsTotalStats sourceStats = statsCollector.getSourceStats(sourceId);
if (null == sourceStats) {
throw new InvalidRequestParamValueException(request.getName(), prefix, sourceIdStr);
}
writeJsonObjectToResponse(sourceStats, request);
if (request.getRequestType() == HttpMethod.PUT || request.getRequestType() == HttpMethod.POST) {
enableOrResetStatsMBean(sourceStats, request);
}
}
use of com.linkedin.databus2.core.container.request.DatabusRequest in project databus by linkedin.
the class ClientStatsRequestProcessor method processOutboundHttpSourceStats.
private void processOutboundHttpSourceStats(DatabusRequest request) throws IOException, RequestProcessingException {
String category = request.getParams().getProperty(DatabusRequest.PATH_PARAM_NAME);
String sourceIdStr = category.substring(INBOUND_HTTP_SOURCE_PREFIX.length());
int sourceId = -1;
try {
sourceId = Integer.valueOf(sourceIdStr);
} catch (NumberFormatException nfe) {
throw new InvalidRequestParamValueException(request.getName(), INBOUND_HTTP_SOURCE_PREFIX, sourceIdStr);
}
DbusHttpTotalStats sourceStats = _client.getHttpStatsCollector().getSourceStats(sourceId);
if (null == sourceStats) {
throw new InvalidRequestParamValueException(request.getName(), INBOUND_HTTP_SOURCE_PREFIX, sourceIdStr);
}
writeJsonObjectToResponse(sourceStats, request);
if (request.getRequestType() == HttpMethod.PUT || request.getRequestType() == HttpMethod.POST) {
enableOrResetStatsMBean(sourceStats, request);
}
}
use of com.linkedin.databus2.core.container.request.DatabusRequest in project databus by linkedin.
the class TargetSCNRequestProcessor method doProcess.
@Override
protected DatabusRequest doProcess(DatabusRequest request) throws IOException, RequestProcessingException {
BootstrapHttpStatsCollector bootstrapStatsCollector = _bootstrapServer.getBootstrapStatsCollector();
long startTime = System.currentTimeMillis();
int srcId = -1;
long targetScn = -1;
String source = request.getRequiredStringParam(SOURCE_PARAM);
BootstrapSCNProcessor processor = null;
try {
processor = new BootstrapSCNProcessor(_config, _bootstrapServer.getInboundEventStatisticsCollector());
try {
// get src id from db
BootstrapDBMetaDataDAO.SourceStatusInfo srcIdStatus = processor.getSrcIdStatusFromDB(source, true);
if (!srcIdStatus.isValidSource())
throw new BootstrapProcessingException("Bootstrap DB not servicing source :" + source);
srcId = srcIdStatus.getSrcId();
// select target scn
targetScn = processor.getSourceTargetScn(srcId);
} catch (BootstrapDatabaseTooOldException tooOldException) {
if (bootstrapStatsCollector != null) {
bootstrapStatsCollector.registerErrTargetSCN();
bootstrapStatsCollector.registerErrDatabaseTooOld();
}
LOG.error("The bootstrap database is too old!", tooOldException);
throw new RequestProcessingException(tooOldException);
} catch (SQLException e) {
if (bootstrapStatsCollector != null) {
bootstrapStatsCollector.registerErrTargetSCN();
bootstrapStatsCollector.registerErrSqlException();
}
LOG.error("Error encountered while fetching targetSCN from database.", e);
throw new RequestProcessingException(e);
}
ObjectMapper mapper = new ObjectMapper();
StringWriter out = new StringWriter(1024);
mapper.writeValue(out, String.valueOf(targetScn));
byte[] resultBytes = out.toString().getBytes(Charset.defaultCharset());
request.getResponseContent().write(ByteBuffer.wrap(resultBytes));
LOG.info("targetSCN: " + targetScn);
} catch (Exception ex) {
LOG.error("Got exception while calculating targetSCN", ex);
throw new RequestProcessingException(ex);
} finally {
if (null != processor)
processor.shutdown();
}
if (bootstrapStatsCollector != null) {
bootstrapStatsCollector.registerTargetSCNReq(System.currentTimeMillis() - startTime);
}
return request;
}
use of com.linkedin.databus2.core.container.request.DatabusRequest in project databus by linkedin.
the class BootstrapRequestProcessor method doProcess.
/*
* (non-Javadoc)
*
* @see
* com.linkedin.databus.container.request.RequestProcessor#process(com.linkedin.databus
* .container.request.DatabusRequest)
*/
@Override
protected DatabusRequest doProcess(DatabusRequest request) throws IOException, RequestProcessingException {
BootstrapProcessor processor = null;
BootstrapHttpStatsCollector bootstrapStatsCollector = _bootstrapServer.getBootstrapStatsCollector();
long startTime = System.currentTimeMillis();
boolean isDebug = LOG.isDebugEnabled();
try {
try {
String threadName = Thread.currentThread().getName();
DbusEventsStatisticsCollector threadCollector = _bootstrapServer.getOutBoundStatsCollectors().getStatsCollector(threadName);
if (null == threadCollector) {
threadCollector = new DbusEventsStatisticsCollector(_bootstrapServer.getContainerStaticConfig().getId(), threadName, true, false, _bootstrapServer.getMbeanServer());
StatsCollectors<DbusEventsStatisticsCollector> ds = _bootstrapServer.getOutBoundStatsCollectors();
ds.addStatsCollector(threadName, threadCollector);
}
processor = new BootstrapProcessor(_config, threadCollector);
} catch (Exception e) {
if (null != bootstrapStatsCollector) {
bootstrapStatsCollector.registerErrBootstrap();
}
throw new RequestProcessingException(e);
}
DatabusComponentStatus componentStatus = _componentStatus.getStatusSnapshot();
if (!componentStatus.isRunningStatus()) {
if (null != bootstrapStatsCollector)
bootstrapStatsCollector.registerErrBootstrap();
throw new RequestProcessingException(componentStatus.getMessage());
}
String partitionInfoString = request.getParams().getProperty(PARTITION_INFO_PARAM);
DbusKeyFilter keyFilter = null;
if ((null != partitionInfoString) && (!partitionInfoString.isEmpty())) {
try {
keyFilter = KeyFilterConfigJSONFactory.parseDbusKeyFilter(partitionInfoString);
if (isDebug)
LOG.debug("ServerSideFilter is :" + keyFilter);
} catch (Exception ex) {
String msg = "Unable to parse partitionInfo from request. PartitionInfo was :" + partitionInfoString;
LOG.error(msg, ex);
throw new RequestProcessingException(msg, ex);
}
}
String outputFormat = request.getParams().getProperty(OUTPUT_PARAM);
Encoding enc = Encoding.BINARY;
if (null != outputFormat) {
try {
enc = Encoding.valueOf(outputFormat.toUpperCase());
} catch (Exception ex) {
LOG.error("Unable to find the output format for bootstrap request for " + outputFormat + ". Using Binary!!", ex);
}
}
processor.setKeyFilter(keyFilter);
String checkpointString = request.getRequiredStringParam(CHECKPOINT_PARAM);
int bufferMarginSpace = DEFAULT_BUFFER_MARGIN_SPACE;
if (null != _serverHostPort) {
bufferMarginSpace = Math.max(bufferMarginSpace, (_serverHostPort.length() + Checkpoint.BOOTSTRAP_SERVER_INFO.length() + DEFAULT_JSON_OVERHEAD_BYTES));
}
int clientFreeBufferSize = request.getRequiredIntParam(BATCHSIZE_PARAM) - checkpointString.length() - bufferMarginSpace;
BootstrapEventWriter writer = null;
if (_config.getPredicatePushDown())
writer = createEventWriter(request, clientFreeBufferSize, null, enc);
else
writer = createEventWriter(request, clientFreeBufferSize, keyFilter, enc);
Checkpoint cp = new Checkpoint(checkpointString);
DbusClientMode consumptionMode = cp.getConsumptionMode();
LOG.info("Bootstrap request received: " + "fetchSize=" + clientFreeBufferSize + ", consumptionMode=" + consumptionMode + ", checkpoint=" + checkpointString + ", predicatePushDown=" + _config.getPredicatePushDown());
try {
boolean phaseCompleted = false;
switch(consumptionMode) {
case BOOTSTRAP_SNAPSHOT:
phaseCompleted = processor.streamSnapShotRows(new Checkpoint(checkpointString), writer);
break;
case BOOTSTRAP_CATCHUP:
phaseCompleted = processor.streamCatchupRows(new Checkpoint(checkpointString), writer);
break;
default:
if (null != bootstrapStatsCollector)
bootstrapStatsCollector.registerErrBootstrap();
throw new RequestProcessingException("Unexpected mode: " + consumptionMode);
}
if (null != bootstrapStatsCollector)
bootstrapStatsCollector.registerBootStrapReq(cp, System.currentTimeMillis() - startTime, clientFreeBufferSize);
if (writer.getNumRowsWritten() == 0 && writer.getSizeOfPendingEvent() > 0) {
// Append a header to indicate to the client that we do have at least one event to
// send, but it is too large to fit into client's offered buffer.
request.getResponseContent().addMetadata(DatabusHttpHeaders.DATABUS_PENDING_EVENT_SIZE, writer.getSizeOfPendingEvent());
if (isDebug) {
LOG.debug("Returning 0 events but have pending event of size " + writer.getSizeOfPendingEvent());
}
}
if (phaseCompleted) {
request.getResponseContent().setMetadata(BootstrapProcessor.PHASE_COMPLETED_HEADER_NAME, BootstrapProcessor.PHASE_COMPLETED_HEADER_TRUE);
}
} catch (BootstrapDatabaseTooOldException e) {
if (null != bootstrapStatsCollector)
bootstrapStatsCollector.registerErrDatabaseTooOld();
LOG.error("Bootstrap database is too old!", e);
throw new RequestProcessingException(e);
} catch (BootstrapDBException e) {
if (null != bootstrapStatsCollector)
bootstrapStatsCollector.registerErrBootstrap();
throw new RequestProcessingException(e);
} catch (SQLException e) {
if (null != bootstrapStatsCollector)
bootstrapStatsCollector.registerErrSqlException();
throw new RequestProcessingException(e);
} catch (BootstrapProcessingException e) {
if (null != bootstrapStatsCollector)
bootstrapStatsCollector.registerErrBootstrap();
throw new RequestProcessingException(e);
}
} finally {
if (null != processor)
processor.shutdown();
}
return request;
}
use of com.linkedin.databus2.core.container.request.DatabusRequest in project databus by linkedin.
the class TestDatabusRequest method makeRequest.
private DatabusRequest makeRequest() throws Exception {
SocketAddress sockAddr = new InetSocketAddress(InetAddress.getByAddress(ipAddr), port);
Properties props = new Properties();
props.setProperty(prop1, propval1);
props.setProperty(prop2, propval2);
ServerContainer.ExecutorConfig defaultConfig = new ServerContainer.ExecutorConfig(3, 2, 100, false, 5);
ServerContainer.ExecutorConfig ioConfig = new ServerContainer.ExecutorConfig(5, 4, 50, true, 6);
ServerContainer.RuntimeConfig runtimeConfig = new ServerContainer.RuntimeConfig(200, defaultConfig, ioConfig);
return new DatabusRequest(reqName, method, sockAddr, props, runtimeConfig);
}
Aggregations