Ejemplo n.º 1
0
        private void StartOrConnectToDeployment(Deployment deployment)
        {
            Log.Print(LogLevel.Info, $"Deployment {deployment.Name}, Status {deployment.Status}.");

            var request = DeploymentModifier.GetGetDeploymentRequest(deployment.Id, workerConfig.ProjectName);

            while (deployment.Status == Deployment.Types.Status.Starting || deployment.Status == Deployment.Types.Status.Stopping)
            {
                // Wait before checking the deployment status again.
                Task.Delay(TaskDelay).Wait();
                deployment = DeploymentModifier.GetDeployment(request);
            }

            switch (deployment.Status)
            {
            case Deployment.Types.Status.Running:
                ConnectToDeployment(deployment);
                break;

            case Deployment.Types.Status.Stopped:
                StartDeployment(deployment.Name);
                break;

            case Deployment.Types.Status.Unknown:
            case Deployment.Types.Status.Error:
                Log.Print(LogLevel.Warn, $"The deployment {deployment.Name} is in an unrecoverable state ({deployment.Status}). Trying to restart it.", serviceConnection);
                DeploymentModifier.StopDeployment(deployment);
                Task.Delay(TaskDelay).Wait();
                StartOrConnectToDeployment(deployment);
                break;
            }
        }
        public static void UpdateDeployment(Deployment deployment)
        {
            ExceptionHandler.HandleGrpcCall(() =>
            {
                var request = new UpdateDeploymentRequest
                {
                    Deployment = deployment
                };

                deploymentServiceClient.UpdateDeployment(request);
            });
        }
        public static void StopDeployment(Deployment deployment)
        {
            ExceptionHandler.HandleGrpcCall(() =>
            {
                var request = new StopDeploymentRequest
                {
                    Id          = deployment.Id,
                    ProjectName = deployment.ProjectName,
                };

                deploymentServiceClient.StopDeployment(request);
            });
        }
Ejemplo n.º 4
0
        private void ConnectToDeployment(Deployment deployment)
        {
            var request = DeploymentModifier.GetGetDeploymentRequest(deployment.Id, workerConfig.ProjectName);

            DeploymentModifier.AddDeploymentTags(request, sessionConfig.DeploymentTags.Append($"{Tags.MaxPlayers}_{sessionConfig.MaxNumberOfClients}"));
            DeploymentModifier.SetMaxWorkerCapacity(request, sessionConfig.ClientType, sessionConfig.MaxNumberOfClients);

            var connector            = new Connector(WorkerType, deployment.Name, serviceConnection);
            var connectionParameters = new ConnectionParameters
            {
                WorkerType = WorkerType,
                Network    =
                {
                    UseExternalIp           = true,
                    ConnectionType          = NetworkConnectionType.Tcp,
                    ConnectionTimeoutMillis =                     10000,
                },
            };

            bool  hasConnected;
            short attempts = 0;

            do
            {
                hasConnected = connector.TryConnect(connectionParameters, devAuthToken);
                attempts++;
            }while (attempts < Utils.MaxRetries && !hasConnected);

            if (!hasConnected)
            {
                throw new Exception($"Unable to connect to deployment {deployment.Name}.");
            }

            var connection            = connector.Connection;
            var handler               = new SpatialOSReceiveHandler(connection, request);
            var deploymentInformation = new DeploymentInformation
            {
                DeploymentId = deployment.Id,
                ProjectName  = deployment.ProjectName,
                Connection   = connection,
                Handler      = handler,
            };

            new Thread(ProcessingOps).Start(deploymentInformation);
        }
Ejemplo n.º 5
0
        protected override void Setup()
        {
            Console.WriteLine($"Starting a deployment with name: {DeploymentName}");
            var launchConfig = File.ReadAllText(LaunchConfigFilePath);

            _deployment = _deploymentServiceClient.CreateDeployment(new CreateDeploymentRequest
            {
                Deployment = new Deployment
                {
                    ProjectName  = ProjectName,
                    Name         = DeploymentName,
                    LaunchConfig = new LaunchConfig
                    {
                        ConfigJson = launchConfig
                    },
                    AssemblyId = AssemblyId,
                    Tag        = { ScenarioDeploymentTag }
                }
            }).PollUntilCompleted().GetResultOrNull();
        }
Ejemplo n.º 6
0
        /// <summary>
        ///     This contains the implementation of the "Capacity limiting" scenario.
        ///     1. Gets the currently running cloud deployment that has a capacity limit.
        ///     2. Tests that connecting more clients than the capacity limit fails.
        ///     3. Updates the deployment to increase the capacity limit.
        ///     4. Tests that additional clients are now able to connect to the deployment.
        /// </summary>
        protected override void Run()
        {
            Console.WriteLine("Finding current running deployment");
            _deployment = _deploymentServiceClient
                          .ListDeployments(new ListDeploymentsRequest
            {
                ProjectName    = ProjectName,
                DeploymentName = DeploymentName
            })
                          .First(d => d.Status == Deployment.Types.Status.Running);
            Console.WriteLine($"Found deployment {_deployment.Id}");

            Console.WriteLine("Setting capacity limit to 2");
            _deployment.WorkerConnectionCapacities.Clear();
            _deployment.WorkerConnectionCapacities.Add(new WorkerCapacity
            {
                WorkerType  = ScenarioWorkerType,
                MaxCapacity = 2
            });
            _deploymentServiceClient.UpdateDeployment(new UpdateDeploymentRequest {
                Deployment = _deployment
            });

            Console.WriteLine("Creating a PlayerIdentityToken");
            var playerIdentityTokenResponse = _playerAuthServiceClient.CreatePlayerIdentityToken(
                new CreatePlayerIdentityTokenRequest
            {
                Provider         = "provider",
                PlayerIdentifier = "player_identifier",
                ProjectName      = ProjectName
            });

            Console.WriteLine(JsonConvert.SerializeObject(playerIdentityTokenResponse));

            Console.WriteLine("Creating a LoginToken for the selected deployment");
            var createLoginTokenResponse = _playerAuthServiceClient.CreateLoginToken(
                new CreateLoginTokenRequest
            {
                PlayerIdentityToken = playerIdentityTokenResponse.PlayerIdentityToken,
                DeploymentId        = _deployment.Id,
                LifetimeDuration    = Duration.FromTimeSpan(new TimeSpan(0, 0, 30, 0)),
                WorkerType          = ScenarioWorkerType
            });

            Console.WriteLine(JsonConvert.SerializeObject(createLoginTokenResponse));

            Console.WriteLine("Connecting 3 workers to the deployment. Expecting only 2 to succeed");
            var locatorParameters = new LocatorParameters
            {
                PlayerIdentity = new PlayerIdentityCredentials
                {
                    PlayerIdentityToken = playerIdentityTokenResponse.PlayerIdentityToken,
                    LoginToken          = createLoginTokenResponse.LoginToken
                }
            };
            var locator = new Locator(LocatorServerAddress, LocatorServerPort, locatorParameters);

            for (var i = 0; i < 3; i++)
            {
                var connectionSucceeded = TryConnectWorker(locator);
                if (!connectionSucceeded && i != 2)
                {
                    throw new Exception("Expected worker to connect successfully");
                }
                if (connectionSucceeded && i == 2)
                {
                    throw new Exception("Expected worker to fail to connect");
                }
            }

            Console.WriteLine("Increasing capacity limit to 3");
            _deployment.WorkerConnectionCapacities.Clear();
            _deployment.WorkerConnectionCapacities.Add(new WorkerCapacity
            {
                WorkerType  = ScenarioWorkerType,
                MaxCapacity = 3
            });
            _deploymentServiceClient.UpdateDeployment(new UpdateDeploymentRequest {
                Deployment = _deployment
            });

            Console.WriteLine("Connecting another worker");
            if (!TryConnectWorker(locator))
            {
                throw new Exception("Expected worker to be able to connect after capacity increase");
            }
        }