コード例 #1
0
  private boolean isStaleConfiguration(Configuration config) {
    String delimiter = "-";
    String configId = config.getId();

    // Bypasses item of "global" and folders of "version", just check db configurations.
    if (configId == null || configId.equals(Constants.GLOBAL_ID) || !configId.contains(delimiter)) {
      return false;
    }

    if (_serviceInfo.getId().endsWith(Constants.STANDALONE_ID)) {
      if (!configId.equals(_serviceInfo.getId())) {
        return true;
      }
    } else {
      CoordinatorClientInetAddressMap nodeMap = _coordinator.getInetAddessLookupMap();
      int nodeCount = nodeMap.getControllerNodeIPLookupMap().size();

      String nodeIndex = configId.split(delimiter)[1];
      if (Constants.STANDALONE_ID.equalsIgnoreCase(nodeIndex)
          || Integer.parseInt(nodeIndex) > nodeCount) {
        return true;
      }
    }
    return false;
  }
コード例 #2
0
  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;
  }
コード例 #3
0
  /**
   * We select seeds based on the following rules - For DR standby sites, use all nodes in active
   * site as seeds For DR active site, use local nodes as seeds. The rule to select local seed is -
   * first boot node(AUTOBOOT = false) uses itself as seed nodes so that it could boot and
   * initialize schema - subsquent node(AUTOBOOT = true) uses other successfully booted(JOINED =
   * true) nodes as seeds
   */
  @Override
  public List<InetAddress> getSeeds() {
    try {
      CoordinatorClientInetAddressMap nodeMap = _client.getInetAddessLookupMap();
      List<Configuration> configs =
          _client.queryAllConfiguration(_client.getSiteId(), Constants.DB_CONFIG);
      List<InetAddress> seeds = new ArrayList<>();

      // If we are upgrading from pre-2.5 releases, dbconfig exists in zk global area
      List<Configuration> leftoverConfig = _client.queryAllConfiguration(Constants.DB_CONFIG);
      configs.addAll(leftoverConfig);

      // Add extra seeds - seeds from remote sites
      for (String seed : extraSeeds) {
        if (StringUtils.isNotEmpty(seed)) {
          seeds.add(InetAddress.getByName(seed));
        }
      }
      // On DR standby site, only use seeds from active site. On active site
      // we use local seeds
      if (isDrActiveSite) {
        for (int i = 0; i < configs.size(); i++) {
          Configuration config = configs.get(i);
          // Bypasses item of "global" and folders of "version", just check db configurations.
          if (config.getId() == null || config.getId().equals(Constants.GLOBAL_ID)) {
            continue;
          }
          String nodeIndex = config.getId().split("-")[1];
          String nodeId = config.getConfig(DbConfigConstants.NODE_ID);
          if (nodeId == null) {
            // suppose that they are existing znodes from a previous version
            // set the NODE_ID config, id is like db-x
            nodeId = "vipr" + nodeIndex;
            config.setConfig(DbConfigConstants.NODE_ID, nodeId);
            config.removeConfig(DbConfigConstants.DB_IP);
            _client.persistServiceConfiguration(_client.getSiteId(), config);
          }
          if (!Boolean.parseBoolean(config.getConfig(DbConfigConstants.AUTOBOOT))
              || (!config.getId().equals(_id)
                  && Boolean.parseBoolean(config.getConfig(DbConfigConstants.JOINED)))) {
            // all non autobootstrap nodes + other nodes are used as seeds
            InetAddress ip = null;
            if (nodeMap != null) {
              String ipAddress = nodeMap.getConnectableInternalAddress(nodeId);
              _logger.debug("ip[" + i + "]: " + ipAddress);
              ip = InetAddress.getByName(ipAddress);
            } else {
              ip = InetAddress.getByName(nodeId);
            }
            seeds.add(ip);
            _logger.info("Seed {}", ip);
          }
        }
      }

      _logger.info("Seeds list {}", StringUtils.join(seeds.toArray(), ","));
      return seeds;
    } catch (Exception e) {
      throw new IllegalStateException(e);
    }
  }