public YarnClientRMConnection(YarnConfiguration config) {
   this.config = config;
   InetSocketAddress remoteAddress =
       NetUtils.createSocketAddr(
           config.get(YarnConfiguration.RM_ADDRESS, YarnConfiguration.DEFAULT_RM_ADDRESS));
   Configuration appsManagerServerConf = new Configuration(config);
   appsManagerServerConf.setClass(
       YarnConfiguration.YARN_SECURITY_SERVICE_AUTHORIZATION_CLIENT_RESOURCEMANAGER,
       ClientRMSecurityInfo.class,
       SecurityInfo.class);
   YarnRPC rpc = YarnRPC.create(appsManagerServerConf);
   crmp =
       ((ClientRMProtocol)
           rpc.getProxy(ClientRMProtocol.class, remoteAddress, appsManagerServerConf));
 }
  public ClientRMProtocol getClientResourceManager() {
    if (clientResourceManager != null) return clientResourceManager;

    YarnConfiguration yarnConf = new YarnConfiguration(conf);
    YarnRPC rpc = YarnRPC.create(yarnConf);
    InetSocketAddress rmAddress =
        NetUtils.createSocketAddr(
            yarnConf.get(YarnConfiguration.RM_ADDRESS, YarnConfiguration.DEFAULT_RM_ADDRESS));

    LOG.info("Connecting to the resource manager (client) at " + rmAddress);

    clientResourceManager =
        (ClientRMProtocol) rpc.getProxy(ClientRMProtocol.class, rmAddress, conf);

    return clientResourceManager;
  }
  public AMRMProtocol getAMResourceManager() {
    if (amResourceManager != null) return amResourceManager;

    LOG.debug("Using configuration: " + conf);

    YarnConfiguration yarnConf = new YarnConfiguration(conf);
    YarnRPC rpc = YarnRPC.create(yarnConf);
    InetSocketAddress rmAddress =
        NetUtils.createSocketAddr(
            yarnConf.get(
                YarnConfiguration.RM_SCHEDULER_ADDRESS,
                YarnConfiguration.DEFAULT_RM_SCHEDULER_ADDRESS));

    LOG.info("Connecting to the resource manager (scheduling) at " + rmAddress);
    amResourceManager = (AMRMProtocol) rpc.getProxy(AMRMProtocol.class, rmAddress, conf);

    return amResourceManager;
  }
Exemple #4
0
  public static void main(String[] args) throws Exception {
    System.err.println("Inside the AM!!!");
    LOG.info("Starting the AM!!!!");

    Options opts = new Options();
    opts.addOption(
        "app_attempt_id", true, "App Attempt ID. Not to be used " + "unless for testing purposes");

    CommandLine cl = new GnuParser().parse(opts, args);

    Map<String, String> envs = System.getenv();
    _appAttemptID = Records.newRecord(ApplicationAttemptId.class);
    if (cl.hasOption("app_attempt_id")) {
      String appIdStr = cl.getOptionValue("app_attempt_id", "");
      _appAttemptID = ConverterUtils.toApplicationAttemptId(appIdStr);
    } else if (envs.containsKey(ApplicationConstants.AM_CONTAINER_ID_ENV)) {
      ContainerId containerId =
          ConverterUtils.toContainerId(envs.get(ApplicationConstants.AM_CONTAINER_ID_ENV));
      _appAttemptID = containerId.getApplicationAttemptId();
    } else {
      throw new IllegalArgumentException(
          "Container and application attempt IDs not set in the environment");
    }

    @SuppressWarnings("rawtypes")
    Map storm_conf = Config.readStormConfig(null);
    YarnConfiguration hadoopConf = new YarnConfiguration();

    StormAMRMClient client = new StormAMRMClient(_appAttemptID, storm_conf, hadoopConf);
    client.init(hadoopConf);
    client.start();

    BlockingQueue<Container> launcherQueue = new LinkedBlockingQueue<Container>();

    try {
      InetSocketAddress addr =
          NetUtils.createSocketAddr(
              hadoopConf.get(
                  YarnConfiguration.RM_SCHEDULER_ADDRESS,
                  YarnConfiguration.DEFAULT_RM_SCHEDULER_ADDRESS));
      int port = Utils.getInt(storm_conf.get(Config.MASTER_THRIFT_PORT));
      RegisterApplicationMasterResponse resp =
          client.registerApplicationMaster(addr.getHostName(), port, null);
      LOG.info("Got a registration response " + resp);
      LOG.info("Max Capability " + resp.getMaximumResourceCapability());
      client.setMaxResource(resp.getMaximumResourceCapability());
      MasterServer server = new MasterServer(storm_conf, client);
      LOG.info("Starting HB thread");
      initAndStartHeartbeat(
          client, launcherQueue, (Integer) storm_conf.get(Config.MASTER_HEARTBEAT_INTERVAL_MILLIS));
      LOG.info("Starting launcher");
      initAndStartLauncher(client, launcherQueue);
      client.startAllSupervisors();
      server.serve();
      client.unregisterApplicationMaster(FinalApplicationStatus.SUCCEEDED, "AllDone", null);
    } finally {
      client.stop();
    }
    System.err.println("See Ya!!!");
    System.exit(0);
  }