Search in sources :

Example 46 with DatabusRequest

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

the class ContainerStatsRequestProcessor method processInboundTrafficTotalStats.

private void processInboundTrafficTotalStats(DatabusRequest request) throws IOException {
    ContainerTrafficTotalStatsMBean inboundTrafficTotalStatsMBean = _containerStatsCollector.getInboundTrafficTotalStats();
    if (null == inboundTrafficTotalStatsMBean)
        return;
    //String json = inboundTrafficTotalStatsMBean.toJson();
    JsonEncoder jsonEncoder = inboundTrafficTotalStatsMBean.createJsonEncoder(Channels.newOutputStream(request.getResponseContent()));
    inboundTrafficTotalStatsMBean.toJson(jsonEncoder, null);
    if (request.getRequestType() == HttpMethod.PUT || request.getRequestType() == HttpMethod.POST) {
        enableOrResetStatsMBean(inboundTrafficTotalStatsMBean, request);
    }
}
Also used : ContainerTrafficTotalStatsMBean(com.linkedin.databus2.core.container.monitoring.mbean.ContainerTrafficTotalStatsMBean) JsonEncoder(org.apache.avro.io.JsonEncoder)

Example 47 with DatabusRequest

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

the class ContainerStatsRequestProcessor method processContainerStats.

private void processContainerStats(DatabusRequest request) throws IOException {
    ContainerStats containerStats = _containerStatsCollector.getContainerStats();
    if (null == containerStats) {
        return;
    }
    writeJsonObjectToResponse(containerStats, request);
}
Also used : ContainerStats(com.linkedin.databus2.core.container.monitoring.mbean.ContainerStats)

Example 48 with DatabusRequest

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

the class HttpRequestHandler method messageReceived.

@Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
    /*NettyStats nettyStats = _configManager.getNettyStats();
      CallCompletion callCompletion = nettyStats.isEnabled() ?
          nettyStats.getRequestHandler_messageRecieved().startCall() :
          null;*/
    try {
        if (!readingChunks) {
            request = (HttpRequest) e.getMessage();
            ctx.sendUpstream(e);
            QueryStringDecoder queryStringDecoder = new QueryStringDecoder(request.getUri());
            String queryPath = queryStringDecoder.getPath();
            int slashPos = queryPath.indexOf('/', 1);
            if (slashPos < 0) {
                slashPos = queryPath.length();
            }
            String cmdName = queryPath.substring(1, slashPos);
            ServerContainer.RuntimeConfig config = _serverContainer.getContainerRuntimeConfigMgr().getReadOnlyConfig();
            if (LOG.isDebugEnabled()) {
                LOG.debug("Got command: " + cmdName);
            }
            dbusRequest = new DatabusRequest(cmdName, request.getMethod(), e.getRemoteAddress(), config);
            if (LOG.isDebugEnabled()) {
                LOG.debug("Starting processing command [" + dbusRequest.getId() + "] " + dbusRequest.getName());
            }
            Properties requestProps = dbusRequest.getParams();
            if (slashPos < queryPath.length()) {
                requestProps.put(DatabusRequest.PATH_PARAM_NAME, queryPath.substring(slashPos + 1));
            }
            for (Map.Entry<String, String> h : request.getHeaders()) {
                handleHttpHeader(h);
            }
            Map<String, List<String>> params = queryStringDecoder.getParameters();
            if (!params.isEmpty()) {
                for (Entry<String, List<String>> p : params.entrySet()) {
                    String key = p.getKey();
                    List<String> vals = p.getValue();
                    if (vals.size() == 1) {
                        requestProps.put(key, vals.get(0));
                    } else {
                        requestProps.put(key, vals);
                    }
                    for (String val : vals) {
                        LOG.trace("PARAM: " + key + " = " + val);
                    }
                }
            }
            if (request.isChunked()) {
                if (null != _readTimeoutHandler) {
                    readingChunks = true;
                    _readTimeoutHandler.start(ctx.getPipeline().getContext(_readTimeoutHandler));
                }
            } else {
                ChannelBuffer content = request.getContent();
                handleRequestContentChunk(content);
                writeResponse(ctx, e);
            }
        } else if (e.getMessage() instanceof HttpChunk) {
            HttpChunk chunk = (HttpChunk) e.getMessage();
            if (chunk.isLast()) {
                readingChunks = false;
                LOG.trace("END OF CONTENT");
                HttpChunkTrailer trailer = (HttpChunkTrailer) chunk;
                for (Map.Entry<String, String> h : trailer.getHeaders()) {
                    handleHttpHeader(h);
                }
                writeResponse(ctx, e);
            } else {
                ChannelBuffer content = chunk.getContent();
                handleRequestContentChunk(content);
            }
        }
        ctx.sendUpstream(e);
    //FIXME   DDS-305: Rework the netty stats collector to use event-based stats aggregation
    /*if (null != callCompletion)
        {
          callCompletion.endCall();
        }*/
    } catch (Exception ex) {
        LOG.error("HttpRequestHandler.messageReceived error", ex);
    //FIXME   DDS-305: Rework the netty stats collector to use event-based stats aggregation
    /*if (null != callCompletion)
        {
          callCompletion.endCallWithError(ex);
        }*/
    }
}
Also used : Properties(java.util.Properties) ClosedChannelException(java.nio.channels.ClosedChannelException) IOException(java.io.IOException) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer) QueryStringDecoder(org.jboss.netty.handler.codec.http.QueryStringDecoder) DatabusRequest(com.linkedin.databus2.core.container.request.DatabusRequest) Entry(java.util.Map.Entry) HttpChunkTrailer(org.jboss.netty.handler.codec.http.HttpChunkTrailer) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) HttpChunk(org.jboss.netty.handler.codec.http.HttpChunk)

Example 49 with DatabusRequest

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

the class ConfigRequestProcessor method doPutConfig.

private void doPutConfig(DatabusRequest request) throws IOException, RequestProcessingException {
    Properties cmdParams = request.getParams();
    try {
        _serverContainer.getContainerRuntimeConfigMgr().loadConfig(cmdParams);
    } catch (InvalidConfigException ice) {
        throw new RequestProcessingException("config load failed", ice);
    }
    ServerContainer.RuntimeConfig newConfig = _serverContainer.getContainerRuntimeConfigMgr().getReadOnlyConfig();
    serializeConfig(newConfig, request.getResponseContent());
}
Also used : InvalidConfigException(com.linkedin.databus.core.util.InvalidConfigException) Properties(java.util.Properties) ServerContainer(com.linkedin.databus2.core.container.netty.ServerContainer)

Example 50 with DatabusRequest

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

the class ContainerAdminRequestProcessor method process.

@Override
public DatabusRequest process(DatabusRequest request) throws IOException, RequestProcessingException {
    String path = request.getParams().getProperty(DatabusRequest.PATH_PARAM_NAME);
    String normPath = normalizePath(path);
    if (null == normPath) {
        if (0 == _normalizedPath.length())
            returnPlainStatus(request);
        else
            throw new RequestProcessingException("expected admin sub-command");
    } else if (_normalizedPath.equals(normPath))
        returnPlainStatus(request);
    else if (_statusPath.equals(normPath))
        returnComponentStatus(request);
    else
        throw new RequestProcessingException("unknown admin sub-command:" + normPath);
    return null;
}
Also used : RequestProcessingException(com.linkedin.databus2.core.container.request.RequestProcessingException)

Aggregations

InvalidRequestParamValueException (com.linkedin.databus2.core.container.request.InvalidRequestParamValueException)20 RequestProcessingException (com.linkedin.databus2.core.container.request.RequestProcessingException)17 ArrayList (java.util.ArrayList)9 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)9 LogicalSource (com.linkedin.databus.core.data_model.LogicalSource)8 DatabusRequest (com.linkedin.databus2.core.container.request.DatabusRequest)8 IOException (java.io.IOException)8 Properties (java.util.Properties)8 DbusHttpTotalStats (com.linkedin.databus2.core.container.monitoring.mbean.DbusHttpTotalStats)6 List (java.util.List)6 RegistrationId (com.linkedin.databus.client.pub.RegistrationId)5 RegisterRequestProcessor (com.linkedin.databus.container.request.RegisterRequestProcessor)5 PhysicalPartition (com.linkedin.databus.core.data_model.PhysicalPartition)5 ChunkedWritableByteChannel (com.linkedin.databus2.core.container.ChunkedWritableByteChannel)5 EventProducer (com.linkedin.databus2.producers.EventProducer)5 SchemaRegistryService (com.linkedin.databus2.schemas.SchemaRegistryService)5 SourceIdNameRegistry (com.linkedin.databus2.schemas.SourceIdNameRegistry)5 HashMap (java.util.HashMap)5 DatabusRegistration (com.linkedin.databus.client.pub.DatabusRegistration)4 DatabusV3Registration (com.linkedin.databus.client.pub.DatabusV3Registration)4