use of com.linkedin.databus2.core.container.request.DatabusRequest in project databus by linkedin.
the class BootstrapRequestProcessorBase method process.
@Override
public final DatabusRequest process(DatabusRequest request) throws IOException, RequestProcessingException {
initBootstrapServerInfo();
String ckptStr = request.getParams().getProperty(CHECKPOINT_PARAM);
Checkpoint ckpt = null;
if (null != ckptStr) {
ckpt = new Checkpoint(ckptStr);
String bsServerInfo = ckpt.getBootstrapServerInfo();
if ((null != bsServerInfo) && (null != _serverInfo)) {
ServerInfo expServerInfo = null;
try {
expServerInfo = ServerInfo.buildServerInfoFromHostPort(bsServerInfo.trim(), DbusConstants.HOSTPORT_DELIMITER);
} catch (Exception ex) {
LOG.error("Unable to fetch ServerInfo from ckpt. Passed ServerInfo was :" + bsServerInfo.trim());
}
if ((null != expServerInfo) && (!_serverInfo.equals(expServerInfo))) {
String msg = "Bootstrap Server Request should be served by different host : " + bsServerInfo + ", This instance is :" + _serverHostPort;
LOG.error(msg);
throw new RequestProcessingException(msg);
}
}
}
DatabusRequest req = doProcess(request);
if (null != _serverHostPort) {
req.getResponseContent().setMetadata(DbusConstants.SERVER_INFO_HOSTPORT_HEADER_PARAM, _serverHostPort);
}
return req;
}
use of com.linkedin.databus2.core.container.request.DatabusRequest in project databus by linkedin.
the class StartSCNRequestProcessor method doProcess.
@Override
protected DatabusRequest doProcess(DatabusRequest request) throws IOException, RequestProcessingException {
BootstrapHttpStatsCollector bootstrapStatsCollector = _bootstrapServer.getBootstrapStatsCollector();
long startTime = System.currentTimeMillis();
String sources = request.getRequiredStringParam(SOURCES_PARAM);
List<String> srcList = getSources(sources);
Checkpoint ckpt = new Checkpoint(request.getRequiredStringParam(CHECKPOINT_PARAM));
LOG.info("StartSCN requested for sources : (" + sources + "). CheckPoint is :" + ckpt);
long sinceScn = ckpt.getBootstrapSinceScn();
ObjectMapper mapper = new ObjectMapper();
StringWriter out = new StringWriter(1024);
long startSCN = -1;
BootstrapSCNProcessor processor = null;
try {
processor = new BootstrapSCNProcessor(_config, _bootstrapServer.getInboundEventStatisticsCollector());
List<SourceStatusInfo> srcStatusPairs = null;
try {
srcStatusPairs = processor.getSourceIdAndStatusFromName(srcList);
startSCN = processor.getMinApplierWindowScn(sinceScn, srcStatusPairs);
if (processor.shouldBypassSnapshot(sinceScn, startSCN, srcStatusPairs)) {
LOG.info("Bootstrap Snapshot phase will be bypassed for startScn request :" + request);
LOG.info("Original startSCN is:" + startSCN + ", Setting startSCN to the sinceSCN:" + sinceScn);
startSCN = sinceScn;
} else {
if (startSCN == BootstrapDBMetaDataDAO.DEFAULT_WINDOWSCN) {
throw new RequestProcessingException("Bootstrap DB is being initialized! startSCN=" + startSCN);
}
if (_config.isEnableMinScnCheck()) {
//snapshot isn't bypassed. Check if snapshot is possible from sinceScn by checking minScn
long minScn = processor.getBootstrapMetaDataDAO().getMinScnOfSnapshots(srcStatusPairs);
LOG.info("Min scn for tab tables is: " + minScn);
if (minScn == BootstrapDBMetaDataDAO.DEFAULT_WINDOWSCN) {
throw new BootstrapDatabaseTooYoungException("BootstrapDB has no minScn for these sources, but minScn check is enabled! minScn=" + minScn);
}
//sinceSCN should be greater than minScn, unless sinceScn=minScn=0
if ((sinceScn <= minScn) && !(sinceScn == 0 && minScn == 0)) {
LOG.error("Bootstrap Snapshot doesn't have requested data . sinceScn too old! sinceScn is " + sinceScn + " but minScn available is " + minScn);
throw new BootstrapDatabaseTooYoungException("Min scn=" + minScn + " Since scn=" + sinceScn);
}
} else {
LOG.debug("Bypassing minScn check! ");
}
}
} catch (BootstrapDatabaseTooOldException tooOldException) {
if (bootstrapStatsCollector != null) {
bootstrapStatsCollector.registerErrStartSCN();
bootstrapStatsCollector.registerErrDatabaseTooOld();
}
LOG.error("The bootstrap database is too old!", tooOldException);
throw new RequestProcessingException(tooOldException);
} catch (BootstrapDatabaseTooYoungException e) {
if (bootstrapStatsCollector != null) {
bootstrapStatsCollector.registerErrStartSCN();
bootstrapStatsCollector.registerErrBootstrap();
}
LOG.error("The bootstrap database is too young!", e);
throw new RequestProcessingException(e);
} catch (SQLException e) {
if (bootstrapStatsCollector != null) {
bootstrapStatsCollector.registerErrStartSCN();
bootstrapStatsCollector.registerErrSqlException();
}
LOG.error("Error encountered while fetching startSCN from database.", e);
throw new RequestProcessingException(e);
}
mapper.writeValue(out, String.valueOf(startSCN));
byte[] resultBytes = out.toString().getBytes(Charset.defaultCharset());
request.getResponseContent().write(ByteBuffer.wrap(resultBytes));
LOG.info("startSCN: " + startSCN + " with server Info :" + _serverHostPort);
} catch (RequestProcessingException ex) {
LOG.error("Got exception while calculating startSCN", ex);
throw ex;
} catch (Exception ex) {
LOG.error("Got exception while calculating startSCN", ex);
throw new RequestProcessingException(ex);
} finally {
if (null != processor)
processor.shutdown();
}
if (bootstrapStatsCollector != null) {
bootstrapStatsCollector.registerStartSCNReq(System.currentTimeMillis() - startTime);
}
return request;
}
use of com.linkedin.databus2.core.container.request.DatabusRequest in project databus by linkedin.
the class ClientRequestProcessor method process.
@Override
public DatabusRequest process(DatabusRequest request) throws IOException, RequestProcessingException, DatabusException {
String category = request.getParams().getProperty(DatabusRequest.PATH_PARAM_NAME);
if (category == null) {
throw new InvalidRequestParamValueException(COMMAND_NAME, "category", "null");
}
LOG.info("Processing command " + category);
if (category.equals(CLIENT_INFO_KEY)) {
Map<String, String> outMap = null;
outMap = _client.printClientInfo();
writeJsonObjectToResponse(outMap, request);
} else if (category.equals(RESET_RELAY_CONNECTIONS)) {
_client.resetRelayConnections();
} else {
throw new InvalidRequestParamValueException(COMMAND_NAME, "category", category);
}
return request;
}
use of com.linkedin.databus2.core.container.request.DatabusRequest in project databus by linkedin.
the class ClientStateRequestProcessor method processMPRegistrations.
/**
* Exposes the mapping between a mpRegistration -> Set of individual registrations
*
*/
private void processMPRegistrations(DatabusRequest request) throws IOException, RequestProcessingException {
Map<RegistrationId, DatabusV3Registration> registrationIdMap = _client.getRegistrationIdMap();
if (null == registrationIdMap)
throw new InvalidRequestParamValueException(request.getName(), REGISTRATIONS_KEY, "Present only for Databus V3 clients");
Map<String, List<String>> ridList = new TreeMap<String, List<String>>();
for (Map.Entry<RegistrationId, DatabusV3Registration> entry : registrationIdMap.entrySet()) {
DatabusV3Registration reg = entry.getValue();
if (reg instanceof DatabusV3MultiPartitionRegistration) {
Collection<DatabusV3Registration> dvrList = ((DatabusV3MultiPartitionRegistration) reg).getPartionRegs().values();
List<String> mpRegList = new ArrayList<String>();
for (DatabusV3Registration dvr : dvrList) {
mpRegList.add(dvr.getRegistrationId().getId());
}
ridList.put(entry.getKey().getId(), mpRegList);
}
}
writeJsonObjectToResponse(ridList, request);
return;
}
use of com.linkedin.databus2.core.container.request.DatabusRequest 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);
}
Aggregations