Package org.apache.twill.discovery

Examples of org.apache.twill.discovery.Discoverable


    Map<String, String> expectedValues = Maps.newHashMap();
    expectedValues.put(EnvKeys.YARN_CONTAINER_MEMORY_MB, "2048");
    expectedValues.put(EnvKeys.TWILL_INSTANCE_COUNT, "1");

    // check environment of the runnable.
    Discoverable discoverable = envEchoServices.iterator().next();
    for (Map.Entry<String, String> expected : expectedValues.entrySet()) {
      Socket socket = new Socket(discoverable.getSocketAddress().getHostName(),
                                 discoverable.getSocketAddress().getPort());
      try {
        PrintWriter writer = new PrintWriter(new OutputStreamWriter(socket.getOutputStream(), Charsets.UTF_8), true);
        LineReader reader = new LineReader(new InputStreamReader(socket.getInputStream(), Charsets.UTF_8));
        writer.println(expected.getKey());
        Assert.assertEquals(expected.getValue(), reader.readLine());
View Full Code Here


    // check that we have 2 runnables.
    ResourceReport report = controller.getResourceReport();
    Assert.assertEquals(2, report.getRunnableResources("BuggyServer").size());

    // cause a divide by 0 in one server
    Discoverable discoverable = echoServices.iterator().next();
    Socket socket = new Socket(discoverable.getSocketAddress().getAddress(),
                               discoverable.getSocketAddress().getPort());
    try {
      PrintWriter writer = new PrintWriter(new OutputStreamWriter(socket.getOutputStream(), Charsets.UTF_8), true);
      writer.println("0");
    } finally {
      socket.close();
View Full Code Here

    return allowedMemoryMB;
  }

  @Override
  public Cancellable announce(final String serviceName, final int port) {
    return discoveryService.register(new Discoverable() {
      @Override
      public String getName() {
        return serviceName;
      }
View Full Code Here

    return allowedMemoryMB;
  }

  @Override
  public Cancellable announce(final String serviceName, final int port) {
    return discoveryService.register(new Discoverable() {
      @Override
      public String getName() {
        return serviceName;
      }
View Full Code Here

    ServiceDiscovered serviceDiscovered = discoveryServiceClient.discover(String.format("service.%s.%s.%s",
                                                                                        accountId,
                                                                                        applicationId,
                                                                                        serviceName));
    EndpointStrategy endpointStrategy = new RandomEndpointStrategy(serviceDiscovered);
    Discoverable discoverable = endpointStrategy.pick();
    if (discoverable != null) {
      return createURL(discoverable, applicationId, serviceName);
    }

    final SynchronousQueue<URL> discoverableQueue = new SynchronousQueue<URL>();
View Full Code Here

    this.procedureName = procedureName;
  }

  @Override
  public byte[] queryRaw(String method, Map<String, String> arguments) throws IOException {
    Discoverable discoverable = discoveryServiceClient.discover(
      String.format("procedure.%s.%s.%s",
                    accountId, applicationId, procedureName)).iterator().next();

    URL url = new URL(String.format("http://%s:%d/apps/%s/procedures/%s/methods/%s",
                      discoverable.getSocketAddress().getHostName(),
                      discoverable.getSocketAddress().getPort(),
                      applicationId,
                      procedureName,
                      method));
    HttpURLConnection urlConn = (HttpURLConnection) url.openConnection();
    urlConn.setDoOutput(true);
View Full Code Here

  protected final Connection getQueryClient() throws Exception {

    // this makes sure the Explore JDBC driver is loaded
    Class.forName(ExploreDriver.class.getName());

    Discoverable discoverable = new StickyEndpointStrategy(
      discoveryClient.discover(Constants.Service.EXPLORE_HTTP_USER_SERVICE)).pick();

    if (null == discoverable) {
      throw new IOException("Explore service could not be discovered.");
    }

    InetSocketAddress address = discoverable.getSocketAddress();
    String host = address.getHostName();
    int port = address.getPort();

    String connectString = String.format("%s%s:%d", Constants.Explore.Jdbc.URL_PREFIX, host, port);
View Full Code Here

  protected void startUp() throws Exception {
    LOG.info("Starting Gateway...");
    httpService.startAndWait();

    // Register the service
    cancelDiscovery = discoveryService.register(new Discoverable() {
      @Override
      public String getName() {
        return Constants.Service.GATEWAY;
      }
View Full Code Here

  @Override
  public void append(AvroFlumeEvent event, org.apache.avro.ipc.Callback<Status> callback) throws IOException {
    try {
      // Discover the stream endpoint
      Discoverable endpoint = endpointStrategy.pick();
      if (endpoint == null) {
        callback.handleError(new IllegalStateException("No stream endpoint available. Unable to write to stream."));
        return;
      }

      // Figure out the stream name
      Map<String, String> headers = Maps.newTreeMap();
      String streamName = createHeaders(event, headers);

      // Forward the request
      URL url = new URL(String.format("http://%s:%d/v2/streams/%s",
                                      endpoint.getSocketAddress().getHostName(),
                                      endpoint.getSocketAddress().getPort(),
                                      streamName));
      HttpURLConnection urlConn = (HttpURLConnection) url.openConnection();
      try {
        urlConn.setDoOutput(true);
View Full Code Here

    if (strategy == null) {
      throw  new HandlerException(HttpResponseStatus.SERVICE_UNAVAILABLE,
                                  String.format("No endpoint strategy found for request : %s",
                                  httpRequest.getUri()));
    }
    Discoverable discoverable = strategy.pick();
    if (discoverable == null) {
      throw  new HandlerException(HttpResponseStatus.SERVICE_UNAVAILABLE,
                                  String.format("No discoverable found for request : %s",
                                                httpRequest.getUri()));
    }
View Full Code Here

TOP

Related Classes of org.apache.twill.discovery.Discoverable

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.