org.apache.hadoop.registry.client.types.Endpoint Java Examples

The following examples show how to use org.apache.hadoop.registry.client.types.Endpoint. 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: RegistryTestHelper.java    From big-c with Apache License 2.0 6 votes vote down vote up
/**
 * Add some endpoints
 * @param entry entry
 */
public static void addSampleEndpoints(ServiceRecord entry, String hostname)
    throws URISyntaxException {
  assertNotNull(hostname);
  entry.addExternalEndpoint(webEndpoint(HTTP_API,
      new URI("http", hostname + ":80", "/")));
  entry.addExternalEndpoint(
      restEndpoint(API_WEBHDFS,
          new URI("http", hostname + ":8020", "/")));

  Endpoint endpoint = ipcEndpoint(API_HDFS, null);
  endpoint.addresses.add(RegistryTypeUtils.hostnamePortPair(hostname, 8030));
  entry.addInternalEndpoint(endpoint);
  InetSocketAddress localhost = new InetSocketAddress("localhost", 8050);
  entry.addInternalEndpoint(
      inetAddrEndpoint(NNIPC, ProtocolTypes.PROTOCOL_THRIFT, "localhost",
          8050));
  entry.addInternalEndpoint(
      RegistryTypeUtils.ipcEndpoint(
          IPC2, localhost));
}
 
Example #2
Source File: RegistryTypeUtils.java    From big-c with Apache License 2.0 6 votes vote down vote up
/**
 * Get a single URI endpoint
 * @param epr endpoint
 * @return the uri of the first entry in the address list. Null if the endpoint
 * itself is null
 * @throws InvalidRecordException if the type is wrong, there are no addresses
 * or the payload ill-formatted
 */
public static List<String> retrieveAddressesUriType(Endpoint epr)
    throws InvalidRecordException {
  if (epr == null) {
    return null;
  }
  requireAddressType(ADDRESS_URI, epr);
  List<Map<String, String>> addresses = epr.addresses;
  if (addresses.size() < 1) {
    throw new InvalidRecordException(epr.toString(),
        "No addresses in endpoint");
  }
  List<String> results = new ArrayList<String>(addresses.size());
  for (Map<String, String> address : addresses) {
    results.add(getAddressField(address, ADDRESS_URI));
  }
  return results;
}
 
Example #3
Source File: RegistryTypeUtils.java    From hadoop with Apache License 2.0 6 votes vote down vote up
/**
 * Get a single URI endpoint
 * @param epr endpoint
 * @return the uri of the first entry in the address list. Null if the endpoint
 * itself is null
 * @throws InvalidRecordException if the type is wrong, there are no addresses
 * or the payload ill-formatted
 */
public static List<String> retrieveAddressesUriType(Endpoint epr)
    throws InvalidRecordException {
  if (epr == null) {
    return null;
  }
  requireAddressType(ADDRESS_URI, epr);
  List<Map<String, String>> addresses = epr.addresses;
  if (addresses.size() < 1) {
    throw new InvalidRecordException(epr.toString(),
        "No addresses in endpoint");
  }
  List<String> results = new ArrayList<String>(addresses.size());
  for (Map<String, String> address : addresses) {
    results.add(getAddressField(address, ADDRESS_URI));
  }
  return results;
}
 
Example #4
Source File: RegistryTestHelper.java    From big-c with Apache License 2.0 6 votes vote down vote up
/**
 * Find an endpoint in a record or fail,
 * @param record record
 * @param api API
 * @param external external?
 * @param addressElements expected # of address elements?
 * @param addressTupleSize expected size of a type
 * @return the endpoint.
 */
public static Endpoint findEndpoint(ServiceRecord record,
    String api, boolean external, int addressElements, int addressTupleSize) {
  Endpoint epr = external ? record.getExternalEndpoint(api)
                          : record.getInternalEndpoint(api);
  if (epr != null) {
    assertEquals("wrong # of addresses",
        addressElements, epr.addresses.size());
    assertEquals("wrong # of elements in an address tuple",
        addressTupleSize, epr.addresses.get(0).size());
    return epr;
  }
  List<Endpoint> endpoints = external ? record.external : record.internal;
  StringBuilder builder = new StringBuilder();
  for (Endpoint endpoint : endpoints) {
    builder.append("\"").append(endpoint).append("\" ");
  }
  fail("Did not find " + api + " in endpoints " + builder);
  // never reached; here to keep the compiler happy
  return null;
}
 
Example #5
Source File: RegistryTestHelper.java    From hadoop with Apache License 2.0 6 votes vote down vote up
/**
 * Find an endpoint in a record or fail,
 * @param record record
 * @param api API
 * @param external external?
 * @param addressElements expected # of address elements?
 * @param addressTupleSize expected size of a type
 * @return the endpoint.
 */
public static Endpoint findEndpoint(ServiceRecord record,
    String api, boolean external, int addressElements, int addressTupleSize) {
  Endpoint epr = external ? record.getExternalEndpoint(api)
                          : record.getInternalEndpoint(api);
  if (epr != null) {
    assertEquals("wrong # of addresses",
        addressElements, epr.addresses.size());
    assertEquals("wrong # of elements in an address tuple",
        addressTupleSize, epr.addresses.get(0).size());
    return epr;
  }
  List<Endpoint> endpoints = external ? record.external : record.internal;
  StringBuilder builder = new StringBuilder();
  for (Endpoint endpoint : endpoints) {
    builder.append("\"").append(endpoint).append("\" ");
  }
  fail("Did not find " + api + " in endpoints " + builder);
  // never reached; here to keep the compiler happy
  return null;
}
 
Example #6
Source File: RegistryTestHelper.java    From hadoop with Apache License 2.0 6 votes vote down vote up
/**
 * Add some endpoints
 * @param entry entry
 */
public static void addSampleEndpoints(ServiceRecord entry, String hostname)
    throws URISyntaxException {
  assertNotNull(hostname);
  entry.addExternalEndpoint(webEndpoint(HTTP_API,
      new URI("http", hostname + ":80", "/")));
  entry.addExternalEndpoint(
      restEndpoint(API_WEBHDFS,
          new URI("http", hostname + ":8020", "/")));

  Endpoint endpoint = ipcEndpoint(API_HDFS, null);
  endpoint.addresses.add(RegistryTypeUtils.hostnamePortPair(hostname, 8030));
  entry.addInternalEndpoint(endpoint);
  InetSocketAddress localhost = new InetSocketAddress("localhost", 8050);
  entry.addInternalEndpoint(
      inetAddrEndpoint(NNIPC, ProtocolTypes.PROTOCOL_THRIFT, "localhost",
          8050));
  entry.addInternalEndpoint(
      RegistryTypeUtils.ipcEndpoint(
          IPC2, localhost));
}
 
Example #7
Source File: JstormMaster.java    From jstorm with Apache License 2.0 5 votes vote down vote up
private ServiceRecord setupServiceRecord() {
    ServiceRecord application = new ServiceRecord();
    application.set(YarnRegistryAttributes.YARN_ID, jstormMasterContext.appAttemptID.getApplicationId().toString());
    application.description = JOYConstants.AM;
    application.set(YarnRegistryAttributes.YARN_PERSISTENCE,
            PersistencePolicies.PERMANENT);
    Map<String, String> addresses = new HashMap<String, String>();
    addresses.put(JOYConstants.HOST, jstormMasterContext.appMasterHostname);
    addresses.put(JOYConstants.PORT, String.valueOf(jstormMasterContext.appMasterThriftPort));
    Endpoint endpoint = new Endpoint(JOYConstants.HTTP, JOYConstants.HOST_PORT, JOYConstants.RPC, addresses);
    application.addExternalEndpoint(endpoint);
    return application;
}
 
Example #8
Source File: RegistryTypeUtils.java    From big-c with Apache License 2.0 5 votes vote down vote up
/**
 * Validate the endpoint by checking for null fields and other invalid
 * conditions
 * @param path path for exceptions
 * @param endpoint endpoint to validate. May be null
 * @throws InvalidRecordException on invalid entries
 */
public static void validateEndpoint(String path, Endpoint endpoint)
    throws InvalidRecordException {
  if (endpoint == null) {
    throw new InvalidRecordException(path, "Null endpoint");
  }
  try {
    endpoint.validate();
  } catch (RuntimeException e) {
    throw new InvalidRecordException(path, e.toString());
  }
}
 
Example #9
Source File: RegistryTypeUtils.java    From big-c with Apache License 2.0 5 votes vote down vote up
/**
 * Get the address URLs. Guranteed to return at least one address.
 * @param epr endpoint
 * @return the address as a URL
 * @throws InvalidRecordException if the type is wrong, there are no addresses
 * or the payload ill-formatted
 * @throws MalformedURLException address can't be turned into a URL
 */
public static List<URL> retrieveAddressURLs(Endpoint epr)
    throws InvalidRecordException, MalformedURLException {
  if (epr == null) {
    throw new InvalidRecordException("", "Null endpoint");
  }
  List<String> addresses = retrieveAddressesUriType(epr);
  List<URL> results = new ArrayList<URL>(addresses.size());
  for (String address : addresses) {
    results.add(new URL(address));
  }
  return results;
}
 
Example #10
Source File: RegistryTypeUtils.java    From big-c with Apache License 2.0 5 votes vote down vote up
/**
 * Require a specific address type on an endpoint
 * @param required required type
 * @param epr endpoint
 * @throws InvalidRecordException if the type is wrong
 */
public static void requireAddressType(String required, Endpoint epr) throws
    InvalidRecordException {
  if (!required.equals(epr.addressType)) {
    throw new InvalidRecordException(
        epr.toString(),
        "Address type of " + epr.addressType
        + " does not match required type of "
        + required);
  }
}
 
Example #11
Source File: RegistryTypeUtils.java    From big-c with Apache License 2.0 5 votes vote down vote up
/**
 * Create an IPC endpoint
 * @param api API
 * @param address the address as a tuple of (hostname, port)
 * @return the new endpoint
 */
public static Endpoint ipcEndpoint(String api, InetSocketAddress address) {
  return new Endpoint(api,
      ADDRESS_HOSTNAME_AND_PORT,
      ProtocolTypes.PROTOCOL_HADOOP_IPC,
      address== null ? null: hostnamePortPair(address));
}
 
Example #12
Source File: RegistryTypeUtils.java    From big-c with Apache License 2.0 5 votes vote down vote up
/**
 * Create an internet address endpoint from a list of URIs
 * @param api implemented API
 * @param protocolType protocol type
 * @param hostname hostname/FQDN
 * @param port port
 * @return a new endpoint
 */

public static Endpoint inetAddrEndpoint(String api,
    String protocolType,
    String hostname,
    int port) {
  Preconditions.checkArgument(api != null, "null API");
  Preconditions.checkArgument(protocolType != null, "null protocolType");
  Preconditions.checkArgument(hostname != null, "null hostname");
  return new Endpoint(api,
      ADDRESS_HOSTNAME_AND_PORT,
      protocolType,
      hostnamePortPair(hostname, port));
}
 
Example #13
Source File: RegistryTestHelper.java    From big-c with Apache License 2.0 5 votes vote down vote up
/**
 * General code to validate bits of a component/service entry built iwth
 * {@link #addSampleEndpoints(ServiceRecord, String)}
 * @param record instance to check
 */
public static void validateEntry(ServiceRecord record) {
  assertNotNull("null service record", record);
  List<Endpoint> endpoints = record.external;
  assertEquals(2, endpoints.size());

  Endpoint webhdfs = findEndpoint(record, API_WEBHDFS, true, 1, 1);
  assertEquals(API_WEBHDFS, webhdfs.api);
  assertEquals(AddressTypes.ADDRESS_URI, webhdfs.addressType);
  assertEquals(ProtocolTypes.PROTOCOL_REST, webhdfs.protocolType);
  List<Map<String, String>> addressList = webhdfs.addresses;
  Map<String, String> url = addressList.get(0);
  String addr = url.get("uri");
  assertTrue(addr.contains("http"));
  assertTrue(addr.contains(":8020"));

  Endpoint nnipc = findEndpoint(record, NNIPC, false, 1,2);
  assertEquals("wrong protocol in " + nnipc, ProtocolTypes.PROTOCOL_THRIFT,
      nnipc.protocolType);

  Endpoint ipc2 = findEndpoint(record, IPC2, false, 1,2);
  assertNotNull(ipc2);

  Endpoint web = findEndpoint(record, HTTP_API, true, 1, 1);
  assertEquals(1, web.addresses.size());
  assertEquals(1, web.addresses.get(0).size());
}
 
Example #14
Source File: RegistryTestHelper.java    From big-c with Apache License 2.0 5 votes vote down vote up
/**
 * Assert that an endpoint matches the criteria
 * @param endpoint endpoint to examine
 * @param addressType expected address type
 * @param protocolType expected protocol type
 * @param api API
 */
public static void assertMatches(Endpoint endpoint,
    String addressType,
    String protocolType,
    String api) {
  assertNotNull(endpoint);
  assertEquals(addressType, endpoint.addressType);
  assertEquals(protocolType, endpoint.protocolType);
  assertEquals(api, endpoint.api);
}
 
Example #15
Source File: RegistryTestHelper.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/**
 * Assert that an endpoint matches the criteria
 * @param endpoint endpoint to examine
 * @param addressType expected address type
 * @param protocolType expected protocol type
 * @param api API
 */
public static void assertMatches(Endpoint endpoint,
    String addressType,
    String protocolType,
    String api) {
  assertNotNull(endpoint);
  assertEquals(addressType, endpoint.addressType);
  assertEquals(protocolType, endpoint.protocolType);
  assertEquals(api, endpoint.api);
}
 
Example #16
Source File: RegistryTestHelper.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/**
 * General code to validate bits of a component/service entry built iwth
 * {@link #addSampleEndpoints(ServiceRecord, String)}
 * @param record instance to check
 */
public static void validateEntry(ServiceRecord record) {
  assertNotNull("null service record", record);
  List<Endpoint> endpoints = record.external;
  assertEquals(2, endpoints.size());

  Endpoint webhdfs = findEndpoint(record, API_WEBHDFS, true, 1, 1);
  assertEquals(API_WEBHDFS, webhdfs.api);
  assertEquals(AddressTypes.ADDRESS_URI, webhdfs.addressType);
  assertEquals(ProtocolTypes.PROTOCOL_REST, webhdfs.protocolType);
  List<Map<String, String>> addressList = webhdfs.addresses;
  Map<String, String> url = addressList.get(0);
  String addr = url.get("uri");
  assertTrue(addr.contains("http"));
  assertTrue(addr.contains(":8020"));

  Endpoint nnipc = findEndpoint(record, NNIPC, false, 1,2);
  assertEquals("wrong protocol in " + nnipc, ProtocolTypes.PROTOCOL_THRIFT,
      nnipc.protocolType);

  Endpoint ipc2 = findEndpoint(record, IPC2, false, 1,2);
  assertNotNull(ipc2);

  Endpoint web = findEndpoint(record, HTTP_API, true, 1, 1);
  assertEquals(1, web.addresses.size());
  assertEquals(1, web.addresses.get(0).size());
}
 
Example #17
Source File: RegistryTypeUtils.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/**
 * Validate the endpoint by checking for null fields and other invalid
 * conditions
 * @param path path for exceptions
 * @param endpoint endpoint to validate. May be null
 * @throws InvalidRecordException on invalid entries
 */
public static void validateEndpoint(String path, Endpoint endpoint)
    throws InvalidRecordException {
  if (endpoint == null) {
    throw new InvalidRecordException(path, "Null endpoint");
  }
  try {
    endpoint.validate();
  } catch (RuntimeException e) {
    throw new InvalidRecordException(path, e.toString());
  }
}
 
Example #18
Source File: RegistryTypeUtils.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/**
 * Get the address URLs. Guranteed to return at least one address.
 * @param epr endpoint
 * @return the address as a URL
 * @throws InvalidRecordException if the type is wrong, there are no addresses
 * or the payload ill-formatted
 * @throws MalformedURLException address can't be turned into a URL
 */
public static List<URL> retrieveAddressURLs(Endpoint epr)
    throws InvalidRecordException, MalformedURLException {
  if (epr == null) {
    throw new InvalidRecordException("", "Null endpoint");
  }
  List<String> addresses = retrieveAddressesUriType(epr);
  List<URL> results = new ArrayList<URL>(addresses.size());
  for (String address : addresses) {
    results.add(new URL(address));
  }
  return results;
}
 
Example #19
Source File: RegistryTypeUtils.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/**
 * Require a specific address type on an endpoint
 * @param required required type
 * @param epr endpoint
 * @throws InvalidRecordException if the type is wrong
 */
public static void requireAddressType(String required, Endpoint epr) throws
    InvalidRecordException {
  if (!required.equals(epr.addressType)) {
    throw new InvalidRecordException(
        epr.toString(),
        "Address type of " + epr.addressType
        + " does not match required type of "
        + required);
  }
}
 
Example #20
Source File: RegistryTypeUtils.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/**
 * Create an IPC endpoint
 * @param api API
 * @param address the address as a tuple of (hostname, port)
 * @return the new endpoint
 */
public static Endpoint ipcEndpoint(String api, InetSocketAddress address) {
  return new Endpoint(api,
      ADDRESS_HOSTNAME_AND_PORT,
      ProtocolTypes.PROTOCOL_HADOOP_IPC,
      address== null ? null: hostnamePortPair(address));
}
 
Example #21
Source File: RegistryTypeUtils.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/**
 * Create an internet address endpoint from a list of URIs
 * @param api implemented API
 * @param protocolType protocol type
 * @param hostname hostname/FQDN
 * @param port port
 * @return a new endpoint
 */

public static Endpoint inetAddrEndpoint(String api,
    String protocolType,
    String hostname,
    int port) {
  Preconditions.checkArgument(api != null, "null API");
  Preconditions.checkArgument(protocolType != null, "null protocolType");
  Preconditions.checkArgument(hostname != null, "null hostname");
  return new Endpoint(api,
      ADDRESS_HOSTNAME_AND_PORT,
      protocolType,
      hostnamePortPair(hostname, port));
}
 
Example #22
Source File: RegistryCli.java    From hadoop with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
public int resolve(String[] args) {
  Options resolveOption = new Options();
  CommandLineParser parser = new GnuParser();
  try {
    CommandLine line = parser.parse(resolveOption, args);

    List<String> argsList = line.getArgList();
    if (argsList.size() != 2) {
      return usageError("resolve requires exactly one path argument",
          RESOLVE_USAGE);
    }
    if (!validatePath(argsList.get(1))) {
      return -1;
    }

    try {
      ServiceRecord record = registry.resolve(argsList.get(1));

      for (Endpoint endpoint : record.external) {
        sysout.println(" Endpoint(ProtocolType="
                       + endpoint.protocolType + ", Api="
                       + endpoint.api + ");"
                       + " Addresses(AddressType="
                       + endpoint.addressType + ") are: ");

        for (Map<String, String> address : endpoint.addresses) {
          sysout.println("[ ");
          for (Map.Entry<String, String> entry : address.entrySet()) {
            sysout.print("\t" + entry.getKey()
                           + ":" + entry.getValue());
          }

          sysout.println("\n]");
        }
        sysout.println();
      }
      return 0;
    } catch (Exception e) {
      syserr.println(analyzeException("resolve", e, argsList));
    }
    return -1;
  } catch (ParseException exp) {
    return usageError("Invalid syntax " + exp, RESOLVE_USAGE);
  }

}
 
Example #23
Source File: RegistryCli.java    From big-c with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
public int resolve(String[] args) {
  Options resolveOption = new Options();
  CommandLineParser parser = new GnuParser();
  try {
    CommandLine line = parser.parse(resolveOption, args);

    List<String> argsList = line.getArgList();
    if (argsList.size() != 2) {
      return usageError("resolve requires exactly one path argument",
          RESOLVE_USAGE);
    }
    if (!validatePath(argsList.get(1))) {
      return -1;
    }

    try {
      ServiceRecord record = registry.resolve(argsList.get(1));

      for (Endpoint endpoint : record.external) {
        sysout.println(" Endpoint(ProtocolType="
                       + endpoint.protocolType + ", Api="
                       + endpoint.api + ");"
                       + " Addresses(AddressType="
                       + endpoint.addressType + ") are: ");

        for (Map<String, String> address : endpoint.addresses) {
          sysout.println("[ ");
          for (Map.Entry<String, String> entry : address.entrySet()) {
            sysout.print("\t" + entry.getKey()
                           + ":" + entry.getValue());
          }

          sysout.println("\n]");
        }
        sysout.println();
      }
      return 0;
    } catch (Exception e) {
      syserr.println(analyzeException("resolve", e, argsList));
    }
    return -1;
  } catch (ParseException exp) {
    return usageError("Invalid syntax " + exp, RESOLVE_USAGE);
  }

}
 
Example #24
Source File: RegistryTypeUtils.java    From big-c with Apache License 2.0 2 votes vote down vote up
/**
 * Create a URL endpoint from a list of URIs
 * @param api implemented API
 * @param protocolType protocol type
 * @param uris URIs
 * @return a new endpoint
 */
public static Endpoint urlEndpoint(String api,
    String protocolType,
    URI... uris) {
  return new Endpoint(api, protocolType, uris);
}
 
Example #25
Source File: RegistryTypeUtils.java    From big-c with Apache License 2.0 2 votes vote down vote up
/**
 * Create a Web UI endpoint from a list of URIs
 * @param api implemented API
 * @param uris URIs
 * @return a new endpoint
 */
public static Endpoint webEndpoint(String api,
    URI... uris) {
  return urlEndpoint(api, ProtocolTypes.PROTOCOL_WEBUI, uris);
}
 
Example #26
Source File: RegistryTypeUtils.java    From big-c with Apache License 2.0 2 votes vote down vote up
/**
 * Create a REST endpoint from a list of URIs
 * @param api implemented API
 * @param uris URIs
 * @return a new endpoint
 */
public static Endpoint restEndpoint(String api,
    URI... uris) {
  return urlEndpoint(api, ProtocolTypes.PROTOCOL_REST, uris);
}
 
Example #27
Source File: RegistryTypeUtils.java    From hadoop with Apache License 2.0 2 votes vote down vote up
/**
 * Create a URL endpoint from a list of URIs
 * @param api implemented API
 * @param protocolType protocol type
 * @param uris URIs
 * @return a new endpoint
 */
public static Endpoint urlEndpoint(String api,
    String protocolType,
    URI... uris) {
  return new Endpoint(api, protocolType, uris);
}
 
Example #28
Source File: RegistryTypeUtils.java    From hadoop with Apache License 2.0 2 votes vote down vote up
/**
 * Create a Web UI endpoint from a list of URIs
 * @param api implemented API
 * @param uris URIs
 * @return a new endpoint
 */
public static Endpoint webEndpoint(String api,
    URI... uris) {
  return urlEndpoint(api, ProtocolTypes.PROTOCOL_WEBUI, uris);
}
 
Example #29
Source File: RegistryTypeUtils.java    From hadoop with Apache License 2.0 2 votes vote down vote up
/**
 * Create a REST endpoint from a list of URIs
 * @param api implemented API
 * @param uris URIs
 * @return a new endpoint
 */
public static Endpoint restEndpoint(String api,
    URI... uris) {
  return urlEndpoint(api, ProtocolTypes.PROTOCOL_REST, uris);
}