Search in sources :

Example 1 with ServiceRecord

use of org.apache.hadoop.registry.client.types.ServiceRecord in project hadoop by apache.

the class RegistryUtils method extractServiceRecords.

/**
   * Extract all service records under a list of stat operations...this
   * skips entries that are too short or simply not matching
   * @param operations operation support for fetches
   * @param parentpath path of the parent of all the entries
   * @param stats Collection of stat results
   * @return a possibly empty map of fullpath:record.
   * @throws IOException for any IO Operation that wasn't ignored.
   */
public static Map<String, ServiceRecord> extractServiceRecords(RegistryOperations operations, String parentpath, Collection<RegistryPathStatus> stats) throws IOException {
    Map<String, ServiceRecord> results = new HashMap<String, ServiceRecord>(stats.size());
    for (RegistryPathStatus stat : stats) {
        if (stat.size > ServiceRecord.RECORD_TYPE.length()) {
            // maybe has data
            String path = join(parentpath, stat.path);
            try {
                ServiceRecord serviceRecord = operations.resolve(path);
                results.put(path, serviceRecord);
            } catch (EOFException ignored) {
                if (LOG.isDebugEnabled()) {
                    LOG.debug("data too short for {}", path);
                }
            } catch (InvalidRecordException record) {
                if (LOG.isDebugEnabled()) {
                    LOG.debug("Invalid record at {}", path);
                }
            } catch (NoRecordException record) {
                if (LOG.isDebugEnabled()) {
                    LOG.debug("No record at {}", path);
                }
            }
        }
    }
    return results;
}
Also used : RegistryPathStatus(org.apache.hadoop.registry.client.types.RegistryPathStatus) HashMap(java.util.HashMap) EOFException(java.io.EOFException) NoRecordException(org.apache.hadoop.registry.client.exceptions.NoRecordException) InvalidRecordException(org.apache.hadoop.registry.client.exceptions.InvalidRecordException) ServiceRecord(org.apache.hadoop.registry.client.types.ServiceRecord)

Example 2 with ServiceRecord

use of org.apache.hadoop.registry.client.types.ServiceRecord in project hadoop by apache.

the class RegistryOperationsService method resolve.

@Override
public ServiceRecord resolve(String path) throws IOException {
    byte[] bytes = zkRead(path);
    ServiceRecord record = serviceRecordMarshal.fromBytes(path, bytes, ServiceRecord.RECORD_TYPE);
    RegistryTypeUtils.validateServiceRecord(path, record);
    return record;
}
Also used : ServiceRecord(org.apache.hadoop.registry.client.types.ServiceRecord)

Example 3 with ServiceRecord

use of org.apache.hadoop.registry.client.types.ServiceRecord in project hadoop by apache.

the class AbstractRegistryTest method putExampleServiceEntry.

/**
   * Create a service entry with the sample endpoints, and put it
   * at the destination
   * @param path path
   * @param createFlags flags
   * @return the record
   * @throws IOException on a failure
   */
protected ServiceRecord putExampleServiceEntry(String path, int createFlags, String persistence) throws IOException, URISyntaxException {
    ServiceRecord record = buildExampleServiceEntry(persistence);
    registry.mknode(RegistryPathUtils.parentOf(path), true);
    operations.bind(path, record, createFlags);
    return record;
}
Also used : ServiceRecord(org.apache.hadoop.registry.client.types.ServiceRecord)

Example 4 with ServiceRecord

use of org.apache.hadoop.registry.client.types.ServiceRecord in project hadoop by apache.

the class RegistryTestHelper method buildExampleServiceEntry.

/**
   * Create a service entry with the sample endpoints
   * @param persistence persistence policy
   * @return the record
   * @throws IOException on a failure
   */
public static ServiceRecord buildExampleServiceEntry(String persistence) throws IOException, URISyntaxException {
    ServiceRecord record = new ServiceRecord();
    record.set(YarnRegistryAttributes.YARN_ID, "example-0001");
    record.set(YarnRegistryAttributes.YARN_PERSISTENCE, persistence);
    addSampleEndpoints(record, "namenode");
    return record;
}
Also used : ServiceRecord(org.apache.hadoop.registry.client.types.ServiceRecord)

Example 5 with ServiceRecord

use of org.apache.hadoop.registry.client.types.ServiceRecord in project hadoop by apache.

the class RegistryTestHelper method createRecord.

public static ServiceRecord createRecord(String id, String persistence, String description) {
    ServiceRecord serviceRecord = new ServiceRecord();
    serviceRecord.set(YarnRegistryAttributes.YARN_ID, id);
    serviceRecord.description = description;
    serviceRecord.set(YarnRegistryAttributes.YARN_PERSISTENCE, persistence);
    return serviceRecord;
}
Also used : ServiceRecord(org.apache.hadoop.registry.client.types.ServiceRecord)

Aggregations

ServiceRecord (org.apache.hadoop.registry.client.types.ServiceRecord)39 Test (org.junit.Test)21 AbstractRegistryTest (org.apache.hadoop.registry.AbstractRegistryTest)14 IOException (java.io.IOException)9 RegistryPathStatus (org.apache.hadoop.registry.client.types.RegistryPathStatus)6 NoRecordException (org.apache.hadoop.registry.client.exceptions.NoRecordException)5 ParseException (org.apache.commons.cli.ParseException)4 PathNotFoundException (org.apache.hadoop.fs.PathNotFoundException)4 RegistryTypeUtils.inetAddrEndpoint (org.apache.hadoop.registry.client.binding.RegistryTypeUtils.inetAddrEndpoint)4 RegistryTypeUtils.restEndpoint (org.apache.hadoop.registry.client.binding.RegistryTypeUtils.restEndpoint)4 InvalidRecordException (org.apache.hadoop.registry.client.exceptions.InvalidRecordException)4 Endpoint (org.apache.hadoop.registry.client.types.Endpoint)4 URISyntaxException (java.net.URISyntaxException)3 HashMap (java.util.HashMap)3 PathIsNotEmptyDirectoryException (org.apache.hadoop.fs.PathIsNotEmptyDirectoryException)3 ZKPathDumper (org.apache.hadoop.registry.client.impl.zk.ZKPathDumper)3 EOFException (java.io.EOFException)2 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)2 URI (java.net.URI)2 Map (java.util.Map)2