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

The following examples show how to use org.apache.reef.tang.Tang#newInjector() . 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: TestReefEventStateManager.java    From reef with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws InjectionException {
  final Tang tang = Tang.Factory.getTang();

  final Configuration configuration = tang.newConfigurationBuilder()
      .bindImplementation(EvaluatorDescriptor.class, MockEvaluatorDescriptor.class)
      .bindImplementation(NodeDescriptor.class, MockNodeDescriptor.class)
      .bindImplementation(EvaluatorProcessFactory.class, CLRProcessFactory.class)
      .bindNamedParameter(RemoteConfiguration.ManagerName.class, "REEF_TEST_REMOTE_MANAGER")
      .bindNamedParameter(RemoteConfiguration.MessageCodec.class, REEFMessageCodec.class)
      .bindNamedParameter(JobIdentifier.class, "my job")
      .build();

  injector = tang.newInjector(configuration);
  reefEventStateManager = injector.getInstance(ReefEventStateManager.class);
}
 
Example 3
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 4
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 5
Source File: ProtocolSerializerTest.java    From reef with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() throws InjectionException {

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

  final Configuration config = tang.newConfigurationBuilder()
      .bindNamedParameter(ProtocolSerializerNamespace.class, "org.apache.reef.wake.test.avro.message")
      .build();

  final Injector injector = tang.newInjector(config);

  remoteManagerFactory = injector.getInstance(RemoteManagerFactory.class);
  serializer = injector.getInstance(ProtocolSerializer.class);
}
 
Example 6
Source File: TestJettyHandler.java    From reef with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws InjectionException, IOException, ServletException {

  this.request = new Request(
      new HttpConnection(new LocalConnector(), new StringEndPoint(), new Server()));

  this.request.setContentType("text/json");

  this.response = new Response(
      new HttpConnection(new LocalConnector(), new StringEndPoint(), new Server()));

  final Configuration httpHandlerConfiguration = HttpHandlerConfiguration.CONF
      .set(HttpHandlerConfiguration.HTTP_HANDLERS, HttpServerReefEventHandler.class)
      .build();

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

  final Configuration remoteConfiguration = tang.newConfigurationBuilder()
      .bindNamedParameter(RemoteConfiguration.ManagerName.class, "REEF_TEST_REMOTE_MANAGER")
      .bindNamedParameter(RemoteConfiguration.MessageCodec.class, REEFMessageCodec.class)
      .bindNamedParameter(JobIdentifier.class, "my job")
      .build();

  final Configuration finalConfig =
      Configurations.merge(httpHandlerConfiguration, remoteConfiguration);

  final Injector injector = tang.newInjector(finalConfig);

  this.handler = injector.getInstance(JettyHandler.class);
}
 
Example 7
Source File: TestReefEventHandler.java    From reef with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws InjectionException, IOException, ServletException {

  this.request = new Request(
      new HttpConnection(new LocalConnector(), new StringEndPoint(), new Server()));

  this.request.setContentType("text/json");

  this.response = new Response(
      new HttpConnection(new LocalConnector(), new StringEndPoint(), new Server()));

  final Configuration httpHandlerConfiguration = HttpHandlerConfiguration.CONF
      .set(HttpHandlerConfiguration.HTTP_HANDLERS, HttpServerReefEventHandler.class)
      .build();

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

  final Configuration remoteConfiguration = tang.newConfigurationBuilder()
      .bindNamedParameter(RemoteConfiguration.ManagerName.class, "REEF_TEST_REMOTE_MANAGER")
      .bindNamedParameter(RemoteConfiguration.MessageCodec.class, REEFMessageCodec.class)
      .bindNamedParameter(JobIdentifier.class, "my job")
      .build();

  final Configuration finalConfig =
      Configurations.merge(httpHandlerConfiguration, remoteConfiguration);

  final Injector injector = tang.newInjector(finalConfig);

  this.handler = injector.getInstance(JettyHandler.class);
}
 
Example 8
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 9
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 10
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);
}