Exemplo n.º 1
0
        private static Cache BuildCache(ClusterManifest clusterManifest)
        {
            var available           = new Dictionary <GrainInterfaceType, List <ushort> >();
            var supportedInterfaces = new Dictionary <(GrainInterfaceType, ushort), List <SiloAddress> >();
            var supportedGrains     = new Dictionary <GrainType, List <SiloAddress> >();

            foreach (var entry in clusterManifest.Silos)
            {
                var silo     = entry.Key;
                var manifest = entry.Value;
                foreach (var grainInterface in manifest.Interfaces)
                {
                    var id = grainInterface.Key;

                    if (!grainInterface.Value.Properties.TryGetValue(WellKnownGrainInterfaceProperties.Version, out var versionString) ||
                        !ushort.TryParse(versionString, out var version))
                    {
                        version = 0;
                    }

                    if (!available.TryGetValue(id, out var versions))
                    {
                        available[id] = new List <ushort> {
                            version
                        };
                    }
                    else if (!versions.Contains(version))
                    {
                        versions.Add(version);
                    }

                    if (!supportedInterfaces.TryGetValue((id, version), out var supportedSilos))
                    {
                        supportedInterfaces[(id, version)] = new List <SiloAddress> {
Exemplo n.º 2
0
 public ClusterManifestProvider(
     ILocalSiloDetails localSiloDetails,
     SiloManifestProvider siloManifestProvider,
     ClusterMembershipService clusterMembershipService,
     IFatalErrorHandler fatalErrorHandler,
     ILogger <ClusterManifestProvider> logger,
     IServiceProvider services)
 {
     _localSiloAddress         = localSiloDetails.SiloAddress;
     _logger                   = logger;
     _services                 = services;
     _clusterMembershipService = clusterMembershipService;
     _fatalErrorHandler        = fatalErrorHandler;
     this.LocalGrainManifest   = siloManifestProvider.SiloManifest;
     _current                  = new ClusterManifest(
         MajorMinorVersion.Zero,
         ImmutableDictionary.CreateRange(new[] { new KeyValuePair <SiloAddress, GrainManifest>(localSiloDetails.SiloAddress, this.LocalGrainManifest) }),
         ImmutableArray.Create(this.LocalGrainManifest));
     _updates = new AsyncEnumerable <ClusterManifest>(
         (previous, proposed) => previous.Version <= MajorMinorVersion.Zero || proposed.Version > previous.Version,
         _current)
     {
         OnPublished = update => Interlocked.Exchange(ref _current, update)
     };
 }
Exemplo n.º 3
0
 public ClusterManifestProvider(
     ILocalSiloDetails localSiloDetails,
     SiloManifest localSiloManifest,
     IInternalGrainFactory grainFactory,
     ClusterMembershipService clusterMembershipService,
     IFatalErrorHandler fatalErrorHandler,
     ILogger <ClusterManifestProvider> logger,
     IOptions <TypeManagementOptions> options,
     IServiceProvider services)
 {
     _localSiloAddress         = localSiloDetails.SiloAddress;
     _grainFactory             = grainFactory;
     _logger                   = logger;
     _services                 = services;
     _clusterMembershipService = clusterMembershipService;
     _fatalErrorHandler        = fatalErrorHandler;
     _options                  = options.Value;
     _current                  = new ClusterManifest(
         MajorMinorVersion.Zero,
         ImmutableDictionary.CreateRange(new[] { new KeyValuePair <SiloAddress, SiloManifest>(localSiloDetails.SiloAddress, localSiloManifest) }));
     _updates = new AsyncEnumerable <ClusterManifest>(
         (previous, proposed) => previous.Version <= MajorMinorVersion.Zero || proposed.Version > previous.Version,
         _current)
     {
         OnPublished = update => Interlocked.Exchange(ref _current, update)
     };
 }
        /// <summary>
        /// Serializes the object to JSON.
        /// </summary>
        /// <param name="writer">The <see cref="T: Newtonsoft.Json.JsonWriter" /> to write to.</param>
        /// <param name="obj">The object to serialize to JSON.</param>
        internal static void Serialize(JsonWriter writer, ClusterManifest obj)
        {
            // Required properties are always serialized, optional properties are serialized when not null.
            writer.WriteStartObject();
            if (obj.Manifest != null)
            {
                writer.WriteProperty(obj.Manifest, "Manifest", JsonWriterExtensions.WriteStringValue);
            }

            writer.WriteEndObject();
        }
Exemplo n.º 5
0
        /// <summary>
        /// Builds a cached resolution mapping.
        /// </summary>
        /// <param name="clusterManifest">The current cluster manifest.</param>
        /// <returns>The cache.</returns>
        private static Cache BuildCache(ClusterManifest clusterManifest)
        {
            var result = new Dictionary <GrainInterfaceType, CacheEntry>();

            foreach (var manifest in clusterManifest.AllGrainManifests)
            {
                foreach (var grainType in manifest.Grains)
                {
                    var id = grainType.Key;
                    grainType.Value.Properties.TryGetValue(WellKnownGrainTypeProperties.TypeName, out var typeName);
                    grainType.Value.Properties.TryGetValue(WellKnownGrainTypeProperties.FullTypeName, out var fullTypeName);
                    foreach (var property in grainType.Value.Properties)
                    {
                        if (!property.Key.StartsWith(WellKnownGrainTypeProperties.ImplementedInterfacePrefix, StringComparison.Ordinal))
                        {
                            continue;
                        }
                        var    implemented = GrainInterfaceType.Create(property.Value);
                        string interfaceTypeName;
                        if (manifest.Interfaces.TryGetValue(implemented, out var interfaceProperties))
                        {
                            interfaceProperties.Properties.TryGetValue(WellKnownGrainInterfaceProperties.TypeName, out interfaceTypeName);
                        }
                        else
                        {
                            interfaceTypeName = null;
                        }

                        // Try to work out the best primary implementation
                        result.TryGetValue(implemented, out var entry);

                        var implementations = entry.Implementations ?? new List <(string Prefix, GrainType GrainType)>();
                        if (!implementations.Contains((fullTypeName, id)))
                        {
                            implementations.Add((fullTypeName, id));
                        }

                        GrainType primaryImplementation;
                        if (!entry.PrimaryImplementation.IsDefault)
                        {
                            primaryImplementation = entry.PrimaryImplementation;
                        }
                        else if (interfaceProperties?.Properties is { } props&& props.TryGetValue(WellKnownGrainInterfaceProperties.DefaultGrainType, out var defaultTypeString))
                        {
                            // A specified default grain type trumps others.
                            primaryImplementation = GrainType.Create(defaultTypeString);
                        }
Exemplo n.º 6
0
 public ManagementGrain(
     IInternalGrainFactory internalGrainFactory,
     ISiloStatusOracle siloStatusOracle,
     IVersionStore versionStore,
     ILogger <ManagementGrain> logger,
     MembershipTableManager membershipTableManager,
     IClusterManifestProvider clusterManifestProvider,
     Catalog catalog)
 {
     this.membershipTableManager = membershipTableManager;
     this.siloManifest           = clusterManifestProvider.LocalGrainManifest;
     this.clusterManifest        = clusterManifestProvider.Current;
     this.internalGrainFactory   = internalGrainFactory;
     this.siloStatusOracle       = siloStatusOracle;
     this.versionStore           = versionStore;
     this.logger  = logger;
     this.catalog = catalog;
 }
 public ClientClusterManifestProvider(
     IServiceProvider services,
     GatewayManager gatewayManager,
     ILogger <ClientClusterManifestProvider> logger,
     ClientManifestProvider clientManifestProvider,
     IOptions <TypeManagementOptions> typeManagementOptions)
 {
     _logger = logger;
     _typeManagementOptions = typeManagementOptions.Value;
     _services               = services;
     _gatewayManager         = gatewayManager;
     this.LocalGrainManifest = clientManifestProvider.ClientManifest;
     _current = new ClusterManifest(MajorMinorVersion.Zero, ImmutableDictionary <SiloAddress, GrainManifest> .Empty, ImmutableArray.Create(this.LocalGrainManifest));
     _updates = new AsyncEnumerable <ClusterManifest>(
         (previous, proposed) => previous is null || proposed.Version == MajorMinorVersion.Zero || proposed.Version > previous.Version,
         _current)
     {
         OnPublished = update => Interlocked.Exchange(ref _current, update)
     };
 }
        /// <summary>
        /// Builds a cached resolution mapping.
        /// </summary>
        /// <param name="clusterManifest">The current cluster manifest.</param>
        /// <returns>The cache.</returns>
        private static Cache BuildCache(ClusterManifest clusterManifest)
        {
            var result = new Dictionary <GrainInterfaceType, CacheEntry>();

            foreach (var manifest in clusterManifest.AllGrainManifests)
            {
                GrainType knownPrimary = default;
                foreach (var grainInterface in manifest.Interfaces)
                {
                    var id = grainInterface.Key;

                    if (grainInterface.Value.Properties.TryGetValue(WellKnownGrainInterfaceProperties.DefaultGrainType, out var defaultTypeString))
                    {
                        knownPrimary = GrainType.Create(defaultTypeString);
                        continue;
                    }
                }

                foreach (var grainType in manifest.Grains)
                {
                    var id = grainType.Key;
                    grainType.Value.Properties.TryGetValue(WellKnownGrainTypeProperties.TypeName, out var typeName);
                    grainType.Value.Properties.TryGetValue(WellKnownGrainTypeProperties.FullTypeName, out var fullTypeName);
                    foreach (var property in grainType.Value.Properties)
                    {
                        if (!property.Key.StartsWith(WellKnownGrainTypeProperties.ImplementedInterfacePrefix, StringComparison.Ordinal))
                        {
                            continue;
                        }
                        var    implemented = GrainInterfaceType.Create(property.Value);
                        string interfaceTypeName;
                        if (manifest.Interfaces.TryGetValue(implemented, out var interfaceProperties))
                        {
                            interfaceProperties.Properties.TryGetValue(WellKnownGrainInterfaceProperties.TypeName, out interfaceTypeName);
                        }
                        else
                        {
                            interfaceTypeName = null;
                        }

                        // Try to work out the best primary implementation
                        result.TryGetValue(implemented, out var entry);
                        GrainType primaryImplementation;
                        if (!knownPrimary.IsDefault)
                        {
                            primaryImplementation = knownPrimary;
                        }
                        else if (!entry.PrimaryImplementation.IsDefault)
                        {
                            primaryImplementation = entry.PrimaryImplementation;
                        }
                        else if (string.Equals(interfaceTypeName?.Substring(1), typeName, StringComparison.Ordinal))
                        {
                            primaryImplementation = id;
                        }
                        else
                        {
                            primaryImplementation = default;
                        }

                        var implementations = entry.Implementations ?? new List <(string Prefix, GrainType GrainType)>();
                        if (!implementations.Contains((fullTypeName, id)))
                        {
                            implementations.Add((fullTypeName, id));
                        }
                        result[implemented] = new CacheEntry(primaryImplementation, implementations);
                    }
                }
            }

            return(new Cache(clusterManifest.Version, result));
        }