org.apache.hadoop.registry.client.binding.RegistryUtils Java Examples

The following examples show how to use org.apache.hadoop.registry.client.binding.RegistryUtils. 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: TestRegistryOperations.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #2
Source File: Executor.java    From jstorm with Apache License 2.0 6 votes vote down vote up
public boolean needUpgrade() {
    String containerPath = RegistryUtils.componentPath(
            JOYConstants.APP_TYPE, this.executorMeta.getInstanceName(),
            this.executorMeta.getApplicationId(), this.executorMeta.getRunningContainer());

    try {
        if (registryOperations.exists(containerPath)) {
            ServiceRecord sr = registryOperations.resolve(containerPath);
            if (sr.get(JOYConstants.NEED_UPGRADE) != null && sr.get(JOYConstants.NEED_UPGRADE).equals(JOYConstants.TRUE)) {
                sr.set(JOYConstants.NEED_UPGRADE, JOYConstants.FALSE);
                registryOperations.bind(containerPath, sr, BindFlags.OVERWRITE);
                LOG.info(JOYConstants.NEED_UPGRADE);
                return true;
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    return false;
}
 
Example #3
Source File: TestRegistryOperations.java    From big-c with Apache License 2.0 6 votes vote down vote up
@Test
public void testComplexUsernames() throws Throwable {
  operations.mknode("/users/user with spaces", true);
  operations.mknode("/users/user-with_underscores", true);
  operations.mknode("/users/000000", true);
  operations.mknode("/users/-storm", true);
  operations.mknode("/users/windows\\ user", true);
  String home = RegistryUtils.homePathForUser("\u0413PA\u0414_3");
  operations.mknode(home, true);
  operations.mknode(
      RegistryUtils.servicePath(home, "service.class", "service 4_5"),
      true);

  operations.mknode(
      RegistryUtils.homePathForUser("[email protected]"),
      true);
  operations.mknode(
      RegistryUtils.homePathForUser("hbase/[email protected]"),
      true);
  home = RegistryUtils.homePathForUser("ADMINISTRATOR/127.0.0.1");
  assertTrue("No 'administrator' in " + home, home.contains("administrator"));
  operations.mknode(
      home,
      true);

}
 
Example #4
Source File: TestRegistryOperations.java    From big-c with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #5
Source File: SlotPortsView.java    From jstorm with Apache License 2.0 6 votes vote down vote up
public String getSupervisorSlotPorts(int memory, int vcores, String supervisorHost) throws Exception {

        String hostPath = RegistryUtils.servicePath(
                JOYConstants.APP_TYPE, this.instanceName, supervisorHost);

        tryHostLock(hostPath);
        try {
            List<String> relist;
            int slotCount = getSlotCount(memory, vcores);

            LOG.info("slotCount:" + slotCount);
            relist = getSetPortUsedBySupervisor(supervisorHost, slotCount);
            LOG.info("get ports string:" + JstormYarnUtils.join(relist, JOYConstants.COMMA, false));

            return JstormYarnUtils.join(relist, JOYConstants.COMMA, false);
        } catch (Exception e) {
            LOG.error(e);
            throw e;
        } finally {
            releaseHostLock(hostPath);
        }
    }
 
Example #6
Source File: TestRegistryOperations.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Test
public void testComplexUsernames() throws Throwable {
  operations.mknode("/users/user with spaces", true);
  operations.mknode("/users/user-with_underscores", true);
  operations.mknode("/users/000000", true);
  operations.mknode("/users/-storm", true);
  operations.mknode("/users/windows\\ user", true);
  String home = RegistryUtils.homePathForUser("\u0413PA\u0414_3");
  operations.mknode(home, true);
  operations.mknode(
      RegistryUtils.servicePath(home, "service.class", "service 4_5"),
      true);

  operations.mknode(
      RegistryUtils.homePathForUser("[email protected]"),
      true);
  operations.mknode(
      RegistryUtils.homePathForUser("hbase/[email protected]"),
      true);
  home = RegistryUtils.homePathForUser("ADMINISTRATOR/127.0.0.1");
  assertTrue("No 'administrator' in " + home, home.contains("administrator"));
  operations.mknode(
      home,
      true);

}
 
Example #7
Source File: JstormMaster.java    From PoseidonX with Apache License 2.0 6 votes vote down vote up
/**
 * JstormAM 的构造函数
 */
public JstormMaster() throws IOException {
    conf = new YarnConfiguration();
    Path jstormYarnConfPath = new Path("jstorm-yarn.xml");
    conf.addResource(jstormYarnConfPath);

    JstormAMContext.serviceUserName = RegistryUtils.currentUser();
    LOG.error("### JstormAMContext.serviceUserName:["+JstormAMContext.serviceUserName+"]");
    registryClient = RegistryClient.init(JstormAMConstant.REGISTRY_JSTORM_YARN,JstormAMContext.serviceUserName,conf);
    slotPortsView = new SlotPortsView(registryClient);
    slotPortsView.setMinPort(JstormAMConstant.SUPERVISOR_MIN_PORT);
    slotPortsView.setMaxPort(JstormAMConstant.SUPERVISOR_MAX_PORT);
    JstormAMContext.requestBlockingQueue = new LinkedBlockingQueue<ContainerRequest>();

    JstormAMContext.currentNimbusNum = new AtomicInteger(0);
    JstormAMContext.currentSupervisorNum = new AtomicInteger(0);
}
 
Example #8
Source File: RegistryClient.java    From PoseidonX with Apache License 2.0 5 votes vote down vote up
public static String getContainerPath(ContainerId containerId){
    String applicationId = containerId.getApplicationAttemptId().getApplicationId().toString();

    String containerIdStr = containerId.toString();
    String containerPath = RegistryUtils.componentPath(
            JstormAMConstant.REGISTYR_APP_TYPE, JstormAMContext.clusterName,applicationId,containerIdStr);
    return containerPath;
}
 
Example #9
Source File: YarnRegistryViewForProviders.java    From jstorm with Apache License 2.0 5 votes vote down vote up
/**
 * Add a component 
 * @param serviceClass service class to use under ~user
 * @param componentName component name
 * @param record record to put
 * @throws IOException
 */
public void putComponent(String serviceClass,
    String serviceName,
    String componentName,
    ServiceRecord record) throws IOException {
  String path = RegistryUtils.componentPath(
      user, serviceClass, serviceName, componentName);
  registryOperations.mknode(RegistryPathUtils.parentOf(path), true);
  registryOperations.bind(path, record, BindFlags.OVERWRITE);
}
 
Example #10
Source File: TestRegistryOperations.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Test
public void testListListFully() throws Throwable {
  ServiceRecord r1 = new ServiceRecord();
  ServiceRecord r2 = createRecord("i",
      PersistencePolicies.PERMANENT, "r2");

  String path = USERPATH + SC_HADOOP + "/listing" ;
  operations.mknode(path, true);
  String r1path = path + "/r1";
  operations.bind(r1path, r1, 0);
  String r2path = path + "/r2";
  operations.bind(r2path, r2, 0);

  RegistryPathStatus r1stat = operations.stat(r1path);
  assertEquals("r1", r1stat.path);
  RegistryPathStatus r2stat = operations.stat(r2path);
  assertEquals("r2", r2stat.path);
  assertNotEquals(r1stat, r2stat);

  // listings now
  List<String> list = operations.list(path);
  assertEquals("Wrong no. of children", 2, list.size());
  // there's no order here, so create one
  Map<String, String> names = new HashMap<String, String>();
  String entries = "";
  for (String child : list) {
    names.put(child, child);
    entries += child + " ";
  }
  assertTrue("No 'r1' in " + entries,
      names.containsKey("r1"));
  assertTrue("No 'r2' in " + entries,
      names.containsKey("r2"));

  Map<String, RegistryPathStatus> stats =
      RegistryUtils.statChildren(operations, path);
  assertEquals("Wrong no. of children", 2, stats.size());
  assertEquals(r1stat, stats.get("r1"));
  assertEquals(r2stat, stats.get("r2"));
}
 
Example #11
Source File: RegistryClient.java    From PoseidonX with Apache License 2.0 5 votes vote down vote up
public static String getContainerPath(Container container){
    String applicationId = container.getId().getApplicationAttemptId().getApplicationId().toString();

    String containerId = container.getId().toString();
    String containerPath = RegistryUtils.componentPath(
            JstormAMConstant.REGISTYR_APP_TYPE, JstormAMContext.clusterName,applicationId,containerId);
    return containerPath;
}
 
Example #12
Source File: YarnRegistryViewForProviders.java    From jstorm with Apache License 2.0 5 votes vote down vote up
/**
 * Add a service under a path, optionally purging any history
 * @param username user
 * @param serviceClass service class to use under ~user
 * @param serviceName name of the service
 * @param record service record
 * @param deleteTreeFirst perform recursive delete of the path first.
 * @return the path the service was created at
 * @throws IOException
 */
public String putService(String username,
    String serviceClass,
    String serviceName,
    ServiceRecord record,
    boolean deleteTreeFirst) throws IOException {
  String path = RegistryUtils.servicePath(
      username, serviceClass, serviceName);
  if (deleteTreeFirst) {
    registryOperations.delete(path, true);
  }
  registryOperations.mknode(RegistryPathUtils.parentOf(path), true);
  registryOperations.bind(path, record, BindFlags.OVERWRITE);
  return path;
}
 
Example #13
Source File: YarnRegistryViewForProviders.java    From jstorm with Apache License 2.0 5 votes vote down vote up
/**
 * Delete a component
 * @param componentName component name
 * @throws IOException
 */
public void deleteComponent(String componentName) throws IOException {
  String path = RegistryUtils.componentPath(
      user, jstormServiceClass, instanceName,
      componentName);
  registryOperations.delete(path, false);
}
 
Example #14
Source File: TestRegistryOperations.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Test
public void testListListFully() throws Throwable {
  ServiceRecord r1 = new ServiceRecord();
  ServiceRecord r2 = createRecord("i",
      PersistencePolicies.PERMANENT, "r2");

  String path = USERPATH + SC_HADOOP + "/listing" ;
  operations.mknode(path, true);
  String r1path = path + "/r1";
  operations.bind(r1path, r1, 0);
  String r2path = path + "/r2";
  operations.bind(r2path, r2, 0);

  RegistryPathStatus r1stat = operations.stat(r1path);
  assertEquals("r1", r1stat.path);
  RegistryPathStatus r2stat = operations.stat(r2path);
  assertEquals("r2", r2stat.path);
  assertNotEquals(r1stat, r2stat);

  // listings now
  List<String> list = operations.list(path);
  assertEquals("Wrong no. of children", 2, list.size());
  // there's no order here, so create one
  Map<String, String> names = new HashMap<String, String>();
  String entries = "";
  for (String child : list) {
    names.put(child, child);
    entries += child + " ";
  }
  assertTrue("No 'r1' in " + entries,
      names.containsKey("r1"));
  assertTrue("No 'r2' in " + entries,
      names.containsKey("r2"));

  Map<String, RegistryPathStatus> stats =
      RegistryUtils.statChildren(operations, path);
  assertEquals("Wrong no. of children", 2, stats.size());
  assertEquals(r1stat, stats.get("r1"));
  assertEquals(r2stat, stats.get("r2"));
}
 
Example #15
Source File: Executor.java    From jstorm with Apache License 2.0 5 votes vote down vote up
/**
 * TODO: purge this once RM is doing the work
 *
 * @throws IOException
 */
protected void setupInitialRegistryPaths() throws IOException {
    if (registryOperations instanceof RMRegistryOperationsService) {
        RMRegistryOperationsService rmRegOperations =
                (RMRegistryOperationsService) registryOperations;
        rmRegOperations.initUserRegistryAsync(RegistryUtils.currentUser());
    }
}
 
Example #16
Source File: ContainersView.java    From jstorm with Apache License 2.0 4 votes vote down vote up
public String getHostPath() {
    String hostPath = RegistryUtils.servicePath(
            JstormKeys.APP_TYPE, this.instanceName, host);
    return hostPath;
}
 
Example #17
Source File: YarnZkRegistryBusiness.java    From PoseidonX with Apache License 2.0 4 votes vote down vote up
public static String componentListPath(String clusterName, String applicationId){
    String containerPath = RegistryUtils.componentListPath(YarnZkContant.ZK_AM_REGISTYR_APP_TYPE, clusterName,applicationId);
    return containerPath;
}
 
Example #18
Source File: RegistryClient.java    From PoseidonX with Apache License 2.0 4 votes vote down vote up
public static String getApplicationPath(){
    String applicationPath = RegistryUtils.servicePath(JstormAMConstant.REGISTYR_APP_TYPE,JstormAMContext.clusterName,JstormAMContext.applicationId.toString());
    return applicationPath;
}
 
Example #19
Source File: RegistryClient.java    From PoseidonX with Apache License 2.0 4 votes vote down vote up
public static String getHostPath(String host){
    String hostPath = RegistryUtils.servicePath(JstormAMConstant.REGISTYR_APP_TYPE,JstormAMConstant.REGISTYR_GLOBAL_HOST,host);
    return hostPath;
}
 
Example #20
Source File: RegistryClient.java    From PoseidonX with Apache License 2.0 4 votes vote down vote up
public static String getGlobalPath(){
    String hostPath = RegistryUtils.serviceclassPath(JstormAMConstant.REGISTYR_APP_TYPE,JstormAMConstant.REGISTYR_GLOBAL_HOST);
    return hostPath;
}
 
Example #21
Source File: RegistryAdminService.java    From big-c with Apache License 2.0 2 votes vote down vote up
/**
 * Get the path to a user's home dir
 * @param username username
 * @return a path for services underneath
 */
protected String homeDir(String username) {
  return RegistryUtils.homePathForUser(username);
}
 
Example #22
Source File: RegistryAdminService.java    From hadoop with Apache License 2.0 2 votes vote down vote up
/**
 * Get the path to a user's home dir
 * @param username username
 * @return a path for services underneath
 */
protected String homeDir(String username) {
  return RegistryUtils.homePathForUser(username);
}