org.apache.reef.tang.Tang Java Examples

The following examples show how to use org.apache.reef.tang.Tang. 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: TestHttpServer.java    From reef with Apache License 2.0 6 votes vote down vote up
@Test
public void httpServerSpecifiedPortTest() throws Exception {

  final Configuration httpRuntimeConfiguration = HttpRuntimeConfiguration.CONF.build();

  final Configuration httpServerConfiguration = Tang.Factory.getTang().newConfigurationBuilder()
      .bindNamedParameter(TcpPortRangeBegin.class, "9000")
      .build();

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

  final Injector injector = Tang.Factory.getTang().newInjector(configuration);
  final HttpServer httpServer = injector.getInstance(HttpServer.class);
  Assert.assertNotNull(httpServer);
  httpServer.stop();
}
 
Example #2
Source File: TestHttpServer.java    From reef with Apache License 2.0 6 votes vote down vote up
@Test
public void httpServerPortRangeTestWithTcpPortProvider() throws Exception {
  final Configuration httpRuntimeConfiguration = HttpRuntimeConfiguration.CONF.build();

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

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

  final Injector injector1 = Tang.Factory.getTang().newInjector(configuration);
  final HttpServer httpServer1 = injector1.getInstance(HttpServer.class);

  final Injector injector2 = Tang.Factory.getTang().newInjector(configuration);
  final HttpServer httpServer2 = injector2.getInstance(HttpServer.class);

  Assert.assertTrue("port number is out of specified range",
      httpServer2.getPort() >= 1000 && httpServer2.getPort() <= 9900);

  httpServer1.stop();
  httpServer2.stop();
}
 
Example #3
Source File: HttpServerReefEventHandler.java    From reef with Apache License 2.0 6 votes vote down vote up
/**
 * Write Driver Info as JSON string to Response.
 */
private void writeDriverJsonInformation(final HttpServletResponse response) throws IOException {

  LOG.log(Level.INFO, "HttpServerReefEventHandler writeDriverJsonInformation invoked.");

  try {
    final DriverInfoSerializer serializer =
        Tang.Factory.getTang().newInjector().getInstance(DriverInfoSerializer.class);
    final AvroDriverInfo driverInfo = serializer.toAvro(
        this.reefStateManager.getDriverEndpointIdentifier(), this.reefStateManager.getStartTime(),
        this.reefStateManager.getServicesInfo());
    writeResponse(response, serializer.toString(driverInfo));
  } catch (final InjectionException e) {
    LOG.log(Level.SEVERE, "Error in injecting DriverInfoSerializer.", e);
    writeResponse(response, "Error in injecting DriverInfoSerializer: " + e);
  }
}
 
Example #4
Source File: CommunicationGroupDriverFactory.java    From reef with Apache License 2.0 6 votes vote down vote up
@Inject
private CommunicationGroupDriverFactory(
    @Parameter(DriverIdentifier.class) final String driverId,
    @Parameter(GroupCommSenderStage.class) final EStage<GroupCommunicationMessage> senderStage,
    @Parameter(GroupCommRunningTaskHandler.class)
        final BroadcastingEventHandler<RunningTask> groupCommRunningTaskHandler,
    @Parameter(GroupCommFailedTaskHandler.class)
        final BroadcastingEventHandler<FailedTask> groupCommFailedTaskHandler,
    @Parameter(GroupCommFailedEvalHandler.class)
        final BroadcastingEventHandler<FailedEvaluator> groupCommFailedEvaluatorHandler,
    final GroupCommMessageHandler groupCommMessageHandler) {
  injector = Tang.Factory.getTang().newInjector();
  injector.bindVolatileParameter(GroupCommSenderStage.class, senderStage);
  injector.bindVolatileParameter(DriverIdentifier.class, driverId);
  injector.bindVolatileParameter(GroupCommRunningTaskHandler.class, groupCommRunningTaskHandler);
  injector.bindVolatileParameter(GroupCommFailedTaskHandler.class, groupCommFailedTaskHandler);
  injector.bindVolatileParameter(GroupCommFailedEvalHandler.class, groupCommFailedEvaluatorHandler);
  injector.bindVolatileInstance(GroupCommMessageHandler.class, groupCommMessageHandler);
}
 
Example #5
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 #6
Source File: TestAvroSerializerForHttp.java    From reef with Apache License 2.0 6 votes vote down vote up
@Test
public void driverInfoSerializerInjectionTest() {
  try {
    final DriverInfoSerializer serializer =
        Tang.Factory.getTang().newInjector().getInstance(DriverInfoSerializer.class);
    final ArrayList<AvroReefServiceInfo> services = new ArrayList<>();
    final AvroReefServiceInfo exampleService =
        AvroReefServiceInfo.newBuilder().setServiceName("exampleService").setServiceInfo("serviceInformation")
            .build();
    services.add(exampleService);
    final AvroDriverInfo driverInfo = serializer.toAvro("abc", "xxxxxx", services);
    final String driverInfoString = serializer.toString(driverInfo);
    Assert.assertEquals(driverInfoString, "{\"remoteId\":\"abc\",\"startTime\":\"xxxxxx\"," +
        "\"services\":[{\"serviceName\":\"exampleService\",\"serviceInfo\":\"serviceInformation\"}]}");
  } catch (final InjectionException e) {
    Assert.fail("Not able to inject DriverInfoSerializer");
  }
}
 
Example #7
Source File: TestConfigurationModule.java    From reef with Apache License 2.0 6 votes vote down vote up
@Test
public void setClassRoundTripTest() throws BindException, InjectionException, IOException {
  final Configuration c = SetClassConfigurationModule.CONF
      .set(SetClassConfigurationModule.P, SubA.class)
      .set(SetClassConfigurationModule.P, SubB.class)
      .build();
  final ConfigurationBuilder cb = Tang.Factory.getTang().newConfigurationBuilder();
  final AvroConfigurationSerializer avroSerializer = new AvroConfigurationSerializer();
  avroSerializer.configurationBuilderFromString(avroSerializer.toString(c), cb);
  final Set<Super> s = Tang.Factory.getTang().newInjector(cb.build()).getNamedInstance(SetClass.class);
  Assert.assertEquals(2, s.size());
  boolean sawA = false, sawB = false;
  for (final Super sup : s) {
    if (sup instanceof SubA) {
      sawA = true;
    } else if (sup instanceof SubB) {
      sawB = true;
    } else {
      Assert.fail();
    }
  }
  Assert.assertTrue(sawA && sawB);
}
 
Example #8
Source File: DriverRPCServer.java    From incubator-nemo with Apache License 2.0 6 votes vote down vote up
/**
 * Runs the RPC server.
 * Specifically, creates a {@link NettyMessagingTransport} and binds it to a listening port.
 */
public void run() {
  // Calling 'run' multiple times is considered invalid, since it will override state variables like
  // 'transport', and 'host'.
  ensureServerState(false);
  try {
    final Injector injector = Tang.Factory.getTang().newInjector();
    final LocalAddressProvider localAddressProvider = injector.getInstance(LocalAddressProvider.class);
    host = localAddressProvider.getLocalAddress();
    injector.bindVolatileParameter(RemoteConfiguration.HostAddress.class, host);
    injector.bindVolatileParameter(RemoteConfiguration.Port.class, 0);
    injector.bindVolatileParameter(RemoteConfiguration.RemoteServerStage.class,
      new SyncStage<>(new ServerEventHandler()));
    transport = injector.getInstance(NettyMessagingTransport.class);
    LOG.info("DriverRPCServer running at {}", transport.getListeningPort());
    isRunning = true;
  } catch (final InjectionException e) {
    throw new RuntimeException(e);
  }
}
 
Example #9
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 #10
Source File: TestAvroSerializerForHttp.java    From reef with Apache License 2.0 6 votes vote down vote up
@Test
public void evaluatorInfoSerializerInjectionTest() {
  try {
    final EvaluatorInfoSerializer serializer =
        Tang.Factory.getTang().newInjector().getInstance(EvaluatorInfoSerializer.class);

    final List<String> ids = new ArrayList<>();
    ids.add("abc");
    final EvaluatorDescriptor evaluatorDescriptor =
        Tang.Factory.getTang().newInjector(EvaluatorDescriptorConfig.CONF.build())
            .getInstance(EvaluatorDescriptor.class);
    final Map<String, EvaluatorDescriptor> data = new HashMap<>();
    data.put("abc", evaluatorDescriptor);

    final AvroEvaluatorsInfo evaluatorInfo = serializer.toAvro(ids, data);
    final String evaluatorInfoString = serializer.toString(evaluatorInfo);
    Assert.assertEquals(evaluatorInfoString, "{\"evaluatorsInfo\":[{\"evaluatorId\":\"abc\",\"nodeId\":\"\"," +
        "\"nodeName\":\"mock\",\"memory\":64,\"type\":\"CLR\",\"internetAddress\":\"\",\"runtimeName\":\"Local\"}]}");
  } catch (final InjectionException e) {
    Assert.fail("Not able to inject EvaluatorInfoSerializer");
  }
}
 
Example #11
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 #12
Source File: SumOnes.java    From reef with Apache License 2.0 6 votes vote down vote up
/**
 * Launch the vortex job, passing appropriate arguments.
 */
public static void main(final String[] args) {
  final Configuration vortexMasterConf = VortexMasterConf.CONF
      .set(VortexMasterConf.WORKER_NUM, 2)
      .set(VortexMasterConf.WORKER_MEM, 1024)
      .set(VortexMasterConf.WORKER_CORES, 4)
      .set(VortexMasterConf.WORKER_CAPACITY, 2000)
      .set(VortexMasterConf.VORTEX_START, SumOnesAggregateStart.class)
      .build();

  final Configuration userConf = Tang.Factory.getTang().newConfigurationBuilder()
      .bindNamedParameter(NumberOfOnes.class, "1000")
      .build();

  final VortexJobConf vortexJobConf = VortexJobConf.newBuilder()
      .setJobName("Vortex_Example_SumOnes")
      .setVortexMasterConf(vortexMasterConf)
      .setUserConf(userConf)
      .build();

  VortexLauncher.launchLocal(vortexJobConf);
}
 
Example #13
Source File: ResourceManagerTest.java    From reef with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Before
public void setUp() throws InjectionException {
  final JavaConfigurationBuilder cb = Tang.Factory.getTang().newConfigurationBuilder();
  cb.bindNamedParameter(RootFolder.class, "target/REEF_LOCAL_RUNTIME");
  injector = Tang.Factory.getTang().newInjector(cb.build());
  remoteManager = injector.getInstance(RemoteManager.class);
  mockRuntimeResourceStatusHandler = mock(EventHandler.class);
  injector.bindVolatileParameter(RuntimeParameters.ResourceStatusHandler.class, mockRuntimeResourceStatusHandler);
  mockNodeDescriptorHandler = mock(EventHandler.class);
  injector.bindVolatileParameter(RuntimeParameters.NodeDescriptorHandler.class, mockNodeDescriptorHandler);
  mockResourceAllocationHandler = mock(EventHandler.class);
  injector.bindVolatileParameter(RuntimeParameters.ResourceAllocationHandler.class, mockResourceAllocationHandler);
  mockRuntimeStatusHandler = mock(EventHandler.class);
  injector.bindVolatileParameter(RuntimeParameters.RuntimeStatusHandler.class, mockRuntimeStatusHandler);
  configurationSerializer = injector.getInstance(ConfigurationSerializer.class);
  filenames = injector.getInstance(REEFFileNames.class);
  loggingScopeFactory = injector.getInstance(LoggingScopeFactory.class);
}
 
Example #14
Source File: RemoteIdentifierFactoryTest.java    From reef with Apache License 2.0 6 votes vote down vote up
@Test
public void testRemoteManagerIdentifier() throws Exception {
  final RemoteManagerFactory remoteManagerFactory = Tang.Factory.getTang().newInjector()
      .getInstance(RemoteManagerFactory.class);

  final Map<Class<?>, Codec<?>> clazzToCodecMap = new HashMap<>();
  clazzToCodecMap.put(TestEvent.class, new TestEventCodec());
  final Codec<?> codec = new MultiCodec<Object>(clazzToCodecMap);


  try (RemoteManager rm =
           remoteManagerFactory.getInstance("TestRemoteManager", 0, codec, new LoggingEventHandler<Throwable>())) {
    final RemoteIdentifier id = rm.getMyIdentifier();

    final IdentifierFactory factory = new DefaultIdentifierFactory();
    final Identifier newId = factory.getNewInstance(id.toString());

    Assert.assertEquals(id, newId);
  }
}
 
Example #15
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 #16
Source File: TestConfigurationModule.java    From reef with Apache License 2.0 5 votes vote down vote up
@Test
public void multiBindTest() throws BindException, InjectionException {
  // Here we set some configuration values.  In true tang style,
  // you won't be able to set them more than once ConfigurationModule's
  // implementation is complete.
  final Configuration c = MultiBindConfigurationModule.CONF
      .set(MultiBindConfigurationModule.THE_FOO, FooImpl.class)
      .set(MultiBindConfigurationModule.FOO_NESS, "" + 12)
      .build();
  final Foo f = Tang.Factory.getTang().newInjector(c).getInstance(Foo.class);
  final Foo g = (Foo) Tang.Factory.getTang().newInjector(c).getInstance(Object.class);
  Assert.assertEquals(f.getFooness(), 12);
  Assert.assertEquals(g.getFooness(), 12);
  Assert.assertFalse(f == g);
}
 
Example #17
Source File: LoopbackLocalAddressProvider.java    From reef with Apache License 2.0 5 votes vote down vote up
@Override
public Configuration getConfiguration() {
  return Tang.Factory.getTang().newConfigurationBuilder()
      .bind(LocalAddressProvider.class, LoopbackLocalAddressProvider.class)
      .bindNamedParameter(RemoteConfiguration.HostAddress.class, getLocalAddress())
      .build();
}
 
Example #18
Source File: TimerMock.java    From reef with Apache License 2.0 5 votes vote down vote up
public static void main(final String[] args) throws BindException, InjectionException, InterruptedException {
  final Configuration c = TimerMock.CONF
      .set(TimerMockConf.MOCK_SLEEP_TIME, 1)
      .build();
  final Timer t = Tang.Factory.getTang().newInjector(c).getInstance(Timer.class);
  System.out.println("Tick...");
  t.sleep();
  System.out.println("...tock.");
}
 
Example #19
Source File: TestTrackingUri.java    From reef with Apache License 2.0 5 votes vote down vote up
/**
 * Get Tracking URI with specified port number and HttpTrackingURLProvider.
 *
 * @throws InjectionException
 * @throws UnknownHostException
 * @throws BindException
 */
@Test
public void testHttpTrackingUri() throws InjectionException, UnknownHostException, BindException {
  final JavaConfigurationBuilder cb = Tang.Factory.getTang().newConfigurationBuilder()
      .bindNamedParameter(TcpPortRangeBegin.class, "8888")
      .bindImplementation(TrackingURLProvider.class, HttpTrackingURLProvider.class)
      .bindImplementation(HttpServer.class, HttpServerImpl.class);

  final Injector injector = Tang.Factory.getTang().newInjector(cb.build());
  final String uri = injector.getInstance(TrackingURLProvider.class).getTrackingUrl();
  final int port = injector.getInstance(HttpServer.class).getPort();
  verifyUri(uri, port);
}
 
Example #20
Source File: TestJettyHandler.java    From reef with Apache License 2.0 5 votes vote down vote up
@Test
public void testAddDuplicatedHandler() throws InjectionException, IOException, ServletException {
  final Injector injector = Tang.Factory.getTang().newInjector();
  final HttpAbcEventHandler abcEventHandler = injector.getInstance(HttpAbcEventHandler.class);
  this.handler.addHandler(abcEventHandler);
  this.handler.addHandler(abcEventHandler);  // it will be ignored
  this.request.setUri(new HttpURI("http://microsoft.com:8080/Abc/v1"));
  this.handler.handle("target", this.request, this.response, 0);
  Assert.assertEquals(HttpServletResponse.SC_OK, this.response.getStatus());
}
 
Example #21
Source File: JobStateManagerTest.java    From nemo with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
  irDAGBuilder = new DAGBuilder<>();
  final LocalMessageDispatcher messageDispatcher = new LocalMessageDispatcher();
  final LocalMessageEnvironment messageEnvironment =
      new LocalMessageEnvironment(MessageEnvironment.MASTER_COMMUNICATION_ID, messageDispatcher);
  final Injector injector = Tang.Factory.getTang().newInjector();
  injector.bindVolatileInstance(MessageEnvironment.class, messageEnvironment);
  blockManagerMaster = injector.getInstance(BlockManagerMaster.class);
  metricMessageHandler = mock(MetricMessageHandler.class);
  injector.bindVolatileParameter(JobConf.DAGDirectory.class, "");
  physicalPlanGenerator = injector.getInstance(PhysicalPlanGenerator.class);
}
 
Example #22
Source File: RemoteManagerTest.java    From reef with Apache License 2.0 5 votes vote down vote up
@Test
public void testRemoteManagerPBufTest() throws Exception {
  System.out.println(LOG_PREFIX + name.getMethodName());
  LoggingUtils.setLoggingLevel(Level.INFO);

  final Monitor monitor = new Monitor();
  final TimerStage timer = new TimerStage(new TimeoutHandler(monitor), 2000, 2000);

  final Map<Class<?>, Codec<?>> clazzToCodecMap = new HashMap<>();
  clazzToCodecMap.put(TestEvent.class, new TestEventCodec());
  final Codec<?> codec = new MultiCodec<Object>(clazzToCodecMap);

  final String hostAddress = localAddressProvider.getLocalAddress();

  final RemoteManager rm = this.remoteManagerFactory.getInstance(
      "name", hostAddress, 0, codec, new LoggingEventHandler<Throwable>(), false, 3, 10000,
      localAddressProvider, Tang.Factory.getTang().newInjector().getInstance(TcpPortProvider.class));

  final RemoteIdentifier remoteId = rm.getMyIdentifier();

  final EventHandler<TestEvent> proxyHandler = rm.getHandler(remoteId, TestEvent.class);

  final AtomicInteger counter = new AtomicInteger(0);
  final int finalSize = 0;
  rm.registerHandler(TestEvent.class, new MessageTypeEventHandler<TestEvent>(rm, monitor, counter, finalSize));

  proxyHandler.onNext(new TestEvent("hello", 0.0));

  monitor.mwait();

  Assert.assertEquals(finalSize, counter.get());

  rm.close();
  timer.close();
}
 
Example #23
Source File: NetworkConnectionServiceTest.java    From reef with Apache License 2.0 5 votes vote down vote up
public NetworkConnectionServiceTest() throws InjectionException {
  localAddressProvider = Tang.Factory.getTang().newInjector().getInstance(LocalAddressProvider.class);
  localAddress = localAddressProvider.getLocalAddress();

  final IdentifierFactory idFac = new StringIdentifierFactory();
  this.groupCommClientId = idFac.getNewInstance("groupComm");
  this.shuffleClientId = idFac.getNewInstance("shuffle");
}
 
Example #24
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 #25
Source File: EvaluatorShimLauncher.java    From reef with Apache License 2.0 5 votes vote down vote up
private static Configuration parseCommandLine(final String[] args) {
  if (args.length != 1) {
    throw new RuntimeException("Expected configuration file name as an argument.");
  }

  final JavaConfigurationBuilder confBuilder = Tang.Factory.getTang().newConfigurationBuilder();
  confBuilder.bindNamedParameter(EvaluatorShimConfigFilePath.class, args[0]);

  return confBuilder.build();
}
 
Example #26
Source File: REEFUncaughtExceptionHandler.java    From reef with Apache License 2.0 5 votes vote down vote up
@Override
public synchronized void uncaughtException(final Thread thread, final Throwable throwable) {

  final String msg = "Thread " + thread.getName() + " threw an uncaught exception.";
  LOG.log(Level.SEVERE, msg, throwable);

  if (this.errorHandler == null) {
    try {
      this.errorHandler = Tang.Factory.getTang()
          .newInjector(this.errorHandlerConfig).getInstance(REEFErrorHandler.class);
    } catch (final InjectionException ie) {
      LOG.log(Level.WARNING, "Unable to inject error handler.");
    }
  }

  if (this.errorHandler != null) {
    this.errorHandler.onNext(new Exception(msg, throwable));
    try {
      this.wait(100);
    } catch (final InterruptedException expected) {
      // try-catch block used to wait and give process a chance to setup communication with its parent
    }
    this.errorHandler.close();
  }

  LOG.log(Level.SEVERE, msg + " System.exit(1)");

  System.exit(1);
}
 
Example #27
Source File: YarnBootstrapREEFLauncher.java    From reef with Apache License 2.0 5 votes vote down vote up
public static void main(final String[] args) throws IOException, InjectionException {
  LOG.log(Level.INFO, "Entering BootstrapLauncher.main().");

  if (args.length != 2) {
    final StringBuilder sb = new StringBuilder();
    sb.append("[ ");
    for (String arg : args) {
      sb.append(arg);
      sb.append(" ");
    }

    sb.append("]");

    final String message = "Bootstrap launcher should have two configuration file inputs, one specifying the" +
        " application submission parameters to be deserialized and the other specifying the job" +
        " submission parameters to be deserialized to create the YarnDriverConfiguration on the fly." +
        " Current args are " + sb.toString();

    throw fatal(message, new IllegalArgumentException(message));
  }

  try {
    final YarnBootstrapDriverConfigGenerator yarnDriverConfigurationGenerator =
        Tang.Factory.getTang().newInjector().getInstance(YarnBootstrapDriverConfigGenerator.class);
    REEFLauncher.main(new String[]{yarnDriverConfigurationGenerator.writeDriverConfigurationFile(args[0], args[1])});
  } catch (final Exception exception) {
    if (!(exception instanceof RuntimeException)) {
      throw fatal("Failed to initialize configurations.", exception);
    }

    throw exception;
  }
}
 
Example #28
Source File: BroadcastDriver.java    From reef with Apache License 2.0 5 votes vote down vote up
private String contextId(final Configuration contextConf) {
  try {
    final Injector injector = Tang.Factory.getTang().newInjector(contextConf);
    return injector.getNamedInstance(ContextIdentifier.class);
  } catch (final InjectionException e) {
    throw new RuntimeException("Unable to inject context identifier from context conf", e);
  }
}
 
Example #29
Source File: BGDControlParameters.java    From reef with Apache License 2.0 5 votes vote down vote up
public Configuration getConfiguration() {
  return Tang.Factory.getTang().newConfigurationBuilder()
      .bindNamedParameter(ModelDimensions.class, Integer.toString(this.dimensions))
      .bindNamedParameter(Lambda.class, Double.toString(this.lambda))
      .bindNamedParameter(Eps.class, Double.toString(this.eps))
      .bindNamedParameter(Eta.class, Double.toString(this.eta))
      .bindNamedParameter(ProbabilityOfSuccessfulIteration.class, Double.toString(probOfSuccessfulIteration))
      .bindNamedParameter(Iterations.class, Integer.toString(this.iters))
      .bindNamedParameter(EnableRampup.class, Boolean.toString(this.rampup))
      .bindNamedParameter(MinParts.class, Integer.toString(this.minParts))
      .bindNamedParameter(LossFunctionType.class, lossType.lossFunctionString())
      .build();
}
 
Example #30
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);
}