Ejemplo n.º 1
0
 public static String buildConnectionString(String zkHosts, int port) {
   String zkPort = Integer.toString(port);
   // parse the hosts
   String[] hostlist = zkHosts.split(",", 0);
   String quorum = SliderUtils.join(hostlist, ":" + zkPort + ",", false);
   return quorum;
 }
Ejemplo n.º 2
0
 /**
  * Build a quorum list, injecting a ":defaultPort" ref if needed on any entry without one
  *
  * @param hostAndPorts
  * @param defaultPort
  * @return
  */
 public static String buildQuorum(List<HostAndPort> hostAndPorts, int defaultPort) {
   List<String> entries = new ArrayList<String>(hostAndPorts.size());
   for (HostAndPort hostAndPort : hostAndPorts) {
     entries.add(buildQuorumEntry(hostAndPort, defaultPort));
   }
   return SliderUtils.join(entries, ",", false);
 }
  private void registerHBaseServiceEntry() throws IOException {

    String name = amState.getApplicationName();
    //    name += ".hbase";
    ServiceInstanceData instanceData = new ServiceInstanceData(name, HBASE_SERVICE_TYPE);
    log.info("registering {}/{}", name, HBASE_SERVICE_TYPE);
    PublishedConfiguration publishedSite = new PublishedConfiguration("HBase site", siteConf);
    PublishedConfigSet configSet = amState.getOrCreatePublishedConfigSet(HBASE_SERVICE_TYPE);
    instanceData.externalView.configurationsURL =
        SliderUtils.appendToURL(
            amWebAPI.toExternalForm(), SLIDER_PATH_PUBLISHER, HBASE_SERVICE_TYPE);
    configSet.put(HBASE_SITE_PUBLISHED_CONFIG, publishedSite);

    registry.registerServiceInstance(instanceData, null);
  }
  /**
   * This is a validation of the application configuration on the AM. Here is where things like the
   * existence of keytabs and other not-seen-client-side properties can be tested, before the actual
   * process is spawned.
   *
   * @param instanceDefinition clusterSpecification
   * @param confDir configuration directory
   * @param secure flag to indicate that secure mode checks must exist
   * @throws IOException IO problemsn
   * @throws SliderException any failure
   */
  @Override
  public void validateApplicationConfiguration(
      AggregateConf instanceDefinition, File confDir, boolean secure)
      throws IOException, SliderException {
    String siteXMLFilename = SITE_XML;
    File siteXML = new File(confDir, siteXMLFilename);
    if (!siteXML.exists()) {
      throw new BadCommandArgumentsException(
          "Configuration directory %s doesn't contain %s - listing is %s",
          confDir, siteXMLFilename, SliderUtils.listDir(confDir));
    }

    // now read it in
    siteConf = ConfigHelper.loadConfFromFile(siteXML);
    // look in the site spec to see that it is OK
    clientProvider.validateHBaseSiteXML(siteConf, secure, siteXMLFilename);

    if (secure) {
      // secure mode: take a look at the keytab of master and RS
      SliderUtils.verifyKeytabExists(siteConf, HBaseConfigFileOptions.KEY_MASTER_KERBEROS_KEYTAB);
      SliderUtils.verifyKeytabExists(
          siteConf, HBaseConfigFileOptions.KEY_REGIONSERVER_KERBEROS_KEYTAB);
    }
  }
  @Override
  public void buildContainerLaunchContext(
      ContainerLauncher launcher,
      AggregateConf instanceDefinition,
      Container container,
      String role,
      SliderFileSystem coreFS,
      Path generatedConfPath,
      MapOperations resourceComponent,
      MapOperations appComponent,
      Path containerTmpDirPath)
      throws IOException, SliderException {

    // Set the environment
    launcher.putEnv(SliderUtils.buildEnvMap(appComponent));

    String logDirs = providerUtils.getLogdir();
    String logDir;
    int idx = logDirs.indexOf(",");
    if (idx > 0) {
      // randomly choose a log dir candidate
      String[] segments = logDirs.split(",");
      Random rand = new Random();
      logDir = segments[rand.nextInt(segments.length)];
    } else logDir = logDirs;
    launcher.setEnv(HBASE_LOG_DIR, logDir);

    launcher.setEnv(
        PROPAGATED_CONFDIR,
        ProviderUtils.convertToAppRelativePath(SliderKeys.PROPAGATED_CONF_DIR_NAME));

    // local resources

    // add the configuration resources
    launcher.addLocalResources(
        coreFS.submitDirectory(generatedConfPath, SliderKeys.PROPAGATED_CONF_DIR_NAME));
    // Add binaries
    // now add the image if it was set
    String imageURI =
        instanceDefinition
            .getInternalOperations()
            .get(InternalKeys.INTERNAL_APPLICATION_IMAGE_PATH);
    coreFS.maybeAddImagePath(launcher.getLocalResources(), imageURI);

    CommandLineBuilder cli = new CommandLineBuilder();

    String heap = appComponent.getOption(RoleKeys.JVM_HEAP, DEFAULT_JVM_HEAP);
    if (SliderUtils.isSet(heap)) {
      String adjustedHeap = SliderUtils.translateTrailingHeapUnit(heap);
      launcher.setEnv(HBASE_HEAPSIZE, adjustedHeap);
    }

    String gcOpts = appComponent.getOption(RoleKeys.GC_OPTS, DEFAULT_GC_OPTS);
    if (SliderUtils.isSet(gcOpts)) {
      launcher.setEnv(HBASE_GC_OPTS, gcOpts);
    }

    // this must stay relative if it is an image
    cli.add(providerUtils.buildPathToScript(instanceDefinition, "bin", HBASE_SCRIPT));
    // config dir is relative to the generated file
    cli.add(ARG_CONFIG);
    cli.add("$PROPAGATED_CONFDIR");

    String roleCommand;
    String logfile;
    // now look at the role

    /* JDK7
        switch (role) {
          case ROLE_WORKER:
            //role is region server
            roleCommand = REGION_SERVER;
            logfile = "/region-server.txt";
            break;
          case ROLE_MASTER:
            roleCommand = MASTER;

            logfile = "/master.txt";
            break;
          case ROLE_REST_GATEWAY:
            roleCommand = REST_GATEWAY;

            logfile = "/rest-gateway.txt";
            break;
          case ROLE_THRIFT_GATEWAY:
            roleCommand = THRIFT_GATEWAY;

            logfile = "/thrift-gateway.txt";
            break;
          case ROLE_THRIFT2_GATEWAY:
            roleCommand = THRIFT2_GATEWAY;

            logfile = "/thrift2-gateway.txt";
            break;
          default:
            throw new SliderInternalStateException("Cannot start role %s", role);
        }

    */
    if (ROLE_WORKER.equals(role)) {
      // role is region server
      roleCommand = REGION_SERVER;
      logfile = "/region-server.txt";

    } else if (ROLE_MASTER.equals(role)) {
      roleCommand = MASTER;
      logfile = "/master.txt";

    } else if (ROLE_REST_GATEWAY.equals(role)) {
      roleCommand = REST_GATEWAY;
      logfile = "/rest-gateway.txt";

    } else if (ROLE_THRIFT_GATEWAY.equals(role)) {
      roleCommand = THRIFT_GATEWAY;
      logfile = "/thrift-gateway.txt";

    } else if (ROLE_THRIFT2_GATEWAY.equals(role)) {
      roleCommand = THRIFT2_GATEWAY;
      logfile = "/thrift2-gateway.txt";
    } else {
      throw new SliderInternalStateException("Cannot start role %s", role);
    }

    cli.add(roleCommand);
    cli.add(ACTION_START);
    // log details
    cli.addOutAndErrFiles(logfile, null);
    launcher.addCommand(cli.build());
  }