@Override
  public String getInstanceID() {
    if (instanceId == null) {
      // want the instance id to be stable for the life of this instance object,
      // so only get it once
      String instanceNamePath = Constants.ZROOT + Constants.ZINSTANCES + "/" + instanceName;
      byte[] iidb = zooCache.get(instanceNamePath);
      if (iidb == null) {
        throw new RuntimeException(
            "Instance name "
                + instanceName
                + " does not exist in zookeeper.  Run \"accumulo org.apache.accumulo.server.util.ListInstances\" to see a list.");
      }
      instanceId = new String(iidb, Constants.UTF8);
    }

    if (zooCache.get(Constants.ZROOT + "/" + instanceId) == null) {
      if (instanceName == null)
        throw new RuntimeException("Instance id " + instanceId + " does not exist in zookeeper");
      throw new RuntimeException(
          "Instance id "
              + instanceId
              + " pointed to by the name "
              + instanceName
              + " does not exist in zookeeper");
    }

    return instanceId;
  }
Esempio n. 2
0
  private static SortedMap<String, String> getMap(Instance instance, boolean nameAsKey) {
    ZooCache zc = getZooCache(instance);

    List<String> tableIds = zc.getChildren(ZooUtil.getRoot(instance) + Constants.ZTABLES);

    TreeMap<String, String> tableMap = new TreeMap<String, String>();

    Map<String, String> namespaceIdToNameMap = new HashMap<String, String>();

    for (String tableId : tableIds) {
      byte[] tableName =
          zc.get(
              ZooUtil.getRoot(instance)
                  + Constants.ZTABLES
                  + "/"
                  + tableId
                  + Constants.ZTABLE_NAME);
      byte[] nId =
          zc.get(
              ZooUtil.getRoot(instance)
                  + Constants.ZTABLES
                  + "/"
                  + tableId
                  + Constants.ZTABLE_NAMESPACE);
      String namespaceName = Constants.DEFAULT_NAMESPACE;
      // create fully qualified table name
      if (nId != null) {
        String namespaceId = new String(nId, Constants.UTF8);
        if (!namespaceId.equals(Constants.DEFAULT_NAMESPACE_ID)) {
          try {
            namespaceName = namespaceIdToNameMap.get(namespaceId);
            if (namespaceName == null) {
              namespaceName = Namespaces.getNamespaceName(instance, namespaceId);
              namespaceIdToNameMap.put(namespaceId, namespaceName);
            }
          } catch (NamespaceNotFoundException e) {
            log.error(
                "Table ("
                    + tableId
                    + ") contains reference to namespace ("
                    + namespaceId
                    + ") that doesn't exist");
            continue;
          }
        }
      }
      if (tableName != null) {
        String tableNameStr = qualified(new String(tableName, Constants.UTF8), namespaceName);
        if (nameAsKey) tableMap.put(tableNameStr, tableId);
        else tableMap.put(tableId, tableNameStr);
      }
    }

    return tableMap;
  }
Esempio n. 3
0
  public static TableState getTableState(Instance instance, String tableId) {
    String statePath =
        ZooUtil.getRoot(instance) + Constants.ZTABLES + "/" + tableId + Constants.ZTABLE_STATE;
    ZooCache zc = getZooCache(instance);
    byte[] state = zc.get(statePath);
    if (state == null) return TableState.UNKNOWN;

    return TableState.valueOf(new String(state));
  }
Esempio n. 4
0
 public static String getNamespace(Instance instance, String tableId) {
   ZooCache zc = getZooCache(instance);
   byte[] n =
       zc.get(
           ZooUtil.getRoot(instance)
               + Constants.ZTABLES
               + "/"
               + tableId
               + Constants.ZTABLE_NAMESPACE);
   return new String(n, Constants.UTF8);
 }
 /** Given a zooCache and instanceId, look up the instance name. */
 public static String lookupInstanceName(ZooCache zooCache, UUID instanceId) {
   ArgumentChecker.notNull(zooCache, instanceId);
   for (String name : zooCache.getChildren(Constants.ZROOT + Constants.ZINSTANCES)) {
     String instanceNamePath = Constants.ZROOT + Constants.ZINSTANCES + "/" + name;
     byte[] bytes = zooCache.get(instanceNamePath);
     UUID iid = UUID.fromString(new String(bytes, Constants.UTF8));
     if (iid.equals(instanceId)) {
       return name;
     }
   }
   return null;
 }
  @Override
  public String getRootTabletLocation() {
    String zRootLocPath = ZooUtil.getRoot(this) + RootTable.ZROOT_TABLET_LOCATION;

    OpTimer opTimer =
        new OpTimer(log, Level.TRACE).start("Looking up root tablet location in zookeeper.");
    byte[] loc = zooCache.get(zRootLocPath);
    opTimer.stop(
        "Found root tablet at " + (loc == null ? null : new String(loc)) + " in %DURATION%");

    if (loc == null) {
      return null;
    }

    return new String(loc).split("\\|")[0];
  }