コード例 #1
0
ファイル: BasicServlet.java プロジェクト: Sciumo/Accumulo
 public void doGet(HttpServletRequest req, HttpServletResponse resp)
     throws ServletException, IOException {
   StringBuilder sb = new StringBuilder();
   try {
     Monitor.fetchData();
     bannerText =
         sanitize(ServerConfiguration.getSystemConfiguration().get(Property.MONITOR_BANNER_TEXT));
     bannerColor =
         ServerConfiguration.getSystemConfiguration()
             .get(Property.MONITOR_BANNER_COLOR)
             .replace("'", "'");
     bannerBackground =
         ServerConfiguration.getSystemConfiguration()
             .get(Property.MONITOR_BANNER_BACKGROUND)
             .replace("'", "'");
     pageStart(req, resp, sb);
     pageBody(req, resp, sb);
     pageEnd(req, resp, sb);
   } catch (Throwable t) {
     log.error("Error building page " + req.getRequestURI(), t);
     sb.append("\n<pre>\n");
     StringWriter sw = new StringWriter();
     t.printStackTrace(new PrintWriter(sw));
     sb.append(sanitize(sw.getBuffer().toString()));
     sb.append("</pre>\n");
   } finally {
     resp.getWriter().print(sb);
     resp.getWriter().flush();
   }
 }
コード例 #2
0
ファイル: Monitor.java プロジェクト: joshelser/accumulo
 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;
 }
コード例 #3
0
ファイル: Monitor.java プロジェクト: joshelser/accumulo
  public static void main(String[] args) throws Exception {
    SecurityUtil.serverLogin(ServerConfiguration.getSiteConfiguration());

    VolumeManager fs = VolumeManagerImpl.get();
    ServerOpts opts = new ServerOpts();
    opts.parseArgs("monitor", args);
    String hostname = opts.getAddress();

    instance = HdfsZooInstance.getInstance();
    config = new ServerConfiguration(instance);
    Accumulo.init(fs, config, "monitor");
    Monitor monitor = new Monitor();
    Accumulo.enableTracing(hostname, "monitor");
    monitor.run(hostname);
  }
コード例 #4
0
    private static SystemToken get(Instance instance) {
      byte[] instanceIdBytes = instance.getInstanceID().getBytes(StandardCharsets.UTF_8);
      byte[] confChecksum;
      MessageDigest md;
      try {
        md = MessageDigest.getInstance(Constants.PW_HASH_ALGORITHM);
      } catch (NoSuchAlgorithmException e) {
        throw new RuntimeException("Failed to compute configuration checksum", e);
      }

      // seed the config with the version and instance id, so at least it's not empty
      md.update(ServerConstants.WIRE_VERSION.toString().getBytes(StandardCharsets.UTF_8));
      md.update(instanceIdBytes);

      for (Entry<String, String> entry : ServerConfiguration.getSiteConfiguration()) {
        // only include instance properties
        if (entry.getKey().startsWith(Property.INSTANCE_PREFIX.toString())) {
          md.update(entry.getKey().getBytes(StandardCharsets.UTF_8));
          md.update(entry.getValue().getBytes(StandardCharsets.UTF_8));
        }
      }
      confChecksum = md.digest();

      int wireVersion = ServerConstants.WIRE_VERSION;

      ByteArrayOutputStream bytes =
          new ByteArrayOutputStream(
              3 * (Integer.SIZE / Byte.SIZE) + instanceIdBytes.length + confChecksum.length);
      DataOutputStream out = new DataOutputStream(bytes);
      try {
        out.write(wireVersion * -1);
        out.write(instanceIdBytes.length);
        out.write(instanceIdBytes);
        out.write(confChecksum.length);
        out.write(confChecksum);
      } catch (IOException e) {
        // this is impossible with ByteArrayOutputStream; crash hard if this happens
        throw new RuntimeException(e);
      }
      return new SystemToken(Base64.encodeBase64(bytes.toByteArray()));
    }
コード例 #5
0
ファイル: TraceServer.java プロジェクト: harayz/accumulo
 private void registerInZooKeeper(String name) throws Exception {
   String root = ZooUtil.getRoot(serverConfiguration.getInstance()) + Constants.ZTRACERS;
   IZooReaderWriter zoo = ZooReaderWriter.getInstance();
   String path = zoo.putEphemeralSequential(root + "/trace-", name.getBytes());
   zoo.exists(path, this);
 }
コード例 #6
0
ファイル: TraceServer.java プロジェクト: harayz/accumulo
  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));
  }
コード例 #7
0
ファイル: Monitor.java プロジェクト: joshelser/accumulo
 public static AccumuloConfiguration getSystemConfiguration() {
   return config.getConfiguration();
 }
コード例 #8
0
ファイル: Monitor.java プロジェクト: joshelser/accumulo
  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();
  }