Search in sources :

Example 1 with ZKPathDumper

use of org.apache.hadoop.registry.client.impl.zk.ZKPathDumper in project hadoop by apache.

the class TestSecureRegistry method userZookeeperToCreateRoot.

/**
   * have the ZK user create the root dir.
   * This logs out the ZK user after and stops its curator instance,
   * to avoid contamination
   * @throws Throwable
   */
public void userZookeeperToCreateRoot() throws Throwable {
    System.setProperty("curator-log-events", "true");
    CuratorService curator = null;
    LoginContext login = login(ZOOKEEPER_LOCALHOST, ZOOKEEPER_CLIENT_CONTEXT, keytab_zk);
    try {
        logLoginDetails(ZOOKEEPER, login);
        RegistrySecurity.setZKSaslClientProperties(ZOOKEEPER, ZOOKEEPER_CLIENT_CONTEXT);
        curator = startCuratorServiceInstance("ZK", true);
        LOG.info(curator.toString());
        addToTeardown(curator);
        curator.zkMkPath("/", CreateMode.PERSISTENT, false, RegistrySecurity.WorldReadWriteACL);
        ZKPathDumper pathDumper = curator.dumpPath(true);
        LOG.info(pathDumper.toString());
    } finally {
        logout(login);
        ServiceOperations.stop(curator);
    }
}
Also used : LoginContext(javax.security.auth.login.LoginContext) ZKPathDumper(org.apache.hadoop.registry.client.impl.zk.ZKPathDumper) CuratorService(org.apache.hadoop.registry.client.impl.zk.CuratorService)

Example 2 with ZKPathDumper

use of org.apache.hadoop.registry.client.impl.zk.ZKPathDumper in project hadoop by apache.

the class TestRegistryRMOperations method testCreateComplexApplication.

/**
   * Create a complex example app
   * @throws Throwable
   */
@Test
public void testCreateComplexApplication() throws Throwable {
    String appId = "application_1408631738011_0001";
    String cid = "container_1408631738011_0001_01_";
    String cid1 = cid + "000001";
    String cid2 = cid + "000002";
    String appPath = USERPATH + "tomcat";
    ServiceRecord webapp = createRecord(appId, PersistencePolicies.APPLICATION, "tomcat-based web application", null);
    webapp.addExternalEndpoint(restEndpoint("www", new URI("http", "//loadbalancer/", null)));
    ServiceRecord comp1 = createRecord(cid1, PersistencePolicies.CONTAINER, null, null);
    comp1.addExternalEndpoint(restEndpoint("www", new URI("http", "//rack4server3:43572", null)));
    comp1.addInternalEndpoint(inetAddrEndpoint("jmx", "JMX", "rack4server3", 43573));
    // Component 2 has a container lifespan
    ServiceRecord comp2 = createRecord(cid2, PersistencePolicies.CONTAINER, null, null);
    comp2.addExternalEndpoint(restEndpoint("www", new URI("http", "//rack1server28:35881", null)));
    comp2.addInternalEndpoint(inetAddrEndpoint("jmx", "JMX", "rack1server28", 35882));
    operations.mknode(USERPATH, false);
    operations.bind(appPath, webapp, BindFlags.OVERWRITE);
    String componentsPath = appPath + RegistryConstants.SUBPATH_COMPONENTS;
    operations.mknode(componentsPath, false);
    String dns1 = RegistryPathUtils.encodeYarnID(cid1);
    String dns1path = componentsPath + dns1;
    operations.bind(dns1path, comp1, BindFlags.CREATE);
    String dns2 = RegistryPathUtils.encodeYarnID(cid2);
    String dns2path = componentsPath + dns2;
    operations.bind(dns2path, comp2, BindFlags.CREATE);
    ZKPathDumper pathDumper = registry.dumpPath(false);
    LOG.info(pathDumper.toString());
    logRecord("tomcat", webapp);
    logRecord(dns1, comp1);
    logRecord(dns2, comp2);
    ServiceRecord dns1resolved = operations.resolve(dns1path);
    assertEquals("Persistence policies on resolved entry", PersistencePolicies.CONTAINER, dns1resolved.get(YarnRegistryAttributes.YARN_PERSISTENCE, ""));
    Map<String, RegistryPathStatus> children = RegistryUtils.statChildren(operations, componentsPath);
    assertEquals(2, children.size());
    Collection<RegistryPathStatus> componentStats = children.values();
    Map<String, ServiceRecord> records = RegistryUtils.extractServiceRecords(operations, componentsPath, componentStats);
    assertEquals(2, records.size());
    ServiceRecord retrieved1 = records.get(dns1path);
    logRecord(retrieved1.get(YarnRegistryAttributes.YARN_ID, ""), retrieved1);
    assertMatches(dns1resolved, retrieved1);
    assertEquals(PersistencePolicies.CONTAINER, retrieved1.get(YarnRegistryAttributes.YARN_PERSISTENCE, ""));
    // create a listing under components/
    operations.mknode(componentsPath + "subdir", false);
    // this shows up in the listing of child entries
    Map<String, RegistryPathStatus> childrenUpdated = RegistryUtils.statChildren(operations, componentsPath);
    assertEquals(3, childrenUpdated.size());
    // the non-record child this is not picked up in the record listing
    Map<String, ServiceRecord> recordsUpdated = RegistryUtils.extractServiceRecords(operations, componentsPath, childrenUpdated);
    assertEquals(2, recordsUpdated.size());
    // now do some deletions.
    // synchronous delete container ID 2
    // fail if the app policy is chosen
    assertEquals(0, purge("/", cid2, PersistencePolicies.APPLICATION, RegistryAdminService.PurgePolicy.FailOnChildren));
    // succeed for container
    assertEquals(1, purge("/", cid2, PersistencePolicies.CONTAINER, RegistryAdminService.PurgePolicy.FailOnChildren));
    assertPathNotFound(dns2path);
    assertPathExists(dns1path);
    // expect a skip on children to skip
    assertEquals(0, purge("/", appId, PersistencePolicies.APPLICATION, RegistryAdminService.PurgePolicy.SkipOnChildren));
    assertPathExists(appPath);
    assertPathExists(dns1path);
    // attempt to delete app with policy of fail on children
    try {
        int p = purge("/", appId, PersistencePolicies.APPLICATION, RegistryAdminService.PurgePolicy.FailOnChildren);
        fail("expected a failure, got a purge count of " + p);
    } catch (PathIsNotEmptyDirectoryException expected) {
    // expected
    }
    assertPathExists(appPath);
    assertPathExists(dns1path);
    // now trigger recursive delete
    assertEquals(1, purge("/", appId, PersistencePolicies.APPLICATION, RegistryAdminService.PurgePolicy.PurgeAll));
    assertPathNotFound(appPath);
    assertPathNotFound(dns1path);
}
Also used : RegistryPathStatus(org.apache.hadoop.registry.client.types.RegistryPathStatus) ZKPathDumper(org.apache.hadoop.registry.client.impl.zk.ZKPathDumper) PathIsNotEmptyDirectoryException(org.apache.hadoop.fs.PathIsNotEmptyDirectoryException) URI(java.net.URI) RegistryTypeUtils.restEndpoint(org.apache.hadoop.registry.client.binding.RegistryTypeUtils.restEndpoint) RegistryTypeUtils.inetAddrEndpoint(org.apache.hadoop.registry.client.binding.RegistryTypeUtils.inetAddrEndpoint) ServiceRecord(org.apache.hadoop.registry.client.types.ServiceRecord) Test(org.junit.Test) AbstractRegistryTest(org.apache.hadoop.registry.AbstractRegistryTest)

Example 3 with ZKPathDumper

use of org.apache.hadoop.registry.client.impl.zk.ZKPathDumper in project hadoop by apache.

the class TestRegistryRMOperations method testPurgeEntryCuratorCallback.

@Test
public void testPurgeEntryCuratorCallback() throws Throwable {
    String path = "/users/example/hbase/hbase1/";
    ServiceRecord written = buildExampleServiceEntry(PersistencePolicies.APPLICATION_ATTEMPT);
    written.set(YarnRegistryAttributes.YARN_ID, "testAsyncPurgeEntry_attempt_001");
    operations.mknode(RegistryPathUtils.parentOf(path), true);
    operations.bind(path, written, 0);
    ZKPathDumper dump = registry.dumpPath(false);
    CuratorEventCatcher events = new CuratorEventCatcher();
    LOG.info("Initial state {}", dump);
    // container query
    String id = written.get(YarnRegistryAttributes.YARN_ID, "");
    int opcount = purge("/", id, PersistencePolicies.CONTAINER, RegistryAdminService.PurgePolicy.PurgeAll, events);
    assertPathExists(path);
    assertEquals(0, opcount);
    assertEquals("Event counter", 0, events.getCount());
    // now the application attempt
    opcount = purge("/", id, PersistencePolicies.APPLICATION_ATTEMPT, RegistryAdminService.PurgePolicy.PurgeAll, events);
    LOG.info("Final state {}", dump);
    assertPathNotFound(path);
    assertEquals("wrong no of delete operations in " + dump, 1, opcount);
    // and validate the callback event
    assertEquals("Event counter", 1, events.getCount());
}
Also used : ZKPathDumper(org.apache.hadoop.registry.client.impl.zk.ZKPathDumper) RegistryTypeUtils.restEndpoint(org.apache.hadoop.registry.client.binding.RegistryTypeUtils.restEndpoint) RegistryTypeUtils.inetAddrEndpoint(org.apache.hadoop.registry.client.binding.RegistryTypeUtils.inetAddrEndpoint) ServiceRecord(org.apache.hadoop.registry.client.types.ServiceRecord) CuratorEventCatcher(org.apache.hadoop.registry.client.impl.CuratorEventCatcher) Test(org.junit.Test) AbstractRegistryTest(org.apache.hadoop.registry.AbstractRegistryTest)

Example 4 with ZKPathDumper

use of org.apache.hadoop.registry.client.impl.zk.ZKPathDumper in project hadoop by apache.

the class TestSecureRMRegistryOperations method testDigestAccess.

@Test
public void testDigestAccess() throws Throwable {
    RMRegistryOperationsService registryAdmin = startRMRegistryOperations();
    String id = "username";
    String pass = "password";
    registryAdmin.addWriteAccessor(id, pass);
    List<ACL> clientAcls = registryAdmin.getClientAcls();
    LOG.info("Client ACLS=\n{}", RegistrySecurity.aclsToString(clientAcls));
    String base = "/digested";
    registryAdmin.mknode(base, false);
    List<ACL> baseACLs = registryAdmin.zkGetACLS(base);
    String aclset = RegistrySecurity.aclsToString(baseACLs);
    LOG.info("Base ACLs=\n{}", aclset);
    ACL found = null;
    for (ACL acl : baseACLs) {
        if (ZookeeperConfigOptions.SCHEME_DIGEST.equals(acl.getId().getScheme())) {
            found = acl;
            break;
        }
    }
    assertNotNull("Did not find digest entry in ACLs " + aclset, found);
    zkClientConf.set(KEY_REGISTRY_USER_ACCOUNTS, "sasl:somebody@EXAMPLE.COM, sasl:other");
    RegistryOperations operations = RegistryOperationsFactory.createAuthenticatedInstance(zkClientConf, id, pass);
    addToTeardown(operations);
    operations.start();
    RegistryOperationsClient operationsClient = (RegistryOperationsClient) operations;
    List<ACL> digestClientACLs = operationsClient.getClientAcls();
    LOG.info("digest client ACLs=\n{}", RegistrySecurity.aclsToString(digestClientACLs));
    operations.stat(base);
    operations.mknode(base + "/subdir", false);
    ZKPathDumper pathDumper = registryAdmin.dumpPath(true);
    LOG.info(pathDumper.toString());
}
Also used : ZKPathDumper(org.apache.hadoop.registry.client.impl.zk.ZKPathDumper) RegistryOperationsClient(org.apache.hadoop.registry.client.impl.RegistryOperationsClient) ACL(org.apache.zookeeper.data.ACL) RegistryOperations(org.apache.hadoop.registry.client.api.RegistryOperations) RMRegistryOperationsService(org.apache.hadoop.registry.server.integration.RMRegistryOperationsService) Test(org.junit.Test)

Example 5 with ZKPathDumper

use of org.apache.hadoop.registry.client.impl.zk.ZKPathDumper in project hadoop by apache.

the class TestSecureRMRegistryOperations method testZookeeperCanWriteUnderSystem.

/**
   * test that ZK can write as itself
   * @throws Throwable
   */
@Test
public void testZookeeperCanWriteUnderSystem() throws Throwable {
    RMRegistryOperationsService rmRegistryOperations = startRMRegistryOperations();
    RegistryOperations operations = rmRegistryOperations;
    operations.mknode(PATH_SYSTEM_SERVICES + "hdfs", false);
    ZKPathDumper pathDumper = rmRegistryOperations.dumpPath(true);
    LOG.info(pathDumper.toString());
}
Also used : ZKPathDumper(org.apache.hadoop.registry.client.impl.zk.ZKPathDumper) RegistryOperations(org.apache.hadoop.registry.client.api.RegistryOperations) RMRegistryOperationsService(org.apache.hadoop.registry.server.integration.RMRegistryOperationsService) Test(org.junit.Test)

Aggregations

ZKPathDumper (org.apache.hadoop.registry.client.impl.zk.ZKPathDumper)6 Test (org.junit.Test)5 AbstractRegistryTest (org.apache.hadoop.registry.AbstractRegistryTest)3 RegistryTypeUtils.inetAddrEndpoint (org.apache.hadoop.registry.client.binding.RegistryTypeUtils.inetAddrEndpoint)3 RegistryTypeUtils.restEndpoint (org.apache.hadoop.registry.client.binding.RegistryTypeUtils.restEndpoint)3 ServiceRecord (org.apache.hadoop.registry.client.types.ServiceRecord)3 RegistryOperations (org.apache.hadoop.registry.client.api.RegistryOperations)2 RMRegistryOperationsService (org.apache.hadoop.registry.server.integration.RMRegistryOperationsService)2 URI (java.net.URI)1 LoginContext (javax.security.auth.login.LoginContext)1 PathIsNotEmptyDirectoryException (org.apache.hadoop.fs.PathIsNotEmptyDirectoryException)1 CuratorEventCatcher (org.apache.hadoop.registry.client.impl.CuratorEventCatcher)1 RegistryOperationsClient (org.apache.hadoop.registry.client.impl.RegistryOperationsClient)1 CuratorService (org.apache.hadoop.registry.client.impl.zk.CuratorService)1 RegistryPathStatus (org.apache.hadoop.registry.client.types.RegistryPathStatus)1 DeleteCompletionCallback (org.apache.hadoop.registry.server.services.DeleteCompletionCallback)1 ACL (org.apache.zookeeper.data.ACL)1