org.batfish.common.Version.isCompatibleVersion()方法的使用及代码示例

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

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

Version.isCompatibleVersion介绍

[英]Returns true if the given version of some other endpoint is compatible with the Batfish version of this process.

At the time of writing, compatibility is determined on having identical major and minor versions.
[中]如果某个其他端点的给定版本与此进程的蝙蝠鱼版本兼容,则返回true。
在撰写本文时,兼容性取决于是否有相同的主要版本和次要版本。

代码示例

代码示例来源:origin: batfish/batfish

static void checkCompatibleVersion(
  String myName, String myVersion, String otherName, @Nullable String otherVersion) {
 checkArgument(
   isCompatibleVersion(myName, myVersion, otherName, otherVersion),
   "%s version: '%s' is not compatible with %s version: '%s'",
   otherName,
   otherVersion,
   myName,
   myVersion);
}

代码示例来源:origin: batfish/batfish

/**
 * Returns {@code true} if the given version of some other endpoint is compatible with the Batfish
 * version of this process.
 *
 * <p>At the time of writing, compatibility is determined on having identical major and minor
 * versions.
 */
public static boolean isCompatibleVersion(
  String myName, String otherName, @Nullable String otherVersion) {
 return isCompatibleVersion(myName, getVersion(), otherName, otherVersion);
}

代码示例来源:origin: batfish/batfish

@Override
 public void filter(ContainerRequestContext requestContext) {
  String clientVersion = requestContext.getHeaderString(HTTP_HEADER_BATFISH_VERSION);
  if (Strings.isNullOrEmpty(clientVersion)) {
   requestContext.abortWith(
     Response.status(Status.BAD_REQUEST)
       .entity(
         String.format(
           "HTTP header %s should contain a client version",
           HTTP_HEADER_BATFISH_VERSION))
       .type(MediaType.APPLICATION_JSON)
       .build());
  } else if (!Version.isCompatibleVersion("Service", "Client", clientVersion)) {
   requestContext.abortWith(
     Response.status(Status.BAD_REQUEST)
       .entity(
         String.format(
           "Client version '%s' is not compatible with server version '%s'",
           clientVersion, Version.getVersion()))
       .type(MediaType.APPLICATION_JSON)
       .build());
  }
 }
}

代码示例来源:origin: batfish/batfish

private boolean cachedConfigsAreCompatible(NetworkId network, SnapshotId snapshot) {
 try {
  ConvertConfigurationAnswerElement ccae =
    loadConvertConfigurationAnswerElement(network, snapshot);
  return ccae != null
    && Version.isCompatibleVersion(
      FileBasedStorage.class.getCanonicalName(),
      "Old processed configurations",
      ccae.getVersion());
 } catch (BatfishException e) {
  _logger.warnf(
    "Unexpected exception caught while deserializing configs for snapshot %s: %s",
    snapshot, Throwables.getStackTraceAsString(e));
  return false;
 }
}

代码示例来源:origin: batfish/batfish

Arrays.asList(CoordConsts.SVC_KEY_FAILURE, "Worker version not specified"));
if (!Version.isCompatibleVersion("Service", "Worker", workerVersion)) {
 return new JSONArray(
   Arrays.asList(

代码示例来源:origin: batfish/batfish

@Override
public SortedMap<String, BgpAdvertisementsByVrf> loadEnvironmentBgpTables() {
 NetworkSnapshot snapshot = getNetworkSnapshot();
 SortedMap<String, BgpAdvertisementsByVrf> environmentBgpTables =
   _cachedEnvironmentBgpTables.get(snapshot);
 if (environmentBgpTables == null) {
  ParseEnvironmentBgpTablesAnswerElement ae = loadParseEnvironmentBgpTablesAnswerElement();
  if (!Version.isCompatibleVersion(
    "Service", "Old processed environment BGP tables", ae.getVersion())) {
   repairEnvironmentBgpTables();
  }
  environmentBgpTables =
    deserializeEnvironmentBgpTables(_testrigSettings.getSerializeEnvironmentBgpTablesPath());
  _cachedEnvironmentBgpTables.put(snapshot, environmentBgpTables);
 }
 return environmentBgpTables;
}

代码示例来源:origin: batfish/batfish

@Test
public void isCompatibleVersion() {
 // identical versions
 assertTrue(Version.isCompatibleVersion("foo", "1.2.3", "other", "1.2.3"));
 // compatible versions, different patch version
 assertTrue(Version.isCompatibleVersion("foo", "1.2.3", "other", "1.2.4"));
 // mine unknown
 assertTrue(Version.isCompatibleVersion("foo", UNKNOWN_VERSION, "other", "1.2.4"));
 // other unknown
 assertTrue(Version.isCompatibleVersion("foo", "1.2.3", "other", UNKNOWN_VERSION));
 // SNAPSHOT
 assertTrue(Version.isCompatibleVersion("foo", "1.2.3", "other", "1.2.3-SNAPSHOT"));
 // Other newer minor
 assertFalse(Version.isCompatibleVersion("foo", "1.2.3", "other", "1.3.3"));
 // Other newer major
 assertFalse(Version.isCompatibleVersion("foo", "1.2.3", "other", "2.2.3"));
 // Other older minor
 assertFalse(Version.isCompatibleVersion("foo", "1.2.3", "other", "1.1.3"));
 // Other older major
 assertFalse(Version.isCompatibleVersion("foo", "1.2.3", "other", "0.2.3"));
}

代码示例来源:origin: batfish/batfish

@Override
public SortedMap<String, RoutesByVrf> loadEnvironmentRoutingTables() {
 NetworkSnapshot snapshot = getNetworkSnapshot();
 SortedMap<String, RoutesByVrf> environmentRoutingTables =
   _cachedEnvironmentRoutingTables.get(snapshot);
 if (environmentRoutingTables == null) {
  ParseEnvironmentRoutingTablesAnswerElement pertae =
    loadParseEnvironmentRoutingTablesAnswerElement();
  if (!Version.isCompatibleVersion(
    "Service", "Old processed environment routing tables", pertae.getVersion())) {
   repairEnvironmentRoutingTables();
  }
  environmentRoutingTables =
    deserializeEnvironmentRoutingTables(
      _testrigSettings.getSerializeEnvironmentRoutingTablesPath());
  _cachedEnvironmentRoutingTables.put(snapshot, environmentRoutingTables);
 }
 return environmentRoutingTables;
}

代码示例来源:origin: batfish/batfish

private void repairConfigurations() {
 ParseVendorConfigurationAnswerElement pvcae = loadParseVendorConfigurationAnswerElement();
 if (!Version.isCompatibleVersion("Service", "Old parsed configurations", pvcae.getVersion())) {
  repairVendorConfigurations();
 }
 Path inputPath = _testrigSettings.getSerializeVendorPath();
 serializeIndependentConfigs(inputPath);
}

代码示例来源:origin: batfish/batfish

private ParseVendorConfigurationAnswerElement loadParseVendorConfigurationAnswerElement(
  boolean firstAttempt) {
 if (Files.exists(_testrigSettings.getParseAnswerPath())) {
  ParseVendorConfigurationAnswerElement pvcae =
    deserializeObject(
      _testrigSettings.getParseAnswerPath(), ParseVendorConfigurationAnswerElement.class);
  if (Version.isCompatibleVersion(
    "Service", "Old processed configurations", pvcae.getVersion())) {
   return pvcae;
  }
 }
 if (firstAttempt) {
  repairVendorConfigurations();
  return loadParseVendorConfigurationAnswerElement(false);
 } else {
  throw new BatfishException(
    "Version error repairing vendor configurations for parse configuration answer element");
 }
}

代码示例来源:origin: batfish/batfish

@Test
public void illegalVersions() {
 _thrown.expect(BatfishException.class);
 _thrown.expectMessage("Illegal version 'zebra' for yours");
 Version.isCompatibleVersion("my", "1.2.3", "yours", "zebra");
}

代码示例来源:origin: batfish/batfish

private ParseEnvironmentBgpTablesAnswerElement loadParseEnvironmentBgpTablesAnswerElement(
  boolean firstAttempt) {
 Path answerPath = _testrigSettings.getParseEnvironmentBgpTablesAnswerPath();
 if (!Files.exists(answerPath)) {
  repairEnvironmentBgpTables();
 }
 ParseEnvironmentBgpTablesAnswerElement ae =
   deserializeObject(answerPath, ParseEnvironmentBgpTablesAnswerElement.class);
 if (!Version.isCompatibleVersion(
   "Service", "Old processed environment BGP tables", ae.getVersion())) {
  if (firstAttempt) {
   repairEnvironmentRoutingTables();
   return loadParseEnvironmentBgpTablesAnswerElement(false);
  } else {
   throw new BatfishException(
     "Version error repairing environment BGP tables for parse environment BGP tables "
       + "answer element");
  }
 } else {
  return ae;
 }
}

代码示例来源:origin: batfish/batfish

@Override
public ConvertConfigurationAnswerElement loadConvertConfigurationAnswerElementOrReparse() {
 ConvertConfigurationAnswerElement ccae =
   _storage.loadConvertConfigurationAnswerElement(
     _settings.getContainer(), _testrigSettings.getName());
 if (ccae != null
   && Version.isCompatibleVersion(
     "Service", "Old processed configurations", ccae.getVersion())) {
  return ccae;
 }
 repairConfigurations();
 ccae =
   _storage.loadConvertConfigurationAnswerElement(
     _settings.getContainer(), _testrigSettings.getName());
 if (ccae != null
   && Version.isCompatibleVersion(
     "Service", "Old processed configurations", ccae.getVersion())) {
  return ccae;
 } else {
  throw new BatfishException(
    "Version error repairing configurations for convert configuration answer element");
 }
}

代码示例来源:origin: batfish/batfish

private ParseEnvironmentRoutingTablesAnswerElement loadParseEnvironmentRoutingTablesAnswerElement(
  boolean firstAttempt) {
 Path answerPath = _testrigSettings.getParseEnvironmentRoutingTablesAnswerPath();
 if (!Files.exists(answerPath)) {
  repairEnvironmentRoutingTables();
 }
 ParseEnvironmentRoutingTablesAnswerElement pertae =
   deserializeObject(answerPath, ParseEnvironmentRoutingTablesAnswerElement.class);
 if (!Version.isCompatibleVersion(
   "Service", "Old processed environment routing tables", pertae.getVersion())) {
  if (firstAttempt) {
   repairEnvironmentRoutingTables();
   return loadParseEnvironmentRoutingTablesAnswerElement(false);
  } else {
   throw new BatfishException(
     "Version error repairing environment routing tables for parse environment routing "
       + "tables answer element");
  }
 } else {
  return pertae;
 }
}

代码示例来源:origin: batfish/batfish

private DataPlaneAnswerElement loadDataPlaneAnswerElement(
  boolean compressed, boolean firstAttempt) {
 Path answerPath =
   compressed
     ? _testrigSettings.getCompressedDataPlaneAnswerPath()
     : _testrigSettings.getDataPlaneAnswerPath();
 DataPlaneAnswerElement bae = deserializeObject(answerPath, DataPlaneAnswerElement.class);
 if (!Version.isCompatibleVersion("Service", "Old data plane", bae.getVersion())) {
  if (firstAttempt) {
   repairDataPlane(compressed);
   return loadDataPlaneAnswerElement(compressed, false);
  } else {
   throw new BatfishException(
     "Version error repairing data plane for data plane answer element");
  }
 } else {
  return bae;
 }
}

代码示例来源:origin: batfish/batfish

@Test
public void loadOldConfigurationsReturnsNull() {
 ConvertConfigurationAnswerElement oldConvertAnswer = new ConvertConfigurationAnswerElement();
 oldConvertAnswer.setVersion(INCOMPATIBLE_VERSION);
 assertThat(
   "should not be compatible with current code",
   Version.isCompatibleVersion("current", "old test", oldConvertAnswer.getVersion()),
   equalTo(false));
 NetworkId network = new NetworkId("network");
 SnapshotId snapshot = new SnapshotId("snapshot");
 Map<String, Configuration> configs = new HashMap<>();
 configs.put("node1", new Configuration("node1", ConfigurationFormat.CISCO_IOS));
 _storage.storeConfigurations(configs, oldConvertAnswer, network, snapshot);
 assertThat(_storage.loadConfigurations(network, snapshot), nullValue());
}

相关文章