Search in sources :

Example 11 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)

Example 12 with ServiceRecord

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

the class TestMarshalling method testUnmarshallWrongType.

@Test(expected = InvalidRecordException.class)
public void testUnmarshallWrongType() throws Throwable {
    byte[] bytes = "{'type':''}".getBytes();
    ServiceRecord serviceRecord = marshal.fromBytes("marshalling", bytes);
    RegistryTypeUtils.validateServiceRecord("validating", serviceRecord);
}
Also used : ServiceRecord(org.apache.hadoop.registry.client.types.ServiceRecord) Test(org.junit.Test)

Example 13 with ServiceRecord

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

the class RegistryCli method resolve.

@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);
    }
}
Also used : Options(org.apache.commons.cli.Options) GnuParser(org.apache.commons.cli.GnuParser) URISyntaxException(java.net.URISyntaxException) InvalidRecordException(org.apache.hadoop.registry.client.exceptions.InvalidRecordException) InvalidPathnameException(org.apache.hadoop.registry.client.exceptions.InvalidPathnameException) AuthenticationFailedException(org.apache.hadoop.registry.client.exceptions.AuthenticationFailedException) PathNotFoundException(org.apache.hadoop.fs.PathNotFoundException) NoRecordException(org.apache.hadoop.registry.client.exceptions.NoRecordException) IOException(java.io.IOException) ParseException(org.apache.commons.cli.ParseException) AccessControlException(org.apache.hadoop.security.AccessControlException) NoPathPermissionsException(org.apache.hadoop.registry.client.exceptions.NoPathPermissionsException) ServiceRecord(org.apache.hadoop.registry.client.types.ServiceRecord) CommandLine(org.apache.commons.cli.CommandLine) Endpoint(org.apache.hadoop.registry.client.types.Endpoint) CommandLineParser(org.apache.commons.cli.CommandLineParser) ParseException(org.apache.commons.cli.ParseException) Map(java.util.Map)

Example 14 with ServiceRecord

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

the class TestRegistryOperations method testOverwrite.

@Test
public void testOverwrite() throws Throwable {
    ServiceRecord written = putExampleServiceEntry(ENTRY_PATH, 0);
    ServiceRecord resolved1 = operations.resolve(ENTRY_PATH);
    resolved1.description = "resolved1";
    try {
        operations.bind(ENTRY_PATH, resolved1, 0);
        fail("overwrite succeeded when it should have failed");
    } catch (FileAlreadyExistsException expected) {
    // expected
    }
    // verify there's no changed
    ServiceRecord resolved2 = operations.resolve(ENTRY_PATH);
    assertMatches(written, resolved2);
    operations.bind(ENTRY_PATH, resolved1, BindFlags.OVERWRITE);
    ServiceRecord resolved3 = operations.resolve(ENTRY_PATH);
    assertMatches(resolved1, resolved3);
}
Also used : FileAlreadyExistsException(org.apache.hadoop.fs.FileAlreadyExistsException) ServiceRecord(org.apache.hadoop.registry.client.types.ServiceRecord) Test(org.junit.Test) AbstractRegistryTest(org.apache.hadoop.registry.AbstractRegistryTest)

Example 15 with ServiceRecord

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

the class TestRegistryOperations method testLsParent.

@Test
public void testLsParent() throws Throwable {
    ServiceRecord written = putExampleServiceEntry(ENTRY_PATH, 0);
    RegistryPathStatus stat = operations.stat(ENTRY_PATH);
    List<String> children = operations.list(PARENT_PATH);
    assertEquals(1, children.size());
    assertEquals(NAME, children.get(0));
    Map<String, RegistryPathStatus> childStats = RegistryUtils.statChildren(operations, PARENT_PATH);
    assertEquals(1, childStats.size());
    assertEquals(stat, childStats.get(NAME));
    Map<String, ServiceRecord> records = RegistryUtils.extractServiceRecords(operations, PARENT_PATH, childStats.values());
    assertEquals(1, records.size());
    ServiceRecord record = records.get(ENTRY_PATH);
    RegistryTypeUtils.validateServiceRecord(ENTRY_PATH, record);
    assertMatches(written, record);
}
Also used : RegistryPathStatus(org.apache.hadoop.registry.client.types.RegistryPathStatus) ServiceRecord(org.apache.hadoop.registry.client.types.ServiceRecord) Test(org.junit.Test) AbstractRegistryTest(org.apache.hadoop.registry.AbstractRegistryTest)

Aggregations

ServiceRecord (org.apache.hadoop.registry.client.types.ServiceRecord)42 Test (org.junit.Test)21 AbstractRegistryTest (org.apache.hadoop.registry.AbstractRegistryTest)14 IOException (java.io.IOException)10 RegistryPathStatus (org.apache.hadoop.registry.client.types.RegistryPathStatus)6 NoRecordException (org.apache.hadoop.registry.client.exceptions.NoRecordException)5 Endpoint (org.apache.hadoop.registry.client.types.Endpoint)5 HashMap (java.util.HashMap)4 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 URISyntaxException (java.net.URISyntaxException)3 Map (java.util.Map)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