Search in sources :

Example 11 with RequestProcessingException

use of com.linkedin.databus2.core.container.request.RequestProcessingException 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;
}
Also used : DatabusRequest(com.linkedin.databus2.core.container.request.DatabusRequest) Checkpoint(com.linkedin.databus.core.Checkpoint) ServerInfo(com.linkedin.databus.client.pub.ServerInfo) RequestProcessingException(com.linkedin.databus2.core.container.request.RequestProcessingException) SQLException(java.sql.SQLException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) RequestProcessingException(com.linkedin.databus2.core.container.request.RequestProcessingException)

Example 12 with RequestProcessingException

use of com.linkedin.databus2.core.container.request.RequestProcessingException 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;
}
Also used : BootstrapHttpStatsCollector(com.linkedin.databus.bootstrap.common.BootstrapHttpStatsCollector) SQLException(java.sql.SQLException) IOException(java.io.IOException) BootstrapDatabaseTooOldException(com.linkedin.databus2.core.container.request.BootstrapDatabaseTooOldException) SQLException(java.sql.SQLException) BootstrapDatabaseTooYoungException(com.linkedin.databus2.core.container.request.BootstrapDatabaseTooYoungException) RequestProcessingException(com.linkedin.databus2.core.container.request.RequestProcessingException) BootstrapDatabaseTooOldException(com.linkedin.databus2.core.container.request.BootstrapDatabaseTooOldException) Checkpoint(com.linkedin.databus.core.Checkpoint) StringWriter(java.io.StringWriter) RequestProcessingException(com.linkedin.databus2.core.container.request.RequestProcessingException) BootstrapDatabaseTooYoungException(com.linkedin.databus2.core.container.request.BootstrapDatabaseTooYoungException) SourceStatusInfo(com.linkedin.databus.bootstrap.common.BootstrapDBMetaDataDAO.SourceStatusInfo) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Example 13 with RequestProcessingException

use of com.linkedin.databus2.core.container.request.RequestProcessingException 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;
}
Also used : InvalidRequestParamValueException(com.linkedin.databus2.core.container.request.InvalidRequestParamValueException)

Example 14 with RequestProcessingException

use of com.linkedin.databus2.core.container.request.RequestProcessingException 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;
}
Also used : DatabusV3MultiPartitionRegistration(com.linkedin.databus.client.pub.DatabusV3MultiPartitionRegistration) RegistrationId(com.linkedin.databus.client.pub.RegistrationId) ArrayList(java.util.ArrayList) TreeMap(java.util.TreeMap) InvalidRequestParamValueException(com.linkedin.databus2.core.container.request.InvalidRequestParamValueException) DatabusV3Registration(com.linkedin.databus.client.pub.DatabusV3Registration) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap)

Example 15 with RequestProcessingException

use of com.linkedin.databus2.core.container.request.RequestProcessingException in project databus by linkedin.

the class ClientStateRequestProcessor method getV2PartitionRegistration.

/**
   * Helper method to get partition registration information for a given V2 Cluster
   * partition
   * 
   * @param cluster
   *          V2 Cluster
   * @param partition
   *          Partition in the cluster.
   * @return
   * @throws RequestProcessingException
   *           When cluster or partition is not hosted in this instance.
   */
private RegInfo getV2PartitionRegistration(String cluster, long partition) throws RequestProcessingException {
    DatabusV2ClusterRegistrationImpl reg = getV2ClusterRegistration(cluster);
    DbusPartitionInfo p = new DbusPartitionInfoImpl(partition);
    DatabusRegistration r = reg.getPartitionRegs().get(p);
    if (null == r)
        throw new RequestProcessingException("Partition(" + partition + ") for cluster (" + cluster + ") not found !!");
    return new RegInfo(r.getState().name(), r.getRegistrationId(), r.getStatus(), r.getFilterConfig(), r.getSubscriptions());
}
Also used : DatabusV2ClusterRegistrationImpl(com.linkedin.databus.client.registration.DatabusV2ClusterRegistrationImpl) DatabusRegistration(com.linkedin.databus.client.pub.DatabusRegistration) DbusPartitionInfoImpl(com.linkedin.databus.client.DbusPartitionInfoImpl) RequestProcessingException(com.linkedin.databus2.core.container.request.RequestProcessingException) DbusPartitionInfo(com.linkedin.databus.client.pub.DbusPartitionInfo)

Aggregations

RequestProcessingException (com.linkedin.databus2.core.container.request.RequestProcessingException)20 InvalidRequestParamValueException (com.linkedin.databus2.core.container.request.InvalidRequestParamValueException)18 ArrayList (java.util.ArrayList)8 IOException (java.io.IOException)7 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)6 DatabusRegistration (com.linkedin.databus.client.pub.DatabusRegistration)5 LogicalSource (com.linkedin.databus.core.data_model.LogicalSource)5 DatabusException (com.linkedin.databus2.core.DatabusException)5 HttpStatisticsCollector (com.linkedin.databus2.core.container.monitoring.mbean.HttpStatisticsCollector)5 DbusPartitionInfo (com.linkedin.databus.client.pub.DbusPartitionInfo)4 RegistrationId (com.linkedin.databus.client.pub.RegistrationId)4 Checkpoint (com.linkedin.databus.core.Checkpoint)4 PhysicalPartition (com.linkedin.databus.core.data_model.PhysicalPartition)4 DbusHttpTotalStats (com.linkedin.databus2.core.container.monitoring.mbean.DbusHttpTotalStats)4 StringWriter (java.io.StringWriter)4 SQLException (java.sql.SQLException)4 BootstrapHttpStatsCollector (com.linkedin.databus.bootstrap.common.BootstrapHttpStatsCollector)3 DatabusV3Registration (com.linkedin.databus.client.pub.DatabusV3Registration)3 DbusEventsStatisticsCollector (com.linkedin.databus.core.monitoring.mbean.DbusEventsStatisticsCollector)3 BootstrapDatabaseTooOldException (com.linkedin.databus2.core.container.request.BootstrapDatabaseTooOldException)3