Beispiel #1
0
  /**
   * Read project meta from zookeeper
   *
   * @param projectName name of the project
   * @return project meta
   * @throws KeeperException throws when write project meta to zookeeper
   * @throws InterruptedException if the zookeeper server transaction is interrupted
   */
  private ProjectMeta constrcutProjectMeta(String projectName)
      throws KeeperException, InterruptedException {
    ProjectMeta projectMeta = null;

    String packageRoot = null;
    String masterAddr = null;

    String projectPath = Utils.getProjectRootPath(projectName);
    byte[] b = zk.getData(projectPath, false, null);

    // read the master meta
    MasterMeta maserMeta = JsonUtils.getObject(b, MasterMeta.class);

    packageRoot = maserMeta.getPackageRoot();
    masterAddr = maserMeta.getMasterAddr();

    String projectMetaPath = Utils.getProjectMetaRootPath(projectName);

    List<String> packageNameList = zk.getChildren(projectMetaPath, false);

    // read package list
    projectMeta =
        new ProjectMeta(
            projectName,
            masterAddr,
            packageRoot,
            readPackageInfo(projectMetaPath, packageNameList));

    return projectMeta;
  }
Beispiel #2
0
  /**
   * Read package info from zookeeper.
   *
   * @param packageRootPath the root path of the packages
   * @param packageNameList the list of package names
   * @return the list of package metas
   * @throws KeeperException throws when write project meta to zookeeper
   * @throws InterruptedException if the zookeeper server transaction is interrupted
   */
  private List<PackageMeta> readPackageInfo(String packageRootPath, List<String> packageNameList)
      throws KeeperException, InterruptedException {
    List<PackageMeta> packageMetaList = new ArrayList<PackageMeta>();

    for (String pkgName : packageNameList) {
      String packagePath = Utils.constructString(packageRootPath, Global.PATH_SEPARATOR, pkgName);
      // read package data and construct the meta object
      byte[] data = zk.getData(packagePath, false, null);
      PackageMeta packageMeta = JsonUtils.getObject(data, PackageMeta.class);

      packageMetaList.add(packageMeta);
    }

    return packageMetaList;
  }