Java Code Examples for org.apache.reef.wake.remote.address.LocalAddressProvider#getLocalAddress()

The following examples show how to use org.apache.reef.wake.remote.address.LocalAddressProvider#getLocalAddress() . 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: 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 2
Source File: NameServerImpl.java    From reef with Apache License 2.0 5 votes vote down vote up
/**
 * @param port    a listening port number
 * @param factory an identifier factory
 * @param localAddressProvider a local address provider
 * Constructs a name server
 */
@Inject
private NameServerImpl(
    @Parameter(RemoteConfiguration.HostAddress.class) final String hostAddress,
    @Parameter(NameServerParameters.NameServerPort.class) final int port,
    @Parameter(NameServerParameters.NameServerIdentifierFactory.class) final IdentifierFactory factory,
    final TcpPortProvider portProvider,
    final LocalAddressProvider localAddressProvider) {

  final Injector injector = Tang.Factory.getTang().newInjector();

  this.localAddressProvider = localAddressProvider;
  this.reefEventStateManager = null;
  final Codec<NamingMessage> codec = NamingCodecFactory.createFullCodec(factory);
  final EventHandler<NamingMessage> handler = createEventHandler(codec);

  String host = UNKNOWN_HOST_NAME.equals(hostAddress) ? localAddressProvider.getLocalAddress() : hostAddress;
  injector.bindVolatileParameter(RemoteConfiguration.HostAddress.class, host);
  injector.bindVolatileParameter(RemoteConfiguration.Port.class, port);
  injector.bindVolatileInstance(TcpPortProvider.class, portProvider);
  injector.bindVolatileParameter(RemoteConfiguration.RemoteServerStage.class,
      new SyncStage<>(new NamingServerHandler(handler, codec)));

  try {
    this.transport = injector.getInstance(NettyMessagingTransport.class);
  } catch (final InjectionException e) {
    throw new RuntimeException(e);
  }

  this.port = transport.getListeningPort();
  this.idToAddrMap = Collections.synchronizedMap(new HashMap<Identifier, InetSocketAddress>());

  LOG.log(Level.FINE, "NameServer starting, listening at port {0}", this.port);
}
 
Example 3
Source File: YarnContainerManager.java    From reef with Apache License 2.0 5 votes vote down vote up
@Inject
private YarnContainerManager(
    @Parameter(YarnHeartbeatPeriod.class) final int yarnRMHeartbeatPeriod,
    @Parameter(JobSubmissionDirectory.class) final String jobSubmissionDirectory,
    final YarnConfiguration yarnConf,
    final YarnProxyUser yarnProxyUser,
    final REEFEventHandlers reefEventHandlers,
    final Containers containers,
    final ApplicationMasterRegistration registration,
    final ContainerRequestCounter containerRequestCounter,
    final DriverStatusManager driverStatusManager,
    final REEFFileNames reefFileNames,
    final TrackingURLProvider trackingURLProvider,
    final LocalAddressProvider addressProvider,
    final RackNameFormatter rackNameFormatter,
    final InjectionFuture<ProgressProvider> progressProvider) throws IOException {

  this.reefEventHandlers = reefEventHandlers;
  this.driverStatusManager = driverStatusManager;

  this.containers = containers;
  this.registration = registration;
  this.containerRequestCounter = containerRequestCounter;
  this.yarnConf = yarnConf;
  this.yarnProxyUser = yarnProxyUser;
  this.rackNameFormatter = rackNameFormatter;

  this.trackingUrl = trackingURLProvider.getTrackingUrl();
  this.amRegistrationHost = addressProvider.getLocalAddress();

  this.resourceManager = AMRMClientAsync.createAMRMClientAsync(yarnRMHeartbeatPeriod, this);
  this.nodeManager = new NMClientAsyncImpl(this);

  this.jobSubmissionDirectory = jobSubmissionDirectory;
  this.reefFileNames = reefFileNames;
  this.progressProvider = progressProvider;

  LOG.log(Level.INFO, "Instantiated YarnContainerManager: {0} {1}, trackingUrl: {3}, jobSubmissionDirectory: {4}.",
      new Object[] {this.registration, this.yarnProxyUser, this.trackingUrl, this.jobSubmissionDirectory});
}
 
Example 4
Source File: HttpServerImpl.java    From reef with Apache License 2.0 5 votes vote down vote up
/**
 * Constructor of HttpServer that wraps Jetty Server.
 *
 * @param jettyHandler
 * @throws Exception
 */
@Inject
HttpServerImpl(@Parameter(RemoteConfiguration.HostAddress.class) final String hostAddress,
               final JettyHandler jettyHandler,
               final LocalAddressProvider addressProvider,
               final TcpPortProvider tcpPortProvider,
               final LoggingScopeFactory loggingScopeFactory) throws Exception {
  this.loggingScopeFactory = loggingScopeFactory;
  this.jettyHandler = jettyHandler;

  this.hostAddress = UNKNOWN_HOST_NAME.equals(hostAddress) ? addressProvider.getLocalAddress() : hostAddress;
  try (LoggingScope ls = this.loggingScopeFactory.httpServer()) {

    Server srv = null;
    int availablePort = -1;
    for (final int p : tcpPortProvider) {
      srv = tryPort(p);
      if (srv != null) {
        availablePort = p;
        break;
      }
    }

    if (srv  != null) {
      this.server = srv;
      this.port = availablePort;
      this.server.setHandler(jettyHandler);
      LOG.log(Level.INFO, "Jetty Server started with port: {0}", availablePort);
    } else {
      throw new RuntimeException("Could not find available port for http");
    }
  }
}
 
Example 5
Source File: JobDriver.java    From reef with Apache License 2.0 5 votes vote down vote up
/**
 * Job driver constructor.
 * All parameters are injected from TANG automatically.
 *
 * @param clock                      Wake clock to schedule and check up running jobs.
 * @param jobMessageObserver         is used to send messages back to the client.
 * @param evaluatorRequestor         is used to request Evaluators.
 * @param activeContextBridgeFactory
 */
@Inject
JobDriver(final Clock clock,
          final HttpServer httpServer,
          final NameServer nameServer,
          final JobMessageObserver jobMessageObserver,
          final EvaluatorRequestor evaluatorRequestor,
          final DriverStatusManager driverStatusManager,
          final LoggingScopeFactory loggingScopeFactory,
          final LocalAddressProvider localAddressProvider,
          final ActiveContextBridgeFactory activeContextBridgeFactory,
          final REEFFileNames reefFileNames,
          final AllocatedEvaluatorBridgeFactory allocatedEvaluatorBridgeFactory,
          final CLRProcessFactory clrProcessFactory,
          @Parameter(DefinedRuntimes.class) final Set<String> definedRuntimes) {
  this.clock = clock;
  this.httpServer = httpServer;
  this.jobMessageObserver = jobMessageObserver;
  this.evaluatorRequestor = evaluatorRequestor;
  this.nameServer = nameServer;
  this.driverStatusManager = driverStatusManager;
  this.activeContextBridgeFactory = activeContextBridgeFactory;
  this.allocatedEvaluatorBridgeFactory = allocatedEvaluatorBridgeFactory;
  this.nameServerInfo = localAddressProvider.getLocalAddress() + ":" + this.nameServer.getPort();
  this.loggingScopeFactory = loggingScopeFactory;
  this.reefFileNames = reefFileNames;
  this.localAddressProvider = localAddressProvider;
  this.clrProcessFactory = clrProcessFactory;
  this.definedRuntimes = definedRuntimes;
}
 
Example 6
Source File: ContainerManager.java    From reef with Apache License 2.0 4 votes vote down vote up
@Inject
private ContainerManager(
    final RemoteManager remoteManager,
    final REEFFileNames fileNames,
    @Parameter(MaxNumberOfEvaluators.class) final int capacity,
    @Parameter(RootFolder.class) final String rootFolderName,
    @Parameter(RuntimeParameters.NodeDescriptorHandler.class) final
    EventHandler<NodeDescriptorEvent> nodeDescriptorHandler,
    @Parameter(RackNames.class) final Set<String> rackNames,
    final ReefRunnableProcessObserver processObserver,
    final LocalAddressProvider localAddressProvider,
    @Parameter(DefaultMemorySize.class) final int defaultMemorySize,
    @Parameter(DefaultNumberOfCores.class) final int defaultNumberOfCores) {

  this.capacity = capacity;
  this.defaultMemorySize = defaultMemorySize;
  this.defaultNumberOfCores = defaultNumberOfCores;
  this.fileNames = fileNames;
  this.processObserver = processObserver;
  this.errorHandlerRID = remoteManager.getMyIdentifier();
  this.nodeDescriptorHandler = nodeDescriptorHandler;
  this.rootFolder = new File(rootFolderName);
  this.localAddress = localAddressProvider.getLocalAddress();
  this.availableRacks = normalize(rackNames);

  LOG.log(Level.FINEST, "Initializing Container Manager with {0} containers", capacity);

  remoteManager.registerHandler(ReefServiceProtos.RuntimeErrorProto.class,
      new EventHandler<RemoteMessage<ReefServiceProtos.RuntimeErrorProto>>() {
        @Override
        public void onNext(final RemoteMessage<ReefServiceProtos.RuntimeErrorProto> value) {
          final FailedRuntime error = new FailedRuntime(value.getMessage());
          LOG.log(Level.SEVERE, "FailedRuntime: " + error, error.getReason().orElse(null));
          release(error.getId());
        }
      });

  init();

  LOG.log(Level.FINE, "Initialized Container Manager with {0} containers", capacity);
}
 
Example 7
Source File: MessagingTransportFactory.java    From reef with Apache License 2.0 4 votes vote down vote up
@Inject
private MessagingTransportFactory(final LocalAddressProvider localAddressProvider) {
  this.localAddress = localAddressProvider.getLocalAddress();
}
 
Example 8
Source File: DefaultRemoteManagerImplementation.java    From reef with Apache License 2.0 4 votes vote down vote up
@Inject
private <T> DefaultRemoteManagerImplementation(
      @Parameter(RemoteConfiguration.ManagerName.class) final String name,
      @Parameter(RemoteConfiguration.HostAddress.class) final String hostAddress,
      @Parameter(RemoteConfiguration.Port.class) final int listeningPort,
      @Parameter(RemoteConfiguration.MessageCodec.class) final Codec<T> codec,
      @Parameter(RemoteConfiguration.ErrorHandler.class) final EventHandler<Throwable> errorHandler,
      @Parameter(RemoteConfiguration.OrderingGuarantee.class) final boolean orderingGuarantee,
      @Parameter(RemoteConfiguration.NumberOfTries.class) final int numberOfTries,
      @Parameter(RemoteConfiguration.RetryTimeout.class) final int retryTimeout,
      final LocalAddressProvider localAddressProvider,
      final TransportFactory tpFactory,
      final TcpPortProvider tcpPortProvider) {

  this.name = name;
  this.handlerContainer = new HandlerContainer<>(name, codec);

  this.reRecvStage = orderingGuarantee ?
      new OrderedRemoteReceiverStage(this.handlerContainer, errorHandler) :
      new RemoteReceiverStage(this.handlerContainer, errorHandler, 10);

  this.transport = tpFactory.newInstance(hostAddress, listeningPort,
      this.reRecvStage, this.reRecvStage, numberOfTries, retryTimeout, tcpPortProvider);

  this.handlerContainer.setTransport(this.transport);

  InetSocketAddress address = new InetSocketAddress(
      localAddressProvider.getLocalAddress(),
      this.transport.getListeningPort());
  this.myIdentifier = new SocketRemoteIdentifier(address);

  this.reSendStage = new RemoteSenderStage(codec, this.transport, 10);

  StageManager.instance().register(this);

  final int counter = COUNTER.incrementAndGet();

  LOG.log(Level.FINEST,
      "RemoteManager {0} instantiated id {1} counter {2} listening on {3} Binding address provided by {4}",
      new Object[] {this.name, this.myIdentifier, counter, this.transport.getLocalAddress(), localAddressProvider});
}