/** * {@inheritDoc} */ @Override public ServerContext createContext(final TProtocol input, final TProtocol output) { final String userName = "metacat-thrift-interface"; String clientHost = null; //requestContext.getHeaderString("X-Forwarded-For"); final long requestThreadId = Thread.currentThread().getId(); final TTransport transport = input.getTransport(); if (transport instanceof TSocket) { final TSocket thriftSocket = (TSocket) transport; clientHost = thriftSocket.getSocket().getInetAddress().getHostAddress(); } final CatalogServerRequestContext context = new CatalogServerRequestContext( userName, null, clientHost, null, "hive", requestThreadId ); MetacatContextManager.setContext(context); return context; }
@Override public ServerContext createContext(TProtocol input, TProtocol output) { String clientName = null; if (input.getTransport() instanceof TSocket) { // tls try { clientName = ((SSLSocket) ((TSocket) input.getTransport()).getSocket()) .getSession().getPeerCertificateChain()[0].getSubjectDN().getName(); } catch (SSLPeerUnverifiedException e) { log.error(e.getMessage(), e); } log.info("createContext: " + clientName); } return null; }
/** * Thrift callback when a new client is connecting */ @Override public ServerContext createContext(TProtocol inputProto, TProtocol outputProto) { clientList.add(clientId.incrementAndGet()); LOGGER.info("Client Connected: " + clientId.get()); return new SentryServerContext(clientId.get()); }
/** * Thrift callback when a client is disconnecting */ @Override public void deleteContext(ServerContext arg0, TProtocol arg1, TProtocol arg2) { clientList.remove(((SentryServerContext) arg0).getContextId()); LOGGER.info("Client Disonnected: " + ((SentryServerContext) arg0).getContextId()); }
/** * {@inheritDoc} */ @Override public void deleteContext(final ServerContext serverContext, final TProtocol input, final TProtocol output) { validateRequest((CatalogServerRequestContext) serverContext); MetacatContextManager.removeContext(); }
/** * {@inheritDoc} */ @Override public void processContext(final ServerContext serverContext, final TTransport inputTransport, final TTransport outputTransport) { validateRequest((CatalogServerRequestContext) serverContext); }
@Override public ServerContext createContext(TProtocol tProtocol, TProtocol tProtocol1) { return null; }
@Override public void deleteContext(ServerContext serverContext, TProtocol tProtocol, TProtocol tProtocol1) { }
@Override public void processContext(ServerContext serverContext, TTransport tTransport, TTransport tTransport1) { }
/** * Loops on processing a client forever */ @Override public void run() { TProcessor processor = null; TTransport inputTransport = null; TTransport outputTransport = null; TProtocol inputProtocol = null; TProtocol outputProtocol = null; final TServerEventHandler eventHandler = getEventHandler(); ServerContext connectionContext = null; final ConnectionListener listener = connListener; final TTransport client = this.client; Socket clientSocket = null; try { processor = processorFactory_.getProcessor(client); inputTransport = inputTransportFactory_.getTransport(client); outputTransport = outputTransportFactory_.getTransport(client); inputProtocol = inputProtocolFactory_.getProtocol(inputTransport); outputProtocol = outputProtocolFactory_.getProtocol(outputTransport); if (eventHandler != null) { connectionContext = eventHandler.createContext(inputProtocol, outputProtocol); } // register with ConnectionListener if (listener != null) { if (client instanceof GfxdTSocket) { clientSocket = ((GfxdTSocket)client).getSocket(); } else if (client instanceof TSocket) { clientSocket = ((TSocket)client).getSocket(); } listener.connectionOpened(clientSocket, this.connectionNumber); } // we check stopped_ first to make sure we're not supposed to be // shutting down. this is necessary for graceful shutdown. while (true) { if (eventHandler != null) { eventHandler.processContext(connectionContext, inputTransport, outputTransport); } if (stopped || !processor.process(inputProtocol, outputProtocol)) { break; } } } catch (TTransportException tte) { // Assume the client died and continue silently } catch (TException te) { LOGGER.error("Thrift error occurred during processing of message.", te); } catch (Exception e) { LOGGER.error("Error occurred during processing of message.", e); } if (eventHandler != null) { eventHandler.deleteContext(connectionContext, inputProtocol, outputProtocol); } if (inputTransport != null) { inputTransport.close(); } if (outputTransport != null) { outputTransport.close(); } // deregister with ConnectionListener if (listener != null) { listener.connectionClosed(clientSocket, this.connectionNumber); } }
@Override public ServerContext createContext(TProtocol arg0, TProtocol arg1) { return null; }
@Override public void deleteContext(ServerContext arg0, TProtocol arg1, TProtocol arg2) { // Do nothing }
@Override public void processContext(ServerContext arg0, TTransport arg1, TTransport arg2) { // Do nothing }
@Override public void deleteContext(ServerContext serverContext, TProtocol input, TProtocol output) { log.info("deleteContext"); }
@Override public void processContext(ServerContext serverContext, TTransport inputTransport, TTransport outputTransport) { log.info("processContext: "); }
@Override public void processContext(ServerContext arg0, TTransport arg1, TTransport arg2) { }