Ejemplo n.º 1
0
 private static GCStatus fetchGcStatus() {
   GCStatus result = null;
   HostAndPort address = null;
   try {
     // Read the gc location from its lock
     ZooReaderWriter zk = ZooReaderWriter.getInstance();
     String path = ZooUtil.getRoot(instance) + Constants.ZGC_LOCK;
     List<String> locks = zk.getChildren(path, null);
     if (locks != null && locks.size() > 0) {
       Collections.sort(locks);
       address =
           new ServerServices(
                   new String(zk.getData(path + "/" + locks.get(0), null), StandardCharsets.UTF_8))
               .getAddress(Service.GC_CLIENT);
       GCMonitorService.Client client =
           ThriftUtil.getClient(
               new GCMonitorService.Client.Factory(), address, config.getConfiguration());
       try {
         result = client.getStatus(Tracer.traceInfo(), SystemCredentials.get().toThrift(instance));
       } finally {
         ThriftUtil.returnClient(client);
       }
     }
   } catch (Exception ex) {
     log.warn("Unable to contact the garbage collector at " + address, ex);
   }
   return result;
 }
Ejemplo n.º 2
0
  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));
  }
Ejemplo n.º 3
0
 public static AccumuloConfiguration getSystemConfiguration() {
   return config.getConfiguration();
 }
Ejemplo n.º 4
0
  public void run(String hostname) {
    try {
      getMonitorLock();
    } catch (Exception e) {
      log.error("Failed to get Monitor ZooKeeper lock");
      throw new RuntimeException(e);
    }

    Monitor.START_TIME = System.currentTimeMillis();
    int port = config.getConfiguration().getPort(Property.MONITOR_PORT);
    try {
      log.debug("Creating monitor on port " + port);
      server = new EmbeddedWebServer(hostname, port);
    } catch (Throwable ex) {
      log.error("Unable to start embedded web server", ex);
      throw new RuntimeException(ex);
    }

    server.addServlet(DefaultServlet.class, "/");
    server.addServlet(OperationServlet.class, "/op");
    server.addServlet(MasterServlet.class, "/master");
    server.addServlet(TablesServlet.class, "/tables");
    server.addServlet(TServersServlet.class, "/tservers");
    server.addServlet(ProblemServlet.class, "/problems");
    server.addServlet(GcStatusServlet.class, "/gc");
    server.addServlet(LogServlet.class, "/log");
    server.addServlet(XMLServlet.class, "/xml");
    server.addServlet(JSONServlet.class, "/json");
    server.addServlet(VisServlet.class, "/vis");
    server.addServlet(Summary.class, "/trace/summary");
    server.addServlet(ListType.class, "/trace/listType");
    server.addServlet(ShowTrace.class, "/trace/show");
    if (server.isUsingSsl()) server.addServlet(ShellServlet.class, "/shell");
    server.start();

    try {
      hostname = InetAddress.getLocalHost().getHostName();

      log.debug("Using " + hostname + " to advertise monitor location in ZooKeeper");

      String monitorAddress = HostAndPort.fromParts(hostname, server.getPort()).toString();

      ZooReaderWriter.getInstance()
          .putPersistentData(
              ZooUtil.getRoot(instance) + Constants.ZMONITOR_HTTP_ADDR,
              monitorAddress.getBytes(StandardCharsets.UTF_8),
              NodeExistsPolicy.OVERWRITE);
      log.info("Set monitor address in zookeeper to " + monitorAddress);
    } catch (Exception ex) {
      log.error("Unable to set monitor HTTP address in zookeeper", ex);
    }

    if (null != hostname) {
      LogService.startLogListener(
          Monitor.getSystemConfiguration(), instance.getInstanceID(), hostname);
    } else {
      log.warn("Not starting log4j listener as we could not determine address to use");
    }

    new Daemon(new LoggingRunnable(log, new ZooKeeperStatus()), "ZooKeeperStatus").start();

    // need to regularly fetch data so plot data is updated
    new Daemon(
            new LoggingRunnable(
                log,
                new Runnable() {

                  @Override
                  public void run() {
                    while (true) {
                      try {
                        Monitor.fetchData();
                      } catch (Exception e) {
                        log.warn(e.getMessage(), e);
                      }

                      UtilWaitThread.sleep(333);
                    }
                  }
                }),
            "Data fetcher")
        .start();
  }