Search in sources :

Example 11 with InvalidRequestParamValueException

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

the class ContainerStatsRequestProcessor method processOutboundTrafficClientStats.

private void processOutboundTrafficClientStats(DatabusRequest request) throws IOException, RequestProcessingException {
    String category = request.getParams().getProperty(DatabusRequest.PATH_PARAM_NAME);
    String prefix = "outbound/client/";
    String client = category.substring(prefix.length());
    ContainerTrafficTotalStats clientStats = _containerStatsCollector.getOutboundClientStats(client);
    if (null == clientStats) {
        throw new InvalidRequestParamValueException(request.getName(), prefix, client);
    }
    JsonEncoder jsonEncoder = clientStats.createJsonEncoder(Channels.newOutputStream(request.getResponseContent()));
    clientStats.toJson(jsonEncoder, null);
    if (request.getRequestType() == HttpMethod.PUT || request.getRequestType() == HttpMethod.POST) {
        enableOrResetStatsMBean(clientStats, request);
    }
}
Also used : JsonEncoder(org.apache.avro.io.JsonEncoder) ContainerTrafficTotalStats(com.linkedin.databus2.core.container.monitoring.mbean.ContainerTrafficTotalStats)

Example 12 with InvalidRequestParamValueException

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

the class ConsumerPauseRequestProcessor method process.

@Override
public DatabusRequest process(DatabusRequest request) throws IOException, RequestProcessingException {
    String action = request.getParams().getProperty(DatabusRequest.PATH_PARAM_NAME, "");
    if (action.equals("pause")) {
        _pauseConsumer.pause();
        request.getResponseContent().write(ByteBuffer.wrap("{\"pauseConsumer\":\"set-pause\"}".getBytes(Charset.defaultCharset())));
    } else if (action.equals("resume")) {
        _pauseConsumer.resume();
        request.getResponseContent().write(ByteBuffer.wrap("{\"pauseConsumer\":\"set-resume\"}".getBytes(Charset.defaultCharset())));
    } else {
        throw new InvalidRequestParamValueException(COMMAND_NAME, "request path", action);
    }
    return request;
}
Also used : InvalidRequestParamValueException(com.linkedin.databus2.core.container.request.InvalidRequestParamValueException)

Example 13 with InvalidRequestParamValueException

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

the class ClientStatsRequestProcessor method processEventsPeerStats.

private void processEventsPeerStats(DbusEventsStatisticsCollector statsCollector, String prefix, DatabusRequest request) throws IOException, RequestProcessingException {
    if (null == statsCollector)
        return;
    String category = request.getParams().getProperty(DatabusRequest.PATH_PARAM_NAME);
    String client = category.substring(prefix.length());
    DbusEventsTotalStats clientStats = statsCollector.getPeerStats(client);
    if (null == clientStats) {
        throw new InvalidRequestParamValueException(request.getName(), prefix, client);
    }
    writeJsonObjectToResponse(clientStats, request);
    if (request.getRequestType() == HttpMethod.PUT || request.getRequestType() == HttpMethod.POST) {
        enableOrResetStatsMBean(clientStats, request);
    }
}
Also used : DbusEventsTotalStats(com.linkedin.databus.core.monitoring.mbean.DbusEventsTotalStats) InvalidRequestParamValueException(com.linkedin.databus2.core.container.request.InvalidRequestParamValueException)

Example 14 with InvalidRequestParamValueException

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

the class ClientStatsRequestProcessor method findV3Registration.

private DatabusV3Registration findV3Registration(DatabusRequest request, String prefix) throws InvalidRequestParamValueException {
    String category = request.getParams().getProperty(DatabusRequest.PATH_PARAM_NAME);
    String registrationIdStr = category.substring(prefix.length());
    DatabusV3Registration reg = _client.getRegistration(new RegistrationId(registrationIdStr));
    if (null == reg) {
        LOG.warn("Invalid registrationId: " + registrationIdStr);
        throw new InvalidRequestParamValueException(request.getName(), prefix, "No data available for this RegistrationId yet");
    }
    return reg;
}
Also used : DatabusV3Registration(com.linkedin.databus.client.pub.DatabusV3Registration) RegistrationId(com.linkedin.databus.client.pub.RegistrationId) InvalidRequestParamValueException(com.linkedin.databus2.core.container.request.InvalidRequestParamValueException)

Example 15 with InvalidRequestParamValueException

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

the class GenerateDataEventsRequestProcessor method process.

@Override
public DatabusRequest process(DatabusRequest request) throws IOException, RequestProcessingException {
    String action = request.getParams().getProperty(DatabusRequest.PATH_PARAM_NAME, "");
    if (action.equals("check")) {
        boolean genRunning = _producer.checkRunning();
        StringBuilder resBuilder = new StringBuilder(1024);
        Formatter fmt = new Formatter(resBuilder);
        fmt.format("{\"genDataEventsRunning\":\"%b\"}", genRunning);
        request.getResponseContent().write(ByteBuffer.wrap(resBuilder.toString().getBytes(Charset.defaultCharset())));
    } else if (action.equals("stop")) {
        _producer.stopGeneration();
        request.getResponseContent().write(ByteBuffer.wrap("{\"genDataEventsRunning\":\"send-stop\"}".getBytes(Charset.defaultCharset())));
    } else if (action.equals("suspend")) {
        _producer.suspendGeneration();
        request.getResponseContent().write(ByteBuffer.wrap("{\"genDataEventsRunning\":\"send-suspend\"}".getBytes(Charset.defaultCharset())));
    } else if (action.equals("resume")) {
        long numEventToGenerate = request.getOptionalLongParam(NUM_EVENTS_TO_GENERATE, Long.MAX_VALUE);
        long keyMin = request.getOptionalLongParam(KEY_MIN_PARAM, 0L);
        long keyMax = request.getOptionalLongParam(KEY_MAX_PARAM, Long.MAX_VALUE);
        int percentOfBufferToGenerate = request.getOptionalIntParam(PERCENT_BUFFER_TO_GENERATE, Integer.MAX_VALUE);
        _producer.resumeGeneration(numEventToGenerate, percentOfBufferToGenerate, keyMin, keyMax);
        request.getResponseContent().write(ByteBuffer.wrap("{\"genDataEventsRunning\":\"send-resume\"}".getBytes(Charset.defaultCharset())));
    } else if (action.equals("start")) {
        long fromScn = request.getRequiredLongParam(SCN_PARAM);
        long durationMs = request.getRequiredLongParam(DURATION_MS);
        int eventsPerSec = request.getRequiredIntParam(EVENTS_PER_SEC_PARAM);
        long numEventToGenerate = request.getOptionalLongParam(NUM_EVENTS_TO_GENERATE, Long.MAX_VALUE);
        int percentOfBufferToGenerate = request.getOptionalIntParam(PERCENT_BUFFER_TO_GENERATE, Integer.MAX_VALUE);
        long keyMin = request.getOptionalLongParam(KEY_MIN_PARAM, 0L);
        long keyMax = request.getOptionalLongParam(KEY_MAX_PARAM, Long.MAX_VALUE);
        String sourcesListStr = request.getRequiredStringParam(SOURCES_NAME_PARAM);
        String[] sourcesStrArray = sourcesListStr.split(",");
        List<IdNamePair> sourcesIdList = new ArrayList<IdNamePair>(sourcesStrArray.length);
        for (String sourceIdStr : sourcesStrArray) {
            try {
                Integer id = Integer.valueOf(sourceIdStr);
                LogicalSource source = _relay.getSourcesIdNameRegistry().getSource(id);
                if (null != source)
                    sourcesIdList.add(source.asIdNamePair());
                else
                    LOG.error("unable to find source id: " + id);
            } catch (NumberFormatException nfe) {
                throw new InvalidRequestParamValueException(COMMAND_NAME, SOURCES_NAME_PARAM, sourceIdStr);
            }
        }
        //We have to use the global stats collector because the generation can go beyond the lifespan
        //of the connection
        boolean tryStart = _producer.startGeneration(fromScn, eventsPerSec, durationMs, numEventToGenerate, percentOfBufferToGenerate, keyMin, keyMax, sourcesIdList, _relayStatsCollector);
        StringBuilder resBuilder = new StringBuilder(1024);
        Formatter fmt = new Formatter(resBuilder);
        fmt.format("{\"genDataEventsStarted\":\"%b\"}", tryStart);
        request.getResponseContent().write(ByteBuffer.wrap(resBuilder.toString().getBytes(Charset.defaultCharset())));
    } else {
        throw new InvalidRequestParamValueException(COMMAND_NAME, "request path", action);
    }
    return request;
}
Also used : Formatter(java.util.Formatter) ArrayList(java.util.ArrayList) LogicalSource(com.linkedin.databus.core.data_model.LogicalSource) InvalidRequestParamValueException(com.linkedin.databus2.core.container.request.InvalidRequestParamValueException) IdNamePair(com.linkedin.databus.core.util.IdNamePair)

Aggregations

InvalidRequestParamValueException (com.linkedin.databus2.core.container.request.InvalidRequestParamValueException)20 ArrayList (java.util.ArrayList)6 LogicalSource (com.linkedin.databus.core.data_model.LogicalSource)4 DbusHttpTotalStats (com.linkedin.databus2.core.container.monitoring.mbean.DbusHttpTotalStats)4 PhysicalPartition (com.linkedin.databus.core.data_model.PhysicalPartition)3 HttpStatisticsCollector (com.linkedin.databus2.core.container.monitoring.mbean.HttpStatisticsCollector)3 RequestProcessingException (com.linkedin.databus2.core.container.request.RequestProcessingException)3 IOException (java.io.IOException)3 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)3 DatabusV3Registration (com.linkedin.databus.client.pub.DatabusV3Registration)2 RegistrationId (com.linkedin.databus.client.pub.RegistrationId)2 DbusEventsTotalStats (com.linkedin.databus.core.monitoring.mbean.DbusEventsTotalStats)2 IdNamePair (com.linkedin.databus.core.util.IdNamePair)2 DatabusException (com.linkedin.databus2.core.DatabusException)2 StringWriter (java.io.StringWriter)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 DatabusV3MultiPartitionRegistration (com.linkedin.databus.client.pub.DatabusV3MultiPartitionRegistration)1 RegisterRequestProcessor (com.linkedin.databus.container.request.RegisterRequestProcessor)1