Search in sources :

Example 11 with HttpResponseStatus

use of org.jboss.netty.handler.codec.http.HttpResponseStatus in project bagheera by mozilla-metrics.

the class SubmissionHandler method handlePost.

private void handlePost(MessageEvent e, BagheeraHttpRequest request) {
    HttpResponseStatus status = BAD_REQUEST;
    ChannelBuffer content = request.getContent();
    String remoteIpAddress = HttpUtil.getRemoteAddr(request, ((InetSocketAddress) e.getChannel().getRemoteAddress()).getAddress().getHostAddress());
    if (content.readable() && content.readableBytes() > 0) {
        BagheeraMessage.Builder templateBuilder = BagheeraMessage.newBuilder();
        setMessageFields(request, e, templateBuilder, System.currentTimeMillis(), false);
        BagheeraMessage template = templateBuilder.buildPartial();
        BagheeraMessage.Builder storeBuilder = BagheeraMessage.newBuilder(template);
        storeBuilder.setPayload(ByteString.copyFrom(content.toByteBuffer()));
        storeBuilder.setId(request.getId());
        producer.send(storeBuilder.build());
        if (request.containsHeader(HEADER_OBSOLETE_DOCUMENT)) {
            handleObsoleteDocuments(request, remoteIpAddress, request.getHeaders(HEADER_OBSOLETE_DOCUMENT), template);
        } else {
            LOG.info("IP " + remoteIpAddress + " " + request.getNamespace() + " HTTP_PUT " + request.getId());
        }
        status = CREATED;
    }
    updateRequestMetrics(request.getNamespace(), request.getMethod().getName(), content.readableBytes());
    writeResponse(status, e, request.getNamespace(), URI.create(request.getId()).toString());
}
Also used : HttpResponseStatus(org.jboss.netty.handler.codec.http.HttpResponseStatus) InetSocketAddress(java.net.InetSocketAddress) BagheeraMessage(com.mozilla.bagheera.BagheeraProto.BagheeraMessage) ByteString(com.google.protobuf.ByteString) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer)

Aggregations

HttpResponseStatus (org.jboss.netty.handler.codec.http.HttpResponseStatus)11 DefaultHttpResponse (org.jboss.netty.handler.codec.http.DefaultHttpResponse)4 HttpResponse (org.jboss.netty.handler.codec.http.HttpResponse)4 DataInputStream (java.io.DataInputStream)3 HttpURLConnection (java.net.HttpURLConnection)3 URL (java.net.URL)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Map (java.util.Map)3 Configuration (org.apache.hadoop.conf.Configuration)3 DataOutputBuffer (org.apache.hadoop.io.DataOutputBuffer)3 ShuffleHeader (org.apache.hadoop.mapreduce.task.reduce.ShuffleHeader)3 YarnConfiguration (org.apache.hadoop.yarn.conf.YarnConfiguration)3 AbstractChannel (org.jboss.netty.channel.AbstractChannel)3 Channel (org.jboss.netty.channel.Channel)3 ChannelHandlerContext (org.jboss.netty.channel.ChannelHandlerContext)3 SocketChannel (org.jboss.netty.channel.socket.SocketChannel)3 HttpRequest (org.jboss.netty.handler.codec.http.HttpRequest)3 Test (org.junit.Test)3 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)2