Example #1
0
File: main.cpp Project: benh/twesos
int main (int argc, char **argv)
{
  Configurator conf;
  conf.addOption<int>("port", 'p', "Port to listen on", 5050);
  conf.addOption<string>("ip", "IP address to listen on");
  local::registerOptions(&conf);

  if (argc == 2 && string("--help") == argv[1]) {
    usage(argv[0], conf);
    exit(1);
  }

  Params params;
  try {
    params = conf.load(argc, argv, true);
  } catch (ConfigurationException& e) {
    cerr << "Configuration error: " << e.what() << endl;
    exit(1);
  }

  Logging::init(argv[0], params);

  if (params.contains("port"))
    setenv("LIBPROCESS_PORT", params["port"].c_str(), 1);

  if (params.contains("ip"))
    setenv("LIBPROCESS_IP", params["ip"].c_str(), 1);

  const PID &master = local::launch(params, false);

  Process::wait(master);

  return 0;
}
Example #2
0
// Check that when we specify a conf directory on the command line,
// we load values from the config file first and then the command line
TEST_WITH_WORKDIR(ConfiguratorTest, CommandLineConfFlag)
{
  if (mkdir("bin", 0755) != 0)
    FAIL() << "Failed to create directory bin";
  if (mkdir("conf2", 0755) != 0)
    FAIL() << "Failed to create directory conf2";
  ofstream file("conf2/mesos.conf");
  file << "a=1\n";
  file << "b=2\n";
  file << "c=3";
  file.close();

  const int ARGC = 4;
  char* argv[ARGC];
  argv[0] = (char*) "bin/filename";
  argv[1] = (char*) "--conf=conf2";
  argv[2] = (char*) "--b=overridden";
  argv[3] = (char*) "--d=fromCmdLine";

  Configurator conf;
  EXPECT_NO_THROW( conf.load(ARGC, argv) );

  EXPECT_EQ("1",           conf.getConfiguration()["a"]);
  EXPECT_EQ("overridden",  conf.getConfiguration()["b"]);
  EXPECT_EQ("3",           conf.getConfiguration()["c"]);
  EXPECT_EQ("fromCmdLine", conf.getConfiguration()["d"]);
}
Example #3
0
// Check that spaces before and after the = signs in config files are ignored
TEST_WITH_WORKDIR(ConfiguratorTest, ConfigFileSpacesIgnored)
{
  if (mkdir("conf", 0755) != 0)
    FAIL() << "Failed to create directory conf";
  ofstream file("conf/mesos.conf");
  file << "test1=coffee # beans are tasty\n";
  file << "# just a comment\n";
  file << "  \t # comment with spaces in front\n";
  file << "\n";
  file << "test2 =tea\n";
  file << "test3=  water\n";
  file << "   test4 =  milk\n";
  file << "  test5 =  hot  chocolate\t\n";
  file << "\ttest6 =  juice# #\n";
  file.close();

  Configurator conf;
  setenv("MESOS_CONF", "conf", 1);
  EXPECT_NO_THROW(conf.load());
  unsetenv("MESOS_CONF");

  EXPECT_EQ("coffee",         conf.getConfiguration()["test1"]);
  EXPECT_EQ("tea",            conf.getConfiguration()["test2"]);
  EXPECT_EQ("water",          conf.getConfiguration()["test3"]);
  EXPECT_EQ("milk",           conf.getConfiguration()["test4"]);
  EXPECT_EQ("hot  chocolate", conf.getConfiguration()["test5"]);
  EXPECT_EQ("juice",          conf.getConfiguration()["test6"]);
}
Example #4
0
int main(int argc, char *argv[]) {
    QGuiApplication* app = SailfishApp::application(argc, argv);
    QQuickView* view = SailfishApp::createView();

    Configurator config;
    config.load();

    //qmlRegisterType<Request>("Sailbook.Request", 1, 0, "Request");
    qmlRegisterUncreatableType<Request>("App.Sailbook", 1, 0, "Request", QStringLiteral("Error"));
    //qmlRegisterInterface<SessionManager>("SessionManager");

    SessionManager session(QStringLiteral(APPID), config.getValue(QStringLiteral("token")).toString());
    session.setExtendedPermission(SessionManager::ExtendedPermissions(
        SessionManager::Email |
        SessionManager::ManageNotifications |
        SessionManager::ManagePages |
        SessionManager::PublishActions |
        SessionManager::ReadFriendList |
        SessionManager::ReadInsights |
        SessionManager::ReadMailbox |
        SessionManager::ReadPageMailboxes |
        SessionManager::ReadStream |
        SessionManager::RsvpEvent
    ));

    session.setUserDataPermission(SessionManager::UserDataPermissions(
        SessionManager::UserAboutMe |
        SessionManager::UserActionsBooks |
        SessionManager::UserActionsMusic |
        SessionManager::UserActionsNews |
        SessionManager::UserActionsVideo |
        SessionManager::UserActivities |
        SessionManager::UserBirthday |
        SessionManager::UserEducationHistory |
        SessionManager::UserEvents |
        SessionManager::UserFriends |
        SessionManager::UserGamesActivity |
        SessionManager::UserGroups |
        SessionManager::UserHometown |
        SessionManager::UserInterests |
        SessionManager::UserLikes |
        SessionManager::UserLocation |
        SessionManager::UserPhotos |
        SessionManager::UserRelationshipDetails |
        SessionManager::UserRelationships |
        SessionManager::UserReligionPolitics |
        SessionManager::UserStatus |
        SessionManager::UserTaggedPlaces |
        SessionManager::UserVideos |
        SessionManager::UserWebsite |
        SessionManager::UserWorkHistory
    ));

    view->rootContext()->setContextProperty("SessionManager", &session);
    view->rootContext()->setContextProperty("Configurator", &config);
    view->setSource(SailfishApp::pathTo("qml/sailbook.qml"));
    view->show();

    return app->exec();
}
Example #5
0
TEST(ConfiguratorTest, Environment)
{
  setenv("MESOS_TEST", "working", true);
  Configurator conf;
  conf.load();
  unsetenv("MESOS_TEST");

  EXPECT_EQ("working", conf.getConfiguration()["test"]);
}
Example #6
0
TvnServer::TvnServer(bool runsInServiceContext, StringStorage vncIniDirPath /*""*/, bool runAsPortable /*=false*/ )
: Singleton<TvnServer>(),
  ListenerContainer<TvnServerListener *>(),
  m_runAsService(runsInServiceContext),
  m_runPortable(runAsPortable),
  m_rfbClientManager(0),
  m_httpServer(0), m_controlServer(0), m_rfbServer(0)
{
  Configurator *configurator = Configurator::getInstance();

  configurator->setServiceFlag(m_runAsService);
  configurator->setPortableRunFlag(m_runPortable);
  configurator->setVncIniDirectoryPath ( vncIniDirPath.getString() );

  configurator->load();

  m_config = Configurator::getInstance()->getServerConfig();

  resetLogFilePath();

  m_log.changeLevel(m_config->getLogLevel());

  Log::message(_T("TightVNC Server Build on %s"), BuildTime::DATE);

  Log::info(_T("Initialize WinSock"));

  try {
    WindowsSocket::startup(2, 1);
  } catch (Exception &ex) {
    Log::interror(_T("%s"), ex.getMessage());
  }

  ZombieKiller *zombieKiller = new ZombieKiller();

  m_rfbClientManager = new RfbClientManager(NULL);

  m_rfbClientManager->addListener(this);

  Configurator::getInstance()->addListener(this);

  {
    AutoLock l(&m_mutex);

    restartMainRfbServer();
    (void)m_extraRfbServers.reload(m_runAsService, m_rfbClientManager);
    restartHttpServer();
    restartControlServer();
  }
}
Example #7
0
// Check that exceptions are thrown on invalid config file
TEST_WITH_WORKDIR(ConfiguratorTest, MalformedConfigFile)
{
  if (mkdir("conf", 0755) != 0)
    FAIL() << "Failed to create directory conf";
  ofstream file("conf/mesos.conf");
  file << "test1=coffee\n";
  file << "JUNK\n";
  file << "test2=tea\n";
  file.close();

  setenv("MESOS_CONF", "conf", 1);
  Configurator conf;
  EXPECT_THROW(conf.load(), ConfigurationException);
  unsetenv("MESOS_CONF");
}
int ControlApplication::runConfigurator(bool configService, bool isRunAsRequested)
{
  // If not enough rights to configurate service, then restart application requesting
  // admin access rights.
  if (configService && (IsUserAnAdmin() == FALSE)) {
    // If admin rights already requested and application still don't have them,
    // then show error message and exit.
    if (isRunAsRequested) {
      MessageBox(0,
        StringTable::getString(IDS_ADMIN_RIGHTS_NEEDED),
        StringTable::getString(IDS_MBC_TVNCONTROL),
        MB_OK | MB_ICONERROR);
      return 0;
    }
    // Path to tvnserver binary.
    StringStorage pathToBinary;
    // Command line for child process.
    StringStorage childCommandLine;

    // Get path to tvnserver binary.
    Environment::getCurrentModulePath(&pathToBinary);
    // Set -dontelevate flag to tvncontrol know that admin rights already requested.
    childCommandLine.format(_T("%s -dontelevate"), m_commandLine.getString());

    // Start child.
    try {
      Shell::runAsAdmin(pathToBinary.getString(), childCommandLine.getString());
    } catch (SystemException &sysEx) {
      if (sysEx.getErrorCode() != ERROR_CANCELLED) {
        MessageBox(0,
          sysEx.getMessage(),
          StringTable::getString(IDS_MBC_TVNCONTROL),
          MB_OK | MB_ICONERROR);
      }
      return 1;
    } // try / catch.
    return 0;
  }

  Configurator *configurator = Configurator::getInstance();

  configurator->setServiceFlag(configService);
  configurator->load();

  ConfigDialog confDialog(configService, 0);

  return confDialog.showModal();
}
Example #9
0
// Check whether specifying just MESOS_CONF allows a config file to be loaded
TEST_WITH_WORKDIR(ConfiguratorTest, ConfigFileWithConfDir)
{
  if (mkdir("conf2", 0755) != 0)
    FAIL() << "Failed to create directory conf2";
  ofstream file("conf2/mesos.conf");
  file << "test3=shake # sugar bomb\n";
  file << "# just a comment\n";
  file << "test4=milk\n";
  file.close();
  setenv("MESOS_CONF", "conf2", 1);
  Configurator conf;
  EXPECT_NO_THROW( conf.load() );
  unsetenv("MESOS_CONF");

  EXPECT_EQ("shake", conf.getConfiguration()["test3"]);
  EXPECT_EQ("milk",  conf.getConfiguration()["test4"]);
}
Example #10
0
int main(int argc, char **argv)
{
  GOOGLE_PROTOBUF_VERIFY_VERSION;

  Configurator configurator;

  logging::registerOptions(&configurator);

  local::registerOptions(&configurator);

  configurator.addOption<int>("port", 'p', "Port to listen on", 5050);
  configurator.addOption<string>("ip", "IP address to listen on");

  if (argc == 2 && string("--help") == argv[1]) {
    usage(argv[0], configurator);
    exit(1);
  }

  Configuration conf;
  try {
    conf = configurator.load(argc, argv);
  } catch (ConfigurationException& e) {
    cerr << "Configuration error: " << e.what() << endl;
    exit(1);
  }

  if (conf.contains("port")) {
    utils::os::setenv("LIBPROCESS_PORT", conf["port"]);
  }

  if (conf.contains("ip")) {
    utils::os::setenv("LIBPROCESS_IP", conf["ip"]);
  }

  // Initialize libprocess.
  process::initialize("master");

  logging::initialize(argv[0], conf);

  process::wait(local::launch(conf, false));

  return 0;
}
Example #11
0
// Check that variables are loaded with the correct priority when an
// environment variable, a config file element , and a config flag
// are all present. Command line flags should have the highest priority,
// second should be environment variables, and last should be the file.
TEST_WITH_WORKDIR(ConfiguratorTest, LoadingPriorities)
{
  // Create a file which contains parameters a, b, c and d
  if (mkdir("bin", 0755) != 0)
    FAIL() << "Failed to create directory bin";
  if (mkdir("conf", 0755) != 0)
    FAIL() << "Failed to create directory conf";
  ofstream file("conf/mesos.conf");
  file << "a=fromFile\n";
  file << "b=fromFile\n";
  file << "c=fromFile\n";
  file << "d=fromFile\n";
  file.close();

  // Set environment to contain parameters a and b
  setenv("MESOS_A", "fromEnv", 1);
  setenv("MESOS_B", "fromEnv", 1);
  setenv("MESOS_CONF", "conf", 1);

  // Pass parameters a and c from the command line
  const int ARGC = 3;
  char* argv[ARGC];
  argv[0] = (char*) "bin/filename";
  argv[1] = (char*) "--a=fromCmdLine";
  argv[2] = (char*) "--c=fromCmdLine";

  Configurator conf;
  EXPECT_NO_THROW(conf.load(ARGC, argv));

  // Clear the environment vars set above
  unsetenv("MESOS_A");
  unsetenv("MESOS_B");
  unsetenv("MESOS_CONF");

  // Check that every variable is obtained from the highest-priority location
  // (command line > env > file)
  EXPECT_EQ("fromCmdLine", conf.getConfiguration()["a"]);
  EXPECT_EQ("fromEnv",     conf.getConfiguration()["b"]);
  EXPECT_EQ("fromCmdLine", conf.getConfiguration()["c"]);
  EXPECT_EQ("fromFile",    conf.getConfiguration()["d"]);
}
Example #12
0
TEST(ConfiguratorTest, DefaultOptions)
{
  const int ARGC = 5;
  char* argv[ARGC];
  argv[0] = (char*) "bin/filename";
  argv[1] = (char*) "--test1=501";
  argv[2] = (char*) "--test2";
  argv[3] = (char*) "--excp=txt";
  argv[4] = (char*) "--test8=foo";

  Configurator conf;

  EXPECT_NO_THROW(conf.addOption<int>("test1", "Testing option", 500));
  EXPECT_NO_THROW(conf.addOption<bool>("test2", "Another tester", 0));
  EXPECT_NO_THROW(conf.addOption<long>("test3", "Tests the default", 2010));
  EXPECT_NO_THROW(conf.addOption<string>("test4", "Option without default"));
  EXPECT_NO_THROW(conf.addOption<string>("test5", "Option with a default",
                                         "default"));
  EXPECT_NO_THROW(conf.addOption<bool>("test6", "Toggler...", false));
  EXPECT_NO_THROW(conf.addOption<bool>("test7", "Toggler...", true));
  EXPECT_NO_THROW(conf.addOption<string>("test8", "Overridden default",
                                         "default"));
  EXPECT_NO_THROW(conf.load(ARGC, argv));

  EXPECT_NO_THROW(conf.addOption<int>("excp", "Exception tester.", 50));
  EXPECT_THROW(conf.validate(), ConfigurationException);
  conf.getConfiguration()["excp"] = "27";
  EXPECT_NO_THROW(conf.validate());

  EXPECT_EQ("501",     conf.getConfiguration()["test1"]);
  EXPECT_EQ("1",       conf.getConfiguration()["test2"]);
  EXPECT_EQ("2010",    conf.getConfiguration()["test3"]);
  EXPECT_EQ("",        conf.getConfiguration()["test4"]);
  EXPECT_EQ("default", conf.getConfiguration()["test5"]);
  EXPECT_EQ("27",      conf.getConfiguration()["excp"]);
  EXPECT_EQ("0",       conf.getConfiguration()["test6"]);
  EXPECT_EQ("1",       conf.getConfiguration()["test7"]);
  EXPECT_EQ("foo",     conf.getConfiguration()["test8"]);
}
Example #13
0
int main(int argc, char **argv)
{
  Configurator configurator;
  local::registerOptions(&configurator);
  configurator.addOption<int>("port", 'p', "Port to listen on", 5050);
  configurator.addOption<string>("ip", "IP address to listen on");

  if (argc == 2 && string("--help") == argv[1]) {
    usage(argv[0], configurator);
    exit(1);
  }

  Configuration conf;
  try {
    conf = configurator.load(argc, argv, true);
  } catch (ConfigurationException& e) {
    cerr << "Configuration error: " << e.what() << endl;
    exit(1);
  }

  Logging::init(argv[0], conf);

  if (conf.contains("port")) {
    setenv("LIBPROCESS_PORT", conf["port"].c_str(), 1);
  }

  if (conf.contains("ip")) {
    setenv("LIBPROCESS_IP", conf["ip"].c_str(), 1);
  }

  // Initialize libprocess library (but not glog, done above).
  process::initialize(false);

  process::wait(local::launch(conf, false));

  return 0;
}
Example #14
0
TEST(ConfiguratorTest, CommandLine)
{
  const int ARGC = 12;
  char* argv[ARGC];
  argv[0] =  (char*) "bin/filename";
  argv[1] =  (char*) "--test1=text1";
  argv[2] =  (char*) "--test2";
  argv[3] =  (char*) "text2";
  argv[4] =  (char*) "-N";
  argv[5] =  (char*) "-25";
  argv[6] =  (char*) "--cAsE=4";
  argv[7] =  (char*) "--space=Long String";
  argv[8] =  (char*) "--bool1";
  argv[9] =  (char*) "--no-bool2";
  argv[10] = (char*) "-a";
  argv[11] = (char*) "-no-b";

  Configurator conf;
  EXPECT_NO_THROW(conf.addOption<int>("negative", 'N', "some val", -30));
  EXPECT_NO_THROW(conf.addOption<string>("test1", "textual value", "text2"));
  EXPECT_NO_THROW(conf.addOption<bool>("bool1", "toggler", false));
  EXPECT_NO_THROW(conf.addOption<bool>("bool2", 'z', "toggler", true));
  EXPECT_NO_THROW(conf.addOption<bool>("bool3", 'a', "toggler", false));
  EXPECT_NO_THROW(conf.addOption<bool>("bool4", 'b', "toggler", true));

  EXPECT_NO_THROW( conf.load(ARGC, argv) );

  EXPECT_EQ("text1",       conf.getConfiguration()["test1"]);
  EXPECT_EQ("1",           conf.getConfiguration()["test2"]);
  EXPECT_EQ("-25",         conf.getConfiguration()["negative"]);
  EXPECT_EQ("4",           conf.getConfiguration()["case"]);
  EXPECT_EQ("Long String", conf.getConfiguration()["space"]);
  EXPECT_EQ("1",           conf.getConfiguration()["bool1"]);
  EXPECT_EQ("0",           conf.getConfiguration()["bool2"]);
  EXPECT_EQ("1",           conf.getConfiguration()["bool3"]);
  EXPECT_EQ("0",           conf.getConfiguration()["bool4"]);
}
Example #15
0
int main(int argc, char **argv)
{
  Configurator configurator;
  Logging::registerOptions(&configurator);
  Master::registerOptions(&configurator);
  configurator.addOption<int>("port", 'p', "Port to listen on", 5050);
  configurator.addOption<string>("ip", "IP address to listen on");
  configurator.addOption<string>("url", 'u', "URL used for leader election");
#ifdef MESOS_WEBUI
  configurator.addOption<int>("webui_port", 'w', "Web UI port", 8080);
#endif

  if (argc == 2 && string("--help") == argv[1]) {
    usage(argv[0], configurator);
    exit(1);
  }

  Configuration conf;
  try {
    conf = configurator.load(argc, argv, true);
  } catch (ConfigurationException& e) {
    cerr << "Configuration error: " << e.what() << endl;
    exit(1);
  }

  Logging::init(argv[0], conf);

  if (conf.contains("port")) {
    setenv("LIBPROCESS_PORT", conf["port"].c_str(), 1);
  }

  if (conf.contains("ip")) {
    setenv("LIBPROCESS_IP", conf["ip"].c_str(), 1);
  }

  // Initialize libprocess library (but not glog, done above).
  process::initialize(false);

  string url = conf.get("url", "");

  LOG(INFO) << "Build: " << build::DATE << " by " << build::USER;
  LOG(INFO) << "Starting Mesos master";

  if (chdir(dirname(argv[0])) != 0) {
    fatalerror("Could not chdir into %s", dirname(argv[0]));
  }

  Master* master = new Master(conf);
  process::spawn(master);

  MasterDetector* detector =
    MasterDetector::create(url, master->self(), true, Logging::isQuiet(conf));

#ifdef MESOS_WEBUI
  webui::start(master->self(), conf);
#endif
  
  process::wait(master->self());
  delete master;

  MasterDetector::destroy(detector);

  return 0;
}
Example #16
0
int main(int argc, char** argv)
{
  Configurator configurator;

  logging::registerOptions(&configurator);

  configurator.addOption<uint64_t>(
      "from",
      "Position from which to start reading in the log");

  configurator.addOption<uint64_t>(
      "to",
      "Position from which to stop reading in the log");

  configurator.addOption<bool>(
      "help",
      'h',
      "Prints this usage message");

  Configuration conf;
  try {
    conf = configurator.load(argc, argv);
  } catch (const ConfigurationException& e) {
    cerr << "Configuration error: " << e.what() << endl;
    usage(argv[0], configurator);
    exit(1);
  }

  if (argc < 2 || conf.contains("help")) {
    usage(argv[0], configurator);
    exit(1);
  }

  process::initialize();

  logging::initialize(argv[0], conf);

  string path = argv[argc - 1];

  Replica replica(path);

  process::Future<uint64_t> begin = replica.beginning();
  process::Future<uint64_t> end = replica.ending();

  begin.await();
  end.await();

  CHECK(begin.isReady());
  CHECK(end.isReady());

  uint64_t from = conf.get<uint64_t>("from", begin.get());
  uint64_t to = conf.get<uint64_t>("to", end.get());

  cerr << endl << "Attempting to read the log from "
       << from << " to " << to << endl << endl;

  process::Future<std::list<Action> > actions = replica.read(from, to);

  actions.await();

  CHECK(!actions.isFailed()) << actions.failure();

  CHECK(actions.isReady());

  foreach (const Action& action, actions.get()) {
    cout << "----------------------------------------------" << endl;
    action.PrintDebugString();
  }

  return 0;
}
Example #17
0
File: main.cpp Project: benh/twesos
int main(int argc, char **argv)
{
  Configurator conf;
  conf.addOption<string>("url", 'u', "Master URL");
  conf.addOption<string>("isolation", 'i', "Isolation module name", "process");
#ifdef MESOS_WEBUI
  conf.addOption<int>("webui_port", 'w', "Web UI port", 8081);
#endif
  Logging::registerOptions(&conf);
  Slave::registerOptions(&conf);

  if (argc == 2 && string("--help") == argv[1]) {
    usage(argv[0], conf);
    exit(1);
  }

  Params params;
  try {
    params = conf.load(argc, argv, true);
  } catch (ConfigurationException& e) {
    cerr << "Configuration error: " << e.what() << endl;
    exit(1);
  }

  Logging::init(argv[0], params);

  if (!params.contains("url")) {
    cerr << "Master URL argument (--url) required." << endl;
    exit(1);
  }
  string url = params["url"];

  string isolation = params["isolation"];
  LOG(INFO) << "Creating \"" << isolation << "\" isolation module";
  IsolationModule *isolationModule = IsolationModule::create(isolation);

  if (isolationModule == NULL) {
    cerr << "Unrecognized isolation type: " << isolation << endl;
    exit(1);
  }

  LOG(INFO) << "Build: " << BUILD_DATE << " by " << BUILD_USER;
  LOG(INFO) << "Starting Mesos slave";

  if (chdir(dirname(argv[0])) != 0)
    fatalerror("Could not chdir into %s", dirname(argv[0]));

  Slave* slave = new Slave(params, false, isolationModule);
  PID pid = Process::spawn(slave);

  bool quiet = Logging::isQuiet(params);
  MasterDetector *detector = MasterDetector::create(url, pid, false, quiet);

#ifdef MESOS_WEBUI
  startSlaveWebUI(pid, params);
#endif

  Process::wait(pid);

  MasterDetector::destroy(detector);

  IsolationModule::destroy(isolationModule);

  delete slave;

  return 0;
}
Example #18
0
int main(int argc, char** argv)
{
  GOOGLE_PROTOBUF_VERIFY_VERSION;

  Configurator configurator;

  // The following options are executable specific (e.g., since we
  // only have one instance of libprocess per execution, we only want
  // to advertise the port and ip option once, here).
  configurator.addOption<int>("port", 'p', "Port to listen on", 5050);
  configurator.addOption<string>("ip", "IP address to listen on");
#ifdef MESOS_WEBUI
  configurator.addOption<int>("webui_port", "Web UI port", 8080);
#endif
  configurator.addOption<string>(
      "master",
      'm',
      "May be one of:\n"
      "  host:port\n"
      "  zk://host1:port1,host2:port2,.../path\n"
      "  zk://username:password@host1:port1,host2:port2,.../path\n"
      "  file://path/to/file (where file contains one of the above)");

  if (argc == 2 && string("--help") == argv[1]) {
    usage(argv[0], configurator);
    exit(1);
  }

  Configuration conf;
  try {
    conf = configurator.load(argc, argv);
  } catch (const ConfigurationException& e) {
    cerr << "Configuration error: " << e.what() << endl;
    exit(1);
  }

  // Initialize libprocess.
  process::initialize();

  if (!conf.contains("master")) {
    cerr << "Missing required option --master (-m)" << endl;
    usage(argv[0], configurator);
    exit(1);
  }

  // TODO(vinod): Parse 'master' when we add ZooKeeper support.
  UPID master(conf["master"]);

  if (!master) {
    cerr << "Could not parse --master=" << conf["master"] << endl;
    usage(argv[0], configurator);
    exit(1);
  }

  if (!conf.contains("name")) {
    // TODO(benh): Need to add '--name' as an option.
    cerr << "Missing --name (-n)" << endl;
    usage(argv[0], configurator);
    exit(1);
  }

  LOG(INFO) << "Submitting scheduler ...";

  Protocol<SubmitSchedulerRequest, SubmitSchedulerResponse> submit;

  SubmitSchedulerRequest request;
  request.set_name(conf["name"]);

  Future<SubmitSchedulerResponse> future = submit(master, request);

  future.await(5.0);

  if (future.isReady()) {
    if (future.get().okay()) {
      cout << "Scheduler submitted successfully" << endl;
    } else {
      cout << "Failed to submit scheduler" << endl;
    }
  } else {
    cout << "Timed out waiting for response from submitting scheduler" << endl;
  }

  return 0;
}
Example #19
0
int main(int argc, char** argv)
{
  GOOGLE_PROTOBUF_VERIFY_VERSION;

  Configurator configurator;
  Logging::registerOptions(&configurator);
  Slave::registerOptions(&configurator);

  // The following options are executable specific (e.g., since we
  // only have one instance of libprocess per execution, we only want
  // to advertise the port and ip option once, here).
  configurator.addOption<int>("port", 'p', "Port to listen on", 0);
  configurator.addOption<string>("ip", "IP address to listen on");
  configurator.addOption<string>("isolation", "Isolation module", "process");
#ifdef MESOS_WEBUI
  configurator.addOption<int>("webui_port", "Web UI port", 8081);
#endif
  configurator.addOption<string>(
      "master",
      'm',
      "May be one of:\n"
      "  host:port\n"
      "  zk://host1:port1,host2:port2,.../path\n"
      "  zk://username:password@host1:port1,host2:port2,.../path\n"
      "  file://path/to/file (where file contains one of the above)");

  if (argc == 2 && string("--help") == argv[1]) {
    usage(argv[0], configurator);
    exit(1);
  }

  Configuration conf;
  try {
    conf = configurator.load(argc, argv);
  } catch (ConfigurationException& e) {
    cerr << "Configuration error: " << e.what() << endl;
    exit(1);
  }

  Logging::init(argv[0], conf);

  if (conf.contains("port")) {
    setenv("LIBPROCESS_PORT", conf["port"].c_str(), 1);
  }

  if (conf.contains("ip")) {
    setenv("LIBPROCESS_IP", conf["ip"].c_str(), 1);
  }

  // Initialize libprocess library (but not glog, done above).
  process::initialize(false);

  if (!conf.contains("master")) {
    cerr << "Missing required option --master (-m)" << endl;
    exit(1);
  }

  string master = conf["master"];

  string isolation = conf["isolation"];
  LOG(INFO) << "Creating \"" << isolation << "\" isolation module";
  IsolationModule* isolationModule = IsolationModule::create(isolation);

  if (isolationModule == NULL) {
    cerr << "Unrecognized isolation type: " << isolation << endl;
    exit(1);
  }

  LOG(INFO) << "Build: " << build::DATE << " by " << build::USER;
  LOG(INFO) << "Starting Mesos slave";

  if (chdir(dirname(argv[0])) != 0) {
    fatalerror("Could not chdir into %s", dirname(argv[0]));
  }

  Slave* slave = new Slave(conf, false, isolationModule);
  process::spawn(slave);

  Try<MasterDetector*> detector =
    MasterDetector::create(master, slave->self(), false, Logging::isQuiet(conf));

  CHECK(detector.isSome())
    << "Failed to create a master detector: " << detector.error();

#ifdef MESOS_WEBUI
  webui::start(slave->self(), conf);
#endif

  process::wait(slave->self());
  delete slave;

  MasterDetector::destroy(detector.get());
  IsolationModule::destroy(isolationModule);

  return 0;
}
Example #20
0
int main(int argc, char** argv)
{
  GOOGLE_PROTOBUF_VERIFY_VERSION;

  Configurator configurator;

  logging::registerOptions(&configurator);

  // We log to stderr by default, but when running tests we'd prefer
  // less junk to fly by, so force one to specify the verbosity.
  configurator.addOption<bool>(
      "verbose",
      'v',
      "Log all severity levels to stderr (default: serverity above ERROR)",
      false);

  configurator.addOption<bool>(
      "help",
      'h',
      "Prints this usage message");

  Configuration conf;
  try {
    conf = configurator.load(argc, argv);
  } catch (const ConfigurationException& e) {
    cerr << "Configuration error: " << e.what() << endl;
    exit(1);
  }

  if (conf.contains("help")) {
    usage(argv[0], configurator);
    cerr << endl;
    testing::InitGoogleTest(&argc, argv); // Get usage from gtest too.
    exit(1);
  }

  // Initialize libprocess.
  process::initialize();

  // Be quiet by default!
  conf.set("quiet", !conf.get("verbose", false));

  // Initialize logging.
  logging::initialize(argv[0], conf);

  // Initialize gmock/gtest.
  testing::InitGoogleTest(&argc, argv);
  testing::FLAGS_gtest_death_test_style = "threadsafe";

  // Get the absolute path to the source (i.e., root) directory.
  Try<string> path = utils::os::realpath(SOURCE_DIR);
  CHECK(path.isSome()) << "Error getting source directory " << path.error();
  mesosSourceDirectory = path.get();

  std::cout << "Source directory: " << mesosSourceDirectory << std::endl;

  // Get absolute path to the build directory.
  path = utils::os::realpath(BUILD_DIR);
  CHECK(path.isSome()) << "Error getting build directory " << path.error();
  mesosBuildDirectory = path.get();

  std::cout << "Build directory: " << mesosBuildDirectory << std::endl;

  // Clear any MESOS_ environment variables so they don't affect our tests.
  Configurator::clearMesosEnvironmentVars();

  return RUN_ALL_TESTS();
}