org.apache.reef.tang.Injector Java Examples

The following examples show how to use org.apache.reef.tang.Injector. 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: NameRegistryClient.java    From reef with Apache License 2.0 6 votes vote down vote up
/**
 * Constructs a naming registry client.
 *
 * @param serverAddr a name server address
 * @param serverPort a name server port
 * @param timeout    timeout in ms
 * @param factory    an identifier factory
 */
NameRegistryClient(final String serverAddr,
                          final int serverPort,
                          final long timeout,
                          final IdentifierFactory factory,
                          final LocalAddressProvider localAddressProvider) {

  this.serverSocketAddr = new InetSocketAddress(serverAddr, serverPort);
  this.timeout = timeout;
  this.codec = NamingCodecFactory.createRegistryCodec(factory);
  this.replyQueue = new LinkedBlockingQueue<>();

  final Injector injector = Tang.Factory.getTang().newInjector();
  injector.bindVolatileParameter(RemoteConfiguration.HostAddress.class, localAddressProvider.getLocalAddress());
  injector.bindVolatileParameter(RemoteConfiguration.RemoteClientStage.class,
      new SyncStage<>(new NamingRegistryClientHandler(new NamingRegistryResponseHandler(replyQueue), codec)));

  try {
    this.transport = injector.getInstance(NettyMessagingTransport.class);
  } catch (final InjectionException e) {
    throw new RuntimeException(e);
  }
}
 
Example #3
Source File: CompilerTestUtil.java    From incubator-nemo with Apache License 2.0 6 votes vote down vote up
private static IRDAG compileDAG(final String[] args) throws Exception {
  final String userMainClassName;
  final String[] userMainMethodArgs;

  try {
    final Configuration configuration = JobLauncher.getJobConf(args);
    final Injector injector = Tang.Factory.getTang().newInjector(configuration);
    userMainClassName = injector.getNamedInstance(JobConf.UserMainClass.class);
    userMainMethodArgs = injector.getNamedInstance(JobConf.UserMainArguments.class).split(" ");
  } catch (final Exception e) {
    throw new RuntimeException("An exception occurred while processing configuration for invoking user main. "
      + "Note: Using compileDAG for multiple times will fail, as compileDAG method enables static method mocking "
      + "on JobLauncher and because of this Tang may misbehave afterwards.", e);
  }
  final Class userMainClass = Class.forName(userMainClassName);
  final Method userMainMethod = userMainClass.getMethod("main", String[].class);

  final ArgumentCaptor<IRDAG> captor = ArgumentCaptor.forClass(IRDAG.class);
  final ArgumentCaptor<String> stringArg = ArgumentCaptor.forClass(String.class);
  PowerMockito.mockStatic(JobLauncher.class);
  PowerMockito.doNothing().when(JobLauncher.class, "launchDAG", captor.capture(), stringArg.capture());
  userMainMethod.invoke(null, (Object) userMainMethodArgs);
  return captor.getValue();
}
 
Example #4
Source File: NetworkMessagingTestService.java    From reef with Apache License 2.0 6 votes vote down vote up
public NetworkMessagingTestService(final String localAddress) throws InjectionException {
  // name server
  final Injector injector = Tang.Factory.getTang().newInjector();
  this.nameServer = injector.getInstance(NameServer.class);
  final Configuration netConf = NameResolverConfiguration.CONF
      .set(NameResolverConfiguration.NAME_SERVER_HOSTNAME, localAddress)
      .set(NameResolverConfiguration.NAME_SERVICE_PORT, nameServer.getPort())
      .build();

  LOG.log(Level.FINEST, "=== Test network connection service receiver start");
  // network service for receiver
  final Injector injectorReceiver = injector.forkInjector(netConf);
  this.receiverNetworkConnService = injectorReceiver.getInstance(NetworkConnectionService.class);
  this.factory = injectorReceiver.getNamedInstance(NetworkConnectionServiceIdFactory.class);

  // network service for sender
  LOG.log(Level.FINEST, "=== Test network connection service sender start");
  final Injector injectorSender = injector.forkInjector(netConf);
  senderNetworkConnService = injectorSender.getInstance(NetworkConnectionService.class);
}
 
Example #5
Source File: DataTransferTest.java    From incubator-nemo with Apache License 2.0 6 votes vote down vote up
private Injector createNameClientInjector() {
  try {
    final Configuration configuration = TANG.newConfigurationBuilder()
      .bindImplementation(IdentifierFactory.class, StringIdentifierFactory.class)
      .build();
    final Injector injector = TANG.newInjector(configuration);
    final LocalAddressProvider localAddressProvider = injector.getInstance(LocalAddressProvider.class);
    final NameServer nameServer = injector.getInstance(NameServer.class);
    final Configuration nameClientConfiguration = NameResolverConfiguration.CONF
      .set(NameResolverConfiguration.NAME_SERVER_HOSTNAME, localAddressProvider.getLocalAddress())
      .set(NameResolverConfiguration.NAME_SERVICE_PORT, nameServer.getPort())
      .build();
    return injector.forkInjector(nameClientConfiguration);
  } catch (final InjectionException e) {
    throw new RuntimeException(e);
  }
}
 
Example #6
Source File: GroupCommClientImpl.java    From reef with Apache License 2.0 6 votes vote down vote up
@Inject
private GroupCommClientImpl(@Parameter(SerializedGroupConfigs.class) final Set<String> groupConfigs,
                            final GroupCommNetworkHandler groupCommNetworkHandler,
                            final ConfigurationSerializer configSerializer,
                            final Injector injector) {

  LOG.log(Level.FINEST, "GroupCommHandler-{0}", groupCommNetworkHandler);

  for (final String groupConfigStr : groupConfigs) {
    try {
      final Configuration groupConfig = configSerializer.fromString(groupConfigStr);
      final Injector forkedInjector = injector.forkInjector(groupConfig);

      final CommunicationGroupServiceClient commGroupClient =
          forkedInjector.getInstance(CommunicationGroupServiceClient.class);

      this.communicationGroups.put(commGroupClient.getName(), commGroupClient);

    } catch (final InjectionException | IOException e) {
      throw new RuntimeException("Unable to deserialize operator config", e);
    }
  }
}
 
Example #7
Source File: PhysicalPlanGeneratorTest.java    From incubator-nemo with Apache License 2.0 6 votes vote down vote up
@Test
public void testBasic() throws Exception {
  final Injector injector = Tang.Factory.getTang().newInjector();
  final PhysicalPlanGenerator physicalPlanGenerator = injector.getInstance(PhysicalPlanGenerator.class);

  final IRVertex v0 = newIRVertex(0, 5);
  final IRVertex v1 = newIRVertex(0, 3);
  final IRDAG irDAG = new IRDAG(new DAGBuilder<IRVertex, IREdge>()
    .addVertex(v0)
    .addVertex(v1)
    .connectVertices(newIREdge(v0, v1, CommunicationPatternProperty.Value.ONE_TO_ONE,
      DataFlowProperty.Value.PULL))
    .buildWithoutSourceSinkCheck());

  final DAG<Stage, StageEdge> stageDAG = physicalPlanGenerator.apply(irDAG);
  final Iterator<Stage> stages = stageDAG.getVertices().iterator();
  final Stage s0 = stages.next();
  final Stage s1 = stages.next();
}
 
Example #8
Source File: RootContextLauncher.java    From reef with Apache License 2.0 6 votes vote down vote up
/**
 * Instantiates the root context.
 * <p>
 * This also launches the initial task if there is any.
 *
 * @param injector
 * @param rootContextConfiguration
 * @param rootServiceConfiguration
 * @return ContextRuntime
 * @throws ContextClientCodeException
 */
private static ContextRuntime getRootContext(final Injector injector,
                                             final Configuration rootContextConfiguration,
                                             final Optional<Configuration> rootServiceConfiguration)
    throws ContextClientCodeException {
  final ContextRuntime result;
  if (rootServiceConfiguration.isPresent()) {
    final Injector rootServiceInjector;
    try {
      rootServiceInjector = injector.forkInjector(rootServiceConfiguration.get());
    } catch (final BindException e) {
      throw new ContextClientCodeException(ContextClientCodeException.getIdentifier(rootContextConfiguration),
          Optional.<String>empty(), "Unable to instatiate the root context", e);
    }
    result = new ContextRuntime(rootServiceInjector, rootContextConfiguration);
  } else {
    result = new ContextRuntime(injector.forkInjector(), rootContextConfiguration);
  }
  return result;
}
 
Example #9
Source File: TestConfigurationModule.java    From reef with Apache License 2.0 6 votes vote down vote up
@Test
public void immutabilityTest() throws BindException, InjectionException {
  // builder methods return copies; the original module is immutable
  final ConfigurationModule builder1 = MyConfigurationModule.CONF
      .set(MyConfigurationModule.THE_FOO, FooImpl.class)
          .set(MyConfigurationModule.FOO_STRING_NESS, "abc");
  Assert.assertFalse(builder1 == MyConfigurationModule.CONF);
  final Configuration config1 = builder1.build();

  // reusable
  final Configuration config2 = MyConfigurationModule.CONF
      .set(MyConfigurationModule.THE_FOO, FooAltImpl.class)
      .set(MyConfigurationModule.FOO_STRING_NESS, "abc")
      .build();

    // instantiation of each just to be sure everything is fine in this situation
  final Injector i1 = Tang.Factory.getTang().newInjector(config1);
  final Injector i2 = Tang.Factory.getTang().newInjector(config2);
  Assert.assertEquals(42, i1.getInstance(Foo.class).getFooness());
  Assert.assertEquals(7, i2.getInstance(Foo.class).getFooness());
}
 
Example #10
Source File: NemoBackendTest.java    From nemo with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws Exception {
  this.dag = builder.addVertex(source).addVertex(map1).addVertex(groupByKey).addVertex(combine).addVertex(map2)
      .connectVertices(new IREdge(DataCommunicationPatternProperty.Value.OneToOne, source, map1, Coder.DUMMY_CODER))
      .connectVertices(new IREdge(DataCommunicationPatternProperty.Value.Shuffle,
          map1, groupByKey, Coder.DUMMY_CODER))
      .connectVertices(new IREdge(DataCommunicationPatternProperty.Value.OneToOne,
          groupByKey, combine, Coder.DUMMY_CODER))
      .connectVertices(new IREdge(DataCommunicationPatternProperty.Value.OneToOne, combine, map2, Coder.DUMMY_CODER))
      .build();

  this.dag = CompiletimeOptimizer.optimize(dag, new PadoPolicy(), EMPTY_DAG_DIRECTORY);

  final Injector injector = Tang.Factory.getTang().newInjector();
  injector.bindVolatileParameter(JobConf.DAGDirectory.class, "");
  this.physicalPlanGenerator = injector.getInstance(PhysicalPlanGenerator.class);
}
 
Example #11
Source File: SimulationSchedulerTest.java    From incubator-nemo with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws Exception {
  final Injector injector = Tang.Factory.getTang().newInjector();
  injector.bindVolatileInstance(PlanRewriter.class, mock(PlanRewriter.class));
  injector.bindVolatileInstance(SchedulingConstraintRegistry.class, mock(SchedulingConstraintRegistry.class));
  final SchedulingPolicy schedulingPolicy = Tang.Factory.getTang().newInjector()
    .getInstance(MinOccupancyFirstSchedulingPolicy.class);
  injector.bindVolatileInstance(SchedulingPolicy.class, schedulingPolicy);
  injector.bindVolatileInstance(BlockManagerMaster.class, mock(BlockManagerMaster.class));
  injector.bindVolatileInstance(ClientRPC.class, mock(ClientRPC.class));
  injector.bindVolatileParameter(JobConf.ExecutorJSONContents.class, defaultExecutorJSONContents);
  injector.bindVolatileParameter(JobConf.ScheduleSerThread.class, 8);
  injector.bindVolatileParameter(JobConf.DAGDirectory.class, "");

  batchScheduler = mock(BatchScheduler.class);
  scheduler = injector.getInstance(SimulationScheduler.class);
}
 
Example #12
Source File: CompilerTestUtil.java    From nemo with Apache License 2.0 6 votes vote down vote up
private static DAG<IRVertex, IREdge> compileDAG(final String[] args) throws Exception {
  final String userMainClassName;
  final String[] userMainMethodArgs;

  try {
    final Configuration configuration = JobLauncher.getJobConf(args);
    final Injector injector = Tang.Factory.getTang().newInjector(configuration);
    userMainClassName = injector.getNamedInstance(JobConf.UserMainClass.class);
    userMainMethodArgs = injector.getNamedInstance(JobConf.UserMainArguments.class).split(" ");
  } catch (final Exception e) {
    throw new RuntimeException("An exception occurred while processing configuration for invoking user main. "
        + "Note: Using compileDAG for multiple times will fail, as compileDAG method enables static method mocking "
        + "on JobLauncher and because of this Tang may misbehave afterwards.", e);
  }
  final Class userMainClass = Class.forName(userMainClassName);
  final Method userMainMethod = userMainClass.getMethod("main", String[].class);

  final ArgumentCaptor<DAG> captor = ArgumentCaptor.forClass(DAG.class);
  PowerMockito.mockStatic(JobLauncher.class);
  PowerMockito.doNothing().when(JobLauncher.class, "launchDAG", captor.capture());
  userMainMethod.invoke(null, (Object) userMainMethodArgs);
  return captor.getValue();
}
 
Example #13
Source File: TaskRetryTest.java    From incubator-nemo with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws Exception {
  // To understand which part of the log belongs to which test
  LOG.info("===== Testing {} =====", testName.getMethodName());
  final Injector injector = LocalMessageEnvironment.forkInjector(LocalMessageDispatcher.getInjector(),
    MessageEnvironment.MASTER_COMMUNICATION_ID);

  // Get random
  random = new Random(0); // Fixed seed for reproducing test results.

  // Get executorRegistry
  executorRegistry = injector.getInstance(ExecutorRegistry.class);

  // Get PlanStateManager
  runPhysicalPlan(TestPlanGenerator.PlanType.TwoVerticesJoined, injector);
}
 
Example #14
Source File: DataTransferTest.java    From nemo with Apache License 2.0 6 votes vote down vote up
private Injector createNameClientInjector() {
  try {
    final Configuration configuration = TANG.newConfigurationBuilder()
        .bindImplementation(IdentifierFactory.class, StringIdentifierFactory.class)
        .build();
    final Injector injector = TANG.newInjector(configuration);
    final LocalAddressProvider localAddressProvider = injector.getInstance(LocalAddressProvider.class);
    final NameServer nameServer = injector.getInstance(NameServer.class);
    final Configuration nameClientConfiguration = NameResolverConfiguration.CONF
        .set(NameResolverConfiguration.NAME_SERVER_HOSTNAME, localAddressProvider.getLocalAddress())
        .set(NameResolverConfiguration.NAME_SERVICE_PORT, nameServer.getPort())
        .build();
    return injector.forkInjector(nameClientConfiguration);
  } catch (final InjectionException e) {
    throw new RuntimeException(e);
  }
}
 
Example #15
Source File: EvaluatorManagerFactory.java    From reef with Apache License 2.0 5 votes vote down vote up
@Inject
EvaluatorManagerFactory(final Injector injector,
                        final ResourceCatalog resourceCatalog,
                        final EvaluatorProcessFactory processFactory,
                        final EvaluatorDescriptorBuilderFactory evaluatorDescriptorBuilderFactory) {
  this.injector = injector;
  this.resourceCatalog = resourceCatalog;
  this.processFactory = processFactory;
  this.evaluatorDescriptorBuilderFactory = evaluatorDescriptorBuilderFactory;
}
 
Example #16
Source File: LoggingScopeTest.java    From reef with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws InjectionException {
  final ConfigurationBuilder b = Tang.Factory.getTang().newConfigurationBuilder()
      .bindNamedParameter(LogLevelName.class, "INFO");

  final Injector i = Tang.Factory.getTang().newInjector(b.build());
  logFactory = i.getInstance(LoggingScopeFactory.class);
}
 
Example #17
Source File: ContextRuntime.java    From reef with Apache License 2.0 5 votes vote down vote up
/**
 * Launches a Task on this context.
 *
 * @param taskConfig the configuration to be used for the task.
 * @throws org.apache.reef.runtime.common.evaluator.task.TaskClientCodeException If the Task cannot be instantiated
 * due to user code / configuration issues.
 * @throws IllegalStateException                                                 If this method is called when
 * there is either a task or child context already present.
 */
@SuppressWarnings("checkstyle:illegalcatch")
void startTask(final Configuration taskConfig) throws TaskClientCodeException {

  synchronized (this.contextLifeCycle) {

    if (this.task.isPresent() && this.task.get().hasEnded()) {
      // clean up state
      this.task = Optional.empty();
    }

    if (this.task.isPresent()) {
      throw new IllegalStateException("Attempting to start a Task when a Task with id '" +
          this.task.get().getId() + "' is running.");
    }

    if (this.childContext.isPresent()) {
      throw new IllegalStateException(
          "Attempting to start a Task on a context that is not the topmost active context");
    }

    try {
      final Injector taskInjector = this.contextInjector.forkInjector(taskConfig);
      final TaskRuntime taskRuntime = taskInjector.getInstance(TaskRuntime.class);
      taskRuntime.initialize();
      this.taskRuntimeThread = new Thread(taskRuntime, taskRuntime.getId());
      this.taskRuntimeThread.start();
      this.task = Optional.of(taskRuntime);
      LOG.log(Level.FINEST, "Started task: {0}", taskRuntime.getTaskId());
    } catch (final BindException | InjectionException e) {
      throw new TaskClientCodeException(TaskClientCodeException.getTaskId(taskConfig),
          this.getIdentifier(),
          "Unable to instantiate the new task", e);
    } catch (final Throwable t) {
      throw new TaskClientCodeException(TaskClientCodeException.getTaskId(taskConfig),
          this.getIdentifier(),
          "Unable to start the new task", t);
    }
  }
}
 
Example #18
Source File: TestHttpServer.java    From reef with Apache License 2.0 5 votes vote down vote up
@Test
public void httpServerPortRetryTestWithTcpPortProvider() throws Exception {

  final Configuration httpRuntimeConfiguration = HttpRuntimeConfiguration.CONF.build();
  final Injector injector1 = Tang.Factory.getTang().newInjector(httpRuntimeConfiguration);
  final HttpServer httpServer1 = injector1.getInstance(HttpServer.class);
  final String portUsed = "" + httpServer1.getPort();

  final Configuration httpServerConfiguration = Tang.Factory.getTang().newConfigurationBuilder()
      .bindNamedParameter(TcpPortRangeCount.class, "1")
      .bindNamedParameter(TcpPortRangeBegin.class, portUsed)
      .bindNamedParameter(TcpPortRangeTryCount.class, "3")
      .build();

  final Configuration configuration =
      Configurations.merge(httpRuntimeConfiguration, httpServerConfiguration);

  final Injector injector2 = Tang.Factory.getTang().newInjector(configuration);

  try {
    injector2.getInstance(HttpServer.class);
    Assert.fail("Created two web servers on the same port: " + portUsed);
  } catch (final InjectionException ex) {
    Assert.assertEquals("Could not find available port for http", ex.getCause().getMessage());
  }

  httpServer1.stop();
}
 
Example #19
Source File: LoggingScopeTest.java    From reef with Apache License 2.0 5 votes vote down vote up
/**
 * Use default log level in injecting LoggingScopeFactory constructor.
 * @throws InjectionException
 */
@Test
public void testLoggingScopeFactoryWithDefaultLogLevel() throws InjectionException {
  final Injector i = Tang.Factory.getTang().newInjector(Tang.Factory.getTang().newConfigurationBuilder().build());
  final LoggingScopeFactory localLogFactory = i.getInstance(LoggingScopeFactory.class);

  try (LoggingScope ls = localLogFactory.activeContextReceived("test")) {
    Assert.assertTrue(true);
  }
}
 
Example #20
Source File: MockUtils.java    From reef with Apache License 2.0 5 votes vote down vote up
public static <U, T extends Name<U>> U getValue(final Configuration configuration, final Class<T> name) {
  try {
    final Injector injector = Tang.Factory.getTang().newInjector(configuration);
    return injector.getNamedInstance(name);
  } catch (InjectionException e) {
    throw new IllegalStateException(e);
  }
}
 
Example #21
Source File: RootContextLauncher.java    From reef with Apache License 2.0 5 votes vote down vote up
@Inject
RootContextLauncher(@Parameter(RootContextConfiguration.class) final String rootContextConfiguration,
                    final Injector injector,
                    @Parameter(RootServiceConfiguration.class) final String rootServiceConfiguration,
                    final ConfigurationSerializer configurationSerializer) throws IOException, BindException {
  this.injector = injector;
  this.configurationSerializer = configurationSerializer;
  this.rootContextConfiguration = this.configurationSerializer.fromString(rootContextConfiguration);
  this.rootServiceConfiguration = Optional.of(this.configurationSerializer.fromString(rootServiceConfiguration));
  this.initialTaskConfiguration = Optional.empty();
}
 
Example #22
Source File: FailBridgeClientUtils.java    From reef with Apache License 2.0 5 votes vote down vote up
/**
 * Setup the bridge service configuration.
 * @param runtimeConfiguration runtime configuration
 * @param driverClientConfiguration driver client configuration
 * @param driverClientConfigurationProto protocol arguments
 * @return bridge service configuration
 * @throws IOException
 * @throws InjectionException
 */
public static Configuration setupDriverService(
    final Configuration runtimeConfiguration,
    final Configuration driverClientConfiguration,
    final ClientProtocol.DriverClientConfiguration driverClientConfigurationProto)
    throws IOException, InjectionException {
  final File driverClientConfigurationFile = File.createTempFile("driverclient", ".conf");
  // Write driver client configuration to a file
  final Injector driverClientInjector = TANG.newInjector(driverClientConfiguration);
  final ConfigurationSerializer configurationSerializer =
      driverClientInjector.getInstance(ConfigurationSerializer.class);
  configurationSerializer.toFile(driverClientConfiguration, driverClientConfigurationFile);

  final Injector runtimeInjector = TANG.newInjector(runtimeConfiguration);
  final REEFFileNames fileNames = runtimeInjector.getInstance(REEFFileNames.class);
  final ClasspathProvider classpathProvider = runtimeInjector.getInstance(ClasspathProvider.class);
  final List<String> launchCommand = new JavaLaunchCommandBuilder(JavaDriverClientLauncher.class, null)
      .setConfigurationFilePaths(
          Collections.singletonList("./" + fileNames.getLocalFolderPath() + "/" +
              driverClientConfigurationFile.getName()))
      .setJavaPath("java")
      .setClassPath(StringUtils.join(classpathProvider.getDriverClasspath(),
          driverClientConfigurationProto.getOperatingSystem() ==
              ClientProtocol.DriverClientConfiguration.OS.WINDOWS ? ";" : ":"))
      .build();
  final String cmd = StringUtils.join(launchCommand, ' ');
  final ClientProtocol.DriverClientConfiguration driverServiceConfiguration =
      ClientProtocol.DriverClientConfiguration.newBuilder(driverClientConfigurationProto)
          .setDriverClientLaunchCommand(cmd)
          .addLocalFiles(driverClientConfigurationFile.getAbsolutePath())
          .build();
  final DriverServiceConfigurationProvider driverServiceConfigurationProvider = TANG.newInjector(
      TANG.newConfigurationBuilder()
          .bindImplementation(DriverServiceConfigurationProvider.class,
              GRPCDriverServiceConfigurationProvider.class)
          .build())
      .getInstance(DriverServiceConfigurationProvider.class);
  return driverServiceConfigurationProvider.getDriverServiceConfiguration(driverServiceConfiguration);
}
 
Example #23
Source File: JobSubmissionHelper.java    From reef with Apache License 2.0 5 votes vote down vote up
/**
 * Fils out a JobSubmissionProto based on the driver configuration given.
 *
 * @param driverConfiguration
 * @return
 * @throws InjectionException
 * @throws IOException
 */
JobSubmissionEventImpl.Builder getJobSubmissionBuilder(final Configuration driverConfiguration)
    throws InjectionException, IOException {
  final Injector injector = Tang.Factory.getTang().newInjector(driverConfiguration);

  final boolean preserveEvaluators = injector.getNamedInstance(ResourceManagerPreserveEvaluators.class);
  final int maxAppSubmissions = injector.getNamedInstance(MaxApplicationSubmissions.class);

  final JobSubmissionEventImpl.Builder jbuilder = JobSubmissionEventImpl.newBuilder()
      .setIdentifier(returnOrGenerateDriverId(injector.getNamedInstance(DriverIdentifier.class)))
      .setDriverMemory(injector.getNamedInstance(DriverMemory.class))
      .setDriverCpuCores(injector.getNamedInstance(DriverCPUCores.class))
      .setUserName(System.getProperty("user.name"))
      .setPreserveEvaluators(preserveEvaluators)
      .setMaxApplicationSubmissions(maxAppSubmissions)
      .setConfiguration(driverConfiguration);

  for (final String globalFileName : injector.getNamedInstance(JobGlobalFiles.class)) {
    LOG.log(Level.FINEST, "Adding global file: {0}", globalFileName);
    jbuilder.addGlobalFile(getFileResourceProto(globalFileName, FileType.PLAIN));
  }

  for (final String globalLibraryName : injector.getNamedInstance(JobGlobalLibraries.class)) {
    LOG.log(Level.FINEST, "Adding global library: {0}", globalLibraryName);
    jbuilder.addGlobalFile(getFileResourceProto(globalLibraryName, FileType.LIB));
  }

  for (final String localFileName : injector.getNamedInstance(DriverLocalFiles.class)) {
    LOG.log(Level.FINEST, "Adding local file: {0}", localFileName);
    jbuilder.addLocalFile(getFileResourceProto(localFileName, FileType.PLAIN));
  }

  for (final String localLibraryName : injector.getNamedInstance(DriverLocalLibraries.class)) {
    LOG.log(Level.FINEST, "Adding local library: {0}", localLibraryName);
    jbuilder.addLocalFile(getFileResourceProto(localLibraryName, FileType.LIB));
  }

  return jbuilder;
}
 
Example #24
Source File: Launch.java    From reef with Apache License 2.0 5 votes vote down vote up
/**
 * 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 org.apache.reef.tang.exceptions.BindException      if configuration commandLineInjector fails.
 * @throws org.apache.reef.tang.exceptions.InjectionException if configuration commandLineInjector fails.
 * @throws java.io.IOException                                error reading the configuration.
 */
private static Configuration getClientConfiguration(final String[] args)
    throws BindException, InjectionException, IOException {

  try (LoggingScope ls = LoggingScopeFactory.getNewLoggingScope(Level.INFO, "Launch::getClientConfiguration")) {
    final Configuration commandLineConf = parseCommandLine(args);

    final Configuration clientConfiguration = ClientConfiguration.CONF
        .set(ClientConfiguration.ON_JOB_COMPLETED, JobClient.CompletedJobHandler.class)
        .set(ClientConfiguration.ON_JOB_FAILED, JobClient.FailedJobHandler.class)
        .set(ClientConfiguration.ON_RUNTIME_ERROR, JobClient.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 Tang.Factory.getTang()
        .newConfigurationBuilder(runtimeConfiguration, clientConfiguration,
            cloneCommandLineConfiguration(commandLineConf))
        .build();
  }
}
 
Example #25
Source File: CommunicationGroupDriverImpl.java    From reef with Apache License 2.0 5 votes vote down vote up
private String taskId(final Configuration partialTaskConf) {
  try {
    final Injector injector = Tang.Factory.getTang().newInjector(partialTaskConf);
    return injector.getNamedInstance(TaskConfigurationOptions.Identifier.class);
  } catch (final InjectionException e) {
    throw new RuntimeException(getQualifiedName() +
        "Injection exception while extracting taskId from partialTaskConf", e);
  }
}
 
Example #26
Source File: CommunicationGroupDriverImpl.java    From reef with Apache License 2.0 5 votes vote down vote up
/**
 * @deprecated in 0.14. Use Tang to obtain an instance of this instead.
 */
@Deprecated
public CommunicationGroupDriverImpl(final Class<? extends Name<String>> groupName,
                                    final ConfigurationSerializer confSerializer,
                                    final EStage<GroupCommunicationMessage> senderStage,
                                    final BroadcastingEventHandler<RunningTask> groupCommRunningTaskHandler,
                                    final BroadcastingEventHandler<FailedTask> groupCommFailedTaskHandler,
                                    final BroadcastingEventHandler<FailedEvaluator> groupCommFailedEvaluatorHandler,
                                    final BroadcastingEventHandler<GroupCommunicationMessage> commGroupMessageHandler,
                                    final String driverId, final int numberOfTasks, final int fanOut) {
  super();
  this.groupName = groupName;
  this.driverId = driverId;
  this.confSerializer = confSerializer;
  this.allInitialTasksRunning = new CountingSemaphore(numberOfTasks, getQualifiedName(), topologiesLock);

  groupCommRunningTaskHandler.addHandler(new TopologyRunningTaskHandler(this));
  groupCommFailedTaskHandler.addHandler(new TopologyFailedTaskHandler(this));
  groupCommFailedEvaluatorHandler.addHandler(new TopologyFailedEvaluatorHandler(this));
  commGroupMessageHandler.addHandler(new TopologyMessageHandler(this));
  final Injector injector = Tang.Factory.getTang().newInjector();
  injector.bindVolatileParameter(CommGroupNameClass.class, groupName);
  injector.bindVolatileParameter(GroupCommSenderStage.class, senderStage);
  injector.bindVolatileParameter(DriverIdentifier.class, driverId);
  injector.bindVolatileParameter(CommGroupNumTask.class, numberOfTasks);
  injector.bindVolatileParameter(TreeTopologyFanOut.class, fanOut);
  try {
    topologyFactory = injector.getInstance(TopologyFactory.class);
  } catch (final InjectionException e) {
    throw new RuntimeException(e);
  }
  this.topologyClass = TreeTopology.class;
}
 
Example #27
Source File: RuntimesHost.java    From reef with Apache License 2.0 5 votes vote down vote up
/**
 * Initializes the configured runtimes.
 */
private synchronized void initialize() {

  if (this.runtimes != null) {
    return;
  }

  this.runtimes = new HashMap<>();

  for (final AvroRuntimeDefinition rd : runtimeDefinition.getRuntimes()) {
    try {

      // We need to create different injector for each runtime as they define conflicting bindings. Also we cannot
      // fork the original injector because of the same reason.
      // We create new injectors and copy form the original injector what we need.
      // rootInjector is an emptyInjector that we copy bindings from the original injector into. Then we fork
      // it to instantiate the actual runtime.
      final Injector rootInjector = Tang.Factory.getTang().newInjector();
      initializeInjector(rootInjector);

      final Configuration runtimeConfig =
          Tang.Factory.getTang().newConfigurationBuilder()
              .bindNamedParameter(RuntimeName.class, rd.getRuntimeName().toString())
              .bindImplementation(Runtime.class, RuntimeImpl.class)
              .build();

      final Configuration config =
          new AvroConfigurationSerializer().fromString(rd.getSerializedConfiguration().toString());

      final Injector runtimeInjector = rootInjector.forkInjector(config, runtimeConfig);

      this.runtimes.put(rd.getRuntimeName().toString(), runtimeInjector.getInstance(Runtime.class));

    } catch (final IOException | InjectionException e) {
      throw new RuntimeException("Unable to initialize runtimes.", e);
    }
  }
}
 
Example #28
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 #29
Source File: BlockStoreTest.java    From nemo with Apache License 2.0 5 votes vote down vote up
/**
 * Test {@link LocalFileStore}.
 */
@Test(timeout = 10000)
public void testLocalFileStore() throws Exception {
  FileUtils.deleteDirectory(new File(TMP_FILE_DIRECTORY));
  final Injector injector = Tang.Factory.getTang().newInjector();
  injector.bindVolatileParameter(JobConf.FileDirectory.class, TMP_FILE_DIRECTORY);
  injector.bindVolatileInstance(SerializerManager.class, serializerManager);

  final BlockStore localFileStore = injector.getInstance(LocalFileStore.class);
  shuffle(localFileStore, localFileStore);
  concurrentRead(localFileStore, localFileStore);
  shuffleInHashRange(localFileStore, localFileStore);
  FileUtils.deleteDirectory(new File(TMP_FILE_DIRECTORY));
}
 
Example #30
Source File: BlockStoreTest.java    From nemo with Apache License 2.0 5 votes vote down vote up
/**
 * Test {@link SerializedMemoryStore}.
 */
@Test(timeout = 10000)
public void testSerMemoryStore() throws Exception {
  final Injector injector = Tang.Factory.getTang().newInjector();
  injector.bindVolatileInstance(SerializerManager.class, serializerManager);
  final BlockStore serMemoryStore = injector.getInstance(SerializedMemoryStore.class);
  shuffle(serMemoryStore, serMemoryStore);
  concurrentRead(serMemoryStore, serMemoryStore);
  shuffleInHashRange(serMemoryStore, serMemoryStore);
}