protected Scanner getScanner(StringBuilder sb) throws AccumuloException, AccumuloSecurityException { AccumuloConfiguration conf = Monitor.getSystemConfiguration(); String principal = conf.get(Property.TRACE_USER); AuthenticationToken at; Map<String, String> loginMap = conf.getAllPropertiesWithPrefix(Property.TRACE_TOKEN_PROPERTY_PREFIX); if (loginMap.isEmpty()) { Property p = Property.TRACE_PASSWORD; at = new PasswordToken(conf.get(p).getBytes(StandardCharsets.UTF_8)); } else { Properties props = new Properties(); int prefixLength = Property.TRACE_TOKEN_PROPERTY_PREFIX.getKey().length(); for (Entry<String, String> entry : loginMap.entrySet()) { props.put(entry.getKey().substring(prefixLength), entry.getValue()); } AuthenticationToken token = Property.createInstanceFromPropertyName( conf, Property.TRACE_TOKEN_TYPE, AuthenticationToken.class, new PasswordToken()); token.init(props); at = token; } String table = conf.get(Property.TRACE_TABLE); try { Connector conn = HdfsZooInstance.getInstance().getConnector(principal, at); if (!conn.tableOperations().exists(table)) { return new NullScanner(); } Scanner scanner = conn.createScanner(table, conn.securityOperations().getUserAuthorizations(principal)); return scanner; } catch (AccumuloSecurityException ex) { sb.append( "<h2>Unable to read trace table: check trace username and password configuration.</h2>\n"); return null; } catch (TableNotFoundException ex) { return new NullScanner(); } }
public TraceServer(ServerConfiguration serverConfiguration, String hostname) throws Exception { this.serverConfiguration = serverConfiguration; AccumuloConfiguration conf = serverConfiguration.getConfiguration(); table = conf.get(Property.TRACE_TABLE); while (true) { try { String principal = conf.get(Property.TRACE_USER); AuthenticationToken at; Map<String, String> loginMap = conf.getAllPropertiesWithPrefix(Property.TRACE_TOKEN_PROPERTY_PREFIX); if (loginMap.isEmpty()) { Property p = Property.TRACE_PASSWORD; at = new PasswordToken(conf.get(p).getBytes()); } else { Properties props = new Properties(); AuthenticationToken token = AccumuloClassLoader.getClassLoader() .loadClass(conf.get(Property.TRACE_TOKEN_TYPE)) .asSubclass(AuthenticationToken.class) .newInstance(); int prefixLength = Property.TRACE_TOKEN_PROPERTY_PREFIX.getKey().length() + 1; for (Entry<String, String> entry : loginMap.entrySet()) { props.put(entry.getKey().substring(prefixLength), entry.getValue()); } token.init(props); at = token; } connector = serverConfiguration.getInstance().getConnector(principal, at); if (!connector.tableOperations().exists(table)) { connector.tableOperations().create(table); IteratorSetting setting = new IteratorSetting(10, "ageoff", AgeOffFilter.class.getName()); AgeOffFilter.setTTL(setting, 7 * 24 * 60 * 60 * 1000l); connector.tableOperations().attachIterator(table, setting); } connector .tableOperations() .setProperty( table, Property.TABLE_FORMATTER_CLASS.getKey(), TraceFormatter.class.getName()); break; } catch (Exception ex) { log.info("Waiting to checking/create the trace table.", ex); UtilWaitThread.sleep(1000); } } int port = conf.getPort(Property.TRACE_PORT); final ServerSocket sock = ServerSocketChannel.open().socket(); sock.setReuseAddress(true); sock.bind(new InetSocketAddress(hostname, port)); final TServerTransport transport = new TServerSocket(sock); TThreadPoolServer.Args options = new TThreadPoolServer.Args(transport); options.processor(new Processor<Iface>(new Receiver())); server = new TThreadPoolServer(options); registerInZooKeeper(sock.getInetAddress().getHostAddress() + ":" + sock.getLocalPort()); writer = connector.createBatchWriter( table, new BatchWriterConfig().setMaxLatency(5, TimeUnit.SECONDS)); }