/** * Parse command line arguments and create TANG configuration ready to be submitted to REEF. * * @param args Command line arguments, as passed into main(). * @return (immutable) TANG Configuration object. * @throws BindException if configuration commandLineInjector fails. * @throws InjectionException if configuration commandLineInjector fails. * @throws IOException error reading the configuration. */ private static Configuration getClientConfiguration(final String[] args) throws BindException, InjectionException, IOException { final Configuration commandLineConf = parseCommandLine(args); final Configuration clientConfiguration = ClientConfiguration.CONF .set(ClientConfiguration.ON_JOB_RUNNING, SuspendClient.RunningJobHandler.class) .set(ClientConfiguration.ON_JOB_FAILED, SuspendClient.FailedJobHandler.class) .set(ClientConfiguration.ON_JOB_COMPLETED, SuspendClient.CompletedJobHandler.class) .set(ClientConfiguration.ON_RUNTIME_ERROR, SuspendClient.RuntimeErrorHandler.class) .build(); final Injector commandLineInjector = Tang.Factory.getTang().newInjector(commandLineConf); final boolean isLocal = commandLineInjector.getNamedInstance(Local.class); final Configuration runtimeConfiguration; if (isLocal) { LOG.log(Level.INFO, "Running on the local runtime"); runtimeConfiguration = LocalRuntimeConfiguration.CONF .set(LocalRuntimeConfiguration.MAX_NUMBER_OF_EVALUATORS, MAX_NUMBER_OF_EVALUATORS) .build(); } else { LOG.log(Level.INFO, "Running on YARN"); runtimeConfiguration = YarnClientConfiguration.CONF.build(); } return Configurations.merge( runtimeConfiguration, clientConfiguration, cloneCommandLineConfiguration(commandLineConf)); }
/** * Writes driver configuration to disk. * * @param jobFolder The folder in which the job is staged. * @param jobId id of the job to be submitted * @param clientRemoteId The client remote id * @return the configuration * @throws IOException */ public Configuration writeConfiguration( final File jobFolder, final String jobId, final String clientRemoteId) throws IOException { final File driverFolder = new File(jobFolder, PreparedDriverFolderLauncher.DRIVER_FOLDER_NAME); final Configuration driverConfiguration1 = driverConfigurationProvider.getDriverConfiguration( jobFolder.toURI(), clientRemoteId, jobId, Constants.DRIVER_CONFIGURATION_WITH_HTTP_AND_NAMESERVER); final ConfigurationBuilder configurationBuilder = Tang.Factory.getTang().newConfigurationBuilder(); for (final ConfigurationProvider configurationProvider : this.configurationProviders) { configurationBuilder.addConfiguration(configurationProvider.getConfiguration()); } final Configuration providedConfigurations = configurationBuilder.build(); final Configuration driverConfiguration = Configurations.merge( driverConfiguration1, Tang.Factory.getTang() .newConfigurationBuilder() .bindNamedParameter(JobSubmissionDirectory.class, driverFolder.toString()) .build(), providedConfigurations); final File driverConfigurationFile = new File(driverFolder, fileNames.getDriverConfigurationPath()); configurationSerializer.toFile(driverConfiguration, driverConfigurationFile); return driverConfiguration; }
/** * Main method that runs the example. * * @param args command line parameters. */ public static void main(final String[] args) { try { final Configuration config = getClientConfiguration(args); LOG.log(Level.INFO, "Configuration:\n--\n{0}--", Configurations.toString(config, true)); final Injector injector = Tang.Factory.getTang().newInjector(config); final SuspendClient client = injector.getInstance(SuspendClient.class); client.submit(); client.waitForCompletion(); LOG.info("Done!"); } catch (final BindException | IOException | InjectionException ex) { LOG.log(Level.SEVERE, "Cannot launch: configuration error", ex); } catch (final Exception ex) { LOG.log(Level.SEVERE, "Cleanup error", ex); } }