Java Code Examples for org.apache.reef.tang.Tang#newConfigurationBuilder()

The following examples show how to use org.apache.reef.tang.Tang#newConfigurationBuilder() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OutputServiceREEF.java    From reef with Apache License 2.0 6 votes vote down vote up
public static void main(final String[] args)
    throws InjectionException, BindException, IOException {

  final Tang tang = Tang.Factory.getTang();
  final JavaConfigurationBuilder cb = tang.newConfigurationBuilder();
  new CommandLine(cb)
      .registerShortNameOfClass(Local.class)
      .registerShortNameOfClass(TimeOut.class)
      .registerShortNameOfClass(OutputDir.class)
      .processCommandLine(args);

  final Injector injector = tang.newInjector(cb.build());
  final boolean isLocal = injector.getNamedInstance(Local.class);
  final String outputDir = injector.getNamedInstance(OutputDir.class);
  final int jobTimeout = injector.getNamedInstance(TimeOut.class) * 60 * 1000;

  final Configuration driverConf = getDriverConf();
  final Configuration outputServiceConf = getOutputServiceConf(isLocal, outputDir);
  final Configuration submittedConfiguration = Tang.Factory.getTang()
      .newConfigurationBuilder(driverConf, outputServiceConf)
      .build();
  final LauncherStatus state = DriverLauncher.getLauncher(getRuntimeConf(isLocal))
      .run(submittedConfiguration, jobTimeout);

  LOG.log(Level.INFO, "REEF job completed: {0}", state);
}
 
Example 2
Source File: Timer.java    From reef with Apache License 2.0 6 votes vote down vote up
public static void main(final String[] args) throws Exception {
  final Tang tang = Tang.Factory.getTang();
  final JavaConfigurationBuilder cb = tang.newConfigurationBuilder();
  final CommandLine cl = new CommandLine(cb);
  cl.registerShortNameOfClass(Timer.Seconds.class);
  cl.processCommandLine(args);
  final Configuration conf = cb.build();
  System.out.println("start conf");
  final AvroConfigurationSerializer avroSerializer = new AvroConfigurationSerializer();
  System.out.println(avroSerializer.toString(conf));
  System.out.println("end conf");
  final InjectorImpl injector = (InjectorImpl) tang.newInjector(conf);
  final InjectionPlan<Timer> ip = injector.getInjectionPlan(Timer.class);
  System.out.println(ip.toPrettyString());
  System.out.println("Number of plans:" + ip.getNumAlternatives());
  final Timer timer = injector.getInstance(Timer.class);
  System.out.println("Tick...");
  timer.sleep();
  System.out.println("Tock.");
}
 
Example 3
Source File: TestParameterParser.java    From reef with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void testDelegatingParser() throws BindException, InjectionException, ClassNotFoundException {
  final Tang tang = Tang.Factory.getTang();
  final JavaConfigurationBuilder cb = tang.newConfigurationBuilder(TypeParser.class);

  JavaConfigurationBuilder cb2 = tang.newConfigurationBuilder(cb.build());

  cb2.bind(ReflectionUtilities.getFullName(ParseName.class), "a");

  final ParseableType t = tang.newInjector(cb2.build()).getNamedInstance(ParseName.class);
  Assert.assertTrue(t instanceof ParseTypeA);

  cb2 = tang.newConfigurationBuilder(cb.build());

  cb2.bind(ReflectionUtilities.getFullName(ParseNameB.class), "b");
  cb2.bindNamedParameter(ParseNameA.class, "a");
  tang.newInjector(cb2.build()).getInstance(NeedsA.class);
  tang.newInjector(cb2.build()).getInstance(NeedsB.class);

}
 
Example 4
Source File: SpoolFileTest.java    From reef with Apache License 2.0 5 votes vote down vote up
@Test
public void testRam() throws BindException, InjectionException, ServiceException, IOException {
  final Tang t = Tang.Factory.getTang();
  final ConfigurationBuilder configurationBuilderOne = t.newConfigurationBuilder(RamConf.CONF.build());

  final AvroConfigurationSerializer avroSerializer = new AvroConfigurationSerializer();
  final String serializedConfiguration = avroSerializer.toString(configurationBuilderOne.build());
  final ConfigurationBuilder configurationBuilderTwo =
      t.newConfigurationBuilder(avroSerializer.fromString(serializedConfiguration));

  @SuppressWarnings("unchecked")
  final Spool<Integer> f = (Spool<Integer>) t.newInjector(configurationBuilderTwo.build()).getInstance(
      Spool.class);
  test(f);
}
 
Example 5
Source File: HelloREEFStandalone.java    From reef with Apache License 2.0 5 votes vote down vote up
/**
 * Start Hello REEF job.
 *
 * @param args command line parameters.
 * @throws BindException      configuration error.
 * @throws InjectionException configuration error.
 */
public static void main(final String[] args) throws BindException, InjectionException {

  final Tang tang = Tang.Factory.getTang();

  final JavaConfigurationBuilder cb = tang.newConfigurationBuilder();

  try{
    new CommandLine(cb)
        .registerShortNameOfClass(NodeListFilePath.class)
        .registerShortNameOfClass(SshPortNum.class)
        .processCommandLine(args);
  } catch(final IOException ex) {
    LOG.log(Level.SEVERE, "Missing parameter 'nodelist' or wrong parameter input.");
    throw new RuntimeException("Missing parameter 'nodelist' or wrong parameter input: ", ex);
  }

  final Injector injector = tang.newInjector(cb.build());

  final String nodeListFilePath = injector.getNamedInstance(NodeListFilePath.class);
  final int sshPortNum = injector.getNamedInstance(SshPortNum.class);

  final Configuration runtimeConf = getRuntimeConfiguration(nodeListFilePath, sshPortNum);
  final Configuration driverConf = getDriverConfiguration();

  final LauncherStatus status = DriverLauncher
      .getLauncher(runtimeConf)
      .run(driverConf, JOB_TIMEOUT);
  LOG.log(Level.INFO, "REEF job completed: {0}", status);
}
 
Example 6
Source File: PrintTypeHierarchy.java    From reef with Apache License 2.0 5 votes vote down vote up
/**
 * @param args command line arguments.
 * @throws BindException      configuration error.
 * @throws InjectionException configuration error.
 * @throws IOException        cannot process command line parameters.
 */
public static void main(final String[] args)
    throws BindException, InjectionException, IOException {

  final Tang tang = Tang.Factory.getTang();
  final ConfigurationBuilder confBuilder = tang.newConfigurationBuilder();

  new CommandLine(confBuilder).processCommandLine(args);
  final Configuration config = confBuilder.build();

  final Injector injector = tang.newInjector(config);
  final PrintTypeHierarchy myself = injector.getInstance(PrintTypeHierarchy.class);

  try (Writer out = new OutputStreamWriter(
          new FileOutputStream("type-hierarchy.dot"), StandardCharsets.UTF_8)) {
    out.write(GraphvizConfigVisitor.getGraphvizString(config, true, true));
  }

  final InjectionPlan<PrintTypeHierarchy> plan =
      injector.getInjectionPlan(PrintTypeHierarchy.class);

  try (Writer out = new OutputStreamWriter(
          new FileOutputStream("injection-plan.dot"), StandardCharsets.UTF_8)) {
    out.write(GraphvizInjectionPlanVisitor.getGraphvizString(plan, true));
  }

  System.out.println(myself);
}
 
Example 7
Source File: TimerV1.java    From reef with Apache License 2.0 5 votes vote down vote up
public static void main(final String[] args) throws BindException, InjectionException {
  final Tang tang = Tang.Factory.getTang();
  final JavaConfigurationBuilder cb = tang.newConfigurationBuilder();
  final Configuration conf = cb.build();
  final Injector injector = tang.newInjector(conf);
  final TimerV1 timer = injector.getInstance(TimerV1.class);

  try {
    System.out.println("Tick...");
    timer.sleep();
    System.out.println("Tock.");
  } catch (final InterruptedException e) {
    e.printStackTrace();
  }
}
 
Example 8
Source File: TestParameterParser.java    From reef with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void testEndToEnd() throws BindException, InjectionException {
  final Tang tang = Tang.Factory.getTang();
  final JavaConfigurationBuilder cb = tang.newConfigurationBuilder(BarParser.class);
  cb.bindNamedParameter(SomeNamedFoo.class, "hdfs://woot");
  final ILikeBars ilb = tang.newInjector(cb.build()).getInstance(ILikeBars.class);
  Assert.assertNotNull(ilb);
}
 
Example 9
Source File: DataLoadingREEF.java    From reef with Apache License 2.0 4 votes vote down vote up
public static void main(final String[] args)
    throws InjectionException, BindException, IOException {

  final Tang tang = Tang.Factory.getTang();

  final JavaConfigurationBuilder cb = tang.newConfigurationBuilder();

  new CommandLine(cb)
      .registerShortNameOfClass(Local.class)
      .registerShortNameOfClass(TimeOut.class)
      .registerShortNameOfClass(DataLoadingREEF.InputDir.class)
      .processCommandLine(args);

  final Injector injector = tang.newInjector(cb.build());

  final boolean isLocal = injector.getNamedInstance(Local.class);
  final int jobTimeout = injector.getNamedInstance(TimeOut.class) * 60 * 1000;
  final String inputDir = injector.getNamedInstance(DataLoadingREEF.InputDir.class);

  final Configuration runtimeConfiguration;
  if (isLocal) {
    LOG.log(Level.INFO, "Running Data Loading demo on the local runtime");
    runtimeConfiguration = LocalRuntimeConfiguration.CONF
        .set(LocalRuntimeConfiguration.MAX_NUMBER_OF_EVALUATORS, MAX_NUMBER_OF_EVALUATORS)
        .build();
  } else {
    LOG.log(Level.INFO, "Running Data Loading demo on YARN");
    runtimeConfiguration = YarnClientConfiguration.CONF.build();
  }

  final EvaluatorRequest computeRequest = EvaluatorRequest.newBuilder()
      .setNumber(NUM_COMPUTE_EVALUATORS)
      .setMemory(512)
      .setNumberOfCores(1)
      .build();

  final EvaluatorRequest dataRequest = EvaluatorRequest.newBuilder()
      .setMemory(512)
      .setNumberOfCores(1)
      .build();

  final Configuration dataLoadConfiguration = new DataLoadingRequestBuilder()
      .setInputFormatClass(TextInputFormat.class)
      .setInputPath(inputDir)
      .setNumberOfDesiredSplits(NUM_SPLITS)
      .addComputeRequest(computeRequest)
      .addDataRequest(dataRequest)
      .setDriverConfigurationModule(DriverConfiguration.CONF
          .set(DriverConfiguration.GLOBAL_LIBRARIES, EnvironmentUtils.getClassLocation(LineCounter.class))
          .set(DriverConfiguration.ON_CONTEXT_ACTIVE, LineCounter.ContextActiveHandler.class)
          .set(DriverConfiguration.ON_TASK_COMPLETED, LineCounter.TaskCompletedHandler.class)
          .set(DriverConfiguration.DRIVER_IDENTIFIER, "DataLoadingREEF"))
      .build();

  final LauncherStatus state =
      DriverLauncher.getLauncher(runtimeConfiguration).run(dataLoadConfiguration, jobTimeout);

  LOG.log(Level.INFO, "REEF job completed: {0}", state);
}