Example #1
0
  /**
   * Parse project config from config file
   *
   * @param configFile filen name of the config file
   * @param localAddr address of the current master node
   * @return the project meta
   * @throws KeeperException throws when write project meta to zookeeper
   * @throws InterruptedException if the zookeeper server transaction is interrupted
   */
  private ProjectMeta parseProjectConfig(String configFile, String localAddr)
      throws KeeperException, InterruptedException {
    ProjectMeta projectMeta = new ProjectMeta(configFile, localAddr);
    checkBasicNode(projectMeta);

    String projectPath = Utils.getProjectRootPath(projectMeta.getProjectName());
    MasterMeta masterMeta =
        new MasterMeta(projectMeta.getMasterAddr(), projectMeta.getPackageRoot());
    byte[] data = JsonUtils.getObjectData(masterMeta);
    zk.setData(projectPath, data, -1);

    writePackageInfo(projectMeta);

    return projectMeta;
  }
Example #2
0
  /**
   * Write packages info of project to zookeeper
   *
   * @param projectMeta project meta
   * @throws KeeperException throws when write project meta to zookeeper
   * @throws InterruptedException if the zookeeper server transaction is interrupted
   */
  private void writePackageInfo(ProjectMeta projectMeta)
      throws KeeperException, InterruptedException {
    String projectMetaPath = Utils.getProjectMetaRootPath(projectMeta.getProjectName());

    List<String> packageNameList = projectMeta.getTopoOrderPackageList();

    for (String pkgName : packageNameList) {
      PackageMeta packageMeta = projectMeta.getPackageMeta(pkgName);

      String packagePath = Utils.constructString(projectMetaPath, Global.PATH_SEPARATOR, pkgName);
      byte[] packageInfo = JsonUtils.getObjectData(packageMeta);
      // write package info
      if (!Utils.checkNode(zk, packagePath)) {
        zk.create(packagePath, packageInfo, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
      } else {
        zk.setData(packagePath, packageInfo, -1);
      }
    }
  }