/**
   * This constructor's argument is from cassandral's yaml configuration. Here is an example
   * seed_provider: - class_name: com.emc.storageos.db.server.impl.SeedProviderImpl parameters: -
   * coordinators: "coordinator://127.0.0.1:2181, coordinator://127.0.0.1:3181,
   * coordinator://127.0.0.1:4181" id: "db-one
   *
   * @param args
   * @throws Exception
   */
  public SeedProviderImpl(Map<String, String> args) throws Exception {
    // get current node id
    _id = args.get(ID);
    if (_id == null) {
      throw new IllegalArgumentException(ID);
    }

    // seed nodes in remote data centers
    String seedsArg = args.get(SEEDS);
    String[] seedIPs = null;
    if (seedsArg != null && !seedsArg.trim().isEmpty()) {
      seedIPs = seedsArg.split(",", -1);
    }
    if (seedIPs != null) {
      // multiple site - assume seeds in other site is available
      // so just pick from config file
      for (String ip : seedIPs) {
        extraSeeds.add(ip);
      }
    }

    // setup zk connection
    String coordinatorArg = args.get(COORDINATORS);
    if (coordinatorArg == null || coordinatorArg.trim().isEmpty()) {
      throw new IllegalArgumentException(COORDINATORS);
    }

    String[] coordinators = coordinatorArg.split(",", -1);
    List<URI> uri = new ArrayList<URI>(coordinators.length);
    for (String coord : coordinators) {
      if (!coord.trim().isEmpty()) {
        uri.add(URI.create(coord.trim()));
      }
    }

    ZkConnection connection = new ZkConnection();
    connection.setServer(uri);
    String siteId = args.get(Constants.SITE_ID_FILE);
    connection.setSiteIdFile(siteId);
    connection.build();

    CoordinatorClientImpl client = new CoordinatorClientImpl();
    client.setZkConnection(connection);

    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("/nodeaddrmap-var.xml");
    CoordinatorClientInetAddressMap inetAddressMap =
        (CoordinatorClientInetAddressMap) ctx.getBean("inetAddessLookupMap");
    if (inetAddressMap == null) {
      _logger.error(
          "CoordinatorClientInetAddressMap is not initialized. Node address lookup will fail.");
    }
    client.setInetAddessLookupMap(inetAddressMap); // HARCODE FOR NOW
    client.start();
    drUtil = new DrUtil(client);
    isDrActiveSite = drUtil.isActiveSite();

    _client = client;
  }
  public static DbClientImpl newDBClient() throws Exception {
    ZkConnection zkConnection = new ZkConnection();
    zkConnection.setServer(Lists.newArrayList(new URI("coordinator://localhost:2181")));
    zkConnection.build();

    DualInetAddress dualInetAddress = DualInetAddress.fromAddresses("127.0.0.1", "::1");
    Map<String, DualInetAddress> addresses = Maps.newHashMap();
    addresses.put("localhost", dualInetAddress);

    CoordinatorClientInetAddressMap map = new CoordinatorClientInetAddressMap();
    map.setNodeId("standalone");
    map.setDualInetAddress(dualInetAddress);
    map.setControllerNodeIPLookupMap(addresses);

    CoordinatorClientImpl coordinatorClient = new CoordinatorClientImpl();
    coordinatorClient.setZkConnection(zkConnection);
    coordinatorClient.setInetAddessLookupMap(map);
    coordinatorClient.start();

    DbClientContext localContext = new DbClientContext();
    localContext.setKeyspaceName("StorageOS");
    localContext.setClusterName("StorageOs");

    DbClientContext geoContext = new DbClientContext();
    geoContext.setKeyspaceName("GeoStorageOs");
    geoContext.setClusterName("GeoStorageOs");

    DbVersionInfo versionInfo = new DbVersionInfo();
    versionInfo.setSchemaVersion("2.0");

    DbClientImpl client = new DbClientImpl();
    client.setDbVersionInfo(versionInfo);
    client.setLocalContext(localContext);
    client.setGeoContext(geoContext);
    client.setCoordinatorClient(coordinatorClient);
    client.setLocalContext(new DbClientContext());

    client.start();

    VdcUtil.setDbClient(client);

    return client;
  }