public override IEnumerable <Bundle <TBundleVersion> > Filter <TBundleVersion>(string argValue, IEnumerable <Bundle <TBundleVersion> > bundles) { var majorMinor = MajorMinorVersion.FromInput(argValue); return(bundles .Where(bundle => bundle.Version.MajorMinor.Equals(majorMinor))); }
internal void TestEquality(string input1, string input2) { var majorMinor1 = MajorMinorVersion.FromInput(input1); var majorMinor2 = MajorMinorVersion.FromInput(input2); EqualityComparisonTestUtils <MajorMinorVersion> .TestEquality(majorMinor1, majorMinor2); }
internal void TestInequality(string lower, string higher) { var lowerMajorMinor = MajorMinorVersion.FromInput(lower); var higherMajorMinor = MajorMinorVersion.FromInput(higher); EqualityComparisonTestUtils <MajorMinorVersion> .TestInequality(lowerMajorMinor, higherMajorMinor); }
private static void AddPluginToPluginPackageInfos(IMinerPlugin plugin) { var version = new MajorMinorVersion(plugin.Version.Major, plugin.Version.Minor); string pluginPackageURL = null; if (version.major == 3) { pluginPackageURL = "https://github.com/nicehash/NHM_MinerPluginsDownloads/releases/download/v3.x/" + GetPluginPackageName(plugin); } else if (version.major == 4) { pluginPackageURL = "https://github.com/nicehash/NHM_MinerPluginsDownloads/releases/download/v4.x/" + GetPluginPackageName(plugin); } else { //throw new Exception("Plugin version not supported"); } string minerPackageURL = null; if (plugin is IMinerBinsSource binsSource) { minerPackageURL = binsSource.GetMinerBinsUrlsForPlugin().FirstOrDefault(); } var binaryVersion = "N/A"; // TODO binary version if (plugin is IGetMinerBinaryVersion binVersionGetter) { binaryVersion = binVersionGetter.GetMinerBinaryVersion(); } PluginMetaInfo pluginMetaInfo = null; if (plugin is IGetPluginMetaInfo pluginMetaInfoGetter) { pluginMetaInfo = pluginMetaInfoGetter.GetPluginMetaInfo(); } if (pluginMetaInfo == null) { return; } var packageInfo = new PluginPackageInfoForJson { PluginUUID = plugin.PluginUUID, PluginAuthor = "*****@*****.**", PluginName = plugin.Name, PluginVersion = version, PluginPackageURL = pluginPackageURL, MinerPackageURL = minerPackageURL, SupportedDevicesAlgorithms = TransformToPluginPackageInfoSupportedDevicesAlgorithms(pluginMetaInfo.SupportedDevicesAlgorithms), // TODO enhance this with the bins version PluginDescription = $"Miner Binary Version '{binaryVersion}'.\n\n" + pluginMetaInfo.PluginDescription }; PluginPackageInfos.Add(packageInfo); }
internal void TestFromInputReject(string input) { Action action = () => MajorMinorVersion.FromInput(input); action.Should().Throw <InvalidInputVersionException>(string.Format(LocalizableStrings.InvalidInputVersionExceptionMessageFormat, input)); MajorMinorVersion.TryFromInput(input, out var majorMinor) .Should().BeFalse(); }
internal void TestFromInput(string input, int major, int minor) { var majorMinor = MajorMinorVersion.FromInput(input); TestProperties(majorMinor, major, minor); MajorMinorVersion.TryFromInput(input, out majorMinor) .Should().BeTrue(); TestProperties(majorMinor, major, minor); }
private Cache BuildCache(MajorMinorVersion version, ImmutableDictionary <GrainType, GrainBindings> bindings) { var newPredicates = new List <BroadcastChannelSubscriberPredicate>(); foreach (var binding in bindings.Values) { foreach (var grainBinding in binding.Bindings) { if (!grainBinding.TryGetValue(WellKnownGrainTypeProperties.BindingTypeKey, out var type) || !string.Equals(type, WellKnownGrainTypeProperties.BroadcastChannelBindingTypeValue, StringComparison.Ordinal)) { continue; } if (!grainBinding.TryGetValue(WellKnownGrainTypeProperties.BroadcastChannelBindingPatternKey, out var pattern)) { throw new KeyNotFoundException( $"Channel binding for grain type {binding.GrainType} is missing a \"{WellKnownGrainTypeProperties.BroadcastChannelBindingPatternKey}\" value"); } IChannelNamespacePredicate predicate = null; foreach (var provider in _providers) { if (provider.TryGetPredicate(pattern, out predicate)) { break; } } if (predicate is null) { throw new KeyNotFoundException( $"Could not find an {nameof(IChannelNamespacePredicate)} for the pattern \"{pattern}\"." + $" Ensure that a corresponding {nameof(IChannelNamespacePredicateProvider)} is registered"); } if (!grainBinding.TryGetValue(WellKnownGrainTypeProperties.ChannelIdMapperKey, out var mapperName)) { throw new KeyNotFoundException( $"Channel binding for grain type {binding.GrainType} is missing a \"{WellKnownGrainTypeProperties.ChannelIdMapperKey}\" value"); } var channelIdMapper = _serviceProvider.GetServiceByName <IChannelIdMapper>(string.IsNullOrWhiteSpace(mapperName) ? DefaultChannelIdMapper.Name : mapperName); var subscriber = new BroadcastChannelSubscriber(binding, channelIdMapper); newPredicates.Add(new BroadcastChannelSubscriberPredicate(subscriber, predicate)); } } return(new Cache(version, newPredicates)); }
private static PluginPackageInfoForJson ToPluginToPluginPackageInfos(IMinerPlugin plugin) { var version = new MajorMinorVersion(plugin.Version.Major, plugin.Version.Minor); if (!Checkers.IsMajorVersionSupported(version.major)) { throw new Exception($"Plugin version '{version.major}' not supported. Make sure you add the download link for this version"); } string minerPackageURL = null; if (plugin is IMinerBinsSource binsSource) { minerPackageURL = binsSource.GetMinerBinsUrlsForPlugin().FirstOrDefault(); } var binaryVersion = "N/A"; // TODO binary version if (plugin is IGetMinerBinaryVersion binVersionGetter) { binaryVersion = binVersionGetter.GetMinerBinaryVersion(); } PluginMetaInfo pluginMetaInfo = null; if (plugin is IGetPluginMetaInfo pluginMetaInfoGetter) { pluginMetaInfo = pluginMetaInfoGetter.GetPluginMetaInfo(); } if (pluginMetaInfo == null) { return(null); } var packagePassword = plugin is IGetBinsPackagePassword p ? p.BinsPackagePassword : null; var packageInfo = new PluginPackageInfoForJson { PluginUUID = plugin.PluginUUID, PluginAuthor = "*****@*****.**", PluginName = plugin.Name, PluginVersion = version, PluginPackageURL = $"https://github.com/nicehash/NHM_MinerPluginsDownloads/releases/download/v{version.major}.x/" + GetPluginPackageName(plugin), MinerPackageURL = minerPackageURL, SupportedDevicesAlgorithms = TransformToPluginPackageInfoSupportedDevicesAlgorithms(pluginMetaInfo.SupportedDevicesAlgorithms), // TODO enhance this with the bins version PluginDescription = $"Miner Binary Version '{binaryVersion}'.\n\n" + pluginMetaInfo.PluginDescription, PackagePassword = packagePassword }; return(packageInfo); }
private Cache BuildCache(MajorMinorVersion version, ImmutableDictionary <GrainType, GrainBindings> bindings) { var newPredicates = new List <StreamSubscriberPredicate>(); foreach (var binding in bindings.Values) { foreach (var grainBinding in binding.Bindings) { if (!grainBinding.TryGetValue(WellKnownGrainTypeProperties.BindingTypeKey, out var type) || !string.Equals(type, WellKnownGrainTypeProperties.StreamBindingTypeValue, StringComparison.Ordinal)) { continue; } if (!grainBinding.TryGetValue(WellKnownGrainTypeProperties.StreamBindingPatternKey, out var pattern)) { throw new KeyNotFoundException( $"Stream binding for grain type {binding.GrainType} is missing a \"{WellKnownGrainTypeProperties.StreamBindingPatternKey}\" value"); } IStreamNamespacePredicate predicate = null; foreach (var provider in _providers) { if (provider.TryGetPredicate(pattern, out predicate)) { break; } } if (predicate is null) { throw new KeyNotFoundException( $"Could not find an {nameof(IStreamNamespacePredicate)} for the pattern \"{pattern}\"." + $" Ensure that a corresponding {nameof(IStreamNamespacePredicateProvider)} is registered"); } bool includeNamespaceInGrainId = false; if (grainBinding.TryGetValue(WellKnownGrainTypeProperties.StreamBindingIncludeNamespaceKey, out var value) && string.Equals(value, "true", StringComparison.OrdinalIgnoreCase)) { includeNamespaceInGrainId = true; } newPredicates.Add(new StreamSubscriberPredicate(new StreamSubscriber(binding.GrainType, includeNamespaceInGrainId), predicate)); } } return(new Cache(version, newPredicates)); }
public override IEnumerable <Bundle <TBundleVersion> > Filter <TBundleVersion>(string argValue, IEnumerable <Bundle <TBundleVersion> > bundles) { if (MajorMinorVersion.TryFromInput(argValue, out var majorMinor)) { return(bundles .Where(bundle => bundle.Version.MajorMinor.CompareTo(majorMinor) < 0)); } else { var version = BundleVersion.FromInput <TBundleVersion>(argValue) as TBundleVersion; return(bundles .Where(bundle => bundle.Version.CompareTo(version) < 0)); } }
private async Task <bool> UpdateManifest(ClusterMembershipSnapshot clusterMembership) { var existingManifest = _current; var builder = existingManifest.Silos.ToBuilder(); var modified = false; // First, remove defunct entries. foreach (var entry in existingManifest.Silos) { var address = entry.Key; var status = clusterMembership.GetSiloStatus(address); if (address.Equals(_localSiloAddress)) { // The local silo is always present in the manifest. continue; } if (status == SiloStatus.None || status == SiloStatus.Dead) { builder.Remove(address); modified = true; } } // Next, fill missing entries. var tasks = new List <Task <(SiloAddress Key, GrainManifest Value, Exception Exception)> >(); foreach (var entry in clusterMembership.Members) { var member = entry.Value; if (member.SiloAddress.Equals(_localSiloAddress)) { // The local silo is always present in the manifest. continue; } if (existingManifest.Silos.ContainsKey(member.SiloAddress)) { // Manifest has already been retrieved for the cluster member. continue; } if (member.Status != SiloStatus.Active) { // If the member is not yet active, it may not be ready to process requests. continue; } tasks.Add(GetManifest(member.SiloAddress)); async Task <(SiloAddress, GrainManifest, Exception)> GetManifest(SiloAddress siloAddress) { try { // Get the manifest from the remote silo. var grainFactory = _services.GetRequiredService <IInternalGrainFactory>(); var remoteManifestProvider = grainFactory.GetSystemTarget <ISiloManifestSystemTarget>(Constants.ManifestProviderType, member.SiloAddress); var manifest = await remoteManifestProvider.GetSiloManifest(); return(siloAddress, manifest, null); } catch (Exception exception) { return(siloAddress, null, exception); } } } var fetchSuccess = true; await Task.WhenAll(tasks); foreach (var task in tasks) { var result = await task; if (result.Exception is Exception exception) { fetchSuccess = false; _logger.LogWarning(exception, "Error retrieving silo manifest for silo {SiloAddress}", result.Key); } else { modified = true; builder[result.Key] = result.Value; } } // Regardless of success or failure, update the manifest if it has been modified. var version = new MajorMinorVersion(clusterMembership.Version.Value, existingManifest.Version.Minor + 1); if (modified) { return(_updates.TryPublish(new ClusterManifest(version, builder.ToImmutable(), builder.Values.ToImmutableArray())) && fetchSuccess); } return(fetchSuccess); }
public Cache(MajorMinorVersion version, List <StreamSubscriberPredicate> predicates) { this.Version = version; this.Predicates = predicates; this.Namespaces = new ConcurrentDictionary <string, HashSet <StreamSubscriber> >(); }
internal void TestConstructor(int major, int minor) { var majorMinor = new MajorMinorVersion(major, minor); TestProperties(majorMinor, major, minor); }
internal void TestInequalityNull(string input) { var majorMinor = MajorMinorVersion.FromInput(input); EqualityComparisonTestUtils <MajorMinorVersion> .TestInequalityNull(majorMinor); }
/// <summary> /// Initializes a new instance of the <see cref="Cache"/> class. /// </summary> /// <param name="version">The cluster manifest version which this instance corresponds to.</param> /// <param name="map">The interface map.</param> public Cache(MajorMinorVersion version, Dictionary <GrainInterfaceType, CacheEntry> map) { this.Version = version; this.Map = map; }
private static PluginPackageInfoForJson ToPluginToPluginPackageInfos(IMinerPlugin plugin) { var version = new MajorMinorVersion(plugin.Version.Major, plugin.Version.Minor); if (!Checkers.IsMajorVersionSupported(version.major)) { throw new Exception($"Plugin version '{version.major}' not supported. Make sure you add the download link for this version"); } string minerPackageURL = null; if (plugin is IMinerBinsSource binsSource) { minerPackageURL = binsSource.GetMinerBinsUrlsForPlugin().FirstOrDefault(); } string binaryHash = null; if (minerPackageURL != null) { var filepath = GetTemporaryWorkFolder($"{plugin.PluginUUID}.tmp"); Logger.Info("MinerPluginsPacker", $"Calculating hash for {plugin.Name}-{plugin.PluginUUID}"); using var myWebClient = new WebClient(); myWebClient.DownloadFile(minerPackageURL, filepath); binaryHash = FileHelpers.GetFileSHA256Checksum(filepath); File.Delete(filepath); } var pluginZipFileName = GetPluginPackageName(plugin); var dllPackageZip = GetPluginsPackagesPath(pluginZipFileName); string pluginPackageHash = FileHelpers.GetFileSHA256Checksum(dllPackageZip); var binaryVersion = "N/A"; // TODO binary version if (plugin is IGetMinerBinaryVersion binVersionGetter) { binaryVersion = binVersionGetter.GetMinerBinaryVersion(); } PluginMetaInfo pluginMetaInfo = null; if (plugin is IGetPluginMetaInfo pluginMetaInfoGetter) { pluginMetaInfo = pluginMetaInfoGetter.GetPluginMetaInfo(); } if (pluginMetaInfo == null) { return(null); } var packagePassword = plugin is IGetBinsPackagePassword p ? p.BinsPackagePassword : null; var packageInfo = new PluginPackageInfoForJson { PluginUUID = plugin.PluginUUID, BinaryPackageHash = binaryHash, PluginPackageHash = pluginPackageHash, PluginAuthor = "*****@*****.**", PluginName = plugin.Name, PluginVersion = version, PluginPackageURL = $"https://github.com/nicehash/NHM_MinerPluginsDownloads/releases/download/v{version.major}.x/" + GetPluginPackageName(plugin), MinerPackageURL = minerPackageURL, SupportedDevicesAlgorithms = TransformToPluginPackageInfoSupportedDevicesAlgorithms(pluginMetaInfo.SupportedDevicesAlgorithms), // TODO enhance this with the bins version PluginDescription = $"Miner Binary Version '{binaryVersion}'.\n\n" + pluginMetaInfo.PluginDescription, PackagePassword = packagePassword }; return(packageInfo); }
public Cache(MajorMinorVersion version, List <BroadcastChannelSubscriberPredicate> predicates) { Version = version; Predicates = predicates; Namespaces = new ConcurrentDictionary <string, HashSet <BroadcastChannelSubscriber> >(); }