org.elasticsearch.Version.fromString()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(8.5k)|赞(0)|评价(0)|浏览(136)

本文整理了Java中org.elasticsearch.Version.fromString()方法的一些代码示例,展示了Version.fromString()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Version.fromString()方法的具体详情如下:
包路径:org.elasticsearch.Version
类名称:Version
方法名:fromString

Version.fromString介绍

[英]Returns the version given its string representation, current version if the argument is null or empty
[中]返回给定字符串表示形式的版本,如果参数为null或空,则返回当前版本

代码示例

代码示例来源:origin: org.elasticsearch/elasticsearch

"property [elasticsearch.version] is missing for plugin [" + name + "]");
final Version esVersion = Version.fromString(esVersionString);
final String javaVersionString = propsMap.remove("java.version");
if (javaVersionString == null) {

代码示例来源:origin: com.strapdata.elasticsearch.test/framework

private Version[] parseVersionRange(String versionRange) {
  if (versionRange == null) {
    return new Version[] { null, null };
  }
  if (versionRange.trim().equals("all")) {
    return new Version[]{VersionUtils.getFirstVersion(), Version.CURRENT};
  }
  String[] skipVersions = versionRange.split("-");
  if (skipVersions.length > 2) {
    throw new IllegalArgumentException("version range malformed: " + versionRange);
  }
  String lower = skipVersions[0].trim();
  String upper = skipVersions[1].trim();
  return new Version[] {
    lower.isEmpty() ? VersionUtils.getFirstVersion() : Version.fromString(lower),
    upper.isEmpty() ? Version.CURRENT : Version.fromString(upper)
  };
}

代码示例来源:origin: com.strapdata.elasticsearch.test/framework

public static Path getIndexDir(
  final Logger logger,
  final String indexName,
  final String indexFile,
  final Path dataDir) throws IOException {
  final Version version = Version.fromString(indexName.substring("index-".length()));
  if (version.before(Version.V_5_0_0_alpha1)) {
    // the bwc scripts packs the indices under this path
    Path src = dataDir.resolve("nodes/0/indices/" + indexName);
    assertTrue("[" + indexFile + "] missing index dir: " + src.toString(), Files.exists(src));
    return src;
  } else {
    final List<Path> indexFolders = new ArrayList<>();
    try (DirectoryStream<Path> stream = Files.newDirectoryStream(dataDir.resolve("0/indices"),
      (p) -> p.getFileName().toString().startsWith("extra") == false)) { // extra FS can break this...
      for (final Path path : stream) {
        indexFolders.add(path);
      }
    }
    assertThat(indexFolders.toString(), indexFolders.size(), equalTo(1));
    final IndexMetaData indexMetaData = IndexMetaData.FORMAT.loadLatestState(logger, NamedXContentRegistry.EMPTY,
      indexFolders.get(0));
    assertNotNull(indexMetaData);
    assertThat(indexFolders.get(0).getFileName().toString(), equalTo(indexMetaData.getIndexUUID()));
    assertThat(indexMetaData.getCreationVersion(), equalTo(version));
    return indexFolders.get(0);
  }
}

代码示例来源:origin: harbby/presto-connectors

throw new IllegalArgumentException("Property [elasticsearch.version] is missing for jvm plugin [" + name + "]");
Version esVersion = Version.fromString(esVersionString);
if (esVersion.equals(Version.CURRENT) == false) {
  throw new IllegalArgumentException("Plugin [" + name + "] is incompatible with Elasticsearch [" + Version.CURRENT.toString() +

代码示例来源:origin: com.strapdata.elasticsearch.test/framework

private static Tuple<Version, Version> readVersionsFromCatNodes(RestClient restClient) throws IOException {
  // we simply go to the _cat/nodes API and parse all versions in the cluster
  Response response = restClient.performRequest("GET", "/_cat/nodes", Collections.singletonMap("h", "version,master"));
  ClientYamlTestResponse restTestResponse = new ClientYamlTestResponse(response);
  String nodesCatResponse = restTestResponse.getBodyAsString();
  String[] split = nodesCatResponse.split("\n");
  Version version = null;
  Version masterVersion = null;
  for (String perNode : split) {
    final String[] versionAndMaster = perNode.split("\\s+");
    assert versionAndMaster.length == 2 : "invalid line: " + perNode + " length: " + versionAndMaster.length;
    final Version currentVersion = Version.fromString(versionAndMaster[0]);
    final boolean master = versionAndMaster[1].trim().equals("*");
    if (master) {
      assert masterVersion == null;
      masterVersion = currentVersion;
    }
    if (version == null) {
      version = currentVersion;
    } else if (version.onOrAfter(currentVersion)) {
      version = currentVersion;
    }
  }
  return new Tuple<>(version, masterVersion);
}

代码示例来源:origin: com.strapdata.elasticsearch.test/framework

private static Version readVersionsFromInfo(RestClient restClient, int numHosts) throws IOException {
  Version version = null;
  for (int i = 0; i < numHosts; i++) {
    //we don't really use the urls here, we rely on the client doing round-robin to touch all the nodes in the cluster
    Response response = restClient.performRequest("GET", "/");
    ClientYamlTestResponse restTestResponse = new ClientYamlTestResponse(response);
    Object latestVersion = restTestResponse.evaluate("version.number");
    if (latestVersion == null) {
      throw new RuntimeException("elasticsearch version not found in the response");
    }
    final Version currentVersion = Version.fromString(latestVersion.toString());
    if (version == null) {
      version = currentVersion;
    } else if (version.onOrAfter(currentVersion)) {
      version = currentVersion;
    }
  }
  return version;
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.elasticsearch

"property [elasticsearch.version] is missing for plugin [" + name + "]");
final Version esVersion = Version.fromString(esVersionString);
final String javaVersionString = propsMap.remove("java.version");
if (javaVersionString == null) {

代码示例来源:origin: apache/servicemix-bundles

"property [elasticsearch.version] is missing for plugin [" + name + "]");
final Version esVersion = Version.fromString(esVersionString);
final String javaVersionString = propsMap.remove("java.version");
if (javaVersionString == null) {

代码示例来源:origin: com.strapdata.elasticsearch/elasticsearch

"property [elasticsearch.version] is missing for plugin [" + name + "]");
final Version esVersion = Version.fromString(esVersionString);
if (esVersion.equals(Version.CURRENT) == false) {
  final String message = String.format(

代码示例来源:origin: com.strapdata.elasticsearch.test/framework

public void testHandshakeWithIncompatVersion() {
  assumeTrue("only tcp transport has a handshake method", serviceA.getOriginalTransport() instanceof TcpTransport);
  NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry(Collections.emptyList());
  Version version = Version.fromString("2.0.0");
  try (MockTcpTransport transport = new MockTcpTransport(Settings.EMPTY, threadPool, BigArrays.NON_RECYCLING_INSTANCE,
    new NoneCircuitBreakerService(), namedWriteableRegistry, new NetworkService(Collections.emptyList()), version);
     MockTransportService service = MockTransportService.createNewService(Settings.EMPTY, transport, version, threadPool, null,
       Collections.emptySet())) {
    service.start();
    service.acceptIncomingRequests();
    DiscoveryNode node =
      new DiscoveryNode("TS_TPC", "TS_TPC", transport.boundAddress().publishAddress(), emptyMap(), emptySet(), version0);
    ConnectionProfile.Builder builder = new ConnectionProfile.Builder();
    builder.addConnections(1,
      TransportRequestOptions.Type.BULK,
      TransportRequestOptions.Type.PING,
      TransportRequestOptions.Type.RECOVERY,
      TransportRequestOptions.Type.REG,
      TransportRequestOptions.Type.STATE);
    expectThrows(ConnectTransportException.class, () -> serviceA.openConnection(node, builder.build()));
  }
}

代码示例来源:origin: com.strapdata.elasticsearch.test/framework

public void testHandshakeUpdatesVersion() throws IOException {
  assumeTrue("only tcp transport has a handshake method", serviceA.getOriginalTransport() instanceof TcpTransport);
  NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry(Collections.emptyList());
  Version version = VersionUtils.randomVersionBetween(random(), Version.CURRENT.minimumCompatibilityVersion(), Version.CURRENT);
  try (MockTcpTransport transport = new MockTcpTransport(Settings.EMPTY, threadPool, BigArrays.NON_RECYCLING_INSTANCE,
    new NoneCircuitBreakerService(), namedWriteableRegistry, new NetworkService(Collections.emptyList()), version);
     MockTransportService service = MockTransportService.createNewService(Settings.EMPTY, transport, version, threadPool, null,
       Collections.emptySet())) {
    service.start();
    service.acceptIncomingRequests();
    DiscoveryNode node =
      new DiscoveryNode("TS_TPC", "TS_TPC", transport.boundAddress().publishAddress(), emptyMap(), emptySet(),
        Version.fromString("2.0.0"));
    ConnectionProfile.Builder builder = new ConnectionProfile.Builder();
    builder.addConnections(1,
      TransportRequestOptions.Type.BULK,
      TransportRequestOptions.Type.PING,
      TransportRequestOptions.Type.RECOVERY,
      TransportRequestOptions.Type.REG,
      TransportRequestOptions.Type.STATE);
    try (Transport.Connection connection = serviceA.openConnection(node, builder.build())) {
      assertEquals(connection.getVersion(), version);
    }
  }
}

相关文章