Example #1
0
File: main.cpp Project: cawka/NFD
static int
main(int argc, char** argv)
{
  Options options;
  bool isDaemon = false;
  std::string configFile;

  po::options_description optionsDescription("Options");
  optionsDescription.add_options()
    ("help,h", "print this message and exit")
    ("version,V", "show version information and exit")
    ("daemon,d", po::bool_switch(&isDaemon)->default_value(isDaemon),
     "Run in daemon mode, detecting network change events and re-running the auto-discovery procedure. "
     "In addition, the auto-discovery procedure is unconditionally re-run every hour.\n"
     "NOTE: if the connection to NFD fails, the daemon will exit.")
    ("ndn-fch-url", po::value<std::string>(&options.ndnFchUrl)->default_value(options.ndnFchUrl),
     "URL for NDN-FCH (Find Closest Hub) service")
    ("config,c", po::value<std::string>(&configFile),
     "Configuration file. Exit immediately unless 'enabled = true' is specified in the config file.")
    ;

  po::variables_map vm;
  try {
    po::store(po::parse_command_line(argc, argv, optionsDescription), vm);
    po::notify(vm);
  }
  catch (const std::exception& e) {
    std::cerr << "ERROR: " << e.what() << "\n\n";
    usage(std::cerr, optionsDescription, argv[0]);
    return 2;
  }

  if (vm.count("help")) {
    usage(std::cout, optionsDescription, argv[0]);
    return 0;
  }

  if (vm.count("version")) {
    std::cout << NFD_VERSION_BUILD_STRING << std::endl;
    return 0;
  }

  if (vm.count("config")) {
    po::options_description configFileOptions;
    configFileOptions.add_options()
      ("enabled", po::value<bool>()->default_value(false))
      ;
    try {
      po::store(po::parse_config_file<char>(configFile.data(), configFileOptions), vm);
      po::notify(vm);
    }
    catch (const std::exception& e) {
      std::cerr << "ERROR in config: " << e.what() << "\n\n";
      return 2;
    }
    if (!vm["enabled"].as<bool>()) {
      // not enabled in config
      return 0;
    }
  }

  int exitCode = 0;
  try {
    Face face;
    KeyChain keyChain;
    Procedure proc(face, keyChain);
    proc.initialize(options);

    if (isDaemon) {
      runDaemon(proc);
    }
    else {
      proc.onComplete.connect([&exitCode] (bool isSuccess) { exitCode = isSuccess ? 0 : 1; });
      proc.runOnce();
      face.processEvents();
    }
  }
  catch (const std::exception& e) {
    std::cerr << ::nfd::getExtendedErrorMessage(e) << std::endl;
    return 1;
  }

  return exitCode;
}
Example #2
0
int main(int argc, char* argv[]) {
    bool verbose = false;
    opt::options_description desc = optionsDescription();
    opt::variables_map vmap;
    opt::store(opt::parse_command_line(argc,argv,desc),vmap);
    opt::notify(vmap);
    
    if (vmap.count("help")) {
        std::cout << desc << "\n";
        return 1;
    }
    
    if(vmap.count("distribution")) {
        isingEnergyDistribution(vmap["dimension"].as<int>(),
                                vmap["clusters"].as<int>());
        exit(0);
    }
    
    verbose = vmap.count("verbose");
    
    size_t iterations = vmap["iterations"].as<size_t>();
    
    DemonBase::ReservoirFactory *rFactory = NULL;
    if ( vmap.count("ising") )  {
        if (!vmap.count("dimension")) {
            std::clog << "Option --ising requires -d\n";
            exit(1);
        }
        
        int dim = vmap["dimension"].as<int>();
        int clst = vmap["clusters"].as<int>();
        rFactory = new Ising::Reservoir::Factory(dim,clst);
    } else if ( vmap.count("tmgas") ){
        if (!vmap.count("dimension")) {
            std::clog << "Option --tmgas requires -d\n";
            exit(1);
        }
        
        int dim = vmap["dimension"].as<int>();
        rFactory = new TMGas::Reservoir::Factory(dim);
    } else {
        //Assume stochastic
        rFactory = new DemonBase::DefaultArgsReservoirFactory<Stochastic::Reservoir>;
    }
    
    DemonBase::SystemFactory *sFactory = new DemonBase::BinomialSystemFactory;
    
    assert(rFactory);
    assert(sFactory);
    
    int dimension = 50;
    const double tau = vmap["tau"].as<double>();
    
    mpi::environment env(argc, argv);
    mpi::communicator world;
    char hostname[256];
    int requester;
    
    if (world.rank()==0) {
        std::string args;
        for (int k=1; k!=argc; ++k) {
            args += " ";
            args += argv[k];
        }
        printf("%s%s\n",PACKAGE_STRING,args.c_str());
        std::clog << "Running v" << PACKAGE_VERSION << " on " << world.size()
                    << " nodes." << std::endl;
        std::clog << (double)(dimension*dimension*iterations)/world.size()
                    << " simulations per node." << std::endl;
        printf("%s\n",DemonBase::outputHeader().c_str());
    }
    
    world.barrier();
    
    gethostname(hostname,255);
    fprintf(stderr, "Hello world from host %s (rank %d)\n",hostname,world.rank());
    
    DemonBase::Experiment::range work;
    DemonBase::Experiment experiment;
    experiment.iterations = iterations;
    experiment.dimension = dimension;
    experiment.sfactory = sFactory;
    experiment.rfactory = rFactory;
    
    for (int k=world.rank(); k<dimension*dimension; k+=world.size()) {
        DemonBase::MeasurementResult result = experiment.performIteration(k);
        printf("%s\n",outputString(result).c_str());
    }
    
    std::clog<<"Rank "<< world.rank()<<" finished.\n";
    return 0;
}
Example #3
0
int main( int argc, char * argv [] )
{
	boost::program_options::options_description optionsDescription( "options" );
	optionsDescription.add_options()
		("help", "produce help message")
		("objectStoreRootPath", boost::program_options::value< std::string >()->default_value( "/var/lib/osmosis/objectstore" ),
			"Path where osmosis will store objects. relevant for 'server', 'purge', 'labellog' and 'leastrecentlyused' commands" )
		("serverTCPPort", boost::program_options::value< unsigned short >()->default_value( 1010 ),
			"the TCP port to bind to, if command is 'server'")
		( "objectStores", boost::program_options::value< std::string >()->default_value( "127.0.0.1:1010" ),
			"the object store to act againt. May be a '+' seperated list for 'checkout' command" )
		( "MD5", "use MD5, not SHA1 for hash in 'checkin' operation" )
		( "putIfMissing", "when command is 'checkout' or 'transfer', this flag will cause any objects received not from the "
		        "nearest object store to be put into all objects stores up to the one it was fetched from" )
		( "removeUnknownFiles", "for checkout: remove files from disk that are not in the dirlist being checked out" )
		( "myUIDandGIDcheckout", "for checkout: use my uid and gid" )
		( "ignore", boost::program_options::value< std::string >(),
			"for checkout: ignore the existance of all files in this ':' seperated list. "
			"if a directory was specified, ignored everything under it as well. specified paths "
			"must reside inside the checkout path" )
		( "transferDestination", boost::program_options::value< std::string >(),
			"destination object store to transfer the label into" )
		( "reportFile", boost::program_options::value< std::string >()->default_value( "" ),
			"periodically write report in JSON format into this file" )
		( "reportIntervalSeconds", boost::program_options::value< unsigned >()->default_value( 15 ),
			"period to report progress" )
		( "noChainTouch", "avoid touching fetched label in all object stores in chain (used for label bookeeping)" )
		( "keep", boost::program_options::value< std::string >()->default_value( "keepforever|bootstrap" ),
		  	"regular expression for labels to never erase. Only relevant under 'leastrecentlyused' command" )
		( "maximumDiskUsage", boost::program_options::value< std::string >(),
		  	"<number>M or <number>G for the amount of storage used for label objects before 'leastrecentlyused' starts erasing labels");

	boost::program_options::options_description positionalDescription( "positionals" );
	positionalDescription.add_options()
		( "command", boost::program_options::value< std::string >() )
		( "arg1", boost::program_options::value< std::string >() )
		( "arg2", boost::program_options::value< std::string >() );

	boost::program_options::positional_options_description positionalMapping;
	positionalMapping.add( "command", 1 ).add( "arg1", 1 ).add( "arg2", 1 );

	boost::program_options::options_description allOptions;
	allOptions.add( optionsDescription ).add( positionalDescription );

	boost::program_options::variables_map options;
	try {
		boost::program_options::store(
			boost::program_options::command_line_parser( argc, argv ).
				positional( positionalMapping ).options( allOptions ).
				run(),
			options );
		boost::program_options::notify( options );
	} catch ( boost::exception & e ) {
		TRACE_BOOST_EXCEPTION( e, "Unable to parse command line" );
		usage( optionsDescription );
		return 1;
	}

	if ( options.count( "help" ) ) {
		usage( optionsDescription );
		return 1;
	}

	try {
		std::string command = options[ "command" ].as< std::string >();
		if ( command == "server" ) {
			if ( options.count( "arg1" ) > 0 or options.count( "arg2" ) > 0 ) {
				TRACE_ERROR( "'workDir' or 'label' must not be present in command line"
						"if 'server' is specified as the command" );
				usage( optionsDescription );
				return 1;
			}
			server( options );
		} else if ( command == "checkin" )
			checkIn( options );
		else if ( command == "checkout" )
			checkOut( options );
		else if ( command == "transfer" )
			transfer( options );
		else if ( command == "listlabels" )
			listLabels( options );
		else if ( command == "eraselabel" )
			eraseLabel( options );
		else if ( command == "purge" )
			purge( options );
		else if ( command == "renamelabel" )
			renameLabel( options );
		else if ( command == "labellog" )
			dumpLabelLog( options );
		else if ( command == "leastrecentlyused" )
			leastRecentlyUsed( options );
		else if ( command == "testhash" )
			testHash( options );
		else {
			TRACE_ERROR( "Unknown command '" << command << "'" );
			usage( optionsDescription );
			return 1;
		}
	} catch ( boost::exception & e ) {
		TRACE_BOOST_EXCEPTION( e, "Terminated on a boost exception" );
		return 1;
	} catch ( Error & e ) {
		TRACE_ERROR( "Terminated on 'Error' exception: '" << e.what() << "' from " << e.backtrace() );
		return 1;
	} catch ( std::exception & e ) {
		TRACE_ERROR( "Terminated on std::exception: '" << e.what() );
		return 1;
	} catch ( ... ) {
		TRACE_ERROR( "Terminated on unknown exception" );
		return 1;
	}

	return 0;
}