Search in sources :

Example 6 with RequestProcessingException

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;
}
Also used : StringWriter(java.io.StringWriter) HttpStatisticsCollector(com.linkedin.databus2.core.container.monitoring.mbean.HttpStatisticsCollector) ArrayList(java.util.ArrayList) IdNamePair(com.linkedin.databus.core.util.IdNamePair) LogicalSource(com.linkedin.databus.core.data_model.LogicalSource) InvalidRequestParamValueException(com.linkedin.databus2.core.container.request.InvalidRequestParamValueException) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Example 7 with RequestProcessingException

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;
}
Also used : InvalidRequestParamValueException(com.linkedin.databus2.core.container.request.InvalidRequestParamValueException) PhysicalPartition(com.linkedin.databus.core.data_model.PhysicalPartition)

Example 8 with RequestProcessingException

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

Example 9 with RequestProcessingException

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

Example 10 with RequestProcessingException

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;
}
Also used : PhysicalSourceStaticConfig(com.linkedin.databus2.relay.config.PhysicalSourceStaticConfig) StringWriter(java.io.StringWriter) HttpStatisticsCollector(com.linkedin.databus2.core.container.monitoring.mbean.HttpStatisticsCollector) ArrayList(java.util.ArrayList) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

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