public static void main ( String [ ] args ) throws Exception { CommandLineParser parser = new DefaultParser ( ) ; Options slaManagerCliOptions = constructCliOptions ( ) ; // parse the help options first. Options helpOptions = constructHelpOptions ( ) ; CommandLine cmd = parser . parse ( helpOptions , args , true ) ; if ( cmd . hasOption ( "h" ) ) { usage ( slaManagerCliOptions ) ; return ; } try { cmd = parser . parse ( slaManagerCliOptions , args ) ; } catch ( ParseException e ) { usage ( slaManagerCliOptions ) ; throw new RuntimeException ( "Error parsing command line options: " , e ) ; } DownloaderMode mode = DownloaderMode . cluster ; if ( cmd . hasOption ( CliArgs . MODE . text ) ) { mode = DownloaderMode . valueOf ( cmd . getOptionValue ( CliArgs . MODE . text , null ) ) ; } Config config ; switch ( mode ) { case cluster : config = Config . toClusterMode ( Config . newBuilder ( ) . putAll ( ConfigLoader . loadClusterConfig ( ) ) . build ( ) ) ; break ; case local : if ( ! cmd . hasOption ( CliArgs . HERON_HOME . text ) || ! cmd . hasOption ( CliArgs . CONFIG_PATH . text ) ) { throw new IllegalArgumentException ( "Missing heron_home or config_path argument" ) ; } String heronHome = cmd . getOptionValue ( CliArgs . HERON_HOME . text , null ) ; String configPath = cmd . getOptionValue ( CliArgs . CONFIG_PATH . text , null ) ; config = Config . toLocalMode ( Config . newBuilder ( ) . putAll ( ConfigLoader . loadConfig ( heronHome , configPath , null , null ) ) . build ( ) ) ; break ; default : throw new IllegalArgumentException ( "Invalid mode: " + cmd . getOptionValue ( CliArgs . MODE . text ) ) ; } String uri = cmd . getOptionValue ( CliArgs . TOPOLOGY_PACKAGE_URI . text , null ) ; String destination = cmd . getOptionValue ( CliArgs . EXTRACT_DESTINATION . text , null ) ; // make it compatible with old param format if ( uri == null && destination == null ) { String [ ] leftOverArgs = cmd . getArgs ( ) ; if ( leftOverArgs . length != 2 ) { System . err . println ( "Usage: downloader <topology-package-uri> <extract-destination>" ) ; return ; } uri = leftOverArgs [ 0 ] ; destination = leftOverArgs [ 1 ] ; } final URI topologyLocation = new URI ( uri ) ; final Path topologyDestination = Paths . get ( destination ) ; final File file = topologyDestination . toFile ( ) ; if ( ! file . exists ( ) ) { file . mkdirs ( ) ; } Class clazz = Registry . UriToClass ( config , topologyLocation ) ; final Downloader downloader = Registry . getDownloader ( clazz , topologyLocation ) ; downloader . download ( topologyLocation , topologyDestination ) ; }
takes topology package URI and extracts it to a directory