Beispiel #1
0
        public override Task <BoolResult> ScaleAsync(OperationContext context, IReadOnlyList <RedisClusterSize> scalePath)
        {
            var extraMessage = $"Path=[{string.Join(" -> ", scalePath)}]";

            return(context.PerformOperationAsync(Tracer, async() =>
            {
                for (var i = 0; i < scalePath.Count; i++)
                {
                    await RefreshAsync(context.Token).ThrowIfFailureAsync();
                    if (i > 0)
                    {
                        // Validate that the Redis cluster's state is the one we expected
                        var previous = scalePath[i - 1];
                        if (!ClusterSize.Equals(previous))
                        {
                            return new BoolResult(errorMessage: $"Expected instance `{Name}` to have size `{previous}` but found `{ClusterSize}`");
                        }
                    }

                    var target = scalePath[i];
                    await RequestScaleAsync(context, target).ThrowIfFailureAsync();
                }

                return BoolResult.Success;
            },
                                                 extraStartMessage: extraMessage,
                                                 extraEndMessage: _ => extraMessage));
        }
Beispiel #2
0
        private Task <BoolResult> RequestScaleAsync(OperationContext context, RedisClusterSize targetClusterSize)
        {
            string extraMessage = $"CurrentClusterSize=[{ClusterSize}] TargetClusterSize=[{targetClusterSize}]";

            return(context.PerformOperationAsync(Tracer, async() =>
            {
                if (ClusterSize.Equals(targetClusterSize))
                {
                    return new BoolResult(errorMessage: $"No-op scale request attempted (`{ClusterSize}` -> `{targetClusterSize}`) on instance `{Name}`");
                }

                if (!RedisScalingUtilities.CanScale(ClusterSize, targetClusterSize))
                {
                    return new BoolResult(errorMessage: $"Scale request `{ClusterSize}` -> `{targetClusterSize}` on instance `{Name}` is disallowed by Azure Cache for Redis");
                }

                if (!IsReadyToScale)
                {
                    return new BoolResult(errorMessage: $"Redis instance `{Name}` is not ready to scale, current provisioning state is `{RedisCache.ProvisioningState}`");
                }

                var instance = RedisCache.Update();

                if (!ClusterSize.Tier.Equals(targetClusterSize.Tier))
                {
                    switch (targetClusterSize.Tier.Plan)
                    {
                    case RedisPlan.Basic:
                        instance = instance.WithBasicSku(targetClusterSize.Tier.Capacity);
                        break;

                    case RedisPlan.Standard:
                        instance = instance.WithStandardSku(targetClusterSize.Tier.Capacity);
                        break;

                    case RedisPlan.Premium:
                        instance = instance.WithPremiumSku(targetClusterSize.Tier.Capacity);
                        break;
                    }
                }

                if (ClusterSize.Shards != targetClusterSize.Shards)
                {
                    instance = instance.WithShardCount(targetClusterSize.Shards);
                }

                await instance.ApplyAsync(context.Token);

                return BoolResult.Success;
            },
                                                 extraStartMessage: extraMessage,
                                                 extraEndMessage: _ => extraMessage,
                                                 pendingOperationTracingInterval: TimeSpan.FromMinutes(1)));
        }
Beispiel #3
0
        private async Task <BoolResult> RequestScaleAsync(RedisClusterSize targetClusterSize, CancellationToken cancellationToken = default)
        {
            if (ClusterSize.Equals(targetClusterSize))
            {
                return(new BoolResult(errorMessage: $"No-op scale request attempted (`{ClusterSize}` -> `{targetClusterSize}`) on instance `{Name}`"));
            }

            if (!RedisScalingUtilities.CanScale(ClusterSize, targetClusterSize))
            {
                return(new BoolResult(errorMessage: $"Scale request `{ClusterSize}` -> `{targetClusterSize}` on instance `{Name}` is disallowed by Azure Cache for Redis"));
            }

            if (!IsReadyToScale)
            {
                return(new BoolResult(errorMessage: $"Redis instance `{Name}` is not ready to scale, current provisioning state is `{RedisCache.ProvisioningState}`"));
            }

            return(await SubmitScaleRequestAsync(targetClusterSize, cancellationToken));
        }
Beispiel #4
0
        public override async Task <BoolResult> ScaleAsync(IReadOnlyList <RedisClusterSize> scalePath, CancellationToken cancellationToken = default)
        {
            for (var i = 0; i < scalePath.Count; i++)
            {
                await RefreshAsync(cancellationToken).ThrowIfFailureAsync();

                if (i > 0)
                {
                    // Validate that the Redis cluster's state is the one we expected
                    var previous = scalePath[i - 1];
                    if (!ClusterSize.Equals(previous))
                    {
                        return(new BoolResult(errorMessage: $"Expected instance `{Name}` to have size `{previous}` but found `{ClusterSize}`"));
                    }
                }

                var target = scalePath[i];
                await RequestScaleAsync(target, cancellationToken).ThrowIfFailureAsync();
            }

            return(BoolResult.Success);
        }
        /// <summary>
        /// Gets called whenever the Custom Room Properties are updated.
        /// In this callback we are interested in the settings the MasterClient can apply to the WorldGenerator.
        /// If all possible settings are updated (and available within the updated properties), these settings are also used
        /// to update the Ingame Control Panel as well as the WorldGenerator on all clients.
        /// Afterwards the WorldGenerator creates a new world with the new settings.
        /// </summary>
        public override void OnRoomPropertiesUpdate(Hashtable propertiesThatChanged)
        {
            if (propertiesThatChanged.ContainsKey(WorldGenerator.Instance.SeedPropertiesKey) && propertiesThatChanged.ContainsKey(WorldGenerator.Instance.WorldSizePropertiesKey) && propertiesThatChanged.ContainsKey(WorldGenerator.Instance.ClusterSizePropertiesKey) && propertiesThatChanged.ContainsKey(WorldGenerator.Instance.WorldTypePropertiesKey))
            {
                // Updating Seed
                int seed = (int)propertiesThatChanged[WorldGenerator.Instance.SeedPropertiesKey];
                seedInputField.text = seed.ToString();

                // Updating World Size
                WorldSize worldSize = (WorldSize)propertiesThatChanged[WorldGenerator.Instance.WorldSizePropertiesKey];
                switch (worldSize)
                {
                case WorldSize.Tiny:
                {
                    worldSizeDropdown.value = 0;
                    break;
                }

                case WorldSize.Small:
                {
                    worldSizeDropdown.value = 1;
                    break;
                }

                case WorldSize.Medium:
                {
                    worldSizeDropdown.value = 2;
                    break;
                }

                case WorldSize.Large:
                {
                    worldSizeDropdown.value = 3;
                    break;
                }
                }

                // Updating Cluster Size
                ClusterSize clusterSize = (ClusterSize)propertiesThatChanged[WorldGenerator.Instance.ClusterSizePropertiesKey];
                switch (clusterSize)
                {
                case ClusterSize.Small:
                {
                    clusterSizeDropdown.value = 0;
                    break;
                }

                case ClusterSize.Medium:
                {
                    clusterSizeDropdown.value = 1;
                    break;
                }

                case ClusterSize.Large:
                {
                    clusterSizeDropdown.value = 2;
                    break;
                }
                }

                // Updating World Type
                WorldType worldType = (WorldType)propertiesThatChanged[WorldGenerator.Instance.WorldTypePropertiesKey];
                switch (worldType)
                {
                case WorldType.Flat:
                {
                    worldTypeDropdown.value = 0;
                    break;
                }

                case WorldType.Standard:
                {
                    worldTypeDropdown.value = 1;
                    break;
                }

                case WorldType.Mountain:
                {
                    worldTypeDropdown.value = 2;
                    break;
                }
                }

                // Generating a new world
                WorldGenerator.Instance.CreateWorld();
            }
        }