コード例 #1
0
  /** Initialize SecondaryNameNode. */
  private void initialize(Configuration conf) throws IOException {
    // initiate Java VM metrics
    JvmMetrics.init("SecondaryNameNode", conf.get("session.id"));

    // Create connection to the namenode.
    shouldRun = true;
    nameNodeAddr = NameNode.getAddress(conf);

    this.conf = conf;
    this.namenode =
        (NamenodeProtocol)
            RPC.waitForProxy(
                NamenodeProtocol.class, NamenodeProtocol.versionID, nameNodeAddr, conf);

    // initialize checkpoint directories
    fsName = getInfoServer();
    checkpointDirs = FSImage.getCheckpointDirs(conf, "/tmp/hadoop/dfs/namesecondary");
    checkpointEditsDirs = FSImage.getCheckpointEditsDirs(conf, "/tmp/hadoop/dfs/namesecondary");
    checkpointImage = new CheckpointStorage(conf);
    checkpointImage.recoverCreate(checkpointDirs, checkpointEditsDirs);

    // Initialize other scheduling parameters from the configuration
    checkpointPeriod = conf.getLong("fs.checkpoint.period", 3600);
    checkpointSize = conf.getLong("fs.checkpoint.size", 4194304);

    // initialize the webserver for uploading files.
    String infoAddr =
        NetUtils.getServerAddress(
            conf,
            "dfs.secondary.info.bindAddress",
            "dfs.secondary.info.port",
            "dfs.secondary.http.address");
    InetSocketAddress infoSocAddr = NetUtils.createSocketAddr(infoAddr);
    infoBindAddress = infoSocAddr.getHostName();
    int tmpInfoPort = infoSocAddr.getPort();
    infoServer = new HttpServer("secondary", infoBindAddress, tmpInfoPort, tmpInfoPort == 0, conf);
    infoServer.setAttribute("name.system.image", checkpointImage);
    this.infoServer.setAttribute("name.conf", conf);
    infoServer.addInternalServlet("getimage", "/getimage", GetImageServlet.class);
    infoServer.start();

    // The web-server port can be ephemeral... ensure we have the correct info
    infoPort = infoServer.getPort();
    conf.set("dfs.secondary.http.address", infoBindAddress + ":" + infoPort);
    LOG.info("Secondary Web-server up at: " + infoBindAddress + ":" + infoPort);
    LOG.warn(
        "Checkpoint Period   :"
            + checkpointPeriod
            + " secs "
            + "("
            + checkpointPeriod / 60
            + " min)");
    LOG.warn(
        "Log Size Trigger    :"
            + checkpointSize
            + " bytes "
            + "("
            + checkpointSize / 1024
            + " KB)");
  }
コード例 #2
0
  public void start() throws IOException {
    final String infoHost = bindAddress.getHostName();
    int infoPort = bindAddress.getPort();

    httpServer =
        new HttpServer(
            "hdfs",
            infoHost,
            infoPort,
            infoPort == 0,
            conf,
            new AccessControlList(conf.get(DFS_ADMIN, " "))) {
          {
            // Add SPNEGO support to NameNode
            if (UserGroupInformation.isSecurityEnabled()) {
              initSpnego(
                  conf,
                  DFSConfigKeys.DFS_NAMENODE_INTERNAL_SPNEGO_USER_NAME_KEY,
                  DFSUtil.getSpnegoKeytabKey(conf, DFSConfigKeys.DFS_NAMENODE_KEYTAB_FILE_KEY));
            }
            if (WebHdfsFileSystem.isEnabled(conf, LOG)) {
              // add SPNEGO authentication filter for webhdfs
              final String name = "SPNEGO";
              final String classname = AuthFilter.class.getName();
              final String pathSpec = WebHdfsFileSystem.PATH_PREFIX + "/*";
              Map<String, String> params = getAuthFilterParams(conf);
              defineFilter(webAppContext, name, classname, params, new String[] {pathSpec});
              LOG.info("Added filter '" + name + "' (class=" + classname + ")");

              // add webhdfs packages
              addJerseyResourcePackage(
                  NamenodeWebHdfsMethods.class.getPackage().getName()
                      + ";"
                      + Param.class.getPackage().getName(),
                  pathSpec);
            }
          }

          private Map<String, String> getAuthFilterParams(Configuration conf) throws IOException {
            Map<String, String> params = new HashMap<String, String>();
            String principalInConf =
                conf.get(DFSConfigKeys.DFS_WEB_AUTHENTICATION_KERBEROS_PRINCIPAL_KEY);
            if (principalInConf != null && !principalInConf.isEmpty()) {
              params.put(
                  DFSConfigKeys.DFS_WEB_AUTHENTICATION_KERBEROS_PRINCIPAL_KEY,
                  SecurityUtil.getServerPrincipal(principalInConf, bindAddress.getHostName()));
            } else if (UserGroupInformation.isSecurityEnabled()) {
              LOG.error(
                  "WebHDFS and security are enabled, but configuration property '"
                      + DFSConfigKeys.DFS_WEB_AUTHENTICATION_KERBEROS_PRINCIPAL_KEY
                      + "' is not set.");
            }
            String httpKeytab =
                conf.get(
                    DFSUtil.getSpnegoKeytabKey(conf, DFSConfigKeys.DFS_NAMENODE_KEYTAB_FILE_KEY));
            if (httpKeytab != null && !httpKeytab.isEmpty()) {
              params.put(DFSConfigKeys.DFS_WEB_AUTHENTICATION_KERBEROS_KEYTAB_KEY, httpKeytab);
            } else if (UserGroupInformation.isSecurityEnabled()) {
              LOG.error(
                  "WebHDFS and security are enabled, but configuration property '"
                      + DFSConfigKeys.DFS_WEB_AUTHENTICATION_KERBEROS_KEYTAB_KEY
                      + "' is not set.");
            }
            return params;
          }
        };

    boolean certSSL = conf.getBoolean(DFSConfigKeys.DFS_HTTPS_ENABLE_KEY, false);
    if (certSSL) {
      boolean needClientAuth = conf.getBoolean("dfs.https.need.client.auth", false);
      InetSocketAddress secInfoSocAddr =
          NetUtils.createSocketAddr(
              infoHost
                  + ":"
                  + conf.get(DFSConfigKeys.DFS_NAMENODE_HTTPS_PORT_KEY, infoHost + ":" + 0));
      Configuration sslConf = new Configuration(false);
      if (certSSL) {
        sslConf.addResource(
            conf.get(DFSConfigKeys.DFS_SERVER_HTTPS_KEYSTORE_RESOURCE_KEY, "ssl-server.xml"));
      }
      httpServer.addSslListener(secInfoSocAddr, sslConf, needClientAuth);
      // assume same ssl port for all datanodes
      InetSocketAddress datanodeSslPort =
          NetUtils.createSocketAddr(
              conf.get(DFSConfigKeys.DFS_DATANODE_HTTPS_ADDRESS_KEY, infoHost + ":" + 50475));
      httpServer.setAttribute(DFSConfigKeys.DFS_DATANODE_HTTPS_PORT_KEY, datanodeSslPort.getPort());
    }
    httpServer.setAttribute(NAMENODE_ATTRIBUTE_KEY, nn);
    httpServer.setAttribute(JspHelper.CURRENT_CONF, conf);
    setupServlets(httpServer, conf);
    httpServer.start();
    httpAddress = new InetSocketAddress(bindAddress.getAddress(), httpServer.getPort());
  }
コード例 #3
0
 protected void setUp() throws Exception {
   server = new HttpServer("jmx", "0.0.0.0", 0, true);
   server.start();
   baseUrl = new URL("http://localhost:" + server.getPort() + "/");
 }